kexi

kexipropertyeditorview.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3 Copyright (C) 2004-2006 Jaroslaw Staniek <js@iidea.pl>
4
5 This program 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 program 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 program; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "kexipropertyeditorview.h"
22#include "keximainwindow.h"
23#include <koproperty/set.h>
24#include <koproperty/editor.h>
25#include <koproperty/property.h>
26
27#include <tdelocale.h>
28#include <kiconloader.h>
29
30#include <tqlayout.h>
31#include <tqlabel.h>
32
33KexiObjectInfoLabel::KexiObjectInfoLabel(TQWidget* parent, const char* name)
34 : TQWidget(parent, name)
35{
36 TQHBoxLayout *hlyr = new TQHBoxLayout(this);
37 m_objectIconLabel = new TQLabel(this);
38 m_objectIconLabel->setMargin(2);
39 setFixedHeight( IconSize(TDEIcon::Small) + 2 + 2 );
40 hlyr->addWidget(m_objectIconLabel);
41 m_objectNameLabel = new TQLabel(this);
42 m_objectNameLabel->setMargin(2);
43 m_objectNameLabel->setSizePolicy(TQSizePolicy::Minimum, TQSizePolicy::Preferred);
44 hlyr->addWidget(m_objectNameLabel);
45}
46
47KexiObjectInfoLabel::~KexiObjectInfoLabel()
48{
49}
50
51void KexiObjectInfoLabel::setObjectClassIcon(const TQString& name)
52{
53 m_classIcon = name;
54 if (m_classIcon.isEmpty())
55 m_objectIconLabel->setFixedWidth( 0 );
56 else
57 m_objectIconLabel->setFixedWidth( IconSize(TDEIcon::Small) + 2 + 2 );
58 m_objectIconLabel->setPixmap( SmallIcon(name) );
59}
60
61void KexiObjectInfoLabel::setObjectClassName(const TQString& name)
62{
63 m_className = name;
64 updateName();
65}
66
67void KexiObjectInfoLabel::setObjectName(const TQString& name)
68{
69 m_objectName = name;
70 updateName();
71}
72
73void KexiObjectInfoLabel::updateName()
74{
75 TQString txt( m_className );
76 if (txt.isEmpty())
77 txt = m_objectName;
78 else if (!m_objectName.isEmpty())
79 txt += TQString(" \"%1\"").arg(m_objectName);
80 m_objectNameLabel->setText(txt);
81}
82
83void KexiObjectInfoLabel::setBuddy( TQWidget * buddy )
84{
85 m_objectNameLabel->setBuddy(buddy);
86}
87
88//------------------------------
89
91class KexiPropertyEditorView::Private
92{
93 public:
94 Private()
95 {
96 }
97 KoProperty::Editor *editor;
98// TQLabel *objectIcon;
99// TQString iconName;
100// TQLabel *objectClassName;
101 KexiObjectInfoLabel *objectInfoLabel;
102};
103
104//------------------------------
105
106KexiPropertyEditorView::KexiPropertyEditorView(KexiMainWindow *mainWin, TQWidget* parent)
107 : TQWidget(parent, "KexiPropertyEditorView")
108 , d(new Private())
109{
110 setCaption(i18n("Properties"));
111 //TODO: set a nice icon
112 setIcon(*mainWin->icon());
113
114 TQVBoxLayout *lyr = new TQVBoxLayout(this);
115
116 //add object class info
117 d->objectInfoLabel = new KexiObjectInfoLabel(this, "KexiObjectInfoLabel");
118 lyr->addWidget(d->objectInfoLabel);
119
120 /*
121 TQHBoxLayout *vlyr = new TQHBoxLayout(lyr);
122 d->objectIcon = new TQLabel(this);
123 d->objectIcon->setMargin(2);
124 d->objectIcon->setFixedHeight( IconSize(TDEIcon::Small) + 2 + 2 );
125 vlyr->addWidget(d->objectIcon);
126 d->objectClassName = new TQLabel(this);
127 d->objectClassName->setMargin(2);
128 d->objectClassName->setSizePolicy(TQSizePolicy::Minimum, TQSizePolicy::Preferred);
129 vlyr->addWidget(d->objectClassName);*/
130
131 d->editor = new KoProperty::Editor(this, true /*AutoSync*/, "propeditor");
132 lyr->addWidget(d->editor);
133 setFocusProxy(d->editor);
134 d->objectInfoLabel->setBuddy(d->editor);
135 setFocusPolicy(TQWidget::WheelFocus);
136
137 connect(d->editor, TQ_SIGNAL(propertySetChanged(KoProperty::Set*)),
138 this, TQ_SLOT(slotPropertySetChanged(KoProperty::Set*)));
139
140// d->iconName = "dummy";
141 slotPropertySetChanged(0);
142}
143
144KexiPropertyEditorView::~KexiPropertyEditorView()
145{
146 delete d;
147}
148
149TQSize KexiPropertyEditorView::sizeHint() const
150{
151 return TQSize(200,200);//m_editor->sizeHint();
152}
153
154TQSize KexiPropertyEditorView::minimumSizeHint() const
155{
156 return TQSize(200,200);//m_editor->sizeHint();
157}
158
159/*void KexiPropertyEditorView::setGeometry ( const TQRect &r )
160{
161 TQWidget::setGeometry(r);
162}
163
164void KexiPropertyEditorView::resize ( int w, int h )
165{
166 TQWidget::resize( w, h );
167}*/
168
169KoProperty::Editor *KexiPropertyEditorView::editor() const
170{
171 return d->editor;
172}
173
182 KoProperty::Set* set, const TQString& textToDisplayForNullSet)
183{
184 TQString className, iconName, objectName;
185 if (set) {
186 if (set->contains("this:classString"))
187 className = (*set)["this:classString"].value().toString();
188 if (set->contains("this:iconName"))
189 iconName = (*set)["this:iconName"].value().toString();
190 const bool useCaptionAsObjectName = set->contains("this:useCaptionAsObjectName")
191 && (*set)["this:useCaptionAsObjectName"].value().toBool();
192 if (set->contains(useCaptionAsObjectName ? "caption" : "name"))
193 objectName = (*set)[useCaptionAsObjectName ? "caption" : "name"].value().toString();
194 }
195 if (!set || objectName.isEmpty()) {
196 objectName = textToDisplayForNullSet;
197 className = TQString();
198 iconName = TQString();
199 }
200
201 if (className.isEmpty() && objectName.isEmpty())
202 infoLabel->hide();
203 else
204 infoLabel->show();
205
206 if (infoLabel->objectClassName() == className
207 && infoLabel->objectClassIcon() == iconName
208 && infoLabel->objectName() == objectName)
209 return;
210
211 infoLabel->setObjectClassIcon(iconName);
212 infoLabel->setObjectClassName(className);
213 infoLabel->setObjectName(objectName);
214}
215
216void KexiPropertyEditorView::slotPropertySetChanged(KoProperty::Set* set)
217{
218 //update information about selected object
219 updateInfoLabelForPropertySet(d->objectInfoLabel, set);
220 d->editor->setEnabled(set);
221}
222
223#include "kexipropertyeditorview.moc"
Kexi's main window interface This interface is implemented by KexiMainWindowImpl class.
Helper class displaying small icon with class name and object name.
static void updateInfoLabelForPropertySet(KexiObjectInfoLabel *infoLabel, KoProperty::Set *set, const TQString &textToDisplayForNullSet=TQString())