~ubuntu-branches/debian/sid/kexi/sid

« back to all changes in this revision

Viewing changes to src/formeditor/factories/KexiStandardFormWidgetsFactory.cpp

  • Committer: Package Import Robot
  • Author(s): Pino Toscano
  • Date: 2017-06-24 20:10:10 UTC
  • Revision ID: package-import@ubuntu.com-20170624201010-5lrzd5r2vwthwifp
Tags: upstream-3.0.1.1
ImportĀ upstreamĀ versionĀ 3.0.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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.
 
20
*/
 
21
 
 
22
#include "KexiStandardFormWidgetsFactory.h"
 
23
#include "KexiStandardFormWidgets.h"
 
24
#include "KexiStandardContainerFormWidgets.h"
 
25
#include "formIO.h"
 
26
#include "form.h"
 
27
#include "widgetlibrary.h"
 
28
#include "objecttree.h"
 
29
#include "WidgetInfo.h"
 
30
#include <kexiutils/utils.h>
 
31
#include <KexiIcon.h>
 
32
#include <kexi.h>
 
33
 
 
34
#include <KProperty>
 
35
#include <KPropertySet>
 
36
 
 
37
#include <KComboBox>
 
38
#include <KTextEdit>
 
39
#include <KLocalizedString>
 
40
 
 
41
#include <QStackedWidget>
 
42
#include <QLabel>
 
43
#include <QRadioButton>
 
44
#include <QCheckBox>
 
45
#include <QSlider>
 
46
#include <QDomDocument>
 
47
#include <QStyle>
 
48
#ifdef KEXI_LIST_FORM_WIDGET_SUPPORT
 
49
#include <QTreeWidget>
 
50
#endif
 
51
#include <QPixmap>
 
52
#include <QFrame>
 
53
#include <QList>
 
54
#include <QProgressBar>
 
55
#include <QTimeEdit>
 
56
#include <QDateEdit>
 
57
#include <QDateTimeEdit>
 
58
#include <QLineEdit>
 
59
#include <QPushButton>
 
60
#include <QAction>
 
61
#include <QSpinBox>
 
62
#include <QDebug>
 
63
 
 
64
KEXI_PLUGIN_FACTORY(KexiStandardFormWidgetsFactory, "kexiforms_standardwidgetsplugin.json")
 
65
 
 
66
KexiStandardFormWidgetsFactory::KexiStandardFormWidgetsFactory(QObject *parent, const QVariantList &args)
 
67
        : KFormDesigner::WidgetFactory(parent)
 
68
{
 
69
    Q_UNUSED(args);
 
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.",
 
82
            "form"));
 
83
    wFormWidget->setDescription(xi18n("A simple form widget"));
 
84
    addClass(wFormWidget);
 
85
 
 
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);
 
93
 
 
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");
 
101
    addClass(wLabel);
 
102
 
 
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");
 
112
    addClass(wPixLabel);
 
113
 
 
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");
 
122
    addClass(wLineEdit);
 
123
 
 
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);
 
134
 
 
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);
 
142
 
 
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");
 
149
    addClass(wCheckBox);
 
150
 
 
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");
 
159
    addClass(wSpinBox);
 
160
 
 
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");
 
170
    addClass(wComboBox);
 
171
 
 
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);
 
187
 
 
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);
 
202
#endif
 
203
 
 
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");
 
213
    addClass(wTextEdit);
 
214
 
 
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");
 
221
    addClass(wSlider);
 
222
 
 
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);
 
230
 
 
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.",
 
243
            "line"));
 
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"));
 
251
    addClass(wLine);
 
252
 
 
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");
 
262
    addClass(wDate);
 
263
 
 
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");
 
273
    addClass(wTime);
 
274
 
 
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");
 
284
    addClass(wDateTime);
 
285
 
 
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"));
 
296
    //line
 
297
    setPropertyDescription("orientation", xi18n("Orientation"));
 
298
    //checkbox
 
299
    setPropertyDescription("checked", xi18nc("Property: Checked checkbox", "Checked"));
 
300
    setPropertyDescription("tristate", xi18nc("Property: Tristate checkbox", "Tristate"));
 
