summaryrefslogtreecommitdiffstats
path: root/tdescreensaver/kxsconfig/kxscontrol.cpp
blob: 594a0255b9eac722b2589f8ea170ce5c56504a21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
//-----------------------------------------------------------------------------
//
// KDE xscreensaver configuration dialog
//
// Copyright (c)  Martin R. Jones <mjones@kde.org> 1999
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation;
// version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; see the file COPYING.  If not, write to
// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301, USA.

#include <tqlabel.h>
#include <tqslider.h>
#include <tqlayout.h>
#include <tqcombobox.h>
#include <tqlineedit.h>
#include <tqspinbox.h>
#include <tqpushbutton.h>
#include <tqxml.h>
#include <klocale.h>
#include <tdefiledialog.h>
#include "kxscontrol.h"

//===========================================================================
KXSRangeControl::KXSRangeControl(TQWidget *parent, const TQString &name,
                                  TDEConfig &config)
  : TQWidget(parent), KXSRangeItem(name, config), mSlider(0), mSpinBox(0)
{
  TQVBoxLayout *l = new TQVBoxLayout(this);
  TQLabel *label = new TQLabel(mLabel, this);
  l->add(label);
  mSlider = new TQSlider(mMinimum, mMaximum, 10, mValue, Qt::Horizontal, this);
  connect(mSlider, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(slotValueChanged(int)));
  l->add(mSlider);
}

KXSRangeControl::KXSRangeControl(TQWidget *parent, const TQString &name,
                                  const TQXmlAttributes &attr )
  : TQWidget(parent), KXSRangeItem(name, attr), mSlider(0), mSpinBox(0)
{
    if (attr.value("type") == "spinbutton" ) {
	TQHBoxLayout *hb = new TQHBoxLayout(this);
	if (!mLabel.isEmpty()) {
            TQLabel *l = new TQLabel(i18n(mLabel.utf8()), this);
	    hb->add(l);
	}
	mSpinBox = new TQSpinBox(mMinimum, mMaximum, 1, this);
	mSpinBox->setValue(mValue);
	connect(mSpinBox, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(slotValueChanged(int)));
	hb->add(mSpinBox);
    } else {
	TQString lowLabel = attr.value("_low-label");
	TQString highLabel = attr.value("_high-label");
	TQVBoxLayout *vb = new TQVBoxLayout(this);
	if (!mLabel.isEmpty()) {
            TQLabel *l = new TQLabel(i18n(mLabel.utf8()), this);
	    vb->add(l);
	}
	TQHBoxLayout *hb = new TQHBoxLayout(vb);
	if (!lowLabel.isEmpty()) {
            TQLabel *l = new TQLabel(i18n(lowLabel.utf8()), this);
	    hb->addWidget(l);
	}
	mSlider = new TQSlider(mMinimum, mMaximum, 10, mValue, Qt::Horizontal, this);
	connect(mSlider, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(slotValueChanged(int)));
	hb->add(mSlider);
	if (!highLabel.isEmpty()){
            TQLabel *l = new TQLabel(i18n(highLabel.utf8()), this);
	    hb->addWidget(l);
	}
    }
}

void KXSRangeControl::slotValueChanged(int value)
{
  mValue = value;
  emit changed();
}

void KXSRangeControl::read(TDEConfig &config)
{
    KXSRangeItem::read(config);
    if ( mSpinBox )
	mSpinBox->setValue(mValue);
    else
	mSlider->setValue(mValue);
}

//===========================================================================
KXSDoubleRangeControl::KXSDoubleRangeControl(TQWidget *parent,
                                  const TQString &name, TDEConfig &config)
  : TQWidget(parent), KXSDoubleRangeItem(name, config)
{
  TQVBoxLayout *l = new TQVBoxLayout(this);
  TQLabel *label = new TQLabel(mLabel, this);
  l->add(label);

  int value = int((mValue - mMinimum) * 100 / (mMaximum - mMinimum));

  mSlider = new TQSlider(0, 100, 10, value, Qt::Horizontal, this);
  connect(mSlider, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(slotValueChanged(int)));
  l->add(mSlider);
}

