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
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
|
/***************************************************************************
* Copyright (C) 2003 by Lucijan Busch <[email protected]> *
* Copyright (C) 2004 Cedric Pasteur <[email protected]> *
* This program 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. *
***************************************************************************/
#include <tqlabel.h>
#include <tqpopupmenu.h>
#include <tqcursor.h>
#include <tqradiobutton.h>
#include <tqcheckbox.h>
#include <tqslider.h>
#include <tqobjectlist.h>
#include <tqstring.h>
#include <tqvariant.h>
#include <tqheader.h>
#include <tqdom.h>
#include <tqstyle.h>
#include <tqvaluevector.h>
#include <klineedit.h>
#include <kpushbutton.h>
#include <knuminput.h>
#include <kcombobox.h>
#include <tdelistbox.h>
#include <ktextedit.h>
#include <tdelistview.h>
#include <kprogress.h>
#include <kiconloader.h>
#include <kgenericfactory.h>
#include <tdelocale.h>
#include <kdebug.h>
#include <tdeversion.h>
#if TDE_VERSION < TDE_MAKE_VERSION(3,1,9)
# include <tqdatetimeedit.h>
# define KTimeWidget TQTimeEdit
# define KDateWidget TQDateEdit
# define KDateTimeWidget TQDateTimeEdit
#else
# include <ktimewidget.h>
# include <kdatewidget.h>
# include <kdatetimewidget.h>
#endif
#include "spring.h"
#include "formIO.h"
#include "form.h"
#include "formmanager.h"
#include "widgetlibrary.h"
#include "widgetpropertyset.h"
#include <koproperty/property.h>
#include "stdwidgetfactory.h"
// Some widgets subclass to allow event filtering and some other things
KexiPictureLabel::KexiPictureLabel(const TQPixmap &pix, TQWidget *parent, const char *name)
: TQLabel(parent, name)
{
setPixmap(pix);
setScaledContents(false);
}
bool
KexiPictureLabel::setProperty(const char *name, const TQVariant &value)
{
if(TQString(name) == "pixmap")
resize(value.toPixmap().height(), value.toPixmap().width());
return TQLabel::setProperty(name, value);
}
Line::Line(Qt::Orientation orient, TQWidget *parent, const char *name)
: TQFrame(parent, name)
{
setFrameShadow(Sunken);
if(orient ==Qt::Horizontal)
setFrameShape(HLine);
else
setFrameShape(VLine);
}
void
Line::setOrientation(Qt::Orientation orient)
{
if(orient ==Qt::Horizontal)
setFrameShape(HLine);
else
setFrameShape(VLine);
}
Qt::Orientation
Line::orientation() const
{
if(frameShape() == HLine)
return Qt::Horizontal;
else
return Qt::Vertical;
}
// The factory itself
StdWidgetFactory::StdWidgetFactory(TQObject *parent, const char *, const TQStringList &)
: KFormDesigner::WidgetFactory(parent, "stdwidgets")
{
KFormDesigner::WidgetInfo *wFormWidget = new KFormDesigner::WidgetInfo(this);
wFormWidget->setPixmap("form");
wFormWidget->setClassName("FormWidgetBase");
wFormWidget->setName(i18n("Form"));
wFormWidget->setNamePrefix(i18n("This string will be used to name widgets of this class. It must _not_ contain white "
"spaces and non latin1 characters.", "form"));
wFormWidget->setDescription(i18n("A simple form widget"));
addClass(wFormWidget);
KFormDesigner::WidgetInfo *wCustomWidget = new KFormDesigner::WidgetInfo(this);
wCustomWidget->setPixmap("unknown_widget");
wCustomWidget->setClassName("CustomWidget");
wCustomWidget->setName(i18n("Custom Widget"));
wCustomWidget->setNamePrefix(i18n("This string will be used to name widgets of this class. It must _not_ contain white "
"spaces and non latin1 characters.", "customWidget"));
wCustomWidget->setDescription(i18n("A custom or non-supported widget"));
addClass(wCustomWidget);
KFormDesigner::WidgetInfo *wLabel = new KFormDesigner::WidgetInfo(this);
wLabel->setPixmap("label");
wLabel->setClassName("TQLabel");
wLabel->setName(i18n("Text Label"));
wLabel->setNamePrefix(
i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "label"));
wLabel->setDescription(i18n("A widget to display text"));
addClass(wLabel);
KFormDesigner::WidgetInfo *wPixLabel = new KFormDesigner::WidgetInfo(this);
wPixLabel->setPixmap("pixmaplabel");
wPixLabel->setClassName("KexiPictureLabel");
wPixLabel->setName(i18n("Picture Label"));
//! @todo TQt designer compatibility: maybe use this class when TQLabel has a pixmap set...?
//wPixLabel->addAlternateClassName("TQLabel");
wPixLabel->setSavingName("KexiPictureLabel");
wPixLabel->setNamePrefix(
i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "picture"));
wPixLabel->setDescription(i18n("A widget to display pictures"));
addClass(wPixLabel);
KFormDesigner::WidgetInfo *wLineEdit = new KFormDesigner::WidgetInfo(this);
wLineEdit->setPixmap("lineedit");
wLineEdit->setClassName("KLineEdit");
wLineEdit->addAlternateClassName("TQLineEdit");
wLineEdit->setIncludeFileName("klineedit.h");
wLineEdit->setName(i18n("Line Edit"));
wLineEdit->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.", "lineEdit"));
wLineEdit->setDescription(i18n("A widget to input text"));
addClass(wLineEdit);
KFormDesigner::WidgetInfo *wSpring = new KFormDesigner::WidgetInfo(this);
wSpring->setPixmap("spring");
wSpring->setClassName("Spring");
wSpring->setName(i18n("Spring"));
wSpring->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.", "spring"));
wSpring->setDescription(i18n("A spring to place between widgets"));
addClass(wSpring);
KFormDesigner::WidgetInfo *wPushButton = new KFormDesigner::WidgetInfo(this);
wPushButton->setPixmap("button");
wPushButton->setClassName("KPushButton");
wPushButton->addAlternateClassName("TQPushButton");
wPushButton->setIncludeFileName("kpushbutton.h");
wPushButton->setName(i18n("Push Button"));
wPushButton->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"));
wPushButton->setDescription(i18n("A simple push button to execute actions"));
addClass(wPushButton);
KFormDesigner::WidgetInfo *wRadioButton = new KFormDesigner::WidgetInfo(this);
wRadioButton->setPixmap("radio");
wRadioButton->setClassName("TQRadioButton");
wRadioButton->setName(i18n("Option Button"));
wRadioButton->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.", "optionButton"));
wRadioButton->setDescription(i18n("An option button with text or pixmap label"));
addClass(wRadioButton);
KFormDesigner::WidgetInfo *wCheckBox = new KFormDesigner::WidgetInfo(this);
wCheckBox->setPixmap("check");
wCheckBox->setClassName("TQCheckBox");
wCheckBox->setName(i18n("Check Box"));
wCheckBox->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"));
wCheckBox->setDescription(i18n("A check box with text or pixmap label"));
addClass(wCheckBox);
KFormDesigner::WidgetInfo *wSpinBox = new KFormDesigner::WidgetInfo(this);
wSpinBox->setPixmap("spin");
wSpinBox->setClassName("KIntSpinBox");
wSpinBox->addAlternateClassName("TQSpinBox");
wSpinBox->setIncludeFileName("knuminput.h");
wSpinBox->setName(i18n("Spin Box"));
wSpinBox->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.", "spinBox"));
wSpinBox->setDescription(i18n("A spin box widget"));
addClass(wSpinBox);
KFormDesigner::WidgetInfo *wComboBox = new KFormDesigner::WidgetInfo(this);
wComboBox->setPixmap("combo");
wComboBox->setClassName("KComboBox");
wComboBox->addAlternateClassName("TQComboBox");
wComboBox->setIncludeFileName("kcombobox.h");
wComboBox->setName(i18n("Combo Box"));
wComboBox->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"));
wComboBox->setDescription(i18n("A combo box widget"));
addClass(wComboBox);
KFormDesigner::WidgetInfo *wListBox = new KFormDesigner::WidgetInfo(this);
wListBox->setPixmap("listbox");
wListBox->setClassName("TDEListBox");
wListBox->addAlternateClassName("TQListBox");
wListBox->setIncludeFileName("tdelistbox.h");
wListBox->setName(i18n("List Box"));
wListBox->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.", "listBox"));
wListBox->setDescription(i18n("A simple list widget"));
addClass(wListBox);
KFormDesigner::WidgetInfo *wTextEdit = new KFormDesigner::WidgetInfo(this);
wTextEdit->setPixmap("textedit");
wTextEdit->setClassName("KTextEdit");
wTextEdit->addAlternateClassName("TQTextEdit");
wTextEdit->setIncludeFileName("ktextedit.h");
wTextEdit->setName(i18n("Text Editor"));
wTextEdit->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"));
wTextEdit->setDescription(i18n("A simple single-page rich text editor"));
addClass(wTextEdit);
KFormDesigner::WidgetInfo *wListView = new KFormDesigner::WidgetInfo(this);
wListView->setPixmap("listview");
wListView->setClassName("TDEListView");
wListView->addAlternateClassName("TQListView");
wListView->setIncludeFileName("tdelistview.h");
wListView->setName(i18n("List View"));
wListView->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.", "listView"));
wListView->setDescription(i18n("A list (or tree) widget"));
addClass(wListView);
KFormDesigner::WidgetInfo *wSlider = new KFormDesigner::WidgetInfo(this);
wSlider->setPixmap("slider");
wSlider->setClassName("TQSlider");
wSlider->setName(i18n("Slider"));
wSlider->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.", "slider"));
wSlider->setDescription(i18n("An horizontal slider"));
addClass(wSlider);
KFormDesigner::WidgetInfo *wProgressBar = new KFormDesigner::WidgetInfo(this);
wProgressBar->setPixmap("progress");
wProgressBar->setClassName("KProgress");
wProgressBar->addAlternateClassName("TQProgressBar");
wProgressBar->setIncludeFileName("kprogress.h");
wProgressBar->setName(i18n("Progress Bar"));
wProgressBar->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.", "progressBar"));
wProgressBar->setDescription(i18n("A progress indicator widget"));
addClass(wProgressBar);
KFormDesigner::WidgetInfo *wLine = new KFormDesigner::WidgetInfo(this);
wLine->setPixmap("line");
wLine->setClassName("Line");
wLine->setName(i18n("Line"));
wLine->setNamePrefix(
i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "line"));
wLine->setDescription(i18n("A line to be used as a separator"));
addClass(wLine);
KFormDesigner::WidgetInfo *wDate = new KFormDesigner::WidgetInfo(this);
wDate->setPixmap("dateedit");
wDate->setClassName("KDateWidget");
#if TDE_VERSION >= TDE_MAKE_VERSION(3,1,9)
wDate->addAlternateClassName("TQDateEdit");
wDate->setIncludeFileName("kdatewidget.h");
#endif
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);
KFormDesigner::WidgetInfo *wTime = new KFormDesigner::WidgetInfo(this);
wTime->setPixmap("timeedit");
wTime->setClassName("KTimeWidget");
#if TDE_VERSION >= TDE_MAKE_VERSION(3,1,9)
wTime->addAlternateClassName("TQTimeEdit");
wTime->setIncludeFileName("ktimewidget.h");
#endif
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);
KFormDesigner::WidgetInfo *wDateTime = new KFormDesigner::WidgetInfo(this);
wDateTime->setPixmap("datetimeedit");
wDateTime->setClassName("KDateTimeWidget");
#if TDE_VERSION >= TDE_MAKE_VERSION(3,1,9)
wDateTime->addAlternateClassName("TQDateTimeEdit");
wDateTime->setIncludeFileName("kdatetimewidget.h");
#endif
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 time and a date"));
addClass(wDateTime);
m_propDesc["toggleButton"] = i18n("Toggle");
m_propDesc["autoRepeat"] = i18n("Auto Repeat");
m_propDesc["autoDefault"] = i18n("Auto Default");
m_propDesc["default"] = i18n("Default");
m_propDesc["flat"] = i18n("Flat");
m_propDesc["echoMode"] =
i18n("Echo mode for Line Edit widget eg. Normal, NoEcho, Password","Echo Mode");
m_propDesc["indent"] = i18n("Indent");
//line
m_propDesc["orientation"] = i18n("Orientation");
//checkbox
m_propDesc["checked"] = i18n("Checked checkbox", "Checked");
m_propDesc["tristate"] = i18n("Tristate checkbox", "Tristate");
//for EchoMode
m_propValDesc["Normal"] = i18n("For Echo Mode", "Normal");
m_propValDesc["NoEcho"] = i18n("For Echo Mode", "No Echo");
m_propValDesc["Password"] = i18n("For Echo Mode", "Password");
//for spring
m_propDesc["sizeType"] = i18n("Size Type");
//for labels
m_propDesc["textFormat"] = i18n("Text Format");
m_propValDesc["PlainText"] = i18n("For Text Format", "Plain");
m_propValDesc["RichText"] = i18n("For Text Format", "Hypertext");
m_propValDesc["AutoText"] = i18n("For Text Format", "Auto");
m_propValDesc["LogText"] = i18n("For Text Format", "Log");
//KTextEdit
m_propDesc["tabStopWidth"] = i18n("Tab Stop Width");
m_propDesc["tabChangesFocus"] = i18n("Tab Changes Focus");
m_propDesc["wrapPolicy"] = i18n("Word Wrap Policy");
m_propValDesc["AtWordBoundary"] = i18n("For Word Wrap Policy", "At Word Boundary");
m_propValDesc["Anywhere"] = i18n("For Word Wrap Policy", "Anywhere");
m_propValDesc["AtWordOrDocumentBoundary"] = i18n("For Word Wrap Policy", "At Word Boundary If Possible");
m_propDesc["wordWrap"] = i18n("Word Wrapping");
m_propDesc["wrapColumnOrWidth"] = i18n("Word Wrap Position");
m_propValDesc["NoWrap"] = i18n("For Word Wrap Position", "None");
m_propValDesc["WidgetWidth"] = i18n("For Word Wrap Position", "Widget's Width");
m_propValDesc["FixedPixelWidth"] = i18n("For Word Wrap Position", "In Pixels");
m_propValDesc["FixedColumnWidth"] = i18n("For Word Wrap Position", "In Columns");
m_propDesc["linkUnderline"] = i18n("Links Underlined");
//internal props
setInternalProperty("Line","orientationSelectionPopup","1");
setInternalProperty("Line","orientationSelectionPopup:horizontalIcon","line_horizontal");
setInternalProperty("Line","orientationSelectionPopup:verticalIcon","line_vertical");
setInternalProperty("Line","orientationSelectionPopup:horizontalText",i18n("Insert &Horizontal Line"));
setInternalProperty("Line","orientationSelectionPopup:verticalText",i18n("Insert &Vertical Line"));
setInternalProperty("Spring","orientationSelectionPopup","1");
setInternalProperty("Spring","orientationSelectionPopup:horizontalIcon","spring");
setInternalProperty("Spring","orientationSelectionPopup:verticalIcon","spring_vertical");
setInternalProperty("Spring","orientationSelectionPopup:horizontalText",i18n("Insert &Horizontal Spring"));
setInternalProperty("Spring","orientationSelectionPopup:verticalText",i18n("Insert &Vertical Spring"));
}
StdWidgetFactory::~StdWidgetFactory()
{
}
TQWidget*
StdWidgetFactory::createWidget(const TQCString &c, TQWidget *p, const char *n,
KFormDesigner::Container *container, int options)
{
TQWidget *w=0;
TQString text( container->form()->library()->textForWidgetName(n, c) );
const bool designMode = options & KFormDesigner::WidgetFactory::DesignViewMode;
if(c == "TQLabel")
w = new TQLabel(text, p, n);
else if(c == "KexiPictureLabel")
w = new KexiPictureLabel(DesktopIcon("image-x-generic"), p, n);
else if(c == "KLineEdit")
{
w = new KLineEdit(p, n);
if (designMode)
w->setCursor(TQCursor(TQt::ArrowCursor));
}
else if(c == "KPushButton")
w = new KPushButton(/*i18n("Button")*/text, p, n);
else if(c == "TQRadioButton")
w = new TQRadioButton(/*i18n("Radio Button")*/text, p, n);
else if(c == "TQCheckBox")
w = new TQCheckBox(/*i18n("Check Box")*/text, p, n);
else if(c == "KIntSpinBox")
w = new KIntSpinBox(p, n);
else if(c == "KComboBox")
w = new KComboBox(p, n);
else if(c == "TDEListBox")
w = new TDEListBox(p, n);
else if(c == "KTextEdit")
w = new KTextEdit(/*i18n("Enter your text here")*/text, TQString(), p, n);
else if(c == "TDEListView")
{
w = new TDEListView(p, n);
if(container->form()->interactiveMode())
((TDEListView*)w)->addColumn(i18n("Column 1"));
((TDEListView*)w)->setRootIsDecorated(true);
}
else if(c == "TQSlider")
w = new TQSlider(Qt::Horizontal, p, n);
else if(c == "KProgress")
w = new KProgress(p, n);
else if(c == "KDateWidget")
w = new KDateWidget(TQDate::currentDate(), p, n);
else if(c == "KTimeWidget")
w = new KTimeWidget(TQTime::currentTime(), p, n);
else if(c == "KDateTimeWidget")
w = new KDateTimeWidget(TQDateTime::currentDateTime(), p, n);
else if(c == "Line")
w = new Line(options & WidgetFactory::VerticalOrientation ? Qt::Vertical : Qt::Horizontal, p, n);
else if(c == "Spring") {
w = new Spring(p, n);
if (0 == (options & WidgetFactory::AnyOrientation))
static_cast<Spring*>(w)->setOrientation(
(options & WidgetFactory::VerticalOrientation) ? Qt::Vertical : Qt::Horizontal);
}
if(w)
return w;
kdDebug() << "WARNING :: w == 0 " << endl;
return 0;
}
bool
StdWidgetFactory::previewWidget(const TQCString &classname, TQWidget *widget, KFormDesigner::Container *)
{
if(classname == "Spring") {
((Spring*)widget)->setPreviewMode();
return true;
}
return false;
}
bool
StdWidgetFactory::createMenuActions(const TQCString &classname, TQWidget *, TQPopupMenu *menu,
KFormDesigner::Container *)
{
if((classname == "TQLabel") || (classname == "KTextEdit"))
{
menu->insertItem(SmallIconSet("edit"), i18n("Edit Rich Text"), this, TQT_SLOT(editText()));
return true;
}
else if(classname == "TDEListView")
{
menu->insertItem(SmallIconSet("edit"), i18n("Edit Listview Contents"), this, TQT_SLOT(editListContents()));
return true;
}
return false;
}
bool
StdWidgetFactory::startEditing(const TQCString &classname, TQWidget *w, KFormDesigner::Container *container)
{
setWidget(w, container);
// m_container = container;
if(classname == "KLineEdit")
{
KLineEdit *lineedit = static_cast<KLineEdit*>(w);
createEditor(classname, lineedit->text(), lineedit, container, lineedit->geometry(), lineedit->alignment(), true);
return true;
}
else if(classname == "TQLabel")
{
TQLabel *label = static_cast<TQLabel*>(w);
if(label->textFormat() == RichText)
{
//m_widget = w;
// setWidget(w, container);
editText();
}
else
createEditor(classname, label->text(), label, container, label->geometry(), label->alignment());
return true;
}
else if(classname == "KPushButton")
{
KPushButton *push = static_cast<KPushButton*>(w);
TQRect r = w->style().subRect(TQStyle::SR_PushButtonContents, w);
TQRect editorRect = TQRect(push->x() + r.x(), push->y() + r.y(), r.width(), r.height());
//r.setX(r.x() + 5);
//r.setY(r.y() + 5);
//r.setWidth(r.width()-10);
//r.setHeight(r.height() - 10);
createEditor(classname, push->text(), push, container, editorRect, TQt::AlignCenter, false, false, TQt::PaletteButton);
return true;
}
else if(classname == "TQRadioButton")
{
TQRadioButton *radio = static_cast<TQRadioButton*>(w);
TQRect r = w->style().subRect(TQStyle::SR_RadioButtonContents, w);
TQRect editorRect = TQRect(radio->x() + r.x(), radio->y() + r.y(), r.width(), r.height());
createEditor(classname, radio->text(), radio, container, editorRect, TQt::AlignAuto);
return true;
}
else if(classname == "TQCheckBox")
{
TQCheckBox *check = static_cast<TQCheckBox*>(w);
//TQRect r(check->geometry());
//r.setX(r.x() + 20);
TQRect r = w->style().subRect(TQStyle::SR_CheckBoxContents, w);
TQRect editorRect = TQRect(check->x() + r.x(), check->y() + r.y(), r.width(), r.height());
createEditor(classname, check->text(), check, container, editorRect, TQt::AlignAuto);
return true;
}
else if((classname == "KComboBox") || (classname == "TDEListBox"))
{
TQStringList list;
if(classname == "TDEListBox")
{
TDEListBox *listbox = (TDEListBox*)w;
for(uint i=0; i < listbox->count(); i++)
list.append(listbox->text(i));
}
else if(classname == "KComboBox")
{
KComboBox *combo = (KComboBox*)w;
for(int i=0; i < combo->count(); i++)
list.append(combo->text(i));
}
if(editList(w, list))
{
if(classname == "TDEListBox")
{
((TDEListBox*)w)->clear();
((TDEListBox*)w)->insertStringList(list);
}
else if(classname == "KComboBox")
{
((KComboBox*)w)->clear();
((KComboBox*)w)->insertStringList(list);
}
}
return true;
}
else if((classname == "KTextEdit") || (classname == "KDateTimeWidget") || (classname == "KTimeWidget") ||
(classname == "KDateWidget") || (classname == "KIntSpinBox")) {
disableFilter(w, container);
return true;
}
return false;
}
bool
StdWidgetFactory::clearWidgetContent(const TQCString &classname, TQWidget *w)
{
if(classname == "KLineEdit")
((KLineEdit*)w)->clear();
else if(classname == "TDEListBox")
((TDEListBox*)w)->clear();
else if(classname == "TDEListView")
((TDEListView*)w)->clear();
else if(classname == "KComboBox")
((KComboBox*)w)->clear();
else if(classname == "KTextEdit")
((KTextEdit*)w)->clear();
else
return false;
return true;
}
bool
StdWidgetFactory::changeText(const TQString &text)
{
TQCString n = WidgetFactory::widget()->className();
TQWidget *w = WidgetFactory::widget();
if(n == "KIntSpinBox")
((KIntSpinBox*)w)->setValue(text.toInt());
else
changeProperty("text", text, m_container->form());
/* By-hand method not needed as sizeHint() can do that for us
TQFontMetrics fm = w->fontMetrics();
TQSize s(fm.width( text ), fm.height());
int width;
if(n == "TQLabel") // labels are resized to fit the text
{
w->resize(w->sizeHint());
WidgetFactory::m_editor->resize(w->size());
return;
}
// and other widgets are just enlarged if needed
else if(n == "KPushButton")
width = w->style().sizeFromContents( TQStyle::CT_PushButton, w, s).width();
else if(n == "TQCheckBox")
width = w->style().sizeFromContents( TQStyle::CT_CheckBox, w, s).width();
else if(n == "TQRadioButton")
width = w->style().sizeFromContents( TQStyle::CT_RadioButton, w, s).width();
else
return;
int width = w->sizeHint().width();*/
#if 0 //not needed here, size hint is used on creation in InsertWidgetCommand::execute()
if(w->width() < width)
{
w->resize(width, w->height() );
//WidgetFactory::m_editor->resize(w->size());
}
#endif
return true;
}
void
StdWidgetFactory::resizeEditor(TQWidget *editor, TQWidget *widget, const TQCString &classname)
{
TQSize s = widget->size();
TQPoint p = widget->pos();
TQRect r;
if(classname == "TQRadioButton")
{
r = widget->style().subRect(TQStyle::SR_RadioButtonContents, widget);
p += r.topLeft();
s.setWidth(r.width());
}
else if(classname == "TQCheckBox")
{
r = widget->style().subRect(TQStyle::SR_CheckBoxContents, widget);
p += r.topLeft();
s.setWidth(r.width());
}
else if(classname == "KPushButton")
{
r = widget->style().subRect(TQStyle::SR_PushButtonContents, widget);
p += r.topLeft();
s = r.size();
}
editor->resize(s);
editor->move(p);
}
bool
StdWidgetFactory::saveSpecialProperty(const TQCString &classname, const TQString &name, const TQVariant &, TQWidget *w, TQDomElement &parentNode, TQDomDocument &domDoc)
{
if(name == "list_items" && classname == "KComboBox")
{
KComboBox *combo = (KComboBox*)w;
for(int i=0; i < combo->count(); i++)
{
TQDomElement item = domDoc.createElement("item");
KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "text", combo->text(i));
parentNode.appendChild(item);
}
return true;
}
else if(name == "list_items" && classname == "TDEListBox")
{
TDEListBox *listbox = (TDEListBox*)w;
for(uint i=0; i < listbox->count(); i++)
{
TQDomElement item = domDoc.createElement("item");
KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "text", listbox->text(i));
parentNode.appendChild(item);
}
return true;
}
else if(name == "list_contents" && classname == "TDEListView")
{
TDEListView *listview = (TDEListView*)w;
// First we save the columns
for(int i = 0; i < listview->columns(); i++)
{
TQDomElement item = domDoc.createElement("column");
KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "text", listview->columnText(i));
KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "width", listview->columnWidth(i));
KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "resizable", listview->header()->isResizeEnabled(i));
KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "clickable", listview->header()->isClickEnabled(i));
KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "fullwidth", listview->header()->isStretchEnabled(i));
parentNode.appendChild(item);
}
// Then we save the list view items
TQListViewItem *item = listview->firstChild();
while(item)
{
saveListItem(item, parentNode, domDoc);
item = item->nextSibling();
}
return true;
}
return false;
}
void
StdWidgetFactory::saveListItem(TQListViewItem *item, TQDomNode &parentNode, TQDomDocument &domDoc)
{
TQDomElement element = domDoc.createElement("item");
parentNode.appendChild(element);
// We save the text of each column
for(int i = 0; i < item->listView()->columns(); i++)
KFormDesigner::FormIO::savePropertyElement(element, domDoc, "property", "text", item->text(i));
// Then we save every sub items
TQListViewItem *child = item->firstChild();
while(child)
{
saveListItem(child, element, domDoc);
child = child->nextSibling();
}
}
bool
StdWidgetFactory::readSpecialProperty(const TQCString &classname, TQDomElement &node, TQWidget *w, KFormDesigner::ObjectTreeItem *)
{
TQString tag = node.tagName();
TQString name = node.attribute("name");
if((tag == "item") && (classname == "KComboBox"))
{
KComboBox *combo = (KComboBox*)w;
TQVariant val = KFormDesigner::FormIO::readPropertyValue(node.firstChild().firstChild(), TQT_TQOBJECT(w), name);
if(val.canCast(TQVariant::Pixmap))
combo->insertItem(val.toPixmap());
else
combo->insertItem(val.toString());
return true;
}
if((tag == "item") && (classname == "TDEListBox"))
{
TDEListBox *listbox = (TDEListBox*)w;
TQVariant val = KFormDesigner::FormIO::readPropertyValue(node.firstChild().firstChild(), TQT_TQOBJECT(w), name);
if(val.canCast(TQVariant::Pixmap))
listbox->insertItem(val.toPixmap());
else
listbox->insertItem(val.toString());
return true;
}
if((tag == "column") && (classname == "TDEListView"))
{
TDEListView *listview = (TDEListView*)w;
int id=0;
for(TQDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling())
{
TQString prop = n.toElement().attribute("name");
TQVariant val = KFormDesigner::FormIO::readPropertyValue(n.firstChild(), TQT_TQOBJECT(w), name);
if(prop == "text")
id = listview->addColumn(val.toString());
else if(prop == "width")
listview->setColumnWidth(id, val.toInt());
else if(prop == "resizable")
listview->header()->setResizeEnabled(val.toBool(), id);
else if(prop == "clickable")
listview->header()->setClickEnabled(val.toBool(), id);
else if(prop == "fullwidth")
listview->header()->setStretchEnabled(val.toBool(), id);
}
return true;
}
else if((tag == "item") && (classname == "TDEListView"))
{
TDEListView *listview = (TDEListView*)w;
readListItem(node, 0, listview);
return true;
}
return false;
}
void
StdWidgetFactory::readListItem(TQDomElement &node, TQListViewItem *parent, TDEListView *listview)
{
TQListViewItem *item;
if(parent)
item = new TDEListViewItem(parent);
else
item = new TDEListViewItem(listview);
// We need to move the item at the end of the list
TQListViewItem *last;
if(parent)
last = parent->firstChild();
else
last = listview->firstChild();
while(last->nextSibling())
last = last->nextSibling();
item->moveItem(last);
int i = 0;
for(TQDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling())
{
TQDomElement childEl = n.toElement();
TQString prop = childEl.attribute("name");
TQString tag = childEl.tagName();
// We read sub items
if(tag == "item")
{
item->setOpen(true);
readListItem(childEl, item, listview);
}
// and column texts
else if((tag == "property") && (prop == "text"))
{
TQVariant val = KFormDesigner::FormIO::readPropertyValue(n.firstChild(), TQT_TQOBJECT(listview), "item");
item->setText(i, val.toString());
i++;
}
}
}
bool
StdWidgetFactory::isPropertyVisibleInternal(const TQCString &classname,
TQWidget *w, const TQCString &property, bool isTopLevel)
{
bool ok = true;
if(classname == "FormWidgetBase")
{
if(property == "iconText"
|| property == "geometry" /*nonsense for toplevel widget*/)
return false;
}
else if (classname == "CustomWidget")
{
}
else if(classname == "Spring")
{
return Spring::isPropertyVisible(property);
}
else if(classname == "KexiPictureLabel")
{
if((property == "text") || (property == "indent") || (property == "textFormat") || (property == "font") || (property == "alignment"))
return false;
}
else if(classname == "TQLabel")
{
if(property == "pixmap")
return false;
}
else if(classname == "KLineEdit")
{
if(property == "vAlign")
return false;
}
else if(classname == "KTextEdit")
ok = m_showAdvancedProperties ||
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 == "Line")
{
if((property == "frameShape") || (property == "font") || (property == "margin"))
return false;
}
else if(classname=="TQCheckBox")
{
ok = m_showAdvancedProperties || (property != "autoRepeat");
}
else if(classname=="TQRadioButton")
{
ok = m_showAdvancedProperties || (property != "autoRepeat");
}
else if(classname=="KPushButton")
{
//! @todo reenable autoDefault / default if the top level window is dialog...
ok = m_showAdvancedProperties || (property != "autoDefault" && property != "default");
}
return ok && WidgetFactory::isPropertyVisibleInternal(classname, w, property, isTopLevel);
}
TQValueList<TQCString>
StdWidgetFactory::autoSaveProperties(const TQCString &classname)
{
TQValueList<TQCString> l;
if(classname == "TQLabel")
l << "text";
if(classname == "KPushButton")
l << "text";
else if(classname == "KexiPictureLabel")
l << "pixmap";
else if(classname == "KComboBox")
l << "list_items";
else if(classname == "TDEListBox")
l << "list_items";
else if(classname == "TDEListView")
l << "list_contents";
else if(classname == "Line")
l << "orientation";
else if(classname == "KTimeWidget")
l << "time";
else if(classname == "KDateWidget")
l << "date";
else if(classname == "KDateTimeWidget")
l << "dateTime";
else if(classname == "Spring")
l << "sizeType" << "orientation";
else if(classname == "KTextEdit")
l << "textFormat" << "text";
return l;
}
void
StdWidgetFactory::editText()
{
TQCString classname = widget()->className();
TQString text;
if(classname == "KTextEdit")
text = ((KTextEdit*)widget())->text();
else if(classname == "TQLabel")
text = ((TQLabel*)widget())->text();
if(editRichText(widget(), text))
{
changeProperty("textFormat", "RichText", m_container->form());
changeProperty("text", text, m_container->form());
}
if(classname == "TQLabel")
widget()->resize(widget()->sizeHint());
}
void
StdWidgetFactory::editListContents()
{
if(widget()->inherits("TQListView"))
editListView((TQListView*)widget());
}
void
StdWidgetFactory::setPropertyOptions( KFormDesigner::WidgetPropertySet& buf, const KFormDesigner::WidgetInfo& info, TQWidget *w )
{
Q_UNUSED( info );
Q_UNUSED( w );
if (buf.contains("indent")) {
buf["indent"].setOption("min", -1);
buf["indent"].setOption("minValueText", i18n("default indent value", "default"));
}
}
KFORMDESIGNER_WIDGET_FACTORY(StdWidgetFactory, stdwidgets)
#include "stdwidgetfactory.moc"
|