16#include <QApplication>
17#include <QContextMenuEvent>
20#include <QGraphicsPixmapItem>
21#include <QGraphicsPolygonItem>
22#include <QGraphicsScene>
37 connect (
this, SIGNAL (
signalDraggedDigFile (QString)), &mainWindow, SLOT (slotFileOpenDraggedDigFile (QString)));
38 connect (
this, SIGNAL (
signalDraggedImage (QImage)), &mainWindow, SLOT (slotFileImportDraggedImage (QImage)));
39 connect (
this, SIGNAL (
signalDraggedImageUrl (QUrl)), &mainWindow, SLOT (slotFileImportDraggedImageUrl (QUrl)));
40 connect (
this, SIGNAL (
signalKeyPress (Qt::Key,
bool)), &mainWindow, SLOT (slotKeyPress (Qt::Key,
bool)));
41 connect (
this, SIGNAL (
signalMouseMove(QPointF)), &mainWindow, SLOT (slotMouseMove (QPointF)));
42 connect (
this, SIGNAL (
signalMousePress (QPointF)), &mainWindow, SLOT (slotMousePress (QPointF)));
43 connect (
this, SIGNAL (
signalMouseRelease (QPointF)), &mainWindow, SLOT (slotMouseRelease (QPointF)));
44 connect (
this, SIGNAL (
signalViewZoomIn ()), &mainWindow, SLOT (slotViewZoomInFromWheelEvent ()));
45 connect (
this, SIGNAL (
signalViewZoomOut ()), &mainWindow, SLOT (slotViewZoomOutFromWheelEvent ()));
47 setMouseTracking (
true);
48 setAcceptDrops (
true);
50 setRenderHints(QPainter::Antialiasing);
51 setBackgroundBrush (QBrush (QColor (Qt::gray)));
52 verticalScrollBar()->setCursor (QCursor (Qt::ArrowCursor));
53 horizontalScrollBar()->setCursor (QCursor (Qt::ArrowCursor));
56 setWhatsThis (tr (
"Main Window\n\n"
57 "After an image file is imported, or an Engauge Document opened, an image appears in this area. "
58 "Points are added to the image.\n\n"
59 "If the image is a graph with two axes and one or more curves, then three axis points must be "
60 "created along those axes. Just put two axis points on one axis and a third axis point on the other "
61 "axis, as far apart as possible for higher accuracy. Then curve points can be added along the curves.\n\n"
62 "If the image is a map with a scale to define length, then two axis points must be "
63 "created at either end of the scale. Then curve points can be added.\n\n"
64 "Zooming the image in or out is performed using any of several methods:\n"
65 "1) rotating the mouse wheel when the cursor is outside of the image\n"
66 "2) pressing the minus or plus keys\n"
67 "3) selecting a new zoom setting from the View/Zoom menu"));
77 <<
" selectedCount=" << scene()->selectedItems().count();
80 const QList<QGraphicsItem*> &items = scene()->selectedItems();
83 if (pointIdentifiers.count() > 0) {
100 QGraphicsView::contextMenuEvent (event);
105 LOG4CPP_INFO_S ((*
mainCat)) <<
"GraphicsView::dragEnterEvent " << (
event->mimeData ()->hasUrls () ?
"urls" :
"non-urls");
107 if (event->mimeData ()->hasImage () ||
108 event->mimeData ()->hasUrls ()) {
109 event->acceptProposedAction();
117 if (event->mimeData ()->hasImage () ||
118 event->mimeData ()->hasUrls ()) {
119 event->acceptProposedAction();
128 QList<QUrl> urlList =
event->mimeData ()->urls ();
130 const QString MIME_FORMAT_TEXT_PLAIN (
"text/plain");
131 QString textPlain (event->mimeData()->data (MIME_FORMAT_TEXT_PLAIN));
134 if (event->mimeData ()->hasUrls () &&
135 urlList.count () > 0) {
136 urlFirst = urlList.at (0);
140 if (event->mimeData()->hasImage()) {
141 image = qvariant_cast<QImage> (event->mimeData ()->imageData ());
144 if (handleDropEvent (textPlain,
145 event->mimeData ()->hasUrls (),
147 event->mimeData ()->hasImage (),
150 event->acceptProposedAction();
155 QGraphicsView::dropEvent (event);
159bool GraphicsView::handleDropEvent (
const QString &possibleDigFileName,
161 const QUrl &urlFirst,
165 bool willAccept =
false;
176 }
else if (hasImage) {
186 LOG4CPP_INFO_S ((*
mainCat)) <<
"GraphicsView::handleDropEvent url=" << urlFirst.toString ().toLatin1 ().data ();
194bool GraphicsView::inBounds (
const QPointF &posScreen)
196 QRectF boundingRect = scene()->sceneRect();
198 return 0 <= posScreen.x () &&
199 0 <= posScreen.y () &&
200 posScreen.x () < boundingRect.width() &&
201 posScreen.y () < boundingRect.height();
209 Qt::Key key =
static_cast<Qt::Key
> (
event->key());
211 bool atLeastOneSelectedItem = (scene ()->selectedItems ().count () > 0);
215 if (key == Qt::Key_Down ||
216 key == Qt::Key_Left ||
217 key == Qt::Key_Right ||
219 key == Qt::Key_Escape ||
220 ((event->modifiers() & Qt::ControlModifier) && (key == Qt::Key_Z))) {
227 QGraphicsView::keyPressEvent (event);
237 QPointF posScreen = mapToScene (event->pos ());
239 if (!inBounds (posScreen)) {
242 posScreen = QPointF (-1.0, -1.0);
247 QGraphicsView::mouseMoveEvent (event);
254 QPointF posScreen = mapToScene (event->pos ());
256 if (!inBounds (posScreen)) {
259 posScreen = QPointF (-1.0, -1.0);
264 QGraphicsView::mousePressEvent (event);
271 QPointF posScreen = mapToScene (event->pos ());
273 if (!inBounds (posScreen)) {
276 posScreen = QPointF (-1.0, -1.0);
282 int bitFlag = (unsigned (event->buttons ()) & Qt::RightButton);
283 bool isRightClick = (bitFlag != 0);
291 QGraphicsView::mouseReleaseEvent (event);
294QStringList GraphicsView::pointIdentifiersFromSelection (
const QList<QGraphicsItem*> &items)
const
298 QStringList pointIdentifiers;
300 QList<QGraphicsItem*>::const_iterator itr;
301 for (itr = items.begin(); itr != items.end(); itr++) {
303 QGraphicsItem *item = *itr;
308 pointIdentifiers << pointIdentifier;
311 return pointIdentifiers;
317 QString emptyDigFileName;
320 if (!urlText.contains (
"http")) {
321 url = QUrl::fromLocalFile (urlText);
323 bool hasImage =
false;
326 handleDropEvent (emptyDigFileName,
335 const int ANGLE_THRESHOLD = 15;
336 const int DELTAS_PER_DEGREE = 8;
338 QPoint numDegrees =
event->angleDelta() / DELTAS_PER_DEGREE;
341 <<
" degrees=" << numDegrees.y()
342 <<
" phase=" <<
event->phase();
348 if ((event->modifiers() & Qt::ControlModifier) != 0) {
350 if (numDegrees.y() >= ANGLE_THRESHOLD) {
355 }
else if (numDegrees.y() <= -ANGLE_THRESHOLD) {
368 QGraphicsView::wheelEvent (event);
const QString AXIS_CURVE_NAME
@ DATA_KEY_GRAPHICS_ITEM_TYPE
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
GraphicsItemType
Runtime type identification (RTTI) for QGraphicsItem objects.
@ GRAPHICS_ITEM_TYPE_POINT
log4cpp::Category * mainCat
virtual void mouseReleaseEvent(QMouseEvent *event)
Intercept mouse release events to move one or more Points.
void signalDraggedImage(QImage)
Send dragged image to MainWindow for import. This typically comes from dragging a file.
virtual void wheelEvent(QWheelEvent *event)
Convert wheel events into zoom in/out.
virtual void dropEvent(QDropEvent *event)
Intercept mouse drop event to support drag-and-drop. This initiates asynchronous loading of the dragg...
void slotDropRegression(QString)
Receive drag and drop regression test url.
void signalKeyPress(Qt::Key, bool atLeastOneSelectedItem)
Send keypress to MainWindow for eventual processing by DigitizeStateAbstractBase subclasses.
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 keyPressEvent(QKeyEvent *event)
Intercept key press events to handle left/right/up/down moving.
void signalViewZoomOut()
Send wheel event to MainWindow for zooming out.
virtual void dragMoveEvent(QDragMoveEvent *event)
Intercept mouse move event to support drag-and-drop.
void signalDraggedDigFile(QString)
Send dragged dig file to MainWindow for import. This comes from dragging an engauge dig file.
virtual void mousePressEvent(QMouseEvent *event)
Intercept mouse press events to create one or more Points.
void signalContextMenuEventAxis(QString pointIdentifier)
Send right click on axis point to MainWindow for editing.
void signalViewZoomIn()
Send wheel event to MainWindow for zooming in.
GraphicsView(QGraphicsScene *scene, MainWindow &mainWindow)
Single constructor.
virtual void mouseMoveEvent(QMouseEvent *event)
Intercept mouse move events to populate the current cursor position in StatusBar.
void signalMousePress(QPointF)
Send mouse press to MainWindow for creating 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 signalContextMenuEventGraph(QStringList pointIdentifiers)
Send right click on graph point(s) to MainWindow for editing.
void signalMouseMove(QPointF)
Send mouse move to MainWindow for eventual display of cursor coordinates in StatusBar.
virtual void contextMenuEvent(QContextMenuEvent *event)
Intercept context event to support point editing.
Returns information about files.
bool loadsAsDigFile(const QString &urlString) const
Returns true if specified file name can be loaded as a DIG file.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Adds ability to QUrl to cleanup url path.
#define LOG4CPP_INFO_S(logger)
#define LOG4CPP_DEBUG_S(logger)