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(mMinimum
, mMaximum
, 10, mValue
, Qt::Horizontal
, this);
46 connect(mSlider
, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
50 KXSRangeControl::KXSRangeControl(QWidget
*parent
, const QString
&name
,
51 const QXmlAttributes
&attr
)
52 : QWidget(parent
), KXSRangeItem(name
, attr
), mSlider(0), mSpinBox(0)
54 if (attr
.value("type") == "spinbutton" ) {
55 QHBoxLayout
*hb
= new QHBoxLayout(this);
56 if (!mLabel
.isEmpty()) {
57 QLabel
*l
= new QLabel(mLabel
, this);
60 mSpinBox
= new QSpinBox(mMinimum
, mMaximum
, 1, this);
61 mSpinBox
->setValue(mValue
);
62 connect(mSpinBox
, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
65 QString lowLabel
= attr
.value("_low-label");
66 QString highLabel
= attr
.value("_high-label");
67 QVBoxLayout
*vb
= new QVBoxLayout(this);
68 if (!mLabel
.isEmpty()) {
69 QLabel
*l
= new QLabel(mLabel
, this);
72 QHBoxLayout
*hb
= new QHBoxLayout(vb
);
73 if (!lowLabel
.isEmpty()) {
74 QLabel
*l
= new QLabel(lowLabel
, this);
77 mSlider
= new QSlider(mMinimum
, mMaximum
, 10, mValue
, Qt::Horizontal
, this);
78 connect(mSlider
, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
80 if (!highLabel
.isEmpty()){
81 QLabel
*l
= new QLabel(highLabel
, this);
87 void KXSRangeControl::slotValueChanged(int value
)
93 void KXSRangeControl::read(KConfig
&config
)
95 KXSRangeItem::read(config
);
97 mSpinBox
->setValue(mValue
);
99 mSlider
->setValue(mValue
);
102 //===========================================================================
103 KXSDoubleRangeControl::KXSDoubleRangeControl(QWidget
*parent
,
104 const QString
&name
, KConfig
&config
)
105 : QWidget(parent
), KXSDoubleRangeItem(name
, config
)
107 QVBoxLayout
*l
= new QVBoxLayout(this);
108 QLabel
*label
= new QLabel(mLabel
, this);
111 int value
= int((mValue
- mMinimum
) * 100 / (mMaximum
- mMinimum
));
113 mSlider
= new QSlider(0, 100, 10, value
, Qt::Horizontal
, this);
114 connect(mSlider
, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
118 KXSDoubleRangeControl::KXSDoubleRangeControl(QWidget
*parent
,
119 const QString
&name
, const QXmlAttributes
&attr
)
120 : QWidget(parent
), KXSDoubleRangeItem(name
, attr
)
122 QString lowLabel
= attr
.value("_low-label");
123 QString highLabel
= attr
.value("_high-label");
124 QVBoxLayout
*vb
= new QVBoxLayout(this);
125 if (!mLabel
.isEmpty()) {
126 QLabel
*l
= new QLabel(mLabel
, this);
129 QHBoxLayout
*hb
= new QHBoxLayout(vb
);
130 if (!lowLabel
.isEmpty()) {
131 QLabel
*l
= new QLabel(lowLabel
, this);
134 int value
= int((mValue
- mMinimum
) * 100 / (mMaximum
- mMinimum
));
135 mSlider
= new QSlider(0, 100, 10, value
, Qt::Horizontal
, this);
136 connect(mSlider
, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
138 if (!highLabel
.isEmpty()){
139 QLabel
*l
= new QLabel(highLabel
, this);
144 void KXSDoubleRangeControl::slotValueChanged(int value
)
146 mValue
= mMinimum
+ value
* (mMaximum
- mMinimum
) / 100.0;
150 void KXSDoubleRangeControl::read(KConfig
&config
)
152 KXSDoubleRangeItem::read(config
);
153 mSlider
->setValue((int)((mValue
- mMinimum
) * 100.0 /
154 (mMaximum
- mMinimum
) + 0.5));
157 //===========================================================================
158 KXSCheckBoxControl::KXSCheckBoxControl(QWidget
*parent
, const QString
&name
,
160 : QCheckBox(parent
), KXSBoolItem(name
, config
)
164 connect(this, SIGNAL(toggled(bool)), SLOT(slotToggled(bool)));
167 KXSCheckBoxControl::KXSCheckBoxControl(QWidget
*parent
, const QString
&name
,
168 const QXmlAttributes
&attr
)
169 : QCheckBox(parent
), KXSBoolItem(name
, attr
)
173 connect(this, SIGNAL(toggled(bool)), SLOT(slotToggled(bool)));
176 void KXSCheckBoxControl::slotToggled(bool state
)
182 void KXSCheckBoxControl::read(KConfig
&config
)
184 KXSBoolItem::read(config
);
188 //===========================================================================
189 KXSDropListControl::KXSDropListControl(QWidget
*parent
, const QString
&name
,
191 : QWidget(parent
), KXSSelectItem(name
, config
)
193 QVBoxLayout
*l
= new QVBoxLayout(this);
194 QLabel
*label
= new QLabel(mLabel
, this);
196 mCombo
= new QComboBox(this);
197 for(uint i
=0; i
< mOptions
.count(); i
++)
198 mCombo
->insertItem( mOptions
[i
] );
199 mCombo
->setCurrentItem(mValue
);
200 connect(mCombo
, SIGNAL(activated(int)), SLOT(slotActivated(int)));
204 KXSDropListControl::KXSDropListControl(QWidget
*parent
, const QString
&name
,
205 const QXmlAttributes
&attr
)
206 : QWidget(parent
), KXSSelectItem(name
, attr
)
208 QVBoxLayout
*l
= new QVBoxLayout(this);
209 QLabel
*label
= new QLabel(mLabel
, this);
211 mCombo
= new QComboBox(this);
212 connect(mCombo
, SIGNAL(activated(int)), SLOT(slotActivated(int)));
216 void KXSDropListControl::addOption(const QXmlAttributes
&attr
)
218 KXSSelectItem::addOption( attr
);
219 mCombo
->insertItem( mOptions
[mOptions
.count()-1] );
220 if ( (unsigned)mValue
== mOptions
.count()-1 )
221 mCombo
->setCurrentItem(mOptions
.count()-1);
224 void KXSDropListControl::slotActivated(int indx
)
230 void KXSDropListControl::read(KConfig
&config
)
232 KXSSelectItem::read(config
);
233 mCombo
->setCurrentItem(mValue
);
236 //===========================================================================
237 KXSLineEditControl::KXSLineEditControl(QWidget
*parent
, const QString
&name
,
239 : QWidget(parent
), KXSStringItem(name
, config
)
241 QVBoxLayout
*l
= new QVBoxLayout(this);
242 QLabel
*label
= new QLabel(mLabel
, this);
244 mEdit
= new QLineEdit(this);
245 connect(mEdit
, SIGNAL(textChanged(const QString
&)), SLOT(textChanged(const QString
&)));
249 KXSLineEditControl::KXSLineEditControl(QWidget
*parent
, const QString
&name
,
250 const QXmlAttributes
&attr
)
251 : QWidget(parent
), KXSStringItem(name
, attr
)
253 QVBoxLayout
*l
= new QVBoxLayout(this);
254 QLabel
*label
= new QLabel(mLabel
, this);
256 mEdit
= new QLineEdit(this);
257 connect(mEdit
, SIGNAL(textChanged(const QString
&)), SLOT(textChanged(const QString
&)));
261 void KXSLineEditControl::textChanged( const QString
&text
)
267 void KXSLineEditControl::read(KConfig
&config
)
269 KXSStringItem::read(config
);
270 mEdit
->setText(mValue
);
273 //===========================================================================
274 KXSFileControl::KXSFileControl(QWidget
*parent
, const QString
&name
,
276 : QWidget(parent
), KXSStringItem(name
, config
)
278 QVBoxLayout
*l
= new QVBoxLayout(this);
279 QLabel
*label
= new QLabel(mLabel
, this);
281 mEdit
= new QLineEdit(this);
282 connect(mEdit
, SIGNAL(textChanged(const QString
&)), SLOT(textChanged(const QString
&)));
286 KXSFileControl::KXSFileControl(QWidget
*parent
, const QString
&name
,
287 const QXmlAttributes
&attr
)
288 : QWidget(parent
), KXSStringItem(name
, attr
)
290 QVBoxLayout
*l
= new QVBoxLayout(this);
291 QLabel
*label
= new QLabel(mLabel
, this);
293 QHBoxLayout
*hb
= new QHBoxLayout(l
);
294 mEdit
= new QLineEdit(this);
295 connect(mEdit
, SIGNAL(textChanged(const QString
&)), SLOT(textChanged(const QString
&)));
297 QPushButton
*pb
= new QPushButton( "...", this );
298 connect( pb
, SIGNAL(clicked()), this, SLOT(selectFile()) );
302 void KXSFileControl::textChanged( const QString
&text
)
308 void KXSFileControl::selectFile()
310 QString f
= KFileDialog::getOpenFileName();
311 if ( !f
.isEmpty() ) {
313 mEdit
->setText(mValue
);
318 void KXSFileControl::read(KConfig
&config
)
320 KXSStringItem::read(config
);
321 mEdit
->setText(mValue
);
324 #include "kxscontrol.moc"