Engauge Digitizer 2
Loading...
Searching...
No Matches
DlgSettingsMainWindow.cpp
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 "DlgSettingsMainWindow.h"
8#include "EngaugeAssert.h"
9#include "Logger.h"
10#include "MainWindow.h"
11#include "MainWindowModel.h"
12#include <QCheckBox>
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#include "ZoomControl.h"
24#include "ZoomFactorInitial.h"
25#include "ZoomLabels.h"
26
28 DlgSettingsAbstractBase (tr ("Main Window"),
29 "DlgSettingsMainWindow",
30 mainWindow),
31 m_modelMainWindowBefore (0),
32 m_modelMainWindowAfter (0)
33{
34 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::DlgSettingsMainWindow";
35
36 QWidget *subPanel = createSubPanel ();
37 finishPanel (subPanel);
38}
39
40DlgSettingsMainWindow::~DlgSettingsMainWindow()
41{
42 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::~DlgSettingsMainWindow";
43}
44
45void DlgSettingsMainWindow::createControls (QGridLayout *layout,
46 int &row)
47{
48 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::createControls";
49
50 const int COLUMN0 = 0;
51
52 QLabel *labelZoomFactor = new QLabel (tr ("Initial zoom:"));
53 layout->addWidget (labelZoomFactor, row, 1);
54
55 m_cmbZoomFactor = new QComboBox;
56 m_cmbZoomFactor->addItem (LABEL_ZOOM_16_TO_1 , QVariant (ZOOM_INITIAL_16_TO_1));
57 m_cmbZoomFactor->addItem (LABEL_ZOOM_8_TO_1 , QVariant (ZOOM_INITIAL_8_TO_1));
58 m_cmbZoomFactor->addItem (LABEL_ZOOM_4_TO_1 , QVariant (ZOOM_INITIAL_4_TO_1));
59 m_cmbZoomFactor->addItem (LABEL_ZOOM_2_TO_1 , QVariant (ZOOM_INITIAL_2_TO_1));
60 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_1 , QVariant (ZOOM_INITIAL_1_TO_1));
61 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_2 , QVariant (ZOOM_INITIAL_1_TO_2));
62 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_4 , QVariant (ZOOM_INITIAL_1_TO_4));
63 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_8 , QVariant (ZOOM_INITIAL_1_TO_8));
64 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_16 , QVariant (ZOOM_INITIAL_1_TO_16));
65 m_cmbZoomFactor->addItem (LABEL_ZOOM_FILL , QVariant (ZOOM_INITIAL_FILL));
66 m_cmbZoomFactor->addItem (LABEL_ZOOM_PREVIOUS , QVariant (ZOOM_INITIAL_PREVIOUS));
67 m_cmbZoomFactor->setWhatsThis(tr ("Initial Zoom\n\n"
68 "Select the initial zoom factor when a new document is loaded. Either the previous "
69 "zoom can be kept, or the specified zoom can be applied."));
70 connect (m_cmbZoomFactor, SIGNAL (currentTextChanged (const QString)), this, SLOT (slotZoomFactor(const QString)));
71 layout->addWidget (m_cmbZoomFactor, row++, 2);
72
73 QLabel *labelZoomControl = new QLabel (tr ("Zoom control:"));
74 layout->addWidget (labelZoomControl, row, 1);
75
76 m_cmbZoomControl = new QComboBox;
77 m_cmbZoomControl->addItem (tr ("Menu only" ), QVariant (ZOOM_CONTROL_MENU_ONLY));
78 m_cmbZoomControl->addItem (tr ("Menu and mouse wheel" ), QVariant (ZOOM_CONTROL_MENU_WHEEL));
79 m_cmbZoomControl->addItem (tr ("Menu and +/- keys" ), QVariant (ZOOM_CONTROL_MENU_PLUSMINUS));
80 m_cmbZoomControl->addItem (tr ("Menu, mouse wheel and +/- keys"), QVariant (ZOOM_CONTROL_MENU_WHEEL_PLUSMINUS));
81 m_cmbZoomControl->setWhatsThis (tr ("Zoom Control\n\n"
82 "Select which inputs are used to zoom in and out."));
83 connect (m_cmbZoomControl, SIGNAL (currentTextChanged (const QString)), this, SLOT (slotZoomControl(const QString)));
84 layout->addWidget (m_cmbZoomControl, row++, 2);
85
86 QLabel *labelLocale = new QLabel (tr ("Locale:"));
87 layout->addWidget (labelLocale, row, 1);
88
89 // Initialization of combobox is liberated from Qt Calendar example
90 m_cmbLocale = new QComboBox;
91 m_cmbLocale->setWhatsThis(tr ("Locale\n\n"
92 "Select the locale that will be used when converting between numbers and strings. "
93 "This affects the use of commas or periods as group delimiters in each number entered "
94 "by the user, displayed in the user interface, or exported to a file."));
95 for (int indexLang = QLocale::C; indexLang <= QLocale::LastLanguage; indexLang++) {
96 QLocale::Language lang = static_cast<QLocale::Language> (indexLang);
97 QList<QLocale::Country> countries = QLocale::countriesForLanguage(lang);
98 for (int indexCountry = 0; indexCountry < countries.count(); indexCountry++) {
99 QLocale::Country country = countries.at(indexCountry);
100 QString label = localeLabel (lang,
101 country);
102 QLocale locale (lang, country);
103 m_cmbLocale->addItem (label, locale);
104 }
105 }
106 m_cmbLocale->model()->sort(COLUMN0); // Sort the new entries
107 connect (m_cmbLocale, SIGNAL (currentIndexChanged (int)), this, SLOT (slotLocale (int)));
108 layout->addWidget (m_cmbLocale, row++, 2);
109
110 QLabel *labelRecent = new QLabel (tr ("Recent file list:"));
111 layout->addWidget (labelRecent, row, 1);
112
113 m_btnRecentClear = new QPushButton (tr ("Clear"));
114 m_btnRecentClear->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
115 m_btnRecentClear->setWhatsThis (tr ("Recent File List Clear\n\n"
116 "Clear the recent file list in the File menu."));
117 connect (m_btnRecentClear, SIGNAL (pressed ()), &mainWindow(), SLOT (slotRecentFileClear ()));
118 connect (m_btnRecentClear, SIGNAL (pressed ()), this, SLOT (slotRecentFileClear()));
119 layout->addWidget (m_btnRecentClear, row++, 2);
120
121 QLabel *labelTitleBarFormat = new QLabel (tr ("Include title bar path:"));
122 layout->addWidget (labelTitleBarFormat, row, 1);
123
124 m_chkTitleBarFormat = new QCheckBox;
125 m_chkTitleBarFormat->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
126 m_chkTitleBarFormat->setWhatsThis (tr ("Title Bar Filename\n\n"
127 "Includes or excludes the path and file extension from the filename in the title bar."));
128 connect (m_chkTitleBarFormat, SIGNAL (toggled (bool)), this, SLOT (slotTitleBarFormat(bool)));
129 layout->addWidget (m_chkTitleBarFormat, row++, 2);
130}
131
133{
134 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::createOptionalSaveDefault";
135}
136
138{
139 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::createSubPanel";
140
141 QWidget *subPanel = new QWidget ();
142 QGridLayout *layout = new QGridLayout (subPanel);
143 subPanel->setLayout (layout);
144
145 layout->setColumnStretch(0, 1); // Empty first column
146 layout->setColumnStretch(1, 0); // Labels
147 layout->setColumnStretch(2, 0); // Values
148 layout->setColumnStretch(3, 1); // Empty first column
149
150 int row = 0;
151 createControls (layout, row);
152
153 return subPanel;
154}
155
157{
158 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::handleOk";
159
160 mainWindow().updateSettingsMainWindow (*m_modelMainWindowAfter);
161
162 hide ();
163}
164void DlgSettingsMainWindow::load (CmdMediator & /* cmdMediator */)
165{
166 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::load";
167
168 ENGAUGE_ASSERT (false);
169}
170
172 const MainWindowModel &modelMainWindow)
173{
174 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::loadMainWindowModel";
175
177
178 // Flush old data
179 if (m_modelMainWindowBefore != 0) {
180 delete m_modelMainWindowBefore;
181 }
182 if (m_modelMainWindowAfter != 0) {
183 delete m_modelMainWindowAfter;
184 }
185
186 // Save new data
187 m_modelMainWindowBefore = new MainWindowModel (modelMainWindow);
188 m_modelMainWindowAfter = new MainWindowModel (modelMainWindow);
189
190 // Populate controls
191 int index = m_cmbZoomFactor->findData (m_modelMainWindowAfter->zoomFactorInitial());
192 m_cmbZoomFactor->setCurrentIndex (index);
193 index = m_cmbZoomControl->findData (m_modelMainWindowAfter->zoomControl());
194 m_cmbZoomControl->setCurrentIndex (index);
195 QString locLabel = localeLabel (m_modelMainWindowAfter->locale().language(),
196 m_modelMainWindowBefore->locale().country());
197 index = m_cmbLocale->findText (locLabel);
198 m_cmbLocale->setCurrentIndex(index);
199 m_chkTitleBarFormat->setChecked (m_modelMainWindowAfter->mainTitleBarFormat() == MAIN_TITLE_BAR_FORMAT_PATH);
200
201 updateControls ();
202 enableOk (false); // Disable Ok button since there not yet any changes
203}
204
205QString DlgSettingsMainWindow::localeLabel (QLocale::Language lang,
206 QLocale::Country country) const
207{
208 return QString ("%1/%2")
209 .arg (QLocale::languageToString (lang))
210 .arg (QLocale::countryToString(country));
211}
212
213void DlgSettingsMainWindow::slotLocale (int index)
214{
215 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotLocale";
216
217 m_modelMainWindowAfter->setLocale (m_cmbLocale->itemData (index).toLocale());
218 updateControls();
219}
220
221void DlgSettingsMainWindow::slotRecentFileClear()
222{
223 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotRecentFileClear";
224
225 // The signal that triggered the call to this method was also sent to MainWindow to clear the list there
226 updateControls();
227}
228
229void DlgSettingsMainWindow::slotTitleBarFormat(bool)
230{
231 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotTitleBarFormat";
232
233 m_modelMainWindowAfter->setMainTitleBarFormat(m_chkTitleBarFormat->isChecked() ?
234 MAIN_TITLE_BAR_FORMAT_PATH :
235 MAIN_TITLE_BAR_FORMAT_NO_PATH);
236 updateControls();
237}
238
239void DlgSettingsMainWindow::slotZoomControl(const QString)
240{
241 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotZoomControl";
242
243 m_modelMainWindowAfter->setZoomControl ((ZoomControl) m_cmbZoomControl->currentData().toInt());
244 updateControls();
245}
246
247void DlgSettingsMainWindow::slotZoomFactor(const QString)
248{
249 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWIndow::slotZoomFactor";
250
251 m_modelMainWindowAfter->setZoomFactorInitial((ZoomFactorInitial) m_cmbZoomFactor->currentData().toInt());
252 updateControls();
253}
254
255void DlgSettingsMainWindow::updateControls ()
256{
257 enableOk (true);
258}
Command queue stack.
Definition CmdMediator.h:24
Abstract base class for all Settings dialogs.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
void finishPanel(QWidget *subPanel)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
MainWindow & mainWindow()
Get method for MainWindow.
void loadMainWindowModel(CmdMediator &cmdMediator, const MainWindowModel &modelMainWindow)
Replaced load method since the main window settings are independent of document, unlike other DlgSett...
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
DlgSettingsMainWindow(MainWindow &mainWindow)
Single constructor.
virtual void handleOk()
Process slotOk.
virtual void load(CmdMediator &cmdMediator)
Load settings from Document.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
Model for DlgSettingsMainWindow.
QLocale locale() const
Get method for locale.
ZoomFactorInitial zoomFactorInitial() const
Get method for initial zoom factor.
void setMainTitleBarFormat(MainTitleBarFormat mainTitleBarFormat)
Set method for MainWindow titlebar filename format.
void setZoomControl(ZoomControl zoomControl)
Set method for zoom control.
ZoomControl zoomControl() const
Get method for zoom control.
void setZoomFactorInitial(ZoomFactorInitial zoomFactorInitial)
Set method for initial zoom factor.
MainTitleBarFormat mainTitleBarFormat() const
Get method for MainWindow titlebar filename format.
void setLocale(QLocale::Language language, QLocale::Country country)
Set method for locale given attributes.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition MainWindow.h:78
void updateSettingsMainWindow(const MainWindowModel &modelMainWindow)
Update with new main window properties.