diff --git a/mainwindow.cpp b/mainwindow.cpp index 08c1140..3d185d0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -41,6 +41,7 @@ MainWindow::MainWindow() connect(dock->timeScaleCheckBox, SIGNAL(stateChanged(int)), &spectrogram, SLOT(setTimeScaleEnable(int))); connect(&spectrogram, SIGNAL(cursorFrequencyChanged(QString)), dock->cursorFrequencyLabel, SLOT(setText(QString))); connect(&spectrogram, SIGNAL(cursorTimeChanged(QString)), dock->cursorTimeLabel, SLOT(setText(QString))); + connect(dock->deltaDragCheckBox, SIGNAL(stateChanged(int)), &spectrogram, SLOT(setDeltaDragEnable(int))); connect(&spectrogram, SIGNAL(deltaFrequencyChanged(QString)), dock->deltaFrequencyLabel, SLOT(setText(QString))); connect(&spectrogram, SIGNAL(deltaTimeChanged(QString)), dock->deltaTimeLabel, SLOT(setText(QString))); } diff --git a/spectrogram.cpp b/spectrogram.cpp index b92ea43..195522d 100644 --- a/spectrogram.cpp +++ b/spectrogram.cpp @@ -36,6 +36,7 @@ Spectrogram::Spectrogram() powerMax = 0.0f; powerMin = -50.0f; timeScaleIsEnabled = true; + deltaDragIsEnabled = true; for (int i = 0; i < 256; i++) { float p = (float)i / 256; @@ -81,8 +82,10 @@ void Spectrogram::xyToFreqTime(int x, int y, float *freq, float *time) { } void Spectrogram::mouseReleaseEvent(QMouseEvent *event) { - cursorStartX = -1; - update(); + if (deltaDragIsEnabled) { + cursorStartX = -1; + update(); + } } void Spectrogram::mouseMoveEvent(QMouseEvent *event) { @@ -102,8 +105,12 @@ void Spectrogram::mouseMoveEvent(QMouseEvent *event) { } void Spectrogram::mousePressEvent(QMouseEvent *event) { - cursorEndX = cursorStartX = event->x(); - cursorEndY = cursorStartY = event->y(); + if (cursorStartX == -1) { + cursorEndX = cursorStartX = event->x(); + cursorEndY = cursorStartY = event->y(); + } else { + cursorStartX = -1; + } update(); } @@ -282,6 +289,11 @@ void Spectrogram::setTimeScaleEnable(int state) update(); } +void Spectrogram::setDeltaDragEnable(int state) +{ + deltaDragIsEnabled = (state == Qt::Checked); +} + int Spectrogram::getHeight() { diff --git a/spectrogram.h b/spectrogram.h index 1514347..d96b708 100644 --- a/spectrogram.h +++ b/spectrogram.h @@ -54,6 +54,7 @@ public slots: void setPowerMin(int power); void setZoomLevel(int zoom); void setTimeScaleEnable(int state); + void setDeltaDragEnable(int state); protected: void paintEvent(QPaintEvent *event); @@ -80,6 +81,7 @@ private: float powerMax; float powerMin; bool timeScaleIsEnabled; + bool deltaDragIsEnabled; int cursorStartX = -1, cursorStartY; int cursorEndX, cursorEndY; diff --git a/spectrogramcontrols.cpp b/spectrogramcontrols.cpp index 625b0fd..9f737b1 100644 --- a/spectrogramcontrols.cpp +++ b/spectrogramcontrols.cpp @@ -66,6 +66,10 @@ SpectrogramControls::SpectrogramControls(const QString & title, QWidget * parent cursorTimeLabel = new QLabel(); layout->addRow(new QLabel(tr("Cursor time:")), cursorTimeLabel); + deltaDragCheckBox = new QCheckBox(widget); + deltaDragCheckBox->setCheckState(Qt::Checked); + layout->addRow(new QLabel(tr("Delta dragging:")), deltaDragCheckBox); + deltaFrequencyLabel = new QLabel(); layout->addRow(new QLabel(tr("Delta frequency:")), deltaFrequencyLabel); diff --git a/spectrogramcontrols.h b/spectrogramcontrols.h index 6a9a165..3f835aa 100644 --- a/spectrogramcontrols.h +++ b/spectrogramcontrols.h @@ -54,6 +54,7 @@ public: QCheckBox *timeScaleCheckBox; QLabel *cursorFrequencyLabel; QLabel *cursorTimeLabel; + QCheckBox *deltaDragCheckBox; QLabel *deltaFrequencyLabel; QLabel *deltaTimeLabel; };