7 #include "CmdMediator.h"
10 #include "DigitizeStateContext.h"
11 #include "DigitizeStateSelect.h"
12 #include "EngaugeAssert.h"
13 #include "GraphicsItemType.h"
14 #include "GraphicsScene.h"
15 #include "GraphicsView.h"
17 #include "MainWindow.h"
19 #include <QGraphicsItem>
22 #include <QtToString.h>
24 const QString MOVE_TEXT_DOWN (QObject::tr (
"Move down"));
25 const QString MOVE_TEXT_LEFT (QObject::tr (
"Move left"));
26 const QString MOVE_TEXT_RIGHT (QObject::tr (
"Move right"));
27 const QString MOVE_TEXT_UP (QObject::tr (
"Move up"));
34 DigitizeStateSelect::~DigitizeStateSelect ()
46 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::begin";
51 setCursorForPoints ();
57 LOG4CPP_DEBUG_S ((*mainCat)) <<
"DigitizeStateSelect::cursor";
59 return QCursor (Qt::ArrowCursor);
64 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::end";
66 unsetCursorForPoints ();
71 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleCurveChange";
76 bool atLeastOneSelectedItem)
78 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleKeyPress"
79 <<
" key=" << QKeySequence (key).toString ().toLatin1 ().data ();
81 if (atLeastOneSelectedItem) {
83 if (key == Qt::Key_Down ||
85 key == Qt::Key_Left ||
86 key == Qt::Key_Right) {
88 keyPressArrow (cmdMediator,
104 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleMousePress"
105 <<
" posScreen=" << QPointFToString (posScreen).toLatin1 ().data ();
109 m_movingStart = posScreen;
115 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleMouseRelease"
116 <<
" posScreen=" << QPointFToString (posScreen).toLatin1 ().data ();
118 QPointF deltaScreen = posScreen - m_movingStart;
121 bool positionHasChanged = (positionHasChangedIdentifers.count () > 0);
123 if (positionHasChanged && (
124 deltaScreen.x () != 0 ||
125 deltaScreen.y () != 0)) {
127 QString moveText = moveTextFromDeltaScreen (deltaScreen);
134 positionHasChangedIdentifers);
146 void DigitizeStateSelect::keyPressArrow (
CmdMediator *cmdMediator,
153 deltaScreen = QPointF (0, zoomedToUnzoomedScreenY ());
154 moveText = MOVE_TEXT_DOWN;
158 deltaScreen = QPointF (-1 * zoomedToUnzoomedScreenX (), 0);
159 moveText = MOVE_TEXT_LEFT;
163 deltaScreen = QPointF (zoomedToUnzoomedScreenX (), 0);
164 moveText = MOVE_TEXT_RIGHT;
168 deltaScreen = QPointF (0, -1 * zoomedToUnzoomedScreenY ());
169 moveText = MOVE_TEXT_UP;
173 ENGAUGE_ASSERT (
false);
186 QString DigitizeStateSelect::moveTextFromDeltaScreen (
const QPointF &deltaScreen)
195 bool downOrRight = (deltaScreen.y () > -1.0 * deltaScreen.x ());
196 bool upOrRight = (deltaScreen.y () < deltaScreen.x ());
197 if (downOrRight && upOrRight) {
198 moveText = MOVE_TEXT_RIGHT;
199 }
else if (downOrRight && !upOrRight) {
200 moveText = MOVE_TEXT_DOWN;
201 }
else if (!downOrRight && upOrRight) {
202 moveText = MOVE_TEXT_UP;
204 moveText = MOVE_TEXT_LEFT;
210 void DigitizeStateSelect::setCursorForPoints()
212 QCursor
cursor (Qt::OpenHandCursor);
215 QList<QGraphicsItem*>::iterator itr;
216 for (itr = items.begin (); itr != items.end (); itr++) {
218 QGraphicsItem *item = *itr;
219 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
227 return "DigitizeStateSelect";
230 void DigitizeStateSelect::unsetCursorForPoints()
233 QList<QGraphicsItem*>::iterator itr;
234 for (itr = items.begin (); itr != items.end (); itr++) {
236 QGraphicsItem *item = *itr;
237 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
238 item->unsetCursor ();
246 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::updateModelDigitizeCurve";
251 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::updateModelSegments";
254 double DigitizeStateSelect::zoomedToUnzoomedScreenX ()
const
260 double DigitizeStateSelect::zoomedToUnzoomedScreenY ()
const
virtual void handleKeyPress(CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
Handle a key press that was intercepted earlier.
virtual QCursor cursor(CmdMediator *cmdMediator) const
Returns the state-specific cursor shape.
void setDragMode(QGraphicsView::DragMode dragMode)
Set QGraphicsView drag mode (in m_view). Called from DigitizeStateAbstractBase subclasses.
virtual void updateModelSegments(const DocumentModelSegments &modelSegments)
Update the segments given the new settings.
void updateAfterMouseRelease()
Call MainWindow::updateControls (which is private) after the very specific case - a mouse press/relea...
QStringList selectedPointIdentifiers() const
Return a list of identifiers for the currently selected points.
virtual void handleCurveChange(CmdMediator *cmdMediator)
Handle the selection of a new curve. At a minimum, DigitizeStateSegment will generate a new set of Se...
virtual void handleMouseRelease(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse release that was intercepted earlier.
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.
virtual void handleMousePress(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse press that was intercepted earlier.
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses...
MainWindow & mainWindow()
Reference to the MainWindow, without const.
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
virtual void begin(CmdMediator *cmdMediator, DigitizeState previousState)
Method that is called at the exact moment a state is entered.
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.
void setCursor(CmdMediator *cmdMediator)
Update the cursor according to the current state.
Container for all DigitizeStateAbstractBase subclasses. This functions as the context class in a stan...
void appendNewCmd(CmdMediator *cmdMediator, QUndoCommand *cmd)
Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subc...
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 handleMouseMove(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse move. This is part of an experiment to see if augmenting the cursor in Point Match mod...
DigitizeStateSelect(DigitizeStateContext &context)
Single constructor.
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 updateModelDigitizeCurve(CmdMediator *cmdMediator, const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update the digitize curve settings.