widgetproxy.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3 Copyright (C) 2004 Alexander Dymo <cloudtemple@mskat.net>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20#include "widgetproxy.h"
21#include "property.h"
22#include "widget.h"
23#include "factory.h"
24
25#include <tqlayout.h>
26#include <tqvariant.h>
27
28namespace KoProperty {
29class WidgetProxyPrivate
30{
31 public:
32 WidgetProxyPrivate()
33 : property(0), widget(0), type(Invalid), layout(0)
34 {}
35 ~WidgetProxyPrivate() {}
36
37 Property *property;
38 Widget *widget;
39 PropertyType type;
40
41 TQHBoxLayout *layout;
42};
43}
44
45using namespace KoProperty;
46
47WidgetProxy::WidgetProxy(TQWidget *parent, const char *name)
48 : TQWidget(parent, name)
49{
50 d = new WidgetProxyPrivate();
51 d->property = new Property();
52 d->layout = new TQHBoxLayout(this, 0, 0);
53}
54
55WidgetProxy::~WidgetProxy()
56{
57 delete d->property;
58}
59
60void
61WidgetProxy::setPropertyType(int propertyType)
62{
63 d->type = propertyType;
64 setWidget();
65}
66
67int
68WidgetProxy::propertyType() const
69{
70 return d->type;
71}
72
73TQVariant
74WidgetProxy::value() const
75{
76 if (m_editor)
77 return m_editor->value();
78 else
79 return TQVariant();
80}
81
82void
83WidgetProxy::setValue(const TQVariant &value)
84{
85 if (d->widget)
86 d->widget->setValue(value, false);
87}
88
89bool
90WidgetProxy::setProperty(const char *name, const TQVariant &value)
91{
92 if( strcmp(name, "value") == 0 ) {
93 setPropertyType((int) value.type() );
94 setValue(value);
95 return true;
96 }
97 else
98 return TQWidget::setProperty(name, value);
99}
100
101TQVariant
102WidgetProxy::property(const char *name) const
103{
104 if( strcmp( name, "value") == 0 )
105 return value( );
106 else
107 return TQWidget::property(name);
108}
109
110void
111WidgetProxy::setWidget()
112{
113 if (d->widget)
114 delete d->widget;
115
116 p->setType(d->type);
117 d->widget = Factory::getInstance()->widgetForProperty(p);
118
119 if (d->widget) {
120 d->widget->reparent(this, TQPoint(0,0), true);
121 d->layout->addWidget(d->widget);
122 }
123}
124
125#include "widgetproxy.moc"
The base class representing a single property.
Definition property.h:177
The base class for all item editors used in Editor.
Definition widget.h:37
const char * name(StdAction id)
Namespace for a set of classes implementing generic properties framework.
@ Invalid
invalid property type
Definition property.h:68