lib

widgetproxy.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00003    Copyright (C) 2004  Alexander Dymo <cloudtemple@mskat.net>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
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"
KDE Home | KDE Accessibility Home | Description of Access Keys