Skip to content
Merged
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
15 changes: 15 additions & 0 deletions plotjuggler_app/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,10 @@ void MainWindow::onPlotAdded(PlotWidget* plot)
plot->setDefaultStyle(ui->buttonDots->isChecked() ? PlotWidgetBase::LINES_AND_DOTS :
PlotWidgetBase::LINES);

QSettings settings;
bool swap_pan_zoom = settings.value("Preferences::swap_pan_zoom", false).toBool();
plot->setSwapZoomPan(swap_pan_zoom);

if (ui->buttonReferencePoint->isChecked() && _reference_tracker_time.has_value())
{
plot->onReferenceLineChecked(ui->buttonReferencePoint->isChecked(),
Expand Down Expand Up @@ -3141,6 +3145,7 @@ void MainWindow::on_actionPreferences_triggered()
{
QSettings settings;
QString prev_style = settings.value("Preferences::theme", "light").toString();
bool prev_swap_pan_zoom = settings.value("Preferences::swap_pan_zoom", false).toBool();

PreferencesDialog dialog;
dialog.exec();
Expand All @@ -3151,6 +3156,16 @@ void MainWindow::on_actionPreferences_triggered()
{
loadStyleSheet(tr(":/resources/stylesheet_%1.qss").arg(theme));
}

// Apply swap pan/zoom preference to all existing plots
bool swap_pan_zoom = settings.value("Preferences::swap_pan_zoom", false).toBool();
if (swap_pan_zoom != prev_swap_pan_zoom)
{
auto visitor = [swap_pan_zoom](PlotWidget* plot) {
plot->setSwapZoomPan(swap_pan_zoom);
};
forEachWidget(visitor);
}
}

void MainWindow::on_playbackStep_valueChanged(double step)
Expand Down
16 changes: 1 addition & 15 deletions plotjuggler_app/plotwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1683,14 +1683,6 @@ bool PlotWidget::eventFilter(QObject* obj, QEvent* event)
return false;
}

void PlotWidget::overrideCursonMove()
{
QSettings settings;
QString theme = settings.value("Preferences::theme", "light").toString();
auto pixmap = LoadSvg(":/resources/svg/move_view.svg", theme);
QApplication::setOverrideCursor(QCursor(pixmap.scaled(24, 24)));
}

void PlotWidget::setAxisScale(QwtAxisId axisId, double min, double max)
{
if (min > max)
Expand Down Expand Up @@ -1746,17 +1738,12 @@ bool PlotWidget::canvasEventFilter(QEvent* event)
emit trackerMoved(pointF);
return true; // don't pass to canvas().
}
else if (mouse_event->modifiers() == Qt::ControlModifier) // panner
{
overrideCursonMove();
}
return false; // send to canvas()
}
else if (mouse_event->buttons() == Qt::MiddleButton &&
mouse_event->modifiers() == Qt::NoModifier)
{
overrideCursonMove();
return false;
return false; // send to canvas()
}
else if (mouse_event->button() == Qt::RightButton)
{
Expand Down Expand Up @@ -1797,7 +1784,6 @@ bool PlotWidget::canvasEventFilter(QEvent* event)
case QEvent::MouseButtonRelease: {
if (_dragging.mode == DragInfo::NONE)
{
QApplication::restoreOverrideCursor();
return false;
}
}
Expand Down
1 change: 0 additions & 1 deletion plotjuggler_app/plotwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ private slots:

// void updateMaximumZoomArea();
void rescaleEqualAxisScaling();
void overrideCursonMove();

void setAxisScale(QwtAxisId axisId, double min, double max);
};
Expand Down
38 changes: 23 additions & 15 deletions plotjuggler_app/preferences_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ PreferencesDialog::PreferencesDialog(QWidget* parent)
{
ui->setupUi(this);
QSettings settings;

// Apperance
QString theme = settings.value("Preferences::theme", "light").toString();
if (theme == "dark")
{
Expand All @@ -27,28 +29,26 @@ PreferencesDialog::PreferencesDialog(QWidget* parent)
ui->comboBoxTheme->setCurrentIndex(0);
}

bool use_separator = settings.value("Preferences::use_separator", true).toBool();
ui->checkBoxSeparator->setChecked(use_separator);

bool use_opengl = settings.value("Preferences::use_opengl", true).toBool();
ui->checkBoxOpenGL->setChecked(use_opengl);

int precision = settings.value("Preferences::precision", 3).toInt();
ui->comboBoxPrecision->setCurrentIndex(precision);

bool no_splash = settings.value("Preferences::no_splash", false).toBool();
ui->checkBoxSkipSplash->setChecked(no_splash);

// Behavior
bool use_plot_color_index = settings.value("Preferences::use_plot_color_index", false).toBool();
bool remember_color = settings.value("Preferences::remember_color", true).toBool();

ui->checkBoxRememberColor->setChecked(remember_color);
ui->radioLocalColorIndex->setChecked(use_plot_color_index);
ui->radioGlobalColorIndex->setChecked(!use_plot_color_index);

ui->pushButtonAdd->setIcon(LoadSvg(":/resources/svg/add_tab.svg", theme));
ui->pushButtonRemove->setIcon(LoadSvg(":/resources/svg/trash.svg", theme));

bool use_separator = settings.value("Preferences::use_separator", true).toBool();
ui->checkBoxSeparator->setChecked(use_separator);

bool use_opengl = settings.value("Preferences::use_opengl", true).toBool();
ui->checkBoxOpenGL->setChecked(use_opengl);

bool no_splash = settings.value("Preferences::no_splash", false).toBool();
ui->checkBoxSkipSplash->setChecked(no_splash);

bool autozoom_visibility = settings.value("Preferences::autozoom_visibility", true).toBool();
ui->checkBoxAutoZoomVisibility->setChecked(autozoom_visibility);

Expand All @@ -59,14 +59,21 @@ PreferencesDialog::PreferencesDialog(QWidget* parent)
settings.value("Preferences::autozoom_filter_applied", true).toBool();
ui->checkBoxAutoZoomFilter->setChecked(autozoom_filter_applied);

bool truncation_check = settings.value("Preferences::truncation_check", true).toBool();
ui->checkBoxTruncation->setChecked(truncation_check);

QSize export_plot =
settings.value("Preferences::export_plot_size", default_document_dimentions).toSize();
ui->spinBoxExportX->setValue(export_plot.width());
ui->spinBoxExportY->setValue(export_plot.height());

bool swap_pan_zoom = settings.value("Preferences::swap_pan_zoom", false).toBool();
ui->checkBoxSwapPanZoom->setChecked(swap_pan_zoom);

bool truncation_check = settings.value("Preferences::truncation_check", true).toBool();
ui->checkBoxTruncation->setChecked(truncation_check);

// Plugins
ui->pushButtonAdd->setIcon(LoadSvg(":/resources/svg/add_tab.svg", theme));
ui->pushButtonRemove->setIcon(LoadSvg(":/resources/svg/trash.svg", theme));

//---------------
auto custom_plugin_folders = settings.value("Preferences::plugin_folders", true).toStringList();
for (const auto& folder : custom_plugin_folders)
Expand Down Expand Up @@ -113,6 +120,7 @@ void PreferencesDialog::on_buttonBox_accepted()
settings.setValue("Preferences::truncation_check", ui->checkBoxTruncation->isChecked());
settings.setValue("Preferences::export_plot_size",
QSize{ ui->spinBoxExportX->value(), ui->spinBoxExportY->value() });
settings.setValue("Preferences::swap_pan_zoom", ui->checkBoxSwapPanZoom->isChecked());

QStringList plugin_folders;
for (int row = 0; row < ui->listWidgetCustom->count(); row++)
Expand Down
24 changes: 23 additions & 1 deletion plotjuggler_app/preferences_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>545</width>
<height>545</height>
<height>600</height>
</rect>
</property>
<property name="minimumSize">
Expand Down Expand Up @@ -452,6 +452,28 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxMouseInteraction">
<property name="title">
<string>Mouse Interaction:</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QCheckBox" name="checkBoxSwapPanZoom">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Default: Left-click to zoom, Ctrl+Left-click to pan&lt;/p&gt;&lt;p&gt;Swapped: Left-click to pan, Ctrl+Left-click to zoom&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Swap pan/zoom mouse action modifiers</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
Expand Down
4 changes: 4 additions & 0 deletions plotjuggler_base/include/PlotJuggler/plotwidget_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class PlotWidgetBase : public QWidget

bool isZoomEnabled() const;

void setSwapZoomPan(bool swapped);

bool isXYPlot() const;

QRectF currentBoundingRect() const;
Expand Down Expand Up @@ -166,6 +168,8 @@ public slots:
PlotLegend* legend();
PlotZoomer* zoomer();
PlotMagnifier* magnifier();
PlotPanner* panner1();
PlotPanner* panner2();

void updateMaximumZoomArea();

Expand Down
36 changes: 36 additions & 0 deletions plotjuggler_base/src/plotpanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include "qwt_scale_div.h"

#include "plotpanner.h"
#include <QMouseEvent>
#include <QApplication>
#include <QSettings>
#include "PlotJuggler/svg_util.h"

void PlotPanner::moveCanvas(int dx, int dy)
{
Expand Down Expand Up @@ -61,3 +65,35 @@ void PlotPanner::moveCanvas(int dx, int dy)
plot->setAutoReplot(doAutoReplot);
plot->replot();
}

void PlotPanner::widgetMousePressEvent(QMouseEvent* event)
{
// Check if this event matches our panning button/modifiers
Qt::MouseButton button;
Qt::KeyboardModifiers modifiers;
getMouseButton(button, modifiers);

if (event->button() == button && event->modifiers() == modifiers)
{
// Set the move cursor when panning starts
QSettings settings;
QString theme = settings.value("Preferences::theme", "light").toString();
auto pixmap = LoadSvg(":/resources/svg/move_view.svg", theme);
QApplication::setOverrideCursor(QCursor(pixmap.scaled(24, 24)));
_cursor_overridden = true;
}

QwtPlotPanner::widgetMousePressEvent(event);
}

void PlotPanner::widgetMouseReleaseEvent(QMouseEvent* event)
{
// Restore cursor before calling base class
if (_cursor_overridden)
{
QApplication::restoreOverrideCursor();
_cursor_overridden = false;
}

QwtPlotPanner::widgetMouseReleaseEvent(event);
}
5 changes: 5 additions & 0 deletions plotjuggler_base/src/plotpanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ public Q_SLOTS:
signals:
void rescaled(QRectF new_size);

protected:
void widgetMousePressEvent(QMouseEvent* event) override;
void widgetMouseReleaseEvent(QMouseEvent* event) override;

private:
bool _cursor_overridden = false;
};