301
 
 
302
    //for labels
 
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"));
 
309
 
 
310
    //QLineEdit
 
311
    setPropertyDescription("placeholderText", xi18nc("Property: line edit's placeholder text", "Placeholder Text"));
 
312
    setPropertyDescription("clearButtonEnabled", xi18nc("Property: Clear Button Enabled", "Clear Button"));
 
313
    //for EchoMode
 
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"));
 
316
 
 
317
    //KTextEdit
 
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"));
 
333
    //ScrollBarPolicy
 
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"));
 
339
 
 
340
    // --- containers ---
 
341
 
 
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.",
 
358
              "tabWidget"));
 
359
    wTabWidget->setDescription(xi18n("A widget to display multiple pages using tabs"));
 
360
    addClass(wTabWidget);
 
361
 
 
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");
 
369
    addClass(wWidget);
 
370
 
 
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.",
 
384
              "groupBox"));
 
385
    wGroupBox->setDescription(xi18n("A container to group some widgets"));
 
386
    addClass(wGroupBox);
 
387
 
 
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");
 
394
    addClass(wFrame);
 
395
 
 
396
    //groupbox
 
397
    setPropertyDescription("title", xi18nc("'Title' property for group box", "Title"));
 
398
    setPropertyDescription("flat", xi18nc("'Flat' property for group box", "Flat"));
 
399
 
 
400
    //tab widget
 
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"));
 
408
 
 
409
    setPropertyDescription("tabsClosable", xi18n("Closable Tabs"));
 
410
    setPropertyDescription("movable", xi18n("Movable Tabs"));
 
411
    setPropertyDescription("documentMode", xi18n("Document Mode"));
 
412
 
 
413
    setValueDescription("Rounded", xi18nc("Property value for Tab Shape", "Rounded"));
 
414
    setValueDescription("Triangular", xi18nc("Property value for Tab Shape", "Triangular"));
 
415
}
 
416
 
 
417
KexiStandardFormWidgetsFactory::~KexiStandardFormWidgetsFactory()
 
418
{
 
419
}
 
420
 
 
421
QWidget* KexiStandardFormWidgetsFactory::createWidget(const QByteArray &c, QWidget *p, const char *n,
 
422
                                                      KFormDesigner::Container *container,
 
423
                                                      CreateWidgetOptions options)
 
424
{
 
425
    QWidget *w = 0;
 
426
    bool createContainer = false;
 
427
    QString text(container->form()->library()->textForWidgetName(n, c));
 
428
    if (c == "QLabel") {
 
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") {
 
441
        w = new QSpinBox(p);
 
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);
 
449
        w = tw;
 
450
        if (container->form()->interactiveMode()) {
 
451
            tw->setColumnCount(1);
 
452
            tw->setHeaderItem(new QTreeWidetItem(tw));
 
453
            tw->headerItem()->setText(1, futureI18n("Column 1"));
 
454
        }
 
455
        lw->setRootIsDecorated(true);
 
456
#endif
 
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);
 
473
        w = tab;
 
474
#if defined(USE_KTabWidget)
 
475
        tab->setTabReorderingEnabled(true);
 
476
        connect(tab, SIGNAL(movedTab(int,int)), this, SLOT(reorderTabs(int,int)));
 
477
#endif
 
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);
 
484
        w->setObjectName(n);
 
485
        new KFormDesigner::Container(container, w, p);
 
486
        return w;
 
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);
 
493
        w = frm;
 
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);
 
499
        w = stack;
 
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));
 
506
 
 
507
        if (container->form()->interactiveMode()) {
 
508
            AddStackPageAction(container, stack, 0).trigger(); // addStackPage();
 
509
        }
 
510
    } else if (c == "HBox") {
 
511
        w = new HBox(p);
 
512
        createContainer = true;
 
513
    } else if (c == "VBox") {
 
514
        w = new VBox(p);
 
515
        createContainer = true;
 
516
    } else if (c == "Grid") {
 
517
        w = new Grid(p);
 
518
        createContainer = true;
 
519
    } else if (c == "HFlow") {
 
520
        w = new HFlow(p);
 
521
        createContainer = true;
 
522
    } else if (c == "VFlow") {
 
523
        w = new VFlow(p);
 
524
        createContainer = true;
 
525
    }
 
