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#if TDE_VERSION >= TDE_MAKE_VERSION(3,1,9)
214 KexiDataAwareWidgetInfo *wDate = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KDateWidget");
215#else
216 KexiDataAwareWidgetInfo *wDate = new KexiDataAwareWidgetInfo(this, "stdwidgets", "TQDateEdit");
217#endif
218 wDate->setPixmap("dateedit");
219 wDate->setClassName("KexiDBDateEdit");
220 wDate->addAlternateClassName("TQDateEdit", true);//override
221 wDate->addAlternateClassName("KDateWidget", true);//override
222 wDate->setName(i18n("Date Widget"));
223 wDate->setNamePrefix(
224 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"));
225 wDate->setDescription(i18n("A widget to input and display a date"));
226 addClass(wDate);
227
228#if TDE_VERSION >= TDE_MAKE_VERSION(3,1,9)
229 KexiDataAwareWidgetInfo *wTime = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KTimeWidget");
230#else
231 KexiDataAwareWidgetInfo *wTime = new KexiDataAwareWidgetInfo(this, "stdwidgets", "TQTimeEdit");
232#endif
233 wTime->setPixmap("timeedit");
234 wTime->setClassName("KexiDBTimeEdit");
235 wTime->addAlternateClassName("TQTimeEdit", true);//override
236 wTime->addAlternateClassName("KTimeWidget", true);//override
237 wTime->setName(i18n("Time Widget"));
238 wTime->setNamePrefix(
239 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"));
240 wTime->setDescription(i18n("A widget to input and display a time"));
241 addClass(wTime);
242
243#if TDE_VERSION >= TDE_MAKE_VERSION(3,1,9)
244 KexiDataAwareWidgetInfo *wDateTime = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KDateTimeWidget");
245#else
246 KexiDataAwareWidgetInfo *wDateTime = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KDateTimeWidget");
247#endif
248 wDateTime->setPixmap("datetimeedit");
249 wDateTime->setClassName("KexiDBDateTimeEdit");
250 wDateTime->addAlternateClassName("TQDateTimeEdit", true);//override
251 wDateTime->addAlternateClassName("KDateTimeWidget", true);//override
252 wDateTime->setName(i18n("Date/Time Widget"));
253 wDateTime->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.", "dateTimeWidget"));
255 wDateTime->setDescription(i18n("A widget to input and display a date and time"));
256 addClass(wDateTime);
257*/
258
259/* KexiDataAwareWidgetInfo *wIntSpinBox = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KIntSpinBox");
260 wIntSpinBox->setPixmap("spin");
261 wIntSpinBox->setClassName("KexiDBIntSpinBox");
262 wIntSpinBox->addAlternateClassName("TQSpinBox", true);
263 wIntSpinBox->addAlternateClassName("KIntSpinBox", true);
264 wIntSpinBox->setName(i18n("Integer Number Spin Box"));
265 wIntSpinBox->setNamePrefix(
266 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"));
267 wIntSpinBox->setDescription(i18n("A spin box widget to input and display integer numbers"));
268 addClass(wIntSpinBox);
269
270 KexiDataAwareWidgetInfo *wDoubleSpinBox = new KexiDataAwareWidgetInfo(this, "stdwidgets");
271 wDoubleSpinBox->setPixmap("spin");
272 wDoubleSpinBox->setClassName("KexiDBDoubleSpinBox");
273 wDoubleSpinBox->addAlternateClassName("KDoubleSpinBox", true);
274 wDoubleSpinBox->setName(i18n("Floating-point Number Spin Box"));
275 wDoubleSpinBox->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.", "dblSpinBox"));
277 wDoubleSpinBox->setDescription(i18n("A spin box widget to input and display floating-point numbers"));
278 addClass(wDoubleSpinBox);*/
279
280 // inherited
282 this, "stdwidgets", "KPushButton");
283 wi->addAlternateClassName("KexiPushButton");
284 wi->setName(i18n("Command Button"));
285 wi->setNamePrefix(
286 i18n("Widget name. This string will be used to name widgets of this class. "
287 "It must _not_ contain white spaces and non latin1 characters.", "button"));
288 wi->setDescription(i18n("A command button to execute actions"));
289 addClass(wi);
290
291 m_propDesc["dataSource"] = i18n("Data Source");
292 m_propDesc["formName"] = i18n("Form Name");
293 m_propDesc["onClickAction"] = i18n("On Click");
294 m_propDesc["onClickActionOption"] = i18n("On Click Option");
295 m_propDesc["autoTabStops"] = i18n("Auto Tab Order");
296 m_propDesc["shadowEnabled"] = i18n("Shadow Enabled");
297 m_propDesc["on"] = i18n("On: button", "On");
298
299 m_propDesc["widgetType"] = i18n("Editor Type");
300 //for autofield's type: inherit i18n from KexiDB
301 m_propValDesc["Auto"] = i18n("AutoField editor's type", "Auto");
302 m_propValDesc["Text"] = KexiDB::Field::typeName(KexiDB::Field::Text);
303 m_propValDesc["Integer"] = KexiDB::Field::typeName(KexiDB::Field::Integer);
304 m_propValDesc["Double"] = KexiDB::Field::typeName(KexiDB::Field::Double);
305 m_propValDesc["Boolean"] = KexiDB::Field::typeName(KexiDB::Field::Boolean);
306 m_propValDesc["Date"] = KexiDB::Field::typeName(KexiDB::Field::Date);
307 m_propValDesc["Time"] = KexiDB::Field::typeName(KexiDB::Field::Time);
308 m_propValDesc["DateTime"] = KexiDB::Field::typeName(KexiDB::Field::DateTime);
309 m_propValDesc["MultiLineText"] = i18n("AutoField editor's type", "Multiline Text");
310 m_propValDesc["ComboBox"] = i18n("AutoField editor's type", "Drop-Down List");
311 m_propValDesc["Image"] = i18n("AutoField editor's type", "Image");
312
313// m_propDesc["labelCaption"] = i18n("Label Text");
314 m_propDesc["autoCaption"] = i18n("Auto Label");
315 m_propDesc["foregroundLabelColor"] = i18n("Label Text Color");
316 m_propDesc["backgroundLabelColor"] = i18n("(a property name, keep the text narrow!)",
317 "Label Background\nColor");
318
319 m_propDesc["labelPosition"] = i18n("Label Position");
320 m_propValDesc["Left"] = i18n("Label Position", "Left");
321 m_propValDesc["Top"] = i18n("Label Position", "Top");
322 m_propValDesc["NoLabel"] = i18n("Label Position", "No Label");
323
324 m_propDesc["sizeInternal"] = i18n("Size");
325// m_propDesc["pixmap"] = i18n("Image");
326 m_propDesc["pixmapId"] = i18n("Image");
327 m_propDesc["scaledContents"] = i18n("Scaled Contents");
328 m_propDesc["keepAspectRatio"] = i18n("Keep Aspect Ratio (short)", "Keep Ratio");
329
330 //hide classes that are replaced by db-aware versions
331 hideClass("KexiPictureLabel");
332 hideClass("KComboBox");
333
334 //used in labels, frames...
335 m_propDesc["frameColor"] = i18n("Frame Color");
336 m_propDesc["dropDownButtonVisible"] =
337 i18n("Drop-Down Button for Image Box Visible (a property name, keep the text narrow!)",
338 "Drop-Down\nButton Visible");
339
340 //for checkbox
341 m_propValDesc["TristateDefault"] = i18n("Tristate checkbox, default", "Default");
342 m_propValDesc["TristateOn"] = i18n("Tristate checkbox, yes", "Yes");
343 m_propValDesc["TristateOff"] = i18n("Tristate checkbox, no", "No");
344
345 //for combobox
346 m_propDesc["editable"] = i18n("Editable combobox", "Editable");
347}
348
349KexiDBFactory::~KexiDBFactory()
350{
351}
352
353TQWidget*
354KexiDBFactory::createWidget(const TQCString &c, TQWidget *p, const char *n,
355 KFormDesigner::Container *container, int options)
356{
357 kexipluginsdbg << "KexiDBFactory::createWidget() " << this << endl;
358
359 TQWidget *w=0;
360 TQString text( container->form()->library()->textForWidgetName(n, c) );
361 const bool designMode = options & KFormDesigner::WidgetFactory::DesignViewMode;
362
363 if(c == "KexiDBSubForm")
364 w = new KexiDBSubForm(container->form(), p, n);
365 else if(c == "KexiDBLineEdit")
366 {
367 w = new KexiDBLineEdit(p, n);
368 if (designMode)
369 w->setCursor(TQCursor(TQt::ArrowCursor));
370 }
371 else if(c == "KexiDBTextEdit")
372 {
373 w = new KexiDBTextEdit(p, n);
374 if (designMode)
375 w->setCursor(TQCursor(TQt::ArrowCursor));
376 }
377 else if(c == "TQFrame" || c == "KexiFrame")
378 {
379 w = new KexiFrame(p, n);
380 new KFormDesigner::Container(container, w, container);
381 }
382 else if(c == "KexiDBLabel")
383 w = new KexiDBLabel(text, p, n);
384#ifndef KEXI_NO_IMAGEBOX_WIDGET
385 else if(c == "KexiDBImageBox") {
386 w = new KexiDBImageBox(designMode, p, n);
387 connect(w, TQ_SIGNAL(idChanged(long)), this, TQ_SLOT(slotImageBoxIdChanged(long)));
388 }
389#endif
390#ifndef KEXI_NO_AUTOFIELD_WIDGET
391 else if(c == "KexiDBAutoField")
392 w = new KexiDBAutoField(p, n, designMode);
393#endif
394 else if(c == "KexiDBCheckBox")
395 w = new KexiDBCheckBox(text, p, n);
396 else if(c == "KexiDBComboBox")
397 w = new KexiDBComboBox(p, n, designMode);
398/* else if(c == "KexiDBTimeEdit")
399 w = new KexiDBTimeEdit(TQTime::currentTime(), p, n);
400 else if(c == "KexiDBDateEdit")
401 w = new KexiDBDateEdit(TQDate::currentDate(), p, n);
402 else if(c == "KexiDBDateTimeEdit")
403 w = new KexiDBDateTimeEdit(TQDateTime::currentDateTime(), p, n);*/
404// else if(c == "KexiDBIntSpinBox")
405// w = new KexiDBIntSpinBox(p, n);
406// else if(c == "KexiDBDoubleSpinBox")
407// w = new KexiDBDoubleSpinBox(p, n);
408 else if(c == "KPushButton" || c == "KexiPushButton")
409 w = new KexiPushButton(text, p, n);
410
411 return w;
412}
413
414bool
415KexiDBFactory::createMenuActions(const TQCString &classname, TQWidget *w, TQPopupMenu *menu,
417{
418 if(classname == "TQPushButton" || classname == "KPushButton" || classname == "KexiPushButton")
419 {
421 m_assignAction->plug( menu );
422 return true;
423 }
424 else if(classname == "KexiDBImageBox")
425 {
426 KexiDBImageBox *imageBox = static_cast<KexiDBImageBox*>(w);
427 imageBox->contextMenu()->updateActionsAvailability();
428 TDEActionCollection *ac = imageBox->contextMenu()->actionCollection();
429 TDEPopupMenu *subMenu = new TDEPopupMenu();
431 menu->insertItem(i18n("&Image"), subMenu);
432 ac->action("insert")->plug(subMenu);
433 ac->action("file_save_as")->plug(subMenu);
434 subMenu->insertSeparator();
435 ac->action("edit_cut")->plug(subMenu);
436 ac->action("edit_copy")->plug(subMenu);
437 ac->action("edit_paste")->plug(subMenu);
438 ac->action("delete")->plug(subMenu);
439 if (ac->action("properties")) {
440 subMenu->insertSeparator();
441 ac->action("properties")->plug(subMenu);
442 }
443 }
444 return false;
445}
446
447void
448KexiDBFactory::createCustomActions(TDEActionCollection* col)
449{
450 //this will create shared instance action for design mode (special collection is provided)
451 m_assignAction = new TDEAction( i18n("&Assign Action..."), SmallIconSet("form_action"),
452 0, 0, 0, col, "widget_assign_action");
453}
454
455bool
456KexiDBFactory::startEditing(const TQCString &classname, TQWidget *w, KFormDesigner::Container *container)
457{
458 m_container = container;
459 if(classname == "KexiDBLineEdit")
460 {
463 KLineEdit *lineedit = static_cast<KLineEdit*>(w);
464 createEditor(classname, lineedit->text(), lineedit, container,
465 lineedit->geometry(), lineedit->alignment(), true);
466 return true;
467 }
468 if(classname == "KexiDBTextEdit")
469 {
472 KTextEdit *textedit = static_cast<KTextEdit*>(w);
473 createEditor(classname, textedit->text(), textedit, container,
474 textedit->geometry(), textedit->alignment(), true, true);
475 //copy a few properties
476 KTextEdit *ed = dynamic_cast<KTextEdit *>( editor(w) );
477 ed->setWrapPolicy(textedit->wrapPolicy());
478 ed->setWordWrap(textedit->wordWrap());
479 ed->setTabStopWidth(textedit->tabStopWidth());
480 ed->setWrapColumnOrWidth(textedit->wrapColumnOrWidth());
481 ed->setLinkUnderline(textedit->linkUnderline());
482 ed->setTextFormat(textedit->textFormat());
483 ed->setHScrollBarMode(textedit->hScrollBarMode());
484 ed->setVScrollBarMode(textedit->vScrollBarMode());
485 return true;
486 }
487 else if ( classname == "KexiDBLabel" ) {
488 KexiDBLabel *label = static_cast<KexiDBLabel*>(w);
489 m_widget = w;
490 if(label->textFormat() == RichText)
491 {
492 TQString text = label->text();
493 if ( editRichText( label, text ) )
494 {
495 changeProperty( "textFormat", "RichText", container->form() );
496 changeProperty( "text", text, container->form() );
497 }
498
499 if ( classname == "KexiDBLabel" )
500 w->resize(w->sizeHint());
501 }
502 else
503 {
504 createEditor(classname, label->text(), label, container,
505 label->geometry(), label->alignment(),
506 false, label->alignment() & TQt::WordBreak /*multiline*/);
507 }
508 return true;
509 }
510 else if (classname == "KexiDBSubForm") {
511 // open the form in design mode
512 KexiMainWindow *mainWin = KexiUtils::findParent<KexiMainWindow>(w, "KexiMainWindow");
513 KexiDBSubForm *subform = static_cast<KexiDBSubForm*>(w);
514 if(mainWin) {
515 bool openingCancelled;
516 mainWin->openObject("kexi/form", subform->formName(), Kexi::DesignViewMode,
517 openingCancelled);
518 }
519 return true;
520 }
521#if 0
522 else if( (classname == "KexiDBDateEdit") || (classname == "KexiDBDateTimeEdit") || (classname == "KexiDBTimeEdit")
523 /*|| (classname == "KexiDBIntSpinBox") || (classname == "KexiDBDoubleSpinBox")*/ ) {
524 disableFilter(w, container);
525 return true;
526 }
527#endif
528 else if(classname == "KexiDBAutoField") {
529 if(static_cast<KexiDBAutoField*>(w)->hasAutoCaption())
530 return false; // caption is auto, abort editing
531 TQLabel *label = static_cast<KexiDBAutoField*>(w)->label();
532 createEditor(classname, label->text(), label, container, label->geometry(), label->alignment());
533 return true;
534 }
535 else if (classname == "KexiDBCheckBox") {
536 KexiDBCheckBox *cb = static_cast<KexiDBCheckBox*>(w);
537 TQRect r( cb->geometry() );
538 r.setLeft( r.left() + 2 + cb->style().subRect( TQStyle::SR_CheckBoxIndicator, cb ).width() );
539 createEditor(classname, cb->text(), cb, container, r, TQt::AlignAuto);
540 return true;
541 }
542 else if(classname == "KexiDBImageBox") {
543 KexiDBImageBox *image = static_cast<KexiDBImageBox*>(w);
544 image->insertFromFile();
545 return true;
546 }
547 return false;
548}
549
550bool
552{
553 return false;
554}
555
556bool
557KexiDBFactory::clearWidgetContent(const TQCString & /*classname*/, TQWidget *w)
558{
561 KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>(w);
562 if(iface)
563 iface->clear();
564 return true;
565}
566
567TQValueList<TQCString>
568KexiDBFactory::autoSaveProperties(const TQCString & /*classname*/)
569{
570 TQValueList<TQCString> lst;
571// if(classname == "KexiDBSubForm")
572 //lst << "formName";
573// if(classname == "KexiDBLineEdit")
574// lst += "dataSource";
575// if(classname == "KexiDBAutoField")
576// lst << "labelCaption";
577 return lst;
578}
579
580bool
581KexiDBFactory::isPropertyVisibleInternal(const TQCString& classname, TQWidget *w,
582 const TQCString& property, bool isTopLevel)
583{
584 //general
585 if (property=="dataSource" || property=="dataSourceMimeType") {
586 return false; //force
587 }
588
589 bool ok = true;
590
591 if(classname == "KexiPushButton") {
592 ok = property!="isDragEnabled"
593#ifdef KEXI_NO_UNFINISHED
594 && property!="onClickAction"
595 && property!="onClickActionOption"
596 && property!="iconSet"
597 && property!="stdItem"
598#endif
599 ;
600 }
601 else if(classname == "KexiDBLineEdit")
602 ok = property!="urlDropsEnabled"
603 && property!="vAlign"
604#ifdef KEXI_NO_UNFINISHED
605 && property!="inputMask"
606 && property!="maxLength"
607#endif
608 ;
609 else if(classname == "KexiDBComboBox")
610 ok = property!="autoCaption"
611 && property!="labelPosition"
612 && property!="widgetType"
613 && property!="fieldTypeInternal"
614 && property!="fieldCaptionInternal"; //hide properties that come with KexiDBAutoField
615 else if(classname == "KexiDBTextEdit")
616 ok = property!="undoDepth"
617 && property!="undoRedoEnabled" //always true!
618 && property!="dragAutoScroll" //always true!
619 && property!="overwriteMode" //always false!
620 && property!="resizePolicy"
621 && property!="autoFormatting" //too complex
622#ifdef KEXI_NO_UNFINISHED
623 && property!="paper"
624#endif
625 ;
626 else if(classname == "KexiDBSubForm")
627 ok = property!="dragAutoScroll"
628 && property!="resizePolicy"
629 && property!="focusPolicy";
630 else if(classname == "KexiDBForm")
631 ok = property!="iconText"
632 && property!="geometry" /*nonsense for toplevel widget; for size, "size" property is used*/;
633 else if(classname == "KexiDBLabel")
634 ok = property!="focusPolicy";
635 else if(classname == "KexiDBAutoField") {
636 if (!isTopLevel && property=="caption")
637 return true; //force
638 if (property=="fieldTypeInternal" || property=="fieldCaptionInternal"
640 || property=="widgetType")
641 return false;
642 ok = property!="text"; /* "text" is not needed as "caption" is used instead */
643 }
644 else if (classname == "KexiDBImageBox") {
645 ok = property!="font" && property!="wordbreak";
646 }
647 else if(classname == "KexiDBCheckBox") {
648 //hide text property if the widget is a child of an autofield beause there's already "caption" for this purpose
649 if (property=="text" && w && dynamic_cast<KFormDesigner::WidgetWithSubpropertiesInterface*>(w->parentWidget()))
650 return false;
651 ok = property!="autoRepeat";
652 }
653
654 return ok && WidgetFactory::isPropertyVisibleInternal(classname, w, property, isTopLevel);
655}
656
657bool
659 TQWidget *w, const TQCString& property)
660{
661 Q_UNUSED(classname);
662 Q_UNUSED(w);
663 if (property=="fieldTypeInternal" || property=="widgetType")
664 return true;
665 return false;
666}
667
668bool
669KexiDBFactory::changeText(const TQString &text)
670{
671 KFormDesigner::Form *form = m_container ? m_container->form() : 0;
672 if (!form)
673 return false;
674 if (!form->selectedWidget())
675 return false;
676 TQCString n( form->selectedWidget()->className() );
677// TQWidget *w = WidgetFactory::widget();
678 if(n == "KexiDBAutoField") {
679 changeProperty("caption", text, form);
680 return true;
681 }
683 return false;
684}
685
686void
687KexiDBFactory::resizeEditor(TQWidget *editor, TQWidget *w, const TQCString &classname)
688{
689 //TQSize s = widget->size();
690 //TQPoint p = widget->pos();
691
692 if(classname == "KexiDBAutoField")
693 editor->setGeometry( static_cast<KexiDBAutoField*>(w)->label()->geometry() );
694}
695
696void
698{
699//old KexiFormView *formView = KexiUtils::findParent<KexiFormView>((TQWidget*)m_widget, "KexiFormView");
700
701 // (js) heh, porting to KFormDesigner::FormManager::self() singleton took me entire day of work...
703 KexiFormView *formView = form ? KexiUtils::findParent<KexiFormView>((TQWidget*)form->widget(), "KexiFormView") : 0;
704 if (formView) {
705 changeProperty("pixmapId", (uint)id, form);
706//old formView->setUnsavedLocalBLOB(m_widget, id);
707 formView->setUnsavedLocalBLOB(form->selectedWidget(), id);
708 }
709}
710
711KFORMDESIGNER_WIDGET_FACTORY(KexiDBFactory, kexidbwidgets)
712
713#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)