stdwidgetfactory.cpp
1/***************************************************************************
2 * Copyright (C) 2003 by Lucijan Busch <lucijan@kde.org> *
3 * Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU Library General Public License as *
6 * published by the Free Software Foundation; either version 2 of the *
7 * License, or (at your option) any later version. *
8 ***************************************************************************/
9
10#include <tqlabel.h>
11#include <tqpopupmenu.h>
12#include <tqcursor.h>
13#include <tqradiobutton.h>
14#include <tqcheckbox.h>
15#include <tqslider.h>
16#include <tqobjectlist.h>
17#include <tqstring.h>
18#include <tqvariant.h>
19#include <tqheader.h>
20#include <tqdom.h>
21#include <tqstyle.h>
22#include <tqvaluevector.h>
23
24#include <klineedit.h>
25#include <kpushbutton.h>
26#include <knuminput.h>
27#include <kcombobox.h>
28#include <tdelistbox.h>
29#include <ktextedit.h>
30#include <tdelistview.h>
31#include <kprogress.h>
32#include <kiconloader.h>
33#include <kgenericfactory.h>
34#include <tdelocale.h>
35#include <kdebug.h>
36#include <tdeversion.h>
37
38#if TDE_VERSION < TDE_MAKE_VERSION(3,1,9)
39# include <tqdatetimeedit.h>
40# define KTimeWidget TQTimeEdit
41# define KDateWidget TQDateEdit
42# define KDateTimeWidget TQDateTimeEdit
43#else
44# include <ktimewidget.h>
45# include <kdatewidget.h>
46# include <kdatetimewidget.h>
47#endif
48
49#include "spring.h"
50#include "formIO.h"
51#include "form.h"
52#include "formmanager.h"
53#include "widgetlibrary.h"
54#include "widgetpropertyset.h"
55#include <koproperty/property.h>
56
57#include "stdwidgetfactory.h"
58
59// Some widgets subclass to allow event filtering and some other things
60KexiPictureLabel::KexiPictureLabel(const TQPixmap &pix, TQWidget *parent, const char *name)
61 : TQLabel(parent, name)
62{
63 setPixmap(pix);
64 setScaledContents(false);
65}
66
67bool
68KexiPictureLabel::setProperty(const char *name, const TQVariant &value)
69{
70 if(TQString(name) == "pixmap")
71 resize(value.toPixmap().height(), value.toPixmap().width());
72 return TQLabel::setProperty(name, value);
73}
74
75Line::Line(TQt::Orientation orient, TQWidget *parent, const char *name)
76 : TQFrame(parent, name)
77{
78 setFrameShadow(Sunken);
79 if(orient ==TQt::Horizontal)
80 setFrameShape(HLine);
81 else
82 setFrameShape(VLine);
83}
84
85void
86Line::setOrientation(TQt::Orientation orient)
87{
88 if(orient ==TQt::Horizontal)
89 setFrameShape(HLine);
90 else
91 setFrameShape(VLine);
92}
93
94TQt::Orientation
95Line::orientation() const
96{
97 if(frameShape() == HLine)
98 return TQt::Horizontal;
99 else
100 return TQt::Vertical;
101}
102
103// The factory itself
104
105StdWidgetFactory::StdWidgetFactory(TQObject *parent, const char *, const TQStringList &)
106 : KFormDesigner::WidgetFactory(parent, "stdwidgets")
107{
109 wFormWidget->setPixmap("form");
110 wFormWidget->setClassName("FormWidgetBase");
111 wFormWidget->setName(i18n("Form"));
112 wFormWidget->setNamePrefix(i18n("This string will be used to name widgets of this class. It must _not_ contain white "
113 "spaces and non latin1 characters.", "form"));
114 wFormWidget->setDescription(i18n("A simple form widget"));
115 addClass(wFormWidget);
116
117 KFormDesigner::WidgetInfo *wCustomWidget = new KFormDesigner::WidgetInfo(this);
118 wCustomWidget->setPixmap("unknown_widget");
119 wCustomWidget->setClassName("CustomWidget");
120 wCustomWidget->setName(i18n("Custom Widget"));
121 wCustomWidget->setNamePrefix(i18n("This string will be used to name widgets of this class. It must _not_ contain white "
122 "spaces and non latin1 characters.", "customWidget"));
123 wCustomWidget->setDescription(i18n("A custom or non-supported widget"));
124 addClass(wCustomWidget);
125
127 wLabel->setPixmap("label");
128 wLabel->setClassName("TQLabel");
129 wLabel->setName(i18n("Text Label"));
130 wLabel->setNamePrefix(
131 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"));
132 wLabel->setDescription(i18n("A widget to display text"));
133 addClass(wLabel);
134
136 wPixLabel->setPixmap("pixmaplabel");
137 wPixLabel->setClassName("KexiPictureLabel");
138 wPixLabel->setName(i18n("Picture Label"));
140 //wPixLabel->addAlternateClassName("TQLabel");
141 wPixLabel->setSavingName("KexiPictureLabel");
142 wPixLabel->setNamePrefix(
143 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"));
144 wPixLabel->setDescription(i18n("A widget to display pictures"));
145 addClass(wPixLabel);
146
148 wLineEdit->setPixmap("lineedit");
149 wLineEdit->setClassName("KLineEdit");
150 wLineEdit->addAlternateClassName("TQLineEdit");
151 wLineEdit->setIncludeFileName("klineedit.h");
152 wLineEdit->setName(i18n("Line Edit"));
153 wLineEdit->setNamePrefix(
154 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"));
155 wLineEdit->setDescription(i18n("A widget to input text"));
156 addClass(wLineEdit);
157
159 wSpring->setPixmap("spring");
160 wSpring->setClassName("Spring");
161 wSpring->setName(i18n("Spring"));
162 wSpring->setNamePrefix(
163 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"));
164 wSpring->setDescription(i18n("A spring to place between widgets"));
165 addClass(wSpring);
166
168 wPushButton->setPixmap("button");
169 wPushButton->setClassName("KPushButton");
170 wPushButton->addAlternateClassName("TQPushButton");
171 wPushButton->setIncludeFileName("kpushbutton.h");
172 wPushButton->setName(i18n("Push Button"));
173 wPushButton->setNamePrefix(
174 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"));
175 wPushButton->setDescription(i18n("A simple push button to execute actions"));
176 addClass(wPushButton);
177
179 wRadioButton->setPixmap("radio");
180 wRadioButton->setClassName("TQRadioButton");
181 wRadioButton->setName(i18n("Option Button"));
182 wRadioButton->setNamePrefix(
183 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"));
184 wRadioButton->setDescription(i18n("An option button with text or pixmap label"));
185 addClass(wRadioButton);
186
188 wCheckBox->setPixmap("check");
189 wCheckBox->setClassName("TQCheckBox");
190 wCheckBox->setName(i18n("Check Box"));
191 wCheckBox->setNamePrefix(
192 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"));
193 wCheckBox->setDescription(i18n("A check box with text or pixmap label"));
194 addClass(wCheckBox);
195
197 wSpinBox->setPixmap("spin");
198 wSpinBox->setClassName("KIntSpinBox");
199 wSpinBox->addAlternateClassName("TQSpinBox");
200 wSpinBox->setIncludeFileName("knuminput.h");
201 wSpinBox->setName(i18n("Spin Box"));
202 wSpinBox->setNamePrefix(
203 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"));
204 wSpinBox->setDescription(i18n("A spin box widget"));
205 addClass(wSpinBox);
206
208 wComboBox->setPixmap("combo");
209 wComboBox->setClassName("KComboBox");
210 wComboBox->addAlternateClassName("TQComboBox");
211 wComboBox->setIncludeFileName("kcombobox.h");
212 wComboBox->setName(i18n("Combo Box"));
213 wComboBox->setNamePrefix(
214 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"));
215 wComboBox->setDescription(i18n("A combo box widget"));
216 addClass(wComboBox);
217
219 wListBox->setPixmap("listbox");
220 wListBox->setClassName("TDEListBox");
221 wListBox->addAlternateClassName("TQListBox");
222 wListBox->setIncludeFileName("tdelistbox.h");
223 wListBox->setName(i18n("List Box"));
224 wListBox->setNamePrefix(
225 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"));
226 wListBox->setDescription(i18n("A simple list widget"));
227 addClass(wListBox);
228
230 wTextEdit->setPixmap("textedit");
231 wTextEdit->setClassName("KTextEdit");
232 wTextEdit->addAlternateClassName("TQTextEdit");
233 wTextEdit->setIncludeFileName("ktextedit.h");
234 wTextEdit->setName(i18n("Text Editor"));
235 wTextEdit->setNamePrefix(
236 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"));
237 wTextEdit->setDescription(i18n("A simple single-page rich text editor"));
238 addClass(wTextEdit);
239
241 wListView->setPixmap("listview");
242 wListView->setClassName("TDEListView");
243 wListView->addAlternateClassName("TQListView");
244 wListView->setIncludeFileName("tdelistview.h");
245 wListView->setName(i18n("List View"));
246 wListView->setNamePrefix(
247 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"));
248 wListView->setDescription(i18n("A list (or tree) widget"));
249 addClass(wListView);
250
252 wSlider->setPixmap("slider");
253 wSlider->setClassName("TQSlider");
254 wSlider->setName(i18n("Slider"));
255 wSlider->setNamePrefix(
256 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"));
257 wSlider->setDescription(i18n("An horizontal slider"));
258 addClass(wSlider);
259
261 wProgressBar->setPixmap("progress");
262 wProgressBar->setClassName("KProgress");
263 wProgressBar->addAlternateClassName("TQProgressBar");
264 wProgressBar->setIncludeFileName("kprogress.h");
265 wProgressBar->setName(i18n("Progress Bar"));
266 wProgressBar->setNamePrefix(
267 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"));
268 wProgressBar->setDescription(i18n("A progress indicator widget"));
269 addClass(wProgressBar);
270
272 wLine->setPixmap("line");
273 wLine->setClassName("Line");
274 wLine->setName(i18n("Line"));
275 wLine->setNamePrefix(
276 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"));
277 wLine->setDescription(i18n("A line to be used as a separator"));
278 addClass(wLine);
279
281 wDate->setPixmap("dateedit");
282 wDate->setClassName("KDateWidget");
283#if TDE_VERSION >= TDE_MAKE_VERSION(3,1,9)
284 wDate->addAlternateClassName("TQDateEdit");
285 wDate->setIncludeFileName("kdatewidget.h");
286#endif
287 wDate->setName(i18n("Date Widget"));
288 wDate->setNamePrefix(
289 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"));
290 wDate->setDescription(i18n("A widget to input and display a date"));
291 addClass(wDate);
292
294 wTime->setPixmap("timeedit");
295 wTime->setClassName("KTimeWidget");
296#if TDE_VERSION >= TDE_MAKE_VERSION(3,1,9)
297 wTime->addAlternateClassName("TQTimeEdit");
298 wTime->setIncludeFileName("ktimewidget.h");
299#endif
300 wTime->setName(i18n("Time Widget"));
301 wTime->setNamePrefix(
302 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"));
303 wTime->setDescription(i18n("A widget to input and display a time"));
304 addClass(wTime);
305
307 wDateTime->setPixmap("datetimeedit");
308 wDateTime->setClassName("KDateTimeWidget");
309#if TDE_VERSION >= TDE_MAKE_VERSION(3,1,9)
310 wDateTime->addAlternateClassName("TQDateTimeEdit");
311 wDateTime->setIncludeFileName("kdatetimewidget.h");
312#endif
313 wDateTime->setName(i18n("Date/Time Widget"));
314 wDateTime->setNamePrefix(
315 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"));
316 wDateTime->setDescription(i18n("A widget to input and display a time and a date"));
317 addClass(wDateTime);
318
319 m_propDesc["toggleButton"] = i18n("Toggle");
320 m_propDesc["autoRepeat"] = i18n("Auto Repeat");
321 m_propDesc["autoDefault"] = i18n("Auto Default");
322 m_propDesc["default"] = i18n("Default");
323 m_propDesc["flat"] = i18n("Flat");
324 m_propDesc["echoMode"] =
325 i18n("Echo mode for Line Edit widget eg. Normal, NoEcho, Password","Echo Mode");
326 m_propDesc["indent"] = i18n("Indent");
327 //line
328 m_propDesc["orientation"] = i18n("Orientation");
329 //checkbox
330 m_propDesc["checked"] = i18n("Checked checkbox", "Checked");
331 m_propDesc["tristate"] = i18n("Tristate checkbox", "Tristate");
332
333 //for EchoMode
334 m_propValDesc["Normal"] = i18n("For Echo Mode", "Normal");
335 m_propValDesc["NoEcho"] = i18n("For Echo Mode", "No Echo");
336 m_propValDesc["Password"] = i18n("For Echo Mode", "Password");
337
338 //for spring
339 m_propDesc["sizeType"] = i18n("Size Type");
340
341 //for labels
342 m_propDesc["textFormat"] = i18n("Text Format");
343 m_propValDesc["PlainText"] = i18n("For Text Format", "Plain");
344 m_propValDesc["RichText"] = i18n("For Text Format", "Hypertext");
345 m_propValDesc["AutoText"] = i18n("For Text Format", "Auto");
346 m_propValDesc["LogText"] = i18n("For Text Format", "Log");
347
348 //KTextEdit
349 m_propDesc["tabStopWidth"] = i18n("Tab Stop Width");
350 m_propDesc["tabChangesFocus"] = i18n("Tab Changes Focus");
351 m_propDesc["wrapPolicy"] = i18n("Word Wrap Policy");
352 m_propValDesc["AtWordBoundary"] = i18n("For Word Wrap Policy", "At Word Boundary");
353 m_propValDesc["Anywhere"] = i18n("For Word Wrap Policy", "Anywhere");
354 m_propValDesc["AtWordOrDocumentBoundary"] = i18n("For Word Wrap Policy", "At Word Boundary If Possible");
355 m_propDesc["wordWrap"] = i18n("Word Wrapping");
356 m_propDesc["wrapColumnOrWidth"] = i18n("Word Wrap Position");
357 m_propValDesc["NoWrap"] = i18n("For Word Wrap Position", "None");
358 m_propValDesc["WidgetWidth"] = i18n("For Word Wrap Position", "Widget's Width");
359 m_propValDesc["FixedPixelWidth"] = i18n("For Word Wrap Position", "In Pixels");
360 m_propValDesc["FixedColumnWidth"] = i18n("For Word Wrap Position", "In Columns");
361 m_propDesc["linkUnderline"] = i18n("Links Underlined");
362
363 //internal props
364 setInternalProperty("Line","orientationSelectionPopup","1");
365 setInternalProperty("Line","orientationSelectionPopup:horizontalIcon","line_horizontal");
366 setInternalProperty("Line","orientationSelectionPopup:verticalIcon","line_vertical");
367 setInternalProperty("Line","orientationSelectionPopup:horizontalText",i18n("Insert &Horizontal Line"));
368 setInternalProperty("Line","orientationSelectionPopup:verticalText",i18n("Insert &Vertical Line"));
369 setInternalProperty("Spring","orientationSelectionPopup","1");
370 setInternalProperty("Spring","orientationSelectionPopup:horizontalIcon","spring");
371 setInternalProperty("Spring","orientationSelectionPopup:verticalIcon","spring_vertical");
372 setInternalProperty("Spring","orientationSelectionPopup:horizontalText",i18n("Insert &Horizontal Spring"));
373 setInternalProperty("Spring","orientationSelectionPopup:verticalText",i18n("Insert &Vertical Spring"));
374}
375
376StdWidgetFactory::~StdWidgetFactory()
377{
378}
379
380TQWidget*
381StdWidgetFactory::createWidget(const TQCString &c, TQWidget *p, const char *n,
382 KFormDesigner::Container *container, int options)
383{
384 TQWidget *w=0;
385 TQString text( container->form()->library()->textForWidgetName(n, c) );
386 const bool designMode = options & KFormDesigner::WidgetFactory::DesignViewMode;
387
388 if(c == "TQLabel")
389 w = new TQLabel(text, p, n);
390 else if(c == "KexiPictureLabel")
391 w = new KexiPictureLabel(DesktopIcon("image-x-generic"), p, n);
392
393 else if(c == "KLineEdit")
394 {
395 w = new KLineEdit(p, n);
396 if (designMode)
397 w->setCursor(TQCursor(TQt::ArrowCursor));
398 }
399 else if(c == "KPushButton")
400 w = new KPushButton(/*i18n("Button")*/text, p, n);
401
402 else if(c == "TQRadioButton")
403 w = new TQRadioButton(/*i18n("Radio Button")*/text, p, n);
404
405 else if(c == "TQCheckBox")
406 w = new TQCheckBox(/*i18n("Check Box")*/text, p, n);
407
408 else if(c == "KIntSpinBox")
409 w = new KIntSpinBox(p, n);
410
411 else if(c == "KComboBox")
412 w = new KComboBox(p, n);
413
414 else if(c == "TDEListBox")
415 w = new TDEListBox(p, n);
416
417 else if(c == "KTextEdit")
418 w = new KTextEdit(/*i18n("Enter your text here")*/text, TQString(), p, n);
419
420 else if(c == "TDEListView")
421 {
422 w = new TDEListView(p, n);
423 if(container->form()->interactiveMode())
424 ((TDEListView*)w)->addColumn(i18n("Column 1"));
425 ((TDEListView*)w)->setRootIsDecorated(true);
426 }
427 else if(c == "TQSlider")
428 w = new TQSlider(TQt::Horizontal, p, n);
429
430 else if(c == "KProgress")
431 w = new KProgress(p, n);
432
433 else if(c == "KDateWidget")
434 w = new KDateWidget(TQDate::currentDate(), p, n);
435
436 else if(c == "KTimeWidget")
437 w = new KTimeWidget(TQTime::currentTime(), p, n);
438
439 else if(c == "KDateTimeWidget")
440 w = new KDateTimeWidget(TQDateTime::currentDateTime(), p, n);
441
442 else if(c == "Line")
443 w = new Line(options & WidgetFactory::VerticalOrientation ? TQt::Vertical : TQt::Horizontal, p, n);
444
445 else if(c == "Spring") {
446 w = new Spring(p, n);
447 if (0 == (options & WidgetFactory::AnyOrientation))
448 static_cast<Spring*>(w)->setOrientation(
449 (options & WidgetFactory::VerticalOrientation) ? TQt::Vertical : TQt::Horizontal);
450 }
451
452 if(w)
453 return w;
454
455 kdDebug() << "WARNING :: w == 0 " << endl;
456 return 0;
457}
458
459bool
460StdWidgetFactory::previewWidget(const TQCString &classname, TQWidget *widget, KFormDesigner::Container *)
461{
462 if(classname == "Spring") {
463 ((Spring*)widget)->setPreviewMode();
464 return true;
465 }
466 return false;
467}
468
469bool
470StdWidgetFactory::createMenuActions(const TQCString &classname, TQWidget *, TQPopupMenu *menu,
472{
473 if((classname == "TQLabel") || (classname == "KTextEdit"))
474 {
475 menu->insertItem(SmallIconSet("edit"), i18n("Edit Rich Text"), this, TQ_SLOT(editText()));
476 return true;
477 }
478 else if(classname == "TDEListView")
479 {
480 menu->insertItem(SmallIconSet("edit"), i18n("Edit Listview Contents"), this, TQ_SLOT(editListContents()));
481 return true;
482 }
483
484 return false;
485}
486
487bool
488StdWidgetFactory::startEditing(const TQCString &classname, TQWidget *w, KFormDesigner::Container *container)
489{
490 setWidget(w, container);
491// m_container = container;
492 if(classname == "KLineEdit")
493 {
494 KLineEdit *lineedit = static_cast<KLineEdit*>(w);
495 createEditor(classname, lineedit->text(), lineedit, container, lineedit->geometry(), lineedit->alignment(), true);
496 return true;
497 }
498 else if(classname == "TQLabel")
499 {
500 TQLabel *label = static_cast<TQLabel*>(w);
501 if(label->textFormat() == RichText)
502 {
503 //m_widget = w;
504// setWidget(w, container);
505 editText();
506 }
507 else
508 createEditor(classname, label->text(), label, container, label->geometry(), label->alignment());
509 return true;
510 }
511 else if(classname == "KPushButton")
512 {
513 KPushButton *push = static_cast<KPushButton*>(w);
514 TQRect r = w->style().subRect(TQStyle::SR_PushButtonContents, w);
515 TQRect editorRect = TQRect(push->x() + r.x(), push->y() + r.y(), r.width(), r.height());
516 //r.setX(r.x() + 5);
517 //r.setY(r.y() + 5);
518 //r.setWidth(r.width()-10);
519 //r.setHeight(r.height() - 10);
520 createEditor(classname, push->text(), push, container, editorRect, TQt::AlignCenter, false, false, TQt::PaletteButton);
521 return true;
522 }
523 else if(classname == "TQRadioButton")
524 {
525 TQRadioButton *radio = static_cast<TQRadioButton*>(w);
526 TQRect r = w->style().subRect(TQStyle::SR_RadioButtonContents, w);
527 TQRect editorRect = TQRect(radio->x() + r.x(), radio->y() + r.y(), r.width(), r.height());
528 createEditor(classname, radio->text(), radio, container, editorRect, TQt::AlignAuto);
529 return true;
530 }
531 else if(classname == "TQCheckBox")
532 {
533 TQCheckBox *check = static_cast<TQCheckBox*>(w);
534 //TQRect r(check->geometry());
535 //r.setX(r.x() + 20);
536 TQRect r = w->style().subRect(TQStyle::SR_CheckBoxContents, w);
537 TQRect editorRect = TQRect(check->x() + r.x(), check->y() + r.y(), r.width(), r.height());
538 createEditor(classname, check->text(), check, container, editorRect, TQt::AlignAuto);
539 return true;
540 }
541 else if((classname == "KComboBox") || (classname == "TDEListBox"))
542 {
543 TQStringList list;
544 if(classname == "TDEListBox")
545 {
546 TDEListBox *listbox = (TDEListBox*)w;
547 for(uint i=0; i < listbox->count(); i++)
548 list.append(listbox->text(i));
549 }
550 else if(classname == "KComboBox")
551 {
552 KComboBox *combo = (KComboBox*)w;
553 for(int i=0; i < combo->count(); i++)
554 list.append(combo->text(i));
555 }
556
557 if(editList(w, list))
558 {
559 if(classname == "TDEListBox")
560 {
561 ((TDEListBox*)w)->clear();
562 ((TDEListBox*)w)->insertStringList(list);
563 }
564 else if(classname == "KComboBox")
565 {
566 ((KComboBox*)w)->clear();
567 ((KComboBox*)w)->insertStringList(list);
568 }
569 }
570 return true;
571 }
572 else if((classname == "KTextEdit") || (classname == "KDateTimeWidget") || (classname == "KTimeWidget") ||
573 (classname == "KDateWidget") || (classname == "KIntSpinBox")) {
574 disableFilter(w, container);
575 return true;
576 }
577 return false;
578}
579
580bool
581StdWidgetFactory::clearWidgetContent(const TQCString &classname, TQWidget *w)
582{
583 if(classname == "KLineEdit")
584 ((KLineEdit*)w)->clear();
585 else if(classname == "TDEListBox")
586 ((TDEListBox*)w)->clear();
587 else if(classname == "TDEListView")
588 ((TDEListView*)w)->clear();
589 else if(classname == "KComboBox")
590 ((KComboBox*)w)->clear();
591 else if(classname == "KTextEdit")
592 ((KTextEdit*)w)->clear();
593 else
594 return false;
595 return true;
596}
597
598bool
599StdWidgetFactory::changeText(const TQString &text)
600{
601 TQCString n = WidgetFactory::widget()->className();
602 TQWidget *w = WidgetFactory::widget();
603 if(n == "KIntSpinBox")
604 ((KIntSpinBox*)w)->setValue(text.toInt());
605 else
606 changeProperty("text", text, m_container->form());
607
608 /* By-hand method not needed as sizeHint() can do that for us
609 TQFontMetrics fm = w->fontMetrics();
610 TQSize s(fm.width( text ), fm.height());
611 int width;
612 if(n == "TQLabel") // labels are resized to fit the text
613 {
614 w->resize(w->sizeHint());
615 WidgetFactory::m_editor->resize(w->size());
616 return;
617 }
618 // and other widgets are just enlarged if needed
619 else if(n == "KPushButton")
620 width = w->style().sizeFromContents( TQStyle::CT_PushButton, w, s).width();
621 else if(n == "TQCheckBox")
622 width = w->style().sizeFromContents( TQStyle::CT_CheckBox, w, s).width();
623 else if(n == "TQRadioButton")
624 width = w->style().sizeFromContents( TQStyle::CT_RadioButton, w, s).width();
625 else
626 return;
627 int width = w->sizeHint().width();*/
628
629#if 0 //not needed here, size hint is used on creation in InsertWidgetCommand::execute()
630 if(w->width() < width)
631 {
632 w->resize(width, w->height() );
633 //WidgetFactory::m_editor->resize(w->size());
634 }
635#endif
636 return true;
637}
638
639void
640StdWidgetFactory::resizeEditor(TQWidget *editor, TQWidget *widget, const TQCString &classname)
641{
642 TQSize s = widget->size();
643 TQPoint p = widget->pos();
644 TQRect r;
645
646 if(classname == "TQRadioButton")
647 {
648 r = widget->style().subRect(TQStyle::SR_RadioButtonContents, widget);
649 p += r.topLeft();
650 s.setWidth(r.width());
651 }
652 else if(classname == "TQCheckBox")
653 {
654 r = widget->style().subRect(TQStyle::SR_CheckBoxContents, widget);
655 p += r.topLeft();
656 s.setWidth(r.width());
657 }
658 else if(classname == "KPushButton")
659 {
660 r = widget->style().subRect(TQStyle::SR_PushButtonContents, widget);
661 p += r.topLeft();
662 s = r.size();
663 }
664
665 editor->resize(s);
666 editor->move(p);
667}
668
669bool
670StdWidgetFactory::saveSpecialProperty(const TQCString &classname, const TQString &name, const TQVariant &, TQWidget *w, TQDomElement &parentNode, TQDomDocument &domDoc)
671{
672 if(name == "list_items" && classname == "KComboBox")
673 {
674 KComboBox *combo = (KComboBox*)w;
675 for(int i=0; i < combo->count(); i++)
676 {
677 TQDomElement item = domDoc.createElement("item");
678 KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "text", combo->text(i));
679 parentNode.appendChild(item);
680 }
681 return true;
682 }
683 else if(name == "list_items" && classname == "TDEListBox")
684 {
685 TDEListBox *listbox = (TDEListBox*)w;
686 for(uint i=0; i < listbox->count(); i++)
687 {
688 TQDomElement item = domDoc.createElement("item");
689 KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "text", listbox->text(i));
690 parentNode.appendChild(item);
691 }
692 return true;
693 }
694 else if(name == "list_contents" && classname == "TDEListView")
695 {
696 TDEListView *listview = (TDEListView*)w;
697 // First we save the columns
698 for(int i = 0; i < listview->columns(); i++)
699 {
700 TQDomElement item = domDoc.createElement("column");
701 KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "text", listview->columnText(i));
702 KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "width", listview->columnWidth(i));
703 KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "resizable", listview->header()->isResizeEnabled(i));
704 KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "clickable", listview->header()->isClickEnabled(i));
705 KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "fullwidth", listview->header()->isStretchEnabled(i));
706 parentNode.appendChild(item);
707 }
708
709 // Then we save the list view items
710 TQListViewItem *item = listview->firstChild();
711 while(item)
712 {
713 saveListItem(item, parentNode, domDoc);
714 item = item->nextSibling();
715 }
716 return true;
717 }
718
719 return false;
720}
721
722void
723StdWidgetFactory::saveListItem(TQListViewItem *item, TQDomNode &parentNode, TQDomDocument &domDoc)
724{
725 TQDomElement element = domDoc.createElement("item");
726 parentNode.appendChild(element);
727
728 // We save the text of each column
729 for(int i = 0; i < item->listView()->columns(); i++)
730 KFormDesigner::FormIO::savePropertyElement(element, domDoc, "property", "text", item->text(i));
731
732 // Then we save every sub items
733 TQListViewItem *child = item->firstChild();
734 while(child)
735 {
736 saveListItem(child, element, domDoc);
737 child = child->nextSibling();
738 }
739}
740
741bool
742StdWidgetFactory::readSpecialProperty(const TQCString &classname, TQDomElement &node, TQWidget *w, KFormDesigner::ObjectTreeItem *)
743{
744 TQString tag = node.tagName();
745 TQString name = node.attribute("name");
746
747 if((tag == "item") && (classname == "KComboBox"))
748 {
749 KComboBox *combo = (KComboBox*)w;
750 TQVariant val = KFormDesigner::FormIO::readPropertyValue(node.firstChild().firstChild(), w, name);
751 if(val.canCast(TQVariant::Pixmap))
752 combo->insertItem(val.toPixmap());
753 else
754 combo->insertItem(val.toString());
755 return true;
756 }
757
758 if((tag == "item") && (classname == "TDEListBox"))
759 {
760 TDEListBox *listbox = (TDEListBox*)w;
761 TQVariant val = KFormDesigner::FormIO::readPropertyValue(node.firstChild().firstChild(), w, name);
762 if(val.canCast(TQVariant::Pixmap))
763 listbox->insertItem(val.toPixmap());
764 else
765 listbox->insertItem(val.toString());
766 return true;
767 }
768
769 if((tag == "column") && (classname == "TDEListView"))
770 {
771 TDEListView *listview = (TDEListView*)w;
772 int id=0;
773 for(TQDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling())
774 {
775 TQString prop = n.toElement().attribute("name");
776 TQVariant val = KFormDesigner::FormIO::readPropertyValue(n.firstChild(), w, name);
777 if(prop == "text")
778 id = listview->addColumn(val.toString());
779 else if(prop == "width")
780 listview->setColumnWidth(id, val.toInt());
781 else if(prop == "resizable")
782 listview->header()->setResizeEnabled(val.toBool(), id);
783 else if(prop == "clickable")
784 listview->header()->setClickEnabled(val.toBool(), id);
785 else if(prop == "fullwidth")
786 listview->header()->setStretchEnabled(val.toBool(), id);
787 }
788 return true;
789 }
790 else if((tag == "item") && (classname == "TDEListView"))
791 {
792 TDEListView *listview = (TDEListView*)w;
793 readListItem(node, 0, listview);
794 return true;
795 }
796
797 return false;
798}
799
800void
801StdWidgetFactory::readListItem(TQDomElement &node, TQListViewItem *parent, TDEListView *listview)
802{
803 TQListViewItem *item;
804 if(parent)
805 item = new TDEListViewItem(parent);
806 else
807 item = new TDEListViewItem(listview);
808
809 // We need to move the item at the end of the list
810 TQListViewItem *last;
811 if(parent)
812 last = parent->firstChild();
813 else
814 last = listview->firstChild();
815
816 while(last->nextSibling())
817 last = last->nextSibling();
818 item->moveItem(last);
819
820 int i = 0;
821 for(TQDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling())
822 {
823 TQDomElement childEl = n.toElement();
824 TQString prop = childEl.attribute("name");
825 TQString tag = childEl.tagName();
826
827 // We read sub items
828 if(tag == "item")
829 {
830 item->setOpen(true);
831 readListItem(childEl, item, listview);
832 }
833 // and column texts
834 else if((tag == "property") && (prop == "text"))
835 {
836 TQVariant val = KFormDesigner::FormIO::readPropertyValue(n.firstChild(), listview, "item");
837 item->setText(i, val.toString());
838 i++;
839 }
840 }
841}
842
843bool
845 TQWidget *w, const TQCString &property, bool isTopLevel)
846{
847 bool ok = true;
848 if(classname == "FormWidgetBase")
849 {
850 if(property == "iconText"
851 || property == "geometry" /*nonsense for toplevel widget*/)
852 return false;
853 }
854 else if (classname == "CustomWidget")
855 {
856 }
857 else if(classname == "Spring")
858 {
859 return Spring::isPropertyVisible(property);
860 }
861 else if(classname == "KexiPictureLabel")
862 {
863 if((property == "text") || (property == "indent") || (property == "textFormat") || (property == "font") || (property == "alignment"))
864 return false;
865 }
866 else if(classname == "TQLabel")
867 {
868 if(property == "pixmap")
869 return false;
870 }
871 else if(classname == "KLineEdit")
872 {
873 if(property == "vAlign")
874 return false;
875 }
876 else if(classname == "KTextEdit")
878 property!="undoDepth"
879 && property!="undoRedoEnabled" //always true!
880 && property!="dragAutoScroll" //always true!
881 && property!="overwriteMode" //always false!
882 && property!="resizePolicy"
883 && property!="autoFormatting" //too complex
884#ifdef KEXI_NO_UNFINISHED
885 && property!="paper"
886#endif
887 ;
888 else if(classname == "Line")
889 {
890 if((property == "frameShape") || (property == "font") || (property == "margin"))
891 return false;
892 }
893 else if(classname=="TQCheckBox")
894 {
895 ok = m_showAdvancedProperties || (property != "autoRepeat");
896 }
897 else if(classname=="TQRadioButton")
898 {
899 ok = m_showAdvancedProperties || (property != "autoRepeat");
900 }
901 else if(classname=="KPushButton")
902 {
904 ok = m_showAdvancedProperties || (property != "autoDefault" && property != "default");
905 }
906 return ok && WidgetFactory::isPropertyVisibleInternal(classname, w, property, isTopLevel);
907}
908
909TQValueList<TQCString>
910StdWidgetFactory::autoSaveProperties(const TQCString &classname)
911{
912 TQValueList<TQCString> l;
913
914 if(classname == "TQLabel")
915 l << "text";
916 if(classname == "KPushButton")
917 l << "text";
918 else if(classname == "KexiPictureLabel")
919 l << "pixmap";
920 else if(classname == "KComboBox")
921 l << "list_items";
922 else if(classname == "TDEListBox")
923 l << "list_items";
924 else if(classname == "TDEListView")
925 l << "list_contents";
926 else if(classname == "Line")
927 l << "orientation";
928 else if(classname == "KTimeWidget")
929 l << "time";
930 else if(classname == "KDateWidget")
931 l << "date";
932 else if(classname == "KDateTimeWidget")
933 l << "dateTime";
934 else if(classname == "Spring")
935 l << "sizeType" << "orientation";
936 else if(classname == "KTextEdit")
937 l << "textFormat" << "text";
938
939 return l;
940}
941
942void
943StdWidgetFactory::editText()
944{
945 TQCString classname = widget()->className();
946 TQString text;
947 if(classname == "KTextEdit")
948 text = ((KTextEdit*)widget())->text();
949 else if(classname == "TQLabel")
950 text = ((TQLabel*)widget())->text();
951
952 if(editRichText(widget(), text))
953 {
954 changeProperty("textFormat", "RichText", m_container->form());
955 changeProperty("text", text, m_container->form());
956 }
957
958 if(classname == "TQLabel")
959 widget()->resize(widget()->sizeHint());
960}
961
962void
963StdWidgetFactory::editListContents()
964{
965 if(widget()->inherits("TQListView"))
966 editListView((TQListView*)widget());
967}
968
969void
970StdWidgetFactory::setPropertyOptions( KFormDesigner::WidgetPropertySet& buf, const KFormDesigner::WidgetInfo& info, TQWidget *w )
971{
972 Q_UNUSED( info );
973 Q_UNUSED( w );
974
975 if (buf.contains("indent")) {
976 buf["indent"].setOption("min", -1);
977 buf["indent"].setOption("minValueText", i18n("default indent value", "default"));
978 }
979}
980
981KFORMDESIGNER_WIDGET_FACTORY(StdWidgetFactory, stdwidgets)
982
983#include "stdwidgetfactory.moc"
984
This class makes a container out of any TQWidget.
Definition container.h:74
Form * form() const
Definition container.h:91
bool interactiveMode() const
Definition form.h:218
WidgetLibrary * library() const
Definition form.h:147
An item representing a widget Holds the properties of a widget (classname, name, parent,...
Definition objecttree.h:59
TQMap< TQCString, TQString > m_propDesc
i18n stuff
bool editRichText(TQWidget *w, TQString &text)
void disableFilter(TQWidget *w, Container *container)
void createEditor(const TQCString &classname, const TQString &text, TQWidget *w, Container *container, TQRect geometry, int align, bool useFrame=false, bool multiLine=false, BackgroundMode background=TQt::NoBackground)
void changeProperty(const char *name, const TQVariant &value, Form *form)
@ DesignViewMode
create widget in design view mode, otherwise preview mode
bool editList(TQWidget *w, TQStringList &list)
void setInternalProperty(const TQCString &classname, const TQCString &property, const TQString &value)
void editListView(TQListView *listview)
This class holds properties of widget classes provided by a factory.
void setSavingName(const TQString &saveName)
void addAlternateClassName(const TQCString &alternateName, bool override=false)
void setIncludeFileName(const TQString &name)
Factory for all basic widgets, including Spring (not containers)
virtual bool createMenuActions(const TQCString &classname, TQWidget *w, TQPopupMenu *menu, KFormDesigner::Container *container)
virtual bool readSpecialProperty(const TQCString &classname, TQDomElement &node, TQWidget *w, KFormDesigner::ObjectTreeItem *item)
virtual bool saveSpecialProperty(const TQCString &classname, const TQString &name, const TQVariant &value, TQWidget *w, TQDomElement &parentNode, TQDomDocument &parent)
virtual TQValueList< TQCString > autoSaveProperties(const TQCString &classname)
virtual bool previewWidget(const TQCString &classname, TQWidget *widget, KFormDesigner::Container *container)
virtual TQWidget * createWidget(const TQCString &c, TQWidget *p, const char *n, KFormDesigner::Container *container, int options=DefaultOptions)
Creates a widget (and if needed a KFormDesigner::Container)
StdWidgetFactory(TQObject *parent, const char *name, const TQStringList &args)
virtual void setPropertyOptions(KFormDesigner::WidgetPropertySet &buf, const KFormDesigner::WidgetInfo &info, TQWidget *w)
virtual bool startEditing(const TQCString &classname, TQWidget *w, KFormDesigner::Container *container)
virtual bool changeText(const TQString &newText)
virtual void resizeEditor(TQWidget *editor, TQWidget *widget, const TQCString &classname)
virtual bool isPropertyVisibleInternal(const TQCString &classname, TQWidget *w, const TQCString &property, bool isTopLevel)