526
 
 
527
    if (w) {
 
528
        w->setObjectName(n);
 
529
        qDebug() << w << w->objectName() << "created";
 
530
    }
 
531
    if (createContainer) {
 
532
        (void)new KFormDesigner::Container(container, w, container);
 
533
    }
 
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();
 
539
        }
 
540
    }
 
541
    return w;
 
542
}
 
543
 
 
544
bool KexiStandardFormWidgetsFactory::previewWidget(const QByteArray &classname,
 
545
                                QWidget *widget, KFormDesigner::Container *container)
 
546
{
 
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);
 
553
    }
 
554
    return true;
 
555
}
 
556
 
 
557
bool KexiStandardFormWidgetsFactory::createMenuActions(const QByteArray &classname, QWidget *w,
 
558
                                                       QMenu *menu, KFormDesigner::Container *container)
 
559
{
 
560
    QWidget *pw = w->parentWidget();
 
561
    if ((classname == "QLabel") || (classname == "KTextEdit")) {
 
562
        menu->addAction( new EditRichTextAction(container, w, menu, this) );
 
563
        return true;
 
564
    }
 
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()));
 
569
        return true;
 
570
    }
 
571
#endif
 
572
    else if (classname == "KFDTabWidget" || pw->parentWidget()->inherits("QTabWidget")) {
 
573
//! @todo KEXI3 port this: setWidget(pw->parentWidget(), m_container->toplevel());
 
574
#if 0
 
575
        if (pw->parentWidget()->inherits("QTabWidget")) {
 
576
            setWidget(pw->parentWidget(), m_container->toplevel());
 
577
        }
 
578
#endif
 
579
 
 
580
        TabWidgetBase *tab = qobject_cast<TabWidgetBase*>(w);
 
581
        if (tab) {
 
582
            menu->addAction( new AddTabAction(container, tab, menu) );
 
583
            menu->addAction( new RenameTabAction(container, tab, menu) );
 
584
            menu->addAction( new RemoveTabAction(container, tab, menu) );
 
585
        }
 
586
        return true;
 
587
    }
 
588
    else if (    (KexiUtils::objectIsA(pw, "QStackedWidget") || /* compat */ KexiUtils::objectIsA(pw, "QWidgetStack"))
 
589
              && !pw->parentWidget()->inherits("QTabWidget")
 
590
            )
 
591
    {
 
592
        QStackedWidget *stack = qobject_cast<QStackedWidget*>(pw);
 
593
//! @todo KEXI3 port this: setWidget( pw, container->form()->objectTree()->lookup(stack->objectName())->parent()->container() );
 
594
#if 0
 
595
        setWidget(
 
596
            pw,
 
597
            container->form()->objectTree()->lookup(stack->objectName())->parent()->container()
 
598
        );
 
599
#endif
 
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) );
 
606
        return true;
 
607
    }
 
608
    return false;
 
609
}
 
610
 
 
611
bool KexiStandardFormWidgetsFactory::startInlineEditing(InlineEditorCreationArguments& args)
 
612
{
 
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;
 
618
        return true;
 
619
    }
 
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();
 
625
//! @todo
 
626
        } else {
 
627
            args.text = label->text();
 
628
            args.alignment = label->alignment();
 
629
        }
 
630
        return true;
 
631
    }
 
632
    else if (args.classname == "QPushButton") {
 
633
        QPushButton *push = static_cast<QPushButton*>(args.widget);
 
634
        QStyleOption option;
 
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;
 
643
        return true;
 
644
    }
 
645
    else if (args.classname == "QRadioButton") {
 
646
        QRadioButton *radio = static_cast<QRadioButton*>(args.widget);
 
647
        QStyleOption option;
 
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());
 
654
        return true;
 
655
    }
 
656
    else if (args.classname == "QCheckBox") {
 
657
        QCheckBox *check = static_cast<QCheckBox*>(args.widget);
 
658
        QStyleOption option;
 
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());
 
664
        return true;
 
