1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
|
/* This file is part of the KDE project
Copyright (C) 2004 Cedric Pasteur <[email protected]>
Copyright (C) 2004-2006 Jaroslaw Staniek <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <tqpopupmenu.h>
#include <tqscrollview.h>
#include <tqcursor.h>
#include <tqpainter.h>
#include <tqstyle.h>
#include <kgenericfactory.h>
#include <tdelocale.h>
#include <kdebug.h>
#include <kiconloader.h>
#include <tdeactioncollection.h>
#include <kstdaction.h>
#include <formeditor/container.h>
#include <formeditor/form.h>
#include <formeditor/formIO.h>
#include <formeditor/formmanager.h>
#include <formeditor/objecttree.h>
#include <formeditor/utils.h>
#include <kexidb/utils.h>
#include <kexidb/connection.h>
#include <kexipart.h>
#include <formeditor/widgetlibrary.h>
#include <kexigradientwidget.h>
#include <keximainwindow.h>
#include <kexiutils/utils.h>
#include <widget/kexicustompropertyfactory.h>
#include <widget/utils/kexicontextmenuutils.h>
#include "kexiformview.h"
#include "widgets/kexidbautofield.h"
#include "widgets/kexidbcheckbox.h"
#include "widgets/kexidbimagebox.h"
//#include "widgets/kexidbdoublespinbox.h"
//#include "widgets/kexidbintspinbox.h"
#include "widgets/kexiframe.h"
#include "widgets/kexidblabel.h"
#include "widgets/kexidblineedit.h"
#include "widgets/kexidbtextedit.h"
#include "widgets/kexidbcombobox.h"
#include "widgets/kexipushbutton.h"
#include "widgets/kexidbform.h"
#include "widgets/kexidbsubform.h"
#include "kexidataawarewidgetinfo.h"
#include "kexidbfactory.h"
#include <core/kexi.h>
//////////////////////////////////////////
KexiDBFactory::KexiDBFactory(TQObject *parent, const char *name, const TQStringList &)
: KFormDesigner::WidgetFactory(parent, name)
{
KFormDesigner::WidgetInfo *wi;
wi = new KexiDataAwareWidgetInfo(this);
wi->setPixmap("form");
wi->setClassName("KexiDBForm");
wi->setName(i18n("Form"));
wi->setNamePrefix(
i18n("Widget name. This string will be used to name widgets of this class. "
"It must _not_ contain white spaces and non latin1 characters.", "form"));
wi->setDescription(i18n("A data-aware form widget"));
addClass(wi);
#ifndef KEXI_NO_SUBFORM
wi = new KexiDataAwareWidgetInfo(this);
wi->setPixmap("subform");
wi->setClassName("KexiDBSubForm");
wi->addAlternateClassName("KexiSubForm", true/*override*/); //older
wi->setName(i18n("Sub Form"));
wi->setNamePrefix(
i18n("Widget name. This string will be used to name widgets of this class. "
"It must _not_ contain white spaces and non latin1 characters.", "subForm"));
wi->setDescription(i18n("A form widget included in another Form"));
wi->setAutoSyncForProperty( "formName", false );
addClass(wi);
#endif
// inherited
wi = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KLineEdit");
wi->setPixmap("lineedit");
wi->setClassName("KexiDBLineEdit");
wi->addAlternateClassName("TQLineEdit", true/*override*/);
wi->addAlternateClassName("KLineEdit", true/*override*/);
wi->setIncludeFileName("klineedit.h");
wi->setName(i18n("Text Box"));
wi->setNamePrefix(
i18n("Widget name. This string will be used to name widgets of this class. "
"It must _not_ contain white spaces and non latin1 characters.", "textBox"));
wi->setDescription(i18n("A widget for entering and displaying text"));
addClass(wi);
// inherited
wi = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KTextEdit");
wi->setPixmap("textedit");
wi->setClassName("KexiDBTextEdit");
wi->addAlternateClassName("TQTextEdit", true/*override*/);
wi->addAlternateClassName("KTextEdit", true/*override*/);
wi->setIncludeFileName("ktextedit.h");
wi->setName(i18n("Text Editor"));
wi->setNamePrefix(
i18n("Widget name. This string will be used to name widgets of this class. "
"It must _not_ contain white spaces and non latin1 characters.", "textEditor"));
wi->setDescription(i18n("A multiline text editor"));
addClass(wi);
wi = new KFormDesigner::WidgetInfo(
this, "containers", "TQFrame" /*we're inheriting to get i18n'd strings already translated there*/);
wi->setPixmap("frame");
wi->setClassName("KexiFrame");
wi->addAlternateClassName("TQFrame", true/*override*/);
wi->setName(i18n("Frame"));
wi->setNamePrefix(
i18n("Widget name. This string will be used to name widgets of this class. "
"It must _not_ contain white spaces and non latin1 characters.", "frame"));
wi->setDescription(i18n("A simple frame widget"));
addClass(wi);
wi = new KexiDataAwareWidgetInfo(
this, "stdwidgets", "TQLabel" /*we're inheriting to get i18n'd strings already translated there*/);
wi->setPixmap("label");
wi->setClassName("KexiDBLabel");
wi->addAlternateClassName("TQLabel", true/*override*/);
wi->addAlternateClassName("KexiLabel", true/*override*/); //older
wi->setName(i18n("Text Label", "Label"));
wi->setNamePrefix(
i18n("Widget name. This string will be used to name widgets of this class. "
"It must _not_ contain white spaces and non latin1 characters.", "label"));
wi->setDescription(i18n("A widget for displaying text"));
addClass(wi);
#ifndef KEXI_NO_IMAGEBOX_WIDGET
wi = new KexiDataAwareWidgetInfo(
this, "stdwidgets", "KexiPictureLabel" /*we're inheriting to get i18n'd strings already translated there*/);
wi->setPixmap("pixmaplabel");
wi->setClassName("KexiDBImageBox");
wi->addAlternateClassName("KexiPictureLabel", true/*override*/);
wi->addAlternateClassName("KexiImageBox", true/*override*/); //older
wi->setName(i18n("Image Box"));
wi->setNamePrefix(
i18n("Widget name. This string will be used to name widgets of this class. "
"It must _not_ contain white spaces and non latin1 characters.", "image"));
wi->setDescription(i18n("A widget for displaying images"));
// wi->setCustomTypeForProperty("pixmapData", KexiCustomPropertyFactory::PixmapData);
wi->setCustomTypeForProperty("pixmapId", KexiCustomPropertyFactory::PixmapId);
addClass(wi);
setInternalProperty("KexiDBImageBox", "dontStartEditingOnInserting", "1");
// setInternalProperty("KexiDBImageBox", "forceShowAdvancedProperty:pixmap", "1");
#endif
#ifdef KEXI_DB_COMBOBOX_WIDGET
wi = new KexiDataAwareWidgetInfo(
this, "stdwidgets", "KComboBox" /*we're inheriting to get i18n'd strings already translated there*/);
wi->setPixmap("combo");
wi->setClassName("KexiDBComboBox");
wi->addAlternateClassName("KComboBox", true/*override*/);
wi->setName(i18n("Combo Box"));
wi->setNamePrefix(
i18n("Widget name. This string will be used to name widgets of this class. "
"It must _not_ contain white spaces and non latin1 characters.", "comboBox"));
wi->setDescription(i18n("A combo box widget"));
addClass(wi);
#endif
wi = new KexiDataAwareWidgetInfo(this, "stdwidgets", "TQCheckBox");
wi->setPixmap("check");
wi->setClassName("KexiDBCheckBox");
wi->addAlternateClassName("TQCheckBox", true/*override*/);
wi->setName(i18n("Check Box"));
wi->setNamePrefix(
i18n("Widget name. This string will be used to name widgets of this class. "
"It must _not_ contain white spaces and non latin1 characters.", "checkBox"));
wi->setDescription(i18n("A check box with text label"));
addClass(wi);
#ifndef KEXI_NO_AUTOFIELD_WIDGET
wi = new KexiDataAwareWidgetInfo(this);
wi->setPixmap("autofield");
wi->setClassName("KexiDBAutoField");
wi->addAlternateClassName("KexiDBFieldEdit", true/*override*/); //older
wi->setName(i18n("Auto Field"));
wi->setNamePrefix(
i18n("Widget name. This string will be used to name widgets of this class. "
"It must _not_ contain white spaces and non latin1 characters", "autoField"));
wi->setDescription(i18n("A widget containing an automatically selected editor "
"and a label to edit the value of a database field of any type."));
addClass(wi);
#endif
/*
#if TDE_VERSION >= TDE_MAKE_VERSION(3,1,9)
KexiDataAwareWidgetInfo *wDate = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KDateWidget");
#else
KexiDataAwareWidgetInfo *wDate = new KexiDataAwareWidgetInfo(this, "stdwidgets", "TQDateEdit");
#endif
wDate->setPixmap("dateedit");
wDate->setClassName("KexiDBDateEdit");
wDate->addAlternateClassName("TQDateEdit", true);//override
wDate->addAlternateClassName("KDateWidget", true);//override
wDate->setName(i18n("Date Widget"));
wDate->setNamePrefix(
i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "dateWidget"));
wDate->setDescription(i18n("A widget to input and display a date"));
addClass(wDate);
#if TDE_VERSION >= TDE_MAKE_VERSION(3,1,9)
KexiDataAwareWidgetInfo *wTime = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KTimeWidget");
#else
KexiDataAwareWidgetInfo *wTime = new KexiDataAwareWidgetInfo(this, "stdwidgets", "TQTimeEdit");
#endif
wTime->setPixmap("timeedit");
wTime->setClassName("KexiDBTimeEdit");
wTime->addAlternateClassName("TQTimeEdit", true);//override
wTime->addAlternateClassName("KTimeWidget", true);//override
wTime->setName(i18n("Time Widget"));
wTime->setNamePrefix(
i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "timeWidget"));
wTime->setDescription(i18n("A widget to input and display a time"));
addClass(wTime);
#if TDE_VERSION >= TDE_MAKE_VERSION(3,1,9)
KexiDataAwareWidgetInfo *wDateTime = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KDateTimeWidget");
#else
KexiDataAwareWidgetInfo *wDateTime = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KDateTimeWidget");
#endif
wDateTime->setPixmap("datetimeedit");
wDateTime->setClassName("KexiDBDateTimeEdit");
wDateTime->addAlternateClassName("TQDateTimeEdit", true);//override
wDateTime->addAlternateClassName("KDateTimeWidget", true);//override
wDateTime->setName(i18n("Date/Time Widget"));
wDateTime->setNamePrefix(
i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "dateTimeWidget"));
wDateTime->setDescription(i18n("A widget to input and display a date and time"));
addClass(wDateTime);
*/
/* KexiDataAwareWidgetInfo *wIntSpinBox = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KIntSpinBox");
wIntSpinBox->setPixmap("spin");
wIntSpinBox->setClassName("KexiDBIntSpinBox");
wIntSpinBox->addAlternateClassName("TQSpinBox", true);
wIntSpinBox->addAlternateClassName("KIntSpinBox", true);
wIntSpinBox->setName(i18n("Integer Number Spin Box"));
wIntSpinBox->setNamePrefix(
i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "intSpinBox"));
wIntSpinBox->setDescription(i18n("A spin box widget to input and display integer numbers"));
addClass(wIntSpinBox);
KexiDataAwareWidgetInfo *wDoubleSpinBox = new KexiDataAwareWidgetInfo(this, "stdwidgets");
wDoubleSpinBox->setPixmap("spin");
wDoubleSpinBox->setClassName("KexiDBDoubleSpinBox");
wDoubleSpinBox->addAlternateClassName("KDoubleSpinBox", true);
wDoubleSpinBox->setName(i18n("Floating-point Number Spin Box"));
wDoubleSpinBox->setNamePrefix(
i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "dblSpinBox"));
wDoubleSpinBox->setDescription(i18n("A spin box widget to input and display floating-point numbers"));
addClass(wDoubleSpinBox);*/
// inherited
wi = new KFormDesigner::WidgetInfo(
this, "stdwidgets", "KPushButton");
wi->addAlternateClassName("KexiPushButton");
wi->setName(i18n("Command Button"));
wi->setNamePrefix(
i18n("Widget name. This string will be used to name widgets of this class. "
"It must _not_ contain white spaces and non latin1 characters.", "button"));
wi->setDescription(i18n("A command button to execute actions"));
addClass(wi);
m_propDesc["dataSource"] = i18n("Data Source");
m_propDesc["formName"] = i18n("Form Name");
m_propDesc["onClickAction"] = i18n("On Click");
m_propDesc["onClickActionOption"] = i18n("On Click Option");
m_propDesc["autoTabStops"] = i18n("Auto Tab Order");
m_propDesc["shadowEnabled"] = i18n("Shadow Enabled");
m_propDesc["on"] = i18n("On: button", "On");
m_propDesc["widgetType"] = i18n("Editor Type");
//for autofield's type: inherit i18n from KexiDB
m_propValDesc["Auto"] = i18n("AutoField editor's type", "Auto");
m_propValDesc["Text"] = KexiDB::Field::typeName(KexiDB::Field::Text);
m_propValDesc["Integer"] = KexiDB::Field::typeName(KexiDB::Field::Integer);
m_propValDesc["Double"] = KexiDB::Field::typeName(KexiDB::Field::Double);
m_propValDesc["Boolean"] = KexiDB::Field::typeName(KexiDB::Field::Boolean);
m_propValDesc["Date"] = KexiDB::Field::typeName(KexiDB::Field::Date);
m_propValDesc["Time"] = KexiDB::Field::typeName(KexiDB::Field::Time);
m_propValDesc["DateTime"] = KexiDB::Field::typeName(KexiDB::Field::DateTime);
m_propValDesc["MultiLineText"] = i18n("AutoField editor's type", "Multiline Text");
m_propValDesc["ComboBox"] = i18n("AutoField editor's type", "Drop-Down List");
m_propValDesc["Image"] = i18n("AutoField editor's type", "Image");
// m_propDesc["labelCaption"] = i18n("Label Text");
m_propDesc["autoCaption"] = i18n("Auto Label");
m_propDesc["foregroundLabelColor"] = i18n("Label Text Color");
m_propDesc["backgroundLabelColor"] = i18n("(a property name, keep the text narrow!)",
"Label Background\nColor");
m_propDesc["labelPosition"] = i18n("Label Position");
m_propValDesc["Left"] = i18n("Label Position", "Left");
m_propValDesc["Top"] = i18n("Label Position", "Top");
m_propValDesc["NoLabel"] = i18n("Label Position", "No Label");
m_propDesc["sizeInternal"] = i18n("Size");
// m_propDesc["pixmap"] = i18n("Image");
m_propDesc["pixmapId"] = i18n("Image");
m_propDesc["scaledContents"] = i18n("Scaled Contents");
m_propDesc["keepAspectRatio"] = i18n("Keep Aspect Ratio (short)", "Keep Ratio");
//hide classes that are replaced by db-aware versions
hideClass("KexiPictureLabel");
hideClass("KComboBox");
//used in labels, frames...
m_propDesc["frameColor"] = i18n("Frame Color");
m_propDesc["dropDownButtonVisible"] =
i18n("Drop-Down Button for Image Box Visible (a property name, keep the text narrow!)",
"Drop-Down\nButton Visible");
//for checkbox
m_propValDesc["TristateDefault"] = i18n("Tristate checkbox, default", "Default");
m_propValDesc["TristateOn"] = i18n("Tristate checkbox, yes", "Yes");
m_propValDesc["TristateOff"] = i18n("Tristate checkbox, no", "No");
//for combobox
m_propDesc["editable"] = i18n("Editable combobox", "Editable");
}
KexiDBFactory::~KexiDBFactory()
{
}
TQWidget*
KexiDBFactory::createWidget(const TQCString &c, TQWidget *p, const char *n,
KFormDesigner::Container *container, int options)
{
kexipluginsdbg << "KexiDBFactory::createWidget() " << this << endl;
TQWidget *w=0;
TQString text( container->form()->library()->textForWidgetName(n, c) );
const bool designMode = options & KFormDesigner::WidgetFactory::DesignViewMode;
if(c == "KexiDBSubForm")
w = new KexiDBSubForm(container->form(), p, n);
else if(c == "KexiDBLineEdit")
{
w = new KexiDBLineEdit(p, n);
if (designMode)
w->setCursor(TQCursor(TQt::ArrowCursor));
}
else if(c == "KexiDBTextEdit")
{
w = new KexiDBTextEdit(p, n);
if (designMode)
w->setCursor(TQCursor(TQt::ArrowCursor));
}
else if(c == "TQFrame" || c == "KexiFrame")
{
w = new KexiFrame(p, n);
new KFormDesigner::Container(container, w, container);
}
else if(c == "KexiDBLabel")
w = new KexiDBLabel(text, p, n);
#ifndef KEXI_NO_IMAGEBOX_WIDGET
else if(c == "KexiDBImageBox") {
w = new KexiDBImageBox(designMode, p, n);
connect(w, TQT_SIGNAL(idChanged(long)), this, TQT_SLOT(slotImageBoxIdChanged(long)));
}
#endif
#ifndef KEXI_NO_AUTOFIELD_WIDGET
else if(c == "KexiDBAutoField")
w = new KexiDBAutoField(p, n, designMode);
#endif
else if(c == "KexiDBCheckBox")
w = new KexiDBCheckBox(text, p, n);
else if(c == "KexiDBComboBox")
w = new KexiDBComboBox(p, n, designMode);
/* else if(c == "KexiDBTimeEdit")
w = new KexiDBTimeEdit(TQTime::currentTime(), p, n);
else if(c == "KexiDBDateEdit")
w = new KexiDBDateEdit(TQDate::currentDate(), p, n);
else if(c == "KexiDBDateTimeEdit")
w = new KexiDBDateTimeEdit(TQDateTime::currentDateTime(), p, n);*/
// else if(c == "KexiDBIntSpinBox")
// w = new KexiDBIntSpinBox(p, n);
// else if(c == "KexiDBDoubleSpinBox")
// w = new KexiDBDoubleSpinBox(p, n);
else if(c == "KPushButton" || c == "KexiPushButton")
w = new KexiPushButton(text, p, n);
return w;
}
bool
KexiDBFactory::createMenuActions(const TQCString &classname, TQWidget *w, TQPopupMenu *menu,
KFormDesigner::Container *)
{
if(classname == "TQPushButton" || classname == "KPushButton" || classname == "KexiPushButton")
{
/*! @todo also call createMenuActions() for inherited factory! */
m_assignAction->plug( menu );
return true;
}
else if(classname == "KexiDBImageBox")
{
KexiDBImageBox *imageBox = static_cast<KexiDBImageBox*>(w);
imageBox->contextMenu()->updateActionsAvailability();
TDEActionCollection *ac = imageBox->contextMenu()->actionCollection();
TDEPopupMenu *subMenu = new TDEPopupMenu();
//! @todo make these actions undoable/redoable
menu->insertItem(i18n("&Image"), subMenu);
ac->action("insert")->plug(subMenu);
ac->action("file_save_as")->plug(subMenu);
subMenu->insertSeparator();
ac->action("edit_cut")->plug(subMenu);
ac->action("edit_copy")->plug(subMenu);
ac->action("edit_paste")->plug(subMenu);
ac->action("delete")->plug(subMenu);
if (ac->action("properties")) {
subMenu->insertSeparator();
ac->action("properties")->plug(subMenu);
}
}
return false;
}
void
KexiDBFactory::createCustomActions(TDEActionCollection* col)
{
//this will create shared instance action for design mode (special collection is provided)
m_assignAction = new TDEAction( i18n("&Assign Action..."), SmallIconSet("form_action"),
0, 0, 0, col, "widget_assign_action");
}
bool
KexiDBFactory::startEditing(const TQCString &classname, TQWidget *w, KFormDesigner::Container *container)
{
m_container = container;
if(classname == "KexiDBLineEdit")
{
//! @todo this code should not be copied here but
//! just inherited StdWidgetFactory::clearWidgetContent() should be called
KLineEdit *lineedit = static_cast<KLineEdit*>(w);
createEditor(classname, lineedit->text(), lineedit, container,
lineedit->geometry(), lineedit->alignment(), true);
return true;
}
if(classname == "KexiDBTextEdit")
{
//! @todo this code should not be copied here but
//! just inherited StdWidgetFactory::clearWidgetContent() should be called
KTextEdit *textedit = static_cast<KTextEdit*>(w);
createEditor(classname, textedit->text(), textedit, container,
textedit->geometry(), textedit->alignment(), true, true);
//copy a few properties
KTextEdit *ed = dynamic_cast<KTextEdit *>( editor(w) );
ed->setWrapPolicy(textedit->wrapPolicy());
ed->setWordWrap(textedit->wordWrap());
ed->setTabStopWidth(textedit->tabStopWidth());
ed->setWrapColumnOrWidth(textedit->wrapColumnOrWidth());
ed->setLinkUnderline(textedit->linkUnderline());
ed->setTextFormat(textedit->textFormat());
ed->setHScrollBarMode(textedit->hScrollBarMode());
ed->setVScrollBarMode(textedit->vScrollBarMode());
return true;
}
else if ( classname == "KexiDBLabel" ) {
KexiDBLabel *label = static_cast<KexiDBLabel*>(w);
m_widget = w;
if(label->textFormat() == RichText)
{
TQString text = label->text();
if ( editRichText( label, text ) )
{
changeProperty( "textFormat", "RichText", container->form() );
changeProperty( "text", text, container->form() );
}
if ( classname == "KexiDBLabel" )
w->resize(w->sizeHint());
}
else
{
createEditor(classname, label->text(), label, container,
label->geometry(), label->alignment(),
false, label->alignment() & TQt::WordBreak /*multiline*/);
}
return true;
}
else if (classname == "KexiDBSubForm") {
// open the form in design mode
KexiMainWindow *mainWin = KexiUtils::findParent<KexiMainWindow>(w, "KexiMainWindow");
KexiDBSubForm *subform = static_cast<KexiDBSubForm*>(w);
if(mainWin) {
bool openingCancelled;
mainWin->openObject("kexi/form", subform->formName(), Kexi::DesignViewMode,
openingCancelled);
}
return true;
}
#if 0
else if( (classname == "KexiDBDateEdit") || (classname == "KexiDBDateTimeEdit") || (classname == "KexiDBTimeEdit")
/*|| (classname == "KexiDBIntSpinBox") || (classname == "KexiDBDoubleSpinBox")*/ ) {
disableFilter(w, container);
return true;
}
#endif
else if(classname == "KexiDBAutoField") {
if(static_cast<KexiDBAutoField*>(w)->hasAutoCaption())
return false; // caption is auto, abort editing
TQLabel *label = static_cast<KexiDBAutoField*>(w)->label();
createEditor(classname, label->text(), label, container, label->geometry(), label->alignment());
return true;
}
else if (classname == "KexiDBCheckBox") {
KexiDBCheckBox *cb = static_cast<KexiDBCheckBox*>(w);
TQRect r( cb->geometry() );
r.setLeft( r.left() + 2 + cb->style().subRect( TQStyle::SR_CheckBoxIndicator, cb ).width() );
createEditor(classname, cb->text(), cb, container, r, TQt::AlignAuto);
return true;
}
else if(classname == "KexiDBImageBox") {
KexiDBImageBox *image = static_cast<KexiDBImageBox*>(w);
image->insertFromFile();
return true;
}
return false;
}
bool
KexiDBFactory::previewWidget(const TQCString &, TQWidget *, KFormDesigner::Container *)
{
return false;
}
bool
KexiDBFactory::clearWidgetContent(const TQCString & /*classname*/, TQWidget *w)
{
//! @todo this code should not be copied here but
//! just inherited StdWidgetFactory::clearWidgetContent() should be called
KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>(w);
if(iface)
iface->clear();
return true;
}
TQValueList<TQCString>
KexiDBFactory::autoSaveProperties(const TQCString & /*classname*/)
{
TQValueList<TQCString> lst;
// if(classname == "KexiDBSubForm")
//lst << "formName";
// if(classname == "KexiDBLineEdit")
// lst += "dataSource";
// if(classname == "KexiDBAutoField")
// lst << "labelCaption";
return lst;
}
bool
KexiDBFactory::isPropertyVisibleInternal(const TQCString& classname, TQWidget *w,
const TQCString& property, bool isTopLevel)
{
//general
if (property=="dataSource" || property=="dataSourceMimeType") {
return false; //force
}
bool ok = true;
if(classname == "KexiPushButton") {
ok = property!="isDragEnabled"
#ifdef KEXI_NO_UNFINISHED
&& property!="onClickAction" /*! @todo reenable */
&& property!="onClickActionOption" /*! @todo reenable */
&& property!="iconSet" /*! @todo reenable */
&& property!="stdItem" /*! @todo reenable stdItem */
#endif
;
}
else if(classname == "KexiDBLineEdit")
ok = property!="urlDropsEnabled"
&& property!="vAlign"
#ifdef KEXI_NO_UNFINISHED
&& property!="inputMask"
&& property!="maxLength" //!< we may want to integrate this with db schema
#endif
;
else if(classname == "KexiDBComboBox")
ok = property!="autoCaption"
&& property!="labelPosition"
&& property!="widgetType"
&& property!="fieldTypeInternal"
&& property!="fieldCaptionInternal"; //hide properties that come with KexiDBAutoField
else if(classname == "KexiDBTextEdit")
ok = property!="undoDepth"
&& property!="undoRedoEnabled" //always true!
&& property!="dragAutoScroll" //always true!
&& property!="overwriteMode" //always false!
&& property!="resizePolicy"
&& property!="autoFormatting" //too complex
#ifdef KEXI_NO_UNFINISHED
&& property!="paper"
#endif
;
else if(classname == "KexiDBSubForm")
ok = property!="dragAutoScroll"
&& property!="resizePolicy"
&& property!="focusPolicy";
else if(classname == "KexiDBForm")
ok = property!="iconText"
&& property!="geometry" /*nonsense for toplevel widget; for size, "size" property is used*/;
else if(classname == "KexiDBLabel")
ok = property!="focusPolicy";
else if(classname == "KexiDBAutoField") {
if (!isTopLevel && property=="caption")
return true; //force
if (property=="fieldTypeInternal" || property=="fieldCaptionInternal"
//! @todo unhide in 2.0
|| property=="widgetType")
return false;
ok = property!="text"; /* "text" is not needed as "caption" is used instead */
}
else if (classname == "KexiDBImageBox") {
ok = property!="font" && property!="wordbreak";
}
else if(classname == "KexiDBCheckBox") {
//hide text property if the widget is a child of an autofield beause there's already "caption" for this purpose
if (property=="text" && w && dynamic_cast<KFormDesigner::WidgetWithSubpropertiesInterface*>(w->parentWidget()))
return false;
ok = property!="autoRepeat";
}
return ok && WidgetFactory::isPropertyVisibleInternal(classname, w, property, isTopLevel);
}
bool
KexiDBFactory::propertySetShouldBeReloadedAfterPropertyChange(const TQCString& classname,
TQWidget *w, const TQCString& property)
{
Q_UNUSED(classname);
Q_UNUSED(w);
if (property=="fieldTypeInternal" || property=="widgetType")
return true;
return false;
}
bool
KexiDBFactory::changeText(const TQString &text)
{
KFormDesigner::Form *form = m_container ? m_container->form() : 0;
if (!form)
return false;
if (!form->selectedWidget())
return false;
TQCString n( form->selectedWidget()->className() );
// TQWidget *w = WidgetFactory::widget();
if(n == "KexiDBAutoField") {
changeProperty("caption", text, form);
return true;
}
//! \todo check field's geometry
return false;
}
void
KexiDBFactory::resizeEditor(TQWidget *editor, TQWidget *w, const TQCString &classname)
{
//TQSize s = widget->size();
//TQPoint p = widget->pos();
if(classname == "KexiDBAutoField")
editor->setGeometry( static_cast<KexiDBAutoField*>(w)->label()->geometry() );
}
void
KexiDBFactory::slotImageBoxIdChanged(KexiBLOBBuffer::Id_t id)
{
//old KexiFormView *formView = KexiUtils::findParent<KexiFormView>((TQWidget*)m_widget, "KexiFormView");
// (js) heh, porting to KFormDesigner::FormManager::self() singleton took me entire day of work...
KFormDesigner::Form *form = KFormDesigner::FormManager::self()->activeForm();
KexiFormView *formView = form ? KexiUtils::findParent<KexiFormView>((TQWidget*)form->widget(), "KexiFormView") : 0;
if (formView) {
changeProperty("pixmapId", (uint)/*! @todo unsafe */id, form);
//old formView->setUnsavedLocalBLOB(m_widget, id);
formView->setUnsavedLocalBLOB(form->selectedWidget(), id);
}
}
KFORMDESIGNER_WIDGET_FACTORY(KexiDBFactory, kexidbwidgets)
#include "kexidbfactory.moc"
|