2 * Copyright (C) 2008 David Greaves
4 * This software is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public License
6 * as published by the Free Software Foundation; either version 2.1 of
7 * the License, or (at your option) any later version.
9 * This software is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this software; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 //#define DEBUG_SHOPPER 1
21 #include "shopper.h" // automake, i8n, gettext
23 #include "PreferencesDialog.h"
27 ////////////////////////////////////////////////////////////////
29 PreferencesDialog::PreferencesDialog( QWidget
* parent
) :
35 // UI pane and options
37 QGridLayout
*uiLayout
= new QGridLayout(uiPane
);
38 // Note that addPref returns a QCheckBox* chk that may be
39 // useful for a connect() to action a preference change in the UI.
40 addPref("ui/ShowCategoryHeadings", true, tr("Show Category Headings"), uiLayout
, 0);
41 addPref("ui/RotateOtherWay", false, tr("Rotate the other way"), uiLayout
, 1);
42 addPref("ui/RotateSafe", false, tr("Rotate to 'normal' on Exit"), uiLayout
, 2);
43 // addPref("ui/ShowTwoColumns", false, tr("Show Two Columns"), uiLayout, 2);
45 // Data pane and options
46 dataPane
= new QWidget
;
47 QGridLayout
*dataLayout
= new QGridLayout(dataPane
);
48 addPref("data/SaveOnExit", true, tr("Save On Exit"), dataLayout
, 0);
50 // Mapped settings send the "setting" for every toggle
51 connect(&signalMapper
, SIGNAL(mapped(const QString
&)),
52 this, SLOT(toggleSetting(const QString
&)));
54 // Add the panes to the tab widget
55 tabWidget
= new QTabWidget
;
56 tabWidget
->addTab(uiPane
, tr("View"));
57 tabWidget
->addTab(dataPane
, tr("Data"));
59 buttonBox
= new QDialogButtonBox(QDialogButtonBox::Ok
);
60 connect(buttonBox
, SIGNAL(accepted()), this, SLOT(accept()));
62 QVBoxLayout
*mainLayout
= new QVBoxLayout
;
63 mainLayout
->addWidget(tabWidget
);
64 mainLayout
->addWidget(buttonBox
);
65 setLayout(mainLayout
);
69 ////////////////////////////////////////////////////////////////
71 QCheckBox
* PreferencesDialog::addPref(const QString setting
, bool defaultVal
, QString label
, QGridLayout
*layout
, int row
)
74 bool value
= settings
.value(setting
, defaultVal
).toBool();
75 settings
.setValue(setting
, value
); // ensure that any default is saved
76 QLabel
*L
= new QLabel(label
);
77 QCheckBox
*Check
= new QCheckBox();
78 layout
->addWidget(L
, row
, 0);
79 layout
->addWidget(Check
, row
, 1);
80 Check
->setChecked(value
);
81 signalMapper
.setMapping(Check
, setting
);
82 connect(Check
, SIGNAL(released()), // ugh - but signalMapper can't cope with anything other than signal()
83 &signalMapper
, SLOT(map()));
87 void PreferencesDialog::toggleSetting(const QString setting
)
91 bool value
= settings
.value(setting
).toBool();
92 settings
.setValue(setting
, ! value
); // invert
93 DEBUG("Set " << setting
<< " from " << value
<< " to " << settings
.value(setting
).toBool());