00001
00002
00003
00004
00005
00006
00007 #include "DlgSettingsMainWindow.h"
00008 #include "EngaugeAssert.h"
00009 #include "ImportCropping.h"
00010 #include "ImportCroppingUtilBase.h"
00011 #include "Logger.h"
00012 #include "MainWindow.h"
00013 #include "MainWindowModel.h"
00014 #include <QCheckBox>
00015 #include <QComboBox>
00016 #include <QDoubleSpinBox>
00017 #include <QGraphicsScene>
00018 #include <QGridLayout>
00019 #include <QGroupBox>
00020 #include <QLabel>
00021 #include <qmath.h>
00022 #include <QPushButton>
00023 #include <QSpinBox>
00024 #include "QtToString.h"
00025 #include "ZoomControl.h"
00026 #include "ZoomFactorInitial.h"
00027 #include "ZoomLabels.h"
00028
00029 const int MAX_GRID_LINES_MIN = 2;
00030 const int MAX_GRID_LINES_MAX = 1000;
00031 const int MINIMUM_DIALOG_WIDTH_MAIN_WINDOW = 550;
00032
00033 DlgSettingsMainWindow::DlgSettingsMainWindow(MainWindow &mainWindow) :
00034 DlgSettingsAbstractBase (tr ("Main Window"),
00035 "DlgSettingsMainWindow",
00036 mainWindow),
00037 m_modelMainWindowBefore (0),
00038 m_modelMainWindowAfter (0)
00039 {
00040 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::DlgSettingsMainWindow";
00041
00042 QWidget *subPanel = createSubPanel ();
00043 finishPanel (subPanel,
00044 MINIMUM_DIALOG_WIDTH_MAIN_WINDOW);
00045 }
00046
00047 DlgSettingsMainWindow::~DlgSettingsMainWindow()
00048 {
00049 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::~DlgSettingsMainWindow";
00050 }
00051
00052 void DlgSettingsMainWindow::createControls (QGridLayout *layout,
00053 int &row)
00054 {
00055 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::createControls";
00056
00057 const int COLUMN0 = 0;
00058
00059 QLabel *labelZoomFactor = new QLabel (tr ("Initial zoom:"));
00060 layout->addWidget (labelZoomFactor, row, 1);
00061
00062 m_cmbZoomFactor = new QComboBox;
00063 m_cmbZoomFactor->addItem (LABEL_ZOOM_16_TO_1 , QVariant (ZOOM_INITIAL_16_TO_1));
00064 m_cmbZoomFactor->addItem (LABEL_ZOOM_8_TO_1 , QVariant (ZOOM_INITIAL_8_TO_1));
00065 m_cmbZoomFactor->addItem (LABEL_ZOOM_4_TO_1 , QVariant (ZOOM_INITIAL_4_TO_1));
00066 m_cmbZoomFactor->addItem (LABEL_ZOOM_2_TO_1 , QVariant (ZOOM_INITIAL_2_TO_1));
00067 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_1 , QVariant (ZOOM_INITIAL_1_TO_1));
00068 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_2 , QVariant (ZOOM_INITIAL_1_TO_2));
00069 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_4 , QVariant (ZOOM_INITIAL_1_TO_4));
00070 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_8 , QVariant (ZOOM_INITIAL_1_TO_8));
00071 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_16 , QVariant (ZOOM_INITIAL_1_TO_16));
00072 m_cmbZoomFactor->addItem (LABEL_ZOOM_FILL , QVariant (ZOOM_INITIAL_FILL));
00073 m_cmbZoomFactor->addItem (LABEL_ZOOM_PREVIOUS , QVariant (ZOOM_INITIAL_PREVIOUS));
00074 m_cmbZoomFactor->setWhatsThis(tr ("Initial Zoom\n\n"
00075 "Select the initial zoom factor when a new document is loaded. Either the previous "
00076 "zoom can be kept, or the specified zoom can be applied."));
00077 connect (m_cmbZoomFactor, SIGNAL (currentTextChanged (const QString)), this, SLOT (slotZoomFactor(const QString)));
00078 layout->addWidget (m_cmbZoomFactor, row++, 2);
00079
00080 QLabel *labelZoomControl = new QLabel (tr ("Zoom control:"));
00081 layout->addWidget (labelZoomControl, row, 1);
00082
00083 m_cmbZoomControl = new QComboBox;
00084 m_cmbZoomControl->addItem (tr ("Menu only" ), QVariant (ZOOM_CONTROL_MENU_ONLY));
00085 m_cmbZoomControl->addItem (tr ("Menu and mouse wheel" ), QVariant (ZOOM_CONTROL_MENU_WHEEL));
00086 m_cmbZoomControl->addItem (tr ("Menu and +/- keys" ), QVariant (ZOOM_CONTROL_MENU_PLUSMINUS));
00087 m_cmbZoomControl->addItem (tr ("Menu, mouse wheel and +/- keys"), QVariant (ZOOM_CONTROL_MENU_WHEEL_PLUSMINUS));
00088 m_cmbZoomControl->setWhatsThis (tr ("Zoom Control\n\n"
00089 "Select which inputs are used to zoom in and out."));
00090 connect (m_cmbZoomControl, SIGNAL (currentTextChanged (const QString)), this, SLOT (slotZoomControl(const QString)));
00091 layout->addWidget (m_cmbZoomControl, row++, 2);
00092
00093 QLabel *labelLocale = new QLabel (tr ("Locale:"));
00094 layout->addWidget (labelLocale, row, 1);
00095
00096
00097 m_cmbLocale = new QComboBox;
00098 m_cmbLocale->setWhatsThis(tr ("Locale\n\n"
00099 "Select the locale that will be used in numbers (immediately), and the language in the user "
00100 "interface (after restart).\n\n"
00101 "The locale determines how numbers are formatted. Specifically, either commas or "
00102 "periods will be used as group delimiters in each number entered "
00103 "by the user, displayed in the user interface, or exported to a file."));
00104 for (int indexLang = QLocale::C; indexLang <= QLocale::LastLanguage; indexLang++) {
00105 QLocale::Language lang = static_cast<QLocale::Language> (indexLang);
00106 QList<QLocale::Country> countries = QLocale::countriesForLanguage(lang);
00107 for (int indexCountry = 0; indexCountry < countries.count(); indexCountry++) {
00108 QLocale::Country country = countries.at(indexCountry);
00109 QLocale locale (lang, country);
00110 QString label = QLocaleToString (locale);
00111 m_cmbLocale->addItem (label, locale);
00112 }
00113 }
00114 m_cmbLocale->model()->sort(COLUMN0);
00115 connect (m_cmbLocale, SIGNAL (currentIndexChanged (int)), this, SLOT (slotLocale (int)));
00116 layout->addWidget (m_cmbLocale, row++, 2);
00117
00118 QLabel *labelImportCropping = new QLabel (tr ("Import cropping:"));
00119 layout->addWidget (labelImportCropping, row, 1);
00120
00121 m_cmbImportCropping = new QComboBox;
00122 m_cmbImportCropping->setWhatsThis (tr ("Import Cropping\n\n"
00123 "Enables or disables cropping of the imported image when importing. Cropping the image is useful "
00124 "for removing unimportant information around a graph, but less useful when the graph already fills "
00125 "the entire image.\n\n"
00126 "This setting only has an effect when Engauge has been built with support for pdf files."));
00127 ImportCroppingUtilBase importCroppingUtil;
00128 m_cmbImportCropping->addItem (importCroppingUtil.importCroppingToString (IMPORT_CROPPING_NEVER), IMPORT_CROPPING_NEVER);
00129 m_cmbImportCropping->addItem (importCroppingUtil.importCroppingToString (IMPORT_CROPPING_MULTIPAGE_PDFS), IMPORT_CROPPING_MULTIPAGE_PDFS);
00130 m_cmbImportCropping->addItem (importCroppingUtil.importCroppingToString (IMPORT_CROPPING_ALWAYS), IMPORT_CROPPING_ALWAYS);
00131 connect (m_cmbImportCropping, SIGNAL (currentIndexChanged (int)), this, SLOT (slotImportCropping (int)));
00132 layout->addWidget (m_cmbImportCropping, row++, 2);
00133
00134 #ifdef ENGAUGE_PDF
00135 QLabel *labelPdfResolution = new QLabel (tr ("Import PDF resolution (dots per inch):"));
00136 layout->addWidget (labelPdfResolution, row, 1);
00137
00138 m_cmbPdfResolution = new QComboBox;
00139 m_cmbPdfResolution->setWhatsThis (tr ("Import PDF Resolution\n\n"
00140 "Imported Portable Document Format (PDF) files will be converted to this pixel resolution "
00141 "in dots per inch (DPI), where each pixel is one dot. A higher value increases the picture resolution "
00142 "and may also improve numeric digitizing accuracy. However, a very high value can make the image so "
00143 "large that Engauge will slow down."));
00144 m_cmbPdfResolution->addItem ("75", 75);
00145 m_cmbPdfResolution->addItem ("100", 100);
00146 m_cmbPdfResolution->addItem ("150", 150);
00147 m_cmbPdfResolution->addItem ("200", 200);
00148 m_cmbPdfResolution->addItem ("250", 250);
00149 m_cmbPdfResolution->addItem ("300", 300);
00150 connect (m_cmbPdfResolution, SIGNAL (currentTextChanged (QString)), this, SLOT (slotPdfResolution (QString)));
00151 layout->addWidget (m_cmbPdfResolution, row++, 2);
00152 #endif
00153
00154 QLabel *labelMaximumGridLines = new QLabel (tr ("Maximum grid lines:"));
00155 layout->addWidget (labelMaximumGridLines, row, 1);
00156
00157 m_spinMaximumGridLines = new QSpinBox;
00158 m_spinMaximumGridLines->setRange (MAX_GRID_LINES_MIN, MAX_GRID_LINES_MAX);
00159 m_spinMaximumGridLines->setWhatsThis (tr ("Maximum Grid Lines\n\n"
00160 "Maximum number of grid lines to be processed. This limit is applied when the step value is too "
00161 "small for the start and stop values, which would result in too many grid lines visually and "
00162 "possibly extremely long processing time (since each grid line would have to be processed)"));
00163 connect (m_spinMaximumGridLines, SIGNAL (valueChanged (int)), this, (SLOT (slotMaximumGridLines (int))));
00164 layout->addWidget (m_spinMaximumGridLines, row++, 2);
00165
00166 QLabel *labelHighlightOpacity = new QLabel (tr ("Highlight opacity:"));
00167 layout->addWidget (labelHighlightOpacity, row, 1);
00168
00169 m_spinHighlightOpacity = new QDoubleSpinBox;
00170 m_spinHighlightOpacity->setRange (0, 1);
00171 m_spinHighlightOpacity->setSingleStep (0.1);
00172 m_spinHighlightOpacity->setWhatsThis (tr ("Highlight Opacity\n\n"
00173 "Opacity to be applied when the cursor is over a curve or axis point in Select mode. The change in "
00174 "appearance shows when the point can be selected."));
00175 connect (m_spinHighlightOpacity, SIGNAL (valueChanged (double)), this, SLOT (slotHighlightOpacity(double)));
00176 layout->addWidget (m_spinHighlightOpacity, row++, 2);
00177
00178 QLabel *labelRecent = new QLabel (tr ("Recent file list:"));
00179 layout->addWidget (labelRecent, row, 1);
00180
00181 m_btnRecentClear = new QPushButton (tr ("Clear"));
00182 m_btnRecentClear->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
00183 m_btnRecentClear->setWhatsThis (tr ("Recent File List Clear\n\n"
00184 "Clear the recent file list in the File menu."));
00185 connect (m_btnRecentClear, SIGNAL (pressed ()), &mainWindow(), SLOT (slotRecentFileClear ()));
00186 connect (m_btnRecentClear, SIGNAL (pressed ()), this, SLOT (slotRecentFileClear()));
00187 layout->addWidget (m_btnRecentClear, row++, 2);
00188
00189 QLabel *labelTitleBarFormat = new QLabel (tr ("Include title bar path:"));
00190 layout->addWidget (labelTitleBarFormat, row, 1);
00191
00192 m_chkTitleBarFormat = new QCheckBox;
00193 m_chkTitleBarFormat->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
00194 m_chkTitleBarFormat->setWhatsThis (tr ("Title Bar Filename\n\n"
00195 "Includes or excludes the path and file extension from the filename in the title bar."));
00196 connect (m_chkTitleBarFormat, SIGNAL (toggled (bool)), this, SLOT (slotTitleBarFormat(bool)));
00197 layout->addWidget (m_chkTitleBarFormat, row++, 2);
00198
00199 QLabel *labelSmallDialogs = new QLabel (tr ("Allow small dialogs:"));
00200 layout->addWidget (labelSmallDialogs, row, 1);
00201
00202 m_chkSmallDialogs = new QCheckBox;
00203 m_chkSmallDialogs->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
00204 m_chkSmallDialogs->setWhatsThis (tr ("Allow Small Dialogs\n\n"
00205 "Allows settings dialogs to be made very small so they fit on small computer screens."));
00206 connect (m_chkSmallDialogs, SIGNAL (toggled (bool)), this, SLOT (slotSmallDialogs (bool)));
00207 layout->addWidget (m_chkSmallDialogs, row++, 2);
00208
00209 QLabel *labelDragDropExport = new QLabel (tr ("Allow drag and drop export:"));
00210 layout->addWidget (labelDragDropExport, row, 1);
00211
00212 m_chkDragDropExport = new QCheckBox;
00213 m_chkDragDropExport->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
00214 m_chkDragDropExport->setWhatsThis (tr ("Allow Drag and Drop Export\n\n"
00215 "Allows drag and drop export from the Curve Fitting Window and Geometry Window tables.\n\n"
00216 "When drag and drop is disabled, a rectangular set of table cells can be selected using click and "
00217 "drag. When drag and drop is enabled, a rectangular set of table cells can be selected using Click "
00218 "then Shift+Click, since click and drag starts the drag operation."));
00219 connect (m_chkDragDropExport, SIGNAL (toggled (bool)), this, SLOT (slotDragDropExport (bool)));
00220 layout->addWidget (m_chkDragDropExport, row++, 2);
00221 }
00222
00223 void DlgSettingsMainWindow::createOptionalSaveDefault (QHBoxLayout * )
00224 {
00225 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::createOptionalSaveDefault";
00226 }
00227
00228 QWidget *DlgSettingsMainWindow::createSubPanel ()
00229 {
00230 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::createSubPanel";
00231
00232 QWidget *subPanel = new QWidget ();
00233 QGridLayout *layout = new QGridLayout (subPanel);
00234 subPanel->setLayout (layout);
00235
00236 layout->setColumnStretch(0, 1);
00237 layout->setColumnStretch(1, 0);
00238 layout->setColumnStretch(2, 0);
00239 layout->setColumnStretch(3, 1);
00240
00241 int row = 0;
00242 createControls (layout, row);
00243
00244 return subPanel;
00245 }
00246
00247 void DlgSettingsMainWindow::handleOk ()
00248 {
00249 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::handleOk";
00250
00251 mainWindow().updateSettingsMainWindow (*m_modelMainWindowAfter);
00252
00253 hide ();
00254 }
00255 void DlgSettingsMainWindow::load (CmdMediator & )
00256 {
00257 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::load";
00258
00259 ENGAUGE_ASSERT (false);
00260 }
00261
00262 void DlgSettingsMainWindow::loadMainWindowModel (CmdMediator &cmdMediator,
00263 const MainWindowModel &modelMainWindow)
00264 {
00265 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::loadMainWindowModel";
00266
00267 setCmdMediator (cmdMediator);
00268
00269
00270 if (m_modelMainWindowBefore != 0) {
00271 delete m_modelMainWindowBefore;
00272 }
00273 if (m_modelMainWindowAfter != 0) {
00274 delete m_modelMainWindowAfter;
00275 }
00276
00277
00278 m_modelMainWindowBefore = new MainWindowModel (modelMainWindow);
00279 m_modelMainWindowAfter = new MainWindowModel (modelMainWindow);
00280
00281
00282 int index = m_cmbZoomFactor->findData (m_modelMainWindowAfter->zoomFactorInitial());
00283 m_cmbZoomFactor->setCurrentIndex (index);
00284 index = m_cmbZoomControl->findData (m_modelMainWindowAfter->zoomControl());
00285 m_cmbZoomControl->setCurrentIndex (index);
00286 QString locLabel = QLocaleToString (m_modelMainWindowAfter->locale());
00287 index = m_cmbLocale->findText (locLabel);
00288 m_cmbLocale->setCurrentIndex(index);
00289 index = m_cmbImportCropping->findData (m_modelMainWindowAfter->importCropping());
00290 m_cmbImportCropping->setCurrentIndex (index);
00291 m_chkTitleBarFormat->setChecked (m_modelMainWindowAfter->mainTitleBarFormat() == MAIN_TITLE_BAR_FORMAT_PATH);
00292 #ifdef ENGAUGE_PDF
00293 index = m_cmbPdfResolution->findData (m_modelMainWindowAfter->pdfResolution());
00294 m_cmbPdfResolution->setCurrentIndex(index);
00295 #endif
00296 m_spinMaximumGridLines->setValue (m_modelMainWindowAfter->maximumGridLines());
00297 m_spinHighlightOpacity->setValue (m_modelMainWindowAfter->highlightOpacity());
00298 m_chkSmallDialogs->setChecked (m_modelMainWindowAfter->smallDialogs());
00299 m_chkDragDropExport->setChecked (m_modelMainWindowAfter->dragDropExport());
00300
00301 updateControls ();
00302 enableOk (false);
00303 }
00304
00305 void DlgSettingsMainWindow::setSmallDialogs(bool )
00306 {
00307 }
00308
00309 void DlgSettingsMainWindow::slotDragDropExport (bool)
00310 {
00311 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotDragDropExport";
00312
00313 m_modelMainWindowAfter->setDragDropExport (m_chkDragDropExport->isChecked());
00314 updateControls ();
00315 }
00316
00317 void DlgSettingsMainWindow::slotHighlightOpacity(double)
00318 {
00319 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotHighlightOpacity";
00320
00321 m_modelMainWindowAfter->setHighlightOpacity (m_spinHighlightOpacity->value());
00322 updateControls();
00323 }
00324
00325 void DlgSettingsMainWindow::slotImportCropping (int index)
00326 {
00327 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotImportCropping";
00328
00329 m_modelMainWindowAfter->setImportCropping ((ImportCropping) m_cmbImportCropping->itemData (index).toInt ());
00330 updateControls();
00331 }
00332
00333 void DlgSettingsMainWindow::slotLocale (int index)
00334 {
00335 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotLocale";
00336
00337 m_modelMainWindowAfter->setLocale (m_cmbLocale->itemData (index).toLocale());
00338 updateControls();
00339 }
00340
00341 void DlgSettingsMainWindow::slotMaximumGridLines (int limit)
00342 {
00343 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWIndow::slotMaximumGridLines";
00344
00345 m_modelMainWindowAfter->setMaximumGridLines (limit);
00346 updateControls ();
00347 }
00348
00349 void DlgSettingsMainWindow::slotPdfResolution(const QString)
00350 {
00351 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWIndow::slotPdfResolution";
00352
00353 #ifdef ENGAUGE_PDF
00354 m_modelMainWindowAfter->setPdfResolution(m_cmbPdfResolution->currentData().toInt());
00355 updateControls();
00356 #endif
00357 }
00358
00359 void DlgSettingsMainWindow::slotRecentFileClear()
00360 {
00361 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotRecentFileClear";
00362
00363
00364 updateControls();
00365 }
00366
00367 void DlgSettingsMainWindow::slotSmallDialogs (bool)
00368 {
00369 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotSmallDialogs";
00370
00371 m_modelMainWindowAfter->setSmallDialogs (m_chkSmallDialogs->isChecked());
00372 updateControls ();
00373 }
00374
00375 void DlgSettingsMainWindow::slotTitleBarFormat(bool)
00376 {
00377 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotTitleBarFormat";
00378
00379 m_modelMainWindowAfter->setMainTitleBarFormat(m_chkTitleBarFormat->isChecked() ?
00380 MAIN_TITLE_BAR_FORMAT_PATH :
00381 MAIN_TITLE_BAR_FORMAT_NO_PATH);
00382 updateControls();
00383 }
00384
00385 void DlgSettingsMainWindow::slotZoomControl(const QString)
00386 {
00387 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotZoomControl";
00388
00389 m_modelMainWindowAfter->setZoomControl ((ZoomControl) m_cmbZoomControl->currentData().toInt());
00390 updateControls();
00391 }
00392
00393 void DlgSettingsMainWindow::slotZoomFactor(const QString)
00394 {
00395 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWIndow::slotZoomFactor";
00396
00397 m_modelMainWindowAfter->setZoomFactorInitial((ZoomFactorInitial) m_cmbZoomFactor->currentData().toInt());
00398 updateControls();
00399 }
00400
00401 void DlgSettingsMainWindow::updateControls ()
00402 {
00403 enableOk (true);
00404 }