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

Scopy 2.0: Cursors rework #1605

Merged
merged 5 commits into from
Apr 25, 2024
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
28 changes: 26 additions & 2 deletions gr-util/src/grtimechanneladdon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,19 @@ GRTimeChannelAddon::GRTimeChannelAddon(QString ch, GRDeviceAddon *dev, GRTimePlo

m_plotAxis = new PlotAxis(yPlotAxisPosition, plot, pen, this);
m_plotCh = new PlotChannel(m_channelName, pen, plot->xAxis(), m_plotAxis, this);
m_plotAxisHandle = new PlotAxisHandle(pen, m_plotAxis, plot, yPlotAxisHandle, this);

m_plotAxisHandle = new PlotAxisHandle(plot, m_plotAxis);
m_plotAxisHandle->handle()->setBarVisibility(BarVisibility::ON_HOVER);
m_plotAxisHandle->handle()->setColor(pen.color());
m_plotAxisHandle->handle()->setHandlePos(yPlotAxisHandle == QwtAxis::YLeft ? HandlePos::NORTH_WEST
: HandlePos::SOUTH_EAST);
connect(m_plotAxisHandle, &PlotAxisHandle::scalePosChanged, this, [=](double pos) {
double min = m_plotAxis->min() - pos;
double max = m_plotAxis->max() - pos;
m_plotAxis->setInterval(min, max);
plot->plot()->replot();
});

m_plotCh->setHandle(m_plotAxisHandle);
plot->addPlotAxisHandle(m_plotAxisHandle);
plot->addPlotChannel(m_plotCh);
Expand Down Expand Up @@ -343,7 +355,19 @@ ImportChannelAddon::ImportChannelAddon(QString name, PlotAddon *plotAddon, QPen

m_plotAxis = new PlotAxis(yPlotAxisPosition, plot, pen, this);
m_plotCh = new PlotChannel(m_channelName, pen, plot->xAxis(), m_plotAxis, this);
m_plotAxisHandle = new PlotAxisHandle(pen, m_plotAxis, plot, yPlotAxisHandle, this);

m_plotAxisHandle = new PlotAxisHandle(plot, m_plotAxis);
m_plotAxisHandle->handle()->setBarVisibility(BarVisibility::ON_HOVER);
m_plotAxisHandle->handle()->setColor(pen.color());
m_plotAxisHandle->handle()->setHandlePos(yPlotAxisHandle == QwtAxis::YLeft ? HandlePos::NORTH_WEST
: HandlePos::SOUTH_EAST);
connect(m_plotAxisHandle, &PlotAxisHandle::scalePosChanged, this, [=](double pos) {
double min = m_plotAxis->min() - pos;
double max = m_plotAxis->max() - pos;
m_plotAxis->setInterval(min, max);
plot->plot()->replot();
});

m_plotCh->setHandle(m_plotAxisHandle);
plot->addPlotAxisHandle(m_plotAxisHandle);
plot->addPlotChannel(m_plotCh);
Expand Down
3 changes: 0 additions & 3 deletions gr-util/src/grtimeplotaddon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ GRTimePlotAddon::GRTimePlotAddon(QString name, GRTopBlock *top, QObject *parent)
// widget->setLayout(m_lay);

m_plotWidget->xAxis()->setInterval(0, 1);
m_plotWidget->leftHandlesArea()->setVisible(true);
m_plotWidget->rightHandlesArea()->setVisible(true);
m_plotWidget->bottomHandlesArea()->setVisible(true);
m_plotWidget->xAxis()->setVisible(true);
// m_plotWidget->topHandlesArea()->setVisible(true);

Expand Down
109 changes: 109 additions & 0 deletions gui/include/gui/axishandle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#ifndef AXISHANDLE_H
#define AXISHANDLE_H

#include "scopy-gui_export.h"
#include <qwt_painter.h>
#include <qwt_plot.h>

namespace scopy {

class PlotAxis;
class PlotWidget;

enum HandlePos : int
{
NORTH_WEST = 0,
SOUTH_EAST = 1
};

enum HandleOrientation : int
{
TO_CENTER = 0,
TO_MIN = 1,
TO_MAX = 2

};

enum BarVisibility : int
{
ALWAYS = 0,
ON_HOVER = 1,
NEVER = 2

};

class SCOPY_GUI_EXPORT AxisHandle : public QWidget
{
Q_OBJECT

public:
AxisHandle(QwtAxisId axisId, HandlePos handlePos, QwtPlot *plot);
~AxisHandle() override;

void setColor(const QColor &color);
QColor getColor();

void setAxis(QwtAxisId axis);
QwtAxisId getAxisId();

int getPos();
void setPos(int pos);
void setPosSilent(int pos);

void setBarVisibility(BarVisibility bar);
BarVisibility getBarVisibility();

void setHandlePos(HandlePos pos);
HandlePos getHandlePos();

void setBounded(bool bounded);
bool isBounded() const;

uint getLineWidth();
void setLineWidth(int width);

void syncWithPlotAxis(bool sync = true);

Q_SIGNALS:
void pixelPosChanged(int pos);

protected:
void init();
void paintEvent(QPaintEvent *event) override;
bool eventFilter(QObject *object, QEvent *event) override;

QRect getBigRect();
QRect getSmallRect();
QRect getRect();
QLine getLine();
QRect getRectFromLine(QLine line);
void setHandle(HandleOrientation orientation = HandleOrientation::TO_CENTER);
void updateHandleOrientation();

void onMouseMove(QPointF pos);
bool onMouseButtonPress(QPointF pos);
void onMouseButtonRelease();
bool onEnter(QPointF pos);
void onLeave();
void onResize();
void onDoubleClick(QPointF pos);

private:
QwtAxisId m_axisId;
QPixmap m_handle;
QwtPlot *m_plot;
QColor m_color;
QPen m_pen;
QPoint m_pos;
HandlePos m_handlePos;
int m_handleMargins;
int m_handlePadding;
int m_handleSize;
bool m_isHovering;
bool m_pressed;
bool m_bounded;
BarVisibility m_barVisibility;
};
} // namespace scopy

#endif /* AXISHANDLE_H */
39 changes: 0 additions & 39 deletions gui/include/gui/cursor.h

This file was deleted.

29 changes: 13 additions & 16 deletions gui/include/gui/cursorcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#define CURSORCONTROLLER_H

#include "scopy-gui_export.h"

#include <QObject>

#include <plotcursors.h>
#include <widgets/cursorsettings.h>
#include <widgets/plotcursorreadouts.h>
Expand All @@ -25,11 +22,11 @@ public Q_SLOTS:
void setVisible(bool visible);
void readoutsSetVisible(bool visible);
void cursorsSetVisible(bool visible);
void horizEnToggled(bool toggled);
void horizLockToggled(bool toggled);
void horizTrackToggled(bool toggled);
void vertEnToggled(bool toggled);
void vertLockToggled(bool toggled);
void xEnToggled(bool toggled);
void xLockToggled(bool toggled);
void xTrackToggled(bool toggled);
void yEnToggled(bool toggled);
void yLockToggled(bool toggled);
void readoutsDragToggled(bool toggled);
void onAddedChannel(PlotChannel *ch);
void onRemovedChannel(PlotChannel *ch);
Expand All @@ -40,14 +37,14 @@ public Q_SLOTS:
CursorSettings *cursorSettings;
PlotCursorReadouts *plotCursorReadouts;
HoverWidget *hoverReadouts;
double horizLockGap;
double vertLockGap;
VCursor *v1Cursor;
VCursor *v2Cursor;
HCursor *h1Cursor;
HCursor *h2Cursor;
bool horizEn, horizLock, horizTrack;
bool vertEn, vertLock;
double LockGap;
double yLockGap;
PlotAxisHandle *y1Cursor;
PlotAxisHandle *y2Cursor;
PlotAxisHandle *x1Cursor;
PlotAxisHandle *x2Cursor;
bool xEn, xLock, xTrack;
bool yEn, yLock;
bool readoutDragsEn;

void initUI();
Expand Down
31 changes: 0 additions & 31 deletions gui/include/gui/hcursor.h

This file was deleted.

36 changes: 26 additions & 10 deletions gui/include/gui/plotaxishandle.h
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
#ifndef PLOTAXISHANDLE_H
#define PLOTAXISHANDLE_H

#include "plot_line_handle.h"
#include "plotwidget.h"
#include "scopy-gui_export.h"

#include <QWidget>
#include <axishandle.h>
#include <QObject>

namespace scopy {
class AxisHandle;

class SCOPY_GUI_EXPORT PlotAxisHandle : public QObject
{
Q_OBJECT
public:
PlotAxisHandle(QPen pen, PlotAxis *ax, PlotWidget *p, int position, QObject *parent = nullptr);
PlotAxisHandle(PlotWidget *plot, PlotAxis *ax);
~PlotAxisHandle();
RoundedHandleV *handle() const;

void setAxis(PlotAxis *axis);
PlotAxis *axis() const;
AxisHandle *handle() const;

double getPosition() const;
void setPosition(double pos);
void setPositionSilent(double pos);

double pixelToScale(int pos);
int scaleToPixel(double pos);

Q_SIGNALS:
void scalePosChanged(double);
void updatePos();

protected:
void init();

private:
double m_pos;
PlotWidget *m_plotWidget;
PlotAxis *m_axis;
QPen m_pen;
HorizBar *m_chOffsetBar;
RoundedHandleV *m_handle;
SymbolController *m_symbolCtrl;
QwtPlot *m_plot;
AxisHandle *m_handle;
};
} // namespace scopy

#endif // PLOTAXISHANDLE_H
25 changes: 12 additions & 13 deletions gui/include/gui/plotcursors.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
#define PLOTCURSORS_H
#include "plotwidget.h"
#include "scopy-gui_export.h"

#include <plotaxishandle.h>
#include <QObject>
#include <QPair>

#include <hcursor.h>
#include <vcursor.h>

namespace scopy {

class SCOPY_GUI_EXPORT PlotCursors : public QObject
Expand All @@ -19,25 +16,27 @@ class SCOPY_GUI_EXPORT PlotCursors : public QObject
~PlotCursors();

void displayIntersection();
void setYHandlePos(HandlePos pos);
void setXHandlePos(HandlePos pos);

public Q_SLOTS:
void setVisible(bool visible);
void horizSetVisible(bool visible);
void vertSetVisible(bool visible);
VCursor *getV1Cursor();
VCursor *getV2Cursor();
HCursor *getH1Cursor();
HCursor *getH2Cursor();
void setCanLeavePlot(bool leave);
void setXVisible(bool visible);
void setYVisible(bool visible);
PlotAxisHandle *getY1Cursor();
PlotAxisHandle *getY2Cursor();
PlotAxisHandle *getX1Cursor();
PlotAxisHandle *getX2Cursor();
void setBounded(bool leave);
void enableTracking(bool tracking);

Q_SIGNALS:
void update();

private:
PlotWidget *m_plot;
QPair<VCursor *, VCursor *> m_vCursors;
QPair<HCursor *, HCursor *> m_hCursors;
QPair<PlotAxisHandle *, PlotAxisHandle *> m_yCursors;
QPair<PlotAxisHandle *, PlotAxisHandle *> m_xCursors;
QwtPlotMarker *plotMarker1;
QwtPlotMarker *plotMarker2;
bool m_tracking;
Expand Down
Loading
Loading