Engauge Digitizer  2
DlgSettingsCommon.cpp
1 #include "CmdMediator.h"
2 #include "CmdSettingsCommon.h"
3 #include "DlgSettingsCommon.h"
4 #include "EngaugeAssert.h"
5 #include "Logger.h"
6 #include "MainWindow.h"
7 #include <QGraphicsScene>
8 #include <QGridLayout>
9 #include <QLabel>
10 #include <qmath.h>
11 #include <QRadioButton>
12 #include <QSpinBox>
13 
15  DlgSettingsAbstractBase ("Common",
16  "DlgSettingsCommon",
17  mainWindow),
18  m_modelCommonBefore (0),
19  m_modelCommonAfter (0)
20 {
21  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCommon::DlgSettingsCommon";
22 
23  QWidget *subPanel = createSubPanel ();
24  finishPanel (subPanel);
25 }
26 
27 DlgSettingsCommon::~DlgSettingsCommon()
28 {
29  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCommon::~DlgSettingsCommon";
30 }
31 
32 void DlgSettingsCommon::createControls (QGridLayout *layout,
33  int &row)
34 {
35  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCommon::createControls";
36 
37  QLabel *labelCursorSize = new QLabel ("Cursor size (pixels):");
38  layout->addWidget (labelCursorSize, row, 1);
39 
40  m_spinCursorSize = new QSpinBox;
41  m_spinCursorSize->setMinimum (1);
42  m_spinCursorSize->setWhatsThis (tr ("Effective Cursor Size\n\n"
43  "This is the effective width and height of the cursor when clicking on a pixel that is "
44  "not part of the background.\n\n"
45  "This parameter is used in the Color Picker and Point Match modes"));
46  connect (m_spinCursorSize, SIGNAL (valueChanged (int)), this, SLOT (slotCursorSize (int)));
47  layout->addWidget (m_spinCursorSize, row++, 2);
48 
49  QLabel *labelExtraPrecision = new QLabel ("Extra precision (digits):");
50  layout->addWidget (labelExtraPrecision, row, 1);
51 
52  m_spinExtraPrecision = new QSpinBox;
53  m_spinExtraPrecision->setMinimum (0);
54  m_spinExtraPrecision->setWhatsThis (tr ("Extra Digits of Precision\n\n"
55  "This is the number of additional digits of precision appended after the significant "
56  "digits determined by the digitization accuracy at that point. The digitization accuracy "
57  "at any point equals the change in graph coordinates from moving one pixel in each direction. "
58  "Appending extra digits does not improve the accuracy of the numbers. More information can "
59  "be found in discussions of accuracy versus precision.\n\n"
60  "This parameter is used on the coordinates in the Status Bar and during Export"));
61  connect (m_spinExtraPrecision, SIGNAL (valueChanged (int)), this, SLOT (slotExtraPrecision (int)));
62  layout->addWidget (m_spinExtraPrecision, row++, 2);
63 }
64 
66 {
67  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCommon::createSubPanel";
68 
69  QWidget *subPanel = new QWidget ();
70  QGridLayout *layout = new QGridLayout (subPanel);
71  subPanel->setLayout (layout);
72 
73  layout->setColumnStretch(0, 1); // Empty first column
74  layout->setColumnStretch(1, 0); // Labels
75  layout->setColumnStretch(2, 0); // Values
76  layout->setColumnStretch(3, 1); // Empty first column
77 
78  int row = 0;
79  createControls (layout, row);
80 
81  return subPanel;
82 }
83 
85 {
86  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCommon::handleOk";
87 
89  cmdMediator ().document(),
90  *m_modelCommonBefore,
91  *m_modelCommonAfter);
92  cmdMediator ().push (cmd);
93 
94  hide ();
95 }
96 
98 {
99  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCommon::load";
100 
101  setCmdMediator (cmdMediator);
102 
103  // Flush old data
104  if (m_modelCommonBefore != 0) {
105  delete m_modelCommonBefore;
106  }
107  if (m_modelCommonAfter != 0) {
108  delete m_modelCommonAfter;
109  }
110 
111  // Save new data
112  m_modelCommonBefore = new DocumentModelCommon (cmdMediator.document());
113  m_modelCommonAfter = new DocumentModelCommon (cmdMediator.document());
114 
115  // Populate controls
116  m_spinCursorSize->setValue (m_modelCommonAfter->cursorSize());
117  m_spinExtraPrecision->setValue (m_modelCommonAfter->extraPrecision());
118 
119  updateControls ();
120  enableOk (false); // Disable Ok button since there not yet any changes
121 }
122 
123 void DlgSettingsCommon::slotCursorSize (int cursorSize)
124 {
125  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCommon::slotCursorSize";
126 
127  m_modelCommonAfter->setCursorSize (cursorSize);
128  updateControls();
129 }
130 
131 void DlgSettingsCommon::slotExtraPrecision (int extraPrecision)
132 {
133  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCommon::slotExtraPrecision";
134 
135  m_modelCommonAfter->setExtraPrecision (extraPrecision);
136  updateControls();
137 }
138 
139 void DlgSettingsCommon::updateControls ()
140 {
141  enableOk (true);
142 }
int extraPrecision() const
Get method for extra digits of precsion.
DlgSettingsCommon(MainWindow &mainWindow)
Single constructor.
Model for DlgSettingsCommon and CmdSettingsCommon.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
virtual void handleOk()
Process slotOk.
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
Definition: CmdMediator.cpp:61
int cursorSize() const
Get method for effective cursor size.
void setExtraPrecision(int extraPrecision)
Set method for extra digits of precision.
void setCursorSize(int cursorSize)
Set method for effective cursor size.
void finishPanel(QWidget *subPanel)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
Command queue stack.
Definition: CmdMediator.h:16
Abstract base class for all Settings dialogs.
Command for DlgSettingsCommon.
MainWindow & mainWindow()
Get method for MainWindow.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:60
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.
virtual void load(CmdMediator &cmdMediator)
Load settings from Document.