1 #include "CmdSettingsMainWindow.h"
2 #include "DlgSettingsMainWindow.h"
3 #include "EngaugeAssert.h"
5 #include "MainWindow.h"
6 #include "MainWindowModel.h"
8 #include <QGraphicsScene>
13 #include <QPushButton>
17 #include "ZoomControl.h"
18 #include "ZoomFactorInitial.h"
19 #include "ZoomLabels.h"
23 "DlgSettingsMainWindow",
25 m_modelMainWindowBefore (0),
26 m_modelMainWindowAfter (0)
28 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsMainWindow::DlgSettingsMainWindow";
34 DlgSettingsMainWindow::~DlgSettingsMainWindow()
36 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsMainWindow::~DlgSettingsMainWindow";
39 void DlgSettingsMainWindow::createControls (QGridLayout *layout,
42 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsMainWindow::createControls";
44 const int COLUMN0 = 0;
46 QLabel *labelZoomFactor =
new QLabel (
"Initial zoom:");
47 layout->addWidget (labelZoomFactor, row, 1);
49 m_cmbZoomFactor =
new QComboBox;
50 m_cmbZoomFactor->addItem (LABEL_ZOOM_16_TO_1 , QVariant (ZOOM_INITIAL_16_TO_1));
51 m_cmbZoomFactor->addItem (LABEL_ZOOM_8_TO_1 , QVariant (ZOOM_INITIAL_8_TO_1));
52 m_cmbZoomFactor->addItem (LABEL_ZOOM_4_TO_1 , QVariant (ZOOM_INITIAL_4_TO_1));
53 m_cmbZoomFactor->addItem (LABEL_ZOOM_2_TO_1 , QVariant (ZOOM_INITIAL_2_TO_1));
54 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_1 , QVariant (ZOOM_INITIAL_1_TO_1));
55 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_2 , QVariant (ZOOM_INITIAL_1_TO_2));
56 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_4 , QVariant (ZOOM_INITIAL_1_TO_4));
57 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_8 , QVariant (ZOOM_INITIAL_1_TO_8));
58 m_cmbZoomFactor->addItem (LABEL_ZOOM_1_TO_16 , QVariant (ZOOM_INITIAL_1_TO_16));
59 m_cmbZoomFactor->addItem (LABEL_ZOOM_FILL , QVariant (ZOOM_INITIAL_FILL));
60 m_cmbZoomFactor->addItem (LABEL_ZOOM_PREVIOUS , QVariant (ZOOM_INITIAL_PREVIOUS));
61 m_cmbZoomFactor->setWhatsThis(tr (
"Initial Zoom\n\n"
62 "Select the initial zoom factor when a new document is loaded. Either the previous "
63 "zoom can be kept, or the specified zoom can be applied."));
64 connect (m_cmbZoomFactor, SIGNAL (currentTextChanged (
const QString)),
this, SLOT (slotZoomFactor(
const QString)));
65 layout->addWidget (m_cmbZoomFactor, row++, 2);
67 QLabel *labelZoomControl =
new QLabel (
"Zoom control:");
68 layout->addWidget (labelZoomControl, row, 1);
70 m_cmbZoomControl =
new QComboBox;
71 m_cmbZoomControl->addItem (
"Menu only" , QVariant (ZOOM_CONTROL_MENU_ONLY));
72 m_cmbZoomControl->addItem (
"Menu and mouse wheel" , QVariant (ZOOM_CONTROL_MENU_WHEEL));
73 m_cmbZoomControl->addItem (
"Menu and +/- keys" , QVariant (ZOOM_CONTROL_MENU_PLUSMINUS));
74 m_cmbZoomControl->addItem (
"Menu, mouse wheel and +/- keys", QVariant (ZOOM_CONTROL_MENU_WHEEL_PLUSMINUS));
75 m_cmbZoomControl->setWhatsThis (tr (
"Zoom Control\n\n"
76 "Select which inputs are used to zoom in and out."));
77 connect (m_cmbZoomControl, SIGNAL (currentTextChanged (
const QString)),
this, SLOT (slotZoomControl(
const QString)));
78 layout->addWidget (m_cmbZoomControl, row++, 2);
80 QLabel *labelLocale =
new QLabel (
"Locale:");
81 layout->addWidget (labelLocale, row, 1);
84 m_cmbLocale =
new QComboBox;
85 m_cmbLocale->setWhatsThis(tr (
"Locale\n\n"
86 "Select the locale that will be used when converting between numbers and strings. "
87 "This affects the use of commas or periods as group delimiters in each number entered "
88 "by the user, displayed in the user interface, or exported to a file."));
89 for (
int indexLang = QLocale::C; indexLang <= QLocale::LastLanguage; indexLang++) {
90 QLocale::Language lang =
static_cast<QLocale::Language
> (indexLang);
91 QList<QLocale::Country> countries = QLocale::countriesForLanguage(lang);
92 for (
int indexCountry = 0; indexCountry < countries.count(); indexCountry++) {
93 QLocale::Country country = countries.at(indexCountry);
94 QString label = localeLabel (lang,
96 QLocale locale (lang, country);
97 m_cmbLocale->addItem (label, locale);
100 m_cmbLocale->model()->sort(COLUMN0);
101 connect (m_cmbLocale, SIGNAL (currentIndexChanged (
int)),
this, SLOT (slotLocale (
int)));
102 layout->addWidget (m_cmbLocale, row++, 2);
108 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsMainWindow::createOptionalSaveDefault";
113 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsMainWindow::createSubPanel";
115 QWidget *subPanel =
new QWidget ();
116 QGridLayout *layout =
new QGridLayout (subPanel);
117 subPanel->setLayout (layout);
119 layout->setColumnStretch(0, 1);
120 layout->setColumnStretch(1, 0);
121 layout->setColumnStretch(2, 0);
122 layout->setColumnStretch(3, 1);
125 createControls (layout, row);
132 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsMainWindow::handleOk";
136 *m_modelMainWindowBefore,
137 *m_modelMainWindowAfter);
144 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsMainWindow::load";
146 ENGAUGE_ASSERT (
false);
152 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsMainWindow::loadMainWindowModel";
157 if (m_modelMainWindowBefore != 0) {
158 delete m_modelMainWindowBefore;
160 if (m_modelMainWindowAfter != 0) {
161 delete m_modelMainWindowAfter;
169 int index = m_cmbZoomFactor->findData (m_modelMainWindowAfter->
zoomFactorInitial());
170 m_cmbZoomFactor->setCurrentIndex (index);
171 index = m_cmbZoomControl->findData (m_modelMainWindowAfter->
zoomControl());
172 m_cmbZoomControl->setCurrentIndex (index);
173 QString locLabel = localeLabel (m_modelMainWindowAfter->
locale().language(),
174 m_modelMainWindowBefore->
locale().country());
175 index = m_cmbLocale->findText (locLabel);
176 m_cmbLocale->setCurrentIndex(index);
182 QString DlgSettingsMainWindow::localeLabel (QLocale::Language lang,
183 QLocale::Country country)
const
185 return QString (
"%1/%2")
186 .arg (QLocale::languageToString (lang))
187 .arg (QLocale::countryToString(country));
190 void DlgSettingsMainWindow::slotLocale (
int index)
192 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsMainWindow::slotLocale";
194 m_modelMainWindowAfter->
setLocale (m_cmbLocale->itemData (index).toLocale());
198 void DlgSettingsMainWindow::slotZoomControl(
const QString)
200 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsMainWindow::slotZoomControl";
202 m_modelMainWindowAfter->
setZoomControl ((ZoomControl) m_cmbZoomControl->currentData().toInt());
206 void DlgSettingsMainWindow::slotZoomFactor(
const QString)
208 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsMainWIndow::slotZoomFactor";
210 m_modelMainWindowAfter->
setZoomFactorInitial((ZoomFactorInitial) m_cmbZoomFactor->currentData().toInt());
214 void DlgSettingsMainWindow::updateControls ()
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
virtual void handleOk()
Process slotOk.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
void setLocale(QLocale::Language language, QLocale::Country country)
Set method for locale given attributes.
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 and CmdSettingsMainWindow.
Command for DlgSettingsMainWindow.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
void finishPanel(QWidget *subPanel)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
void setZoomControl(ZoomControl zoomControl)
Set method for zoom control.
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.
QLocale locale() const
Get method for locale.
MainWindow & mainWindow()
Get method for MainWindow.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.