Try to fix it
[kdeartwork.git] / kscreensaver / kxsconfig / kxscontrol.cpp
bloba2b9d795b4fa902a00dd2d48c9da03681ca7ae00
1 //-----------------------------------------------------------------------------
2 //
3 // KDE xscreensaver configuration dialog
4 //
5 // Copyright (c) Martin R. Jones <mjones@kde.org> 1999
6 //
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.
22 #include <qlabel.h>
23 #include <qslider.h>
24 #include <qlayout.h>
25 #include <qcombobox.h>
26 #include <qlineedit.h>
27 #include <qspinbox.h>
28 #include <qpushbutton.h>
29 #include <qxml.h>
30 //Added by qt3to4:
31 #include <QVBoxLayout>
32 #include <QHBoxLayout>
33 #include <klocale.h>
34 #include <kfiledialog.h>
35 #include "kxscontrol.h"
37 //===========================================================================
38 KXSRangeControl::KXSRangeControl(QWidget *parent, const QString &name,
39 KConfig &config)
40 : QWidget(parent), KXSRangeItem(name, config), mSlider(0), mSpinBox(0)
42 QVBoxLayout *l = new QVBoxLayout(this);
43 QLabel *label = new QLabel(mLabel, this);
44 l->add(label);
45 mSlider = new QSlider(mMinimum, mMaximum, 10, mValue, Qt::Horizontal, this);
46 connect(mSlider, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
47 l->add(mSlider);
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);
58 hb->add(l);
60 mSpinBox = new QSpinBox(mMinimum, mMaximum, 1, this);
61 mSpinBox->setValue(mValue);
62 connect(mSpinBox, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
63 hb->add(mSpinBox);
64 } else {
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);
70 vb->add(l);
72 QHBoxLayout *hb = new QHBoxLayout(vb);
73 if (!lowLabel.isEmpty()) {
74 QLabel *l = new QLabel(lowLabel, this);
75 hb->addWidget(l);
77 mSlider = new QSlider(mMinimum, mMaximum, 10, mValue, Qt::Horizontal, this);
78 connect(mSlider, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
79 hb->add(mSlider);
80 if (!highLabel.isEmpty()){
81 QLabel *l = new QLabel(highLabel, this);
82 hb->addWidget(l);
87 void KXSRangeControl::slotValueChanged(int value)
89 mValue = value;
90 emit changed();
93 void KXSRangeControl::read(KConfig &config)
95 KXSRangeItem::read(config);
96 if ( mSpinBox )
97 mSpinBox->setValue(mValue);
98 else
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);
109 l->add(label);
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)));
115 l->add(mSlider);
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);
127 vb->add(l);
129 QHBoxLayout *hb = new QHBoxLayout(vb);
130 if (!lowLabel.isEmpty()) {
131 QLabel *l = new QLabel(lowLabel, this);
132 hb->addWidget(l);
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)));
137 hb->add(mSlider);
138 if (!highLabel.isEmpty()){
139 QLabel *l = new QLabel(highLabel, this);
140 hb->addWidget(l);
144 void KXSDoubleRangeControl::slotValueChanged(int value)
146 mValue = mMinimum + value * (mMaximum - mMinimum) / 100.0;
147 emit changed();
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,
159 KConfig &config)
160 : QCheckBox(parent), KXSBoolItem(name, config)
162 setText(mLabel);
163 setChecked(mValue);
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)
171 setText(mLabel);
172 setChecked(mValue);
173 connect(this, SIGNAL(toggled(bool)), SLOT(slotToggled(bool)));
176 void KXSCheckBoxControl::slotToggled(bool state)
178 mValue = state;
179 emit changed();
182 void KXSCheckBoxControl::read(KConfig &config)
184 KXSBoolItem::read(config);
185 setChecked(mValue);
188 //===========================================================================
189 KXSDropListControl::KXSDropListControl(QWidget *parent, const QString &name,
190 KConfig &config)
191 : QWidget(parent), KXSSelectItem(name, config)
193 QVBoxLayout *l = new QVBoxLayout(this);
194 QLabel *label = new QLabel(mLabel, this);
195 l->add(label);
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)));
201 l->add(mCombo);
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);
210 l->add(label);
211 mCombo = new QComboBox(this);
212 connect(mCombo, SIGNAL(activated(int)), SLOT(slotActivated(int)));
213 l->add(mCombo);
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)
226 mValue = indx;
227 emit changed();
230 void KXSDropListControl::read(KConfig &config)
232 KXSSelectItem::read(config);
233 mCombo->setCurrentItem(mValue);
236 //===========================================================================
237 KXSLineEditControl::KXSLineEditControl(QWidget *parent, const QString &name,
238 KConfig &config)
239 : QWidget(parent), KXSStringItem(name, config)
241 QVBoxLayout *l = new QVBoxLayout(this);
242 QLabel *label = new QLabel(mLabel, this);
243 l->add(label);
244 mEdit = new QLineEdit(this);
245 connect(mEdit, SIGNAL(textChanged(const QString &)), SLOT(textChanged(const QString &)));
246 l->add(mEdit);
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);
255 l->add(label);
256 mEdit = new QLineEdit(this);
257 connect(mEdit, SIGNAL(textChanged(const QString &)), SLOT(textChanged(const QString &)));
258 l->add(mEdit);
261 void KXSLineEditControl::textChanged( const QString &text )
263 mValue = text;
264 emit changed();
267 void KXSLineEditControl::read(KConfig &config)
269 KXSStringItem::read(config);
270 mEdit->setText(mValue);
273 //===========================================================================
274 KXSFileControl::KXSFileControl(QWidget *parent, const QString &name,
275 KConfig &config)
276 : QWidget(parent), KXSStringItem(name, config)
278 QVBoxLayout *l = new QVBoxLayout(this);
279 QLabel *label = new QLabel(mLabel, this);
280 l->add(label);
281 mEdit = new QLineEdit(this);
282 connect(mEdit, SIGNAL(textChanged(const QString &)), SLOT(textChanged(const QString &)));
283 l->add(mEdit);
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);
292 l->add(label);
293 QHBoxLayout *hb = new QHBoxLayout(l);
294 mEdit = new QLineEdit(this);
295 connect(mEdit, SIGNAL(textChanged(const QString &)), SLOT(textChanged(const QString &)));
296 hb->add(mEdit);
297 QPushButton *pb = new QPushButton( "...", this );
298 connect( pb, SIGNAL(clicked()), this, SLOT(selectFile()) );
299 hb->addWidget(pb);
302 void KXSFileControl::textChanged( const QString &text )
304 mValue = text;
305 emit changed();
308 void KXSFileControl::selectFile()
310 QString f = KFileDialog::getOpenFileName();
311 if ( !f.isEmpty() ) {
312 mValue = f;
313 mEdit->setText(mValue);
314 emit changed();
318 void KXSFileControl::read(KConfig &config)
320 KXSStringItem::read(config);
321 mEdit->setText(mValue);
324 #include "kxscontrol.moc"