665
    } else if (args.classname == "KComboBox" || args.classname == "QComboBox") {
 
666
        QStringList list;
 
667
        KComboBox *combo = qobject_cast<KComboBox*>(args.widget);
 
668
        for (int i = 0; i < combo->count(); i++) {
 
669
            list.append(combo->itemText(i));
 
670
        }
 
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);
 
675
        }
 
676
        return true;
 
677
    }
 
678
    else if (   args.classname == "KTextEdit" || args.classname == "KDateTimeWidget"
 
679
             || args.classname == "KTimeWidget" || args.classname == "KDateWidget"
 
680
             || args.classname == "KIntSpinBox")
 
681
    {
 
682
        args.execute = false;
 
683
        disableFilter(args.widget, args.container);
 
684
        return true;
 
685
    }
 
686
    return false;
 
687
}
 
688
 
 
689
bool KexiStandardFormWidgetsFactory::clearWidgetContent(const QByteArray &classname, QWidget *w)
 
690
{
 
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();
 
696
#endif
 
697
    else if (classname == "KComboBox")
 
698
        qobject_cast<KComboBox*>(w)->clear();
 
699
    else if (classname == "KTextEdit")
 
700
        qobject_cast<KTextEdit*>(w)->clear();
 
701
    else
 
702
        return false;
 
703
    return true;
 
704
}
 
705
 
 
706
bool KexiStandardFormWidgetsFactory::changeInlineText(KFormDesigner::Form *form, QWidget *widget,
 
707
                                                      const QString &text, QString &oldText)
 
708
{
 
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());
 
713
    }
 
714
    else {
 
715
        oldText = widget->property("text").toString();
 
716
        changeProperty(form, widget, "text", text);
 
717
    }
 
718
    return true;
 
719
}
 
720
 
 
721
void KexiStandardFormWidgetsFactory::resizeEditor(QWidget *editor, QWidget *widget,
 
722
                                                  const QByteArray &classname)
 
723
{
 
724
    QSize s = widget->size();
 
725
    QPoint p = widget->pos();
 
726
    QRect r;
 
727
 
 
728
    if (classname == "QRadioButton") {
 
729
        QStyleOption option;
 
730
        option.initFrom(widget);
 
731
        r = widget->style()->subElementRect(
 
732
                QStyle::SE_RadioButtonContents, &option, widget);
 
733
        p += r.topLeft();
 
734
        s.setWidth(r.width());
 
735
    } else if (classname == "QCheckBox") {
 
736
        QStyleOption option;
 
737
        option.initFrom(widget);
 
738
        r = widget->style()->subElementRect(
 
739
                QStyle::SE_CheckBoxContents, &option, widget);
 
740
        p += r.topLeft();
 
741
        s.setWidth(r.width());
 
742
    } else if (classname == "QPushButton") {
 
743
        QStyleOption option;
 
744
        option.initFrom(widget);
 
745
        r = widget->style()->subElementRect(
 
746
                QStyle::SE_PushButtonContents, &option, widget);
 
747
        p += r.topLeft();
 
748
        s = r.size();
 
749
    }
 
750
 
 
751
    editor->resize(s);
 
752
    editor->move(p);
 
753
 
 
754
    //! @todo KEXI3
 
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); */
 
759
}
 
760
 
 
761
bool KexiStandardFormWidgetsFactory::saveSpecialProperty(const QByteArray &classname,
 
762
                                      const QString &name, const QVariant &,
 
763
                                      QWidget *w, QDomElement &parentNode, QDomDocument &domDoc)
 
764
{
 
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);
 
771
        }
 
772
        return true;
 
773
    }
 
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();
 
779
        if (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);
 
793
            }
 
794
        }
 
795
        // Then we save the list view items
 
796
        QTreeWidgetItem *item = listwidget->firstChild();
 
797
        while (item) {
 
798
            saveListItem(item, parentNode, domDoc);
 
799
            item = item->nextSibling();
 
800
        }
 
801
        return true;
 
802
    }
 
803
#endif
 
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")))
 
811
    {
 
812
        QStackedWidget *stack = qobject_cast<QStackedWidget*>(w->parentWidget());
 
813
        KFormDesigner::FormIO::savePropertyElement(
 
814
            parentNode, domDoc, "attribute", "stackIndex", stack->indexOf(w));
 
815
    } else
 
