18 #include <QGraphicsScene>
21 #include <QWheelEvent>
24 const double min_zoom_value = 1.0;
25 const double max_zoom_value = 5.0;
26 const double zoom_step = 0.05;
30 : QGraphicsView(scene, parent), m_current_zoom_value(1.0)
32 setObjectName(
"MaskGraphicsView");
33 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
34 setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
35 setStyleSheet(
"QGraphicsView { border-style: none; }");
36 setMouseTracking(
true);
49 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
50 centerOn(mapToScene(event->position().toPoint()));
52 centerOn(mapToScene(event->pos()));
54 if (event->angleDelta().y() > 0) {
59 if (horizontalScrollBar()->isVisible() || verticalScrollBar()->isVisible())
63 QGraphicsView::wheelEvent(event);
70 QWidget::resizeEvent(event);
83 switch (event->key()) {
87 if (!event->isAutoRepeat()) {
97 case Qt::Key_Backspace:
101 QWidget::keyPressEvent(event);
107 switch (event->key()) {
109 if (!event->isAutoRepeat()) {
114 QWidget::keyPressEvent(event);
120 if (event->modifiers().testFlag(Qt::ControlModifier)) {
136 const QTransform oldMatrix = transform();
138 translate(oldMatrix.dx(), oldMatrix.dy());
139 scale(zoom_value, zoom_value);
146 if (zoom_value < min_zoom_value)
147 zoom_value = min_zoom_value;
154 if (zoom_value > max_zoom_value)
155 zoom_value = max_zoom_value;
161 for (QGraphicsItem* graphicsItem : scene()->items()) {
163 proxy->resize(newSize);
164 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()
MaskGraphicsView(QGraphicsScene *scene, QWidget *parent=0)
void changeActivityRequest(MaskEditorFlags::Activity)
void wheelEvent(QWheelEvent *event)
void setZoomValue(double zoom_value)
double m_current_zoom_value
void updateSize(const QSize &newSize)
bool isControlButtonIsPressed(QWheelEvent *event)
void keyPressEvent(QKeyEvent *event)
void resizeEvent(QResizeEvent *event)
On resize event changes scene size and MaskGraphicsProxy so they would get the size of viewport.
void cancelCurrentDrawing()
void deleteSelectedRequest()
void keyReleaseEvent(QKeyEvent *event)
void onResetViewRequest()
Reset given view to original zoom state. Also asks graphics scene to do the same with color map.