diff --git a/cursors.cpp b/cursors.cpp index 38446de..9af4ad8 100644 --- a/cursors.cpp +++ b/cursors.cpp @@ -75,15 +75,22 @@ void Cursors::paintFront(QPainter &painter, QRect &rect, range_t sampleRa { painter.save(); + QRect cursorRect(cursorPositions[0], rect.top(), cursorPositions[1] - cursorPositions[0], rect.height()); // Draw translucent white fill for highlight painter.fillRect( - QRect(cursorPositions[0], rect.top(), cursorPositions[1] - cursorPositions[0], rect.bottom()), + cursorRect, QBrush(QColor(255, 255, 255, 50)) ); + // Draw vertical edges for individual bits + painter.setPen(QPen(Qt::gray, 1, Qt::DashLine)); + for (int i = 1; i < bitCount; i++) { + int pos = cursorPositions[0] + (i * cursorRect.width() / bitCount); + painter.drawLine(pos, rect.top(), pos, rect.bottom()); + } + // Draw vertical edges - QPen pen(Qt::white, 1, Qt::DashLine); - painter.setPen(pen); + painter.setPen(QPen(Qt::white, 1, Qt::SolidLine)); painter.drawLine(cursorPositions[0], rect.top(), cursorPositions[0], rect.bottom()); painter.drawLine(cursorPositions[1], rect.top(), cursorPositions[1], rect.bottom()); @@ -101,6 +108,12 @@ range_t Cursors::selection() } } +void Cursors::setBits(int bits) +{ + bitCount = std::max(bits, 1); + +} + void Cursors::setSelection(range_t selection) { cursorPositions[0] = selection.minimum; diff --git a/cursors.h b/cursors.h index 13a7ceb..9c6cedc 100644 --- a/cursors.h +++ b/cursors.h @@ -32,6 +32,7 @@ public: Cursors(QObject * parent); void paintFront(QPainter &painter, QRect &rect, range_t sampleRange); range_t selection(); + void setBits(int bits); void setSelection(range_t selection); signals: @@ -43,6 +44,7 @@ protected: private: bool pointOverCursor(QPoint point, int &cursor); + int bitCount = 1; bool dragging = false; int selectedCursor = 0; int cursorPositions[2] = {0, 50}; diff --git a/mainwindow.cpp b/mainwindow.cpp index cdd26b0..1cda6ca 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -44,6 +44,7 @@ MainWindow::MainWindow() connect(dock->powerMaxSlider, SIGNAL(valueChanged(int)), plots, SLOT(setPowerMax(int))); connect(dock->powerMinSlider, SIGNAL(valueChanged(int)), plots, SLOT(setPowerMin(int))); connect(dock->cursorsCheckBox, &QCheckBox::stateChanged, plots, &PlotView::enableCursors); + connect(dock->cursorBitsSpinBox, static_cast(&QSpinBox::valueChanged), plots, &PlotView::setCursorBits); // Connect dock outputs connect(plots, SIGNAL(timeSelectionChanged(float)), dock, SLOT(timeSelectionChanged(float))); diff --git a/plotview.cpp b/plotview.cpp index 28ab01c..d436311 100644 --- a/plotview.cpp +++ b/plotview.cpp @@ -117,6 +117,12 @@ void PlotView::invalidateEvent() horizontalScrollBar()->setMaximum(mainSampleSource->count()); } +void PlotView::setCursorBits(int bits) +{ + cursors.setBits(bits); + viewport()->update(); +} + void PlotView::setFFTSize(int size) { fftSize = size; @@ -201,6 +207,7 @@ void PlotView::updateView() horizontalScrollBar()->value(), horizontalScrollBar()->value() + width() * samplesPerLine() }; + horizontalScrollBar()->setMaximum(mainSampleSource->count() - ((width() - 1) * samplesPerLine())); // Update cursors QRect rect = viewport()->rect(); diff --git a/plotview.h b/plotview.h index 8a48be3..e182c6c 100644 --- a/plotview.h +++ b/plotview.h @@ -43,6 +43,7 @@ public slots: void cursorsMoved(); void enableCursors(bool enable); void invalidateEvent(); + void setCursorBits(int bits); void setFFTSize(int size); void setZoomLevel(int zoom); void setPowerMin(int power); diff --git a/spectrogramcontrols.cpp b/spectrogramcontrols.cpp index a6d235a..a4b0f71 100644 --- a/spectrogramcontrols.cpp +++ b/spectrogramcontrols.cpp @@ -73,12 +73,21 @@ SpectrogramControls::SpectrogramControls(const QString & title, QWidget * parent cursorsCheckBox = new QCheckBox(widget); layout->addRow(new QLabel(tr("Enable cursors:")), cursorsCheckBox); + cursorBitsSpinBox = new QSpinBox(); + layout->addRow(new QLabel(tr("Bits:")), cursorBitsSpinBox); + timeSelectionFreqLabel = new QLabel(); layout->addRow(new QLabel(tr("Frequency:")), timeSelectionFreqLabel); timeSelectionTimeLabel = new QLabel(); layout->addRow(new QLabel(tr("Time:")), timeSelectionTimeLabel); + bitSelectionFreqLabel = new QLabel(); + layout->addRow(new QLabel(tr("Bit frequency:")), bitSelectionFreqLabel); + + bitSelectionTimeLabel = new QLabel(); + layout->addRow(new QLabel(tr("Bit time:")), bitSelectionTimeLabel); + widget->setLayout(layout); setWidget(widget); @@ -94,6 +103,7 @@ void SpectrogramControls::setDefaults() powerMaxSlider->setValue(0); powerMinSlider->setValue(-50); cursorsCheckBox->setCheckState(Qt::Unchecked); + cursorBitsSpinBox->setValue(1); } void SpectrogramControls::fftSizeSliderChanged(int size) @@ -113,4 +123,8 @@ void SpectrogramControls::timeSelectionChanged(float time) { timeSelectionTimeLabel->setText(QString::number(time) + "s"); timeSelectionFreqLabel->setText(QString::number(1 / time) + "Hz"); + + int bits = cursorBitsSpinBox->value(); + bitSelectionTimeLabel->setText(QString::number(time / bits) + "s"); + bitSelectionFreqLabel->setText(QString::number(bits / time) + "Hz"); } diff --git a/spectrogramcontrols.h b/spectrogramcontrols.h index 0399972..b1ebd94 100644 --- a/spectrogramcontrols.h +++ b/spectrogramcontrols.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -57,8 +58,11 @@ public: QSlider *powerMaxSlider; QSlider *powerMinSlider; QCheckBox *cursorsCheckBox; + QSpinBox *cursorBitsSpinBox; QLabel *pointerFrequencyLabel; QLabel *pointerTimeLabel; QLabel *timeSelectionFreqLabel; QLabel *timeSelectionTimeLabel; + QLabel *bitSelectionFreqLabel; + QLabel *bitSelectionTimeLabel; };