Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
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 "ImportCropping.h"
10 #include "ImportCroppingUtilBase.h"
11 #include "Logger.h"
12 #include "MainWindow.h"
13 #include "MainWindowModel.h"
14 #include <QCheckBox>
15 #include <QComboBox>
16 #include <QDoubleSpinBox>
17 #include <QGraphicsScene>
18 #include <QGridLayout>
19 #include <QGroupBox>
20 #include <QLabel>
21 #include <qmath.h>
22 #include <QPushButton>
23 #include <QSpinBox>
24 #include "QtToString.h"
25 #include "ZoomControl.h"
26 #include "ZoomFactorInitial.h"
27 #include "ZoomLabels.h"
28 
29 const int MINIMUM_DIALOG_WIDTH_MAIN_WINDOW = 550;
30 
32  DlgSettingsAbstractBase (tr ("Main Window"),
33  "DlgSettingsMainWindow",
34  mainWindow),
35  m_modelMainWindowBefore (0),
36  m_modelMainWindowAfter (0)
37 {
38  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::DlgSettingsMainWindow";
39 
40  QWidget *subPanel = createSubPanel ();
41  finishPanel (subPanel,
42  MINIMUM_DIALOG_WIDTH_MAIN_WINDOW);
43 }
44 
45 DlgSettingsMainWindow::~DlgSettingsMainWindow()
46 {
47  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::~DlgSettingsMainWindow";
48 }
49 
50 void DlgSettingsMainWindow::createControls (QGridLayout *layout,
51  int &row)
52 {
53  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::createControls";
54 
55  const int COLUMN0 = 0;
56 
57  QLabel *labelZoomFactor = new QLabel (tr ("Initial zoom:"));
58  layout->addWidget (labelZoomFactor, row, 1);
59 
60  m_cmbZoomFactor = new QComboBox;
61  m_cmbZoomFactor->addItem (LABEL_ZOOM_16_TO_1 , QVariant (ZOOM_INITIAL_16_TO_1));
62  m_cmbZoomFactor->addItem (LABEL_ZOOM_8_TO_1 , QVariant (ZOOM_INITIAL_8_TO_1));
63  m_cmbZoomFactor->addItem (LABEL_ZOOM_4_TO_1 , QVariant (ZOOM_INITIAL_4_TO_1));
64  m_cmbZoomFactor->addItem (LABEL_ZOOM_2_TO_1 , QVariant (ZOOM_INITIAL_2_TO_1));
65  m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_1 , QVariant (ZOOM_INITIAL_1_TO_1));
66  m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_2 , QVariant (ZOOM_INITIAL_1_TO_2));
67  m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_4 , QVariant (ZOOM_INITIAL_1_TO_4));
68  m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_8 , QVariant (ZOOM_INITIAL_1_TO_8));
69  m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_16 , QVariant (ZOOM_INITIAL_1_TO_16));
70  m_cmbZoomFactor->addItem (LABEL_ZOOM_FILL , QVariant (ZOOM_INITIAL_FILL));
71  m_cmbZoomFactor->addItem (LABEL_ZOOM_PREVIOUS , QVariant (ZOOM_INITIAL_PREVIOUS));
72  m_cmbZoomFactor->setWhatsThis(tr ("Initial Zoom\n\n"
73  "Select the initial zoom factor when a new document is loaded. Either the previous "
74  "zoom can be kept, or the specified zoom can be applied."));
75  connect (m_cmbZoomFactor, SIGNAL (currentTextChanged (const QString)), this, SLOT (slotZoomFactor(const QString)));
76  layout->addWidget (m_cmbZoomFactor, row++, 2);
77 
78  QLabel *labelZoomControl = new QLabel (tr ("Zoom control:"));
79  layout->addWidget (labelZoomControl, row, 1);
80 
81  m_cmbZoomControl = new QComboBox;
82  m_cmbZoomControl->addItem (tr ("Menu only" ), QVariant (ZOOM_CONTROL_MENU_ONLY));
83  m_cmbZoomControl->addItem (tr ("Menu and mouse wheel" ), QVariant (ZOOM_CONTROL_MENU_WHEEL));
84  m_cmbZoomControl->addItem (tr ("Menu and +/- keys" ), QVariant (ZOOM_CONTROL_MENU_PLUSMINUS));
85  m_cmbZoomControl->addItem (tr ("Menu, mouse wheel and +/- keys"), QVariant (ZOOM_CONTROL_MENU_WHEEL_PLUSMINUS));
86  m_cmbZoomControl->setWhatsThis (tr ("Zoom Control\n\n"
87  "Select which inputs are used to zoom in and out."));
88  connect (m_cmbZoomControl, SIGNAL (currentTextChanged (const QString)), this, SLOT (slotZoomControl(const QString)));
89  layout->addWidget (m_cmbZoomControl, row++, 2);
90 
91  QLabel *labelLocale = new QLabel (tr ("Locale:"));
92  layout->addWidget (labelLocale, row, 1);
93 
94  // Initialization of combobox is liberated from Qt Calendar example
95  m_cmbLocale = new QComboBox;
96  m_cmbLocale->setWhatsThis(tr ("Locale\n\n"
97  "Select the locale that will be used in numbers (immediately), and the language in the user "
98  "interface (after restart).\n\n"
99  "The locale determines how numbers are formatted. Specifically, either commas or "
100  "periods will be used as group delimiters in each number entered "
101  "by the user, displayed in the user interface, or exported to a file."));
102  for (int indexLang = QLocale::C; indexLang <= QLocale::LastLanguage; indexLang++) {
103  QLocale::Language lang = static_cast<QLocale::Language> (indexLang);
104  QList<QLocale::Country> countries = QLocale::countriesForLanguage(lang);
105  for (int indexCountry = 0; indexCountry < countries.count(); indexCountry++) {
106  QLocale::Country country = countries.at(indexCountry);
107  QLocale locale (lang, country);
108  QString label = QLocaleToString (locale);
109  m_cmbLocale->addItem (label, locale);
110  }
111  }
112  m_cmbLocale->model()->sort(COLUMN0); // Sort the new entries
113  connect (m_cmbLocale, SIGNAL (currentIndexChanged (int)), this, SLOT (slotLocale (int)));
114  layout->addWidget (m_cmbLocale, row++, 2);
115 
116  QLabel *labelImportCropping = new QLabel (tr ("Import cropping:"));
117  layout->addWidget (labelImportCropping, row, 1);
118 
119  m_cmbImportCropping = new QComboBox;
120  m_cmbImportCropping->setWhatsThis (tr ("Import Cropping\n\n"
121  "Enables or disables cropping of the imported image when importing. Cropping the image is useful "
122  "for removing unimportant information around a graph, but less useful when the graph already fills "
123  "the entire image."));
124  ImportCroppingUtilBase importCroppingUtil;
125  m_cmbImportCropping->addItem (importCroppingUtil.importCroppingToString (IMPORT_CROPPING_NEVER), IMPORT_CROPPING_NEVER);
126  m_cmbImportCropping->addItem (importCroppingUtil.importCroppingToString (IMPORT_CROPPING_MULTIPAGE_PDFS), IMPORT_CROPPING_MULTIPAGE_PDFS);
127  m_cmbImportCropping->addItem (importCroppingUtil.importCroppingToString (IMPORT_CROPPING_ALWAYS), IMPORT_CROPPING_ALWAYS);
128  connect (m_cmbImportCropping, SIGNAL (currentIndexChanged (int)), this, SLOT (slotImportCropping (int)));
129  layout->addWidget (m_cmbImportCropping, row++, 2);
130 
131 #ifdef ENGAUGE_PDF
132  QLabel *labelPdfResolution = new QLabel (tr ("Import PDF resolution (dots per inch):"));
133  layout->addWidget (labelPdfResolution, row, 1);
134 
135  m_cmbPdfResolution = new QComboBox;
136  m_cmbPdfResolution->setWhatsThis (tr ("Import PDF Resolution\n\n"
137  "Imported Portable Document Format (PDF) files will be converted to this pixel resolution "
138  "in dots per inch (DPI), where each pixel is one dot. A higher value increases the picture resolution "
139  "and may also improve numeric digitizing accuracy. However, a very high value can make the image so "
140  "large that Engauge will slow down."));
141  m_cmbPdfResolution->addItem ("75", 75);
142  m_cmbPdfResolution->addItem ("100", 100);
143  m_cmbPdfResolution->addItem ("150", 150);
144  m_cmbPdfResolution->addItem ("200", 200);
145  m_cmbPdfResolution->addItem ("250", 250);
146  m_cmbPdfResolution->addItem ("300", 300);
147  connect (m_cmbPdfResolution, SIGNAL (currentTextChanged (QString)), this, SLOT (slotPdfResolution (QString)));
148  layout->addWidget (m_cmbPdfResolution, row++, 2);
149 #endif
150 
151  QLabel *labelMaximumGridLines = new QLabel (tr ("Maximum grid lines:"));
152  layout->addWidget (labelMaximumGridLines, row, 1);
153 
154  m_spinMaximumGridLines = new QSpinBox;
155  m_spinMaximumGridLines->setMinimum (2);
156  m_spinMaximumGridLines->setWhatsThis (tr ("Maximum Grid Lines\n\n"
157  "Maximum number of grid lines to be processed. This limit is applied when the step value is too "
158  "small for the start and stop values, which would result in too many grid lines visually and "
159  "possibly extremely long processing time (since each grid line would have to be processed)"));
160  connect (m_spinMaximumGridLines, SIGNAL (valueChanged (int)), this, (SLOT (slotMaximumGridLines (int))));
161  layout->addWidget (m_spinMaximumGridLines, row++, 2);
162 
163  QLabel *labelHighlightOpacity = new QLabel (tr ("Highlight opacity:"));
164  layout->addWidget (labelHighlightOpacity, row, 1);
165 
166  m_spinHighlightOpacity = new QDoubleSpinBox;
167  m_spinHighlightOpacity->setRange (0, 1);
168  m_spinHighlightOpacity->setSingleStep (0.1);
169  m_spinHighlightOpacity->setWhatsThis (tr ("Highligh Opacity\n\n"
170  "Opacity to be applied when the cursor is over a curve or axis point in Select mode. The change in "
171  "appearance shows when the point can be selected."));
172  connect (m_spinHighlightOpacity, SIGNAL (valueChanged (double)), this, SLOT (slotHighlightOpacity(double)));
173  layout->addWidget (m_spinHighlightOpacity, row++, 2);
174 
175  QLabel *labelRecent = new QLabel (tr ("Recent file list:"));
176  layout->addWidget (labelRecent, row, 1);
177 
178  m_btnRecentClear = new QPushButton (tr ("Clear"));
179  m_btnRecentClear->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
180  m_btnRecentClear->setWhatsThis (tr ("Recent File List Clear\n\n"
181  "Clear the recent file list in the File menu."));
182  connect (m_btnRecentClear, SIGNAL (pressed ()), &mainWindow(), SLOT (slotRecentFileClear ()));
183  connect (m_btnRecentClear, SIGNAL (pressed ()), this, SLOT (slotRecentFileClear()));
184  layout->addWidget (m_btnRecentClear, row++, 2);
185 
186  QLabel *labelTitleBarFormat = new QLabel (tr ("Include title bar path:"));
187  layout->addWidget (labelTitleBarFormat, row, 1);
188 
189  m_chkTitleBarFormat = new QCheckBox;
190  m_chkTitleBarFormat->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
191  m_chkTitleBarFormat->setWhatsThis (tr ("Title Bar Filename\n\n"
192  "Includes or excludes the path and file extension from the filename in the title bar."));
193  connect (m_chkTitleBarFormat, SIGNAL (toggled (bool)), this, SLOT (slotTitleBarFormat(bool)));
194  layout->addWidget (m_chkTitleBarFormat, row++, 2);
195 
196  QLabel *labelSmallDialogs = new QLabel (tr ("Allow small dialogs:"));
197  layout->addWidget (labelSmallDialogs, row, 1);
198 
199  m_chkSmallDialogs = new QCheckBox;
200  m_chkSmallDialogs->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
201  m_chkSmallDialogs->setWhatsThis (tr ("Allow Small Dialogs\n\n"
202  "Allows settings dialogs to be made very small so they fit on small computer screens."));
203  connect (m_chkSmallDialogs, SIGNAL (toggled (bool)), this, SLOT (slotSmallDialogs (bool)));
204  layout->addWidget (m_chkSmallDialogs, row++, 2);
205 }
206 
207 void DlgSettingsMainWindow::createOptionalSaveDefault (QHBoxLayout * /* layout */)
208 {
209  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::createOptionalSaveDefault";
210 }
211 
213 {
214  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::createSubPanel";
215 
216  QWidget *subPanel = new QWidget ();
217  QGridLayout *layout = new QGridLayout (subPanel);
218  subPanel->setLayout (layout);
219 
220  layout->setColumnStretch(0, 1); // Empty first column
221  layout->setColumnStretch(1, 0); // Labels
222  layout->setColumnStretch(2, 0); // Values
223  layout->setColumnStretch(3, 1); // Empty first column
224 
225  int row = 0;
226  createControls (layout, row);
227 
228  return subPanel;
229 }
230 
232 {
233  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::handleOk";
234 
235  mainWindow().updateSettingsMainWindow (*m_modelMainWindowAfter);
236 
237  hide ();
238 }
239 void DlgSettingsMainWindow::load (CmdMediator & /* cmdMediator */)
240 {
241  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::load";
242 
243  ENGAUGE_ASSERT (false);
244 }
245 
247  const MainWindowModel &modelMainWindow)
248 {
249  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::loadMainWindowModel";
250 
251  setCmdMediator (cmdMediator);
252 
253  // Flush old data
254  if (m_modelMainWindowBefore != 0) {
255  delete m_modelMainWindowBefore;
256  }
257  if (m_modelMainWindowAfter != 0) {
258  delete m_modelMainWindowAfter;
259  }
260 
261  // Save new data
262  m_modelMainWindowBefore = new MainWindowModel (modelMainWindow);
263  m_modelMainWindowAfter = new MainWindowModel (modelMainWindow);
264 
265  // Populate controls
266  int index = m_cmbZoomFactor->findData (m_modelMainWindowAfter->zoomFactorInitial());
267  m_cmbZoomFactor->setCurrentIndex (index);
268  index = m_cmbZoomControl->findData (m_modelMainWindowAfter->zoomControl());
269  m_cmbZoomControl->setCurrentIndex (index);
270  QString locLabel = QLocaleToString (m_modelMainWindowAfter->locale());
271  index = m_cmbLocale->findText (locLabel);
272  m_cmbLocale->setCurrentIndex(index);
273  index = m_cmbImportCropping->findData (m_modelMainWindowAfter->importCropping());
274  m_cmbImportCropping->setCurrentIndex (index);
275  m_chkTitleBarFormat->setChecked (m_modelMainWindowAfter->mainTitleBarFormat() == MAIN_TITLE_BAR_FORMAT_PATH);
276 #ifdef ENGAUGE_PDF
277  index = m_cmbPdfResolution->findData (m_modelMainWindowAfter->pdfResolution());
278  m_cmbPdfResolution->setCurrentIndex(index);
279 #endif
280  m_spinMaximumGridLines->setValue (m_modelMainWindowAfter->maximumGridLines());
281  m_spinHighlightOpacity->setValue (m_modelMainWindowAfter->highlightOpacity());
282  m_chkSmallDialogs->setChecked (m_modelMainWindowAfter->smallDialogs());
283 
284  updateControls ();
285  enableOk (false); // Disable Ok button since there not yet any changes
286 }
287 
288 void DlgSettingsMainWindow::setSmallDialogs(bool /* smallDialogs */)
289 {
290 }
291 
292 void DlgSettingsMainWindow::slotHighlightOpacity(double)
293 {
294  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotHighlightOpacity";
295 
296  m_modelMainWindowAfter->setHighlightOpacity (m_spinHighlightOpacity->value());
297  updateControls();
298 }
299 
300 void DlgSettingsMainWindow::slotImportCropping (int index)
301 {
302  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotImportCropping";
303 
304  m_modelMainWindowAfter->setImportCropping ((ImportCropping) m_cmbImportCropping->itemData (index).toInt ());
305  updateControls();
306 }
307 
308 void DlgSettingsMainWindow::slotLocale (int index)
309 {
310  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotLocale";
311 
312  m_modelMainWindowAfter->setLocale (m_cmbLocale->itemData (index).toLocale());
313  updateControls();
314 }
315 
316 void DlgSettingsMainWindow::slotMaximumGridLines (int limit)
317 {
318  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWIndow::slotMaximumGridLines";
319 
320  m_modelMainWindowAfter->setMaximumGridLines (limit);
321  updateControls ();
322 }
323 
324 void DlgSettingsMainWindow::slotPdfResolution(const QString)
325 {
326  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWIndow::slotPdfResolution";
327 
328 #ifdef ENGAUGE_PDF
329  m_modelMainWindowAfter->setPdfResolution(m_cmbPdfResolution->currentData().toInt());
330  updateControls();
331 #endif
332 }
333 
334 void DlgSettingsMainWindow::slotRecentFileClear()
335 {
336  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotRecentFileClear";
337 
338  // The signal that triggered the call to this method was also sent to MainWindow to clear the list there
339  updateControls();
340 }
341 
342 void DlgSettingsMainWindow::slotSmallDialogs (bool)
343 {
344  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotSmallDialogs";
345 
346  m_modelMainWindowAfter->setSmallDialogs (m_chkSmallDialogs->isChecked());
347  updateControls ();
348 }
349 
350 void DlgSettingsMainWindow::slotTitleBarFormat(bool)
351 {
352  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotTitleBarFormat";
353 
354  m_modelMainWindowAfter->setMainTitleBarFormat(m_chkTitleBarFormat->isChecked() ?
355  MAIN_TITLE_BAR_FORMAT_PATH :
356  MAIN_TITLE_BAR_FORMAT_NO_PATH);
357  updateControls();
358 }
359 
360 void DlgSettingsMainWindow::slotZoomControl(const QString)
361 {
362  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotZoomControl";
363 
364  m_modelMainWindowAfter->setZoomControl ((ZoomControl) m_cmbZoomControl->currentData().toInt());
365  updateControls();
366 }
367 
368 void DlgSettingsMainWindow::slotZoomFactor(const QString)
369 {
370  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWIndow::slotZoomFactor";
371 
372  m_modelMainWindowAfter->setZoomFactorInitial((ZoomFactorInitial) m_cmbZoomFactor->currentData().toInt());
373  updateControls();
374 }
375 
376 void DlgSettingsMainWindow::updateControls ()
377 {
378  enableOk (true);
379 }
static QString importCroppingToString(ImportCropping importCropping)
Option as string for display to user.
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
void updateSettingsMainWindow(const MainWindowModel &modelMainWindow)
Update with new main window properties.
virtual void handleOk()
Process slotOk.
MainTitleBarFormat mainTitleBarFormat() const
Get method for MainWindow titlebar filename format.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
void setHighlightOpacity(double highlightOpacity)
Set method for highlight opacity.
void finishPanel(QWidget *subPanel, int minimumWidth=MINIMUM_DIALOG_WIDTH, int minimumHeightOrZero=0)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
void setLocale(QLocale::Language language, QLocale::Country country)
Set method for locale given attributes.
int maximumGridLines() const
Maximum number of grid lines.
void loadMainWindowModel(CmdMediator &cmdMediator, const MainWindowModel &modelMainWindow)
Replaced load method since the main window settings are independent of document, unlike other DlgSett...
bool smallDialogs() const
Get method for small dialogs flag.
virtual void load(CmdMediator &cmdMediator)
Load settings from Document.
DlgSettingsMainWindow(MainWindow &mainWindow)
Single constructor.
ZoomControl zoomControl() const
Get method for zoom control.
Model for DlgSettingsMainWindow.
void setMaximumGridLines(int maximumGridLines)
Set method for maximum number of grid lines.
double highlightOpacity() const
Get method for highlight opacity.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
int pdfResolution() const
Get method for resolution of imported PDF files, in dots per inch.
Utility class for import cropping options.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
void setZoomControl(ZoomControl zoomControl)
Set method for zoom control.
void setMainTitleBarFormat(MainTitleBarFormat mainTitleBarFormat)
Set method for MainWindow titlebar filename format.
Command queue stack.
Definition: CmdMediator.h:23
void setZoomFactorInitial(ZoomFactorInitial zoomFactorInitial)
Set method for initial zoom factor.
Abstract base class for all Settings dialogs.
ZoomFactorInitial zoomFactorInitial() const
Get method for initial zoom factor.
void setSmallDialogs(bool smallDialogs)
Set method for small dialogs flag.
ImportCropping importCropping() const
Get method for import cropping.
QLocale locale() const
Get method for locale.
MainWindow & mainWindow()
Get method for MainWindow.
void setPdfResolution(int resolution)
Set method for resolution of imported PDF files, in dots per inch.
void setImportCropping(ImportCropping importCropping)
Set method for import cropping.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:83