Engauge Digitizer 2
Loading...
Searching...
No Matches
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 "ButtonWhatsThis.h"
8#include "CmdMediator.h"
10#include "DlgSettingsGeneral.h"
11#include "EngaugeAssert.h"
12#include "Logger.h"
13#include "MainWindow.h"
14#include <QComboBox>
15#include <QGraphicsScene>
16#include <QGridLayout>
17#include <QGroupBox>
18#include <QLabel>
19#include <qmath.h>
20#include <QPushButton>
21#include <QSettings>
22#include <QSpinBox>
23#include <QWhatsThis>
24#include "Settings.h"
25
27 DlgSettingsAbstractBase (tr ("General"),
28 "DlgSettingsGeneral",
30 m_modelGeneralBefore (nullptr),
31 m_modelGeneralAfter (nullptr)
32{
33 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::DlgSettingsGeneral";
34
35 QWidget *subPanel = createSubPanel ();
36 finishPanel (subPanel);
37}
38
40{
41 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::~DlgSettingsGeneral";
42}
43
44void DlgSettingsGeneral::createControls (QGridLayout *layout,
45 int &row)
46{
47 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::createControls";
48
49 QLabel *labelCursorSize = new QLabel (QString ("%1:").arg (tr ("Effective cursor size (pixels)")));
50 layout->addWidget (labelCursorSize, row, 1);
51
52 m_spinCursorSize = new QSpinBox;
53 m_spinCursorSize->setMinimum (1);
54 m_spinCursorSize->setWhatsThis (tr ("Effective Cursor Size\n\n"
55 "This is the effective width and height of the cursor when clicking on a pixel that is "
56 "not part of the background.\n\n"
57 "This parameter is used in the Color Picker and Point Match modes"));
58 connect (m_spinCursorSize, SIGNAL (valueChanged (int)), this, SLOT (slotCursorSize (int)));
59 layout->addWidget (m_spinCursorSize, row++, 2);
60
61 QLabel *labelExtraPrecision = new QLabel (QString ("%1:").arg (tr ("Extra precision (digits)")));
62 layout->addWidget (labelExtraPrecision, row, 1);
63
64 m_spinExtraPrecision = new QSpinBox;
65 m_spinExtraPrecision->setMinimum (0);
66 m_spinExtraPrecision->setWhatsThis (tr ("Extra Digits of Precision\n\n"
67 "This is the number of additional digits of precision appended after the significant "
68 "digits determined by the digitization accuracy at that point. The digitization accuracy "
69 "at any point equals the change in graph coordinates from moving one pixel in each direction. "
70 "Appending extra digits does not improve the accuracy of the numbers. More information can "
71 "be found in discussions of accuracy versus precision.\n\n"
72 "This parameter is used on the coordinates in the Status Bar and during Export"));
73 connect (m_spinExtraPrecision, SIGNAL (valueChanged (int)), this, SLOT (slotExtraPrecision (int)));
74 layout->addWidget (m_spinExtraPrecision, row++, 2);
75}
76
78{
79 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::createOptionalSaveDefault";
80
81 m_btnSaveDefault = new QPushButton (tr ("Save As Default"));
82 m_btnSaveDefault->setWhatsThis (tr ("Save the settings for use as future defaults, according to the curve name selection."));
83 connect (m_btnSaveDefault, SIGNAL (released ()), this, SLOT (slotSaveDefault ()));
84 layout->addWidget (m_btnSaveDefault, 0, Qt::AlignLeft);
85}
86
88{
89 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::createSubPanel";
90
91 QWidget *subPanel = new QWidget ();
92 QGridLayout *layout = new QGridLayout (subPanel);
93 subPanel->setLayout (layout);
94
95 layout->setColumnStretch(0, 1); // Empty first column
96 layout->setColumnStretch(1, 0); // Labels
97 layout->setColumnStretch(2, 0); // Values
98 layout->setColumnStretch(3, 1); // Empty first column
99
100 int row = 0;
101
102 createWhatsThis (layout,
103 m_btnWhatsThis,
104 row++,
105 3);
106
107 createControls (layout, row);
108
109 return subPanel;
110}
111
113{
114 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::handleOk";
115
117 cmdMediator ().document(),
118 *m_modelGeneralBefore,
119 *m_modelGeneralAfter);
120 cmdMediator ().push (cmd);
121
122 hide ();
123}
124
126{
127 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::load";
128
130
131 // Flush old data
132 delete m_modelGeneralBefore;
133 delete m_modelGeneralAfter;
134
135 // Save new data
136 m_modelGeneralBefore = new DocumentModelGeneral (cmdMediator.document());
137 m_modelGeneralAfter = new DocumentModelGeneral (cmdMediator.document());
138
139 // Populate controls
140 m_spinCursorSize->setValue (m_modelGeneralAfter->cursorSize());
141 m_spinExtraPrecision->setValue (m_modelGeneralAfter->extraPrecision());
142
143 updateControls ();
144 enableOk (false); // Disable Ok button since there not yet any changes
145}
146
147void DlgSettingsGeneral::setSmallDialogs(bool /* smallDialogs */)
148{
149}
150
151void DlgSettingsGeneral::slotCursorSize (int cursorSize)
152{
153 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::slotCursorSize";
154
155 m_modelGeneralAfter->setCursorSize (cursorSize);
156 updateControls();
157}
158
159void DlgSettingsGeneral::slotExtraPrecision (int extraPrecision)
160{
161 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::slotExtraPrecision";
162
163 m_modelGeneralAfter->setExtraPrecision (extraPrecision);
164 updateControls();
165}
166
167void DlgSettingsGeneral::slotSaveDefault()
168{
169 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::slotSaveDefault";
170
171 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
172 settings.beginGroup (SETTINGS_GROUP_GENERAL);
173
174 settings.setValue (SETTINGS_GENERAL_CURSOR_SIZE,
175 m_modelGeneralAfter->cursorSize());
176 settings.setValue (SETTINGS_GENERAL_EXTRA_PRECISION,
177 m_modelGeneralAfter->extraPrecision());
178 settings.endGroup ();
179}
180
181void DlgSettingsGeneral::slotWhatsThis ()
182{
183 QWhatsThis::enterWhatsThisMode();
184}
185
186void DlgSettingsGeneral::updateControls ()
187{
188 enableOk (true);
189}
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
Command for DlgSettingsGeneral.
DlgSettingsAbstractBase(const QString &title, const QString &dialogName, MainWindow &mainWindow)
Single constructor.
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 createWhatsThis(QGridLayout *layout, ButtonWhatsThis *button, int row, int column)
Create a WhatsThis button in a grid layout.
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.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition MainWindow.h:95
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18