Engauge Digitizer  2
MainWindow.h
1 #ifndef MAIN_WINDOW_H
2 #define MAIN_WINDOW_H
3 
4 #include "BackgroundImage.h"
5 #include "DigitizeStateAbstractBase.h"
6 #include "MainWindowModel.h"
7 #include <QCursor>
8 #include <QMainWindow>
9 #include <QUrl>
10 #include "Transformation.h"
11 #include "ZoomControl.h"
12 #include "ZoomFactor.h"
13 
15 class ChecklistGuide;
16 class CmdMediator;
17 class CmdStackShadow;
18 class CurveStyles;
22 class DlgSettingsCoords;
27 class DlgSettingsGeneral;
41 class ExportToFile;
42 class GraphicsScene;
43 class GraphicsView;
44 class HelpWindow;
45 class LoadImageFromUrl;
46 class NetworkClient;
47 class QAction;
48 class QActionGroup;
49 class QCloseEvent;
50 class QComboBox;
51 class QDomDocument;
52 class QGraphicsLineItem;
53 class QMenu;
54 class QSettings;
55 class QTextStream;
56 class QTimer;
57 class QToolBar;
58 class QVBoxLayout;
59 class StatusBar;
61 class TutorialDlg;
62 class ViewPointStyle;
63 class ViewSegmentFilter;
64 
66 class MainWindow : public QMainWindow
67 {
68  Q_OBJECT
69 
70 public:
72  MainWindow(const QString &errorReportFile, // Empty if unused
73  bool isGnuplot,
74  QStringList loadStartupFiles,
75  QWidget *parent = 0);
76  ~MainWindow();
77 
80 
82  virtual bool eventFilter(QObject *, QEvent *);
83 
85  QImage imageFiltered () const;
86 
88  bool isGnuplot() const;
89 
92 
94  void resizeEvent (QResizeEvent *event);
95 
97  void saveErrorReportFileAndExit(const char *comment,
98  const char *file,
99  int line,
100  const char *context) const;
101 
103  GraphicsScene &scene();
104 
107  BackgroundImage selectOriginal(BackgroundImage backgroundImage);
108 
110  QString selectedGraphCurve () const;
111 
113  virtual void showEvent(QShowEvent *);
114 
116  void showTemporaryMessage (const QString &temporaryMessage);
117 
120 
122  bool transformIsDefined() const;
123 
125  void updateAfterCommand();
126 
129 
131  void updateDigitizeStateIfSoftwareTriggered (DigitizeState digitizeState);
132 
136 
138  void updateSettingsAxesChecker(const DocumentModelAxesChecker &modelAxesChecker);
139 
141  void updateSettingsColorFilter(const DocumentModelColorFilter &modelColorFilter);
142 
144  void updateSettingsCoords(const DocumentModelCoords &modelCoords);
145 
147  void updateSettingsCurveAddRemove (const CurvesGraphs &curvesGraphs);
148 
150  void updateSettingsCurveStyles(const CurveStyles &modelCurveStyles);
151 
153  void updateSettingsDigitizeCurve(const DocumentModelDigitizeCurve &modelDigitizeCurve);
154 
156  void updateSettingsExportFormat(const DocumentModelExportFormat &modelExport);
157 
159  void updateSettingsGeneral(const DocumentModelGeneral &modelGeneral);
160 
162  void updateSettingsGridRemoval(const DocumentModelGridRemoval &modelGridRemoval);
163 
165  void updateSettingsMainWindow(const MainWindowModel &modelMainWindow);
166 
168  void updateSettingsPointMatch(const DocumentModelPointMatch &modelPointMatch);
169 
171  void updateSettingsSegments(const DocumentModelSegments &modelSegments);
172 
174  void updateViewsOfSettings (const QString &activeCurve);
175 
177  GraphicsView &view ();
178 
180  const GraphicsView &view () const;
181 
183  virtual void wheelEvent(QWheelEvent *event);
184 
185 private slots:
186  void slotCanRedoChanged (bool);
187  void slotCanUndoChanged (bool);
188  void slotChecklistClosed ();
189  void slotCleanChanged (bool);
190  void slotCmbBackground(int);
191  void slotCmbCurve(int);
192  void slotContextMenuEvent (QString);
193  void slotDigitizeAxis ();
194  void slotDigitizeColorPicker ();
195  void slotDigitizeCurve ();
196  void slotDigitizePointMatch ();
197  void slotDigitizeSegment ();
198  void slotDigitizeSelect ();
199  void slotEditCopy ();
200  void slotEditCut ();
201  void slotEditDelete ();
202  void slotEditPaste ();
203  void slotFileClose ();
204  void slotFileExport ();
205  void slotFileImport();
206  void slotFileImportDraggedImage(QImage);
207  void slotFileImportDraggedImageUrl(QUrl);
208  void slotFileImportImage(QString, QImage);
209  void slotFileOpen();
210  void slotFileOpenDraggedDigFile (QString);
211  void slotFilePrint();
212  bool slotFileSave();
213  bool slotFileSaveAs();
214  void slotHelpAbout();
215  void slotHelpTutorial();
216  void slotKeyPress (Qt::Key, bool);
217  void slotLeave ();
218  void slotLoadStartupFiles ();
219  void slotMouseMove (QPointF);
220  void slotMousePress (QPointF);
221  void slotMouseRelease (QPointF);
222  void slotRecentFileAction ();
223  void slotRedoTextChanged (const QString &);
224  void slotSetOverrideCursor (QCursor);
225  void slotSettingsAxesChecker ();
226  void slotSettingsColorFilter ();
227  void slotSettingsCoords ();
228  void slotSettingsCurveAddRemove ();
229  void slotSettingsCurveProperties ();
230  void slotSettingsDigitizeCurve ();
231  void slotSettingsExportFormat ();
232  void slotSettingsGeneral ();
233  void slotSettingsGridRemoval ();
234  void slotSettingsMainWindow ();
235  void slotSettingsPointMatch ();
236  void slotSettingsSegments ();
237  void slotUndoTextChanged (const QString &);
238  void slotViewGroupBackground(QAction*);
239  void slotViewGroupCurves(QAction*);
240  void slotViewGroupStatus(QAction*);
241  void slotViewToolBarBackground ();
242  void slotViewToolBarChecklistGuide ();
243  void slotViewToolBarDigitize ();
244  void slotViewToolBarSettingsViews ();
245  void slotViewToolTips ();
246  void slotViewZoom16To1 ();
247  void slotViewZoom8To1 ();
248  void slotViewZoom4To1 ();
249  void slotViewZoom2To1 ();
250  void slotViewZoom1To1 ();
251  void slotViewZoom1To2 ();
252  void slotViewZoom1To4 ();
253  void slotViewZoom1To8 ();
254  void slotViewZoom1To16 ();
255  void slotViewZoom (int);
256  void slotViewZoomFill ();
257  void slotViewZoomIn ();
258  void slotViewZoomOut ();
259 
260 signals:
262  void signalZoom(int);
263 
264 private:
265  MainWindow();
266 
267  void applyZoomFactorAfterLoad();
268  virtual void closeEvent(QCloseEvent *event);
269  void createActions();
270  void createActionsDigitize ();
271  void createActionsEdit ();
272  void createActionsFile ();
273  void createActionsHelp ();
274  void createActionsSettings ();
275  void createActionsView ();
276  void createCentralWidget ();
277  void createCommandStackShadow ();
278  void createHelpWindow ();
279  void createIcons();
280  void createLoadImageFromUrl ();
281  void createMenus();
282  void createNetwork();
283  void createScene ();
284  void createSettingsDialogs ();
285  void createStateContextBackground();
286  void createStateContextDigitize();
287  void createStateContextTransformation();
288  void createStatusBar();
289  void createToolBars();
290  void createTutorial();
291  ZoomFactor currentZoomFactor () const;
292  void fileImport (const QString &fileName);
293  void loadCurveListFromCmdMediator();
294  void loadDocumentFile (const QString &fileName);
295  void loadErrorReportFile(const QString &initialPath,
296  const QString &errorReportFile);
297  void loadImage (const QString &fileName,
298  const QImage &image);
299  void loadInputFileForErrorReport(QDomDocument &domInputFile) const;
300  void loadToolTips ();
301  bool maybeSave();
302  DocumentModelExportFormat modelExportOverride (const DocumentModelExportFormat &modelExportFormatBefore,
303  const ExportToFile &exportStrategy,
304  const QString &selectedNameFilter) const;
305  void rebuildRecentFileListForCurrentFile(const QString &filePath);
306  bool saveDocumentFile(const QString &fileName);
307  QString saveErrorReportFileAndExitXml (const char *comment,
308  const char *file,
309  int line,
310  const char *context,
311  bool includeDocument) const;
312  void saveStartingDocumentSnapshot();
313  void setCurrentFile(const QString &fileName);
314  void setCurrentPathFromFile (const QString &fileName);
315  void setPixmap (const QPixmap &pixmap);
316  void settingsRead ();
317  void settingsReadEnvironment (QSettings &settings);
318  void settingsReadMainWindow (QSettings &settings);
319  void settingsWrite ();
320  void setupAfterLoad (const QString &fileName,
321  const QString &temporaryMessage);
322  void updateAfterCommandStatusBarCoords ();
323  void updateControls (); // Update the widgets (typically in terms of show/hide state) depending on the application state.
324  void updateRecentFileList();
325  void updateSettingsMainWindow();
326  void updateTransformationAndItsDependencies();
327  void updateViewedCurves ();
328  void updateViewsOfSettings (); // Private version gets active curve name from DigitizeContext
329  void writeCheckpointToLogFile();
330 
331  QString m_originalFile; // Original filename for error report
332  bool m_originalFileWasImported; // True/false for imported/opened
333  bool m_isDocumentExported;
334  QString m_engaugeFile; // Not empty when a Document is currently loaded AND it was loaded and/or saved as an Engauge file
335  QString m_currentFile; // Not empty when a Document is currently loaded
336 
337  QMenu *m_menuFile;
338  QAction *m_actionImport;
339  QAction *m_actionOpen;
340  QMenu *m_menuFileOpenRecent;
341  QList<QAction*> m_actionRecentFiles;
342  QAction *m_actionClose;
343  QAction *m_actionSave;
344  QAction *m_actionSaveAs;
345  QAction *m_actionExport;
346  QAction *m_actionPrint;
347  QAction *m_actionExit;
348 
349  QMenu *m_menuEdit;
350  QAction *m_actionEditUndo;
351  QAction *m_actionEditRedo;
352  QAction *m_actionEditCut;
353  QAction *m_actionEditCopy;
354  QAction *m_actionEditPaste;
355  QAction *m_actionEditDelete;
356 
357  QMenu *m_menuDigitize;
358  QActionGroup *m_groupDigitize;
359  QAction *m_actionDigitizeSelect;
360  QAction *m_actionDigitizeAxis;
361  QAction *m_actionDigitizeCurve;
362  QAction *m_actionDigitizePointMatch;
363  QAction *m_actionDigitizeColorPicker;
364  QAction *m_actionDigitizeSegment;
365 
366  QMenu *m_menuView;
367  QAction *m_actionViewBackground;
368  QAction *m_actionViewChecklistGuide;
369  QAction *m_actionViewDigitize;
370  QAction *m_actionViewSettingsViews;
371  QAction *m_actionViewToolTips;
372  QMenu *m_menuViewBackground;
373  QActionGroup *m_groupBackground;
374  QAction *m_actionViewBackgroundNone;
375  QAction *m_actionViewBackgroundOriginal;
376  QAction *m_actionViewBackgroundFiltered;
377  QMenu *m_menuViewCurves;
378  QActionGroup *m_groupCurves;
379  QAction *m_actionViewCurvesNone;
380  QAction *m_actionViewCurvesSelected;
381  QAction *m_actionViewCurvesAll;
382  QMenu *m_menuViewStatus;
383  QActionGroup *m_groupStatus;
384  QAction *m_actionStatusNever;
385  QAction *m_actionStatusTemporary;
386  QAction *m_actionStatusAlways;
387  QMenu *m_menuViewZoom;
388  QAction *m_actionZoomOut;
389  QAction *m_actionZoomIn;
390  QActionGroup *m_groupZoom;
391  QAction *m_actionZoomFill;
392  QAction *m_actionZoom16To1;
393  QAction *m_actionZoom8To1;
394  QAction *m_actionZoom4To1;
395  QAction *m_actionZoom2To1;
396  QAction *m_actionZoom1To1;
397  QAction *m_actionZoom1To2;
398  QAction *m_actionZoom1To4;
399  QAction *m_actionZoom1To8;
400  QAction *m_actionZoom1To16;
401 
402  QMenu *m_menuSettings;
403  QAction *m_actionSettingsAxesChecker;
404  QAction *m_actionSettingsColorFilter;
405  QAction *m_actionSettingsCoords;
406  QAction *m_actionSettingsCurveAddRemove;
407  QAction *m_actionSettingsCurveProperties;
408  QAction *m_actionSettingsDigitizeCurve;
409  QAction *m_actionSettingsExport;
410  QAction *m_actionSettingsGeneral;
411  QAction *m_actionSettingsGridRemoval;
412  QAction *m_actionSettingsMainWindow;
413  QAction *m_actionSettingsPointMatch;
414  QAction *m_actionSettingsSegments;
415 
416  QMenu *m_menuHelp;
417  QAction *m_actionHelpAbout;
418  QAction *m_actionHelpChecklistGuideWizard;
419  QAction *m_actionHelpHelp;
420  QAction *m_actionHelpTutorial;
421  QAction *m_actionHelpWhatsThis;
422 
423  QVBoxLayout *m_layout;
424  GraphicsScene *m_scene;
425  GraphicsView *m_view;
426 
427  StatusBar *m_statusBar;
428  Transformation m_transformation;
429 
430  QComboBox *m_cmbCurve;
431  QToolBar *m_toolDigitize;
432  LoadImageFromUrl *m_loadImageFromUrl;
433 
434  QComboBox *m_cmbBackground;
435  QToolBar *m_toolBackground;
436 
437  ViewPointStyle *m_viewPointStyle;
438  ViewSegmentFilter *m_viewSegmentFilter;
439  QToolBar *m_toolSettingsViews;
440  ChecklistGuide *m_dockChecklistGuide;
441 
442  HelpWindow *m_helpWindow;
443  TutorialDlg *m_tutorialDlg;
444 
445  CmdMediator *m_cmdMediator;
446  CmdStackShadow *m_cmdStackShadow;
447 
448  // State machine for user interface states
449  DigitizeStateContext *m_digitizeStateContext;
450 
451  // State machine for transformation states
452  TransformationStateContext *m_transformationStateContext;
453 
454  // State machine for background image
455  BackgroundStateContext *m_backgroundStateContext;
456 
457  DlgSettingsAxesChecker *m_dlgSettingsAxesChecker;
458  DlgSettingsColorFilter *m_dlgSettingsColorFilter;
459  DlgSettingsCoords *m_dlgSettingsCoords;
460  DlgSettingsCurveAddRemove *m_dlgSettingsCurveAddRemove;
461  DlgSettingsCurveProperties *m_dlgSettingsCurveProperties;
462  DlgSettingsDigitizeCurve * m_dlgSettingsDigitizeCurve;
463  DlgSettingsExportFormat *m_dlgSettingsExportFormat;
464  DlgSettingsGeneral *m_dlgSettingsGeneral;
465  DlgSettingsGridRemoval *m_dlgSettingsGridRemoval;
466  DlgSettingsMainWindow *m_dlgSettingsMainWindow;
467  DlgSettingsPointMatch *m_dlgSettingsPointMatch;
468  DlgSettingsSegments *m_dlgSettingsSegments;
469 
470  // Crash reports
471  QString m_startingDocumentSnapshot; // Serialized snapshot of document at startup. Included in error report if user approves
472  NetworkClient *m_networkClient;
473 
474  // Main window settings
475  bool m_isGnuplot; // From command line
476  MainWindowModel m_modelMainWindow; // From settings file or DlgSettingsMainWindow
477 
478  // File names to be loaded at startup. Only one is loaded into the current instance, with external instances created for the other files
479  QTimer *m_timerLoadStartupFiles;
480  QStringList m_loadStartupFiles;
481 };
482 
483 #endif // MAIN_WINDOW_H
Model for DlgSettingsGeneral and CmdSettingsGeneral.
Model for DlgSettingsPointMatch and CmdSettingsPointMatch.
void updateSettingsMainWindow(const MainWindowModel &modelMainWindow)
Update with new main window properties.
void updateDigitizeStateIfSoftwareTriggered(DigitizeState digitizeState)
After software-triggered state transition, this method manually triggers the action as if user had cl...
Class that displays the current Segment Filter in a MainWindow toolbar.
Dialog for editing Segments settings, for DigitizeStateSegment.
Model for DlgSettingsExportFormat and CmdSettingsExportFormat.
Dialog for editing point match settings, for DigitizeStatePointMatch.
Transformation transformation() const
Return read-only copy of transformation.
Context class for transformation state machine.
Model for DlgSettingsCurveProperties and CmdSettingsCurveProperties.
Definition: CurveStyles.h:16
Dockable help window.
Definition: HelpWindow.h:7
void updateSettingsCurveAddRemove(const CurvesGraphs &curvesGraphs)
Update with new curves.
void updateAfterMouseRelease()
Call MainWindow::updateControls (which is private) after the very specific case - a mouse press/relea...
virtual void wheelEvent(QWheelEvent *event)
Convert wheel events into zoom in/out.
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.
CmdMediator & cmdMediator()
Accessor for commands to process the Document.
Definition: MainWindow.cpp:244
BackgroundImage selectOriginal(BackgroundImage backgroundImage)
Make original background visible, for DigitizeStateColorPicker.
Dialog for editing grid removal settings.
Dialog for editing exporting settings.
void showTemporaryMessage(const QString &temporaryMessage)
Show temporary message in status bar.
Dialog for editing curve names settings.
void updateSettingsDigitizeCurve(const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update with new curve digitization styles.
Tutorial using a strategy like a comic strip with decision points deciding which panels appear...
Definition: TutorialDlg.h:13
Strategy class for exporting to a file. This strategy is external to the Document class so that class...
Definition: ExportToFile.h:19
Dockable text window containing checklist guide.
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
GraphicsView & view()
View for the QImage and QGraphicsItems, without const.
Affine transformation between screen and graph coordinates, based on digitized axis points...
Dialog for editing filtering settings.
Container for all graph curves. The axes point curve is external to this class.
Definition: CurvesGraphs.h:18
Model for DlgSettingsColorFilter and CmdSettingsColorFilter.
Wrapper around QStatusBar to manage permanent widgets.
Definition: StatusBar.h:15
GraphicsScene & scene()
Scene container for the QImage and QGraphicsItems.
void updateSettingsCurveStyles(const CurveStyles &modelCurveStyles)
Update with new curve styles.
Client for interacting with Engauge server.
Definition: NetworkClient.h:10
Context class that manages the background image state machine.
QGraphicsView class with event handling added. Typically the events are sent to the active digitizing...
Definition: GraphicsView.h:14
Container for all DigitizeStateAbstractBase subclasses. This functions as the context class in a stan...
Model for DlgSettingsMainWindow and CmdSettingsMainWindow.
Dialog for editing general settings.
Model for DlgSettingsCoords and CmdSettingsCoords.
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.
void updateSettingsColorFilter(const DocumentModelColorFilter &modelColorFilter)
Update with new color filter properties.
Dialog for editing DigitizeStateCurve settings.
void updateSettingsAxesChecker(const DocumentModelAxesChecker &modelAxesChecker)
Update with new axes indicator properties.
void updateSettingsPointMatch(const DocumentModelPointMatch &modelPointMatch)
Update with new point match properties.
void updateSettingsGeneral(const DocumentModelGeneral &modelGeneral)
Update with new general properties.
QImage imageFiltered() const
Background image that has been filtered for the current curve. This asserts if a curve-specific image...
void updateSettingsGridRemoval(const DocumentModelGridRemoval &modelGridRemoval)
Update with new grid removal properties.
Class that displays a view of the current Curve's point style.
Dialog for editing main window settings, which are entirely independent of all documents.
Model for DlgSettingsAxesChecker and CmdSettingsAxesChecker.
Command stack that shadows the CmdMediator command stack at startup when reading commands from an err...
void updateSettingsExportFormat(const DocumentModelExportFormat &modelExport)
Update with new export properties.
Dialog for editing coordinates settings.
Load QImage from url. This is trivial for a file, but requires an asynchronous download step for http...
virtual bool eventFilter(QObject *, QEvent *)
Catch secret keypresses.
bool isGnuplot() const
Get method for gnuplot flag.
Dialog for editing curve properties settings.
Command queue stack.
Definition: CmdMediator.h:16
void saveErrorReportFileAndExit(const char *comment, const char *file, int line, const char *context) const
Save error report and exit.
void signalZoom(int)
Send zoom selection, picked from menu or keystroke, to StatusBar.
Model for DlgSettingsSegments and CmdSettingsSegments.
void resizeEvent(QResizeEvent *event)
Intercept resize event so graphics scene can be appropriately resized when in Fill mode...
void updateSettingsCoords(const DocumentModelCoords &modelCoords)
Update with new coordinate properties.
Add point and line handling to generic QGraphicsScene.
Definition: GraphicsScene.h:25
Model for DlgSettingsGridRemoval and CmdSettingsGridRemoval. The settings are unstable until the user...
void updateSettingsSegments(const DocumentModelSegments &modelSegments)
Update with new segments properties.
Dialog for editing axes checker settings.
void updateGraphicsLinesToMatchGraphicsPoints()
Update the graphics lines so they follow the graphics points, after a drag, addition, removal, and such.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:66
MainWindowModel modelMainWindow() const
Get method for main window model.
virtual void showEvent(QShowEvent *)
Processing performed after gui becomes available.
bool transformIsDefined() const
Return true if all three axis points have been defined.