Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust scale limits by dragging the mouse #200

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ MainWindow::MainWindow()

// Connect dock outputs
connect(plots, &PlotView::timeSelectionChanged, dock, &SpectrogramControls::timeSelectionChanged);
connect(plots, &PlotView::adjustPowerContrast, dock, &SpectrogramControls::adjustPowerContrast);
connect(plots, &PlotView::adjustPowerBias, dock, &SpectrogramControls::adjustPowerBias);
connect(plots, &PlotView::zoomIn, dock, &SpectrogramControls::zoomIn);
connect(plots, &PlotView::zoomOut, dock, &SpectrogramControls::zoomOut);

Expand Down
22 changes: 22 additions & 0 deletions src/plotview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,28 @@ bool PlotView::viewportEvent(QEvent *event) {
return true;
}

if (event->type() == QEvent::MouseMove)
{
// Handle scale limit adjustments
// if Ctrl+Alt pressed, OR middle mouse button is pressed
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if (((QApplication::keyboardModifiers() & Qt::ControlModifier) &&
QApplication::keyboardModifiers() & Qt::AltModifier) ||
(mouseEvent->buttons() & Qt::MiddleButton)) {
int delta_x = mouseEvent->pos().x() - last_x_clicked;
int delta_y = last_y_clicked - mouseEvent->pos().y();
last_x_clicked = mouseEvent->pos().x();
last_y_clicked = mouseEvent->pos().y();
if (std::abs(delta_x) > 30 || std::abs(delta_y) > 30)
{
return true;
}
emit adjustPowerBias(delta_x);
emit adjustPowerContrast(delta_y);
return true;
}
}

// Handle parent eveents
return QGraphicsView::viewportEvent(event);
}
Expand Down
4 changes: 4 additions & 0 deletions src/plotview.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class PlotView : public QGraphicsView, Subscriber

signals:
void timeSelectionChanged(float time);
void adjustPowerContrast(int amount);
void adjustPowerBias(int amount);
void zoomIn();
void zoomOut();

Expand Down Expand Up @@ -73,6 +75,8 @@ public slots:

int fftSize = 1024;
int zoomLevel = 1;
int last_y_clicked = 0;
int last_x_clicked = 0;
int powerMin;
int powerMax;
bool cursorsEnabled;
Expand Down
16 changes: 16 additions & 0 deletions src/spectrogramcontrols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,22 @@ void SpectrogramControls::timeSelectionChanged(float time)
}
}

void SpectrogramControls::adjustPowerBias(int amount)
{
if (powerMaxSlider->value() >= 10 || powerMinSlider->value() <= -140)
{
return;
}
powerMinSlider->setValue(std::max(std::min(powerMinSlider->value() + amount, 10), -140));
powerMaxSlider->setValue(std::max(std::min(powerMaxSlider->value() + amount, 10), -140));
}

void SpectrogramControls::adjustPowerContrast(int amount)
{
powerMinSlider->setValue(std::max(std::min(powerMinSlider->value() - amount, 10), -140));
powerMaxSlider->setValue(std::max(std::min(powerMaxSlider->value() + amount, 10), -140));
}

void SpectrogramControls::zoomIn()
{
zoomLevelSlider->setValue(zoomLevelSlider->value() + 1);
Expand Down
2 changes: 2 additions & 0 deletions src/spectrogramcontrols.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class SpectrogramControls : public QDockWidget

public slots:
void timeSelectionChanged(float time);
void adjustPowerContrast(int amount);
void adjustPowerBias(int amount);
void zoomIn();
void zoomOut();

Expand Down