kdeui Library API Documentation

kconfigdialog.cpp

00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (C) 2003 Benjamin C Meyer (ben+kdelibs at meyerhome dot net) 00004 * Copyright (C) 2003 Waldo Bastian <bastian@kde.org> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public License 00017 * along with this library; see the file COPYING.LIB. If not, write to 00018 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00019 * Boston, MA 02111-1307, USA. 00020 */ 00021 #include "kconfigdialog.h" 00022 #include "kconfigdialog.moc" 00023 00024 #include <kconfigskeleton.h> 00025 #include <kconfigdialogmanager.h> 00026 #include <klocale.h> 00027 #include <kiconloader.h> 00028 #include <kdebug.h> 00029 00030 #include <qlayout.h> 00031 #include <qvbox.h> 00032 00033 QAsciiDict<KConfigDialog> KConfigDialog::openDialogs; 00034 00035 // This class is here purly so we don't break binary compatibility down the road. 00036 class KConfigDialog::KConfigDialogPrivate 00037 { 00038 00039 public: 00040 KConfigDialogPrivate(KDialogBase::DialogType t) 00041 : shown(false), type(t), mgr(0) { } 00042 00043 bool shown; 00044 KDialogBase::DialogType type; 00045 KConfigDialogManager *mgr; 00046 }; 00047 00048 KConfigDialog::KConfigDialog( QWidget *parent, const char *name, 00049 KConfigSkeleton *config, 00050 DialogType dialogType, 00051 int dialogButtons, 00052 ButtonCode defaultButton, 00053 bool modal ) : 00054 KDialogBase( dialogType, Qt::WStyle_DialogBorder, 00055 parent, name, modal, i18n("Configure"), dialogButtons, defaultButton ), 00056 d(new KConfigDialogPrivate(dialogType)) 00057 { 00058 if ( name ) { 00059 openDialogs.insert(name, this); 00060 } else { 00061 QCString genericName; 00062 genericName.sprintf("SettingsDialog-%p", this); 00063 openDialogs.insert(genericName, this); 00064 setName(genericName); 00065 } 00066 00067 d->mgr = new KConfigDialogManager(this, config); 00068 00069 // TODO: Emit settingsChanged signal from slot to guarantee sequence 00070 connect(d->mgr, SIGNAL(settingsChanged()), this, SIGNAL(settingsChanged())); 00071 connect(d->mgr, SIGNAL(settingsChanged()), this, SLOT(settingsChangedSlot())); 00072 connect(d->mgr, SIGNAL(widgetModified()), this, SLOT(updateButtons())); 00073 00074 connect(this, SIGNAL(okClicked()), this, SLOT(updateSettings())); 00075 connect(this, SIGNAL(okClicked()), d->mgr, SLOT(updateSettings())); 00076 00077 connect(this, SIGNAL(applyClicked()), this, SLOT(updateSettings())); 00078 connect(this, SIGNAL(applyClicked()), d->mgr, SLOT(updateSettings())); 00079 connect(this, SIGNAL(applyClicked()), this, SLOT(updateButtons())); 00080 00081 connect(this, SIGNAL(defaultClicked()), this, SLOT(updateWidgetsDefault())); 00082 connect(this, SIGNAL(defaultClicked()), d->mgr, SLOT(updateWidgetsDefault())); 00083 connect(this, SIGNAL(defaultClicked()), this, SLOT(updateButtons())); 00084 00085 enableButton(Apply, false); 00086 } 00087 00088 KConfigDialog::~KConfigDialog() 00089 { 00090 openDialogs.remove(name()); 00091 delete d; 00092 } 00093 00094 void KConfigDialog::addPage(QWidget *page, 00095 const QString &itemName, 00096 const QString &pixmapName, 00097 const QString &header, 00098 bool manage) 00099 { 00100 if(d->shown) 00101 { 00102 kdDebug(240) << "KConfigDialog::addPage: can not add a page after the dialog has been shown."; 00103 return; 00104 } 00105 switch(d->type) 00106 { 00107 case TreeList: 00108 case IconList: 00109 case Tabbed: { 00110 QVBox *frame = addVBoxPage(itemName, header, SmallIcon(pixmapName, 32)); 00111 frame->setSpacing( 0 ); 00112 frame->setMargin( 0 ); 00113 page->reparent(((QWidget*)frame), 0, QPoint()); 00114 } 00115 break; 00116 00117 case Swallow: 00118 { 00119 page->reparent(this, 0, QPoint()); 00120 setMainWidget(page); 00121 } 00122 break; 00123 00124 case Plain: 00125 { 00126 QFrame *main = plainPage(); 00127 QVBoxLayout *topLayout = new QVBoxLayout( main, 0, 0 ); 00128 page->reparent(((QWidget*)main), 0, QPoint()); 00129 topLayout->addWidget( page ); 00130 } 00131 break; 00132 00133 default: 00134 kdDebug(240) << "KConfigDialog::addpage: unknown type."; 00135 } 00136 if(manage) 00137 d->mgr->addWidget(page); 00138 } 00139 00140 KConfigDialog* KConfigDialog::exists(const char* name) 00141 { 00142 return openDialogs.find(name); 00143 } 00144 00145 bool KConfigDialog::showDialog(const char* name) 00146 { 00147 KConfigDialog *dialog = exists(name); 00148 if(dialog) 00149 dialog->show(); 00150 return (dialog != NULL); 00151 } 00152 00153 void KConfigDialog::updateButtons() 00154 { 00155 static bool only_once = false; 00156 if (only_once) return; 00157 only_once = true; 00158 enableButton(Apply, d->mgr->hasChanged() || hasChanged()); 00159 enableButton(Default, !(d->mgr->isDefault() && isDefault())); 00160 emit widgetModified(); 00161 only_once = false; 00162 } 00163 00164 void KConfigDialog::settingsChangedSlot() 00165 { 00166 // Update the buttons 00167 updateButtons(); 00168 emit (settingsChanged(name())); 00169 } 00170 00171 void KConfigDialog::show() 00172 { 00173 updateWidgets(); 00174 d->mgr->updateWidgets(); 00175 enableButton(Apply, d->mgr->hasChanged() || hasChanged()); 00176 enableButton(Default, !(d->mgr->isDefault() && isDefault())); 00177 d->shown = true; 00178 KDialogBase::show(); 00179 } 00180 00181 void KConfigDialog::updateSettings() 00182 { 00183 } 00184 00185 void KConfigDialog::updateWidgets() 00186 { 00187 } 00188 00189 void KConfigDialog::updateWidgetsDefault() 00190 { 00191 }
KDE Logo
This file is part of the documentation for kdeui Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 12 15:08:14 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003