kexi

kexidbfactory.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00003    Copyright (C) 2004-2006 Jaroslaw Staniek <js@iidea.pl>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <qpopupmenu.h>
00022 #include <qscrollview.h>
00023 #include <qcursor.h>
00024 #include <qpainter.h>
00025 #include <qstyle.h>
00026 
00027 #include <kgenericfactory.h>
00028 #include <klocale.h>
00029 #include <kdebug.h>
00030 #include <kiconloader.h>
00031 #include <kactioncollection.h>
00032 #include <kstdaction.h>
00033 
00034 #include <formeditor/container.h>
00035 #include <formeditor/form.h>
00036 #include <formeditor/formIO.h>
00037 #include <formeditor/formmanager.h>
00038 #include <formeditor/objecttree.h>
00039 #include <formeditor/utils.h>
00040 #include <kexidb/utils.h>
00041 #include <kexidb/connection.h>
00042 #include <kexipart.h>
00043 #include <formeditor/widgetlibrary.h>
00044 #include <kexigradientwidget.h>
00045 #include <keximainwindow.h>
00046 #include <kexiutils/utils.h>
00047 #include <widget/kexicustompropertyfactory.h>
00048 #include <widget/utils/kexicontextmenuutils.h>
00049 
00050 #include "kexiformview.h"
00051 #include "widgets/kexidbautofield.h"
00052 #include "widgets/kexidbcheckbox.h"
00053 #include "widgets/kexidbimagebox.h"
00054 //#include "widgets/kexidbdoublespinbox.h"
00055 //#include "widgets/kexidbintspinbox.h"
00056 #include "widgets/kexiframe.h"
00057 #include "widgets/kexidblabel.h"
00058 #include "widgets/kexidblineedit.h"
00059 #include "widgets/kexidbtextedit.h"
00060 #include "widgets/kexidbcombobox.h"
00061 #include "widgets/kexipushbutton.h"
00062 #include "widgets/kexidbform.h"
00063 #include "widgets/kexidbsubform.h"
00064 #include "kexidataawarewidgetinfo.h"
00065 
00066 #include "kexidbfactory.h"
00067 #include <core/kexi.h>
00068 
00069 
00071 
00072 KexiDBFactory::KexiDBFactory(QObject *parent, const char *name, const QStringList &)
00073  : KFormDesigner::WidgetFactory(parent, name)
00074 {
00075     KFormDesigner::WidgetInfo *wi;
00076     wi = new KexiDataAwareWidgetInfo(this);
00077     wi->setPixmap("form");
00078     wi->setClassName("KexiDBForm");
00079     wi->setName(i18n("Form"));
00080     wi->setNamePrefix(
00081         i18n("Widget name. This string will be used to name widgets of this class. "
00082         "It must _not_ contain white spaces and non latin1 characters.", "form"));
00083     wi->setDescription(i18n("A data-aware form widget"));
00084     addClass(wi);
00085 
00086 #ifndef KEXI_NO_SUBFORM
00087     wi = new KexiDataAwareWidgetInfo(this);
00088     wi->setPixmap("subform");
00089     wi->setClassName("KexiDBSubForm");
00090     wi->addAlternateClassName("KexiSubForm", true/*override*/); //older
00091     wi->setName(i18n("Sub Form"));
00092     wi->setNamePrefix(
00093         i18n("Widget name. This string will be used to name widgets of this class. "
00094         "It must _not_ contain white spaces and non latin1 characters.", "subForm"));
00095     wi->setDescription(i18n("A form widget included in another Form"));
00096     wi->setAutoSyncForProperty( "formName", false );
00097     addClass(wi);
00098 #endif
00099 
00100     // inherited
00101     wi = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KLineEdit");
00102     wi->setPixmap("lineedit");
00103     wi->setClassName("KexiDBLineEdit");
00104     wi->addAlternateClassName("QLineEdit", true/*override*/);
00105     wi->addAlternateClassName("KLineEdit", true/*override*/);
00106     wi->setIncludeFileName("klineedit.h");
00107     wi->setName(i18n("Text Box"));
00108     wi->setNamePrefix(
00109         i18n("Widget name. This string will be used to name widgets of this class. "
00110         "It must _not_ contain white spaces and non latin1 characters.", "textBox"));
00111     wi->setDescription(i18n("A widget for entering and displaying text"));
00112     addClass(wi);
00113 
00114     // inherited
00115     wi = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KTextEdit");
00116     wi->setPixmap("textedit");
00117     wi->setClassName("KexiDBTextEdit");
00118     wi->addAlternateClassName("QTextEdit", true/*override*/);
00119     wi->addAlternateClassName("KTextEdit", true/*override*/);
00120     wi->setIncludeFileName("ktextedit.h");
00121     wi->setName(i18n("Text Editor"));
00122     wi->setNamePrefix(
00123         i18n("Widget name. This string will be used to name widgets of this class. "
00124         "It must _not_ contain white spaces and non latin1 characters.", "textEditor"));
00125     wi->setDescription(i18n("A multiline text editor"));
00126     addClass(wi);
00127 
00128     wi = new KFormDesigner::WidgetInfo(
00129         this, "containers", "QFrame" /*we're inheriting to get i18n'd strings already translated there*/);
00130     wi->setPixmap("frame");
00131     wi->setClassName("KexiFrame");
00132     wi->addAlternateClassName("QFrame", true/*override*/);
00133     wi->setName(i18n("Frame"));
00134     wi->setNamePrefix(
00135         i18n("Widget name. This string will be used to name widgets of this class. "
00136         "It must _not_ contain white spaces and non latin1 characters.", "frame"));
00137     wi->setDescription(i18n("A simple frame widget"));
00138     addClass(wi);
00139 
00140     wi = new KexiDataAwareWidgetInfo(
00141         this, "stdwidgets", "QLabel" /*we're inheriting to get i18n'd strings already translated there*/);
00142     wi->setPixmap("label");
00143     wi->setClassName("KexiDBLabel");
00144     wi->addAlternateClassName("QLabel", true/*override*/);
00145     wi->addAlternateClassName("KexiLabel", true/*override*/); //older
00146     wi->setName(i18n("Text Label", "Label"));
00147     wi->setNamePrefix(
00148         i18n("Widget name. This string will be used to name widgets of this class. "
00149         "It must _not_ contain white spaces and non latin1 characters.", "label"));
00150     wi->setDescription(i18n("A widget for displaying text"));
00151     addClass(wi);
00152 
00153 #ifndef KEXI_NO_IMAGEBOX_WIDGET
00154     wi = new KexiDataAwareWidgetInfo(
00155         this, "stdwidgets", "KexiPictureLabel" /*we're inheriting to get i18n'd strings already translated there*/);
00156     wi->setPixmap("pixmaplabel");
00157     wi->setClassName("KexiDBImageBox");
00158     wi->addAlternateClassName("KexiPictureLabel", true/*override*/);
00159     wi->addAlternateClassName("KexiImageBox", true/*override*/); //older
00160     wi->setName(i18n("Image Box"));
00161     wi->setNamePrefix(
00162         i18n("Widget name. This string will be used to name widgets of this class. "
00163         "It must _not_ contain white spaces and non latin1 characters.", "image"));
00164     wi->setDescription(i18n("A widget for displaying images"));
00165 //  wi->setCustomTypeForProperty("pixmapData", KexiCustomPropertyFactory::PixmapData);
00166     wi->setCustomTypeForProperty("pixmapId", KexiCustomPropertyFactory::PixmapId);
00167     addClass(wi);
00168 
00169     setInternalProperty("KexiDBImageBox", "dontStartEditingOnInserting", "1");
00170 //  setInternalProperty("KexiDBImageBox", "forceShowAdvancedProperty:pixmap", "1");
00171 #endif
00172 
00173 #ifdef KEXI_DB_COMBOBOX_WIDGET
00174     wi = new KexiDataAwareWidgetInfo(
00175         this, "stdwidgets", "KComboBox" /*we're inheriting to get i18n'd strings already translated there*/);
00176     wi->setPixmap("combo");
00177     wi->setClassName("KexiDBComboBox");
00178     wi->addAlternateClassName("KComboBox", true/*override*/);
00179     wi->setName(i18n("Combo Box"));
00180     wi->setNamePrefix(
00181         i18n("Widget name. This string will be used to name widgets of this class. "
00182         "It must _not_ contain white spaces and non latin1 characters.", "comboBox"));
00183     wi->setDescription(i18n("A combo box widget"));
00184     addClass(wi);
00185 #endif
00186 
00187     wi = new KexiDataAwareWidgetInfo(this, "stdwidgets", "QCheckBox");
00188     wi->setPixmap("check");
00189     wi->setClassName("KexiDBCheckBox");
00190     wi->addAlternateClassName("QCheckBox", true/*override*/);
00191     wi->setName(i18n("Check Box"));
00192     wi->setNamePrefix(
00193         i18n("Widget name. This string will be used to name widgets of this class. "
00194         "It must _not_ contain white spaces and non latin1 characters.", "checkBox"));
00195     wi->setDescription(i18n("A check box with text label"));
00196     addClass(wi);
00197 
00198 #ifndef KEXI_NO_AUTOFIELD_WIDGET
00199     wi = new KexiDataAwareWidgetInfo(this);
00200     wi->setPixmap("autofield");
00201     wi->setClassName("KexiDBAutoField");
00202     wi->addAlternateClassName("KexiDBFieldEdit", true/*override*/); //older
00203     wi->setName(i18n("Auto Field"));
00204     wi->setNamePrefix(
00205         i18n("Widget name. This string will be used to name widgets of this class. "
00206     "It must _not_ contain white spaces and non latin1 characters", "autoField"));
00207     wi->setDescription(i18n("A widget containing an automatically selected editor "
00208         "and a label to edit the value of a database field of any type."));
00209     addClass(wi);
00210 #endif
00211 
00212 /*
00213 #if KDE_VERSION >= KDE_MAKE_VERSION(3,1,9)
00214     KexiDataAwareWidgetInfo *wDate = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KDateWidget");
00215 #else
00216     KexiDataAwareWidgetInfo *wDate = new KexiDataAwareWidgetInfo(this, "stdwidgets", "QDateEdit");
00217 #endif
00218     wDate->setPixmap("dateedit");
00219     wDate->setClassName("KexiDBDateEdit");
00220     wDate->addAlternateClassName("QDateEdit", true);//override
00221     wDate->addAlternateClassName("KDateWidget", true);//override
00222     wDate->setName(i18n("Date Widget"));
00223     wDate->setNamePrefix(
00224         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"));
00225     wDate->setDescription(i18n("A widget to input and display a date"));
00226     addClass(wDate);
00227 
00228 #if KDE_VERSION >= KDE_MAKE_VERSION(3,1,9)
00229     KexiDataAwareWidgetInfo *wTime = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KTimeWidget");
00230 #else
00231     KexiDataAwareWidgetInfo *wTime = new KexiDataAwareWidgetInfo(this, "stdwidgets", "QTimeEdit");
00232 #endif
00233     wTime->setPixmap("timeedit");
00234     wTime->setClassName("KexiDBTimeEdit");
00235     wTime->addAlternateClassName("QTimeEdit", true);//override
00236     wTime->addAlternateClassName("KTimeWidget", true);//override
00237     wTime->setName(i18n("Time Widget"));
00238     wTime->setNamePrefix(
00239         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"));
00240     wTime->setDescription(i18n("A widget to input and display a time"));
00241     addClass(wTime);
00242 
00243 #if KDE_VERSION >= KDE_MAKE_VERSION(3,1,9)
00244     KexiDataAwareWidgetInfo *wDateTime = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KDateTimeWidget");
00245 #else
00246     KexiDataAwareWidgetInfo *wDateTime = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KDateTimeWidget");
00247 #endif
00248     wDateTime->setPixmap("datetimeedit");
00249     wDateTime->setClassName("KexiDBDateTimeEdit");
00250     wDateTime->addAlternateClassName("QDateTimeEdit", true);//override
00251     wDateTime->addAlternateClassName("KDateTimeWidget", true);//override
00252     wDateTime->setName(i18n("Date/Time Widget"));
00253     wDateTime->setNamePrefix(
00254         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"));
00255     wDateTime->setDescription(i18n("A widget to input and display a date and time"));
00256     addClass(wDateTime);
00257 */
00258 
00259 /*  KexiDataAwareWidgetInfo *wIntSpinBox = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KIntSpinBox");
00260     wIntSpinBox->setPixmap("spin");
00261     wIntSpinBox->setClassName("KexiDBIntSpinBox");
00262     wIntSpinBox->addAlternateClassName("QSpinBox", true);
00263     wIntSpinBox->addAlternateClassName("KIntSpinBox", true);
00264     wIntSpinBox->setName(i18n("Integer Number Spin Box"));
00265     wIntSpinBox->setNamePrefix(
00266         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"));
00267     wIntSpinBox->setDescription(i18n("A spin box widget to input and display integer numbers"));
00268     addClass(wIntSpinBox);
00269 
00270     KexiDataAwareWidgetInfo *wDoubleSpinBox = new KexiDataAwareWidgetInfo(this, "stdwidgets");
00271     wDoubleSpinBox->setPixmap("spin");
00272     wDoubleSpinBox->setClassName("KexiDBDoubleSpinBox");
00273     wDoubleSpinBox->addAlternateClassName("KDoubleSpinBox", true);
00274     wDoubleSpinBox->setName(i18n("Floating-point Number Spin Box"));
00275     wDoubleSpinBox->setNamePrefix(
00276         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"));
00277     wDoubleSpinBox->setDescription(i18n("A spin box widget to input and display floating-point numbers"));
00278     addClass(wDoubleSpinBox);*/
00279 
00280     // inherited
00281     wi = new KFormDesigner::WidgetInfo(
00282         this, "stdwidgets", "KPushButton");
00283     wi->addAlternateClassName("KexiPushButton");
00284     wi->setName(i18n("Command Button"));
00285     wi->setNamePrefix(
00286         i18n("Widget name. This string will be used to name widgets of this class. "
00287         "It must _not_ contain white spaces and non latin1 characters.", "button"));
00288     wi->setDescription(i18n("A command button to execute actions"));
00289     addClass(wi);
00290 
00291     m_propDesc["dataSource"] = i18n("Data Source");
00292     m_propDesc["formName"] = i18n("Form Name");
00293     m_propDesc["onClickAction"] = i18n("On Click");
00294     m_propDesc["onClickActionOption"] = i18n("On Click Option");
00295     m_propDesc["autoTabStops"] = i18n("Auto Tab Order");
00296     m_propDesc["shadowEnabled"] = i18n("Shadow Enabled");
00297     m_propDesc["on"] = i18n("On: button", "On");
00298 
00299     m_propDesc["widgetType"] = i18n("Editor Type");
00300     //for autofield's type: inherit i18n from KexiDB
00301     m_propValDesc["Auto"] = i18n("AutoField editor's type", "Auto"); 
00302     m_propValDesc["Text"] = KexiDB::Field::typeName(KexiDB::Field::Text);
00303     m_propValDesc["Integer"] = KexiDB::Field::typeName(KexiDB::Field::Integer);
00304     m_propValDesc["Double"] = KexiDB::Field::typeName(KexiDB::Field::Double);
00305     m_propValDesc["Boolean"] = KexiDB::Field::typeName(KexiDB::Field::Boolean);
00306     m_propValDesc["Date"] = KexiDB::Field::typeName(KexiDB::Field::Date);
00307     m_propValDesc["Time"] = KexiDB::Field::typeName(KexiDB::Field::Time);
00308     m_propValDesc["DateTime"] = KexiDB::Field::typeName(KexiDB::Field::DateTime);
00309     m_propValDesc["MultiLineText"] = i18n("AutoField editor's type", "Multiline Text");
00310     m_propValDesc["ComboBox"] = i18n("AutoField editor's type", "Drop-Down List"); 
00311     m_propValDesc["Image"] = i18n("AutoField editor's type", "Image");
00312 
00313 //  m_propDesc["labelCaption"] = i18n("Label Text");
00314     m_propDesc["autoCaption"] = i18n("Auto Label");
00315     m_propDesc["foregroundLabelColor"] = i18n("Label Text Color");
00316     m_propDesc["backgroundLabelColor"] = i18n("(a property name, keep the text narrow!)", 
00317         "Label Background\nColor");
00318 
00319     m_propDesc["labelPosition"] = i18n("Label Position");
00320     m_propValDesc["Left"] = i18n("Label Position", "Left");
00321     m_propValDesc["Top"] = i18n("Label Position", "Top");
00322     m_propValDesc["NoLabel"] = i18n("Label Position", "No Label");
00323 
00324     m_propDesc["sizeInternal"] = i18n("Size");
00325 //  m_propDesc["pixmap"] = i18n("Image");
00326     m_propDesc["pixmapId"] = i18n("Image");
00327     m_propDesc["scaledContents"] = i18n("Scaled Contents");
00328     m_propDesc["keepAspectRatio"] = i18n("Keep Aspect Ratio (short)", "Keep Ratio");
00329 
00330     //hide classes that are replaced by db-aware versions
00331     hideClass("KexiPictureLabel");
00332     hideClass("KComboBox");
00333 
00334     //used in labels, frames...
00335     m_propDesc["frameColor"] = i18n("Frame Color");
00336     m_propDesc["dropDownButtonVisible"] = 
00337         i18n("Drop-Down Button for Image Box Visible (a property name, keep the text narrow!)", 
00338             "Drop-Down\nButton Visible");
00339 
00340     //for checkbox
00341     m_propValDesc["TristateDefault"] = i18n("Tristate checkbox, default", "Default");
00342     m_propValDesc["TristateOn"] = i18n("Tristate checkbox, yes", "Yes");
00343     m_propValDesc["TristateOff"] = i18n("Tristate checkbox, no", "No");
00344     
00345     //for combobox
00346     m_propDesc["editable"] = i18n("Editable combobox", "Editable");
00347 }
00348 
00349 KexiDBFactory::~KexiDBFactory()
00350 {
00351 }
00352 
00353 QWidget*
00354 KexiDBFactory::createWidget(const QCString &c, QWidget *p, const char *n, 
00355     KFormDesigner::Container *container, int options)
00356 {
00357     kexipluginsdbg << "KexiDBFactory::createWidget() " << this << endl;
00358 
00359     QWidget *w=0;
00360     QString text( container->form()->library()->textForWidgetName(n, c) );
00361     const bool designMode = options & KFormDesigner::WidgetFactory::DesignViewMode;
00362 
00363     if(c == "KexiDBSubForm")
00364         w = new KexiDBSubForm(container->form(), p, n);
00365     else if(c == "KexiDBLineEdit")
00366     {
00367         w = new KexiDBLineEdit(p, n);
00368         if (designMode)
00369             w->setCursor(QCursor(Qt::ArrowCursor));
00370     }
00371     else if(c == "KexiDBTextEdit")
00372     {
00373         w = new KexiDBTextEdit(p, n);
00374         if (designMode)
00375             w->setCursor(QCursor(Qt::ArrowCursor));
00376     }
00377     else if(c == "QFrame" || c == "KexiFrame")
00378     {
00379         w = new KexiFrame(p, n);
00380         new KFormDesigner::Container(container, w, container);
00381     }
00382     else if(c == "KexiDBLabel")
00383         w = new KexiDBLabel(text, p, n);
00384 #ifndef KEXI_NO_IMAGEBOX_WIDGET
00385     else if(c == "KexiDBImageBox") {
00386         w = new KexiDBImageBox(designMode, p, n);
00387         connect(w, SIGNAL(idChanged(long)), this, SLOT(slotImageBoxIdChanged(long)));
00388     }
00389 #endif
00390 #ifndef KEXI_NO_AUTOFIELD_WIDGET
00391     else if(c == "KexiDBAutoField")
00392         w = new KexiDBAutoField(p, n, designMode);
00393 #endif
00394     else if(c == "KexiDBCheckBox")
00395         w = new KexiDBCheckBox(text, p, n);
00396     else if(c == "KexiDBComboBox")
00397         w = new KexiDBComboBox(p, n, designMode);
00398 /*  else if(c == "KexiDBTimeEdit")
00399         w = new KexiDBTimeEdit(QTime::currentTime(), p, n);
00400     else if(c == "KexiDBDateEdit")
00401         w = new KexiDBDateEdit(QDate::currentDate(), p, n);
00402     else if(c == "KexiDBDateTimeEdit")
00403         w = new KexiDBDateTimeEdit(QDateTime::currentDateTime(), p, n);*/
00404 //  else if(c == "KexiDBIntSpinBox")
00405 //      w = new KexiDBIntSpinBox(p, n);
00406 //  else if(c == "KexiDBDoubleSpinBox")
00407 //      w = new KexiDBDoubleSpinBox(p, n);
00408     else if(c == "KPushButton" || c == "KexiPushButton")
00409         w = new KexiPushButton(text, p, n);
00410 
00411     return w;
00412 }
00413 
00414 bool
00415 KexiDBFactory::createMenuActions(const QCString &classname, QWidget *w, QPopupMenu *menu,
00416            KFormDesigner::Container *)
00417 {
00418     if(classname == "QPushButton" || classname == "KPushButton" || classname == "KexiPushButton")
00419     {
00421         m_assignAction->plug( menu );
00422         return true;
00423     }
00424     else if(classname == "KexiDBImageBox")
00425     {
00426         KexiDBImageBox *imageBox = static_cast<KexiDBImageBox*>(w);
00427         imageBox->contextMenu()->updateActionsAvailability();
00428         KActionCollection *ac = imageBox->contextMenu()->actionCollection();
00429         KPopupMenu *subMenu = new KPopupMenu();
00431         menu->insertItem(i18n("&Image"), subMenu);
00432         ac->action("insert")->plug(subMenu);
00433         ac->action("file_save_as")->plug(subMenu);
00434         subMenu->insertSeparator();
00435         ac->action("edit_cut")->plug(subMenu);
00436         ac->action("edit_copy")->plug(subMenu);
00437         ac->action("edit_paste")->plug(subMenu);
00438         ac->action("delete")->plug(subMenu);
00439         if (ac->action("properties")) {
00440             subMenu->insertSeparator();
00441             ac->action("properties")->plug(subMenu);
00442         }
00443     }
00444     return false;
00445 }
00446 
00447 void
00448 KexiDBFactory::createCustomActions(KActionCollection* col)
00449 {
00450     //this will create shared instance action for design mode (special collection is provided)
00451     m_assignAction = new KAction( i18n("&Assign Action..."), SmallIconSet("form_action"),
00452         0, 0, 0, col, "widget_assign_action");
00453 }
00454 
00455 bool
00456 KexiDBFactory::startEditing(const QCString &classname, QWidget *w, KFormDesigner::Container *container)
00457 {
00458     m_container = container;
00459     if(classname == "KexiDBLineEdit")
00460     {
00463         KLineEdit *lineedit = static_cast<KLineEdit*>(w);
00464         createEditor(classname, lineedit->text(), lineedit, container,
00465             lineedit->geometry(), lineedit->alignment(), true);
00466         return true;
00467     }
00468     if(classname == "KexiDBTextEdit")
00469     {
00472         KTextEdit *textedit = static_cast<KTextEdit*>(w);
00473         createEditor(classname, textedit->text(), textedit, container,
00474             textedit->geometry(), textedit->alignment(), true, true);
00475         //copy a few properties
00476         KTextEdit *ed = dynamic_cast<KTextEdit *>( editor(w) );
00477         ed->setWrapPolicy(textedit->wrapPolicy());
00478         ed->setWordWrap(textedit->wordWrap());
00479         ed->setTabStopWidth(textedit->tabStopWidth());
00480         ed->setWrapColumnOrWidth(textedit->wrapColumnOrWidth());
00481         ed->setLinkUnderline(textedit->linkUnderline());
00482         ed->setTextFormat(textedit->textFormat());
00483         ed->setHScrollBarMode(textedit->hScrollBarMode());
00484         ed->setVScrollBarMode(textedit->vScrollBarMode());
00485         return true;
00486     }
00487     else if ( classname == "KexiDBLabel" ) {
00488         KexiDBLabel *label = static_cast<KexiDBLabel*>(w);
00489         m_widget = w;
00490         if(label->textFormat() == RichText)
00491         {
00492             QString text = label->text();
00493             if ( editRichText( label, text ) )
00494             {
00495                 changeProperty( "textFormat", "RichText", container->form() );
00496                 changeProperty( "text", text, container->form() );
00497             }
00498 
00499             if ( classname == "KexiDBLabel" )
00500                 w->resize(w->sizeHint());
00501         }
00502         else
00503         {
00504             createEditor(classname, label->text(), label, container,
00505                 label->geometry(), label->alignment(), 
00506                 false, label->alignment() & Qt::WordBreak /*multiline*/);
00507         }
00508         return true;
00509     }
00510     else if (classname == "KexiDBSubForm") {
00511         // open the form in design mode
00512         KexiMainWindow *mainWin = KexiUtils::findParent<KexiMainWindow>(w, "KexiMainWindow");
00513         KexiDBSubForm *subform = static_cast<KexiDBSubForm*>(w);
00514         if(mainWin) {
00515             bool openingCancelled;
00516             mainWin->openObject("kexi/form", subform->formName(), Kexi::DesignViewMode, 
00517                 openingCancelled);
00518         }
00519         return true;
00520     }
00521 #if 0
00522     else if( (classname == "KexiDBDateEdit") || (classname == "KexiDBDateTimeEdit") || (classname == "KexiDBTimeEdit")
00523             /*|| (classname == "KexiDBIntSpinBox") || (classname == "KexiDBDoubleSpinBox")*/ ) {
00524         disableFilter(w, container);
00525         return true;
00526     }
00527 #endif
00528     else if(classname == "KexiDBAutoField") {
00529         if(static_cast<KexiDBAutoField*>(w)->hasAutoCaption())
00530             return false; // caption is auto, abort editing
00531         QLabel *label = static_cast<KexiDBAutoField*>(w)->label();
00532         createEditor(classname, label->text(), label, container, label->geometry(), label->alignment());
00533         return true;
00534     }
00535     else if (classname == "KexiDBCheckBox") {
00536         KexiDBCheckBox *cb = static_cast<KexiDBCheckBox*>(w);
00537         QRect r( cb->geometry() );
00538         r.setLeft( r.left() + 2 + cb->style().subRect( QStyle::SR_CheckBoxIndicator, cb ).width() );
00539         createEditor(classname, cb->text(), cb, container, r, Qt::AlignAuto);
00540         return true;
00541     }
00542     else if(classname == "KexiDBImageBox") {
00543         KexiDBImageBox *image = static_cast<KexiDBImageBox*>(w);
00544         image->insertFromFile();
00545         return true;
00546     }
00547     return false;
00548 }
00549 
00550 bool
00551 KexiDBFactory::previewWidget(const QCString &, QWidget *, KFormDesigner::Container *)
00552 {
00553     return false;
00554 }
00555 
00556 bool
00557 KexiDBFactory::clearWidgetContent(const QCString & /*classname*/, QWidget *w)
00558 {
00561     KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>(w);
00562     if(iface)
00563         iface->clear();
00564     return true;
00565 }
00566 
00567 QValueList<QCString>
00568 KexiDBFactory::autoSaveProperties(const QCString & /*classname*/)
00569 {
00570     QValueList<QCString> lst;
00571 //  if(classname == "KexiDBSubForm")
00572         //lst << "formName";
00573 //  if(classname == "KexiDBLineEdit")
00574 //  lst += "dataSource";
00575 //  if(classname == "KexiDBAutoField")
00576 //      lst << "labelCaption";
00577     return lst;
00578 }
00579 
00580 bool
00581 KexiDBFactory::isPropertyVisibleInternal(const QCString& classname, QWidget *w,
00582     const QCString& property, bool isTopLevel)
00583 {
00584     //general
00585     if (property=="dataSource" || property=="dataSourceMimeType") {
00586         return false; //force
00587     }
00588 
00589     bool ok = true;
00590 
00591     if(classname == "KexiPushButton") {
00592         ok = property!="isDragEnabled"
00593 #ifdef KEXI_NO_UNFINISHED
00594             && property!="onClickAction" 
00595             && property!="onClickActionOption" 
00596             && property!="iconSet" 
00597             && property!="stdItem" 
00598 #endif
00599             ;
00600     }
00601     else if(classname == "KexiDBLineEdit")
00602         ok = property!="urlDropsEnabled"
00603             && property!="vAlign"
00604 #ifdef KEXI_NO_UNFINISHED
00605             && property!="inputMask"
00606             && property!="maxLength" 
00607 #endif
00608         ;
00609     else if(classname == "KexiDBComboBox")
00610         ok = property!="autoCaption"
00611             && property!="labelPosition"
00612             && property!="widgetType"
00613             && property!="fieldTypeInternal"
00614             && property!="fieldCaptionInternal"; //hide properties that come with KexiDBAutoField
00615     else if(classname == "KexiDBTextEdit")
00616         ok = property!="undoDepth"
00617             && property!="undoRedoEnabled" //always true!
00618             && property!="dragAutoScroll" //always true!
00619             && property!="overwriteMode" //always false!
00620             && property!="resizePolicy"
00621             && property!="autoFormatting" //too complex
00622 #ifdef KEXI_NO_UNFINISHED
00623             && property!="paper"
00624 #endif
00625             ;
00626     else if(classname == "KexiDBSubForm")
00627         ok = property!="dragAutoScroll"
00628             && property!="resizePolicy"
00629             && property!="focusPolicy";
00630     else if(classname == "KexiDBForm")
00631         ok = property!="iconText"
00632             && property!="geometry" /*nonsense for toplevel widget; for size, "size" property is used*/;
00633     else if(classname == "KexiDBLabel")
00634         ok = property!="focusPolicy";
00635     else if(classname == "KexiDBAutoField") {
00636         if (!isTopLevel && property=="caption")
00637             return true; //force
00638         if (property=="fieldTypeInternal" || property=="fieldCaptionInternal"
00640             || property=="widgetType")
00641             return false;
00642         ok = property!="text"; /* "text" is not needed as "caption" is used instead */
00643     }
00644     else if (classname == "KexiDBImageBox") {
00645         ok = property!="font" && property!="wordbreak";
00646     }
00647     else if(classname == "KexiDBCheckBox") {
00648         //hide text property if the widget is a child of an autofield beause there's already "caption" for this purpose
00649         if (property=="text" && w && dynamic_cast<KFormDesigner::WidgetWithSubpropertiesInterface*>(w->parentWidget()))
00650             return false;
00651         ok = property!="autoRepeat";
00652     }
00653 
00654     return ok && WidgetFactory::isPropertyVisibleInternal(classname, w, property, isTopLevel);
00655 }
00656 
00657 bool
00658 KexiDBFactory::propertySetShouldBeReloadedAfterPropertyChange(const QCString& classname, 
00659     QWidget *w, const QCString& property)
00660 {
00661     Q_UNUSED(classname);
00662     Q_UNUSED(w);
00663     if (property=="fieldTypeInternal" || property=="widgetType")
00664         return true;
00665     return false;
00666 }
00667 
00668 bool
00669 KexiDBFactory::changeText(const QString &text)
00670 {
00671     KFormDesigner::Form *form = m_container ? m_container->form() : 0;
00672     if (!form)
00673         return false;
00674     if (!form->selectedWidget())
00675         return false;
00676     QCString n( form->selectedWidget()->className() );
00677 //  QWidget *w = WidgetFactory::widget();
00678     if(n == "KexiDBAutoField") {
00679         changeProperty("caption", text, form);
00680         return true;
00681     }
00683     return false;
00684 }
00685 
00686 void
00687 KexiDBFactory::resizeEditor(QWidget *editor, QWidget *w, const QCString &classname)
00688 {
00689     //QSize s = widget->size();
00690     //QPoint p = widget->pos();
00691 
00692     if(classname == "KexiDBAutoField")
00693         editor->setGeometry( static_cast<KexiDBAutoField*>(w)->label()->geometry() );
00694 }
00695 
00696 void
00697 KexiDBFactory::slotImageBoxIdChanged(KexiBLOBBuffer::Id_t id)
00698 {
00699 //old   KexiFormView *formView = KexiUtils::findParent<KexiFormView>((QWidget*)m_widget, "KexiFormView"); 
00700 
00701     // (js) heh, porting to KFormDesigner::FormManager::self() singleton took me entire day of work...
00702     KFormDesigner::Form *form = KFormDesigner::FormManager::self()->activeForm();
00703     KexiFormView *formView = form ? KexiUtils::findParent<KexiFormView>((QWidget*)form->widget(), "KexiFormView") : 0;
00704     if (formView) {
00705         changeProperty("pixmapId", (uint)id, form);
00706 //old       formView->setUnsavedLocalBLOB(m_widget, id);
00707         formView->setUnsavedLocalBLOB(form->selectedWidget(), id);
00708     }
00709 }
00710 
00711 KFORMDESIGNER_WIDGET_FACTORY(KexiDBFactory, kexidbwidgets)
00712 
00713 #include "kexidbfactory.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys