/*************************************************************************** * Copyright (C) 2005-2007 Nicolas Hadacek * * Copyright (C) 2004 Alain Gibaud * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #ifndef CONFIG_WIDGET_H #define CONFIG_WIDGET_H #include #include #include #include #include "container.h" //----------------------------------------------------------------------------- class ConfigWidget : public Container { Q_OBJECT TQ_OBJECT public: ConfigWidget(TQWidget *parent = 0) : Container(parent) {} virtual TQString title() const { return TQString(); } virtual TQString header() const { return TQString(); } virtual TQPixmap pixmap() const { return TQPixmap(); } public slots: virtual void loadConfig() = 0; virtual void saveConfig() = 0; }; //----------------------------------------------------------------------------- template class BaseConfigWidget { public: BaseConfigWidget(ConfigWidget *widget) { _widgets.resize(Type::Nb_Types); for(Type type; type _widgets; static TQWidget *createWidget(Type type, ConfigWidget *widget) { TQWidget *w = 0; uint row = widget->numRows(); switch (type.data().defValue.type()) { case TQVariant::Bool: w = new TQCheckBox(type.label(), widget); widget->addWidget(w, row,row, 0,1); break; default: Q_ASSERT(false); break; } return w; } void load(Type type, TQWidget *widget) const { switch (type.data().defValue.type()) { case TQVariant::Bool: static_cast(widget)->setChecked(readConfigEntry(type).toBool()); break; default: Q_ASSERT(false); break; } } void save(Type type, TQWidget *widget) { switch (type.data().defValue.type()) { case TQVariant::Bool: writeConfigEntry(type, TQVariant(static_cast(widget)->isChecked(), 0)); break; default: Q_ASSERT(false); break; } } void setDefault(Type type, TQWidget *widget) const { switch (type.data().defValue.type()) { case TQVariant::Bool: static_cast(widget)->setChecked(type.data().defValue.toBool()); break; default: Q_ASSERT(false); break; } } }; //----------------------------------------------------------------------------- #define BEGIN_DECLARE_CONFIG_WIDGET(ConfigType, ConfigWidgetType) \ class ConfigWidgetType : public ::ConfigWidget, public BaseConfigWidget \ { \ public: \ ConfigWidgetType() : BaseConfigWidget(this) {} \ virtual void loadConfig() { BaseConfigWidget::loadConfig(); } \ virtual void saveConfig() { BaseConfigWidget::saveConfig(); } \ #define END_DECLARE_CONFIG_WIDGET \ }; #endif