2 #include "GraphicsItemType.h"
3 #include "GraphicsView.h"
5 #include "MainWindow.h"
7 #include <QApplication>
9 #include <QGraphicsPixmapItem>
10 #include <QGraphicsPolygonItem>
11 #include <QGraphicsScene>
13 #include <QMouseEvent>
15 #include "QtToString.h"
17 extern const QString AXIS_CURVE_NAME;
23 connect (
this, SIGNAL (
signalContextMenuEvent (QString)), &mainWindow, SLOT (slotContextMenuEvent (QString)));
24 connect (
this, SIGNAL (
signalDraggedImage (QImage)), &mainWindow, SLOT (slotFileImportDraggedImage (QImage)));
25 connect (
this, SIGNAL (
signalDraggedImageUrl (QUrl)), &mainWindow, SLOT (slotFileImportDraggedImageUrl (QUrl)));
26 connect (
this, SIGNAL (
signalKeyPress (Qt::Key,
bool)), &mainWindow, SLOT (slotKeyPress (Qt::Key,
bool)));
27 connect (
this, SIGNAL (
signalLeave ()), &mainWindow, SLOT (slotLeave ()));
28 connect (
this, SIGNAL (
signalMouseMove(QPointF)), &mainWindow, SLOT (slotMouseMove (QPointF)));
29 connect (
this, SIGNAL (
signalMousePress (QPointF)), &mainWindow, SLOT (slotMousePress (QPointF)));
30 connect (
this, SIGNAL (
signalMouseRelease (QPointF)), &mainWindow, SLOT (slotMouseRelease (QPointF)));
32 setMouseTracking (
true);
33 setAcceptDrops (
true);
35 setRenderHints(QPainter::Antialiasing);
36 setBackgroundBrush (QBrush (QColor (Qt::gray)));
37 verticalScrollBar()->setCursor (QCursor (Qt::ArrowCursor));
38 horizontalScrollBar()->setCursor (QCursor (Qt::ArrowCursor));
41 setWhatsThis (tr (
"Document\n\n"
42 "After an image file is imported, or an Engauge Document opened, an image appears in this area. "
43 "Points are added to the image.\n\n"
44 "If the image is a graph with two axes and one or more curves, then three axis points must be "
45 "created along those axes. Just put two axis points on one axis and a third axis point on the other "
46 "axis, as far apart as possible for higher accuracy. Then curve points can be added along the curves.\n\n"
47 "If the image is a map with a scale to define length, then two axis points must be "
48 "created at either end of the scale. Then curve points can be added."));
51 GraphicsView::~GraphicsView()
57 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::contextMenuEvent";
59 QList<QGraphicsItem*> items = scene()->selectedItems ();
61 if (items.count () == 1) {
63 QGraphicsItem *item = items.first ();
64 QString pointIdentifier = item->data (DATA_KEY_IDENTIFIER).toString ();
65 GraphicsItemType type = (GraphicsItemType) item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt ();
68 if ((type == GRAPHICS_ITEM_TYPE_POINT) &&
69 (curveName == AXIS_CURVE_NAME)) {
79 QGraphicsView::contextMenuEvent (event);
84 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dragEnterEvent " << (
event->mimeData ()->hasUrls () ?
"urls" :
"non-urls");
86 if (event->mimeData ()->hasImage () ||
87 event->mimeData ()->hasUrls ()) {
88 event->acceptProposedAction();
94 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dragMoveEvent";
96 if (event->mimeData ()->hasImage () ||
97 event->mimeData ()->hasUrls ()) {
98 event->acceptProposedAction();
104 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dropEvent";
109 QList<QUrl> urlList =
event->mimeData ()->urls ();
111 QTextStream str (&urls);
112 QList<QUrl>::const_iterator itr;
113 for (itr = urlList.begin (); itr != urlList.end (); itr++) {
115 str <<
" url=" << url.toString () <<
" ";
118 if (event->mimeData ()->hasImage ()) {
121 QImage image = qvariant_cast<QImage> (
event->mimeData ()->imageData ());
122 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dropEvent image";
125 }
else if (event->mimeData ()->hasUrls ()) {
129 QUrl url = urlList.at(0);
130 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dropEvent url=" << url.toString ().toLatin1 ().data ();
132 event->acceptProposedAction();
136 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dropEvent dropped";
137 QGraphicsView::dropEvent (event);
142 bool GraphicsView::inBounds (
const QPointF &posScreen)
144 QRectF boundingRect = scene()->sceneRect();
146 return 0 <= posScreen.x () &&
147 0 <= posScreen.y () &&
148 posScreen.x () < boundingRect.width() &&
149 posScreen.y () < boundingRect.height();
154 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsView::keyPressEvent";
157 Qt::Key key = (Qt::Key) event->key();
159 bool atLeastOneSelectedItem = (scene ()->selectedItems ().count () > 0);
161 if (key == Qt::Key_Down ||
162 key == Qt::Key_Left ||
163 key == Qt::Key_Right ||
171 QGraphicsView::keyPressEvent (event);
178 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsView::leaveEvent";
182 QGraphicsView::leaveEvent (event);
190 QPointF posScreen = mapToScene (event->pos ());
192 if (!inBounds (posScreen)) {
195 posScreen = QPointF (-1.0, -1.0);
200 QGraphicsView::mouseMoveEvent (event);
205 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsView::mousePressEvent";
207 QPointF posScreen = mapToScene (event->pos ());
209 if (inBounds (posScreen)) {
215 QGraphicsView::mousePressEvent (event);
220 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsView::mouseReleaseEvent";
222 QPointF posScreen = mapToScene (event->pos ());
227 int bitFlag = (
event->buttons () & Qt::RightButton);
228 bool isRightClick = (bitFlag != 0);
230 if (inBounds (posScreen) &&
237 QGraphicsView::mouseReleaseEvent (event);
void signalMouseMove(QPointF)
Send mouse move to MainWindow for eventual display of cursor coordinates in StatusBar.
static QString curveNameFromPointIdentifier(const QString &pointIdentifier)
Parse the curve name from the specified point identifier. This does the opposite of uniqueIdentifierG...
virtual void keyPressEvent(QKeyEvent *event)
Intercept key press events to handle left/right/up/down moving.
virtual void dragMoveEvent(QDragMoveEvent *event)
Intercept mouse move event to support drag-and-drop.
virtual void dropEvent(QDropEvent *event)
Intercept mouse drop event to support drag-and-drop. This initiates asynchronous loading of the dragg...
void contextMenuEvent(QContextMenuEvent *event)
Intercept right click to support point editing.
virtual void mouseMoveEvent(QMouseEvent *event)
Intercept mouse move events to populate the current cursor position in StatusBar. ...
GraphicsView(QGraphicsScene *scene, MainWindow &mainWindow)
Single constructor.
void signalMousePress(QPointF)
Send mouse press to MainWindow for creating one or more Points.
void signalKeyPress(Qt::Key, bool atLeastOneSelectedItem)
Send keypress to MainWindow for eventual processing by DigitizeStateAbstractBase subclasses.
virtual void mousePressEvent(QMouseEvent *event)
Intercept mouse press events to create one or more Points.
void signalDraggedImage(QImage)
Send dragged image to MainWindow for import. This typically comes from dragging a file...
virtual void leaveEvent(QEvent *event)
Intercept leave events to manage override cursor.
void signalMouseRelease(QPointF)
Send mouse release to MainWindow for moving Points.
virtual void dragEnterEvent(QDragEnterEvent *event)
Intercept mouse drag event to support drag-and-drop.
virtual void mouseReleaseEvent(QMouseEvent *event)
Intercept mouse release events to move one or more Points.
void signalDraggedImageUrl(QUrl)
Send dragged url to MainWindow for import. This typically comes from dragging an image from a browser...
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
void signalLeave()
Send leave to MainWindow for managing the override cursor.
void signalContextMenuEvent(QString pointIdentifier)
Send right click on axis point to MainWindow for editing.