kexi

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