816
        return false;
 
817
    return true;
 
818
}
 
819
 
 
820
#ifdef KEXI_LIST_FORM_WIDGET_SUPPORT
 
821
void
 
822
KexiStandardFormWidgetsFactory::saveListItem(QListWidgetItem *item,
 
823
                               QDomNode &parentNode, QDomDocument &domDoc)
 
824
{
 
825
    QDomElement element = domDoc.createElement("item");
 
826
    parentNode.appendChild(element);
 
827
 
 
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));
 
832
    }
 
833
 
 
834
    // Then we save every sub items
 
835
    QListWidgetItem *child = item->firstChild();
 
836
    while (child) {
 
837
        saveListItem(child, element, domDoc);
 
838
        child = child->nextSibling();
 
839
    }
 
840
}
 
841
#endif
 
842
 
 
843
bool KexiStandardFormWidgetsFactory::readSpecialProperty(const QByteArray &classname,
 
844
                                                         QDomElement &node, QWidget *w,
 
845
                                                         KFormDesigner::ObjectTreeItem *item)
 
846
{
 
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();
 
851
 
 
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());
 
858
        else
 
859
            combo->addItem(val.toString());
 
860
        return true;
 
861
    }
 
862
#ifdef KEXI_LIST_FORM_WIDGET_SUPPORT
 
863
    else if (tag == "column" && classname == "QTreeWidget") {
 
864
        QTreeWidget *tw = qobject_cast<QTreeWidget*>(w);
 
865
        int id = 0;
 
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);
 
869
            if (prop == "text")
 
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);
 
879
        }
 
880
        return true;
 
881
    }
 
882
    else if (tag == "item" && classname == "QTreeWidget") {
 
883
        QTreeWidget *tw = qobject_cast<QTreeWidget*>(w);
 
884
        readListItem(node, 0, tw);
 
885
        return true;
 
886
    }
 
887
#endif
 
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());
 
892
        return true;
 
893
    }
 
894
    else if (name == "stackIndex"
 
895
        && (KexiUtils::objectIsA(w->parentWidget(), "QStackedWidget")
 
896
            || /*compat*/ KexiUtils::objectIsA(w->parentWidget(), "QWidgetStack")))
 
897
    {
 
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);
 
903
        return true;
 
904
    }
 
905
    return false;
 
906
}
 
907
 
 
908
#ifdef KEXI_LIST_FORM_WIDGET_SUPPORT
 
909
void
 
910
KexiStandardFormWidgetsFactory::readTreeItem(
 
911
    QDomElement &node, QTreeWidgetItem *parent, QTreeWidget *treewidget)
 
912
{
 
913
    QTreeWidgetItem *item;
 
914
    if (parent)
 
915
        item = new QTreeWidgetItem(parent);
 
916
    else
 
917
        item = new QTreeWidgetItem(treewidget);
 
918
 
 
919
    // We need to move the item at the end of the list
 
920
    QTreeWidgetItem *last;
 
921
    if (parent)
 
922
        last = parent->firstChild();
 
923
    else
 
924
        last = treewidget->firstChild();
 
925
 
 
926
    while (last->nextSibling())
 
927
        last = last->nextSibling();
 
928
    item->moveItem(last);
 
929
 
 
930
    int i = 0;
 
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();
 
935
 
 
936
        // We read sub items
 
937
        if (tag == "item") {
 
938
            item->setOpen(true);
 
939
            readListItem(childEl, item, treewidget);
 
940
        }
 
941
        // and column texts
 
942
        else if (tag == "property" && prop == "text") {
 
943
            QVariant val = KFormDesigner::FormIO::readPropertyValue(
 
944
                n.firstChild(), treewidget, "item");
 
945
            item->setText(i, val.toString());
 
946
            i++;
 
947
        }
 
948
    }
 
949
}
 
950
#endif
 
951
 
 
952
bool KexiStandardFormWidgetsFactory::isPropertyVisibleInternal(const QByteArray &classname,
 
953
                                                               QWidget *w, const QByteArray &property,
 
954
                                                               bool isTopLevel)
 