#endif // PLOTPANNER_H
27 changes: 27 additions & 0 deletions plotjuggler_base/src/plotwidget_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,22 @@ bool PlotWidgetBase::isZoomEnabled() const
return p->zoom_enabled;
}

void PlotWidgetBase::setSwapZoomPan(bool swapped)
{
if (swapped)
{
// Swap: Left button for pan, Ctrl+Left for zoom
p->zoomer->setMousePattern(QwtEventPattern::MouseSelect1, Qt::LeftButton, Qt::ControlModifier);
p->panner1->setMouseButton(Qt::LeftButton, Qt::NoModifier);
}
else
{
// Default: Left button for zoom, Ctrl+Left for pan
p->zoomer->setMousePattern(QwtEventPattern::MouseSelect1, Qt::LeftButton, Qt::NoModifier);
p->panner1->setMouseButton(Qt::LeftButton, Qt::ControlModifier);
}
}

void PlotWidgetBase::overrideCurvesStyle(std::optional<CurveStyle> style)
{
p->overridden_curve_style = style;
Expand Down Expand Up @@ -818,6 +834,7 @@ PlotLegend* PlotWidgetBase::legend()
{
return p->legend;
}

PlotZoomer* PlotWidgetBase::zoomer()
{
return p->zoomer;
Expand All @@ -828,6 +845,16 @@ PlotMagnifier* PlotWidgetBase::magnifier()
return p->magnifier;
}

PlotPanner* PlotWidgetBase::panner1()
{
return p->panner1;
}

PlotPanner* PlotWidgetBase::panner2()
{
return p->panner2;
}

void PlotWidgetBase::updateMaximumZoomArea()
{
QRectF max_rect;
Expand Down
6 changes: 5 additions & 1 deletion plotjuggler_base/src/plotzoomer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ void PlotZoomer::widgetMouseMoveEvent(QMouseEvent* me)
void PlotZoomer::widgetMouseReleaseEvent(QMouseEvent* me)
{
_mouse_pressed = false;
_zoom_enabled = false;
if (_zoom_enabled)
{
QApplication::restoreOverrideCursor();
_zoom_enabled = false;
}
QwtPlotPicker::widgetMouseReleaseEvent(me);
this->setTrackerMode(AlwaysOff);
}
Expand Down