Back to index

kdeartwork  4.3.2
kxscontrol.cpp
Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 //
00003 // KDE xscreensaver configuration dialog
00004 //
00005 // Copyright (c)  Martin R. Jones <mjones@kde.org> 1999
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public
00009 // License as published by the Free Software Foundation;
00010 // version 2 of the License.
00011 //
00012 // This program is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 // General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with this program; see the file COPYING.  If not, write to
00019 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020 // Boston, MA 02110-1301, USA.
00021 
00022 #include <qlabel.h>
00023 #include <qslider.h>
00024 #include <qlayout.h>
00025 #include <qcombobox.h>
00026 #include <qlineedit.h>
00027 #include <qspinbox.h>
00028 #include <qpushbutton.h>
00029 #include <qxml.h>
00030 //Added by qt3to4:
00031 #include <QVBoxLayout>
00032 #include <QHBoxLayout>
00033 #include <klocale.h>
00034 #include <kfiledialog.h>
00035 #include "kxscontrol.h"
00036 
00037 //===========================================================================
00038 KXSRangeControl::KXSRangeControl(QWidget *parent, const QString &name,
00039                                   KConfig &config)
00040   : QWidget(parent), KXSRangeItem(name, config), mSlider(0), mSpinBox(0)
00041 {
00042   QVBoxLayout *l = new QVBoxLayout(this);
00043   QLabel *label = new QLabel(mLabel, this);
00044   l->addWidget(label);
00045   mSlider = new QSlider(Qt::Horizontal, this);
00046   mSlider->setMinimum(mMinimum);
00047   mSlider->setMaximum(mMaximum);
00048   mSlider->setPageStep(10);
00049   mSlider->setValue(mValue);
00050   connect(mSlider, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
00051   l->addWidget(mSlider);
00052 }
00053 
00054 KXSRangeControl::KXSRangeControl(QWidget *parent, const QString &name,
00055                                   const QXmlAttributes &attr )
00056   : QWidget(parent), KXSRangeItem(name, attr), mSlider(0), mSpinBox(0)
00057 {
00058     if (attr.value("type") == "spinbutton" ) {
00059        QHBoxLayout *hb = new QHBoxLayout(this);
00060        if (!mLabel.isEmpty()) {
00061            QLabel *l = new QLabel(i18n(mLabel.toUtf8()), this);
00062            hb->addWidget(l);
00063        }
00064        mSpinBox = new QSpinBox(this);
00065         mSpinBox->setMinimum(mMinimum);
00066         mSpinBox->setMaximum(mMaximum);
00067         mSpinBox->setSingleStep(1);
00068        mSpinBox->setValue(mValue);
00069        connect(mSpinBox, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
00070        hb->addWidget(mSpinBox);
00071     } else {
00072        QString lowLabel = attr.value("_low-label");
00073        QString highLabel = attr.value("_high-label");
00074        QVBoxLayout *vb = new QVBoxLayout(this);
00075        if (!mLabel.isEmpty()) {
00076            QLabel *l = new QLabel(i18n(mLabel.toUtf8()), this);
00077            vb->addWidget(l);
00078        }
00079        QHBoxLayout *hb = new QHBoxLayout();
00080         vb->addLayout(hb);
00081        if (!lowLabel.isEmpty()) {
00082            QLabel *l = new QLabel(i18n(lowLabel.toUtf8()), this);
00083            hb->addWidget(l);
00084        }
00085        mSlider = new QSlider(Qt::Horizontal, this);
00086        mSlider->setMinimum(mMinimum);
00087        mSlider->setMaximum(mMaximum);
00088        mSlider->setPageStep(10);
00089        mSlider->setValue(mValue);
00090        connect(mSlider, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
00091        hb->addWidget(mSlider);
00092        if (!highLabel.isEmpty()){
00093            QLabel *l = new QLabel(i18n(highLabel.toUtf8()), this);
00094            hb->addWidget(l);
00095        }
00096     }
00097 }
00098 
00099 void KXSRangeControl::slotValueChanged(int value)
00100 {
00101   mValue = value;
00102   emit changed();
00103 }
00104 
00105 void KXSRangeControl::read(KConfig &config)
00106 {
00107     KXSRangeItem::read(config);
00108     if ( mSpinBox )
00109        mSpinBox->setValue(mValue);
00110     else
00111        mSlider->setValue(mValue);
00112 }
00113 
00114 //===========================================================================
00115 KXSDoubleRangeControl::KXSDoubleRangeControl(QWidget *parent,
00116                                   const QString &name, KConfig &config)
00117   : QWidget(parent), KXSDoubleRangeItem(name, config)
00118 {
00119   QVBoxLayout *l = new QVBoxLayout(this);
00120   QLabel *label = new QLabel(mLabel, this);
00121   l->addWidget(label);
00122 
00123   int value = int((mValue - mMinimum) * 100 / (mMaximum - mMinimum));
00124 
00125   mSlider = new QSlider(Qt::Horizontal, this);
00126   mSlider->setMinimum(0);
00127   mSlider->setMaximum(100);
00128   mSlider->setPageStep(10);
00129   mSlider->setValue(value);
00130   connect(mSlider, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
00131   l->addWidget(mSlider);
00132 }
00133 
00134 KXSDoubleRangeControl::KXSDoubleRangeControl(QWidget *parent,
00135                                   const QString &name, const QXmlAttributes &attr)
00136   : QWidget(parent), KXSDoubleRangeItem(name, attr)
00137 {
00138     QString lowLabel = attr.value("_low-label");
00139     QString highLabel = attr.value("_high-label");
00140     QVBoxLayout *vb = new QVBoxLayout(this);
00141     if (!mLabel.isEmpty()) {
00142        QLabel *l = new QLabel(i18n(mLabel.toUtf8()), this);
00143        vb->addWidget(l);
00144     }
00145     QHBoxLayout *hb = new QHBoxLayout();
00146     vb->addLayout(hb);
00147     if (!lowLabel.isEmpty()) {
00148        QLabel *l = new QLabel(i18n(lowLabel.toUtf8()), this);
00149        hb->addWidget(l);
00150     }
00151     int value = int((mValue - mMinimum) * 100 / (mMaximum - mMinimum));
00152     mSlider = new QSlider(Qt::Horizontal, this);
00153     mSlider->setMinimum(0);
00154     mSlider->setMaximum(100);
00155     mSlider->setPageStep(10);
00156     mSlider->setValue(value);
00157     connect(mSlider, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
00158     hb->addWidget(mSlider);
00159     if (!highLabel.isEmpty()){
00160        QLabel *l = new QLabel(i18n(highLabel.toUtf8()), this);
00161        hb->addWidget(l);
00162     }
00163 }
00164 
00165 void KXSDoubleRangeControl::slotValueChanged(int value)
00166 {
00167   mValue = mMinimum + value * (mMaximum - mMinimum) / 100.0;
00168   emit changed();
00169 }
00170 
00171 void KXSDoubleRangeControl::read(KConfig &config)
00172 {
00173     KXSDoubleRangeItem::read(config);
00174     mSlider->setValue((int)((mValue - mMinimum) * 100.0 /
00175                             (mMaximum - mMinimum) + 0.5));
00176 }
00177 
00178 //===========================================================================
00179 KXSCheckBoxControl::KXSCheckBoxControl(QWidget *parent, const QString &name,
00180                                       KConfig &config)
00181   : QCheckBox(parent), KXSBoolItem(name, config)
00182 {
00183   setText(mLabel);
00184   setChecked(mValue);
00185   connect(this, SIGNAL(toggled(bool)), SLOT(slotToggled(bool)));
00186 }
00187 
00188 KXSCheckBoxControl::KXSCheckBoxControl(QWidget *parent, const QString &name,
00189                                       const QXmlAttributes &attr)
00190   : QCheckBox(parent), KXSBoolItem(name, attr)
00191 {
00192   setText(i18n(mLabel.toUtf8()));
00193   setChecked(mValue);
00194   connect(this, SIGNAL(toggled(bool)), SLOT(slotToggled(bool)));
00195 }
00196 
00197 void KXSCheckBoxControl::slotToggled(bool state)
00198 {
00199     mValue = state;
00200     emit changed();
00201 }
00202 
00203 void KXSCheckBoxControl::read(KConfig &config)
00204 {
00205     KXSBoolItem::read(config);
00206     setChecked(mValue);
00207 }
00208 
00209 //===========================================================================
00210 KXSDropListControl::KXSDropListControl(QWidget *parent, const QString &name,
00211                                       KConfig &config)
00212   : QWidget(parent), KXSSelectItem(name, config)
00213 {
00214   QVBoxLayout *l = new QVBoxLayout(this);
00215   QLabel *label = new QLabel(mLabel, this);
00216   l->addWidget(label);
00217   mCombo = new QComboBox(this);
00218   for(int i=0; i < mOptions.count(); i++)
00219       mCombo->addItem( i18n(mOptions[i].toUtf8()) );
00220   mCombo->setCurrentIndex(mValue);
00221   connect(mCombo, SIGNAL(activated(int)), SLOT(slotActivated(int)));
00222   l->addWidget(mCombo);
00223 }
00224 
00225 KXSDropListControl::KXSDropListControl(QWidget *parent, const QString &name,
00226                                       const QXmlAttributes &attr)
00227   : QWidget(parent), KXSSelectItem(name, attr)
00228 {
00229   QVBoxLayout *l = new QVBoxLayout(this);
00230   QString labelText = mLabel.isEmpty() ? QString():i18n(mLabel.toUtf8());
00231   QLabel *label = new QLabel(labelText, this);
00232   l->addWidget(label);
00233   mCombo = new QComboBox(this);
00234   connect(mCombo, SIGNAL(activated(int)), SLOT(slotActivated(int)));
00235   l->addWidget(mCombo);
00236 }
00237 
00238 void KXSDropListControl::addOption(const QXmlAttributes &attr)
00239 {
00240     KXSSelectItem::addOption( attr );
00241     mCombo->addItem( i18n(mOptions[mOptions.count()-1].toUtf8()) );
00242     if ( mValue == mOptions.count()-1 )
00243        mCombo->setCurrentIndex(mOptions.count()-1);
00244 }
00245 
00246 void KXSDropListControl::slotActivated(int indx)
00247 {
00248   mValue = indx;
00249   emit changed();
00250 }
00251 
00252 void KXSDropListControl::read(KConfig &config)
00253 {
00254     KXSSelectItem::read(config);
00255     mCombo->setCurrentIndex(mValue);
00256 }
00257 
00258 //===========================================================================
00259 KXSLineEditControl::KXSLineEditControl(QWidget *parent, const QString &name,
00260                                   KConfig &config)
00261   : QWidget(parent), KXSStringItem(name, config)
00262 {
00263   QVBoxLayout *l = new QVBoxLayout(this);
00264   QLabel *label = new QLabel(mLabel, this);
00265   l->addWidget(label);
00266   mEdit = new QLineEdit(this);
00267   connect(mEdit, SIGNAL(textChanged(const QString &)), SLOT(textChanged(const QString &)));
00268   l->addWidget(mEdit);
00269 }
00270 
00271 KXSLineEditControl::KXSLineEditControl(QWidget *parent, const QString &name,
00272                                   const QXmlAttributes &attr )
00273   : QWidget(parent), KXSStringItem(name, attr)
00274 {
00275   QVBoxLayout *l = new QVBoxLayout(this);
00276   QLabel *label = new QLabel(i18n(mLabel.toUtf8()), this);
00277   l->addWidget(label);
00278   mEdit = new QLineEdit(this);
00279   connect(mEdit, SIGNAL(textChanged(const QString &)), SLOT(textChanged(const QString &)));
00280   l->addWidget(mEdit);
00281 }
00282 
00283 void KXSLineEditControl::textChanged( const QString &text )
00284 {
00285     mValue = text;
00286     emit changed();
00287 }
00288 
00289 void KXSLineEditControl::read(KConfig &config)
00290 {
00291     KXSStringItem::read(config);
00292     mEdit->setText(mValue);
00293 }
00294 
00295 //===========================================================================
00296 KXSFileControl::KXSFileControl(QWidget *parent, const QString &name,
00297                                   KConfig &config)
00298   : QWidget(parent), KXSStringItem(name, config)
00299 {
00300   QVBoxLayout *l = new QVBoxLayout(this);
00301   QLabel *label = new QLabel(mLabel, this);
00302   l->addWidget(label);
00303   mEdit = new QLineEdit(this);
00304   connect(mEdit, SIGNAL(textChanged(const QString &)), SLOT(textChanged(const QString &)));
00305   l->addWidget(mEdit);
00306 }
00307 
00308 KXSFileControl::KXSFileControl(QWidget *parent, const QString &name,
00309                                   const QXmlAttributes &attr )
00310   : QWidget(parent), KXSStringItem(name, attr)
00311 {
00312   QVBoxLayout *l = new QVBoxLayout(this);
00313   QLabel *label = new QLabel(i18n(mLabel.toUtf8()), this);
00314   l->addWidget(label);
00315   QHBoxLayout *hb = new QHBoxLayout();
00316   l->addLayout(hb);
00317   mEdit = new QLineEdit(this);
00318   connect(mEdit, SIGNAL(textChanged(const QString &)), SLOT(textChanged(const QString &)));
00319   hb->addWidget(mEdit);
00320   QPushButton *pb = new QPushButton( "...", this );
00321   connect( pb, SIGNAL(clicked()), this, SLOT(selectFile()) );
00322   hb->addWidget(pb);
00323 }
00324 
00325 void KXSFileControl::textChanged( const QString &text )
00326 {
00327     mValue = text;
00328     emit changed();
00329 }
00330 
00331 void KXSFileControl::selectFile()
00332 {
00333     QString f = KFileDialog::getOpenFileName();
00334     if ( !f.isEmpty() ) {
00335        mValue = f;
00336        mEdit->setText(mValue);
00337        emit changed();
00338     }
00339 }
00340 
00341 void KXSFileControl::read(KConfig &config)
00342 {
00343     KXSStringItem::read(config);
00344     mEdit->setText(mValue);
00345 }
00346 
00347 #include "kxscontrol.moc"