Engauge Digitizer  2
DigitizeStateAbstractBase.cpp
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #include "CmdEditPointAxis.h"
8 #include "CmdMediator.h"
9 #include "DigitizeStateAbstractBase.h"
10 #include "DigitizeStateContext.h"
11 #include "DlgEditPoint.h"
12 #include "Document.h"
13 #include "Logger.h"
14 #include "MainWindow.h"
15 #include <QApplication>
16 #include <QGraphicsScene>
17 #include <QImage>
18 #include <QMessageBox>
19 #include <QTimer>
20 #include "QtToString.h"
21 #include "Version.h"
22 
24  m_context (context),
25  m_isOverrideCursor (false)
26 {
27 }
28 
29 DigitizeStateAbstractBase::~DigitizeStateAbstractBase()
30 {
31 }
32 
34 {
35  return m_context;
36 }
37 
39 {
40  return m_context;
41 }
42 
44  const QString &pointIdentifier)
45 {
46  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAbstractBase::handleContextMenuEvent point=" << pointIdentifier.toLatin1 ().data ();
47 
48  QPointF posScreen = cmdMediator->document().positionScreen (pointIdentifier);
49  QPointF posGraphBefore = cmdMediator->document().positionGraph (pointIdentifier);
50  bool isXOnly = cmdMediator->document().isXOnly (pointIdentifier);
51 
52  // Ask user for coordinates
53  double x = posGraphBefore.x();
54  double y = posGraphBefore.y();
55 
56  DlgEditPoint *dlg = new DlgEditPoint(context().mainWindow(),
57  *this,
58  cmdMediator->document().modelCoords(),
60  cursor (cmdMediator),
62  cmdMediator->document().documentAxesPointsRequired(),
63  isXOnly,
64  &x,
65  &y);
66  int rtn = dlg->exec ();
67 
68  QPointF posGraphAfter = dlg->posGraph (isXOnly); // This call returns new values for isXOnly and the graph position
69  delete dlg;
70 
71  if (rtn == QDialog::Accepted) {
72 
73  // User wants to edit this axis point, but let's perform sanity checks first
74 
75  bool isError;
76  QString errorMessage;
77 
78  context().mainWindow().cmdMediator()->document().checkEditPointAxis(pointIdentifier,
79  posScreen,
80  posGraphAfter,
81  isError,
82  errorMessage);
83 
84  if (isError) {
85 
86  QMessageBox::warning (0,
87  engaugeWindowTitle(),
88  errorMessage);
89 
90  } else {
91 
92  // Create a command to edit the point
93  CmdEditPointAxis *cmd = new CmdEditPointAxis (context().mainWindow(),
94  cmdMediator->document(),
95  pointIdentifier,
96  posGraphBefore,
97  posGraphAfter,
98  isXOnly);
99  context().appendNewCmd(cmdMediator,
100  cmd);
101  }
102  }
103 }
104 
106 {
107  LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateAbstractBase::handleLeave";
108 
110 }
111 
113  const QCursor &cursor)
114 {
116 
117  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAbstractBase::handleSetOverrideCursor setOverrideCursor="
118  << QtCursorToString (cursor.shape ()).toLatin1 ().data ();
119 
120  QApplication::setOverrideCursor (cursor);
121  m_isOverrideCursor = true;
122 }
123 
125 {
126  if (m_isOverrideCursor) {
127 
128  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAbstractBase::handleLeave restoreOverrideCursor="
129  << QtCursorToString (QApplication::overrideCursor ()->shape ()).toLatin1 ().data ();
130 
131  // Override cursor from last QDialog must be restored
132  QApplication::restoreOverrideCursor ();
133 
134  m_isOverrideCursor = false;
135  }
136 }
137 
139 {
140  LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateAbstractBase::setCursor";
141 
143  context().view().setCursor (cursor (cmdMediator));
144 }
QPointF positionScreen(const QString &pointIdentifier) const
See Curve::positionScreen.
Definition: Document.cpp:691
DocumentAxesPointsRequired documentAxesPointsRequired() const
Get method for DocumentAxesPointsRequired.
Definition: Document.cpp:326
bool isXOnly(const QString &pointIdentifier) const
See Curve::isXOnly.
Definition: Document.cpp:357
Transformation transformation() const
Return read-only copy of transformation.
virtual QCursor cursor(CmdMediator *cmdMediator) const =0
Returns the state-specific cursor shape.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
Definition: Document.cpp:611
QPointF posGraph(bool &isXOnly) const
Return the graph coordinates position specified by the user. Only applies if dialog was accepted...
CmdMediator * cmdMediator()
Accessor for commands to process the Document.
Definition: MainWindow.cpp:298
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
Definition: CmdMediator.cpp:72
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:248
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...
void handleContextMenuEvent(CmdMediator *cmdMediator, const QString &pointIdentifier)
Handle a right click that was intercepted earlier. This is done in the superclass since it works the ...
QPointF positionGraph(const QString &pointIdentifier) const
See Curve::positionGraph.
Definition: Document.cpp:686
Dialog box for editing the information of one axis point.
Definition: DlgEditPoint.h:30
Command queue stack.
Definition: CmdMediator.h:23
virtual void handleLeave(CmdMediator *cmdMediator)
Handle leave in case an override cursor is in effect from last QDialog, by resetting the override cur...
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.
void handleSetOverrideCursor(CmdMediator *cmdMediator, const QCursor &cursor)
Handle the command to set the override cursor.
DigitizeStateAbstractBase(DigitizeStateContext &context)
Single constructor.
MainWindowModel modelMainWindow() const
Get method for main window model.