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
113  : QGraphicsView(parent), d{std::make_unique<ImageTaskGraphicsViewImpl>(this)}
114 {
115  viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
116  setInteractive(true);
117  setMouseTracking(true);
118  setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
119  setDragMode(QGraphicsView::ScrollHandDrag);
120  setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
121 
122  populateUi();
123 }
void populateUi()
Definition: imagetaskgraphicsview.cpp:259
std::unique_ptr< ImageTaskGraphicsViewImpl > d
Definition: imagetaskgraphicsview.h:43

Here is the call graph for this function:

geometrize::scene::ImageTaskGraphicsView::~ImageTaskGraphicsView ( )
virtual
126 {
127 }

Member Function Documentation

void geometrize::scene::ImageTaskGraphicsView::changeEvent ( QEvent *  event)
overrideprotected
252 {
253  if (event->type() == QEvent::LanguageChange) {
254  populateUi();
255  }
256  QGraphicsView::changeEvent(event);
257 }
void populateUi()
Definition: imagetaskgraphicsview.cpp:259

Here is the call graph for this function:

void geometrize::scene::ImageTaskGraphicsView::keyPressEvent ( QKeyEvent *  event)
overrideprivate
242 {
243  QGraphicsView::keyPressEvent(event);
244 }
void geometrize::scene::ImageTaskGraphicsView::keyReleaseEvent ( QKeyEvent *  event)
overrideprivate
247 {
248  QGraphicsView::keyReleaseEvent(event);
249 }
void geometrize::scene::ImageTaskGraphicsView::mouseMoveEvent ( QMouseEvent *  event)
overrideprivate
237 {
238  QGraphicsView::mouseMoveEvent(event);
239 }
void geometrize::scene::ImageTaskGraphicsView::mousePressEvent ( QMouseEvent *  event)
overrideprivate
227 {
228  QGraphicsView::mousePressEvent(event);
229 }
void geometrize::scene::ImageTaskGraphicsView::mouseReleaseEvent ( QMouseEvent *  event)
overrideprivate
232 {
233  QGraphicsView::mouseReleaseEvent(event);
234 }
void geometrize::scene::ImageTaskGraphicsView::populateUi ( )
private
260 {
261 
262 }

Here is the caller graph for this function:

bool geometrize::scene::ImageTaskGraphicsView::viewportEvent ( QEvent *  event)
overrideprivate
130 {
131  switch(event->type()) {
132  case QEvent::TabletMove:
133  case QEvent::TabletPress:
134  case QEvent::TabletRelease:
135  case QEvent::TabletEnterProximity:
136  case QEvent::TabletLeaveProximity:
137  {
138  // Forward an event containing relevant tablet event data to the graphics scene
139  const auto customEventData = makeCustomTabletEventData(static_cast<QTabletEvent&>(*event), *this);
140  geometrize::scene::CustomTabletEvent customEvent(customEventData, this);
141  QCoreApplication::sendEvent(dynamic_cast<geometrize::scene::ImageTaskScene*>(scene()), &customEvent);
142  event->accept();
143  return true;
144  }
145  // TODO implement pinch-to-zoom
146  /*
147  case QEvent::TouchBegin:
148  case QEvent::TouchUpdate:
149  case QEvent::TouchEnd:
150  {
151  QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
152  QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
153  if (touchPoints.count() == 2) {
154  // determine scale factor
155  const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
156  const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();
157  qreal currentScaleFactor =
158  QLineF(touchPoint0.pos(), touchPoint1.pos()).length()
159  / QLineF(touchPoint0.startPos(), touchPoint1.startPos()).length();
160  if (touchEvent->touchPointStates() & Qt::TouchPointReleased) {
161  // if one of the fingers is released, remember the current scale
162  // factor so that adding another finger later will continue zooming
163  // by adding new scale factor to the existing remembered value.
164  d->m_totalScaleFactor *= currentScaleFactor;
165  currentScaleFactor = 1;
166  }
167  setTransform(QTransform().scale(d->m_totalScaleFactor * currentScaleFactor,
168  d->m_totalScaleFactor * currentScaleFactor));
169  }
170  event->accept();
171  return true;
172  }
173  */
174  default:
175  break;
176  }
177  return QGraphicsView::viewportEvent(event);
178 }
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
181 {
182  if(e->modifiers() & Qt::ControlModifier) {
183  // Pass down to scene/children in scene if control is pressed
184  QGraphicsView::wheelEvent(e);
185  return;
186  }
187 
188  // Handle zooming
189  if (e->angleDelta().x() == 0) {
190  #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
191  const QPointF pos{e->position()};
192  const QPointF posf{mapToScene(pos.toPoint())};
193  const QPointF newPos{mapToScene(pos.toPoint())};
194  #else
195  const QPoint pos{e->pos()};
196  const QPointF posf{mapToScene(pos)};
197  const QPointF newPos{mapToScene(pos)};
198  #endif
199 
200  const double angle{static_cast<double>(e->angleDelta().y())};
201  double by{0.0};
202  if(angle > 0) {
203  by = 1 + (angle / 360 * 0.1);
204  } else if (angle < 0) {
205  by = 1 - (-angle / 360 * 0.1);
206  } else {
207  by = 1;
208  }
209 
210  scale(by, by);
211 
212  const int w{viewport()->width()};
213  const int h{viewport()->height()};
214  const double wf{mapToScene(QPoint(w - 1, 0)).x() - mapToScene(QPoint(0,0)).x()};
215  const double hf{mapToScene(QPoint(0, h - 1)).y() - mapToScene(QPoint(0,0)).y()};
216  const double lf{posf.x() - pos.x() * wf / w};
217  const double tf{posf.y() - pos.y() * hf / h};
218 
219  ensureVisible(lf, tf, wf, hf, 0, 0);
220  ensureVisible(QRectF(QPointF(lf, tf) - newPos + posf, QSizeF(wf, hf)), 0, 0);
221 
222  e->accept();
223  }
224 }

Member Data Documentation

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

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