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