KXSDoubleRangeControl::KXSDoubleRangeControl(TQWidget *parent,
                                  const TQString &name, const TQXmlAttributes &attr)
  : TQWidget(parent), KXSDoubleRangeItem(name, attr)
{
    TQString lowLabel = attr.value("_low-label");
    TQString highLabel = attr.value("_high-label");
    TQVBoxLayout *vb = new TQVBoxLayout(this);
    if (!mLabel.isEmpty()) {
        TQLabel *l = new TQLabel(i18n(mLabel.utf8()), this);
	vb->add(l);
    }
    TQHBoxLayout *hb = new TQHBoxLayout(vb);
    if (!lowLabel.isEmpty()) {
        TQLabel *l = new TQLabel(i18n(lowLabel.utf8()), this);
	hb->addWidget(l);
    }
    int value = int((mValue - mMinimum) * 100 / (mMaximum - mMinimum));
    mSlider = new TQSlider(0, 100, 10, value, Qt::Horizontal, this);
    connect(mSlider, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(slotValueChanged(int)));
    hb->add(mSlider);
    if (!highLabel.isEmpty()){
        TQLabel *l = new TQLabel(i18n(highLabel.utf8()), this);
	hb->addWidget(l);
    }
}

void KXSDoubleRangeControl::slotValueChanged(int value)
{
  mValue = mMinimum + value * (mMaximum - mMinimum) / 100.0;
  emit changed();
}

void KXSDoubleRangeControl::read(TDEConfig &config)
{
    KXSDoubleRangeItem::read(config);
    mSlider->setValue((int)((mValue - mMinimum) * 100.0 /
                            (mMaximum - mMinimum) + 0.5));
}

//===========================================================================
KXSCheckBoxControl::KXSCheckBoxControl(TQWidget *parent, const TQString &name,
                                      TDEConfig &config)
  : TQCheckBox(parent), KXSBoolItem(name, config)
{
  setText(mLabel);
  setChecked(mValue);
  connect(this, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotToggled(bool)));
}

KXSCheckBoxControl::KXSCheckBoxControl(TQWidget *parent, const TQString &name,
                                      const TQXmlAttributes &attr)
  : TQCheckBox(parent), KXSBoolItem(name, attr)
{
  setText(i18n(mLabel.utf8()));
  setChecked(mValue);
  connect(this, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotToggled(bool)));
}

void KXSCheckBoxControl::slotToggled(bool state)
{
  mValue = state;
  emit changed();
}

void KXSCheckBoxControl::read(TDEConfig &config)
{
    KXSBoolItem::read(config);
    setChecked(mValue);
}

//===========================================================================
KXSDropListControl::KXSDropListControl(TQWidget *parent, const TQString &name,
                                      TDEConfig &config)
  : TQWidget(parent), KXSSelectItem(name, config)
{
  TQVBoxLayout *l = new TQVBoxLayout(this);
  TQLabel *label = new TQLabel(mLabel, this);
  l->add(label);
  mCombo = new TQComboBox(this);
  for(uint i=0; i < mOptions.count(); i++)
      mCombo->insertItem( i18n(mOptions[i].utf8()) );
  mCombo->setCurrentItem(mValue);
  connect(mCombo, TQT_SIGNAL(activated(int)), TQT_SLOT(slotActivated(int)));
  l->add(mCombo);
}

KXSDropListControl::KXSDropListControl(TQWidget *parent, const TQString &name,
                                      const TQXmlAttributes &attr)
  : TQWidget(parent), KXSSelectItem(name, attr)
{
  TQVBoxLayout *l = new TQVBoxLayout(this);
  TQLabel *label = new TQLabel(i18n(mLabel.utf8()), this);
  l->add(label);
  mCombo = new TQComboBox(this);
  connect(mCombo, TQT_SIGNAL(activated(int)), TQT_SLOT(slotActivated(int)));
  l->add(mCombo);
}

