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 #ifndef DLG_SETTINGS_SEGMENTS_H
8 #define DLG_SETTINGS_SEGMENTS_H
9 
10 #include "DlgSettingsAbstractBase.h"
11 #include "GraphicsPoint.h"
12 #include <QImage>
13 #include <QList>
14 
15 class DocumentModelSegments;
16 class QCheckBox;
17 class QComboBox;
18 class QGridLayout;
19 class QGraphicsScene;
20 class QSpinBox;
21 class Segment;
22 class ViewPreview;
23 
24 typedef QList<GraphicsPoint*> GraphicsPoints;
25 
26 /// Dialog for editing Segments settings, for DigitizeStateSegment.
27 class DlgSettingsSegments : public DlgSettingsAbstractBase
28 {
29   Q_OBJECT;
30 
31 public:
32   /// Single constructor.
33   DlgSettingsSegments(MainWindow &mainWindow);
34   virtual ~DlgSettingsSegments();
35 
36   virtual void createOptionalSaveDefault (QHBoxLayout *layout);
37   virtual QWidget *createSubPanel ();
38   virtual void load (CmdMediator &cmdMediator);
39   virtual void setSmallDialogs (bool smallDialogs);
40 
41 private slots:
42   void slotFillCorners (int state);
43   void slotLineColor (const QString &);
44   void slotLineWidth (int);
45   void slotMinLength (const QString &);
46   void slotPointSeparation (const QString &);
47 
48 protected:
49   virtual void handleOk ();
50 
51 private:
52 
53   void clearPoints();
54   void createControls (QGridLayout *layout, int &row);
55   void createPreview (QGridLayout *layout, int &row);
56   QImage createPreviewImage () const;
57   void updateControls();
58   void updatePreview();
59 
60   QSpinBox *m_spinMinLength;
61   QSpinBox *m_spinPointSeparation;
62   QCheckBox *m_chkFillCorners;
63   QSpinBox *m_spinLineWidth;
64   QComboBox *m_cmbLineColor;
65 
66   QGraphicsScene *m_scenePreview;
67   ViewPreview *m_viewPreview;
68 
69   DocumentModelSegments *m_modelSegmentsBefore;
70   DocumentModelSegments *m_modelSegmentsAfter;
71 
72   QList<Segment*> m_segments; // Segments extracted from image
73   GraphicsPoints m_points; // Points spread along the segments
74 
75   bool m_loading; // Flag that prevents multiple preview updates during loading while controls get loaded
76 };
77 
78 #endif // DLG_SETTINGS_SEGMENTS_H
79