QGraphicsView class with event handling added. Typically the events are sent to the active digitizing state.
More...
#include <GraphicsView.h>
|
| | GraphicsView (QGraphicsScene *scene, MainWindow &mainWindow) |
| | Single constructor. More...
|
| |
| virtual | ~GraphicsView () |
| |
| virtual void | contextMenuEvent (QContextMenuEvent *event) |
| | Intercept context event to support point editing. More...
|
| |
| virtual void | dragEnterEvent (QDragEnterEvent *event) |
| | Intercept mouse drag event to support drag-and-drop. More...
|
| |
| virtual void | dragMoveEvent (QDragMoveEvent *event) |
| | Intercept mouse move event to support drag-and-drop. More...
|
| |
| virtual void | dropEvent (QDropEvent *event) |
| | Intercept mouse drop event to support drag-and-drop. This initiates asynchronous loading of the dragged image. More...
|
| |
| virtual void | keyPressEvent (QKeyEvent *event) |
| | Intercept key press events to handle left/right/up/down moving. More...
|
| |
| virtual void | mouseMoveEvent (QMouseEvent *event) |
| | Intercept mouse move events to populate the current cursor position in StatusBar. More...
|
| |
| virtual void | mousePressEvent (QMouseEvent *event) |
| | Intercept mouse press events to create one or more Points. More...
|
| |
| virtual void | mouseReleaseEvent (QMouseEvent *event) |
| | Intercept mouse release events to move one or more Points. More...
|
| |
| virtual void | wheelEvent (QWheelEvent *event) |
| | Convert wheel events into zoom in/out. More...
|
| |
QGraphicsView class with event handling added. Typically the events are sent to the active digitizing state.
Definition at line 19 of file GraphicsView.h.
◆ GraphicsView()
| GraphicsView::GraphicsView |
( |
QGraphicsScene * |
scene, |
|
|
MainWindow & |
mainWindow |
|
) |
| |
Single constructor.
Definition at line 30 of file GraphicsView.cpp.
36 connect (
this, SIGNAL (
signalDraggedDigFile (QString)), &mainWindow, SLOT (slotFileOpenDraggedDigFile (QString)));
37 connect (
this, SIGNAL (
signalDraggedImage (QImage)), &mainWindow, SLOT (slotFileImportDraggedImage (QImage)));
38 connect (
this, SIGNAL (
signalDraggedImageUrl (QUrl)), &mainWindow, SLOT (slotFileImportDraggedImageUrl (QUrl)));
39 connect (
this, SIGNAL (
signalKeyPress (Qt::Key,
bool)), &mainWindow, SLOT (slotKeyPress (Qt::Key,
bool)));
40 connect (
this, SIGNAL (
signalMouseMove(QPointF)), &mainWindow, SLOT (slotMouseMove (QPointF)));
41 connect (
this, SIGNAL (
signalMousePress (QPointF)), &mainWindow, SLOT (slotMousePress (QPointF)));
42 connect (
this, SIGNAL (
signalMouseRelease (QPointF)), &mainWindow, SLOT (slotMouseRelease (QPointF)));
43 connect (
this, SIGNAL (
signalViewZoomIn ()), &mainWindow, SLOT (slotViewZoomInFromWheelEvent ()));
44 connect (
this, SIGNAL (
signalViewZoomOut ()), &mainWindow, SLOT (slotViewZoomOutFromWheelEvent ()));
46 setMouseTracking (
true);
47 setAcceptDrops (
true);
49 setRenderHints(QPainter::Antialiasing);
50 setBackgroundBrush (QBrush (QColor (Qt::gray)));
51 verticalScrollBar()->setCursor (QCursor (Qt::ArrowCursor));
52 horizontalScrollBar()->setCursor (QCursor (Qt::ArrowCursor));
55 setWhatsThis (tr (
"Main Window\n\n"
56 "After an image file is imported, or an Engauge Document opened, an image appears in this area. "
57 "Points are added to the image.\n\n"
58 "If the image is a graph with two axes and one or more curves, then three axis points must be "
59 "created along those axes. Just put two axis points on one axis and a third axis point on the other "
60 "axis, as far apart as possible for higher accuracy. Then curve points can be added along the curves.\n\n"
61 "If the image is a map with a scale to define length, then two axis points must be "
62 "created at either end of the scale. Then curve points can be added.\n\n"
63 "Zooming the image in or out is performed using any of several methods:\n"
64 "1) rotating the mouse wheel when the cursor is outside of the image\n"
65 "2) pressing the minus or plus keys\n"
66 "3) selecting a new zoom setting from the View/Zoom menu"));
◆ ~GraphicsView()
| GraphicsView::~GraphicsView |
( |
| ) |
|
|
virtual |
◆ contextMenuEvent()
| void GraphicsView::contextMenuEvent |
( |
QContextMenuEvent * |
event | ) |
|
|
virtual |
Intercept context event to support point editing.
Definition at line 73 of file GraphicsView.cpp.
76 <<
" selectedCount=" << scene()->selectedItems().count();
79 const QList<QGraphicsItem*> &items = scene()->selectedItems();
82 if (pointIdentifiers.count() > 0) {
99 QGraphicsView::contextMenuEvent (event);
◆ dragEnterEvent()
| void GraphicsView::dragEnterEvent |
( |
QDragEnterEvent * |
event | ) |
|
|
virtual |
Intercept mouse drag event to support drag-and-drop.
Definition at line 102 of file GraphicsView.cpp.
104 LOG4CPP_INFO_S ((*
mainCat)) <<
"GraphicsView::dragEnterEvent " << (
event->mimeData ()->hasUrls () ?
"urls" :
"non-urls");
106 if (event->mimeData ()->hasImage () ||
107 event->mimeData ()->hasUrls ()) {
108 event->acceptProposedAction();
◆ dragMoveEvent()
| void GraphicsView::dragMoveEvent |
( |
QDragMoveEvent * |
event | ) |
|
|
virtual |
Intercept mouse move event to support drag-and-drop.
Definition at line 112 of file GraphicsView.cpp.
116 if (event->mimeData ()->hasImage () ||
117 event->mimeData ()->hasUrls ()) {
118 event->acceptProposedAction();
◆ dropEvent()
| void GraphicsView::dropEvent |
( |
QDropEvent * |
event | ) |
|
|
virtual |
Intercept mouse drop event to support drag-and-drop. This initiates asynchronous loading of the dragged image.
Definition at line 122 of file GraphicsView.cpp.
127 QList<QUrl> urlList =
event->mimeData ()->urls ();
129 const QString MIME_FORMAT_TEXT_PLAIN (
"text/plain");
130 QString textPlain (event->mimeData()->data (MIME_FORMAT_TEXT_PLAIN));
133 if (event->mimeData ()->hasUrls () &&
134 urlList.count () > 0) {
135 urlFirst = urlList.at (0);
139 if (event->mimeData()->hasImage()) {
140 image = qvariant_cast<QImage> (event->mimeData ()->imageData ());
143 if (handleDropEvent (textPlain,
144 event->mimeData ()->hasUrls (),
146 event->mimeData ()->hasImage (),
149 event->acceptProposedAction();
154 QGraphicsView::dropEvent (event);
◆ keyPressEvent()
| void GraphicsView::keyPressEvent |
( |
QKeyEvent * |
event | ) |
|
|
virtual |
Intercept key press events to handle left/right/up/down moving.
Definition at line 203 of file GraphicsView.cpp.
208 Qt::Key key = static_cast<Qt::Key> (event->key());
210 bool atLeastOneSelectedItem = (scene ()->selectedItems ().count () > 0);
212 if (key == Qt::Key_Down ||
213 key == Qt::Key_Left ||
214 key == Qt::Key_Right ||
222 QGraphicsView::keyPressEvent (event);
◆ mouseMoveEvent()
| void GraphicsView::mouseMoveEvent |
( |
QMouseEvent * |
event | ) |
|
|
virtual |
Intercept mouse move events to populate the current cursor position in StatusBar.
Definition at line 227 of file GraphicsView.cpp.
232 QPointF posScreen = mapToScene (event->pos ());
234 if (!inBounds (posScreen)) {
237 posScreen = QPointF (-1.0, -1.0);
242 QGraphicsView::mouseMoveEvent (event);
◆ mousePressEvent()
| void GraphicsView::mousePressEvent |
( |
QMouseEvent * |
event | ) |
|
|
virtual |
Intercept mouse press events to create one or more Points.
Definition at line 245 of file GraphicsView.cpp.
249 QPointF posScreen = mapToScene (event->pos ());
251 if (!inBounds (posScreen)) {
254 posScreen = QPointF (-1.0, -1.0);
259 QGraphicsView::mousePressEvent (event);
◆ mouseReleaseEvent()
| void GraphicsView::mouseReleaseEvent |
( |
QMouseEvent * |
event | ) |
|
|
virtual |
Intercept mouse release events to move one or more Points.
Definition at line 262 of file GraphicsView.cpp.
266 QPointF posScreen = mapToScene (event->pos ());
268 if (!inBounds (posScreen)) {
271 posScreen = QPointF (-1.0, -1.0);
277 int bitFlag = (unsigned (event->buttons ()) & Qt::RightButton);
278 bool isRightClick = (bitFlag != 0);
286 QGraphicsView::mouseReleaseEvent (event);
◆ signalContextMenuEventAxis
| void GraphicsView::signalContextMenuEventAxis |
( |
QString |
pointIdentifier | ) |
|
|
signal |
Send right click on axis point to MainWindow for editing.
◆ signalContextMenuEventGraph
| void GraphicsView::signalContextMenuEventGraph |
( |
QStringList |
pointIdentifiers | ) |
|
|
signal |
Send right click on graph point(s) to MainWindow for editing.
◆ signalDraggedDigFile
| void GraphicsView::signalDraggedDigFile |
( |
QString |
| ) |
|
|
signal |
Send dragged dig file to MainWindow for import. This comes from dragging an engauge dig file.
◆ signalDraggedImage
| void GraphicsView::signalDraggedImage |
( |
QImage |
| ) |
|
|
signal |
Send dragged image to MainWindow for import. This typically comes from dragging a file.
◆ signalDraggedImageUrl
| void GraphicsView::signalDraggedImageUrl |
( |
QUrl |
| ) |
|
|
signal |
Send dragged url to MainWindow for import. This typically comes from dragging an image from a browser.
◆ signalKeyPress
| void GraphicsView::signalKeyPress |
( |
Qt::Key |
, |
|
|
bool |
atLeastOneSelectedItem |
|
) |
| |
|
signal |
◆ signalMouseMove
| void GraphicsView::signalMouseMove |
( |
QPointF |
| ) |
|
|
signal |
◆ signalMousePress
| void GraphicsView::signalMousePress |
( |
QPointF |
| ) |
|
|
signal |
Send mouse press to MainWindow for creating one or more Points.
◆ signalMouseRelease
| void GraphicsView::signalMouseRelease |
( |
QPointF |
| ) |
|
|
signal |
Send mouse release to MainWindow for moving Points.
◆ signalViewZoomIn
| void GraphicsView::signalViewZoomIn |
( |
| ) |
|
|
signal |
◆ signalViewZoomOut
| void GraphicsView::signalViewZoomOut |
( |
| ) |
|
|
signal |
◆ slotDropRegression
| void GraphicsView::slotDropRegression |
( |
QString |
urlText | ) |
|
|
slot |
Receive drag and drop regression test url.
Definition at line 309 of file GraphicsView.cpp.
312 QString emptyDigFileName;
315 if (!urlText.contains (
"http")) {
316 url = QUrl::fromLocalFile (urlText);
318 bool hasImage =
false;
321 handleDropEvent (emptyDigFileName,
◆ wheelEvent()
| void GraphicsView::wheelEvent |
( |
QWheelEvent * |
event | ) |
|
|
virtual |
Convert wheel events into zoom in/out.
Definition at line 328 of file GraphicsView.cpp.
330 const int ANGLE_THRESHOLD = 15;
331 const int DELTAS_PER_DEGREE = 8;
333 QPoint numDegrees =
event->angleDelta() / DELTAS_PER_DEGREE;
336 <<
" degrees=" << numDegrees.y()
337 <<
" phase=" <<
event->phase();
343 if ((event->modifiers() & Qt::ControlModifier) != 0) {
345 if (numDegrees.y() >= ANGLE_THRESHOLD) {
350 }
else if (numDegrees.y() <= -ANGLE_THRESHOLD) {
363 QGraphicsView::wheelEvent (event);
The documentation for this class was generated from the following files: