8 #include "GraphicsItemType.h" 9 #include "GraphicsView.h" 10 #include "LoadFileInfo.h" 12 #include "MainWindow.h" 14 #include <QApplication> 17 #include <QGraphicsPixmapItem> 18 #include <QGraphicsPolygonItem> 19 #include <QGraphicsScene> 21 #include <QMouseEvent> 23 #include "QtToString.h" 25 extern const QString AXIS_CURVE_NAME;
31 connect (
this, SIGNAL (
signalContextMenuEvent (QString)), &mainWindow, SLOT (slotContextMenuEvent (QString)));
32 connect (
this, SIGNAL (
signalDraggedDigFile (QString)), &mainWindow, SLOT (slotFileOpenDraggedDigFile (QString)));
33 connect (
this, SIGNAL (
signalDraggedImage (QImage)), &mainWindow, SLOT (slotFileImportDraggedImage (QImage)));
34 connect (
this, SIGNAL (
signalDraggedImageUrl (QUrl)), &mainWindow, SLOT (slotFileImportDraggedImageUrl (QUrl)));
35 connect (
this, SIGNAL (
signalKeyPress (Qt::Key,
bool)), &mainWindow, SLOT (slotKeyPress (Qt::Key,
bool)));
36 connect (
this, SIGNAL (
signalLeave ()), &mainWindow, SLOT (slotLeave ()));
37 connect (
this, SIGNAL (
signalMouseMove(QPointF)), &mainWindow, SLOT (slotMouseMove (QPointF)));
38 connect (
this, SIGNAL (
signalMousePress (QPointF)), &mainWindow, SLOT (slotMousePress (QPointF)));
39 connect (
this, SIGNAL (
signalMouseRelease (QPointF)), &mainWindow, SLOT (slotMouseRelease (QPointF)));
40 connect (
this, SIGNAL (
signalViewZoomIn ()), &mainWindow, SLOT (slotViewZoomInFromWheelEvent ()));
41 connect (
this, SIGNAL (
signalViewZoomOut ()), &mainWindow, SLOT (slotViewZoomOutFromWheelEvent ()));
43 setMouseTracking (
true);
44 setAcceptDrops (
true);
46 setRenderHints(QPainter::Antialiasing);
47 setBackgroundBrush (QBrush (QColor (Qt::gray)));
48 verticalScrollBar()->setCursor (QCursor (Qt::ArrowCursor));
49 horizontalScrollBar()->setCursor (QCursor (Qt::ArrowCursor));
52 setWhatsThis (tr (
"Main Window\n\n" 53 "After an image file is imported, or an Engauge Document opened, an image appears in this area. " 54 "Points are added to the image.\n\n" 55 "If the image is a graph with two axes and one or more curves, then three axis points must be " 56 "created along those axes. Just put two axis points on one axis and a third axis point on the other " 57 "axis, as far apart as possible for higher accuracy. Then curve points can be added along the curves.\n\n" 58 "If the image is a map with a scale to define length, then two axis points must be " 59 "created at either end of the scale. Then curve points can be added.\n\n" 60 "Zooming the image in or out is performed using any of several methods:\n" 61 "1) rotating the mouse wheel when the cursor is outside of the image\n" 62 "2) pressing the minus or plus keys\n" 63 "3) selecting a new zoom setting from the View/Zoom menu"));
66 GraphicsView::~GraphicsView()
72 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::contextMenuEvent";
74 QList<QGraphicsItem*> items = scene()->selectedItems ();
76 if (items.count () == 1) {
78 QGraphicsItem *item = items.first ();
79 QString pointIdentifier = item->data (DATA_KEY_IDENTIFIER).toString ();
80 GraphicsItemType type = (GraphicsItemType) item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt ();
83 if ((type == GRAPHICS_ITEM_TYPE_POINT) &&
84 (curveName == AXIS_CURVE_NAME)) {
94 QGraphicsView::contextMenuEvent (event);
99 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dragEnterEvent " << (
event->mimeData ()->hasUrls () ?
"urls" :
"non-urls");
101 if (event->mimeData ()->hasImage () ||
102 event->mimeData ()->hasUrls ()) {
103 event->acceptProposedAction();
109 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dragMoveEvent";
111 if (event->mimeData ()->hasImage () ||
112 event->mimeData ()->hasUrls ()) {
113 event->acceptProposedAction();
119 const QString MIME_FORMAT_TEXT_PLAIN (
"text/plain");
122 QList<QUrl> urlList =
event->mimeData ()->urls ();
124 QTextStream str (&urls);
125 QList<QUrl>::const_iterator itr;
126 for (itr = urlList.begin (); itr != urlList.end (); itr++) {
128 str <<
" url=" << url.toString () <<
" ";
131 QString textPlain (event->mimeData()->data (MIME_FORMAT_TEXT_PLAIN));
133 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dropEvent" 134 <<
" formats=(" <<
event->mimeData()->formats().join (
", ").toLatin1().data() <<
")" 135 <<
" hasUrls=" << (
event->mimeData()->hasUrls() ?
"yes" :
"no")
136 <<
" urlCount=" << urlList.count()
137 <<
" urls=(" << urls.toLatin1().data() <<
")" 138 <<
" text=" << textPlain.toLatin1().data()
139 <<
" hasImage=" << (
event->mimeData()->hasImage() ?
"yes" :
"no");
144 LOG4CPP_INFO_S ((*mainCat)) <<
"QGraphicsView::dropEvent dig file";
145 QUrl url (textPlain);
147 event->acceptProposedAction();
149 }
else if (event->mimeData ()->hasImage ()) {
152 QImage image = qvariant_cast<QImage> (
event->mimeData ()->imageData ());
153 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dropEvent image";
156 }
else if (event->mimeData ()->hasUrls () &&
157 urlList.count () > 0) {
161 QUrl url = urlList.at(0);
162 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dropEvent url=" << url.toString ().toLatin1 ().data ();
164 event->acceptProposedAction();
168 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsView::dropEvent dropped";
169 QGraphicsView::dropEvent (event);
174 bool GraphicsView::inBounds (
const QPointF &posScreen)
176 QRectF boundingRect = scene()->sceneRect();
178 return 0 <= posScreen.x () &&
179 0 <= posScreen.y () &&
180 posScreen.x () < boundingRect.width() &&
181 posScreen.y () < boundingRect.height();
186 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsView::keyPressEvent";
189 Qt::Key key = (Qt::Key) event->key();
191 bool atLeastOneSelectedItem = (scene ()->selectedItems ().count () > 0);
193 if (key == Qt::Key_Down ||
194 key == Qt::Key_Left ||
195 key == Qt::Key_Right ||
203 QGraphicsView::keyPressEvent (event);
210 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsView::leaveEvent";
214 QGraphicsView::leaveEvent (event);
222 QPointF posScreen = mapToScene (event->pos ());
224 if (!inBounds (posScreen)) {
227 posScreen = QPointF (-1.0, -1.0);
232 QGraphicsView::mouseMoveEvent (event);
237 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsView::mousePressEvent";
239 QPointF posScreen = mapToScene (event->pos ());
241 if (!inBounds (posScreen)) {
244 posScreen = QPointF (-1.0, -1.0);
249 QGraphicsView::mousePressEvent (event);
254 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsView::mouseReleaseEvent signalMouseRelease";
256 QPointF posScreen = mapToScene (event->pos ());
258 if (!inBounds (posScreen)) {
261 posScreen = QPointF (-1.0, -1.0);
267 int bitFlag = (
event->buttons () & Qt::RightButton);
268 bool isRightClick = (bitFlag != 0);
277 QGraphicsView::mouseReleaseEvent (event);
282 const int ANGLE_THRESHOLD = 15;
283 const int DELTAS_PER_DEGREE = 8;
285 QPoint numDegrees =
event->angleDelta() / DELTAS_PER_DEGREE;
287 LOG4CPP_INFO_S ((*mainCat)) <<
"MainWindow::wheelEvent" 288 <<
" degrees=" << numDegrees.y()
289 <<
" phase=" <<
event->phase();
295 if ((event->modifiers() & Qt::ControlModifier) != 0) {
297 if (numDegrees.y() >= ANGLE_THRESHOLD) {
302 }
else if (numDegrees.y() <= -ANGLE_THRESHOLD) {
315 QGraphicsView::wheelEvent (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 wheelEvent(QWheelEvent *event)
Convert wheel events into zoom in/out.
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 signalViewZoomIn()
Send wheel event to MainWindow for zooming in.
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...
void signalViewZoomOut()
Send wheel event to MainWindow for zooming out.
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.