2 #include "GraphicsItemType.h"
3 #include "GraphicsView.h"
4 #include "LoadFileInfo.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 (
"Main Window\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.\n\n"
52 "Zooming the image in or out is performed using any of several methods:\n"
53 "1) rotating the mouse wheel when the cursor is outside of the image\n"
54 "2) pressing the minus or plus keys\n"
55 "3) selecting a new zoom setting from the View/Zoom menu"));
58 GraphicsView::~GraphicsView()
64 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::contextMenuEvent";
66 QList<QGraphicsItem*> items = scene()->selectedItems ();
68 if (items.count () == 1) {
70 QGraphicsItem *item = items.first ();
71 QString pointIdentifier = item->data (DATA_KEY_IDENTIFIER).toString ();
72 GraphicsItemType type = (GraphicsItemType) item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt ();
75 if ((type == GRAPHICS_ITEM_TYPE_POINT) &&
76 (curveName == AXIS_CURVE_NAME)) {
86 QGraphicsView::contextMenuEvent (event);
91 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dragEnterEvent " << (
event->mimeData ()->hasUrls () ?
"urls" :
"non-urls");
93 if (event->mimeData ()->hasImage () ||
94 event->mimeData ()->hasUrls ()) {
95 event->acceptProposedAction();
101 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dragMoveEvent";
103 if (event->mimeData ()->hasImage () ||
104 event->mimeData ()->hasUrls ()) {
105 event->acceptProposedAction();
111 const QString MIME_FORMAT_TEXT_PLAIN (
"text/plain");
114 QList<QUrl> urlList =
event->mimeData ()->urls ();
116 QTextStream str (&urls);
117 QList<QUrl>::const_iterator itr;
118 for (itr = urlList.begin (); itr != urlList.end (); itr++) {
120 str <<
" url=" << url.toString () <<
" ";
123 QString textPlain (event->mimeData()->data (MIME_FORMAT_TEXT_PLAIN));
125 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dropEvent"
126 <<
" formats=(" <<
event->mimeData()->formats().join (
", ").toLatin1().data() <<
")"
127 <<
" hasUrls=" << (
event->mimeData()->hasUrls() ?
"yes" :
"no")
128 <<
" urlCount=" << urlList.count()
129 <<
" urls=(" << urls.toLatin1().data() <<
")"
130 <<
" text=" << textPlain.toLatin1().data()
131 <<
" hasImage=" << (
event->mimeData()->hasImage() ?
"yes" :
"no");
136 LOG4CPP_INFO_S ((*mainCat)) <<
"QGraphicsView::dropEvent dig file";
137 QUrl url (textPlain);
139 event->acceptProposedAction();
141 }
else if (event->mimeData ()->hasImage ()) {
144 QImage image = qvariant_cast<QImage> (
event->mimeData ()->imageData ());
145 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dropEvent image";
148 }
else if (event->mimeData ()->hasUrls () &&
149 urlList.count () > 0) {
153 QUrl url = urlList.at(0);
154 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dropEvent url=" << url.toString ().toLatin1 ().data ();
156 event->acceptProposedAction();
160 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dropEvent dropped";
161 QGraphicsView::dropEvent (event);
166 bool GraphicsView::inBounds (
const QPointF &posScreen)
168 QRectF boundingRect = scene()->sceneRect();
170 return 0 <= posScreen.x () &&
171 0 <= posScreen.y () &&
172 posScreen.x () < boundingRect.width() &&
173 posScreen.y () < boundingRect.height();
178 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsView::keyPressEvent";
181 Qt::Key key = (Qt::Key) event->key();
183 bool atLeastOneSelectedItem = (scene ()->selectedItems ().count () > 0);
185 if (key == Qt::Key_Down ||
186 key == Qt::Key_Left ||
187 key == Qt::Key_Right ||
195 QGraphicsView::keyPressEvent (event);
202 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsView::leaveEvent";
206 QGraphicsView::leaveEvent (event);
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)) {
236 posScreen = QPointF (-1.0, -1.0);
241 QGraphicsView::mousePressEvent (event);
246 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsView::mouseReleaseEvent signalMouseRelease";
248 QPointF posScreen = mapToScene (event->pos ());
250 if (!inBounds (posScreen)) {
253 posScreen = QPointF (-1.0, -1.0);
259 int bitFlag = (
event->buttons () & Qt::RightButton);
260 bool isRightClick = (bitFlag != 0);
269 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...
Returns information about files.
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.
bool loadsAsDigFile(const QString &urlString) const
Returns true if specified file name can be loaded as a DIG file.
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.