955
{
 
956
    bool ok = true;
 
957
    if (classname == "FormWidgetBase") {
 
958
        if (property == "windowIconText"
 
959
                || property == "geometry" /*nonsense for toplevel widget*/)
 
960
        {
 
961
            return false;
 
962
        }
 
963
    }
 
964
    else if (classname == "CustomWidget") {
 
965
    }
 
966
    else if (classname == "KexiPictureLabel") {
 
967
        if (   property == "text" || property == "indent"
 
968
            || property == "textFormat" || property == "font"
 
969
            || property == "alignment")
 
970
        {
 
971
            return false;
 
972
        }
 
973
    } else if (classname == "QLabel") {
 
974
        if (property == "pixmap")
 
975
            return false;
 
976
    } else if (classname == "QLineEdit") {
 
977
        if (property == "vAlign")
 
978
            return false;
 
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"
 
989
#endif
 
990
             );
 
991
    else if (classname == "Line") {
 
992
        if ((property == "frameShape") || (property == "font") || (property == "margin"))
 
993
            return false;
 
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");
 
1001
    }
 
1002
    else if (   classname == "HBox" || classname == "VBox" || classname == "Grid"
 
1003
             || classname == "HFlow" || classname == "VFlow")
 
1004
    {
 
1005
        return property == "objectName" || property == "geometry";
 
1006
    }
 
1007
    else if (classname == "QGroupBox") {
 
1008
        ok =
 
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")) &&
 
1014
#endif
 
1015
            true;
 
1016
    } else if (classname == "KFDTabWidget") {
 
1017
        ok = (KFormDesigner::WidgetFactory::advancedPropertiesVisible()
 
1018
              || (property != "tabReorderingEnabled" && property != "hoverCloseButton"
 
1019
                  && property != "hoverCloseButtonDelayed"));
 
1020
    }
 
1021
    return ok && WidgetFactory::isPropertyVisibleInternal(classname, w, property, isTopLevel);
 
1022
}
 
1023
 
 
1024
#ifdef KEXI_LIST_FORM_WIDGET_SUPPORT
 
1025
void
 
1026
KexiStandardFormWidgetsFactory::editListContents()
 
1027
{
 
1028
    if (widget()->inherits("QTreeWidget"))
 
1029
        editTreeWidget(qobject_cast<QTreeWidget*>(widget()));
 
1030
}
 
1031
#endif
 
1032
 
 
1033
void KexiStandardFormWidgetsFactory::setPropertyOptions(KPropertySet& set,
 
1034
                                                        const KFormDesigner::WidgetInfo& info,
 
1035
                                                        QWidget *w)
 
1036
{
 
1037
    Q_UNUSED(info);
 
1038
    Q_UNUSED(w);
 
1039
 
 
1040
    if (set.contains("indent")) {
 
1041
        set["indent"].setOption("min", -1);
 
1042
        set["indent"].setOption("minValueText", xi18nc("default indent value", "default"));
 
1043
    }
 
1044
}
 
1045
 
 
1046
void KexiStandardFormWidgetsFactory::reorderTabs(int oldpos, int newpos)
 
1047
{
 
1048
    KFDTabWidget *tabWidget = qobject_cast<KFDTabWidget*>(sender());
 
1049
    KFormDesigner::ObjectTreeItem *tab
 
1050
            = tabWidget->container()->form()->objectTree()->lookup(tabWidget->objectName());
 
1051
    if (!tab)
 
1052
        return;
 
1053
 
 
1054
    tab->children()->move(oldpos, newpos);
 
1055
}
 
1056
 
 
1057
KFormDesigner::ObjectTreeItem* KexiStandardFormWidgetsFactory::selectableItem(
 
1058
                                                KFormDesigner::ObjectTreeItem* item)
 
1059
{
 
1060
    if (item->parent() && item->parent()->widget()) {
 
1061
        if (qobject_cast<QTabWidget*>(item->parent()->widget())) {
 
1062
            // tab widget's page
 
1063
            return item->parent();
 
1064
        }
 
1065
    }
 
1066
    return item;
 
1067
}
 
1068
 
 
1069
#include "KexiStandardFormWidgetsFactory.moc"