26#include <tqbuttongroup.h>
27#include <tqlineedit.h>
31#include <tqcombobox.h>
32#include <tqcheckbox.h>
33#include <tqradiobutton.h>
34#include <tqpushbutton.h>
35#include <tqdatetimeedit.h>
36#include <tqwhatsthis.h>
38#include <kcolorbutton.h>
41#include <tdefontdialog.h>
42#include <tdemessagebox.h>
43#include <tdeconfigskeleton.h>
44#include <kurlrequester.h>
48#include "kprefsdialog.h"
49#include "kprefsdialog.moc"
51namespace KPrefsWidFactory {
53KPrefsWid *create( TDEConfigSkeletonItem *item, TQWidget *parent )
55 TDEConfigSkeleton::ItemBool *boolItem =
56 dynamic_cast<TDEConfigSkeleton::ItemBool *
>( item );
61 TDEConfigSkeleton::ItemString *stringItem =
62 dynamic_cast<TDEConfigSkeleton::ItemString *
>( item );
67 TDEConfigSkeleton::ItemEnum *enumItem =
68 dynamic_cast<TDEConfigSkeleton::ItemEnum *
>( item );
70 TQValueList<TDEConfigSkeleton::ItemEnum::Choice> choices = enumItem->choices();
71 if ( choices.isEmpty() ) {
72 kdError() <<
"KPrefsWidFactory::create(): Enum has no choices." << endl;
76 TQValueList<TDEConfigSkeleton::ItemEnum::Choice>::ConstIterator it;
77 for( it = choices.begin(); it != choices.end(); ++it ) {
84 TDEConfigSkeleton::ItemInt *intItem =
85 dynamic_cast<TDEConfigSkeleton::ItemInt *
>( item );
98 return TQValueList<TQWidget *>();
105 mCheck =
new TQCheckBox( item->label(), parent);
106 connect( mCheck, TQ_SIGNAL( clicked() ), TQ_SIGNAL(
changed() ) );
107 if ( !item->whatsThis().isNull() ) {
108 TQWhatsThis::add( mCheck, item->whatsThis() );
114 mCheck->setChecked( mItem->value() );
119 mItem->setValue( mCheck->isChecked() );
129 TQValueList<TQWidget *>
widgets;
139 mLabel =
new TQLabel( mItem->label()+
':', parent );
140 mSpin =
new TQSpinBox( parent );
141 if ( !item->minValue().isNull() ) {
142 mSpin->setMinValue( item->minValue().toInt() );
144 if ( !item->maxValue().isNull() ) {
145 mSpin->setMaxValue( item->maxValue().toInt() );
147 connect( mSpin, TQ_SIGNAL( valueChanged(
int ) ), TQ_SIGNAL(
changed() ) );
148 mLabel->setBuddy( mSpin );
149 TQString whatsThis = mItem->whatsThis();
150 if ( !whatsThis.isEmpty() ) {
151 TQWhatsThis::add( mLabel, whatsThis );
152 TQWhatsThis::add( mSpin, whatsThis );
158 mSpin->setValue( mItem->value() );
163 mItem->setValue( mSpin->value() );
178 TQValueList<TQWidget *>
widgets;
189 mButton =
new KColorButton( parent );
190 connect( mButton, TQ_SIGNAL(
changed(
const TQColor & ) ), TQ_SIGNAL(
changed() ) );
191 mLabel =
new TQLabel( mButton, mItem->label()+
':', parent );
192 mLabel->setBuddy( mButton );
193 TQString whatsThis = mItem->whatsThis();
194 if (!whatsThis.isNull()) {
195 TQWhatsThis::add(mButton, whatsThis);
206 mButton->setColor( mItem->value() );
211 mItem->setValue( mButton->color() );
226 TQWidget *parent,
const TQString &sampleText )
229 mLabel =
new TQLabel( mItem->label()+
':', parent );
231 mPreview =
new TQLabel( sampleText, parent );
232 mPreview->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
234 mButton =
new TQPushButton( i18n(
"Choose..."), parent );
235 connect( mButton, TQ_SIGNAL( clicked() ), TQ_SLOT( selectFont() ) );
236 TQString whatsThis = mItem->whatsThis();
237 if (!whatsThis.isNull()) {
238 TQWhatsThis::add(mPreview, whatsThis);
239 TQWhatsThis::add(mButton, whatsThis);
249 mPreview->setFont( mItem->value() );
254 mItem->setValue( mPreview->font() );
272void KPrefsWidFont::selectFont()
274 TQFont myFont(mPreview->font());
275 int result = TDEFontDialog::getFont(myFont);
276 if (result == TDEFontDialog::Accepted) {
277 mPreview->setFont(myFont);
287 mLabel =
new TQLabel( mItem->label()+
':', parent );
289 mLabel->setBuddy( mTimeEdit );
290 connect( mTimeEdit, TQ_SIGNAL( timeChanged( TQTime ) ), TQ_SIGNAL(
changed() ) );
291 TQString whatsThis = mItem->whatsThis();
292 if ( !whatsThis.isNull() ) {
293 TQWhatsThis::add( mTimeEdit, whatsThis );
299 mTimeEdit->
setTime( mItem->value().time() );
306 TQDateTime dt( mItem->value() );
307 dt.setTime( mTimeEdit->
getTime() );
308 mItem->setValue( dt );
326 mLabel =
new TQLabel( mItem->label()+
':', parent );
327 mTimeEdit =
new TQTimeEdit( parent );
328 mLabel->setBuddy( mTimeEdit );
329 mTimeEdit->setAutoAdvance(
true );
330 mTimeEdit->setDisplay( TQTimeEdit::Hours | TQTimeEdit::Minutes );
331 mTimeEdit->setRange( TQTime( 0, 1 ), TQTime( 24, 0 ) );
333 TQ_SIGNAL( valueChanged(
const TQTime & ) ), TQ_SIGNAL(
changed() ) );
334 TQString whatsThis = mItem->whatsThis();
335 if ( !whatsThis.isNull() ) {
336 TQWhatsThis::add( mTimeEdit, whatsThis );
342 mTimeEdit->setTime( mItem->value().time() );
347 TQDateTime dt( mItem->value() );
348 dt.setTime( mTimeEdit->time() );
349 mItem->setValue( dt );
367 mLabel =
new TQLabel( mItem->label()+
':', parent );
369 mLabel->setBuddy( mDateEdit );
370 connect( mDateEdit, TQ_SIGNAL( dateChanged(
const TQDate& ) ), TQ_SIGNAL(
changed() ) );
371 TQString whatsThis = mItem->whatsThis();
372 if ( !whatsThis.isNull() ) {
373 TQWhatsThis::add( mDateEdit, whatsThis );
379 mDateEdit->
setDate( mItem->value().date().isValid() ? mItem->value().date() : TQDate::currentDate() );
384 TQDateTime dt( mItem->value() );
385 dt.setDate( mDateEdit->
date() );
386 mItem->setValue( dt );
404 mBox =
new TQButtonGroup( 1, TQt::Horizontal, mItem->label(), parent );
405 connect( mBox, TQ_SIGNAL( clicked(
int ) ), TQ_SIGNAL(
changed() ) );
408KPrefsWidRadios::~KPrefsWidRadios()
414 TQRadioButton *r =
new TQRadioButton(text,mBox);
415 if (!whatsThis.isNull()) {
416 TQWhatsThis::add(r, whatsThis);
427 mBox->setButton( mItem->value() );
432 mItem->setValue( mBox->id( mBox->selected() ) );
437 TQValueList<TQWidget *> w;
446 TQHBox *hbox =
new TQHBox(parent);
447 new TQLabel( mItem->label(), hbox );
448 mCombo =
new TQComboBox( hbox );
449 connect( mCombo, TQ_SIGNAL( activated(
int ) ), TQ_SIGNAL(
changed() ) );
452KPrefsWidCombo::~KPrefsWidCombo()
458 mCombo->setCurrentItem( mItem->value() );
463 mItem->setValue( mCombo->currentItem() );
468 TQValueList<TQWidget *> w;
473TQComboBox* KPrefsWidCombo::comboBox()
480 TQLineEdit::EchoMode echomode )
483 mLabel =
new TQLabel( mItem->label()+
':', parent );
484 mEdit =
new TQLineEdit( parent );
485 mLabel->setBuddy( mEdit );
486 connect( mEdit, TQ_SIGNAL( textChanged(
const TQString & ) ),
488 mEdit->setEchoMode( echomode );
489 TQString whatsThis = mItem->whatsThis();
490 if ( !whatsThis.isNull() ) {
491 TQWhatsThis::add( mEdit, whatsThis );
501 mEdit->setText( mItem->value() );
506 mItem->setValue( mEdit->text() );
521 TQValueList<TQWidget *>
widgets;
529 const TQString &filter, uint mode )
532 mLabel =
new TQLabel( mItem->label()+
':', parent );
533 mURLRequester =
new KURLRequester( parent );
534 mLabel->setBuddy( mURLRequester );
535 mURLRequester->setMode( mode );
536 mURLRequester->setFilter( filter );
537 connect( mURLRequester, TQ_SIGNAL( textChanged(
const TQString & ) ),
539 TQString whatsThis = mItem->whatsThis();
540 if ( !whatsThis.isNull() ) {
541 TQWhatsThis::add( mURLRequester, whatsThis );
551 mURLRequester->setURL( mItem->value() );
556 mItem->setValue( mURLRequester->url() );
566 return mURLRequester;
571 TQValueList<TQWidget *>
widgets;
573 widgets.append( mURLRequester );
589 mPrefsWids.append( wid );
636 TQValueList<TDEConfigSkeleton::ItemEnum::Choice> choices;
637 choices = item->choices();
638 TQValueList<TDEConfigSkeleton::ItemEnum::Choice>::ConstIterator it;
639 for( it = choices.begin(); it != choices.end(); ++it ) {
640 w->
addRadio( (*it).label, (*it).whatsThis );
650 TQValueList<TDEConfigSkeleton::ItemEnum::Choice> choices;
651 choices = item->choices();
652 TQValueList<TDEConfigSkeleton::ItemEnum::Choice>::ConstIterator it;
653 for( it = choices.begin(); it != choices.end(); ++it ) {
654 w->comboBox()->insertItem( (*it).label, -1 );
664 TQLineEdit::Normal );
670 TQWidget *parent,
const TQString &filter, uint mode )
687 const TQString &sampleText )
704 kdDebug() <<
"KPrefsWidManager::setWidDefaults()" << endl;
706 bool tmp = mPrefs->useDefaults(
true );
710 mPrefs->useDefaults( tmp );
715 kdDebug(5310) <<
"KPrefsWidManager::readWidConfig()" << endl;
718 for( wid = mPrefsWids.first(); wid; wid = mPrefsWids.next() ) {
725 kdDebug(5310) <<
"KPrefsWidManager::writeWidConfig()" << endl;
728 for( wid = mPrefsWids.first(); wid; wid = mPrefsWids.next() ) {
732 mPrefs->writeConfig();
738 : KDialogBase(IconList,i18n(
"Preferences"),Ok|Apply|Cancel|Default,Ok,parent,
746 connect(
this,TQ_SIGNAL(cancelClicked()),TQ_SLOT(reject()));
753void KPrefsDialog::autoCreate()
755 TDEConfigSkeletonItem::List items = prefs()->items();
757 TQMap<TQString,TQWidget *> mGroupPages;
758 TQMap<TQString,TQGridLayout *> mGroupLayouts;
759 TQMap<TQString,int> mCurrentRows;
761 TDEConfigSkeletonItem::List::ConstIterator it;
762 for( it = items.begin(); it != items.end(); ++it ) {
763 TQString group = (*it)->group();
764 TQString name = (*it)->name();
766 kdDebug() <<
"ITEMS: " << (*it)->name() << endl;
769 TQGridLayout *layout;
771 if ( !mGroupPages.contains( group ) ) {
772 page = addPage( group );
773 layout =
new TQGridLayout( page );
774 mGroupPages.insert( group, page );
775 mGroupLayouts.insert( group, layout );
777 mCurrentRows.insert( group, currentRow );
779 page = mGroupPages[ group ];
780 layout = mGroupLayouts[ group ];
781 currentRow = mCurrentRows[ group ];
784 KPrefsWid *wid = KPrefsWidFactory::create( *it, page );
787 TQValueList<TQWidget *> widgets = wid->
widgets();
788 if ( widgets.count() == 1 ) {
789 layout->addMultiCellWidget( widgets[ 0 ],
790 currentRow, currentRow, 0, 1 );
791 }
else if ( widgets.count() == 2 ) {
792 layout->addWidget( widgets[ 0 ], currentRow, 0 );
793 layout->addWidget( widgets[ 1 ], currentRow, 1 );
795 kdError() <<
"More widgets than expected: " << widgets.count() << endl;
798 if ( (*it)->isImmutable() ) {
799 TQValueList<TQWidget *>::Iterator it2;
800 for( it2 = widgets.begin(); it2 != widgets.end(); ++it2 ) {
801 (*it2)->setEnabled(
false );
807 mCurrentRows.replace( group, ++currentRow );
850 kdDebug() <<
"KPrefsDialog::slotDefault()" << endl;
852 if (KMessageBox::warningContinueCancel(
this,
853 i18n(
"You are about to set all preferences to default values. All "
854 "custom modifications will be lost."),i18n(
"Setting Default Preferences"),
855 i18n(
"Reset to Defaults"))
860KPrefsModule::KPrefsModule( TDEConfigSkeleton *prefs, TQWidget *parent,
862 : TDECModule( parent, name ),
865 emit changed(
false );
868void KPrefsModule::addWid(
KPrefsWid *wid )
872 connect( wid, TQ_SIGNAL( changed() ), TQ_SLOT( slotWidChanged() ) );
875void KPrefsModule::slotWidChanged()
877 kdDebug(5310) <<
"KPrefsModule::slotWidChanged()" << endl;
879 emit changed(
true );
882void KPrefsModule::load()
884 kdDebug(5310) <<
"KPrefsModule::load()" << endl;
890 emit changed(
false );
893void KPrefsModule::save()
895 kdDebug(5310) <<
"KPrefsModule::save()" << endl;
902void KPrefsModule::defaults()
906 emit changed(
true );
A date editing widget that consists of an editable combo box.
void setDate(const TQDate &date)
Sets the date.
void slotApply()
Apply changes to preferences.
void readConfig()
Read preferences from config file.
void writeConfig()
Write preferences to config file.
virtual void usrReadConfig()
Implement this to read custom configuration widgets.
KPrefsDialog(TDEConfigSkeleton *prefs, TQWidget *parent=0, char *name=0, bool modal=false)
Create a KPrefsDialog for a KPrefs object.
void setDefaults()
Set all widgets to default values.
void slotOk()
Accept changes to preferences and close dialog.
virtual ~KPrefsDialog()
Destructor.
void slotDefault()
Set preferences to default values.
void configChanged()
Emitted when the a changed configuration has been stored.
virtual void usrWriteConfig()
Implement this to write custom configuration widgets.
Widgets for bool settings in KPrefsDialog.
TQValueList< TQWidget * > widgets() const
Return a list of widgets used by this control element.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
KPrefsWidBool(TDEConfigSkeleton::ItemBool *item, TQWidget *parent)
Create a bool value control element consisting of a TQCheckbox.
TQCheckBox * checkBox()
Return the TQCheckbox used by this control element.
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
Widgets for color settings in KPrefsDialog.
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
KColorButton * button()
Return button opening the color dialog.
KPrefsWidColor(TDEConfigSkeleton::ItemColor *item, TQWidget *parent)
Create a color value control element consisting of a test field and a button for opening a color dial...
~KPrefsWidColor()
Destruct color setting widget.
TQLabel * label()
Return TQLabel for the button.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
Widgets for settings represented by a combo box in KPrefsDialog.
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
TQValueList< TQWidget * > widgets() const
Return a list of widgets used by this control element.
KPrefsWidCombo(TDEConfigSkeleton::ItemEnum *item, TQWidget *parent)
Create a control element for selection of an option.
Widgets for time settings in KPrefsDialog.
KPrefsWidDate(TDEConfigSkeleton::ItemDateTime *item, TQWidget *parent)
Create a time value control element consisting of a label and a date box.
TQLabel * label()
Return TQLabel used by this widget.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
KDateEdit * dateEdit()
Return TQSpinBox used by this widget.
Widgets for duration settings in KPrefsDialog.
TQLabel * label()
Return TQLabel used by this widget.
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
KPrefsWidDuration(TDEConfigSkeleton::ItemDateTime *item, TQWidget *parent)
Create a duration value control element consisting of a label and a spinbox.
TQTimeEdit * timeEdit()
Return TQSpinBox used by this widget.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
Widgets for font settings in KPrefsDialog.
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
~KPrefsWidFont()
Destruct font setting widget.
TQFrame * preview()
Return TQFrame used as preview field.
TQLabel * label()
Return TQLabel.
TQPushButton * button()
Return button opening the font dialog.
KPrefsWidFont(TDEConfigSkeleton::ItemFont *item, TQWidget *parent, const TQString &sampleText)
Create a font value control element consisting of a test field and a button for opening a font dialog...
Widgets for int settings in KPrefsDialog.
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
TQLabel * label()
Return TQLabel used by this control element.
TQSpinBox * spinBox()
Return the TQSpinBox used by this control element.
TQValueList< TQWidget * > widgets() const
Return a list of widgets used by this control element.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
KPrefsWidInt(TDEConfigSkeleton::ItemInt *item, TQWidget *parent)
Create a integer value control element consisting of a label and a spinbox.
Class for managing KPrefsWid objects.
KPrefsWidDuration * addWidDuration(TDEConfigSkeleton::ItemDateTime *item, TQWidget *parent)
Register a KPrefsWidDuration object.
KPrefsWidColor * addWidColor(TDEConfigSkeleton::ItemColor *item, TQWidget *parent)
Register a KPrefsWidColor object.
KPrefsWidString * addWidString(TDEConfigSkeleton::ItemString *item, TQWidget *parent)
Register a KPrefsWidString object.
KPrefsWidRadios * addWidRadios(TDEConfigSkeleton::ItemEnum *item, TQWidget *parent)
Register a KPrefsWidRadios object.
KPrefsWidTime * addWidTime(TDEConfigSkeleton::ItemDateTime *item, TQWidget *parent)
Register a KPrefsWidTime object.
KPrefsWidFont * addWidFont(TDEConfigSkeleton::ItemFont *item, TQWidget *parent, const TQString &sampleText)
Register a KPrefsWidFont object.
KPrefsWidPath * addWidPath(TDEConfigSkeleton::ItemPath *item, TQWidget *parent, const TQString &filter=TQString(), uint mode=KFile::File)
Register a path KPrefsWidPath object.
KPrefsWidBool * addWidBool(TDEConfigSkeleton::ItemBool *item, TQWidget *parent)
Register a KPrefsWidBool object.
void setWidDefaults()
Set all widgets to default values.
KPrefsWidCombo * addWidCombo(TDEConfigSkeleton::ItemEnum *item, TQWidget *parent)
Register a KPrefsWidCombo object.
KPrefsWidManager(TDEConfigSkeleton *prefs)
Create a KPrefsWidManager object for a KPrefs object.
virtual void addWid(KPrefsWid *)
Register a custom KPrefsWid object.
KPrefsWidDate * addWidDate(TDEConfigSkeleton::ItemDateTime *item, TQWidget *parent)
Register a KPrefsWidDate object.
void writeWidConfig()
Write preferences to config file.
KPrefsWidString * addWidPassword(TDEConfigSkeleton::ItemString *item, TQWidget *parent)
Register a password KPrefsWidString object, with echomode set to TQLineEdit::Password.
KPrefsWidInt * addWidInt(TDEConfigSkeleton::ItemInt *item, TQWidget *parent)
Register a KPrefsWidInt object.
void readWidConfig()
Read preferences from config file.
virtual ~KPrefsWidManager()
Destructor.
Widgets for string settings in KPrefsDialog.
KURLRequester * urlRequester()
Return TQLineEdit used by this widget.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
KPrefsWidPath(TDEConfigSkeleton::ItemPath *item, TQWidget *parent, const TQString &filter=TQString(), uint mode=KFile::File)
Create a string value control element consisting of a test label and a line edit.
TQValueList< TQWidget * > widgets() const
Return a list of widgets used by this control element.
virtual ~KPrefsWidPath()
Destructor.
TQLabel * label()
Return TQLabel used by this widget.
Widgets for settings represented by a group of radio buttons in KPrefsDialog.
void addRadio(const TQString &text, const TQString &whatsThis=TQString())
Add a radio button.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
KPrefsWidRadios(TDEConfigSkeleton::ItemEnum *item, TQWidget *parent)
Create a control element for selection of an option.
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
TQButtonGroup * groupBox()
Return the box widget used by this widget.
TQValueList< TQWidget * > widgets() const
Return a list of widgets used by this control element.
Widgets for string settings in KPrefsDialog.
virtual ~KPrefsWidString()
Destructor.
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
TQLineEdit * lineEdit()
Return TQLineEdit used by this widget.
TQValueList< TQWidget * > widgets() const
Return a list of widgets used by this control element.
KPrefsWidString(TDEConfigSkeleton::ItemString *item, TQWidget *parent, TQLineEdit::EchoMode echomode=TQLineEdit::Normal)
Create a string value control element consisting of a test label and a line edit.
TQLabel * label()
Return TQLabel used by this widget.
Widgets for time settings in KPrefsDialog.
KPrefsWidTime(TDEConfigSkeleton::ItemDateTime *item, TQWidget *parent)
Create a time value control element consisting of a label and a spinbox.
TQLabel * label()
Return TQLabel used by this widget.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
KTimeEdit * timeEdit()
Return TQSpinBox used by this widget.
Base class for GUI control elements used by KPrefsDialog.
virtual TQValueList< TQWidget * > widgets() const
Return a list of widgets used by this control element.
void changed()
Emitted when widget value has changed.
virtual void writeConfig()=0
This function is called to write the current setting of the widget to the stored configuration.
virtual void readConfig()=0
This function is called to read value of the setting from the stored configuration and display it in ...
This is a class that provides an easy, user friendly way to edit times.
TQTime getTime() const
returns the time that is currently set in the timeLineEdit.
void setTime(TQTime qt)
used to set the time which is displayed to a specific value.