2 * Copyright (C) 2011 Toni Gundogdu <legatvs@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <QCoreApplication>
21 #include <QImageReader>
22 #include <QVBoxLayout>
23 #include <QHBoxLayout>
24 #include <QGridLayout>
25 #include <QFileDialog>
26 #include <QPushButton>
31 #include <NSettingsMutator>
32 #include <NSettingsDialog>
33 #include <NTripwireEdit>
36 extern nn::NSettingsMutator settings
; // main.cpp
41 NSettingsAppearance::NSettingsAppearance(QWidget
*parent
/*=NULL*/)
42 : NSettingsTabWidget(parent
)
48 QGridLayout
*iconsBox
= new QGridLayout
;
49 addGridRow(iconsBox
, tr("Application:"), &appEdit
, SLOT(browseApp()));
50 addGridRow(iconsBox
, tr("Busy:"), &busyEdit
, SLOT(browseBusy()));
51 addGridRow(iconsBox
, tr("Error:"), &errorEdit
, SLOT(browseError()));
53 QGroupBox
*gIcons
= new QGroupBox(tr("Icons"));
54 gIcons
->setLayout(iconsBox
);
59 langCombo
= new QComboBox
;
60 langCombo
->addItem("English");
62 foreach (const lang::NResultPair p
, lang::qm_files())
64 langCombo
->addItem(p
.first
);
67 QHBoxLayout
*langBox
= new QHBoxLayout
;
68 langBox
->addWidget(langCombo
);
69 langBox
->addStretch(0);
71 QGroupBox
*gLang
= new QGroupBox(tr("Language"));
72 gLang
->setLayout(langBox
);
76 QVBoxLayout
*box
= new QVBoxLayout
;
78 box
->addWidget(gIcons
);
80 box
->addWidget(gLang
);
85 void NSettingsAppearance::addGridRow(QGridLayout
*g
,
90 QLabel
*l
= new QLabel(text
);
91 *e
= new NTripwireEdit
;
94 (*e
)->setReadOnly(true);
95 (*e
)->setToolTip(tr("Leave empty for application default"));
97 connect(*e
, SIGNAL(entered()), this, slot
);
99 QPushButton
*b
= new QPushButton
;
100 b
->setIcon(QIcon(":/images/edit-clear.png"));
101 b
->setToolTip(tr("Clear"));
103 connect(b
, SIGNAL(clicked()), *e
, SLOT(clear()));
105 const int row
= g
->rowCount() + 1;
107 g
->addWidget(l
, row
, 0);
108 g
->addWidget(*e
, row
, 1);
109 g
->addWidget(b
, row
, 2);
112 void NSettingsAppearance::init()
116 void NSettingsAppearance::read()
119 appEdit
->setText(settings
.value(CustomApplicationIcon
).toString());
120 busyEdit
->setText(settings
.value(CustomBusyIcon
).toString());
121 errorEdit
->setText(settings
.value(CustomErrorIcon
).toString());
123 const int n
= langCombo
->findText(settings
.value(Language
).toString());
125 langCombo
->setCurrentIndex(n
);
128 void NSettingsAppearance::write()
131 settings
.setValue(CustomApplicationIcon
, appEdit
->text());
132 settings
.setValue(CustomBusyIcon
, busyEdit
->text());
133 settings
.setValue(CustomErrorIcon
, errorEdit
->text());
135 settings
.setValue(Language
, langCombo
->currentText());
138 bool NSettingsAppearance::verify(QString
&)
143 static QString
construct_filter()
146 qApp
->translate("nn::NSettingsAppearance","Images") + " (";
148 foreach(QByteArray b
, QImageReader::supportedImageFormats())
150 filter
+= "*." +b
+ " ";
153 filter
= filter
.simplified();
159 static bool browse(QWidget
*parent
, QString
& fname
)
161 fname
= QFileDialog::getOpenFileName(
163 qApp
->translate("nn::NSettingsAppearance", "Open image"),
166 return ! fname
.isEmpty();
170 void NSettingsAppearance::browseApp()
173 if (browse(this, fname
))
174 appEdit
->setText(fname
);
177 void NSettingsAppearance::browseBusy()
180 if (browse(this, fname
))
181 busyEdit
->setText(fname
);
184 void NSettingsAppearance::browseError()
187 if (browse(this, fname
))
188 errorEdit
->setText(fname
);
194 /* vim: set ts=2 sw=2 tw=72 expandtab: */