Geometrize  1.0
An application for geometrizing images into geometric primitives
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
Classes | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
geometrize::scene::ImageTaskGraphicsView Class Reference

The ImageTaskGraphicsView class models a graphics view for viewing the images and shapes used and/or produced by image tasks. More...

#include <imagetaskgraphicsview.h>

Inheritance diagram for geometrize::scene::ImageTaskGraphicsView:
Inheritance graph
[legend]
Collaboration diagram for geometrize::scene::ImageTaskGraphicsView:
Collaboration graph
[legend]

Classes

class  ImageTaskGraphicsViewImpl
 

Public Member Functions

 ImageTaskGraphicsView (QWidget *parent=nullptr)
 
virtual ~ImageTaskGraphicsView ()
 

Protected Member Functions

void changeEvent (QEvent *) override
 

Private Member Functions

void populateUi ()
 
bool viewportEvent (QEvent *event) override
 
void wheelEvent (QWheelEvent *event) override
 
void mousePressEvent (QMouseEvent *event) override
 
void mouseReleaseEvent (QMouseEvent *event) override
 
void mouseMoveEvent (QMouseEvent *event) override
 
void keyPressEvent (QKeyEvent *event) override
 
void keyReleaseEvent (QKeyEvent *event) override
 

Private Attributes

std::unique_ptr
< ImageTaskGraphicsViewImpl
d
 

Detailed Description

The ImageTaskGraphicsView class models a graphics view for viewing the images and shapes used and/or produced by image tasks.

Constructor & Destructor Documentation

geometrize::scene::ImageTaskGraphicsView::ImageTaskGraphicsView ( QWidget *  parent = nullptr)
explicit
90  : QGraphicsView(parent), d{std::make_unique<ImageTaskGraphicsViewImpl>(this)}
91 {
92  viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
93  setInteractive(true);
94  setMouseTracking(true);
95  setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
96  setDragMode(QGraphicsView::ScrollHandDrag);
97  setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
98 
99  populateUi();
100 }
void populateUi()
Definition: imagetaskgraphicsview.cpp:230
std::unique_ptr< ImageTaskGraphicsViewImpl > d
Definition: imagetaskgraphicsview.h:43

Here is the call graph for this function:

geometrize::scene::ImageTaskGraphicsView::~ImageTaskGraphicsView ( )
virtual
103 {
104 }

Member Function Documentation

void geometrize::scene::ImageTaskGraphicsView::changeEvent ( QEvent *  event)
overrideprotected
223 {
224  if (event->type() == QEvent::LanguageChange) {
225  populateUi();
226  }
227  QGraphicsView::changeEvent(event);
228 }
void populateUi()
Definition: imagetaskgraphicsview.cpp:230

Here is the call graph for this function:

void geometrize::scene::ImageTaskGraphicsView::keyPressEvent ( QKeyEvent *  event)
overrideprivate
213 {
214  QGraphicsView::keyPressEvent(event);
215 }
void geometrize::scene::ImageTaskGraphicsView::keyReleaseEvent ( QKeyEvent *  event)
overrideprivate
218 {
219  QGraphicsView::keyReleaseEvent(event);
220 }
void geometrize::scene::ImageTaskGraphicsView::mouseMoveEvent ( QMouseEvent *  event)
overrideprivate
208 {
209  QGraphicsView::mouseMoveEvent(event);
210 }
void geometrize::scene::ImageTaskGraphicsView::mousePressEvent ( QMouseEvent *  event)
overrideprivate
198 {
199  QGraphicsView::mousePressEvent(event);
200 }
void geometrize::scene::ImageTaskGraphicsView::mouseReleaseEvent ( QMouseEvent *  event)
overrideprivate
203 {
204  QGraphicsView::mouseReleaseEvent(event);
205 }
void geometrize::scene::ImageTaskGraphicsView::populateUi ( )
private
231 {
232 
233 }

Here is the caller graph for this function:

