kexireportfactory.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19#include <tqpopupmenu.h>
20#include <tqvaluevector.h>
21
22#include <kgenericfactory.h>
23#include <tdelocale.h>
24#include <kiconloader.h>
25#include <kdebug.h>
26#include <klineedit.h>
27
28#include <container.h>
29#include <form.h>
30#include <formmanager.h>
31#include <widgetlibrary.h>
32
33#include "reportwidgets.h"
34#include "kexireportfactory.h"
35
36KexiReportFactory::KexiReportFactory(TQObject *parent, const char *name, const TQStringList &)
37 : KFormDesigner::WidgetFactory(parent, name)
38{
40 wView->setPixmap("report");
41 wView->setClassName("KexiReportForm");
42 wView->setName(i18n("Report"));
43 wView->setNamePrefix(
44 i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "report"));
45 wView->setDescription(i18n("A report"));
46 addClass(wView);
47
49 wLabel->setPixmap("label");
50 wLabel->setClassName("Label");
51 wLabel->setName(i18n("Label"));
52 wLabel->setNamePrefix(
53 i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "label"));
54 wLabel->setDescription(i18n("A label to display text"));
55 addClass(wLabel);
56
58 wPicLabel->setPixmap("pixmaplabel");
59 wPicLabel->setClassName("PicLabel");
60 wPicLabel->setName(i18n("Picture Label"));
61 wPicLabel->setNamePrefix(
62 i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "picture"));
63 wPicLabel->setDescription(i18n("A label to display images or icons"));
64 addClass(wPicLabel);
65
67 wLine->setPixmap("line");
68 wLine->setClassName("ReportLine");
69 wLine->setName(i18n("Line"));
70 wLine->setNamePrefix(
71 i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "line"));
72 wLine->setDescription(i18n("A simple line"));
73 addClass(wLine);
74
76 wSubReport->setPixmap("report");
77 wSubReport->setClassName("KexiSubReport");
78 wSubReport->setName(i18n("Sub Report"));
79 wSubReport->setNamePrefix(
80 i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "subReport"));
81 wSubReport->setDescription(i18n("A report embedded in another report"));
82 addClass(wSubReport);
83}
84
85KexiReportFactory::~KexiReportFactory()
86{
87}
88
89TQString
90KexiReportFactory::name()
91{
92 return "kexireportwidgets";
93}
94
95TQWidget*
96KexiReportFactory::createWidget(const TQCString &c, TQWidget *p, const char *n,
97 KFormDesigner::Container *container, int options)
98{
99 Q_UNUSED(options);
100 kexipluginsdbg << "KexiReportFactory::create() " << this << endl;
101
102 TQString text( container->form()->library()->textForWidgetName(n, c) );
103
104 if(c == "Label")
105 return new Label(text, p, n);
106 else if(c == "PicLabel")
107 return new PicLabel(DesktopIcon("image-x-generic"), p, n);
108 else if(c == "ReportLine")
109 return new ReportLine(p, n);
110 else if(c == "KexiSubReport")
111 return new KexiSubReport(p, n);
112
113 return 0;
114}
115
116bool
117KexiReportFactory::createMenuActions(const TQCString &classname, TQWidget *w,
118 TQPopupMenu *menu, KFormDesigner::Container *container)
119{
120 Q_UNUSED(w);
121 Q_UNUSED(container);
122 if(classname == "Label") {
124 menu->insertItem(SmallIconSet("edit"), i18n("Edit Rich Text"), this, TQ_SLOT(editText()));
125 return true;
126 }
127 return false;
128}
129
130bool
131KexiReportFactory::startEditing(const TQCString &c, TQWidget *w, KFormDesigner::Container *container)
132{
133 m_container = container;
134
135 if(c == "Label") {
136 TQLabel *label = static_cast<TQLabel*>(w);
137 if(label->textFormat() == RichText) {
138 m_widget = w;
139 editText();
140 }
141 else
142 createEditor(c, label->text(), label, container, label->geometry(), label->alignment());
143 return true;
144 }
145 return false;
146}
147
148bool
149KexiReportFactory::isPropertyVisibleInternal(const TQCString &classname, TQWidget *w, const TQCString &property, bool isTopLevel)
150{
151 if(classname == "Label") {
152 if(property == "pixmap")
153 return false;
154 }
155 else if(classname == "PicLabel") {
156 if((property == "text") || (property == "indent") || (property == "textFormat") || (property == "font") || (property == "alignment"))
157 return false;
158 }
159
160 return WidgetFactory::isPropertyVisibleInternal(classname, w, property, isTopLevel);
161}
162
163TQValueList<TQCString>
164KexiReportFactory::autoSaveProperties(const TQCString &classname)
165{
166 TQValueList<TQCString> l;
167
168 if(classname == "Label")
169 l << "text";
170 else if(classname == "PicLabel")
171 l << "pixmap";
172
173 return l;
174}
175
176/*
177void
178KexiReportFactory::changeText(const TQString &text)
179{
180 TQWidget *w = WidgetFactory::m_widget;
181 changeProperty("text", text, m_container);
182
183 int width = w->sizeHint().width();
184
185 if(w->width() < width)
186 w->resize(width, w->height() );
187}
188
189void
190KexiReportFactory::resizeEditor(TQWidget *widget, const TQCString &)
191{
192 TQSize s = widget->size();
193 TQPoint p = widget->pos();
194 TQRect r;
195
196 m_editor->resize(s);
197 m_editor->move(p);
198}*/
199
200void
201KexiReportFactory::editText()
202{
203 TQCString classname = m_widget->className();
204 TQString text;
205
206 if(classname == "Label")
207 text = ((TQLabel*)m_widget)->text();
208
209 if(editRichText(m_widget, text)) {
210 changeProperty("textFormat", "RichText", m_container->form());
211 changeProperty("text", text, m_container->form());
212 }
213
214 if(classname == "Label")
215 m_widget->resize(m_widget->sizeHint());
216}
217
218bool
220{
221 return false;
222}
223
224KFORMDESIGNER_WIDGET_FACTORY(KexiReportFactory, kexireportwidgets)
225
226#include "kexireportfactory.moc"
227
This class makes a container out of any TQWidget.
Definition container.h:74
Form * form() const
Definition container.h:91
WidgetLibrary * library() const
Definition form.h:147
bool editRichText(TQWidget *w, TQString &text)
void createEditor(const TQCString &classname, const TQString &text, TQWidget *w, Container *container, TQRect geometry, int align, bool useFrame=false, bool multiLine=false, BackgroundMode background=TQt::NoBackground)
void changeProperty(const char *name, const TQVariant &value, Form *form)
This class holds properties of widget classes provided by a factory.
Kexi Factory (DB widgets + subform)
virtual bool createMenuActions(const TQCString &classname, TQWidget *w, TQPopupMenu *menu, KFormDesigner::Container *container)
virtual TQWidget * createWidget(const TQCString &classname, TQWidget *parent, const char *name, KFormDesigner::Container *container, int options=DefaultOptions)
Creates a widget (and if needed a KFormDesigner::Container)
virtual bool startEditing(const TQCString &classname, TQWidget *w, KFormDesigner::Container *container)
virtual bool previewWidget(const TQCString &, TQWidget *, KFormDesigner::Container *)
virtual bool isPropertyVisibleInternal(const TQCString &, TQWidget *, const TQCString &, bool isTopLevel)
virtual TQValueList< TQCString > autoSaveProperties(const TQCString &classname)
A form embedded as a widget inside other form.
A simple label inside a report.
A simple picture label inside a report.