libkdepim Library API Documentation

kprefsdialog.cpp

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 // $Id: kprefsdialog.cpp,v 1.4 2002/09/01 22:56:37 cumming Exp $
00025 
00026 #include <qlayout.h>
00027 #include <qlabel.h>
00028 #include <qgroupbox.h>
00029 #include <qbuttongroup.h>
00030 #include <qlineedit.h>
00031 #include <qfont.h>
00032 #include <qslider.h>
00033 #include <qfile.h>
00034 #include <qtextstream.h>
00035 #include <qvbox.h>
00036 #include <qhbox.h>
00037 #include <qspinbox.h>
00038 #include <qdatetime.h>
00039 #include <qframe.h>
00040 #include <qcombobox.h>
00041 #include <qcheckbox.h>
00042 #include <qradiobutton.h>
00043 #include <qpushbutton.h>
00044 
00045 #include <kcolorbutton.h>
00046 #include <kdebug.h>
00047 #include <klocale.h>
00048 #include <kglobal.h>
00049 #include <kfontdialog.h>
00050 #include <kmessagebox.h>
00051 #include <kcolordialog.h>
00052 #include <kiconloader.h>
00053 
00054 #include "kprefs.h"
00055 
00056 #include "kprefsdialog.h"
00057 #include "kprefsdialog.moc"
00058 
00059 KPrefsWidBool::KPrefsWidBool(const QString &text,bool *reference,
00060                              QWidget *parent)
00061 {
00062   mReference = reference;
00063 
00064   mCheck = new QCheckBox(text,parent);
00065 }
00066 
00067 void KPrefsWidBool::readConfig()
00068 {
00069   mCheck->setChecked(*mReference);
00070 }
00071 
00072 void KPrefsWidBool::writeConfig()
00073 {
00074   *mReference = mCheck->isChecked();
00075 }
00076 
00077 QCheckBox *KPrefsWidBool::checkBox()
00078 {
00079   return mCheck;
00080 }
00081 
00082 
00083 KPrefsWidColor::KPrefsWidColor(const QString &text,QColor *reference,
00084                                QWidget *parent)
00085 {
00086   mReference = reference;
00087 
00088   mButton = new KColorButton(parent);
00089   mLabel = new QLabel(mButton, text, parent);
00090 }
00091 
00092 KPrefsWidColor::~KPrefsWidColor()
00093 {
00094 //  kdDebug(5300) << "KPrefsWidColor::~KPrefsWidColor()" << endl;
00095 }
00096 
00097 void KPrefsWidColor::readConfig()
00098 {
00099   mButton->setColor(*mReference);
00100 }
00101 
00102 void KPrefsWidColor::writeConfig()
00103 {
00104   *mReference = mButton->color();
00105 }
00106 
00107 QLabel *KPrefsWidColor::label()
00108 {
00109   return mLabel;
00110 }
00111 
00112 KColorButton *KPrefsWidColor::button()
00113 {
00114   return mButton;
00115 }
00116 
00117 KPrefsWidFont::KPrefsWidFont(const QString &sampleText,const QString &labelText,
00118                              QFont *reference,QWidget *parent)
00119 {
00120   mReference = reference;
00121 
00122   mLabel = new QLabel(labelText, parent);
00123 
00124   mPreview = new QLabel(sampleText,parent);
00125   mPreview->setFrameStyle(QFrame::Panel|QFrame::Sunken);
00126 
00127   mButton = new QPushButton(i18n("Choose..."), parent);
00128   connect(mButton,SIGNAL(clicked()),SLOT(selectFont()));
00129 }
00130 
00131 KPrefsWidFont::~KPrefsWidFont()
00132 {
00133 }
00134 
00135 void KPrefsWidFont::readConfig()
00136 {
00137   mPreview->setFont(*mReference);
00138 }
00139 
00140 void KPrefsWidFont::writeConfig()
00141 {
00142   *mReference = mPreview->font();
00143 }
00144 
00145 QLabel *KPrefsWidFont::label()
00146 {
00147   return mLabel;
00148 }
00149 
00150 QFrame *KPrefsWidFont::preview()
00151 {
00152   return mPreview;
00153 }
00154 
00155 QPushButton *KPrefsWidFont::button()
00156 {
00157   return mButton;
00158 }
00159 
00160 void KPrefsWidFont::selectFont()
00161 {
00162   QFont myFont(mPreview->font());
00163   int result = KFontDialog::getFont(myFont);
00164   if (result == KFontDialog::Accepted) {
00165     mPreview->setFont(myFont);
00166   }
00167 }
00168 
00169 
00170 KPrefsWidTime::KPrefsWidTime(const QString &text,int *reference,
00171                              QWidget *parent)
00172 {
00173   mReference = reference;
00174 
00175   mLabel = new QLabel(text,parent);
00176   mSpin = new QSpinBox(0,23,1,parent);
00177   mSpin->setSuffix(":00");
00178 }
00179 
00180 void KPrefsWidTime::readConfig()
00181 {
00182   mSpin->setValue(*mReference);
00183 }
00184 
00185 void KPrefsWidTime::writeConfig()
00186 {
00187   *mReference = mSpin->value();
00188 }
00189 
00190 QLabel *KPrefsWidTime::label()
00191 {
00192   return mLabel;
00193 }
00194 
00195 QSpinBox *KPrefsWidTime::spinBox()
00196 {
00197   return mSpin;
00198 }
00199 
00200 
00201 KPrefsWidRadios::KPrefsWidRadios(const QString &text,int *reference,
00202                 QWidget *parent)
00203 {
00204   mReference = reference;
00205 
00206   mBox = new QButtonGroup(1,Qt::Horizontal,text,parent);
00207 }
00208 
00209 KPrefsWidRadios::~KPrefsWidRadios()
00210 {
00211 }
00212 
00213 void KPrefsWidRadios::addRadio(const QString &text)
00214 {
00215   new QRadioButton(text,mBox);
00216 }
00217 
00218 QButtonGroup *KPrefsWidRadios::groupBox()
00219 {
00220   return mBox;
00221 }
00222 
00223 void KPrefsWidRadios::readConfig()
00224 {
00225   mBox->setButton(*mReference);
00226 }
00227 
00228 void KPrefsWidRadios::writeConfig()
00229 {
00230   *mReference = mBox->id(mBox->selected());
00231 }
00232 
00233 
00234 KPrefsWidString::KPrefsWidString(const QString &text,QString *reference,
00235                                  QWidget *parent, QLineEdit::EchoMode echomode)
00236 {
00237   mReference = reference;
00238   
00239   mLabel = new QLabel(text,parent);
00240   mEdit = new QLineEdit(parent);
00241   mEdit->setEchoMode( echomode );
00242 }
00243 
00244 KPrefsWidString::~KPrefsWidString()
00245 {
00246 }
00247 
00248 void KPrefsWidString::readConfig()
00249 {
00250   mEdit->setText(*mReference);
00251 }
00252 
00253 void KPrefsWidString::writeConfig()
00254 {
00255   *mReference = mEdit->text();
00256 }
00257 
00258 QLabel *KPrefsWidString::label()
00259 {
00260   return mLabel;
00261 }
00262 
00263 QLineEdit *KPrefsWidString::lineEdit()
00264 {
00265   return mEdit;
00266 }
00267 
00268 
00269 KPrefsDialog::KPrefsDialog(KPrefs *prefs,QWidget *parent,char *name,bool modal) :
00270   KDialogBase(IconList,i18n("Preferences"),Ok|Apply|Cancel|Default,Ok,parent,
00271               name,modal,true)
00272 {
00273   mPrefs = prefs;
00274 
00275 // This seems to cause a crash on exit. Investigate later.
00276 //  mPrefsWids.setAutoDelete(true);
00277 
00278   connect(this,SIGNAL(defaultClicked()),SLOT(setDefaults()));
00279   connect(this,SIGNAL(cancelClicked()),SLOT(reject()));
00280 }
00281 
00282 KPrefsDialog::~KPrefsDialog()
00283 {
00284 }
00285 
00286 void KPrefsDialog::addWid(KPrefsWid *wid)
00287 {
00288   mPrefsWids.append(wid);
00289 }
00290 
00291 KPrefsWidBool *KPrefsDialog::addWidBool(const QString &text,bool *reference,QWidget *parent)
00292 {
00293   KPrefsWidBool *w = new KPrefsWidBool(text,reference,parent);
00294   addWid(w);
00295   return w;
00296 }
00297 
00298 KPrefsWidTime *KPrefsDialog::addWidTime(const QString &text,int *reference,QWidget *parent)
00299 {
00300   KPrefsWidTime *w = new KPrefsWidTime(text,reference,parent);
00301   addWid(w);
00302   return w;
00303 }
00304 
00305 KPrefsWidColor *KPrefsDialog::addWidColor(const QString &text,QColor *reference,QWidget *parent)
00306 {
00307   KPrefsWidColor *w = new KPrefsWidColor(text,reference,parent);
00308   addWid(w);
00309   return w;
00310 }
00311 
00312 KPrefsWidRadios *KPrefsDialog::addWidRadios(const QString &text,int *reference,QWidget *parent)
00313 {
00314   KPrefsWidRadios *w = new KPrefsWidRadios(text,reference,parent);
00315   addWid(w);
00316   return w;
00317 }
00318 
00319 KPrefsWidString *KPrefsDialog::addWidString(const QString &text,QString *reference,QWidget *parent)
00320 {
00321   KPrefsWidString *w = new KPrefsWidString(text,reference,parent);
00322   addWid(w);
00323   return w;
00324 }
00325 
00326 KPrefsWidString *KPrefsDialog::addWidPassword(const QString &text,QString *reference,QWidget *parent)
00327 {
00328   KPrefsWidString *w = new KPrefsWidString(text,reference,parent,QLineEdit::Password);
00329   addWid(w);
00330   return w;
00331 }
00332 
00333 KPrefsWidFont *KPrefsDialog::addWidFont(const QString &sampleText,const QString &buttonText,
00334                                         QFont *reference,QWidget *parent)
00335 {
00336   KPrefsWidFont *w = new KPrefsWidFont(sampleText,buttonText,reference,parent);
00337   addWid(w);
00338   return w;
00339 }
00340 
00341 void KPrefsDialog::setDefaults()
00342 {
00343   mPrefs->setDefaults();
00344   
00345   readConfig();
00346 }
00347 
00348 void KPrefsDialog::readConfig()
00349 {
00350 //  kdDebug(5300) << "KPrefsDialog::readConfig()" << endl;
00351 
00352   KPrefsWid *wid;
00353   for(wid = mPrefsWids.first();wid;wid=mPrefsWids.next()) {
00354     wid->readConfig();
00355   }
00356 
00357   usrReadConfig();
00358 }
00359 
00360 void KPrefsDialog::writeConfig()
00361 {
00362 //  kdDebug(5300) << "KPrefsDialog::writeConfig()" << endl;
00363 
00364   KPrefsWid *wid;
00365   for(wid = mPrefsWids.first();wid;wid=mPrefsWids.next()) {
00366     wid->writeConfig();
00367   }
00368 
00369   usrWriteConfig();
00370 
00371 //  kdDebug(5300) << "KPrefsDialog::writeConfig() now writing..." << endl;
00372   
00373   mPrefs->writeConfig();
00374 
00375 //  kdDebug(5300) << "KPrefsDialog::writeConfig() done" << endl;
00376 }
00377 
00378 
00379 void KPrefsDialog::slotApply()
00380 {
00381   writeConfig();
00382   emit configChanged();
00383 }
00384 
00385 void KPrefsDialog::slotOk()
00386 {
00387   slotApply();
00388   accept();
00389 }
00390 
00391 void KPrefsDialog::slotDefault()
00392 {
00393   if (KMessageBox::warningContinueCancel(this,
00394       i18n("You are about to set all preferences to default values. All "
00395       "custom modifications will be lost."),i18n("Setting Default Preferences"),
00396       i18n("Continue"))
00397     == KMessageBox::Continue) setDefaults(); 
00398 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:22 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001