bool geometrize::scene::ImageTaskGraphicsView::viewportEvent ( QEvent *  event)
overrideprivate
107 {
108  switch(event->type()) {
109  case QEvent::TabletMove:
110  case QEvent::TabletPress:
111  case QEvent::TabletRelease:
112  case QEvent::TabletEnterProximity:
113  case QEvent::TabletLeaveProximity:
114  {
115  // Forward an event containing relevant tablet event data to the graphics scene
116  const auto customEventData = makeCustomTabletEventData(static_cast<QTabletEvent&>(*event), *this);
117  geometrize::scene::CustomTabletEvent customEvent(customEventData, this);
118  QCoreApplication::sendEvent(dynamic_cast<geometrize::scene::ImageTaskScene*>(scene()), &customEvent);
119  event->accept();
120  return true;
121  }
122  // TODO implement pinch-to-zoom
123  /*
124  case QEvent::TouchBegin:
125  case QEvent::TouchUpdate:
126  case QEvent::TouchEnd:
127  {
128  QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
129  QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
130  if (touchPoints.count() == 2) {
131  // determine scale factor
132  const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
133  const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();
134  qreal currentScaleFactor =
135  QLineF(touchPoint0.pos(), touchPoint1.pos()).length()
136  / QLineF(touchPoint0.startPos(), touchPoint1.startPos()).length();
137  if (touchEvent->touchPointStates() & Qt::TouchPointReleased) {
138  // if one of the fingers is released, remember the current scale
139  // factor so that adding another finger later will continue zooming
140  // by adding new scale factor to the existing remembered value.
141  d->m_totalScaleFactor *= currentScaleFactor;
142  currentScaleFactor = 1;
143  }
144  setTransform(QTransform().scale(d->m_totalScaleFactor * currentScaleFactor,
145  d->m_totalScaleFactor * currentScaleFactor));
146  }
147  event->accept();
148  return true;
149  }
150  */
151  default:
152  break;
153  }
154  return QGraphicsView::viewportEvent(event);
155 }
The CustomTabletEvent class represents a tablet event (specifically from a Wacom Pro pen) that can be...
Definition: customtabletevent.h:87
void geometrize::scene::ImageTaskGraphicsView::wheelEvent ( QWheelEvent *  event)
overrideprivate
158 {
159  if(e->modifiers() & Qt::ControlModifier) {
160  // Pass down to scene/children in scene if control is pressed
161  QGraphicsView::wheelEvent(e);
162  return;
163  }
164 
165  // Handle zooming
166  if (e->angleDelta().x() == 0) {
167  const QPoint pos{e->pos()};
168  const QPointF posf{mapToScene(pos)};
169 
170  const double angle{static_cast<double>(e->angleDelta().y())};
171  double by{0.0};
172  if(angle > 0) {
173  by = 1 + (angle / 360 * 0.1);
174  } else if (angle < 0) {
175  by = 1 - (-angle / 360 * 0.1);
176  } else {
177  by = 1;
178  }
179 
180  scale(by, by);
181 
182  const int w{viewport()->width()};
183  const int h{viewport()->height()};
184  const double wf{mapToScene(QPoint(w - 1, 0)).x() -mapToScene(QPoint(0,0)).x()};
185  const double hf{mapToScene(QPoint(0, h - 1)).y() - mapToScene(QPoint(0,0)).y()};
186  const double lf{posf.x() - pos.x() * wf / w};
187  const double tf{posf.y() - pos.y() * hf / h};
188 
189  ensureVisible(lf, tf, wf, hf, 0, 0);
190  const QPointF newPos{mapToScene(pos)};
191  ensureVisible(QRectF(QPointF(lf, tf) - newPos + posf, QSizeF(wf, hf)), 0, 0);
192 
193  e->accept();
194  }
195 }

Member Data Documentation

std::unique_ptr<ImageTaskGraphicsViewImpl> geometrize::scene::ImageTaskGraphicsView::d
private

The documentation for this class was generated from the following files: