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