00001
00002
00003
00004
00005
00006
00007 #include "DlgSettingsMainWindow.h"
00008 #include "EngaugeAssert.h"
00009 #include "Logger.h"
00010 #include "MainWindow.h"
00011 #include "MainWindowModel.h"
00012 #include <QCheckBox>
00013 #include <QComboBox>
00014 #include <QGraphicsScene>
00015 #include <QGridLayout>
00016 #include <QGroupBox>
00017 #include <QLabel>
00018 #include <qmath.h>
00019 #include <QPushButton>
00020 #include <QSettings>
00021 #include <QSpinBox>
00022 #include "QtToString.h"
00023 #include "Settings.h"
00024 #include "ZoomControl.h"
00025 #include "ZoomFactorInitial.h"
00026 #include "ZoomLabels.h"
00027
00028 DlgSettingsMainWindow::DlgSettingsMainWindow(MainWindow &mainWindow) :
00029 DlgSettingsAbstractBase (tr ("Main Window"),
00030 "DlgSettingsMainWindow",
00031 mainWindow),
00032 m_modelMainWindowBefore (0),
00033 m_modelMainWindowAfter (0)
00034 {
00035 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::DlgSettingsMainWindow";
00036
00037 QWidget *subPanel = createSubPanel ();
00038 finishPanel (subPanel);
00039 }
00040
00041 DlgSettingsMainWindow::~DlgSettingsMainWindow()
00042 {
00043 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::~DlgSettingsMainWindow";
00044 }
00045
00046 void DlgSettingsMainWindow::createControls (QGridLayout *layout,
00047 int &row)
00048 {
00049 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::createControls";
00050
00051 const int COLUMN0 = 0;
00052
00053 QLabel *labelZoomFactor = new QLabel (tr ("Initial zoom:"));
00054 layout->addWidget (labelZoomFactor, row, 1);
00055
00056 m_cmbZoomFactor = new QComboBox;
00057 m_cmbZoomFactor->addItem (LABEL_ZOOM_16_TO_1 , QVariant (ZOOM_INITIAL_16_TO_1));
00058 m_cmbZoomFactor->addItem (LABEL_ZOOM_8_TO_1 , QVariant (ZOOM_INITIAL_8_TO_1));
00059 m_cmbZoomFactor->addItem (LABEL_ZOOM_4_TO_1 , QVariant (ZOOM_INITIAL_4_TO_1));
00060 m_cmbZoomFactor->addItem (LABEL_ZOOM_2_TO_1 , QVariant (ZOOM_INITIAL_2_TO_1));
00061 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_1 , QVariant (ZOOM_INITIAL_1_TO_1));
00062 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_2 , QVariant (ZOOM_INITIAL_1_TO_2));
00063 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_4 , QVariant (ZOOM_INITIAL_1_TO_4));
00064 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_8 , QVariant (ZOOM_INITIAL_1_TO_8));
00065 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_16 , QVariant (ZOOM_INITIAL_1_TO_16));
00066 m_cmbZoomFactor->addItem (LABEL_ZOOM_FILL , QVariant (ZOOM_INITIAL_FILL));
00067 m_cmbZoomFactor->addItem (LABEL_ZOOM_PREVIOUS , QVariant (ZOOM_INITIAL_PREVIOUS));
00068 m_cmbZoomFactor->setWhatsThis(tr ("Initial Zoom\n\n"
00069 "Select the initial zoom factor when a new document is loaded. Either the previous "
00070 "zoom can be kept, or the specified zoom can be applied."));
00071 connect (m_cmbZoomFactor, SIGNAL (currentTextChanged (const QString)), this, SLOT (slotZoomFactor(const QString)));
00072 layout->addWidget (m_cmbZoomFactor, row++, 2);
00073
00074 QLabel *labelZoomControl = new QLabel (tr ("Zoom control:"));
00075 layout->addWidget (labelZoomControl, row, 1);
00076
00077 m_cmbZoomControl = new QComboBox;
00078 m_cmbZoomControl->addItem (tr ("Menu only" ), QVariant (ZOOM_CONTROL_MENU_ONLY));
00079 m_cmbZoomControl->addItem (tr ("Menu and mouse wheel" ), QVariant (ZOOM_CONTROL_MENU_WHEEL));
00080 m_cmbZoomControl->addItem (tr ("Menu and +/- keys" ), QVariant (ZOOM_CONTROL_MENU_PLUSMINUS));
00081 m_cmbZoomControl->addItem (tr ("Menu, mouse wheel and +/- keys"), QVariant (ZOOM_CONTROL_MENU_WHEEL_PLUSMINUS));
00082 m_cmbZoomControl->setWhatsThis (tr ("Zoom Control\n\n"
00083 "Select which inputs are used to zoom in and out."));
00084 connect (m_cmbZoomControl, SIGNAL (currentTextChanged (const QString)), this, SLOT (slotZoomControl(const QString)));
00085 layout->addWidget (m_cmbZoomControl, row++, 2);
00086
00087 QLabel *labelLocale = new QLabel (tr ("Locale:"));
00088 layout->addWidget (labelLocale, row, 1);
00089
00090
00091 m_cmbLocale = new QComboBox;
00092 m_cmbLocale->setWhatsThis(tr ("Locale\n\n"
00093 "Select the locale that will be used in numbers (immediately), and the language in the user "
00094 "interface (after restart).\n\n"
00095 "The locale determines how numbers are formatted. Specifically, either commas or "
00096 "periods will be used as group delimiters in each number entered "
00097 "by the user, displayed in the user interface, or exported to a file."));
00098 for (int indexLang = QLocale::C; indexLang <= QLocale::LastLanguage; indexLang++) {
00099 QLocale::Language lang = static_cast<QLocale::Language> (indexLang);
00100 QList<QLocale::Country> countries = QLocale::countriesForLanguage(lang);
00101 for (int indexCountry = 0; indexCountry < countries.count(); indexCountry++) {
00102 QLocale::Country country = countries.at(indexCountry);
00103 QLocale locale (lang, country);
00104 QString label = QLocaleToString (locale);
00105 m_cmbLocale->addItem (label, locale);
00106 }
00107 }
00108 m_cmbLocale->model()->sort(COLUMN0);
00109 connect (m_cmbLocale, SIGNAL (currentIndexChanged (int)), this, SLOT (slotLocale (int)));
00110 layout->addWidget (m_cmbLocale, row++, 2);
00111
00112 QLabel *labelRecent = new QLabel (tr ("Recent file list:"));
00113 layout->addWidget (labelRecent, row, 1);
00114
00115 m_btnRecentClear = new QPushButton (tr ("Clear"));
00116 m_btnRecentClear->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
00117 m_btnRecentClear->setWhatsThis (tr ("Recent File List Clear\n\n"
00118 "Clear the recent file list in the File menu."));
00119 connect (m_btnRecentClear, SIGNAL (pressed ()), &mainWindow(), SLOT (slotRecentFileClear ()));
00120 connect (m_btnRecentClear, SIGNAL (pressed ()), this, SLOT (slotRecentFileClear()));
00121 layout->addWidget (m_btnRecentClear, row++, 2);
00122
00123 QLabel *labelTitleBarFormat = new QLabel (tr ("Include title bar path:"));
00124 layout->addWidget (labelTitleBarFormat, row, 1);
00125
00126 m_chkTitleBarFormat = new QCheckBox;
00127 m_chkTitleBarFormat->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
00128 m_chkTitleBarFormat->setWhatsThis (tr ("Title Bar Filename\n\n"
00129 "Includes or excludes the path and file extension from the filename in the title bar."));
00130 connect (m_chkTitleBarFormat, SIGNAL (toggled (bool)), this, SLOT (slotTitleBarFormat(bool)));
00131 layout->addWidget (m_chkTitleBarFormat, row++, 2);
00132 }
00133
00134 void DlgSettingsMainWindow::createOptionalSaveDefault (QHBoxLayout * )
00135 {
00136 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::createOptionalSaveDefault";
00137 }
00138
00139 QWidget *DlgSettingsMainWindow::createSubPanel ()
00140 {
00141 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::createSubPanel";
00142
00143 QWidget *subPanel = new QWidget ();
00144 QGridLayout *layout = new QGridLayout (subPanel);
00145 subPanel->setLayout (layout);
00146
00147 layout->setColumnStretch(0, 1);
00148 layout->setColumnStretch(1, 0);
00149 layout->setColumnStretch(2, 0);
00150 layout->setColumnStretch(3, 1);
00151
00152 int row = 0;
00153 createControls (layout, row);
00154
00155 return subPanel;
00156 }
00157
00158 void DlgSettingsMainWindow::handleOk ()
00159 {
00160 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::handleOk";
00161
00162 mainWindow().updateSettingsMainWindow (*m_modelMainWindowAfter);
00163
00164 hide ();
00165 }
00166 void DlgSettingsMainWindow::load (CmdMediator & )
00167 {
00168 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::load";
00169
00170 ENGAUGE_ASSERT (false);
00171 }
00172
00173 void DlgSettingsMainWindow::loadMainWindowModel (CmdMediator &cmdMediator,
00174 const MainWindowModel &modelMainWindow)
00175 {
00176 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::loadMainWindowModel";
00177
00178 setCmdMediator (cmdMediator);
00179
00180
00181 if (m_modelMainWindowBefore != 0) {
00182 delete m_modelMainWindowBefore;
00183 }
00184 if (m_modelMainWindowAfter != 0) {
00185 delete m_modelMainWindowAfter;
00186 }
00187
00188
00189 m_modelMainWindowBefore = new MainWindowModel (modelMainWindow);
00190 m_modelMainWindowAfter = new MainWindowModel (modelMainWindow);
00191
00192
00193 int index = m_cmbZoomFactor->findData (m_modelMainWindowAfter->zoomFactorInitial());
00194 m_cmbZoomFactor->setCurrentIndex (index);
00195 index = m_cmbZoomControl->findData (m_modelMainWindowAfter->zoomControl());
00196 m_cmbZoomControl->setCurrentIndex (index);
00197 QString locLabel = QLocaleToString (m_modelMainWindowAfter->locale());
00198 index = m_cmbLocale->findText (locLabel);
00199 m_cmbLocale->setCurrentIndex(index);
00200 m_chkTitleBarFormat->setChecked (m_modelMainWindowAfter->mainTitleBarFormat() == MAIN_TITLE_BAR_FORMAT_PATH);
00201
00202 updateControls ();
00203 enableOk (false);
00204 }
00205
00206 void DlgSettingsMainWindow::slotLocale (int index)
00207 {
00208 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotLocale";
00209
00210 m_modelMainWindowAfter->setLocale (m_cmbLocale->itemData (index).toLocale());
00211 updateControls();
00212 }
00213
00214 void DlgSettingsMainWindow::slotRecentFileClear()
00215 {
00216 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotRecentFileClear";
00217
00218
00219 updateControls();
00220 }
00221
00222 void DlgSettingsMainWindow::slotTitleBarFormat(bool)
00223 {
00224 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotTitleBarFormat";
00225
00226 m_modelMainWindowAfter->setMainTitleBarFormat(m_chkTitleBarFormat->isChecked() ?
00227 MAIN_TITLE_BAR_FORMAT_PATH :
00228 MAIN_TITLE_BAR_FORMAT_NO_PATH);
00229 updateControls();
00230 }
00231
00232 void DlgSettingsMainWindow::slotZoomControl(const QString)
00233 {
00234 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWindow::slotZoomControl";
00235
00236 m_modelMainWindowAfter->setZoomControl ((ZoomControl) m_cmbZoomControl->currentData().toInt());
00237 updateControls();
00238 }
00239
00240 void DlgSettingsMainWindow::slotZoomFactor(const QString)
00241 {
00242 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsMainWIndow::slotZoomFactor";
00243
00244 m_modelMainWindowAfter->setZoomFactorInitial((ZoomFactorInitial) m_cmbZoomFactor->currentData().toInt());
00245 updateControls();
00246 }
00247
00248 void DlgSettingsMainWindow::updateControls ()
00249 {
00250 enableOk (true);
00251 }