18 #include <QGraphicsScene>
21 #include <QWheelEvent>
25 const double min_zoom_value = 1.0;
26 const double max_zoom_value = 5.0;
27 const double zoom_step = 0.05;
32 : QGraphicsView(scene, parent)
33 , m_current_zoom_value(1.0)
35 setObjectName(
"MaskGraphicsView");
36 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
37 setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
38 setStyleSheet(
"QGraphicsView { border-style: none; }");
39 setMouseTracking(
true);
52 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
53 centerOn(mapToScene(event->position().toPoint()));
55 centerOn(mapToScene(event->pos()));
57 if (event->angleDelta().y() > 0) {
62 if (horizontalScrollBar()->isVisible() || verticalScrollBar()->isVisible())
66 QGraphicsView::wheelEvent(event);
73 QWidget::resizeEvent(event);
86 switch (event->key()) {
90 if (!event->isAutoRepeat())
97 case Qt::Key_Backspace:
101 QWidget::keyPressEvent(event);
107 switch (event->key()) {
109 if (!event->isAutoRepeat())
113 QWidget::keyPressEvent(event);
119 return event->modifiers().testFlag(Qt::ControlModifier);
132 const QTransform oldMatrix = transform();
134 translate(oldMatrix.dx(), oldMatrix.dy());
135 scale(zoom_value, zoom_value);
142 if (zoom_value < min_zoom_value)
143 zoom_value = min_zoom_value;
150 if (zoom_value > max_zoom_value)
151 zoom_value = max_zoom_value;
157 for (QGraphicsItem* graphicsItem : scene()->items()) {
159 proxy->resize(newSize);
160 scene()->setSceneRect(0, 0, newSize.width(), newSize.height());
Defines class MaskGraphicsProxy.
Defines class MaskGraphicsScene.
Defines class MaskGraphicsView.
Graphics proxy to place QWidget inside QGraphicsScene, used by MaskEditorCanvas.
Graphics scene for MaskEditorCanvas to draw masks on top of intensity data widgets.
void cancelCurrentDrawing()
void wheelEvent(QWheelEvent *event) override
void changeActivityRequest(MaskEditorFlags::Activity)
void setZoomValue(double zoom_value)
double m_current_zoom_value
void updateSize(const QSize &newSize)
void resizeEvent(QResizeEvent *event) override
On resize event changes scene size and MaskGraphicsProxy so they would get the size of viewport.
bool isControlButtonIsPressed(QWheelEvent *event)
MaskGraphicsView(QGraphicsScene *scene, QWidget *parent=nullptr)
void keyReleaseEvent(QKeyEvent *event) override
void cancelCurrentDrawing()
void deleteSelectedRequest()
void keyPressEvent(QKeyEvent *event) override
void onResetViewRequest()
Reset given view to original zoom state. Also asks graphics scene to do the same with color map.