00001 /* 00002 Aseba - an event-based framework for distributed robot control 00003 Copyright (C) 2007--2012: 00004 Stephane Magnenat <stephane at magnenat dot net> 00005 (http://stephane.magnenat.net) 00006 and other contributors, see authors.txt for details 00007 00008 This program is free software: you can redistribute it and/or modify 00009 it under the terms of the GNU Lesser General Public License as published 00010 by the Free Software Foundation, version 3 of the License. 00011 00012 This program 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 00015 GNU Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #ifndef CONFIG_DIALOG_H 00022 #define CONFIG_DIALOG_H 00023 00024 #include <QWidget> 00025 #include <QString> 00026 #include <QtGui> 00027 00028 #include <map> 00029 00030 #define CONFIG_PROPERTY_CHECKBOX_DECLARE(name) \ 00031 public: \ 00032 static const bool get##name(void); \ 00033 static void set##name(bool); 00034 00035 namespace Aseba 00036 { 00037 class GeneralPage; 00038 class EditorPage; 00039 00040 // ConfigDialog 00041 class ConfigDialog: public QDialog 00042 { 00043 Q_OBJECT 00044 00045 public: 00046 // instantiate / kill the singleton 00047 static void init(QWidget* parent = 0); 00048 static void bye(void); 00049 static const ConfigDialog* getInstance() { return me; } 00050 00051 static void showConfig(); 00052 00053 // access to properties 00054 // layout properties 00055 CONFIG_PROPERTY_CHECKBOX_DECLARE(ShowHidden) 00056 CONFIG_PROPERTY_CHECKBOX_DECLARE(ShowLineNumbers) 00057 CONFIG_PROPERTY_CHECKBOX_DECLARE(ShowKeywordToolbar) 00058 CONFIG_PROPERTY_CHECKBOX_DECLARE(ShowMemoryUsage) 00059 // autocompletion behaviour 00060 CONFIG_PROPERTY_CHECKBOX_DECLARE(AutoCompletion) 00061 00062 signals: 00063 void settingsChanged(); 00064 00065 protected: 00066 ConfigDialog(QWidget* parent = 0); 00067 ~ConfigDialog(); 00068 void setupWidgets(); 00069 00070 protected: 00071 static ConfigDialog* me; // pointer to the singleton 00072 00073 QPushButton* okButton; 00074 QPushButton* cancelButton; 00075 QListWidget* topicList; 00076 QStackedWidget* configStack; 00077 00078 // individual pages 00079 GeneralPage* generalpage; 00080 EditorPage* editorpage; 00081 00082 void readSettings(); 00083 void writeSettings(); 00084 00085 public slots: 00086 virtual void saveState(); 00087 virtual void reloadFromCache(); 00088 virtual void accept(); 00089 virtual void reject(); 00090 00091 protected slots: 00092 void flushCache(); 00093 }; 00094 00095 // ConfigPage 00096 class ConfigPage: public QWidget 00097 { 00098 Q_OBJECT 00099 00100 public: 00101 ConfigPage(QString title = QString(), QWidget* parent = 0); 00102 ~ConfigPage(){} 00103 00104 friend class ConfigDialog; 00105 00106 protected: 00107 virtual void readSettings(); 00108 virtual void writeSettings(); 00109 00110 virtual void saveState(); 00111 virtual void flushCache(); 00112 virtual void discardChanges(); 00113 virtual void reloadFromCache(); 00114 00115 QCheckBox* newCheckbox(QString label, QString ID, bool checked = false); 00116 00117 protected: 00118 template <class T> struct WidgetCache { 00119 WidgetCache(): widget(NULL){} 00120 WidgetCache(QWidget* widget, T value):widget(widget),value(value){} 00121 QWidget* widget; 00122 T value; 00123 }; 00124 std::map<QString, WidgetCache<bool> > checkboxCache; 00125 std::map<QString, WidgetCache<bool> > checkboxCacheSave; // used to save the state prior to changes 00126 00127 QVBoxLayout* mainLayout; 00128 }; 00129 00130 // GeneralPage 00131 class GeneralPage: public ConfigPage 00132 { 00133 Q_OBJECT 00134 00135 public: 00136 GeneralPage(QWidget* parent = 0); 00137 ~GeneralPage(){} 00138 00139 friend class ConfigDialog; 00140 00141 protected: 00142 virtual void readSettings(); 00143 virtual void writeSettings(); 00144 }; 00145 00146 // EditorPage 00147 class EditorPage: public ConfigPage 00148 { 00149 Q_OBJECT 00150 00151 public: 00152 EditorPage(QWidget* parent = 0); 00153 ~EditorPage(){} 00154 00155 friend class ConfigDialog; 00156 00157 protected: 00158 virtual void readSettings(); 00159 virtual void writeSettings(); 00160 }; 00161 } 00162 00163 #endif // CONFIG_DIALOG_H 00164