1
/* This file is part of the KDE project
2
Copyright (C) 2003 by Lucijan Busch <lucijan@kde.org>
3
Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
4
Copyright (C) 2009-2014 JarosÅaw Staniek <staniek@kde.org>
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Library General Public
8
License as published by the Free Software Foundation; either
9
version 2 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Library General Public License for more details.
16
You should have received a copy of the GNU Library General Public License
17
along with this library; see the file COPYING.LIB. If not, write to
18
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301, USA.
22
#include "KexiStandardFormWidgetsFactory.h"
23
#include "KexiStandardFormWidgets.h"
24
#include "KexiStandardContainerFormWidgets.h"
27
#include "widgetlibrary.h"
28
#include "objecttree.h"
29
#include "WidgetInfo.h"
30
#include <kexiutils/utils.h>
35
#include <KPropertySet>
39
#include <KLocalizedString>
41
#include <QStackedWidget>
43
#include <QRadioButton>
46
#include <QDomDocument>
48
#ifdef KEXI_LIST_FORM_WIDGET_SUPPORT
49
#include <QTreeWidget>
54
#include <QProgressBar>
57
#include <QDateTimeEdit>
59
#include <QPushButton>
64
KEXI_PLUGIN_FACTORY(KexiStandardFormWidgetsFactory, "kexiforms_standardwidgetsplugin.json")
66
KexiStandardFormWidgetsFactory::KexiStandardFormWidgetsFactory(QObject *parent, const QVariantList &args)
67
: KFormDesigner::WidgetFactory(parent)
70
KFormDesigner::WidgetInfo *wFormWidget = new KFormDesigner::WidgetInfo(this);
71
wFormWidget->setIconName(KexiIconName("form"));
72
wFormWidget->setClassName("FormWidgetBase");
73
wFormWidget->setName(xi18n("Form"));
74
wFormWidget->setNamePrefix(
75
xi18nc("A prefix for identifiers of form widgets. Based on that, identifiers such as "
76
"form1, form2 are generated. "
77
"This string can be used to refer the widget object as variables in programming "
78
"languages or macros so it must _not_ contain white spaces and non latin1 characters, "
79
"should start with lower case letter and if there are subsequent words, these should "
80
"start with upper case letter. Example: smallCamelCase. "
81
"Moreover, try to make this prefix as short as possible.",
83
wFormWidget->setDescription(xi18n("A simple form widget"));
84
addClass(wFormWidget);
86
KFormDesigner::WidgetInfo *wCustomWidget = new KFormDesigner::WidgetInfo(this);
87
wCustomWidget->setIconName(KexiIconName("unknown-widget"));
88
wCustomWidget->setClassName("CustomWidget");
89
wCustomWidget->setName(/* no i18n needed */ "Custom Widget");
90
wCustomWidget->setNamePrefix(/* no i18n needed */ "customWidget");
91
wCustomWidget->setDescription(/* no i18n needed */ "A custom or non-supported widget");
92
addClass(wCustomWidget);
94
KFormDesigner::WidgetInfo *wLabel = new KFormDesigner::WidgetInfo(this);
95
wLabel->setIconName(KexiIconName("label"));
96
wLabel->setClassName("QLabel");
97
wLabel->setName(/* no i18n needed */ "Text Label");
98
wLabel->setNamePrefix(/* no i18n needed */ "label");
99
wLabel->setDescription(/* no i18n needed */ "A widget to display text");
100
wLabel->setAutoSaveProperties(QList<QByteArray>() << "text");
103
KFormDesigner::WidgetInfo *wPixLabel = new KFormDesigner::WidgetInfo(this);
104
wPixLabel->setIconName(KexiIconName("imagebox"));
105
wPixLabel->setClassName("KexiPictureLabel");
106
wPixLabel->setName(/* no i18n needed */ "Picture Label");
107
//! @todo Qt designer compatibility: maybe use this class when QLabel has a pixmap set...?
108
wPixLabel->setSavingName("KexiPictureLabel");
109
wPixLabel->setNamePrefix(/* no i18n needed */ "picture");
110
wPixLabel->setDescription(/* no i18n needed */ "A widget to display pictures");
111
wPixLabel->setAutoSaveProperties(QList<QByteArray>() << "pixmap");
114
KFormDesigner::WidgetInfo *wLineEdit = new KFormDesigner::WidgetInfo(this);
115
wLineEdit->setIconName(KexiIconName("lineedit"));
116
wLineEdit->setClassName("QLineEdit");
117
wLineEdit->addAlternateClassName("KLineEdit");
118
wLineEdit->setIncludeFileName("qlineedit.h");
119
wLineEdit->setName(/* no i18n needed */ "Line Edit");
120
wLineEdit->setNamePrefix(/* no i18n needed */ "lineEdit");
121
wLineEdit->setDescription(/* no i18n needed */ "A widget to input text");
124
KFormDesigner::WidgetInfo *wPushButton = new KFormDesigner::WidgetInfo(this);
125
wPushButton->setIconName(KexiIconName("button"));
126
wPushButton->setClassName("QPushButton");
127
wPushButton->addAlternateClassName("KPushButton");
128
wPushButton->setIncludeFileName("qpushbutton.h");
129
wPushButton->setName(/* no i18n needed */ "Push Button");
130
wPushButton->setNamePrefix(/* no i18n needed */ "button");
131
wPushButton->setDescription(/* no i18n needed */ "A simple push button to execute actions");
132
wPushButton->setAutoSaveProperties(QList<QByteArray>() << "text");
133
addClass(wPushButton);
135
KFormDesigner::WidgetInfo *wRadioButton = new KFormDesigner::WidgetInfo(this);
136
wRadioButton->setIconName(KexiIconName("radiobutton"));
137
wRadioButton->setClassName("QRadioButton");
138
wRadioButton->setName(/* no i18n needed */ "Option Button");
139
wRadioButton->setNamePrefix(/* no i18n needed */ "option");
140
wRadioButton->setDescription(/* no i18n needed */ "An option button with text or pixmap label");
141
addClass(wRadioButton);
143
KFormDesigner::WidgetInfo *wCheckBox = new KFormDesigner::WidgetInfo(this);
144
wCheckBox->setIconName(KexiIconName("checkbox"));
145
wCheckBox->setClassName("QCheckBox");
146
wCheckBox->setName(/* no i18n needed */ "Check Box");
147
wCheckBox->setNamePrefix(/* no i18n needed */ "checkBox");
148
wCheckBox->setDescription(/* no i18n needed */ "A check box with text or pixmap label");
151
KFormDesigner::WidgetInfo *wSpinBox = new KFormDesigner::WidgetInfo(this);
152
wSpinBox->setIconName(KexiIconName("spinbox"));
153
wSpinBox->setClassName("QSpinBox");
154
wSpinBox->addAlternateClassName("KIntSpinBox");
155
wSpinBox->setIncludeFileName("qspinbox.h");
156
wSpinBox->setName(/* no i18n needed */ "Spin Box");
157
wSpinBox->setNamePrefix(/* no i18n needed */ "spinBox");
158
wSpinBox->setDescription(/* no i18n needed */ "A spin box widget");
161
KFormDesigner::WidgetInfo *wComboBox = new KFormDesigner::WidgetInfo(this);
162
wComboBox->setIconName(KexiIconName("combobox"));
163
wComboBox->setClassName("KComboBox");
164
wComboBox->addAlternateClassName("QComboBox");
165
wComboBox->setIncludeFileName("KComboBox");
166
wComboBox->setName(/* no i18n needed */ "Combo Box");
167
wComboBox->setNamePrefix(/* no i18n needed */ "comboBox");
168
wComboBox->setDescription(/* no i18n needed */ "A combo box widget");
169
wComboBox->setAutoSaveProperties(QList<QByteArray>() << "list_items");
172
#ifdef KEXI_LIST_FORM_WIDGET_SUPPORT
173
// Unused, commented-out in Kexi 2.9 to avoid unnecessary translations:
174
// KFormDesigner::WidgetInfo *wListBox = new KFormDesigner::WidgetInfo(this);
175
// wListBox->setIconName(KexiIconName("listbox"));
176
// wListBox->setClassName("KListBox");
177
// wListBox->addAlternateClassName("QListBox");
178
// wListBox->addAlternateClassName("KListBox");
179
// wListBox->setIncludeFileName("qlistbox.h");
180
// wListBox->setName(xi18n("List Box"));
181
// wListBox->setNamePrefix(
182
// xi18nc("Widget name. This string will be used to name widgets of this class. "
183
// "It must _not_ contain white spaces and non latin1 characters.", "listBox"));
184
// wListBox->setDescription(xi18n("A simple list widget"));
185
// wListBox->setAutoSaveProperties(QList<QByteArray>() << "list_items");
186
// addClass(wListBox);
188
// Unused, commented-out in Kexi 2.9 to avoid unnecessary translations:
189
// KFormDesigner::WidgetInfo *wTreeWidget = new KFormDesigner::WidgetInfo(this);
190
// wTreeWidget->setIconName(KexiIconName("listwidget"));
191
// wTreeWidget->setClassName("QTreetWidget");
192
// //? wTreeWidget->addAlternateClassName("QListView");
193
// //? wTreeWidget->addAlternateClassName("KListView");
194
// wTreeWidget->setIncludeFileName("qtreewidget.h");
195
// wTreeWidget->setName(xi18n("List Widget"));
196
// wTreeWidget->setNamePrefix(
197
// xi18nc("Widget name. This string will be used to name widgets of this class. "
198
// "It must _not_ contain white spaces and non latin1 characters.", "listWidget"));
199
// wTreeWidget->setDescription(xi18n("A list (or tree) widget"));
200
// wTreeWidget->setAutoSaveProperties(QList<QByteArray>() << "list_contents");
201
// addClass(wTreeWidget);
204
KFormDesigner::WidgetInfo *wTextEdit = new KFormDesigner::WidgetInfo(this);
205
wTextEdit->setIconName(KexiIconName("textedit"));
206
wTextEdit->setClassName("KTextEdit");
207
wTextEdit->addAlternateClassName("QTextEdit");
208
wTextEdit->setIncludeFileName("KTextEdit");
209
wTextEdit->setName(/* no i18n needed */ "Text Editor");
210
wTextEdit->setNamePrefix(/* no i18n needed */ "textEditor");
211
wTextEdit->setDescription(/* no i18n needed */ "A simple single-page rich text editor");
212
wTextEdit->setAutoSaveProperties(QList<QByteArray>() << "text");
215
KFormDesigner::WidgetInfo *wSlider = new KFormDesigner::WidgetInfo(this);
216
wSlider->setIconName(KexiIconName("slider"));
217
wSlider->setClassName("QSlider");
218
wSlider->setName(/* no i18n needed */ "Slider");
219
wSlider->setNamePrefix(/* no i18n needed */ "slider");
220
wSlider->setDescription(/* no i18n needed */ "A Slider widget");
223
KFormDesigner::WidgetInfo *wProgressBar = new KFormDesigner::WidgetInfo(this);
224
wProgressBar->setIconName(KexiIconName("progressbar"));
225
wProgressBar->setClassName("QProgressBar");
226
wProgressBar->setName(/* no i18n needed */ "Progress Bar");
227
wProgressBar->setNamePrefix(/* no i18n needed */ "progressBar");
228
wProgressBar->setDescription(/* no i18n needed */ "A progress indicator widget");
229
addClass(wProgressBar);
231
KFormDesigner::WidgetInfo *wLine = new KFormDesigner::WidgetInfo(this);
232
wLine->setIconName(KexiIconName("line-horizontal"));
233
wLine->setClassName("Line");
234
wLine->setName(xi18n("Line"));
235
wLine->setNamePrefix(
236
xi18nc("A prefix for identifiers of line widgets. Based on that, identifiers such as "
237
"line1, line2 are generated. "
238
"This string can be used to refer the widget object as variables in programming "
239
"languages or macros so it must _not_ contain white spaces and non latin1 characters, "
240
"should start with lower case letter and if there are subsequent words, these should "
241
"start with upper case letter. Example: smallCamelCase. "
242
"Moreover, try to make this prefix as short as possible.",
244
wLine->setDescription(xi18n("A line to be used as a separator"));
245
wLine->setAutoSaveProperties(QList<QByteArray>() << "orientation");
246
wLine->setInternalProperty("orientationSelectionPopup", true);
247
wLine->setInternalProperty("orientationSelectionPopup:horizontalIcon", KexiIconName("line-horizontal"));
248
wLine->setInternalProperty("orientationSelectionPopup:verticalIcon", KexiIconName("line-vertical"));
249
wLine->setInternalProperty("orientationSelectionPopup:horizontalText", xi18n("Insert &Horizontal Line"));
250
wLine->setInternalProperty("orientationSelectionPopup:verticalText", xi18n("Insert &Vertical Line"));
253
KFormDesigner::WidgetInfo *wDate = new KFormDesigner::WidgetInfo(this);
254
wDate->setIconName(KexiIconName("dateedit"));
255
wDate->setClassName("QDateEdit");
256
wDate->addAlternateClassName("KDateWidget");
257
wDate->setIncludeFileName("qdateedit.h");
258
wDate->setName(/* no i18n needed */ "Date Widget");
259
wDate->setNamePrefix(/* no i18n needed */ "dateWidget");
260
wDate->setDescription(/* no i18n needed */ "A widget to input and display a date");
261
wDate->setAutoSaveProperties(QList<QByteArray>() << "date");
264
KFormDesigner::WidgetInfo *wTime = new KFormDesigner::WidgetInfo(this);
265
wTime->setIconName(KexiIconName("timeedit"));
266
wTime->setClassName("QTimeEdit");
267
wTime->addAlternateClassName("KTimeWidget");
268
wTime->setIncludeFileName("qtimewidget.h");
269
wTime->setName(/* no i18n needed */ "Time Widget");
270
wTime->setNamePrefix(/* no i18n needed */ "timeWidget");
271
wTime->setDescription(/* no i18n needed */ "A widget to input and display a time");
272
wTime->setAutoSaveProperties(QList<QByteArray>() << "time");
275
KFormDesigner::WidgetInfo *wDateTime = new KFormDesigner::WidgetInfo(this);
276
wDateTime->setIconName(KexiIconName("datetimeedit"));
277
wDateTime->setClassName("QDateTimeEdit");
278
wDateTime->addAlternateClassName("KDateTimeWidget");
279
wDateTime->setIncludeFileName("qdatetimewidget.h");
280
wDateTime->setName(/* no i18n needed */ "Date/Time Widget");
281
wDateTime->setNamePrefix(/* no i18n needed */ "dateTimeWidget");
282
wDateTime->setDescription(/* no i18n needed */ "A widget to input and display a time and a date");
283
wDateTime->setAutoSaveProperties(QList<QByteArray>() << "dateTime");
286
setPropertyDescription("checkable", xi18nc("Property: Button is checkable", "On/Off"));
287
setPropertyDescription("autoRepeat", xi18nc("Property: Button", "Auto Repeat"));
288
setPropertyDescription("autoRepeatDelay", xi18nc("Property: Auto Repeat Button's Delay", "Auto Rep. Delay"));
289
setPropertyDescription("autoRepeatInterval", xi18nc("Property: Auto Repeat Button's Interval", "Auto Rep. Interval"));
290
// unused (too advanced) setPropertyDescription("autoDefault", xi18n("Auto Default"));
291
// unused (too advanced) setPropertyDescription("default", xi18nc("Property: Button is default", "Default"));
292
setPropertyDescription("flat", xi18nc("Property: Button is flat", "Flat"));
293
setPropertyDescription("echoMode",
294
xi18nc("Property: Echo mode for Line Edit widget eg. Normal, NoEcho, Password", "Echo Mode"));
295
setPropertyDescription("indent", xi18n("Indent"));
297
setPropertyDescription("orientation", xi18n("Orientation"));
299
setPropertyDescription("checked", xi18nc("Property: Checked checkbox", "Checked"));
300
setPropertyDescription("tristate", xi18nc("Property: Tristate checkbox", "Tristate"));
303
setPropertyDescription("textFormat", xi18n("Text Format"));
304
setValueDescription("PlainText", xi18nc("For Text Format", "Plain"));
305
setValueDescription("RichText", xi18nc("For Text Format", "Hypertext"));
306
setValueDescription("AutoText", xi18nc("For Text Format", "Auto"));
307
setValueDescription("LogText", xi18nc("For Text Format", "Log"));
308
setPropertyDescription("openExternalLinks", xi18nc("property: Can open external links in label", "Open Ext. Links"));
311
setPropertyDescription("placeholderText", xi18nc("Property: line edit's placeholder text", "Placeholder Text"));
312
setPropertyDescription("clearButtonEnabled", xi18nc("Property: Clear Button Enabled", "Clear Button"));
314
setPropertyDescription("passwordMode", xi18nc("Property: Password Mode for line edit", "Password Mode"));
315
setPropertyDescription("squeezedTextEnabled", xi18nc("Property: Squeezed Text Mode for line edit", "Squeezed Text"));
318
setPropertyDescription("tabStopWidth", xi18n("Tab Stop Width"));
319
setPropertyDescription("tabChangesFocus", xi18n("Tab Changes Focus"));
320
setPropertyDescription("wrapPolicy", xi18n("Word Wrap Policy"));
321
setValueDescription("AtWordBoundary", xi18nc("Property: For Word Wrap Policy", "At Word Boundary"));
322
setValueDescription("Anywhere", xi18nc("Property: For Word Wrap Policy", "Anywhere"));
323
setValueDescription("AtWordOrDocumentBoundary", xi18nc("Property: For Word Wrap Policy", "At Word Boundary If Possible"));
324
setPropertyDescription("wordWrap", xi18n("Word Wrapping"));
325
setPropertyDescription("wrapColumnOrWidth", xi18n("Word Wrap Position"));
326
setValueDescription("NoWrap", xi18nc("Property: For Word Wrap Position", "None"));
327
setValueDescription("WidgetWidth", xi18nc("Property: For Word Wrap Position", "Widget's Width"));
328
setValueDescription("FixedPixelWidth", xi18nc("Property: For Word Wrap Position", "In Pixels"));
329
setValueDescription("FixedColumnWidth", xi18nc("Property: For Word Wrap Position", "In Columns"));
330
setPropertyDescription("linkUnderline", xi18n("Links Underlined"));
331
setPropertyDescription("horizontalScrollBarPolicy", xi18n("Horizontal Scroll Bar"));
332
setPropertyDescription("verticalScrollBarPolicy", xi18n("Vertical Scroll Bar"));
334
setValueDescription("ScrollBarAsNeeded", xi18nc("Property: Show Scroll Bar As Needed", "As Needed"));
335
setValueDescription("ScrollBarAlwaysOff", xi18nc("Property: Scroll Bar Always Off", "Always Off"));
336
setValueDescription("ScrollBarAlwaysOn", xi18nc("Property: Scroll Bar Always On", "Always On"));
337
setPropertyDescription("acceptRichText", xi18nc("Property: Text Edit accepts rich text", "Rich Text"));
338
setPropertyDescription("HTML", xi18nc("Property: HTML value of text edit", "HTML"));
340
// --- containers ---
342
KFormDesigner::WidgetInfo *wTabWidget = new KFormDesigner::WidgetInfo(this);
343
wTabWidget->setIconName(KexiIconName("tabwidget"));
344
wTabWidget->setClassName("KFDTabWidget");
345
wTabWidget->addAlternateClassName("KTabWidget");
346
wTabWidget->addAlternateClassName("QTabWidget");
347
wTabWidget->setSavingName("QTabWidget");
348
wTabWidget->setIncludeFileName("qtabwidget.h");
349
wTabWidget->setName(xi18n("Tab Widget"));
350
wTabWidget->setNamePrefix(
351
xi18nc("A prefix for identifiers of tab widgets. Based on that, identifiers such as "
352
"tab1, tab2 are generated. "
353
"This string can be used to refer the widget object as variables in programming "
354
"languages or macros so it must _not_ contain white spaces and non latin1 characters, "
355
"should start with lower case letter and if there are subsequent words, these should "
356
"start with upper case letter. Example: smallCamelCase. "
357
"Moreover, try to make this prefix as short as possible.",
359
wTabWidget->setDescription(xi18n("A widget to display multiple pages using tabs"));
360
addClass(wTabWidget);
362
KFormDesigner::WidgetInfo *wWidget = new KFormDesigner::WidgetInfo(this);
363
wWidget->setIconName(KexiIconName("frame"));
364
wWidget->setClassName("QWidget");
365
wWidget->addAlternateClassName("ContainerWidget");
366
wWidget->setName(/* no i18n needed */ "Basic container");
367
wWidget->setNamePrefix(/* no i18n needed */ "container");
368
wWidget->setDescription(/* no i18n needed */ "An empty container with no frame");
371
KFormDesigner::WidgetInfo *wGroupBox = new KFormDesigner::WidgetInfo(this);
372
wGroupBox->setIconName(KexiIconName("groupbox"));
373
wGroupBox->setClassName("QGroupBox");
374
wGroupBox->addAlternateClassName("GroupBox");
375
wGroupBox->setName(xi18n("Group Box"));
376
wGroupBox->setNamePrefix(
377
xi18nc("A prefix for identifiers of group box widgets. Based on that, identifiers such as "
378
"groupBox1, groupBox2 are generated. "
379
"This string can be used to refer the widget object as variables in programming "
380
"languages or macros so it must _not_ contain white spaces and non latin1 characters, "
381
"should start with lower case letter and if there are subsequent words, these should "
382
"start with upper case letter. Example: smallCamelCase. "
383
"Moreover, try to make this prefix as short as possible.",
385
wGroupBox->setDescription(xi18n("A container to group some widgets"));
388
KFormDesigner::WidgetInfo *wFrame = new KFormDesigner::WidgetInfo(this);
389
wFrame->setIconName(KexiIconName("frame"));
390
wFrame->setClassName("QFrame");
391
wFrame->setName(/* no i18n needed */ "Frame");
392
wFrame->setNamePrefix(/* no i18n needed */ "frame");
393
wFrame->setDescription(/* no i18n needed */ "A simple frame container");
397
setPropertyDescription("title", xi18nc("'Title' property for group box", "Title"));
398
setPropertyDescription("flat", xi18nc("'Flat' property for group box", "Flat"));
401
setPropertyDescription("tabBarAutoHide", xi18n("Auto-hide Tabs"));
402
setPropertyDescription("tabPosition", xi18n("Tab Position"));
403
setPropertyDescription("currentIndex", xi18nc("'Current page' property for tab widget", "Current Page"));
404
setPropertyDescription("tabShape", xi18n("Tab Shape"));
405
setPropertyDescription("elideMode", xi18nc("Tab Widget's Elide Mode property", "Elide Mode"));
406
setPropertyDescription("usesScrollButtons",
407
xi18nc("Tab Widget's property: true if can use scroll buttons", "Scroll Buttons"));
409
setPropertyDescription("tabsClosable", xi18n("Closable Tabs"));
410
setPropertyDescription("movable", xi18n("Movable Tabs"));
411
setPropertyDescription("documentMode", xi18n("Document Mode"));
413
setValueDescription("Rounded", xi18nc("Property value for Tab Shape", "Rounded"));
414
setValueDescription("Triangular", xi18nc("Property value for Tab Shape", "Triangular"));
417
KexiStandardFormWidgetsFactory::~KexiStandardFormWidgetsFactory()
421
QWidget* KexiStandardFormWidgetsFactory::createWidget(const QByteArray &c, QWidget *p, const char *n,
422
KFormDesigner::Container *container,
423
CreateWidgetOptions options)
426
bool createContainer = false;
427
QString text(container->form()->library()->textForWidgetName(n, c));
429
w = new QLabel(text, p);
430
} else if (c == "KexiPictureLabel") {
431
w = new KexiPictureLabel(koDesktopIcon("image-x-generic"), p);
432
} else if (c == "QLineEdit") {
433
w = new QLineEdit(p);
434
} else if (c == "QPushButton") {
435
w = new QPushButton(text, p);
436
} else if (c == "QRadioButton") {
437
w = new QRadioButton(text, p);
438
} else if (c == "QCheckBox") {
439
w = new QCheckBox(text, p);
440
} else if (c == "KIntSpinBox") {
442
} else if (c == "KComboBox") {
443
w = new KComboBox(p);
444
} else if (c == "KTextEdit") {
445
w = new KTextEdit(text, p);
446
#ifdef KEXI_LIST_FORM_WIDGET_SUPPORT
447
} else if (c == "QTreeWidget") {
448
QTreeWidget *tw = new QTreeWidget(p);
450
if (container->form()->interactiveMode()) {
451
tw->setColumnCount(1);
452
tw->setHeaderItem(new QTreeWidetItem(tw));
453
tw->headerItem()->setText(1, futureI18n("Column 1"));
455
lw->setRootIsDecorated(true);
457
} else if (c == "QSlider") {
458
w = new QSlider(Qt::Horizontal, p);
459
} else if (c == "QProgressBar") {
460
w = new QProgressBar(p);
461
} else if (c == "KDateWidget" || c == "QDateEdit") {
462
w = new QDateEdit(QDate::currentDate(), p);
463
} else if (c == "KTimeWidget" || c == "QTimeEdit") {
464
w = new QTimeEdit(QTime::currentTime(), p);
465
} else if (c == "KDateTimeWidget" || c == "QDateTimeEdit") {
466
w = new QDateTimeEdit(QDateTime::currentDateTime(), p);
467
} else if (c == "Line") {
468
w = new Line(options & WidgetFactory::VerticalOrientation
469
? Qt::Vertical : Qt::Horizontal, p);
470
} // --- containers ---
471
else if (c == "KFDTabWidget") {
472
KFDTabWidget *tab = new KFDTabWidget(container, p);
474
#if defined(USE_KTabWidget)
475
tab->setTabReorderingEnabled(true);
476
connect(tab, SIGNAL(movedTab(int,int)), this, SLOT(reorderTabs(int,int)));
478
//qDebug() << "Creating ObjectTreeItem:";
479
container->form()->objectTree()->addItem(container->objectTree(),
480
new KFormDesigner::ObjectTreeItem(
481
container->form()->library()->displayName(c), n, tab, container));
482
} else if (c == "QWidget") {
483
w = new ContainerWidget(p);
485
new KFormDesigner::Container(container, w, p);
487
} else if (c == "QGroupBox") {
488
QString text = container->form()->library()->textForWidgetName(n, c);
489
w = new GroupBox(text, p);
490
createContainer = true;
491
} else if (c == "QFrame") {
492
QFrame *frm = new QFrame(p);
494
frm->setLineWidth(2);
495
frm->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
496
createContainer = true;
497
} else if (c == "QStackedWidget" || /* compat */ c == "QWidgetStack") {
498
QStackedWidget *stack = new QStackedWidget(p);
500
stack->setLineWidth(2);
501
stack->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
502
//qDebug() << "Creating ObjectTreeItem:";
503
container->form()->objectTree()->addItem(container->objectTree(),
504
new KFormDesigner::ObjectTreeItem(
505
container->form()->library()->displayName(c), n, stack, container));
507
if (container->form()->interactiveMode()) {
508
AddStackPageAction(container, stack, 0).trigger(); // addStackPage();
510
} else if (c == "HBox") {
512
createContainer = true;
513
} else if (c == "VBox") {
515
createContainer = true;
516
} else if (c == "Grid") {
518
createContainer = true;
519
} else if (c == "HFlow") {
521
createContainer = true;
522
} else if (c == "VFlow") {
524
createContainer = true;
529
qDebug() << w << w->objectName() << "created";
531
if (createContainer) {
532
(void)new KFormDesigner::Container(container, w, container);
534
if (c == "KFDTabWidget") {
535
// if we are loading, don't add this tab
536
if (container->form()->interactiveMode()) {
537
TabWidgetBase *tab = qobject_cast<TabWidgetBase*>(w);
538
AddTabAction(container, tab, 0).slotTriggered();
544
bool KexiStandardFormWidgetsFactory::previewWidget(const QByteArray &classname,
545
QWidget *widget, KFormDesigner::Container *container)
547
if (classname == "QStackedWidget" || /* compat */ classname == "QWidgetStack") {
548
QStackedWidget *stack = qobject_cast<QStackedWidget*>(widget);
549
KFormDesigner::ObjectTreeItem *tree = container->form()->objectTree()->lookup(
550
widget->objectName());
551
if (!tree->modifiedProperties()->contains("frameShape"))
552
stack->setFrameStyle(QFrame::NoFrame);
557
bool KexiStandardFormWidgetsFactory::createMenuActions(const QByteArray &classname, QWidget *w,
558
QMenu *menu, KFormDesigner::Container *container)
560
QWidget *pw = w->parentWidget();
561
if ((classname == "QLabel") || (classname == "KTextEdit")) {
562
menu->addAction( new EditRichTextAction(container, w, menu, this) );
565
#ifdef KEXI_LIST_FORM_WIDGET_SUPPORT
566
else if (classname == "QTreeWidget") {
567
menu->addAction(koIcon("document-properties"), xi18n("Edit Contents of List Widget"),
568
this, SLOT(editListContents()));
572
else if (classname == "KFDTabWidget" || pw->parentWidget()->inherits("QTabWidget")) {
573
//! @todo KEXI3 port this: setWidget(pw->parentWidget(), m_container->toplevel());
575
if (pw->parentWidget()->inherits("QTabWidget")) {
576
setWidget(pw->parentWidget(), m_container->toplevel());
580
TabWidgetBase *tab = qobject_cast<TabWidgetBase*>(w);
582
menu->addAction( new AddTabAction(container, tab, menu) );
583
menu->addAction( new RenameTabAction(container, tab, menu) );
584
menu->addAction( new RemoveTabAction(container, tab, menu) );
588
else if ( (KexiUtils::objectIsA(pw, "QStackedWidget") || /* compat */ KexiUtils::objectIsA(pw, "QWidgetStack"))
589
&& !pw->parentWidget()->inherits("QTabWidget")
592
QStackedWidget *stack = qobject_cast<QStackedWidget*>(pw);
593
//! @todo KEXI3 port this: setWidget( pw, container->form()->objectTree()->lookup(stack->objectName())->parent()->container() );
597
container->form()->objectTree()->lookup(stack->objectName())->parent()->container()
600
KFormDesigner::Container *parentContainer
601
= container->form()->objectTree()->lookup(stack->objectName())->parent()->container();
602
menu->addAction( new AddStackPageAction(parentContainer, pw, menu) );
603
menu->addAction( new RemoveStackPageAction(parentContainer, pw, menu) );
604
menu->addAction( new GoToStackPageAction(GoToStackPageAction::Previous, parentContainer, pw, menu) );
605
menu->addAction( new GoToStackPageAction(GoToStackPageAction::Next, parentContainer, pw, menu) );
611
bool KexiStandardFormWidgetsFactory::startInlineEditing(InlineEditorCreationArguments& args)
613
if (args.classname == "QLineEdit") {
614
QLineEdit *lineedit = static_cast<QLineEdit*>(args.widget);
615
args.text = lineedit->text();
616
args.alignment = lineedit->alignment();
617
args.useFrame = true;
620
else if (args.widget->inherits("QLabel")) {
621
QLabel *label = static_cast<QLabel*>(args.widget);
622
if (label->textFormat() == Qt::RichText) {
623
args.execute = false;
624
EditRichTextAction(args.container, label, 0, this).trigger();
627
args.text = label->text();
628
args.alignment = label->alignment();
632
else if (args.classname == "QPushButton") {
633
QPushButton *push = static_cast<QPushButton*>(args.widget);
635
option.initFrom(push);
636
args.text = push->text();
637
const QRect r(push->style()->subElementRect(
638
QStyle::SE_PushButtonContents, &option, push));
639
args.geometry = QRect(push->x() + r.x(), push->y() + r.y(), r.width(), r.height());
640
//! @todo this is typical alignment, can we get actual from the style?
641
args.alignment = Qt::AlignCenter;
642
args.transparentBackground = true;
645
else if (args.classname == "QRadioButton") {
646
QRadioButton *radio = static_cast<QRadioButton*>(args.widget);
648
option.initFrom(radio);
649
args.text = radio->text();
650
const QRect r(radio->style()->subElementRect(
651
QStyle::SE_RadioButtonContents, &option, radio));
652
args.geometry = QRect(
653
radio->x() + r.x(), radio->y() + r.y(), r.width(), r.height());
656
else if (args.classname == "QCheckBox") {
657
QCheckBox *check = static_cast<QCheckBox*>(args.widget);
659
option.initFrom(check);
660
const QRect r(args.widget->style()->subElementRect(
661
QStyle::SE_CheckBoxContents, &option, check));
662
args.geometry = QRect(
663
check->x() + r.x(), check->y() + r.y(), r.width(), r.height());
665
} else if (args.classname == "KComboBox" || args.classname == "QComboBox") {
667
KComboBox *combo = qobject_cast<KComboBox*>(args.widget);
668
for (int i = 0; i < combo->count(); i++) {
669
list.append(combo->itemText(i));
671
args.execute = false;
672
if (editList(args.widget, list)) {
673
qobject_cast<KComboBox*>(args.widget)->clear();
674
qobject_cast<KComboBox*>(args.widget)->addItems(list);
678
else if ( args.classname == "KTextEdit" || args.classname == "KDateTimeWidget"
679
|| args.classname == "KTimeWidget" || args.classname == "KDateWidget"
680
|| args.classname == "KIntSpinBox")
682
args.execute = false;
683
disableFilter(args.widget, args.container);
689
bool KexiStandardFormWidgetsFactory::clearWidgetContent(const QByteArray &classname, QWidget *w)
691
if (classname == "QLineEdit")
692
qobject_cast<QLineEdit*>(w)->clear();
693
#ifdef KEXI_LIST_FORM_WIDGET_SUPPORT
694
else if (classname == "QTreeWidget")
695
qobject_cast<QTreeWidget*>(w)->clear();
697
else if (classname == "KComboBox")
698
qobject_cast<KComboBox*>(w)->clear();
699
else if (classname == "KTextEdit")
700
qobject_cast<KTextEdit*>(w)->clear();
706
bool KexiStandardFormWidgetsFactory::changeInlineText(KFormDesigner::Form *form, QWidget *widget,
707
const QString &text, QString &oldText)
709
const QByteArray n(widget->metaObject()->className());
710
if (n == "KIntSpinBox") {
711
oldText = QString::number(qobject_cast<QSpinBox*>(widget)->value());
712
qobject_cast<QSpinBox*>(widget)->setValue(text.toInt());
715
oldText = widget->property("text").toString();
716
changeProperty(form, widget, "text", text);
721
void KexiStandardFormWidgetsFactory::resizeEditor(QWidget *editor, QWidget *widget,
722
const QByteArray &classname)
724
QSize s = widget->size();
725
QPoint p = widget->pos();
728
if (classname == "QRadioButton") {
730
option.initFrom(widget);
731
r = widget->style()->subElementRect(
732
QStyle::SE_RadioButtonContents, &option, widget);
734
s.setWidth(r.width());
735
} else if (classname == "QCheckBox") {
737
option.initFrom(widget);
738
r = widget->style()->subElementRect(
739
QStyle::SE_CheckBoxContents, &option, widget);
741
s.setWidth(r.width());
742
} else if (classname == "QPushButton") {
744
option.initFrom(widget);
745
r = widget->style()->subElementRect(
746
QStyle::SE_PushButtonContents, &option, widget);
755
/* from ContainerFactory::resizeEditor(QWidget *editor, QWidget *widget, const QByteArray &):
756
QSize s = widget->size();
757
editor->move(widget->x() + 2, widget->y() - 5);
758
editor->resize(s.width() - 20, widget->fontMetrics().height() + 10); */
761
bool KexiStandardFormWidgetsFactory::saveSpecialProperty(const QByteArray &classname,
762
const QString &name, const QVariant &,
763
QWidget *w, QDomElement &parentNode, QDomDocument &domDoc)
765
if (name == "list_items" && classname == "KComboBox") {
766
KComboBox *combo = qobject_cast<KComboBox*>(w);
767
for (int i = 0; i < combo->count(); i++) {
768
QDomElement item = domDoc.createElement("item");
769
KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "text", combo->itemText(i));
770
parentNode.appendChild(item);
774
#ifdef KEXI_LIST_FORM_WIDGET_SUPPORT
775
else if (name == "list_contents" && classname == "QTreeWidget") {
776
QTreeWidget *treewidget = qobject_cast<QTreeWidget*>(w);
777
// First we save the columns
778
QTreeWidgetItem *headerItem = treewidget->headerItem();
780
for (int i = 0; i < treewidget->columnCount(); i++) {
781
QDomElement item = domDoc.createElement("column");
782
KFormDesigner::FormIO::savePropertyElement(
783
item, domDoc, "property", "text", headerItem->text(i));
784
KFormDesigner::FormIO::savePropertyElement(
785
item, domDoc, "property", "width", treewidget->columnWidth(i));
786
KFormDesigner::FormIO::savePropertyElement(
787
item, domDoc, "property", "resizable", treewidget->header()->isResizeEnabled(i));
788
KFormDesigner::FormIO::savePropertyElement(
789
item, domDoc, "property", "clickable", treewidget->header()->isClickEnabled(i));
790
KFormDesigner::FormIO::savePropertyElement(
791
item, domDoc, "property", "fullwidth", treewidget->header()->isStretchEnabled(i));
792
parentNode.appendChild(item);
795
// Then we save the list view items
796
QTreeWidgetItem *item = listwidget->firstChild();
798
saveListItem(item, parentNode, domDoc);
799
item = item->nextSibling();
804
else if ((name == "title") && (w->parentWidget()->parentWidget()->inherits("QTabWidget"))) {
805
TabWidgetBase *tab = qobject_cast<TabWidgetBase*>(w->parentWidget()->parentWidget());
806
KFormDesigner::FormIO::savePropertyElement(
807
parentNode, domDoc, "attribute", "title", tab->tabText(tab->indexOf(w)));
808
} else if ((name == "stackIndex")
809
&& (KexiUtils::objectIsA(w->parentWidget(), "QStackedWidget")
810
|| /*compat*/ KexiUtils::objectIsA(w->parentWidget(), "QWidgetStack")))
812
QStackedWidget *stack = qobject_cast<QStackedWidget*>(w->parentWidget());
813
KFormDesigner::FormIO::savePropertyElement(
814
parentNode, domDoc, "attribute", "stackIndex", stack->indexOf(w));
820
#ifdef KEXI_LIST_FORM_WIDGET_SUPPORT
822
KexiStandardFormWidgetsFactory::saveListItem(QListWidgetItem *item,
823
QDomNode &parentNode, QDomDocument &domDoc)
825
QDomElement element = domDoc.createElement("item");
826
parentNode.appendChild(element);
828
// We save the text of each column
829
for (int i = 0; i < item->listWidget()->columns(); i++) {
830
KFormDesigner::FormIO::savePropertyElement(
831
element, domDoc, "property", "text", item->text(i));
834
// Then we save every sub items
835
QListWidgetItem *child = item->firstChild();
837
saveListItem(child, element, domDoc);
838
child = child->nextSibling();
843
bool KexiStandardFormWidgetsFactory::readSpecialProperty(const QByteArray &classname,
844
QDomElement &node, QWidget *w,
845
KFormDesigner::ObjectTreeItem *item)
847
const QString tag( node.tagName() );
848
const QString name( node.attribute("name") );
849
KFormDesigner::Form *form = item->container()
850
? item->container()->form() : item->parent()->container()->form();
852
if ((tag == "item") && (classname == "KComboBox")) {
853
KComboBox *combo = qobject_cast<KComboBox*>(w);
854
QVariant val = KFormDesigner::FormIO::readPropertyValue(
855
form, node.firstChild().firstChild(), w, name);
856
if (val.canConvert(QVariant::Pixmap))
857
combo->addItem(val.value<QPixmap>(), QString());
859
combo->addItem(val.toString());
862
#ifdef KEXI_LIST_FORM_WIDGET_SUPPORT
863
else if (tag == "column" && classname == "QTreeWidget") {
864
QTreeWidget *tw = qobject_cast<QTreeWidget*>(w);
866
for (QDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling()) {
867
QString prop = n.toElement().attribute("name");
868
QVariant val = KFormDesigner::FormIO::readPropertyValue(n.firstChild(), w, name);
870
id = tw->addColumn(val.toString());
871
else if (prop == "width")
872
tw->setColumnWidth(id, val.toInt());
873
else if (prop == "resizable")
874
tw->header()->setResizeEnabled(val.toBool(), id);
875
else if (prop == "clickable")
876
tw->header()->setClickEnabled(val.toBool(), id);
877
else if (prop == "fullwidth")
878
tw->header()->setStretchEnabled(val.toBool(), id);
882
else if (tag == "item" && classname == "QTreeWidget") {
883
QTreeWidget *tw = qobject_cast<QTreeWidget*>(w);
884
readListItem(node, 0, tw);
888
else if ((name == "title") && (item->parent()->widget()->inherits("QTabWidget"))) {
889
TabWidgetBase *tab = qobject_cast<TabWidgetBase*>(w->parentWidget());
890
tab->addTab(w, node.firstChild().toElement().text());
891
item->addModifiedProperty("title", node.firstChild().toElement().text());
894
else if (name == "stackIndex"
895
&& (KexiUtils::objectIsA(w->parentWidget(), "QStackedWidget")
896
|| /*compat*/ KexiUtils::objectIsA(w->parentWidget(), "QWidgetStack")))
898
QStackedWidget *stack = qobject_cast<QStackedWidget*>(w->parentWidget());
899
int index = KFormDesigner::FormIO::readPropertyValue(form, node.firstChild(), w, name).toInt();
900
stack->insertWidget(index, w);
901
stack->setCurrentWidget(w);
902
item->addModifiedProperty("stackIndex", index);
908
#ifdef KEXI_LIST_FORM_WIDGET_SUPPORT
910
KexiStandardFormWidgetsFactory::readTreeItem(
911
QDomElement &node, QTreeWidgetItem *parent, QTreeWidget *treewidget)
913
QTreeWidgetItem *item;
915
item = new QTreeWidgetItem(parent);
917
item = new QTreeWidgetItem(treewidget);
919
// We need to move the item at the end of the list
920
QTreeWidgetItem *last;
922
last = parent->firstChild();
924
last = treewidget->firstChild();
926
while (last->nextSibling())
927
last = last->nextSibling();
928
item->moveItem(last);
931
for (QDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling()) {
932
QDomElement childEl = n.toElement();
933
QString prop = childEl.attribute("name");
934
QString tag = childEl.tagName();
939
readListItem(childEl, item, treewidget);
942
else if (tag == "property" && prop == "text") {
943
QVariant val = KFormDesigner::FormIO::readPropertyValue(
944
n.firstChild(), treewidget, "item");
945
item->setText(i, val.toString());
952
bool KexiStandardFormWidgetsFactory::isPropertyVisibleInternal(const QByteArray &classname,
953
QWidget *w, const QByteArray &property,
957
if (classname == "FormWidgetBase") {
958
if (property == "windowIconText"
959
|| property == "geometry" /*nonsense for toplevel widget*/)
964
else if (classname == "CustomWidget") {
966
else if (classname == "KexiPictureLabel") {
967
if ( property == "text" || property == "indent"
968
|| property == "textFormat" || property == "font"
969
|| property == "alignment")
973
} else if (classname == "QLabel") {
974
if (property == "pixmap")
976
} else if (classname == "QLineEdit") {
977
if (property == "vAlign")
979
} else if (classname == "KTextEdit")
980
ok = KFormDesigner::WidgetFactory::advancedPropertiesVisible() ||
981
( property != "undoDepth"
982
&& property != "undoRedoEnabled" //always true!
983
&& property != "dragAutoScroll" //always true!
984
&& property != "overwriteMode" //always false!
985
&& property != "resizePolicy"
986
&& property != "autoFormatting" //too complex
987
#ifndef KEXI_SHOW_UNFINISHED
988
&& property != "paper"
991
else if (classname == "Line") {
992
if ((property == "frameShape") || (property == "font") || (property == "margin"))
994
} else if (classname == "QCheckBox") {
995
ok = KFormDesigner::WidgetFactory::advancedPropertiesVisible() || (property != "autoRepeat");
996
} else if (classname == "QRadioButton") {
997
ok = KFormDesigner::WidgetFactory::advancedPropertiesVisible() || (property != "autoRepeat");
998
} else if (classname == "QPushButton") {
999
//! @todo reenable autoDefault / default if the top level window is dialog...
1000
ok = KFormDesigner::WidgetFactory::advancedPropertiesVisible() || (property != "autoDefault" && property != "default");
1002
else if ( classname == "HBox" || classname == "VBox" || classname == "Grid"
1003
|| classname == "HFlow" || classname == "VFlow")
1005
return property == "objectName" || property == "geometry";
1007
else if (classname == "QGroupBox") {
1009
#ifndef KEXI_SHOW_UNFINISHED
1010
/*! @todo Hidden for now in Kexi. "checkable" and "checked" props need adding
1011
a fake properties which will allow to properly work in design mode, otherwise
1012
child widgets become frozen when checked==true */
1013
(KFormDesigner::WidgetFactory::advancedPropertiesVisible() || (property != "checkable" && property != "checked")) &&
1016
} else if (classname == "KFDTabWidget") {
1017
ok = (KFormDesigner::WidgetFactory::advancedPropertiesVisible()
1018
|| (property != "tabReorderingEnabled" && property != "hoverCloseButton"
1019
&& property != "hoverCloseButtonDelayed"));
1021
return ok && WidgetFactory::isPropertyVisibleInternal(classname, w, property, isTopLevel);
1024
#ifdef KEXI_LIST_FORM_WIDGET_SUPPORT
1026
KexiStandardFormWidgetsFactory::editListContents()
1028
if (widget()->inherits("QTreeWidget"))
1029
editTreeWidget(qobject_cast<QTreeWidget*>(widget()));
1033
void KexiStandardFormWidgetsFactory::setPropertyOptions(KPropertySet& set,
1034
const KFormDesigner::WidgetInfo& info,
1040
if (set.contains("indent")) {
1041
set["indent"].setOption("min", -1);
1042
set["indent"].setOption("minValueText", xi18nc("default indent value", "default"));
1046
void KexiStandardFormWidgetsFactory::reorderTabs(int oldpos, int newpos)
1048
KFDTabWidget *tabWidget = qobject_cast<KFDTabWidget*>(sender());
1049
KFormDesigner::ObjectTreeItem *tab
1050
= tabWidget->container()->form()->objectTree()->lookup(tabWidget->objectName());
1054
tab->children()->move(oldpos, newpos);
1057
KFormDesigner::ObjectTreeItem* KexiStandardFormWidgetsFactory::selectableItem(
1058
KFormDesigner::ObjectTreeItem* item)
1060
if (item->parent() && item->parent()->widget()) {
1061
if (qobject_cast<QTabWidget*>(item->parent()->widget())) {
1062
// tab widget's page
1063
return item->parent();
1069
#include "KexiStandardFormWidgetsFactory.moc"