Skip to content

Commit

Permalink
Make Y graph header resizeable
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr committed Oct 3, 2023
1 parent 15b495f commit 333c378
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 19 deletions.
22 changes: 16 additions & 6 deletions libshvvisu/src/timeline/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1223,24 +1223,34 @@ void Graph::setVisualSettings(const VisualSettings &settings)
}
}

void Graph::resizeChannel(qsizetype ix, int delta_px)
void Graph::resizeChannelHeight(qsizetype ix, int delta_px)
{
GraphChannel *ch = channelAt(ix);

if (ch != nullptr) {
GraphChannel::Style ch_style = ch->style();

double new_u = px2u(ch->verticalHeaderRect().height() + (delta_px));
double h = px2u(ch->verticalHeaderRect().height() + (delta_px));

if (new_u > GraphChannel::Style::DEFAULT_HEIGHT_MIN) {
ch_style.setHeightMax(new_u);
ch_style.setHeightMin(new_u);
if (h > GraphChannel::Style::DEFAULT_HEIGHT_MIN) {
ch_style.setHeightMax(h);
ch_style.setHeightMin(h);
ch->setStyle(ch_style);
Q_EMIT layoutChanged();
}
}
}

void Graph::resizeVerticalHeaderWidth(int delta_px)
{
double w = m_style.verticalHeaderWidth() + px2u(delta_px);

if (w > MIN_VERTICAL_HEADER_WIDTH && w < MAX_VERTICAL_HEADER_WIDTH) {
m_style.setVerticalHeaderWidth(w);
Q_EMIT layoutChanged();
}
}

Graph::VisualSettings Graph::visualSettings() const
{
VisualSettings view;
Expand Down Expand Up @@ -1886,7 +1896,7 @@ void Graph::drawSamples(QPainter *painter, int channel_ix, const DataRect &src_r
QColor line_area_color;
if(ch_style.lineAreaStyle() == GraphChannel::Style::LineAreaStyle::Filled) {
line_area_color = line_color;
line_area_color.setAlphaF(0.4F);
line_area_color.setAlphaF(0.2F);
}

int sample_point_size = u2px(0.3);
Expand Down
8 changes: 6 additions & 2 deletions libshvvisu/src/timeline/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class SHVVISU_DECL_EXPORT Graph : public QObject

using WidgetRange = Range<int>;

static constexpr double MIN_VERTICAL_HEADER_WIDTH = 10;
static constexpr double MAX_VERTICAL_HEADER_WIDTH = 25;

class SHVVISU_DECL_EXPORT Style : public QVariantMap
{
SHV_VARIANTMAP_FIELD2(int, u, setU, nitSize, 20) // px
Expand All @@ -59,7 +62,7 @@ class SHVVISU_DECL_EXPORT Graph : public QObject
SHV_VARIANTMAP_FIELD2(double, x, setX, AxisHeight, 1.5) // units
SHV_VARIANTMAP_FIELD2(double, y, setY, AxisWidth, 2.5) // units
SHV_VARIANTMAP_FIELD2(double, m, setM, iniMapHeight, 2) // units
SHV_VARIANTMAP_FIELD2(double, v, setV, erticalHeaderWidth, 10) // units
SHV_VARIANTMAP_FIELD2(double, v, setV, erticalHeaderWidth, MIN_VERTICAL_HEADER_WIDTH) // units
SHV_VARIANTMAP_FIELD2(bool, s, setS, eparateChannels, true)
SHV_VARIANTMAP_FIELD2(bool, y, setY, AxisVisible, true)

Expand Down Expand Up @@ -224,7 +227,8 @@ class SHVVISU_DECL_EXPORT Graph : public QObject

VisualSettings visualSettings() const;
void setVisualSettings(const VisualSettings &settings);
void resizeChannel(qsizetype ix, int delta_px);
void resizeChannelHeight(qsizetype ix, int delta_px);
void resizeVerticalHeaderWidth(int delta_px);

void saveVisualSettings(const QString &settings_id, const QString &name) const;
void deleteVisualSettings(const QString &settings_id, const QString &name) const;
Expand Down
2 changes: 1 addition & 1 deletion libshvvisu/src/timeline/graphchannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SHVVISU_DECL_EXPORT GraphChannel : public QObject

SHV_VARIANTMAP_FIELD2(int, i, setI, nterpolation, Interpolation::Stepped)
SHV_VARIANTMAP_FIELD2(int, l, setL, ineAreaStyle, LineAreaStyle::Blank)
SHV_VARIANTMAP_FIELD2(double, l, setL, ineWidth, 0.2)
SHV_VARIANTMAP_FIELD2(double, l, setL, ineWidth, 0.1)

public:
Style();
Expand Down
43 changes: 35 additions & 8 deletions libshvvisu/src/timeline/graphwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,21 @@ void GraphWidget::mousePressEvent(QMouseEvent *event)
event->accept();
return;
}
if (isMouseAboveChannelResizeHandle(pos)) {
m_mouseOperation = MouseOperation::ChannelHeaderResize;
if (isMouseAboveChannelResizeHandle(pos, Qt::Edge::BottomEdge)) {
m_mouseOperation = MouseOperation::ChannelHeaderResizeHeight;
m_resizeChannelIx = graph()->posToChannelHeader(pos);
m_recentMousePos = pos;
event->accept();
return;
}
if (isMouseAboveChannelResizeHandle(pos, Qt::Edge::RightEdge)) {
m_mouseOperation = MouseOperation::GraphVerticalHeaderResizeWidth;
m_resizeChannelIx = graph()->posToChannelHeader(pos);
m_recentMousePos = pos;
event->accept();
return;
}

if(posToChannel(pos) >= 0) {
if(event->modifiers() == Qt::ControlModifier) {
m_mouseOperation = MouseOperation::GraphDataAreaLeftCtrlPress;
Expand Down Expand Up @@ -301,7 +309,7 @@ void GraphWidget::mouseReleaseEvent(QMouseEvent *event)
update();
return;
}
else if(old_mouse_op == MouseOperation::ChannelHeaderResize) {
else if((old_mouse_op == MouseOperation::ChannelHeaderResizeHeight) || (old_mouse_op == MouseOperation::GraphVerticalHeaderResizeWidth)) {
m_resizeChannelIx = -1;
event->accept();
update();
Expand Down Expand Up @@ -335,9 +343,12 @@ void GraphWidget::mouseMoveEvent(QMouseEvent *event)
else if(isMouseAboveMiniMapSlider(pos)) {
setCursor(QCursor(Qt::SizeHorCursor));
}
else if((isMouseAboveChannelResizeHandle(pos)) || (m_mouseOperation == MouseOperation::ChannelHeaderResize)) {
else if(isMouseAboveChannelResizeHandle(pos, Qt::Edge::BottomEdge) || (m_mouseOperation == MouseOperation::ChannelHeaderResizeHeight)) {
setCursor(QCursor(Qt::SizeVerCursor));
}
else if(isMouseAboveChannelResizeHandle(pos, Qt::Edge::RightEdge) || (m_mouseOperation == MouseOperation::GraphVerticalHeaderResizeWidth)) {
setCursor(QCursor(Qt::SizeHorCursor));
}
else {
setCursor(QCursor(Qt::ArrowCursor));
}
Expand Down Expand Up @@ -412,8 +423,13 @@ void GraphWidget::mouseMoveEvent(QMouseEvent *event)
case MouseOperation::GraphDataAreaRightPress:
case MouseOperation::GraphDataAreaLeftCtrlShiftPress:
return;
case MouseOperation::ChannelHeaderResize: {
gr->resizeChannel(m_resizeChannelIx, pos.y() - m_recentMousePos.y());
case MouseOperation::ChannelHeaderResizeHeight: {
gr->resizeChannelHeight(m_resizeChannelIx, pos.y() - m_recentMousePos.y());
m_recentMousePos = pos;
return;
}
case MouseOperation::GraphVerticalHeaderResizeWidth: {
gr->resizeVerticalHeaderWidth(pos.x() - m_recentMousePos.x());
m_recentMousePos = pos;
return;
}
Expand Down Expand Up @@ -828,7 +844,7 @@ void GraphWidget::removeProbes(qsizetype channel_ix)
}
}

bool GraphWidget::isMouseAboveChannelResizeHandle(const QPoint &mouse_pos) const
bool GraphWidget::isMouseAboveChannelResizeHandle(const QPoint &mouse_pos, Qt::Edge header_edge) const
{
const Graph *gr = graph();
const int MARGIN = gr->u2px(0.5);
Expand All @@ -838,7 +854,18 @@ bool GraphWidget::isMouseAboveChannelResizeHandle(const QPoint &mouse_pos) const
if (channel_ix > -1) {
const GraphChannel *ch = gr->channelAt(channel_ix);
QRect header_rect = ch->verticalHeaderRect();
return (header_rect.bottom() - mouse_pos.y() < MARGIN);

switch (header_edge) {
case Qt::Edge::BottomEdge:
return (header_rect.bottom() - mouse_pos.y() < MARGIN);
break;
case Qt::Edge::RightEdge:
return (header_rect.right() - mouse_pos.x() < MARGIN);
break;
default:
shvWarning() << "Unsupported resize header edge option";
break;
}
}

return false;
Expand Down
5 changes: 3 additions & 2 deletions libshvvisu/src/timeline/graphwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SHVVISU_DECL_EXPORT GraphWidget : public QWidget
protected:
void createProbe(qsizetype channel_ix, timemsec_t time);
void removeProbes(qsizetype channel_ix);
bool isMouseAboveChannelResizeHandle(const QPoint &mouse_pos) const;
bool isMouseAboveChannelResizeHandle(const QPoint &mouse_pos, Qt::Edge header_edge) const;
bool isMouseAboveMiniMap(const QPoint &mouse_pos) const;
bool isMouseAboveMiniMapHandle(const QPoint &mouse_pos, bool left) const;
bool isMouseAboveLeftMiniMapHandle(const QPoint &pos) const;
Expand All @@ -81,7 +81,8 @@ class SHVVISU_DECL_EXPORT GraphWidget : public QWidget
None = 0,
MiniMapLeftResize,
MiniMapRightResize,
ChannelHeaderResize,
ChannelHeaderResizeHeight,
GraphVerticalHeaderResizeWidth,
MiniMapScrollZoom,
ChannelHeaderMove,
GraphDataAreaLeftPress,
Expand Down

0 comments on commit 333c378

Please sign in to comment.