Engauge Digitizer  2
DlgSettingsGeneral.cpp
Go to the documentation of this file.
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 "CmdMediator.h"
8 #include "CmdSettingsGeneral.h"
9 #include "DlgSettingsGeneral.h"
10 #include "EngaugeAssert.h"
11 #include "Logger.h"
12 #include "MainWindow.h"
13 #include <QComboBox>
14 #include <QGraphicsScene>
15 #include <QGridLayout>
16 #include <QGroupBox>
17 #include <QLabel>
18 #include <qmath.h>
19 #include <QPushButton>
20 #include <QSettings>
21 #include <QSpinBox>
22 #include "Settings.h"
23 
25  DlgSettingsAbstractBase (tr ("General"),
26  "DlgSettingsGeneral",
27  mainWindow),
28  m_modelGeneralBefore (nullptr),
29  m_modelGeneralAfter (nullptr)
30 {
31  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::DlgSettingsGeneral";
32 
33  QWidget *subPanel = createSubPanel ();
34  finishPanel (subPanel);
35 }
36 
38 {
39  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::~DlgSettingsGeneral";
40 }
41 
42 void DlgSettingsGeneral::createControls (QGridLayout *layout,
43  int &row)
44 {
45  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::createControls";
46 
47  QLabel *labelCursorSize = new QLabel (QString ("%1:").arg (tr ("Effective cursor size (pixels)")));
48  layout->addWidget (labelCursorSize, row, 1);
49 
50  m_spinCursorSize = new QSpinBox;
51  m_spinCursorSize->setMinimum (1);
52  m_spinCursorSize->setWhatsThis (tr ("Effective Cursor Size\n\n"
53  "This is the effective width and height of the cursor when clicking on a pixel that is "
54  "not part of the background.\n\n"
55  "This parameter is used in the Color Picker and Point Match modes"));
56  connect (m_spinCursorSize, SIGNAL (valueChanged (int)), this, SLOT (slotCursorSize (int)));
57  layout->addWidget (m_spinCursorSize, row++, 2);
58 
59  QLabel *labelExtraPrecision = new QLabel (QString ("%1:").arg (tr ("Extra precision (digits)")));
60  layout->addWidget (labelExtraPrecision, row, 1);
61 
62  m_spinExtraPrecision = new QSpinBox;
63  m_spinExtraPrecision->setMinimum (0);
64  m_spinExtraPrecision->setWhatsThis (tr ("Extra Digits of Precision\n\n"
65  "This is the number of additional digits of precision appended after the significant "
66  "digits determined by the digitization accuracy at that point. The digitization accuracy "
67  "at any point equals the change in graph coordinates from moving one pixel in each direction. "
68  "Appending extra digits does not improve the accuracy of the numbers. More information can "
69  "be found in discussions of accuracy versus precision.\n\n"
70  "This parameter is used on the coordinates in the Status Bar and during Export"));
71  connect (m_spinExtraPrecision, SIGNAL (valueChanged (int)), this, SLOT (slotExtraPrecision (int)));
72  layout->addWidget (m_spinExtraPrecision, row++, 2);
73 }
74 
76 {
77  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::createOptionalSaveDefault";
78 
79  m_btnSaveDefault = new QPushButton (tr ("Save As Default"));
80  m_btnSaveDefault->setWhatsThis (tr ("Save the settings for use as future defaults, according to the curve name selection."));
81  connect (m_btnSaveDefault, SIGNAL (released ()), this, SLOT (slotSaveDefault ()));
82  layout->addWidget (m_btnSaveDefault, 0, Qt::AlignLeft);
83 }
84 
86 {
87  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::createSubPanel";
88 
89  QWidget *subPanel = new QWidget ();
90  QGridLayout *layout = new QGridLayout (subPanel);
91  subPanel->setLayout (layout);
92 
93  layout->setColumnStretch(0, 1); // Empty first column
94  layout->setColumnStretch(1, 0); // Labels
95  layout->setColumnStretch(2, 0); // Values
96  layout->setColumnStretch(3, 1); // Empty first column
97 
98  int row = 0;
99  createControls (layout, row);
100 
101  return subPanel;
102 }
103 
105 {
106  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::handleOk";
107 
109  cmdMediator ().document(),
110  *m_modelGeneralBefore,
111  *m_modelGeneralAfter);
112  cmdMediator ().push (cmd);
113 
114  hide ();
115 }
116 
118 {
119  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::load";
120 
122 
123  // Flush old data
124  delete m_modelGeneralBefore;
125  delete m_modelGeneralAfter;
126 
127  // Save new data
128  m_modelGeneralBefore = new DocumentModelGeneral (cmdMediator.document());
129  m_modelGeneralAfter = new DocumentModelGeneral (cmdMediator.document());
130 
131  // Populate controls
132  m_spinCursorSize->setValue (m_modelGeneralAfter->cursorSize());
133  m_spinExtraPrecision->setValue (m_modelGeneralAfter->extraPrecision());
134 
135  updateControls ();
136  enableOk (false); // Disable Ok button since there not yet any changes
137 }
138 
139 void DlgSettingsGeneral::setSmallDialogs(bool /* smallDialogs */)
140 {
141 }
142 
143 void DlgSettingsGeneral::slotCursorSize (int cursorSize)
144 {
145  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::slotCursorSize";
146 
147  m_modelGeneralAfter->setCursorSize (cursorSize);
148  updateControls();
149 }
150 
151 void DlgSettingsGeneral::slotExtraPrecision (int extraPrecision)
152 {
153  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::slotExtraPrecision";
154 
155  m_modelGeneralAfter->setExtraPrecision (extraPrecision);
156  updateControls();
157 }
158 
159 void DlgSettingsGeneral::slotSaveDefault()
160 {
161  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::slotSaveDefault";
162 
163  QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
164  settings.beginGroup (SETTINGS_GROUP_GENERAL);
165 
166  settings.setValue (SETTINGS_GENERAL_CURSOR_SIZE,
167  m_modelGeneralAfter->cursorSize());
168  settings.setValue (SETTINGS_GENERAL_EXTRA_PRECISION,
169  m_modelGeneralAfter->extraPrecision());
170  settings.endGroup ();
171 }
172 
173 void DlgSettingsGeneral::updateControls ()
174 {
175  enableOk (true);
176 }
log4cpp::Category * mainCat
Definition: Logger.cpp:14
const QString SETTINGS_ENGAUGE
const QString SETTINGS_GROUP_GENERAL
const QString SETTINGS_GENERAL_CURSOR_SIZE
const QString SETTINGS_GENERAL_EXTRA_PRECISION
const QString SETTINGS_DIGITIZER
Command queue stack.
Definition: CmdMediator.h:24
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
Definition: CmdMediator.cpp:72
Command for DlgSettingsGeneral.
Abstract base class for all Settings dialogs.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
void finishPanel(QWidget *subPanel, int minimumWidth=MINIMUM_DIALOG_WIDTH, int minimumHeightOrZero=0)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
MainWindow & mainWindow()
Get method for MainWindow.
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
virtual void handleOk()
Process slotOk.
virtual void load(CmdMediator &cmdMediator)
Load settings from Document.
DlgSettingsGeneral(MainWindow &mainWindow)
Single constructor.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
Model for DlgSettingsGeneral and CmdSettingsGeneral.
void setCursorSize(int cursorSize)
Set method for effective cursor size.
void setExtraPrecision(int extraPrecision)
Set method for extra digits of precision.
int extraPrecision() const
Get method for extra digits of precsion.
int cursorSize() const
Get method for effective cursor size.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:92
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18