kexi

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