PropertyPage.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
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         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 
00026 #include "PropertyPage.h"
00027 #include "PrefWidgets.h"
00028 #include "WidgetFactory.h"
00029 #include <Base/Console.h>
00030 
00031 using namespace Gui::Dialog;
00032 
00034 PropertyPage::PropertyPage(QWidget* parent) : QWidget(parent) 
00035 {
00036   bChanged = false;
00037 }
00038 
00040 PropertyPage::~PropertyPage() 
00041 {
00042 }
00043 
00045 void PropertyPage::apply()
00046 {
00047 }
00048 
00050 void PropertyPage::cancel()
00051 {
00052 }
00053 
00055 void PropertyPage::reset()
00056 {
00057 }
00058 
00060 bool PropertyPage::isModified()
00061 {
00062   return bChanged;
00063 }
00064 
00066 void PropertyPage::setModified(bool b)
00067 {
00068   bChanged = b;
00069 }
00070 
00072 void PropertyPage::onApply()
00073 {
00074   if (isModified())
00075     apply();
00076 
00077   setModified(false);
00078 }
00079 
00081 void PropertyPage::onCancel()
00082 {
00083   if (isModified())
00084   {
00085     cancel();
00086     setModified(false);
00087   }
00088 }
00089 
00091 void PropertyPage::onReset()
00092 {
00093   reset();
00094 }
00095 
00096 // ----------------------------------------------------------------
00097 
00099 PreferencePage::PreferencePage(QWidget* parent) : QWidget(parent) 
00100 {
00101 }
00102 
00104 PreferencePage::~PreferencePage() 
00105 {
00106 }
00107 
00108 void PreferencePage::changeEvent(QEvent *e)
00109 {
00110     QWidget::changeEvent(e);
00111 }
00112 
00113 // ----------------------------------------------------------------
00114 
00115 PreferenceUiForm::PreferenceUiForm(const QString& fn, QWidget* parent)
00116   : PreferencePage(parent), form(0)
00117 {
00118     UiLoader loader;
00119 #if QT_VERSION >= 0x040500
00120     loader.setLanguageChangeEnabled(true);
00121 #endif
00122     QFile file(fn);
00123     if (file.open(QFile::ReadOnly))
00124         form = loader.load(&file, this);
00125     file.close();
00126     if (form) {
00127         this->setWindowTitle(form->windowTitle());
00128         QVBoxLayout *layout = new QVBoxLayout;
00129         layout->addWidget(form);
00130         setLayout(layout);
00131     }
00132     else {
00133         Base::Console().Error("Failed to load UI file from '%s'\n",
00134             (const char*)fn.toUtf8());
00135     }
00136 }
00137 
00138 PreferenceUiForm::~PreferenceUiForm()
00139 {
00140 }
00141 
00142 void PreferenceUiForm::changeEvent(QEvent *e)
00143 {
00144     QWidget::changeEvent(e);
00145 }
00146 
00147 template <typename PW>
00148 void PreferenceUiForm::loadPrefWidgets(void)
00149 {
00150     QList<PW> pw = form->findChildren<PW>();
00151     for (typename QList<PW>::iterator it = pw.begin(); it != pw.end(); ++it)
00152         (*it)->onRestore();
00153 }
00154 
00155 template <typename PW>
00156 void PreferenceUiForm::savePrefWidgets(void)
00157 {
00158     QList<PW> pw = form->findChildren<PW>();
00159     for (typename QList<PW>::iterator it = pw.begin(); it != pw.end(); ++it)
00160         (*it)->onSave();
00161 }
00162 
00163 void PreferenceUiForm::loadSettings()
00164 {
00165     if (!form)
00166         return;
00167 
00168     // search for all pref widgets to restore their settings
00169     loadPrefWidgets<Gui::PrefSpinBox        *>();
00170     loadPrefWidgets<Gui::PrefDoubleSpinBox  *>();
00171     loadPrefWidgets<Gui::PrefLineEdit       *>();
00172     loadPrefWidgets<Gui::PrefFileChooser    *>();
00173     loadPrefWidgets<Gui::PrefComboBox       *>();
00174     loadPrefWidgets<Gui::PrefCheckBox       *>();
00175     loadPrefWidgets<Gui::PrefRadioButton    *>();
00176     loadPrefWidgets<Gui::PrefSlider         *>();
00177     loadPrefWidgets<Gui::PrefColorButton    *>();
00178 }
00179 
00180 void PreferenceUiForm::saveSettings()
00181 {
00182     if (!form)
00183         return;
00184 
00185     // search for all pref widgets to save their settings
00186     savePrefWidgets<Gui::PrefSpinBox        *>();
00187     savePrefWidgets<Gui::PrefDoubleSpinBox  *>();
00188     savePrefWidgets<Gui::PrefLineEdit       *>();
00189     savePrefWidgets<Gui::PrefFileChooser    *>();
00190     savePrefWidgets<Gui::PrefComboBox       *>();
00191     savePrefWidgets<Gui::PrefCheckBox       *>();
00192     savePrefWidgets<Gui::PrefRadioButton    *>();
00193     savePrefWidgets<Gui::PrefSlider         *>();
00194     savePrefWidgets<Gui::PrefColorButton    *>();
00195 }
00196 
00197 // ----------------------------------------------------------------
00198 
00200 CustomizeActionPage::CustomizeActionPage(QWidget* parent) : QWidget(parent) 
00201 {
00202 }
00203 
00205 CustomizeActionPage::~CustomizeActionPage() 
00206 {
00207 }
00208 
00209 bool CustomizeActionPage::event(QEvent* e)
00210 {
00211     bool ok = QWidget::event(e);
00212 
00213     if (e->type() == QEvent::ParentChange || e->type() == QEvent::ParentAboutToChange) {
00214         QWidget* topLevel = this->parentWidget();
00215         while (topLevel && !topLevel->inherits("QDialog"))
00216             topLevel = topLevel->parentWidget();
00217         if (topLevel) {
00218             int index = topLevel->metaObject()->indexOfSignal( QMetaObject::normalizedSignature("addMacroAction(const QByteArray&)") );
00219             if (index >= 0) {
00220                 if (e->type() == QEvent::ParentChange) {
00221                     connect(topLevel, SIGNAL(addMacroAction( const QByteArray& )),
00222                             this, SLOT(onAddMacroAction( const QByteArray& )));
00223                     connect(topLevel, SIGNAL(removeMacroAction( const QByteArray& )),
00224                             this, SLOT(onRemoveMacroAction( const QByteArray& )));
00225                     connect(topLevel, SIGNAL(modifyMacroAction( const QByteArray& )),
00226                             this, SLOT(onModifyMacroAction( const QByteArray& )));
00227                 }
00228                 else {
00229                     disconnect(topLevel, SIGNAL(addMacroAction( const QByteArray& )),
00230                                this, SLOT(onAddMacroAction( const QByteArray& )));
00231                     disconnect(topLevel, SIGNAL(removeMacroAction( const QByteArray& )),
00232                                this, SLOT(onRemoveMacroAction( const QByteArray& )));
00233                     disconnect(topLevel, SIGNAL(modifyMacroAction( const QByteArray& )),
00234                                this, SLOT(onModifyMacroAction( const QByteArray& )));
00235                 }
00236             }
00237         }
00238     }
00239 
00240     return ok;
00241 }
00242 
00243 void CustomizeActionPage::changeEvent(QEvent *e)
00244 {
00245     QWidget::changeEvent(e);
00246 }
00247 
00248 #include "moc_PropertyPage.cpp"

Generated on Wed Nov 23 19:00:31 2011 for FreeCAD by  doxygen 1.6.1