Skip to content

Commit

Permalink
gui: PlotNavigator: added zoom cancel button
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Popa <[email protected]>
  • Loading branch information
andrei47w committed Apr 18, 2024
1 parent 57e6e51 commit 5ea95a9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
8 changes: 7 additions & 1 deletion gui/include/gui/plotnavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#include <QwtPlot>
#include "scopy-gui_export.h"

namespace scopy {
class QPushButton;

namespace scopy {
class HoverWidget;
class PlotChannel;
class PlotWidget;
class PlotMagnifier;
Expand Down Expand Up @@ -90,6 +92,7 @@ class SCOPY_GUI_EXPORT PlotNavigator : public QObject
Qt::KeyboardModifier getZoomerXYModifier();

static void syncPlotNavigators(PlotNavigator *pNav1, PlotNavigator *pNav2, QSet<QwtAxisId> *axes);
void setResetButtonEn(bool en);

Q_SIGNALS:
void reset();
Expand All @@ -104,6 +107,7 @@ class SCOPY_GUI_EXPORT PlotNavigator : public QObject
private:
void init();
void initNavigators();
void initResetButton();
QWidget *canvas();
PlotMagnifier *createMagnifier(QwtAxisId axisId);
PlotZoomer *createZoomer(QwtAxisId axisId);
Expand All @@ -127,6 +131,8 @@ class SCOPY_GUI_EXPORT PlotNavigator : public QObject
bool m_magnifierEn, m_zoomerEn;
Qt::KeyboardModifier m_zoomerXModifier, m_zoomerYModifier, m_zoomerXYModifier;
Qt::KeyboardModifier m_magnifierPanModifier, m_magnifierZoomModifier;
QPushButton *m_resetButton;
HoverWidget *m_resetHover;
};
} // namespace scopy

Expand Down
1 change: 1 addition & 0 deletions gui/res/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
<file>icons/warning.svg</file>
<file>icons/scopy-default/icons/RegMap.svg</file>
<file>icons/handle_arrow.svg</file>
<file>icons/search_crossed.svg</file>
</qresource>
<qresource prefix="/">
<file>icons/scopy-default/icons/search.svg</file>
Expand Down
27 changes: 27 additions & 0 deletions gui/src/plotnavigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
#include "plotzoomer.hpp"
#include "qevent.h"

#include <QPushButton>
#include <hoverwidget.h>
#include <plotaxis.h>
#include <stylehelper.h>

using namespace scopy;

Expand Down Expand Up @@ -39,6 +42,7 @@ PlotNavigator::PlotNavigator(PlotWidget *plotWidget, QSet<PlotChannel *> *channe
, m_zoomerXYModifier(Qt::NoModifier)
, m_magnifierPanModifier(Qt::ShiftModifier)
, m_magnifierZoomModifier(Qt::NoModifier)
, m_resetButton(nullptr)
{
init();
}
Expand All @@ -50,6 +54,9 @@ void PlotNavigator::init()
m_axes->insert(ch->yAxis()->axisId());
}

initResetButton();
setResetButtonEn(true);

initNavigators();
connect(this, &PlotNavigator::undo, this, &PlotNavigator::onUndo);
connect(this, &PlotNavigator::reset, this, &PlotNavigator::onReset);
Expand All @@ -71,6 +78,24 @@ void PlotNavigator::initNavigators()
}
}

void PlotNavigator::initResetButton()
{
m_resetButton = new QPushButton(m_plot->canvas());
QIcon icon(QPixmap(":/gui/icons/search_crossed.svg"));
m_resetButton->setFlat(true);
StyleHelper::TransparentWidget(m_resetButton);
m_resetButton->setIcon(icon);

connect(m_resetButton, &QPushButton::clicked, this, [=]() { Q_EMIT reset(); });
connect(this, &PlotNavigator::rectChanged, this, [=]() { m_resetButton->setVisible(isZoomed()); });

m_resetHover = new HoverWidget(m_resetButton, m_plot, m_plot);
m_resetHover->setAnchorPos(HoverPosition::HP_BOTTOMRIGHT);
m_resetHover->setContentPos(HoverPosition::HP_TOPLEFT);
m_resetHover->setAnchorOffset(QPoint(-6, -6));
m_resetHover->show();
}

QWidget *PlotNavigator::canvas() { return m_plot->canvas(); }

bool PlotNavigator::eventFilter(QObject *object, QEvent *event)
Expand Down Expand Up @@ -536,4 +561,6 @@ void PlotNavigator::syncPlotNavigators(PlotNavigator *pNav1, PlotNavigator *pNav
}
}

void PlotNavigator::setResetButtonEn(bool en) { m_resetHover->setVisible(en); }

#include "moc_plotnavigator.cpp"

0 comments on commit 5ea95a9

Please sign in to comment.