From 0fa836331f443547e090ccd3ad818255c136d747 Mon Sep 17 00:00:00 2001 From: ulf69 Date: Tue, 21 Sep 2004 19:58:03 +0000 Subject: initial revision of widget to edit global configsettings (Locale) --- diff --git a/libkdepim/kprefswidget.cpp b/libkdepim/kprefswidget.cpp new file mode 100644 index 0000000..be9ad30 --- a/dev/null +++ b/libkdepim/kprefswidget.cpp @@ -0,0 +1,427 @@ +/* + This file is part of KOrganizer. + Copyright (c) 2001 Cornelius Schumacher + + 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; either version 2 of the License, or + (at your option) any later version. + + 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; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +// $Id$ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kprefs.h" + +#include "kprefswidget.h" +//#include "kprefsdialog.moc" + +KPrefsWidBool::KPrefsWidBool(const QString &text,bool *reference, + QWidget *parent) +{ + mReference = reference; + + mCheck = new QCheckBox(text,parent); + + connect( mCheck, SIGNAL( toggled( bool ) ), SIGNAL( modified() ) ); + +} + +void KPrefsWidBool::readConfig() +{ + mCheck->setChecked(*mReference); +} + +void KPrefsWidBool::writeConfig() +{ + *mReference = mCheck->isChecked(); +} + +QCheckBox *KPrefsWidBool::checkBox() +{ + return mCheck; +} + + +KPrefsWidColor::KPrefsWidColor(const QString &text,QColor *reference, + QWidget *parent) +{ + mReference = reference; + + mButton = new KColorButton(parent); + mLabel = new QLabel(mButton, text, parent); + mButton->setColor( *mReference ); + mButton->setColor( Qt::red ); + + connect( mButton, SIGNAL( changed(const QColor &)), SIGNAL( modified() ) ); + +} + +KPrefsWidColor::~KPrefsWidColor() +{ +// kdDebug(5300) << "KPrefsWidColor::~KPrefsWidColor()" << endl; +} + +void KPrefsWidColor::readConfig() +{ + mButton->setColor(*mReference); +} + +void KPrefsWidColor::writeConfig() +{ + *mReference = mButton->color(); +} + +QLabel *KPrefsWidColor::label() +{ + return mLabel; +} + +KColorButton *KPrefsWidColor::button() +{ + return mButton; +} + +KPrefsWidFont::KPrefsWidFont(const QString &sampleText,const QString &labelText, + QFont *reference,QWidget *parent) +{ + mReference = reference; + + mLabel = new QLabel(labelText, parent); + + mPreview = new QLabel(sampleText,parent); + mPreview->setFrameStyle(QFrame::Panel|QFrame::Sunken); + + mButton = new QPushButton(i18n("Choose..."), parent); + connect(mButton,SIGNAL(clicked()),SLOT(selectFont())); + mPreview->setMaximumHeight( QApplication::desktop()->height() / 12 ); + mPreview->setMaximumWidth( (QApplication::desktop()->width() / 2)-10 ); +} + +KPrefsWidFont::~KPrefsWidFont() +{ +} + +void KPrefsWidFont::readConfig() +{ + mPreview->setFont(*mReference); +} + +void KPrefsWidFont::writeConfig() +{ + *mReference = mPreview->font(); +} + +QLabel *KPrefsWidFont::label() +{ + return mLabel; +} + +QLabel *KPrefsWidFont::preview() +{ + return mPreview; +} + +QPushButton *KPrefsWidFont::button() +{ + return mButton; +} + +void KPrefsWidFont::selectFont() +{ + QFont myFont(mPreview->font()); + bool ok; + myFont = KFontDialog::getFont(myFont, ok); + if ( ok ) { + mPreview->setFont(myFont); + emit modified(); + } +} + + +KPrefsWidTime::KPrefsWidTime(const QString &text,int *reference, + QWidget *parent) +{ + mReference = reference; + + mLabel = new QLabel(text,parent); + mSpin = new QSpinBox(0,23,1,parent); + mSpin->setSuffix(":00"); + connect( mSpin, SIGNAL( valueChanged(int)), SIGNAL( modified() ) ); + +} + +void KPrefsWidTime::readConfig() +{ + mSpin->setValue(*mReference); +} + +void KPrefsWidTime::writeConfig() +{ + *mReference = mSpin->value(); +} + +QLabel *KPrefsWidTime::label() +{ + return mLabel; +} + +QSpinBox *KPrefsWidTime::spinBox() +{ + return mSpin; +} + + +KPrefsWidRadios::KPrefsWidRadios(const QString &text,int *reference, + QWidget *parent) +{ + mReference = reference; + + mBox = new QButtonGroup(1,Qt::Horizontal,text,parent); + connect( mBox, SIGNAL( clicked(int)), SIGNAL( modified() ) ); +} + +KPrefsWidRadios::~KPrefsWidRadios() +{ +} + +void KPrefsWidRadios::addRadio(const QString &text) +{ + new QRadioButton(text,mBox); +} + +QButtonGroup *KPrefsWidRadios::groupBox() +{ + return mBox; +} + +void KPrefsWidRadios::readConfig() +{ + mBox->setButton(*mReference); +} + +void KPrefsWidRadios::writeConfig() +{ + *mReference = mBox->id(mBox->selected()); +} + + +KPrefsWidString::KPrefsWidString(const QString &text,QString *reference, + QWidget *parent, QLineEdit::EchoMode echomode) +{ + mReference = reference; + + mLabel = new QLabel(text,parent); + mEdit = new QLineEdit(parent); + mEdit->setEchoMode( echomode ); + connect( mEdit, SIGNAL( textChanged(const QString&) ), SIGNAL( modified() ) ); + +} + +KPrefsWidString::~KPrefsWidString() +{ +} + +void KPrefsWidString::readConfig() +{ + mEdit->setText(*mReference); +} + +void KPrefsWidString::writeConfig() +{ + *mReference = mEdit->text(); +} + +QLabel *KPrefsWidString::label() +{ + return mLabel; +} + +QLineEdit *KPrefsWidString::lineEdit() +{ + return mEdit; +} + + +KPrefsWidget::KPrefsWidget(KPrefs *prefs,QWidget *parent,const char *name) : + QWidget(parent, name ) +{ + mPrefs = prefs; +} + +KPrefsWidget::~KPrefsWidget() +{ +} + +void KPrefsWidget::addWid(KPrefsWid *wid) +{ + mPrefsWids.append(wid); + connect( wid, SIGNAL( modified() ), this, SLOT( modified() ) ); + +} + +KPrefsWidBool *KPrefsWidget::addWidBool(const QString &text,bool *reference,QWidget *parent) +{ + KPrefsWidBool *w = new KPrefsWidBool(text,reference,parent); + addWid(w); + return w; +} + +KPrefsWidTime *KPrefsWidget::addWidTime(const QString &text,int *reference,QWidget *parent) +{ + KPrefsWidTime *w = new KPrefsWidTime(text,reference,parent); + addWid(w); + return w; +} + +KPrefsWidColor *KPrefsWidget::addWidColor(const QString &text,QColor *reference,QWidget *parent) +{ + KPrefsWidColor *w = new KPrefsWidColor(text,reference,parent); + addWid(w); + return w; +} + +KPrefsWidRadios *KPrefsWidget::addWidRadios(const QString &text,int *reference,QWidget *parent) +{ + KPrefsWidRadios *w = new KPrefsWidRadios(text,reference,parent); + addWid(w); + return w; +} + +KPrefsWidString *KPrefsWidget::addWidString(const QString &text,QString *reference,QWidget *parent) +{ + KPrefsWidString *w = new KPrefsWidString(text,reference,parent); + addWid(w); + return w; +} + +KPrefsWidString *KPrefsWidget::addWidPassword(const QString &text,QString *reference,QWidget *parent) +{ + KPrefsWidString *w = new KPrefsWidString(text,reference,parent,QLineEdit::Password); + addWid(w); + return w; +} + +KPrefsWidFont *KPrefsWidget::addWidFont(const QString &sampleText,const QString &buttonText, + QFont *reference,QWidget *parent) +{ + KPrefsWidFont *w = new KPrefsWidFont(sampleText,buttonText,reference,parent); + addWid(w); + return w; +} + +void KPrefsWidget::setDefaults() +{ + mPrefs->setDefaults(); + + readConfig(); +} + +void KPrefsWidget::readConfig() +{ +// kdDebug(5300) << "KPrefsDialog::readConfig()" << endl; + + KPrefsWid *wid; + for(wid = mPrefsWids.first();wid;wid=mPrefsWids.next()) { + wid->readConfig(); + } + + usrReadConfig(); + + emit changed( false ); + +} + +void KPrefsWidget::writeConfig() +{ +// kdDebug(5300) << "KPrefsDialog::writeConfig()" << endl; + + KPrefsWid *wid; + for(wid = mPrefsWids.first();wid;wid=mPrefsWids.next()) { + wid->writeConfig(); + } + + usrWriteConfig(); + +// kdDebug(5300) << "KPrefsDialog::writeConfig() now writing..." << endl; + + mPrefs->writeConfig(); + + emit changed( false ); + +// kdDebug(5300) << "KPrefsDialog::writeConfig() done" << endl; +} + +/*US +void KPrefsWidget::slotApply() +{ + writeConfig(); + emit configChanged(); +} + +void KPrefsDialog::slotOk() +{ + slotApply(); + QDialog::accept(); +} +void KPrefsDialog::accept() +{ + slotOk(); +} + +void KPrefsDialog::slotDefault() +{ + if (KMessageBox::warningContinueCancel(this, + i18n("You are about to set all\npreferences to default values.\nAll " + "custom modifications will be lost."),i18n("Setting Default Preferences"), + i18n("Continue")) + == KMessageBox::Continue) setDefaults(); +} +*/ + +void KPrefsWidget::modified() +{ + emit changed( true ); +} + diff --git a/libkdepim/kprefswidget.h b/libkdepim/kprefswidget.h new file mode 100644 index 0000000..8a24515 --- a/dev/null +++ b/libkdepim/kprefswidget.h @@ -0,0 +1,454 @@ +/* + This file is part of KOrganizer. + Copyright (c) 2001 Cornelius Schumacher + + 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; either version 2 of the License, or + (at your option) any later version. + + 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; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ +// $Id$ + +#ifndef _KPREFSWIDGET_H +#define _KPREFSWIDGET_H + +#include +#include + +#include + +class KPrefs; + +class KColorButton; +class QCheckBox; +class QLabel; +class QSpinBox; +class QButtonGroup; + +/** + @short Base class for widgets used by @ref KPrefsDialog. + @author Cornelius Schumacher + @see KPrefsDialog + + This class provides the interface for the preferences widgets used by + KPrefsDialog. +*/ +class KPrefsWid : public QObject +{ + Q_OBJECT + public: + /** + This function is called to read value of the setting from the + stored configuration and display it in the widget. + */ + virtual void readConfig() = 0; + /** + This function is called to write the current setting of the widget to the + stored configuration. + */ + virtual void writeConfig() = 0; + + //connect to this signal if you want to be notified of changes + signals: + void modified(); + +}; + +/** + @short Widget for bool settings in @ref KPrefsDialog. + + This class provides a widget for configuring bool values. It is meant to be + used by KPrefsDialog. The user is responsible for the layout management. +*/ +class KPrefsWidBool : public KPrefsWid +{ + public: + /** + Create a bool widget consisting of a QCheckbox. + + @param text Text of QCheckBox. + @param reference Pointer to variable read and written by this widget. + @param parent Parent widget. + */ + KPrefsWidBool(const QString &text,bool *reference,QWidget *parent); + + /** + Return the QCheckbox used by this widget. + */ + QCheckBox *checkBox(); + + void readConfig(); + void writeConfig(); + + private: + bool *mReference; + + QCheckBox *mCheck; +}; + +/** + @short Widget for time settings in @ref KPrefsDialog. + + This class provides a widget for configuring time values. It is meant to be + used by KPrefsDialog. The user is responsible for the layout management. +*/ +class KPrefsWidTime : public KPrefsWid +{ + public: + /** + Create a time widget consisting of a label and a spinbox. + + @param text Text of Label. + @param reference Pointer to variable read and written by this widget. + @param parent Parent widget. + */ + KPrefsWidTime(const QString &text,int *reference,QWidget *parent); + + /** + Return QLabel used by this widget. + */ + QLabel *label(); + /** + Return QSpinBox used by this widget. + */ + QSpinBox *spinBox(); + + void readConfig(); + void writeConfig(); + + private: + int *mReference; + + QLabel *mLabel; + QSpinBox *mSpin; +}; + +/** + @short Widget for color settings in @ref KPrefsDialog. + + This class provides a widget for configuring color values. It is meant to be + used by KPrefsDialog. The user is responsible for the layout management. +*/ +class KPrefsWidColor : public KPrefsWid +{ + public: + /** + Create a color widget consisting of a test field and a button for opening + a color dialog. + + @param text Text of button. + @param reference Pointer to variable read and written by this widget. + @param parent Parent widget. + */ + KPrefsWidColor(const QString &text,QColor *reference,QWidget *parent); + /** + Destruct color setting widget. + */ + ~KPrefsWidColor(); + + /** + Return QLabel for the button + */ + QLabel *label(); + /** + Return button opening the color dialog. + */ + KColorButton *button(); + + void readConfig(); + void writeConfig(); + + private: + QColor *mReference; + + QLabel *mLabel; + KColorButton *mButton; +}; + +/** + @short Widget for font settings in @ref KPrefsDialog. + + This class provides a widget for configuring font values. It is meant to be + used by KPrefsDialog. The user is responsible for the layout management. +*/ +class KPrefsWidFont : public KPrefsWid +{ + Q_OBJECT + public: + /** + Create a font widget consisting of a test field and a button for opening + a font dialog. + + @param label Text of label. + @param reference Pointer to variable read and written by this widget. + @param parent Parent widget. + */ + KPrefsWidFont(const QString &sampleText,const QString &labelText, + QFont *reference,QWidget *parent); + /** + Destruct font setting widget. + */ + ~KPrefsWidFont(); + + /** + Return label. + */ + QLabel *label(); + /** + Return QFrame used as preview field. + */ + QLabel *preview(); + /** + Return button opening the font dialog. + */ + QPushButton *button(); + + void readConfig(); + void writeConfig(); + + protected slots: + void selectFont(); + + private: + QFont *mReference; + + QLabel *mLabel; + QLabel *mPreview; + QPushButton *mButton; +}; + +/** + @short Widget for settings represented by a group of radio buttons in + @ref KPrefsDialog. + + This class provides a widget for configuring selections. It is meant to be + used by KPrefsDialog. The user is responsible for the layout management. The + setting is interpreted as an int value, corresponding to the position of the + radio button. The position of the button is defined by the sequence of @ref + addRadio() calls, starting with 0. +*/ +class KPrefsWidRadios : public KPrefsWid +{ + public: + /** + Create a widget for selection of an option. It consists of a box with + several radio buttons. + + @param text Text of main box. + @param reference Pointer to variable read and written by this widget. + @param parent Parent widget. + */ + KPrefsWidRadios(const QString &text,int *reference,QWidget *parent); + virtual ~KPrefsWidRadios(); + + /** + Add a radio button. + + @param text Text of the button. + */ + void addRadio(const QString &text); + + /** + Return the box widget used by this widget. + */ + QButtonGroup *groupBox(); + + void readConfig(); + void writeConfig(); + + private: + int *mReference; + + QButtonGroup *mBox; +}; + + +/** + @short Widget for string settings in @ref KPrefsDialog. + + This class provides a widget for configuring string values. It is meant to be + used by KPrefsDialog. The user is responsible for the layout management. +*/ +class KPrefsWidString : public KPrefsWid +{ + public: + /** + Create a string widget consisting of a test label and a line edit. + + @param text Text of label. + @param reference Pointer to variable read and written by this widget. + @param parent Parent widget. + */ + KPrefsWidString(const QString &text,QString *reference,QWidget *parent,QLineEdit::EchoMode echomode=QLineEdit::Normal); + /** + Destructor. + */ + virtual ~KPrefsWidString(); + + /** + Return label used by this widget. + */ + QLabel *label(); + /** + Return QLineEdit used by this widget. + */ + QLineEdit *lineEdit(); + + void readConfig(); + void writeConfig(); + + private: + QString *mReference; + + QLabel *mLabel; + QLineEdit *mEdit; +}; + + +/** + @short Base class for a preferences widget. + + This class provides the framework for a preferences widget. You have to + subclass it and add the code to create the actual configuration widgets and + do the layout management. + + KPrefsWidget provides functions to add subclasses of @ref KPrefsWid. For + these widgets the reading, writing and setting to default values is handled + automatically. Custom widgets have to be handled in the functions @ref + usrReadConfig() and @ref usrWriteConfig(). +*/ +class KPrefsWidget : public QWidget +{ + Q_OBJECT + public: + /** + Create a KPrefsDialog for a KPrefs object. + + @param prefs KPrefs object used to access te configuration. + @param parent Parent widget. + @param name Widget name. + */ + KPrefsWidget(KPrefs *prefs,QWidget *parent=0,const char *name=0); + /** + Destructor. + */ + virtual ~KPrefsWidget(); + + /** + Register a custom KPrefsWid object. + */ + void addWid(KPrefsWid *); + /** + Register a @ref KPrefsWidBool object. + + @param text Text of bool widget. + @param reference Reference to variable storing the setting. + @param parent Parent widget. + */ + KPrefsWidBool *addWidBool(const QString &text,bool *reference,QWidget *parent); + /** + Register a @ref KPrefsWidTime object. + + @param text Text of time widget. + @param reference Reference to variable storing the setting. + @param parent Parent widget. + */ + KPrefsWidTime *addWidTime(const QString &text,int *reference,QWidget *parent); + /** + Register a @ref KPrefsWidColor object. + + @param text Text of color widget. + @param reference Reference to variable storing the setting. + @param parent Parent widget. + */ + KPrefsWidColor *addWidColor(const QString &text,QColor *reference,QWidget *parent); + /** + Register a @ref KPrefsWidRadios object. + + @param text Text of radio button box widget. + @param reference Reference to variable storing the setting. + @param parent Parent widget. + */ + KPrefsWidRadios *addWidRadios(const QString &text,int *reference,QWidget *parent); + /** + Register a @ref KPrefsWidString object. + + @param text Text of string widget. + @param reference Reference to variable storing the setting. + @param parent Parent widget. + */ + KPrefsWidString *addWidString(const QString &text,QString *reference,QWidget *parent); + /** + Register a password @ref KPrefsWidString object, with echomode set to QLineEdit::Password. + + @param text Text of string widget. + @param reference Reference to variable storing the setting. + @param parent Parent widget. + */ + KPrefsWidString *addWidPassword (const QString &text,QString *reference,QWidget *parent); + /** + Register a @ref KPrefsWidFont object. + + @param sampleText Sample text of font widget. + @param buttonText Button text of font widget. + @param reference Reference to variable storing the setting. + @param parent Parent widget. + */ + KPrefsWidFont *addWidFont(const QString &sampleText,const QString &buttonText, + QFont *reference,QWidget *parent); + + public slots: + /** Set all widgets to default values. */ + void setDefaults(); + + /** Read preferences from config file. */ + void readConfig(); + + /** Write preferences to config file. */ + void writeConfig(); + + /** connect this slot to all UI elements */ + void modified(); + + signals: + /** Emitted when the a changed configuration has been stored. */ + //US void configChanged(); + void changed( bool ); + + protected slots: + /** Apply changes to preferences */ + //US void slotApply(); + + //US void accept(); + /** Accept changes to preferences and close dialog */ + //US void slotOk(); + + /** Set preferences to default values */ + //US void slotDefault(); + + protected: + /** Implement this to read custom configuration widgets. */ + virtual void usrReadConfig() {} + /** Implement this to write custom configuration widgets. */ + virtual void usrWriteConfig() {} + + private: + KPrefs *mPrefs; + + QPtrList mPrefsWids; +}; + +#endif -- cgit v0.9.0.2