3 #include "GraphicsItemType.h"
4 #include "GraphicsView.h"
6 #include "MainWindow.h"
8 #include <QApplication>
11 #include <QGraphicsPixmapItem>
12 #include <QGraphicsPolygonItem>
13 #include <QGraphicsScene>
15 #include <QMouseEvent>
17 #include "QtToString.h"
19 extern const QString AXIS_CURVE_NAME;
25 connect (
this, SIGNAL (
signalContextMenuEvent (QString)), &mainWindow, SLOT (slotContextMenuEvent (QString)));
26 connect (
this, SIGNAL (
signalDraggedDigFile (QString)), &mainWindow, SLOT (slotFileOpenDraggedDigFile (QString)));
27 connect (
this, SIGNAL (
signalDraggedImage (QImage)), &mainWindow, SLOT (slotFileImportDraggedImage (QImage)));
28 connect (
this, SIGNAL (
signalDraggedImageUrl (QUrl)), &mainWindow, SLOT (slotFileImportDraggedImageUrl (QUrl)));
29 connect (
this, SIGNAL (
signalKeyPress (Qt::Key,
bool)), &mainWindow, SLOT (slotKeyPress (Qt::Key,
bool)));
30 connect (
this, SIGNAL (
signalLeave ()), &mainWindow, SLOT (slotLeave ()));
31 connect (
this, SIGNAL (
signalMouseMove(QPointF)), &mainWindow, SLOT (slotMouseMove (QPointF)));
32 connect (
this, SIGNAL (
signalMousePress (QPointF)), &mainWindow, SLOT (slotMousePress (QPointF)));
33 connect (
this, SIGNAL (
signalMouseRelease (QPointF)), &mainWindow, SLOT (slotMouseRelease (QPointF)));
35 setMouseTracking (
true);
36 setAcceptDrops (
true);
38 setRenderHints(QPainter::Antialiasing);
39 setBackgroundBrush (QBrush (QColor (Qt::gray)));
40 verticalScrollBar()->setCursor (QCursor (Qt::ArrowCursor));
41 horizontalScrollBar()->setCursor (QCursor (Qt::ArrowCursor));
44 setWhatsThis (tr (
"Document\n\n"
45 "After an image file is imported, or an Engauge Document opened, an image appears in this area. "
46 "Points are added to the image.\n\n"
47 "If the image is a graph with two axes and one or more curves, then three axis points must be "
48 "created along those axes. Just put two axis points on one axis and a third axis point on the other "
49 "axis, as far apart as possible for higher accuracy. Then curve points can be added along the curves.\n\n"
50 "If the image is a map with a scale to define length, then two axis points must be "
51 "created at either end of the scale. Then curve points can be added."));
54 GraphicsView::~GraphicsView()
60 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::contextMenuEvent";
62 QList<QGraphicsItem*> items = scene()->selectedItems ();
64 if (items.count () == 1) {
66 QGraphicsItem *item = items.first ();
67 QString pointIdentifier = item->data (DATA_KEY_IDENTIFIER).toString ();
68 GraphicsItemType type = (GraphicsItemType) item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt ();
71 if ((type == GRAPHICS_ITEM_TYPE_POINT) &&
72 (curveName == AXIS_CURVE_NAME)) {
82 QGraphicsView::contextMenuEvent (event);
87 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dragEnterEvent " << (
event->mimeData ()->hasUrls () ?
"urls" :
"non-urls");
89 if (event->mimeData ()->hasImage () ||
90 event->mimeData ()->hasUrls ()) {
91 event->acceptProposedAction();
97 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dragMoveEvent";
99 if (event->mimeData ()->hasImage () ||
100 event->mimeData ()->hasUrls ()) {
101 event->acceptProposedAction();
107 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dropEvent"
108 <<
" formats=" <<
event->mimeData()->formats().join (
", ").toLatin1().data();
110 const QString MIME_FORMAT_TEXT_PLAIN (
"text/plain");
115 QList<QUrl> urlList =
event->mimeData ()->urls ();
117 QTextStream str (&urls);
118 QList<QUrl>::const_iterator itr;
119 for (itr = urlList.begin (); itr != urlList.end (); itr++) {
121 str <<
" url=" << url.toString () <<
" ";
124 if (loadsAsDigFile (event->mimeData()->data (MIME_FORMAT_TEXT_PLAIN))) {
126 LOG4CPP_INFO_S ((*mainCat)) <<
"QGraphicsView::dropEvent dig file";
127 QUrl url (event->mimeData()->data(MIME_FORMAT_TEXT_PLAIN));
129 event->acceptProposedAction();
131 }
else if (event->mimeData ()->hasImage ()) {
134 QImage image = qvariant_cast<QImage> (
event->mimeData ()->imageData ());
135 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dropEvent image";
138 }
else if (event->mimeData ()->hasUrls () &&
139 event->mimeData ()->urls().count () > 0) {
143 QUrl url = urlList.at(0);
144 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dropEvent url=" << url.toString ().toLatin1 ().data ();
146 event->acceptProposedAction();
150 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dropEvent dropped";
151 QGraphicsView::dropEvent (event);
156 bool GraphicsView::inBounds (
const QPointF &posScreen)
158 QRectF boundingRect = scene()->sceneRect();
160 return 0 <= posScreen.x () &&
161 0 <= posScreen.y () &&
162 posScreen.x () < boundingRect.width() &&
163 posScreen.y () < boundingRect.height();
168 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsView::keyPressEvent";
171 Qt::Key key = (Qt::Key) event->key();
173 bool atLeastOneSelectedItem = (scene ()->selectedItems ().count () > 0);
175 if (key == Qt::Key_Down ||
176 key == Qt::Key_Left ||
177 key == Qt::Key_Right ||
185 QGraphicsView::keyPressEvent (event);
192 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsView::leaveEvent";
196 QGraphicsView::leaveEvent (event);
199 bool GraphicsView::loadsAsDigFile (
const QString &urlString)
const
201 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::loadsAsDigFile";
203 QUrl url (urlString);
204 Document document (url.toLocalFile());
214 QPointF posScreen = mapToScene (event->pos ());
216 if (!inBounds (posScreen)) {
219 posScreen = QPointF (-1.0, -1.0);
224 QGraphicsView::mouseMoveEvent (event);
229 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsView::mousePressEvent";
231 QPointF posScreen = mapToScene (event->pos ());
233 if (inBounds (posScreen)) {
239 QGraphicsView::mousePressEvent (event);
244 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsView::mouseReleaseEvent";
246 QPointF posScreen = mapToScene (event->pos ());
251 int bitFlag = (
event->buttons () & Qt::RightButton);
252 bool isRightClick = (bitFlag != 0);
254 if (inBounds (posScreen) &&
261 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.
bool successfulRead() const
Return true if startup loading succeeded. If the loading failed then reasonForUnsuccessfulRed will ex...
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.
Storage of one imported image and the data attached to that image.
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 signalDraggedDigFile(QString)
Send dragged dig file to MainWindow for import. This comes from dragging an engauge dig file...
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.