summaryrefslogtreecommitdiffstats
path: root/kexi/plugins/reports/kexireportfactory.cpp
blob: 0ac782c45b8d4418eb460af3526d297d4f415379 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/* This file is part of the KDE project
   Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/
#include <qpopupmenu.h>
#include <qvaluevector.h>

#include <kgenericfactory.h>
#include <klocale.h>
#include <kiconloader.h>
#include <kdebug.h>
#include <klineedit.h>

#include <container.h>
#include <form.h>
#include <formmanager.h>
#include <widgetlibrary.h>

#include "reportwidgets.h"
#include "kexireportfactory.h"

KexiReportFactory::KexiReportFactory(QObject *parent, const char *name, const QStringList &)
 : KFormDesigner::WidgetFactory(parent, name)
{
	KFormDesigner::WidgetInfo *wView = new KFormDesigner::WidgetInfo(this);
	wView->setPixmap("report");
	wView->setClassName("KexiReportForm");
	wView->setName(i18n("Report"));
	wView->setNamePrefix(
		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"));
	wView->setDescription(i18n("A report"));
	addClass(wView);

	KFormDesigner::WidgetInfo *wLabel = new KFormDesigner::WidgetInfo(this);
	wLabel->setPixmap("label");
	wLabel->setClassName("Label");
	wLabel->setName(i18n("Label"));
	wLabel->setNamePrefix(
		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"));
	wLabel->setDescription(i18n("A label to display text"));
	addClass(wLabel);

	KFormDesigner::WidgetInfo *wPicLabel = new KFormDesigner::WidgetInfo(this);
	wPicLabel->setPixmap("pixmaplabel");
	wPicLabel->setClassName("PicLabel");
	wPicLabel->setName(i18n("Picture Label"));
	wPicLabel->setNamePrefix(
		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"));
	wPicLabel->setDescription(i18n("A label to display images or icons"));
	addClass(wPicLabel);

	KFormDesigner::WidgetInfo *wLine = new KFormDesigner::WidgetInfo(this);
	wLine->setPixmap("line");
	wLine->setClassName("ReportLine");
	wLine->setName(i18n("Line"));
	wLine->setNamePrefix(
		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"));
	wLine->setDescription(i18n("A simple line"));
	addClass(wLine);

	KFormDesigner::WidgetInfo *wSubReport = new KFormDesigner::WidgetInfo(this);
	wSubReport->setPixmap("report");
	wSubReport->setClassName("KexiSubReport");
	wSubReport->setName(i18n("Sub Report"));
	wSubReport->setNamePrefix(
		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"));
	wSubReport->setDescription(i18n("A report embedded in another report"));
	addClass(wSubReport);
}

KexiReportFactory::~KexiReportFactory()
{
}

QString
KexiReportFactory::name()
{
	return "kexireportwidgets";
}

QWidget*
KexiReportFactory::createWidget(const QCString &c, QWidget *p, const char *n, 
	KFormDesigner::Container *container, int options)
{
	Q_UNUSED(options);
	kexipluginsdbg << "KexiReportFactory::create() " << this << endl;

	QString text( container->form()->library()->textForWidgetName(n, c) );

	if(c == "Label")
		return new Label(text, p, n);
	else if(c == "PicLabel")
		return new PicLabel(DesktopIcon("image"), p, n);
	else if(c == "ReportLine")
		return new ReportLine(p, n);
	else if(c == "KexiSubReport")
		return new KexiSubReport(p, n);

	return 0;
}

bool
KexiReportFactory::createMenuActions(const QCString &classname, QWidget *w, 
	QPopupMenu *menu,	KFormDesigner::Container *container)
{
	Q_UNUSED(w);
	Q_UNUSED(container);
	if(classname == "Label") {
		/*! @todo use KAction */
		menu->insertItem(SmallIconSet("edit"), i18n("Edit Rich Text"), this, SLOT(editText()));
		return true;
	}
	return false;
}

bool
KexiReportFactory::startEditing(const QCString &c, QWidget *w, KFormDesigner::Container *container)
{
	m_container = container;

	if(c == "Label") {
		QLabel *label = static_cast<QLabel*>(w);
		if(label->textFormat() == RichText) {
			m_widget = w;
			editText();
		}
		else
			createEditor(c, label->text(), label, container, label->geometry(), label->alignment());
		return true;
	}
	return false;
}

bool
KexiReportFactory::isPropertyVisibleInternal(const QCString &classname, QWidget *w, const QCString &property, bool isTopLevel)
{
	if(classname == "Label") {
		if(property == "pixmap")
			return false;
	}
	else if(classname == "PicLabel") {
		if((property == "text") || (property == "indent") || (property == "textFormat") || (property == "font") || (property == "alignment"))
			return false;
	}

	return WidgetFactory::isPropertyVisibleInternal(classname, w, property, isTopLevel);
}

QValueList<QCString>
KexiReportFactory::autoSaveProperties(const QCString &classname)
{
	QValueList<QCString> l;

	if(classname == "Label")
		l << "text";
	else if(classname == "PicLabel")
		l << "pixmap";

	return l;
}

/*
void
KexiReportFactory::changeText(const QString &text)
{
	QWidget *w = WidgetFactory::m_widget;
	changeProperty("text", text, m_container);

	int width = w->sizeHint().width();

	if(w->width() < width)
		w->resize(width, w->height() );
}

void
KexiReportFactory::resizeEditor(QWidget *widget, const QCString &)
{
	QSize s = widget->size();
	QPoint p = widget->pos();
	QRect r;

	m_editor->resize(s);
	m_editor->move(p);
}*/

void
KexiReportFactory::editText()
{
	QCString classname = m_widget->className();
	QString text;

	if(classname == "Label")
		text = ((QLabel*)m_widget)->text();

	if(editRichText(m_widget, text)) {
		changeProperty("textFormat", "RichText", m_container->form());
		changeProperty("text", text, m_container->form());
	}

	if(classname == "Label")
		m_widget->resize(m_widget->sizeHint());
}

bool
KexiReportFactory::previewWidget(const QCString &, QWidget *, KFormDesigner::Container *)
{
	return false;
}

KFORMDESIGNER_WIDGET_FACTORY(KexiReportFactory, kexireportwidgets)

#include "kexireportfactory.moc"