21 #include <QPainterPath>
28 setAcceptHoverEvents(
true);
48 prepareGeometryChange();
56 painter->setClipRect(
sceneAdapter()->viewportRectangle());
66 auto output = QRectF(real_rect);
87 double x = real_rect.x();
88 double y = real_rect.y();
89 double w = real_rect.width();
90 double h = real_rect.height();
92 double center_x = x + w / 2.;
93 double center_y = y + h / 2.;
96 center_x = adapter->toSceneX(-center_x);
99 center_y = adapter->toSceneY(center_y);
102 w = adapter->toSceneX(w) - adapter->toSceneX(0);
105 h = adapter->toSceneY(h) - adapter->toSceneY(0);
108 x = center_x - w / 2;
109 y = center_y - h / 2;
111 return QRectF(x, y, w, h);
118 double x = real_rect.x();
119 double y = real_rect.y();
120 double w = real_rect.width();
121 double h = real_rect.height();
124 x = adapter->toSceneX(-x);
127 y = adapter->toSceneY(y);
130 w = adapter->toSceneX(w) - adapter->toSceneX(0);
133 h = adapter->toSceneY(h) - adapter->toSceneY(0);
136 return QRectF(x, y, w, h);
142 double x_i = real_rect.x();
143 double y_i = real_rect.y();
144 double x_f = real_rect.x() + real_rect.width();
145 double y_f = real_rect.y() + real_rect.height();
148 x_i = viewport_rect.x();
150 return QRectF(x_i, y_i, x_f - x_i, y_f - y_i);
156 double x_i = real_rect.x();
157 double y_i = real_rect.y();
158 double x_f = real_rect.x() + real_rect.width();
159 double y_f = real_rect.y() + real_rect.height();
162 x_f = viewport_rect.x() + viewport_rect.width();
164 return QRectF(x_i, y_i, x_f - x_i, y_f - y_i);
174 auto display_path = QPainterPath(real_path);
175 for (
int i = 0; i < display_path.elementCount(); i++) {
176 QPointF pt = display_path.elementAt(i);
177 display_path.setElementPositionAt(i, adapter->toSceneX(-pt.x()), adapter->toSceneY(pt.y()));
189 return QPointF(-adapter->fromSceneX(pixel_pos.x()), adapter->fromSceneY(pixel_pos.y()));
237 if (flags() & QGraphicsItem::ItemIsMovable)
238 setCursor(QCursor(Qt::OpenHandCursor));
239 QGraphicsItem::hoverEnterEvent(event);
246 QGraphicsItem::hoverLeaveEvent(event);
252 if (flags() & QGraphicsItem::ItemIsMovable)
253 setCursor(QCursor(Qt::ClosedHandCursor));
254 QGraphicsItem::mousePressEvent(event);
260 if (flags() & QGraphicsItem::ItemIsMovable)
261 setCursor(QCursor(Qt::OpenHandCursor));
262 QGraphicsItem::mouseReleaseEvent(event);
Interface to convert coordinates of "scene" to coordinates of "widget".
virtual QRectF viewportRectangle() const =0
returns viewport rectangle in scene coordinates
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
paint override
void setCenterBased(bool choice)
Adapt the dimensions according to the center.
QPointF scenePos(QPointF pixel_pos) const
modify the rectangle for display according to the scene adapter
QRectF stretchRectLeft(const QRectF &real_rect) const
Stretch the rectangle to the left limit of the viewport.
QPainterPath displayPath(QPainterPath real_path) const
modify the path for display according to the scene adapter
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
The mouse press event.
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
The mouse release event.
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override
The hoover exit event.
void advance(int phase) override
Advance method used by the scene adapter.
ModelView::SceneAdapterInterface * sceneAdapter() const
Get the conversion axes.
void stretchRight(bool choice)
Stretch the rectangle to the right limit of the viewport.
void stretchLeft(bool choice)
Stretch the rectangle to the left limit of the viewport.
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override
The hoover enter event.
QRectF displayRectEdgeBased(const QRectF &real_rect) const
Helper function for displayRect based on the edge of real_rect.
QRectF displayRect(const QRectF &real_rect) const
modify the rectangle for display according to the scene adapter
void adaptY(bool choice)
Adapt the y position.
void adaptX(bool choice)
Adapt the x position.
QRectF displayRectCenterBased(const QRectF &real_rect) const
Helper function for displayRect based on the center of real_rect.
void adaptW(bool choice)
Adapt the width.
QRectF stretchRectRight(const QRectF &real_rect) const
Stretch the rectangle to the right limit of the viewport.
void adaptH(bool choice)
Adapt the height.
ElementView()
The constructor.
Custom graphics scene to show QCustomPlot with additional elements on top.
ModelView::SceneAdapterInterface * sceneAdapter() const
Return the pointer of the scene adapter on request.
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.