Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
DigitizeStateAbstractBase.cpp
1 #include "CmdEditPointAxis.h"
2 #include "CmdMediator.h"
3 #include "DigitizeStateAbstractBase.h"
4 #include "DigitizeStateContext.h"
5 #include "DlgEditPoint.h"
6 #include "Document.h"
7 #include "Logger.h"
8 #include "MainWindow.h"
9 #include <QApplication>
10 #include <QGraphicsScene>
11 #include <QImage>
12 #include <QMessageBox>
13 #include <QTimer>
14 #include "QtToString.h"
15 #include "Version.h"
16 
18  m_context (context),
19  m_isOverrideCursor (false)
20 {
21 }
22 
23 DigitizeStateAbstractBase::~DigitizeStateAbstractBase()
24 {
25 }
26 
28 {
29  return m_context;
30 }
31 
33 {
34  return m_context;
35 }
36 
37 void DigitizeStateAbstractBase::handleContextMenuEvent (const QString &pointIdentifier)
38 {
39  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAbstractBase::handleContextMenuEvent point=" << pointIdentifier.toLatin1 ().data ();
40 
41  QPointF posScreen = context().cmdMediator().document().positionScreen (pointIdentifier);
42  QPointF posGraphBefore = context().cmdMediator().document().positionGraph (pointIdentifier);
43 
44  // Ask user for coordinates
45  double x = posGraphBefore.x();
46  double y = posGraphBefore.y();
47  DlgEditPoint *dlg = new DlgEditPoint(context().mainWindow(),
48  *this,
49  context().cmdMediator().document().modelCoords(),
50  cursor (),
51  context().mainWindow().transformation(),
52  &x,
53  &y);
54  int rtn = dlg->exec ();
55 
56  QPointF posGraphAfter = dlg->posGraph ();
57  delete dlg;
58 
59  if (rtn == QDialog::Accepted) {
60 
61  // User wants to edit this axis point, but let's perform sanity checks first
62 
63  bool isError;
64  QString errorMessage;
65 
67  posScreen,
68  posGraphAfter,
69  isError,
70  errorMessage);
71 
72  if (isError) {
73 
74  QMessageBox::warning (0,
75  engaugeWindowTitle(),
76  errorMessage);
77 
78  } else {
79 
80  // Create a command to edit the point
81  CmdEditPointAxis *cmd = new CmdEditPointAxis (context().mainWindow(),
82  context().cmdMediator().document(),
83  pointIdentifier,
84  posGraphBefore,
85  posGraphAfter);
86  context().appendNewCmd(cmd);
87  }
88  }
89 }
90 
92 {
93  LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateAbstractBase::handleLeave";
94 
96 }
97 
99 {
101 
102  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAbstractBase::handleSetOverrideCursor setOverrideCursor="
103  << QtCursorToString (cursor.shape ()).toLatin1 ().data ();
104 
105  QApplication::setOverrideCursor (cursor);
106  m_isOverrideCursor = true;
107 }
108 
110 {
111  if (m_isOverrideCursor) {
112 
113  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAbstractBase::handleLeave restoreOverrideCursor="
114  << QtCursorToString (QApplication::overrideCursor ()->shape ()).toLatin1 ().data ();
115 
116  // Override cursor from last QDialog must be restored
117  QApplication::restoreOverrideCursor ();
118 
119  m_isOverrideCursor = false;
120  }
121 }
122 
124 {
125  LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateAbstractBase::setCursor";
126 
128  context().view().setCursor (cursor ());
129 }
QPointF positionScreen(const QString &pointIdentifier) const
See Curve::positionScreen.
Definition: Document.cpp:728
CmdMediator & cmdMediator()
Provide CmdMediator for indirect access to the Document.
virtual void handleLeave()
Handle leave in case an override cursor is in effect from last QDialog, by resetting the override cur...
CmdMediator & cmdMediator()
Accessor for commands to process the Document.
Definition: MainWindow.cpp:177
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
Definition: CmdMediator.cpp:61
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses...
MainWindow & mainWindow()
Reference to the MainWindow, without const.
void checkEditPointAxis(const QString &pointIdentifier, const QPointF &posScreen, const QPointF &posGraph, bool &isError, QString &errorMessage)
Check before calling editPointAxis.
Definition: Document.cpp:233
QPointF posGraph() const
Return the graph coordinates position specified by the user. Only applies if dialog was accepted...
Container for all DigitizeStateAbstractBase subclasses. This functions as the context class in a stan...
void setCursor()
Update the cursor according to the current state.
QPointF positionGraph(const QString &pointIdentifier) const
See Curve::positionGraph.
Definition: Document.cpp:720
Dialog box for editing the information of one axis point.
Definition: DlgEditPoint.h:22
void appendNewCmd(QUndoCommand *cmd)
Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subc...
void handleContextMenuEvent(const QString &pointIdentifier)
Handle a right click that was intercepted earlier. This is done in the superclass since it works the ...
void removeOverrideCursor()
Remove the override cursor if it is in use. This is called after a leave event, and prior to displayi...
QGraphicsView & view()
QGraphicsView for use by DigitizeStateAbstractBase subclasses.
Command for editing the graph coordinates one axis point.
DigitizeStateAbstractBase(DigitizeStateContext &context)
Single constructor.
void handleSetOverrideCursor(const QCursor &cursor)
Handle the command to set the override cursor.
virtual QCursor cursor() const =0
Returns the state-specific cursor shape.