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