1 //-----------------------------------------------------------------------------
3 // KDE xscreensaver configuration dialog
5 // Copyright (c) Martin R. Jones <mjones@kde.org> 1999
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public
9 // License as published by the Free Software Foundation;
10 // version 2 of the License.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; see the file COPYING. If not, write to
19 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 // Boston, MA 02110-1301, USA.
25 #include <qcombobox.h>
26 #include <qlineedit.h>
28 #include <qpushbutton.h>
31 #include <QVBoxLayout>
32 #include <QHBoxLayout>
34 #include <kfiledialog.h>
35 #include "kxscontrol.h"
37 //===========================================================================
38 KXSRangeControl::KXSRangeControl(QWidget
*parent
, const QString
&name
,
40 : QWidget(parent
), KXSRangeItem(name
, config
), mSlider(0), mSpinBox(0)
42 QVBoxLayout
*l
= new QVBoxLayout(this);
43 QLabel
*label
= new QLabel(mLabel
, this);
45 mSlider
= new QSlider(Qt::Horizontal
, this);
46 mSlider
->setMinimum(mMinimum
);
47 mSlider
->setMaximum(mMaximum
);
48 mSlider
->setPageStep(10);
49 mSlider
->setValue(mValue
);
50 connect(mSlider
, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
51 l
->addWidget(mSlider
);
54 KXSRangeControl::KXSRangeControl(QWidget
*parent
, const QString
&name
,
55 const QXmlAttributes
&attr
)
56 : QWidget(parent
), KXSRangeItem(name
, attr
), mSlider(0), mSpinBox(0)
58 if (attr
.value("type") == "spinbutton" ) {
59 QHBoxLayout
*hb
= new QHBoxLayout(this);
60 if (!mLabel
.isEmpty()) {
61 QLabel
*l
= new QLabel(i18n(mLabel
.toUtf8()), this);
64 mSpinBox
= new QSpinBox(this);
65 mSpinBox
->setMinimum(mMinimum
);
66 mSpinBox
->setMaximum(mMaximum
);
67 mSpinBox
->setSingleStep(1);
68 mSpinBox
->setValue(mValue
);
69 connect(mSpinBox
, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
70 hb
->addWidget(mSpinBox
);
72 QString lowLabel
= attr
.value("_low-label");
73 QString highLabel
= attr
.value("_high-label");
74 QVBoxLayout
*vb
= new QVBoxLayout(this);
75 if (!mLabel
.isEmpty()) {
76 QLabel
*l
= new QLabel(i18n(mLabel
.toUtf8()), this);
79 QHBoxLayout
*hb
= new QHBoxLayout();
81 if (!lowLabel
.isEmpty()) {
82 QLabel
*l
= new QLabel(i18n(lowLabel
.toUtf8()), this);
85 mSlider
= new QSlider(Qt::Horizontal
, this);
86 mSlider
->setMinimum(mMinimum
);
87 mSlider
->setMaximum(mMaximum
);
88 mSlider
->setPageStep(10);
89 mSlider
->setValue(mValue
);
90 connect(mSlider
, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
91 hb
->addWidget(mSlider
);
92 if (!highLabel
.isEmpty()){
93 QLabel
*l
= new QLabel(i18n(highLabel
.toUtf8()), this);
99 void KXSRangeControl::slotValueChanged(int value
)
105 void KXSRangeControl::read(KConfig
&config
)
107 KXSRangeItem::read(config
);
109 mSpinBox
->setValue(mValue
);
111 mSlider
->setValue(mValue
);
114 //===========================================================================
115 KXSDoubleRangeControl::KXSDoubleRangeControl(QWidget
*parent
,
116 const QString
&name
, KConfig
&config
)
117 : QWidget(parent
), KXSDoubleRangeItem(name
, config
)
119 QVBoxLayout
*l
= new QVBoxLayout(this);
120 QLabel
*label
= new QLabel(mLabel
, this);
123 int value
= int((mValue
- mMinimum
) * 100 / (mMaximum
- mMinimum
));
125 mSlider
= new QSlider(Qt::Horizontal
, this);
126 mSlider
->setMinimum(0);
127 mSlider
->setMaximum(100);
128 mSlider
->setPageStep(10);
129 mSlider
->setValue(value
);
130 connect(mSlider
, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
131 l
->addWidget(mSlider
);
134 KXSDoubleRangeControl::KXSDoubleRangeControl(QWidget
*parent
,
135 const QString
&name
, const QXmlAttributes
&attr
)
136 : QWidget(parent
), KXSDoubleRangeItem(name
, attr
)
138 QString lowLabel
= attr
.value("_low-label");
139 QString highLabel
= attr
.value("_high-label");
140 QVBoxLayout
*vb
= new QVBoxLayout(this);
141 if (!mLabel
.isEmpty()) {
142 QLabel
*l
= new QLabel(i18n(mLabel
.toUtf8()), this);
145 QHBoxLayout
*hb
= new QHBoxLayout();
147 if (!lowLabel
.isEmpty()) {
148 QLabel
*l
= new QLabel(i18n(lowLabel
.toUtf8()), this);
151 int value
= int((mValue
- mMinimum
) * 100 / (mMaximum
- mMinimum
));
152 mSlider
= new QSlider(Qt::Horizontal
, this);
153 mSlider
->setMinimum(0);
154 mSlider
->setMaximum(100);
155 mSlider
->setPageStep(10);
156 mSlider
->setValue(value
);
157 connect(mSlider
, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
158 hb
->addWidget(mSlider
);
159 if (!highLabel
.isEmpty()){
160 QLabel
*l
= new QLabel(i18n(highLabel
.toUtf8()), this);
165 void KXSDoubleRangeControl::slotValueChanged(int value
)
167 mValue
= mMinimum
+ value
* (mMaximum
- mMinimum
) / 100.0;
171 void KXSDoubleRangeControl::read(KConfig
&config
)
173 KXSDoubleRangeItem::read(config
);
174 mSlider
->setValue((int)((mValue
- mMinimum
) * 100.0 /
175 (mMaximum
- mMinimum
) + 0.5));
178 //===========================================================================
179 KXSCheckBoxControl::KXSCheckBoxControl(QWidget
*parent
, const QString
&name
,
181 : QCheckBox(parent
), KXSBoolItem(name
, config
)
185 connect(this, SIGNAL(toggled(bool)), SLOT(slotToggled(bool)));
188 KXSCheckBoxControl::KXSCheckBoxControl(QWidget
*parent
, const QString
&name
,
189 const QXmlAttributes
&attr
)
190 : QCheckBox(parent
), KXSBoolItem(name
, attr
)
192 setText(i18n(mLabel
.toUtf8()));
194 connect(this, SIGNAL(toggled(bool)), SLOT(slotToggled(bool)));
197 void KXSCheckBoxControl::slotToggled(bool state
)
203 void KXSCheckBoxControl::read(KConfig
&config
)
205 KXSBoolItem::read(config
);
209 //===========================================================================
210 KXSDropListControl::KXSDropListControl(QWidget
*parent
, const QString
&name
,
212 : QWidget(parent
), KXSSelectItem(name
, config
)
214 QVBoxLayout
*l
= new QVBoxLayout(this);
215 QLabel
*label
= new QLabel(mLabel
, this);
217 mCombo
= new QComboBox(this);
218 for(int i
=0; i
< mOptions
.count(); i
++)
219 mCombo
->addItem( i18n(mOptions
[i
].toUtf8()) );
220 mCombo
->setCurrentIndex(mValue
);
221 connect(mCombo
, SIGNAL(activated(int)), SLOT(slotActivated(int)));
222 l
->addWidget(mCombo
);
225 KXSDropListControl::KXSDropListControl(QWidget
*parent
, const QString
&name
,
226 const QXmlAttributes
&attr
)
227 : QWidget(parent
), KXSSelectItem(name
, attr
)
229 QVBoxLayout
*l
= new QVBoxLayout(this);
230 QString labelText
= mLabel
.isEmpty() ? QString():i18n(mLabel
.toUtf8());
231 QLabel
*label
= new QLabel(labelText
, this);
233 mCombo
= new QComboBox(this);
234 connect(mCombo
, SIGNAL(activated(int)), SLOT(slotActivated(int)));
235 l
->addWidget(mCombo
);
238 void KXSDropListControl::addOption(const QXmlAttributes
&attr
)
240 KXSSelectItem::addOption( attr
);
241 mCombo
->addItem( i18n(mOptions
[mOptions
.count()-1].toUtf8()) );
242 if ( mValue
== mOptions
.count()-1 )
243 mCombo
->setCurrentIndex(mOptions
.count()-1);
246 void KXSDropListControl::slotActivated(int indx
)
252 void KXSDropListControl::read(KConfig
&config
)
254 KXSSelectItem::read(config
);
255 mCombo
->setCurrentIndex(mValue
);
258 //===========================================================================
259 KXSLineEditControl::KXSLineEditControl(QWidget
*parent
, const QString
&name
,
261 : QWidget(parent
), KXSStringItem(name
, config
)
263 QVBoxLayout
*l
= new QVBoxLayout(this);
264 QLabel
*label
= new QLabel(mLabel
, this);
266 mEdit
= new QLineEdit(this);
267 connect(mEdit
, SIGNAL(textChanged(const QString
&)), SLOT(textChanged(const QString
&)));
271 KXSLineEditControl::KXSLineEditControl(QWidget
*parent
, const QString
&name
,
272 const QXmlAttributes
&attr
)
273 : QWidget(parent
), KXSStringItem(name
, attr
)
275 QVBoxLayout
*l
= new QVBoxLayout(this);
276 QLabel
*label
= new QLabel(i18n(mLabel
.toUtf8()), this);
278 mEdit
= new QLineEdit(this);
279 connect(mEdit
, SIGNAL(textChanged(const QString
&)), SLOT(textChanged(const QString
&)));
283 void KXSLineEditControl::textChanged( const QString
&text
)
289 void KXSLineEditControl::read(KConfig
&config
)
291 KXSStringItem::read(config
);
292 mEdit
->setText(mValue
);
295 //===========================================================================
296 KXSFileControl::KXSFileControl(QWidget
*parent
, const QString
&name
,
298 : QWidget(parent
), KXSStringItem(name
, config
)
300 QVBoxLayout
*l
= new QVBoxLayout(this);
301 QLabel
*label
= new QLabel(mLabel
, this);
303 mEdit
= new QLineEdit(this);
304 connect(mEdit
, SIGNAL(textChanged(const QString
&)), SLOT(textChanged(const QString
&)));
308 KXSFileControl::KXSFileControl(QWidget
*parent
, const QString
&name
,
309 const QXmlAttributes
&attr
)
310 : QWidget(parent
), KXSStringItem(name
, attr
)
312 QVBoxLayout
*l
= new QVBoxLayout(this);
313 QLabel
*label
= new QLabel(i18n(mLabel
.toUtf8()), this);
315 QHBoxLayout
*hb
= new QHBoxLayout();
317 mEdit
= new QLineEdit(this);
318 connect(mEdit
, SIGNAL(textChanged(const QString
&)), SLOT(textChanged(const QString
&)));
319 hb
->addWidget(mEdit
);
320 QPushButton
*pb
= new QPushButton( "...", this );
321 connect( pb
, SIGNAL(clicked()), this, SLOT(selectFile()) );
325 void KXSFileControl::textChanged( const QString
&text
)
331 void KXSFileControl::selectFile()
333 QString f
= KFileDialog::getOpenFileName();
334 if ( !f
.isEmpty() ) {
336 mEdit
->setText(mValue
);
341 void KXSFileControl::read(KConfig
&config
)
343 KXSStringItem::read(config
);
344 mEdit
->setText(mValue
);
347 #include "kxscontrol.moc"