void KXSDropListControl::addOption(const TQXmlAttributes &attr)
{
    KXSSelectItem::addOption( attr );
    mCombo->insertItem( i18n(mOptions[mOptions.count()-1].utf8()) );
    if ( (unsigned)mValue == mOptions.count()-1 )
	mCombo->setCurrentItem(mOptions.count()-1);
}

void KXSDropListControl::slotActivated(int indx)
{
  mValue = indx;
  emit changed();
}

void KXSDropListControl::read(TDEConfig &config)
{
    KXSSelectItem::read(config);
    mCombo->setCurrentItem(mValue);
}

//===========================================================================
KXSLineEditControl::KXSLineEditControl(TQWidget *parent, const TQString &name,
                                  TDEConfig &config)
  : TQWidget(parent), KXSStringItem(name, config)
{
  TQVBoxLayout *l = new TQVBoxLayout(this);
  TQLabel *label = new TQLabel(mLabel, this);
  l->add(label);
  mEdit = new TQLineEdit(this);
  connect(mEdit, TQT_SIGNAL(textChanged(const TQString &)), TQT_SLOT(textChanged(const TQString &)));
  l->add(mEdit);
}

KXSLineEditControl::KXSLineEditControl(TQWidget *parent, const TQString &name,
                                  const TQXmlAttributes &attr )
  : TQWidget(parent), KXSStringItem(name, attr)
{
  TQVBoxLayout *l = new TQVBoxLayout(this);
  TQLabel *label = new TQLabel(i18n(mLabel.utf8()), this);
  l->add(label);
  mEdit = new TQLineEdit(this);
  connect(mEdit, TQT_SIGNAL(textChanged(const TQString &)), TQT_SLOT(textChanged(const TQString &)));
  l->add(mEdit);
}

void KXSLineEditControl::textChanged( const TQString &text )
{
  mValue = text;
  emit changed();
}

void KXSLineEditControl::read(TDEConfig &config)
{
    KXSStringItem::read(config);
    mEdit->setText(mValue);
}

//===========================================================================
KXSFileControl::KXSFileControl(TQWidget *parent, const TQString &name,
                                  TDEConfig &config)
  : TQWidget(parent), KXSStringItem(name, config)
{
  TQVBoxLayout *l = new TQVBoxLayout(this);
  TQLabel *label = new TQLabel(mLabel, this);
  l->add(label);
  mEdit = new TQLineEdit(this);
  connect(mEdit, TQT_SIGNAL(textChanged(const TQString &)), TQT_SLOT(textChanged(const TQString &)));
  l->add(mEdit);
}

KXSFileControl::KXSFileControl(TQWidget *parent, const TQString &name,
                                  const TQXmlAttributes &attr )
  : TQWidget(parent), KXSStringItem(name, attr)
{
  TQVBoxLayout *l = new TQVBoxLayout(this);
  TQLabel *label = new TQLabel(i18n(mLabel.utf8()), this);
  l->add(label);
  TQHBoxLayout *hb = new TQHBoxLayout(l);
  mEdit = new TQLineEdit(this);
  connect(mEdit, TQT_SIGNAL(textChanged(const TQString &)), TQT_SLOT(textChanged(const TQString &)));
  hb->add(mEdit);
  TQPushButton *pb = new TQPushButton( "...", this );
  connect( pb, TQT_SIGNAL(clicked()), this, TQT_SLOT(selectFile()) );
  hb->addWidget(pb);
}

void KXSFileControl::textChanged( const TQString &text )
{
  mValue = text;
  emit changed();
}

void KXSFileControl::selectFile()
{
    TQString f = KFileDialog::getOpenFileName();
    if ( !f.isEmpty() ) {
	mValue = f;
	mEdit->setText(mValue);
	emit changed();
    }
}

void KXSFileControl::read(TDEConfig &config)
{
    KXSStringItem::read(config);
    mEdit->setText(mValue);
}

#include "kxscontrol.moc"