| # kdeui Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# 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  *  Copyright (C) 2004 Michael Brade <brade@kde.org>
    00006  *
    00007  *  This library is free software; you can redistribute it and/or
    00008  *  modify it under the terms of the GNU Library General Public
    00009  *  License as published by the Free Software Foundation; either
    00010  *  version 2 of the License, or (at your option) any later version.
    00011  *
    00012  *  This library 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  *  Library General Public License for more details.
    00016  *
    00017  *  You should have received a copy of the GNU Library General Public License
    00018  *  along with this library; see the file COPYING.LIB.  If not, write to
    00019  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00020  *  Boston, MA 02111-1307, USA.
    00021  */
    00022 #include "kconfigdialog.h"
    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 #include <qmap.h>
    00033
    00034 QAsciiDict<KConfigDialog> KConfigDialog::openDialogs;
    00035
    00036 // This class is here purly so we don't break binary compatibility down the road.
    00037 class KConfigDialog::KConfigDialogPrivate
    00038 {
    00039 public:
    00040   KConfigDialogPrivate(KDialogBase::DialogType t)
    00041   : shown(false), type(t), manager(0) { }
    00042
    00043   bool shown;
    00044   KDialogBase::DialogType type;
    00045   KConfigDialogManager *manager;
    00046   QMap<QWidget *, KConfigDialogManager *> managerForPage;
    00047 };
    00048
    00049 KConfigDialog::KConfigDialog( QWidget *parent, const char *name,
    00050           KConfigSkeleton *config,
    00051           DialogType dialogType,
    00052           int dialogButtons,
    00053           ButtonCode defaultButton,
    00054           bool modal ) :
    00055     KDialogBase( dialogType, Qt::WStyle_DialogBorder,
    00056           parent, name, modal, i18n("Configure"), dialogButtons, defaultButton ),
    00057     d(new KConfigDialogPrivate(dialogType))
    00058 {
    00059   if ( name ) {
    00060     openDialogs.insert(name, this);
    00061   } else {
    00062     QCString genericName;
    00063     genericName.sprintf("SettingsDialog-%p", this);
    00064     openDialogs.insert(genericName, this);
    00065     setName(genericName);
    00066   }
    00067
    00068   connect(this, SIGNAL(okClicked()), this, SLOT(updateSettings()));
    00069   connect(this, SIGNAL(applyClicked()), this, SLOT(updateSettings()));
    00070   connect(this, SIGNAL(applyClicked()), this, SLOT(updateButtons()));
    00071   connect(this, SIGNAL(defaultClicked()), this, SLOT(updateWidgetsDefault()));
    00072   connect(this, SIGNAL(defaultClicked()), this, SLOT(updateButtons()));
    00073
    00074   d->manager = new KConfigDialogManager(this, config);
    00075   setupManagerConnections(d->manager);
    00076
    00077   enableButton(Apply, false);
    00078 }
    00079
    00080 KConfigDialog::~KConfigDialog()
    00081 {
    00082   openDialogs.remove(name());
    00083   delete d;
    00084 }
    00085
    00086 void KConfigDialog::addPage(QWidget *page,
    00087                                 const QString &itemName,
    00088                                 const QString &pixmapName,
    00089                                 const QString &header,
    00090                                 bool manage)
    00091 {
    00092   addPageInternal(page, itemName, pixmapName, header);
    00093   if(manage)
    00094     d->manager->addWidget(page);
    00095 }
    00096
    00097 void KConfigDialog::addPage(QWidget *page,
    00098                                 KConfigSkeleton *config,
    00099                                 const QString &itemName,
    00100                                 const QString &pixmapName,
    00101                                 const QString &header)
    00102 {
    00103   addPageInternal(page, itemName, pixmapName, header);
    00104   d->managerForPage[page] = new KConfigDialogManager(page, config);
    00105   setupManagerConnections(d->managerForPage[page]);
    00106 }
    00107
    00108 void KConfigDialog::addPageInternal(QWidget *page,
    00109                                         const QString &itemName,
    00110                                         const QString &pixmapName,
    00111                                         const QString &header)
    00112 {
    00113   if(d->shown)
    00114   {
    00115     kdDebug(240) << "KConfigDialog::addPage: can not add a page after the dialog has been shown.";
    00116     return;
    00117   }
    00118   switch(d->type)
    00119   {
    00120     case TreeList:
    00121     case IconList:
    00122     case Tabbed: {
    00123       QVBox *frame = addVBoxPage(itemName, header, SmallIcon(pixmapName, 32));
    00124       frame->setSpacing( 0 );
    00125       frame->setMargin( 0 );
    00126       page->reparent(((QWidget*)frame), 0, QPoint());
    00127     }
    00128     break;
    00129
    00130     case Swallow:
    00131     {
    00132       page->reparent(this, 0, QPoint());
    00133       setMainWidget(page);
    00134     }
    00135     break;
    00136
    00137     case Plain:
    00138     {
    00139       QFrame *main = plainPage();
    00140       QVBoxLayout *topLayout = new QVBoxLayout( main, 0, 0 );
    00141       page->reparent(((QWidget*)main), 0, QPoint());
    00142       topLayout->addWidget( page );
    00143     }
    00144     break;
    00145
    00146     default:
    00147       kdDebug(240) << "KConfigDialog::addpage: unknown type.";
    00148   }
    00149 }
    00150
    00151 void KConfigDialog::setupManagerConnections(KConfigDialogManager *manager)
    00152 {
    00153   connect(manager, SIGNAL(settingsChanged()), this, SLOT(settingsChangedSlot()));
    00154   connect(manager, SIGNAL(widgetModified()), this, SLOT(updateButtons()));
    00155
    00156   connect(this, SIGNAL(okClicked()), manager, SLOT(updateSettings()));
    00157   connect(this, SIGNAL(applyClicked()), manager, SLOT(updateSettings()));
    00158   connect(this, SIGNAL(defaultClicked()), manager, SLOT(updateWidgetsDefault()));
    00159 }
    00160
    00161 KConfigDialog* KConfigDialog::exists(const char* name)
    00162 {
    00163   return openDialogs.find(name);
    00164 }
    00165
    00166 bool KConfigDialog::showDialog(const char* name)
    00167 {
    00168   KConfigDialog *dialog = exists(name);
    00169   if(dialog)
    00170     dialog->show();
    00171   return (dialog != NULL);
    00172 }
    00173
    00174 void KConfigDialog::updateButtons()
    00175 {
    00176   static bool only_once = false;
    00177   if (only_once) return;
    00178   only_once = true;
    00179
    00180   QMap<QWidget *, KConfigDialogManager *>::iterator it;
    00181
    00182   bool has_changed = d->manager->hasChanged() || hasChanged();
    00183   for (it = d->managerForPage.begin();
    00184           it != d->managerForPage.end() && !has_changed;
    00185           ++it)
    00186   {
    00187     has_changed |= (*it)->hasChanged();
    00188   }
    00189
    00190   enableButton(Apply, has_changed);
    00191
    00192   bool is_default = d->manager->isDefault() && isDefault();
    00193   for (it = d->managerForPage.begin();
    00194           it != d->managerForPage.end() && is_default;
    00195           ++it)
    00196   {
    00197     is_default &= (*it)->isDefault();
    00198   }
    00199
    00200   enableButton(Default, !is_default);
    00201
    00202   emit widgetModified();
    00203   only_once = false;
    00204 }
    00205
    00206 void KConfigDialog::settingsChangedSlot()
    00207 {
    00208   // Update the buttons
    00209   updateButtons();
    00210   emit settingsChanged();
    00211   emit settingsChanged(name());
    00212 }
    00213
    00214 void KConfigDialog::show()
    00215 {
    00216   QMap<QWidget *, KConfigDialogManager *>::iterator it;
    00217
    00218   updateWidgets();
    00219   d->manager->updateWidgets();
    00220   for (it = d->managerForPage.begin(); it != d->managerForPage.end(); ++it)
    00221     (*it)->updateWidgets();
    00222
    00223   bool has_changed = d->manager->hasChanged() || hasChanged();
    00224   for (it = d->managerForPage.begin();
    00225           it != d->managerForPage.end() && !has_changed;
    00226           ++it)
    00227   {
    00228     has_changed |= (*it)->hasChanged();
    00229   }
    00230
    00231   enableButton(Apply, has_changed);
    00232
    00233   bool is_default = d->manager->isDefault() && isDefault();
    00234   for (it = d->managerForPage.begin();
    00235           it != d->managerForPage.end() && is_default;
    00236           ++it)
    00237   {
    00238     is_default &= (*it)->isDefault();
    00239   }
    00240
    00241   enableButton(Default, !is_default);
    00242   d->shown = true;
    00243   KDialogBase::show();
    00244 }
    00245
    00246 void KConfigDialog::updateSettings()
    00247 {
    00248 }
    00249
    00250 void KConfigDialog::updateWidgets()
    00251 {
    00252 }
    00253
    00254 void KConfigDialog::updateWidgetsDefault()
    00255 {
    00256 }
    00257
    00258
    00259 #include "kconfigdialog.moc"

This file is part of the documentation for kdeui Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:20:15 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003