lib
widgetproxy.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "widgetproxy.h"
00021 #include "property.h"
00022 #include "widget.h"
00023 #include "factory.h"
00024
00025 #include <qlayout.h>
00026 #include <qvariant.h>
00027
00028 namespace KoProperty {
00029 class WidgetProxyPrivate
00030 {
00031 public:
00032 WidgetProxyPrivate()
00033 : property(0), widget(0), type(Invalid), layout(0)
00034 {}
00035 ~WidgetProxyPrivate() {}
00036
00037 Property *property;
00038 Widget *widget;
00039 PropertyType type;
00040
00041 QHBoxLayout *layout;
00042 };
00043 }
00044
00045 using namespace KoProperty;
00046
00047 WidgetProxy::WidgetProxy(QWidget *parent, const char *name)
00048 : QWidget(parent, name)
00049 {
00050 d = new WidgetProxyPrivate();
00051 d->property = new Property();
00052 d->layout = new QHBoxLayout(this, 0, 0);
00053 }
00054
00055 WidgetProxy::~WidgetProxy()
00056 {
00057 delete d->property;
00058 }
00059
00060 void
00061 WidgetProxy::setPropertyType(int propertyType)
00062 {
00063 d->type = propertyType;
00064 setWidget();
00065 }
00066
00067 int
00068 WidgetProxy::propertyType() const
00069 {
00070 return d->type;
00071 }
00072
00073 QVariant
00074 WidgetProxy::value() const
00075 {
00076 if (m_editor)
00077 return m_editor->value();
00078 else
00079 return QVariant();
00080 }
00081
00082 void
00083 WidgetProxy::setValue(const QVariant &value)
00084 {
00085 if (d->widget)
00086 d->widget->setValue(value, false);
00087 }
00088
00089 bool
00090 WidgetProxy::setProperty(const char *name, const QVariant &value)
00091 {
00092 if( strcmp(name, "value") == 0 ) {
00093 setPropertyType((int) value.type() );
00094 setValue(value);
00095 return true;
00096 }
00097 else
00098 return QWidget::setProperty(name, value);
00099 }
00100
00101 QVariant
00102 WidgetProxy::property(const char *name) const
00103 {
00104 if( strcmp( name, "value") == 0 )
00105 return value( );
00106 else
00107 return QWidget::property(name);
00108 }
00109
00110 void
00111 WidgetProxy::setWidget()
00112 {
00113 if (d->widget)
00114 delete d->widget;
00115
00116 p->setType(d->type);
00117 d->widget = Factory::getInstance()->widgetForProperty(p);
00118
00119 if (d->widget) {
00120 d->widget->reparent(this, QPoint(0,0), true);
00121 d->layout->addWidget(d->widget);
00122 }
00123 }
00124
00125 #include "widgetproxy.moc"
|