1 #include "CmdMediator.h"
4 #include "DigitizeStateContext.h"
5 #include "DigitizeStateSelect.h"
6 #include "EngaugeAssert.h"
7 #include "GraphicsItemType.h"
8 #include "GraphicsScene.h"
9 #include "GraphicsView.h"
11 #include "MainWindow.h"
13 #include <QGraphicsItem>
15 #include <QtToString.h>
17 const QString MOVE_TEXT_DOWN (
"Move down");
18 const QString MOVE_TEXT_LEFT (
"Move left");
19 const QString MOVE_TEXT_RIGHT (
"Move right");
20 const QString MOVE_TEXT_UP (
"Move up");
27 DigitizeStateSelect::~DigitizeStateSelect ()
38 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::begin";
43 setCursorForPoints ();
49 LOG4CPP_DEBUG_S ((*mainCat)) <<
"DigitizeStateSelect::cursor";
51 return QCursor (Qt::ArrowCursor);
56 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::end";
58 unsetCursorForPoints ();
63 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleCurveChange";
67 bool atLeastOneSelectedItem)
69 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleKeyPress"
70 <<
" key=" << QKeySequence (key).toString ().toLatin1 ().data ();
72 if (atLeastOneSelectedItem) {
74 if (key == Qt::Key_Down ||
76 key == Qt::Key_Left ||
77 key == Qt::Key_Right) {
92 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleMousePress"
93 <<
" posScreen=" << QPointFToString (posScreen).toLatin1 ().data ();
97 m_movingStart = posScreen;
102 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleMouseRelease"
103 <<
" posScreen=" << QPointFToString (posScreen).toLatin1 ().data ();
105 QPointF deltaScreen = posScreen - m_movingStart;
108 bool positionHasChanged = (positionHasChangedIdentifers.count () > 0);
110 if (positionHasChanged && (
111 deltaScreen.x () != 0 ||
112 deltaScreen.y () != 0)) {
114 QString moveText = moveTextFromDeltaScreen (deltaScreen);
118 context().cmdMediator().document(),
121 positionHasChangedIdentifers);
132 void DigitizeStateSelect::keyPressArrow (Qt::Key key)
138 deltaScreen = QPointF (0, zoomedToUnzoomedScreenY ());
139 moveText = MOVE_TEXT_DOWN;
143 deltaScreen = QPointF (-1 * zoomedToUnzoomedScreenX (), 0);
144 moveText = MOVE_TEXT_LEFT;
148 deltaScreen = QPointF (zoomedToUnzoomedScreenX (), 0);
149 moveText = MOVE_TEXT_RIGHT;
153 deltaScreen = QPointF (0, -1 * zoomedToUnzoomedScreenY ());
154 moveText = MOVE_TEXT_UP;
158 ENGAUGE_ASSERT (
false);
163 context().cmdMediator ().document(),
166 context().mainWindow().scene ().selectedPointIdentifiers ());
170 QString DigitizeStateSelect::moveTextFromDeltaScreen (
const QPointF &deltaScreen)
179 bool downOrRight = (deltaScreen.y () > -1.0 * deltaScreen.x ());
180 bool upOrRight = (deltaScreen.y () < deltaScreen.x ());
181 if (downOrRight && upOrRight) {
182 moveText = MOVE_TEXT_RIGHT;
183 }
else if (downOrRight && !upOrRight) {
184 moveText = MOVE_TEXT_DOWN;
185 }
else if (!downOrRight && upOrRight) {
186 moveText = MOVE_TEXT_UP;
188 moveText = MOVE_TEXT_LEFT;
194 void DigitizeStateSelect::setCursorForPoints()
196 QCursor
cursor (Qt::OpenHandCursor);
199 QList<QGraphicsItem*>::iterator itr;
200 for (itr = items.begin (); itr != items.end (); itr++) {
202 QGraphicsItem *item = *itr;
203 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
211 return "DigitizeStateSelect";
214 void DigitizeStateSelect::unsetCursorForPoints()
217 QList<QGraphicsItem*>::iterator itr;
218 for (itr = items.begin (); itr != items.end (); itr++) {
220 QGraphicsItem *item = *itr;
221 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
222 item->unsetCursor ();
229 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::updateModelDigitizeCurve";
234 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::updateModelSegments";
237 double DigitizeStateSelect::zoomedToUnzoomedScreenX ()
const
243 double DigitizeStateSelect::zoomedToUnzoomedScreenY ()
const
virtual QCursor cursor() const
Returns the state-specific cursor shape.
virtual void handleMousePress(QPointF posScreen)
Handle a mouse press that was intercepted earlier.
void setDragMode(QGraphicsView::DragMode dragMode)
Set QGraphicsView drag mode (in m_view). Called from DigitizeStateAbstractBase subclasses.
virtual void handleCurveChange()
Handle the selection of a new curve. At a minimum, DigitizeStateSegment will generate a new set of Se...
virtual void updateModelSegments(const DocumentModelSegments &modelSegments)
Update the segments given the new settings.
virtual void handleMouseRelease(QPointF posScreen)
Handle a mouse release that was intercepted earlier.
void updateAfterMouseRelease()
Call MainWindow::updateControls (which is private) after the very specific case - a mouse press/relea...
void updateViewsOfSettings(const QString &activeCurve)
Update curve-specific view of settings. Private version gets active curve name from DigitizeStateCont...
QString selectedGraphCurve() const
Curve name that is currently selected in m_cmbCurve.
Command for moving all selected Points by a specified translation.
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses...
MainWindow & mainWindow()
Reference to the MainWindow, without const.
virtual void handleKeyPress(Qt::Key key, bool atLeastOneSelectedItem)
Handle a key press that was intercepted earlier.
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
GraphicsView & view()
View for the QImage and QGraphicsItems, without const.
QStringList positionHasChangedPointIdentifiers() const
Return a list of identifiers for the points that have moved since the last call to resetPositionHasCh...
GraphicsScene & scene()
Scene container for the QImage and QGraphicsItems.
virtual void updateModelDigitizeCurve(const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update the digitize curve settings.
Container for all DigitizeStateAbstractBase subclasses. This functions as the context class in a stan...
void setCursor()
Update the cursor according to the current state.
virtual QString activeCurve() const
Name of the active Curve. This can include AXIS_CURVE_NAME.
virtual void end()
Method that is called at the exact moment a state is exited. Typically called just before begin for t...
virtual void begin(DigitizeState previousState)
Method that is called at the exact moment a state is entered.
DigitizeStateSelect(DigitizeStateContext &context)
Single constructor.
void appendNewCmd(QUndoCommand *cmd)
Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subc...
Model for DlgSettingsSegments and CmdSettingsSegments.
Base class for all digitizing states. This serves as an interface to DigitizeStateContext.
virtual QString state() const
State name for debugging.
virtual void handleMouseMove(QPointF posScreen)
Handle a mouse move. This is part of an experiment to see if augmenting the cursor in Point Match mod...