diff --git a/kexi/plugins/forms/CMakeLists.txt b/kexi/plugins/forms/CMakeLists.txt index 588fae90323..97a77305e30 100644 --- a/kexi/plugins/forms/CMakeLists.txt +++ b/kexi/plugins/forms/CMakeLists.txt @@ -1,132 +1,133 @@ include_directories( ${CMAKE_SOURCE_DIR}/kexi/core ${CMAKE_SOURCE_DIR}/kexi ${CMAKE_SOURCE_DIR}/kexi/widget/utils ${CMAKE_SOURCE_DIR}/kexi/widget ${CMAKE_SOURCE_DIR}/kexi/formeditor ${CMAKE_SOURCE_DIR}/lib ${CMAKE_SOURCE_DIR}/libs/main ${CMAKE_SOURCE_DIR}/kexi/widget/tableview/private ${CMAKE_SOURCE_DIR}/kexi/widget/tableview ${KDE4_INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR}) ########### next target ############### if(MARBLE_FOUND) add_subdirectory(widgets/mapbrowser) endif(MARBLE_FOUND) ########### next target ############### if(QT_QTWEBKIT_FOUND) add_subdirectory(widgets/webbrowser) endif(QT_QTWEBKIT_FOUND) set(kexihandler_form_PART_SRCS kexiforms.cpp ) kde4_add_plugin(kexihandler_form ${kexihandler_form_PART_SRCS}) target_link_libraries( kexihandler_form kexicore kexiguiutils kexidatatable kexiextendedwidgets kformdesigner ${KOPROPERTY_LIBS} kexiformutils ${KDE4_KDECORE_LIBS} ${QT_QT3SUPPORT_LIBRARY} ) install(TARGETS kexihandler_form DESTINATION ${PLUGIN_INSTALL_DIR}) ########### next target ############### set(kformdesigner_kexidbwidgets_PART_SRCS kexidbfactory.cpp ) kde4_add_plugin(kformdesigner_kexidbwidgets ${kformdesigner_kexidbwidgets_PART_SRCS}) target_link_libraries( kformdesigner_kexidbwidgets kformdesigner kexiformutils kexidb kexicore kexiguiutils kexidataviewcommon kexidatatable kexiextendedwidgets ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS} ${QT_QTGUI_LIBRARY} ${QT_QT3SUPPORT_LIBRARY} ) install(TARGETS kformdesigner_kexidbwidgets DESTINATION ${PLUGIN_INSTALL_DIR}) ########### next target ############### set(kexiformutils_LIB_SRCS # kexiformdataiteminterface.cpp kexidataawarewidgetinfo.cpp kexiformscrollview.cpp kexidbtextwidgetinterface.cpp kexiformmanager.cpp kexidatasourcepage.cpp kexiformpart.cpp kexiformview.cpp kexidbfactorybase.cpp widgets/kexidbutils.cpp widgets/kexidbautofield.cpp widgets/kexidbform.cpp # todo widgets/kexidbsubform.cpp widgets/kexidblabel.cpp widgets/kexidbimagebox.cpp widgets/kexipushbutton.cpp widgets/kexiframe.cpp widgets/kexidblineedit.cpp widgets/kexidbcheckbox.cpp widgets/kexidbtextedit.cpp widgets/kexidbcombobox.cpp widgets/kexidbcommandlinkbutton.cpp widgets/kexidbslider.cpp widgets/kexidbprogressbar.cpp + widgets/kexidbdatepicker.cpp ) #obsolete widgets/kexidbdoublespinbox.cpp #obsolete widgets/kexidbintspinbox.cpp #obsolete widgets/kexidbdatetimeedit.cpp #obsolete widgets/kexidbtimeedit.cpp #obsolete widgets/kexidbdateedit.cpp kde4_add_library(kexiformutils SHARED ${kexiformutils_LIB_SRCS}) target_link_libraries( kexiformutils kexicore kexiextendedwidgets kformdesigner kexidb kexiutils kexidataviewcommon kexidatatable kexiguiutils ${KOPROPERTY_LIBS} ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS} ${KDE4_KDE3SUPPORT_LIBS} ${QT_QTGUI_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QT3SUPPORT_LIBRARY} ) set_target_properties(kexiformutils PROPERTIES VERSION ${GENERIC_CALLIGRA_LIB_VERSION} SOVERSION ${GENERIC_CALLIGRA_LIB_SOVERSION} ) install(TARGETS kexiformutils ${INSTALL_TARGETS_DEFAULT_ARGS}) ########### install files ############### install( FILES kformdesigner_kexidbfactory.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kformdesigner) install( FILES kexiformhandler.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kexi) diff --git a/kexi/plugins/forms/kexidbfactory.cpp b/kexi/plugins/forms/kexidbfactory.cpp index 4d8412372d8..e0802bc2946 100644 --- a/kexi/plugins/forms/kexidbfactory.cpp +++ b/kexi/plugins/forms/kexidbfactory.cpp @@ -1,836 +1,850 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004-2009 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kexiformview.h" #include "widgets/kexidbautofield.h" #include "widgets/kexidbcheckbox.h" #include "widgets/kexidbimagebox.h" //#include "widgets/kexidbdoublespinbox.h" //#include "widgets/kexidbintspinbox.h" #include "widgets/kexiframe.h" #include "widgets/kexidblabel.h" #include "widgets/kexidblineedit.h" #include "widgets/kexidbtextedit.h" #include "widgets/kexidbcombobox.h" #include "widgets/kexipushbutton.h" #include "widgets/kexidbform.h" #include "widgets/kexidbcommandlinkbutton.h" #include "widgets/kexidbslider.h" #include "widgets/kexidbprogressbar.h" +#include "widgets/kexidbdatepicker.h" #ifndef KEXI_NO_SUBFORM # include "widgets/kexidbsubform.h" #endif #include "kexidataawarewidgetinfo.h" #include "kexidbfactory.h" #include ////////////////////////////////////////// KexiDBFactory::KexiDBFactory(QObject *parent, const QVariantList &) : KexiDBFactoryBase(parent, "kexidb") , m_assignAction(0) { { KexiDataAwareWidgetInfo *wi = new KexiDataAwareWidgetInfo(this); wi->setPixmap("form"); wi->setClassName("KexiDBForm"); wi->setName(i18n("Form")); wi->setNamePrefix( i18nc("Widget name. This string will be used to name widgets of this class. " "It must _not_ contain white spaces and non latin1 characters.", "form")); wi->setDescription(i18n("A data-aware form widget")); addClass(wi); } #ifndef KEXI_NO_SUBFORM { KexiDataAwareWidgetInfo* wi = new KexiDataAwareWidgetInfo(this); wi->setPixmap("subform"); wi->setClassName("KexiDBSubForm"); wi->addAlternateClassName("KexiSubForm", true/*override*/); //older wi->setName(i18n("Sub Form")); wi->setNamePrefix( i18nc("Widget name. This string will be used to name widgets of this class. " "It must _not_ contain white spaces and non latin1 characters.", "subForm")); wi->setDescription(i18n("A form widget included in another Form")); wi->setAutoSyncForProperty("formName", false); addClass(wi); } #endif { // inherited KexiDataAwareWidgetInfo* wi = new KexiDataAwareWidgetInfo(this); wi->setPixmap("lineedit"); wi->setClassName("KexiDBLineEdit"); wi->setParentFactoryName("stdwidgets"); wi->setInheritedClassName("KLineEdit"); wi->addAlternateClassName("QLineEdit", true/*override*/); wi->addAlternateClassName("KLineEdit", true/*override*/); wi->setIncludeFileName("klineedit.h"); wi->setName(i18n("Text Box")); wi->setNamePrefix( i18nc("Widget name. This string will be used to name widgets of this class. " "It must _not_ contain white spaces and non latin1 characters.", "textBox")); wi->setDescription(i18n("A widget for entering and displaying text")); wi->setInternalProperty("dontStartEditingOnInserting", true); // because we are most probably assign data source to this widget wi->setInlineEditingEnabledWhenDataSourceSet(false); addClass(wi); } { // inherited KexiDataAwareWidgetInfo* wi = new KexiDataAwareWidgetInfo(this); wi->setPixmap("textedit"); wi->setClassName("KexiDBTextEdit"); wi->setParentFactoryName("stdwidgets"); wi->setInheritedClassName("KTextEdit"); wi->addAlternateClassName("QTextEdit", true/*override*/); wi->addAlternateClassName("KTextEdit", true/*override*/); wi->setIncludeFileName("ktextedit.h"); wi->setName(i18n("Text Editor")); wi->setNamePrefix( i18nc("Widget name. This string will be used to name widgets of this class. " "It must _not_ contain white spaces and non latin1 characters.", "textEditor")); wi->setDescription(i18n("A multiline text editor")); wi->setInternalProperty("dontStartEditingOnInserting", true); // because we are most probably assign data source to this widget wi->setInlineEditingEnabledWhenDataSourceSet(false); addClass(wi); } { KFormDesigner::WidgetInfo* wi = new KFormDesigner::WidgetInfo(this); wi->setPixmap("frame"); wi->setClassName("KexiFrame"); wi->setParentFactoryName("containers"); wi->setInheritedClassName("QFrame"); /* we are inheriting to get i18n'd strings already translated there */ wi->addAlternateClassName("QFrame", true/*override*/); wi->addAlternateClassName("Q3Frame", true/*override*/); wi->setName(i18n("Frame")); wi->setNamePrefix( i18nc("Widget name. This string will be used to name widgets of this class. " "It must _not_ contain white spaces and non latin1 characters.", "frame")); wi->setDescription(i18n("A simple frame widget")); addClass(wi); } { KexiDataAwareWidgetInfo* wi = new KexiDataAwareWidgetInfo(this); wi->setPixmap("label"); wi->setClassName("KexiDBLabel"); wi->setParentFactoryName("stdwidgets"); wi->setInheritedClassName("QLabel"); /* we are inheriting to get i18n'd strings already translated there */ wi->addAlternateClassName("QLabel", true/*override*/); wi->addAlternateClassName("KexiLabel", true/*override*/); //older wi->setName(i18nc("Text Label", "Label")); wi->setNamePrefix( i18nc("Widget name. This string will be used to name widgets of this class. " "It must _not_ contain white spaces and non latin1 characters.", "label")); wi->setDescription(i18n("A widget for displaying text")); wi->setInlineEditingEnabledWhenDataSourceSet(false); addClass(wi); } #ifndef KEXI_NO_IMAGEBOX_WIDGET { KexiDataAwareWidgetInfo* wi = new KexiDataAwareWidgetInfo(this); wi->setPixmap("pixmaplabel"); wi->setClassName("KexiDBImageBox"); wi->setParentFactoryName("stdwidgets"); wi->setInheritedClassName("KexiPictureLabel"); /* we are inheriting to get i18n'd strings already translated there */ wi->addAlternateClassName("KexiPictureLabel", true/*override*/); wi->addAlternateClassName("KexiImageBox", true/*override*/); //older wi->setName(i18n("Image Box")); wi->setNamePrefix( i18nc("Widget name. This string will be used to name widgets of this class. " "It must _not_ contain white spaces and non latin1 characters.", "image")); wi->setDescription(i18n("A widget for displaying images")); // wi->setCustomTypeForProperty("pixmapData", KexiCustomPropertyFactory::PixmapData); wi->setCustomTypeForProperty("pixmapId", KexiCustomPropertyFactory::PixmapId); wi->setInternalProperty("dontStartEditingOnInserting", true); addClass(wi); } #endif #ifdef KEXI_DB_COMBOBOX_WIDGET { KexiDataAwareWidgetInfo* wi = new KexiDataAwareWidgetInfo(this); wi->setPixmap("combo"); wi->setClassName("KexiDBComboBox"); wi->setParentFactoryName("stdwidgets"); wi->setInheritedClassName("KComboBox"); /* we are inheriting to get i18n'd strings already translated there */ wi->addAlternateClassName("KComboBox", true/*override*/); wi->setName(i18n("Combo Box")); wi->setNamePrefix( i18nc("Widget name. This string will be used to name widgets of this class. " "It must _not_ contain white spaces and non latin1 characters.", "comboBox")); wi->setDescription(i18n("A combo box widget")); addClass(wi); } #endif { KexiDataAwareWidgetInfo* wi = new KexiDataAwareWidgetInfo(this); wi->setPixmap("check"); wi->setClassName("KexiDBCheckBox"); wi->setParentFactoryName("stdwidgets"); wi->setInheritedClassName("QCheckBox"); /* we are inheriting to get i18n'd strings already translated there */ wi->addAlternateClassName("QCheckBox", true/*override*/); wi->setName(i18n("Check Box")); wi->setNamePrefix( i18nc("Widget name. This string will be used to name widgets of this class. " "It must _not_ contain white spaces and non latin1 characters.", "checkBox")); wi->setDescription(i18n("A check box with text label")); addClass(wi); } #ifndef KEXI_NO_AUTOFIELD_WIDGET { KexiDataAwareWidgetInfo* wi = new KexiDataAwareWidgetInfo(this); wi->setPixmap("autofield"); wi->setClassName("KexiDBAutoField"); wi->addAlternateClassName("KexiDBFieldEdit", true/*override*/); //older wi->setName(i18n("Auto Field")); wi->setNamePrefix( i18nc("Widget name. This string will be used to name widgets of this class. " "It must _not_ contain white spaces and non latin1 characters", "autoField")); wi->setDescription(i18n("A widget containing an automatically selected editor " "and a label to edit the value of a database field of any type.")); addClass(wi); } #endif /* KexiDataAwareWidgetInfo *wDate = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KDateWidget"); wDate->setPixmap("dateedit"); wDate->setClassName("KexiDBDateEdit"); wDate->addAlternateClassName("QDateEdit", true);//override wDate->addAlternateClassName("KDateWidget", true);//override wDate->setName(i18n("Date Widget")); wDate->setNamePrefix( 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")); wDate->setDescription(i18n("A widget to input and display a date")); addClass(wDate); KexiDataAwareWidgetInfo *wTime = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KTimeWidget"); wTime->setPixmap("timeedit"); wTime->setClassName("KexiDBTimeEdit"); wTime->addAlternateClassName("QTimeEdit", true);//override wTime->addAlternateClassName("KTimeWidget", true);//override wTime->setName(i18n("Time Widget")); wTime->setNamePrefix( 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")); wTime->setDescription(i18n("A widget to input and display a time")); addClass(wTime); KexiDataAwareWidgetInfo *wDateTime = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KDateTimeWidget"); wDateTime->setPixmap("datetimeedit"); wDateTime->setClassName("KexiDBDateTimeEdit"); wDateTime->addAlternateClassName("QDateTimeEdit", true);//override wDateTime->addAlternateClassName("KDateTimeWidget", true);//override wDateTime->setName(i18n("Date/Time Widget")); wDateTime->setNamePrefix( 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")); wDateTime->setDescription(i18n("A widget to input and display a date and time")); addClass(wDateTime); */ /* KexiDataAwareWidgetInfo *wIntSpinBox = new KexiDataAwareWidgetInfo(this, "stdwidgets", "KIntSpinBox"); wIntSpinBox->setPixmap("spin"); wIntSpinBox->setClassName("KexiDBIntSpinBox"); wIntSpinBox->addAlternateClassName("QSpinBox", true); wIntSpinBox->addAlternateClassName("KIntSpinBox", true); wIntSpinBox->setName(i18n("Integer Number Spin Box")); wIntSpinBox->setNamePrefix( 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")); wIntSpinBox->setDescription(i18n("A spin box widget to input and display integer numbers")); addClass(wIntSpinBox); KexiDataAwareWidgetInfo *wDoubleSpinBox = new KexiDataAwareWidgetInfo(this, "stdwidgets"); wDoubleSpinBox->setPixmap("spin"); wDoubleSpinBox->setClassName("KexiDBDoubleSpinBox"); wDoubleSpinBox->addAlternateClassName("KDoubleSpinBox", true); wDoubleSpinBox->setName(i18n("Floating-point Number Spin Box")); wDoubleSpinBox->setNamePrefix( 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")); wDoubleSpinBox->setDescription(i18n("A spin box widget to input and display floating-point numbers")); addClass(wDoubleSpinBox);*/ { // inherited KFormDesigner::WidgetInfo* wi = new KFormDesigner::WidgetInfo(this); wi->addAlternateClassName("KexiPushButton"); wi->setName(i18n("Button")); wi->setNamePrefix( i18nc("Widget name. This string will be used to name widgets of this class. " "It must _not_ contain white spaces and non latin1 characters.", "button")); wi->setDescription(i18n("A button for executing actions")); wi->setParentFactoryName("stdwidgets"); wi->setInheritedClassName("KPushButton"); addClass(wi); } { KFormDesigner::WidgetInfo* wi = new KFormDesigner::WidgetInfo(this); wi->setClassName("KexiDBCommandLinkButton"); wi->setPixmap("button"); wi->setName(i18n("Link Button")); wi->setNamePrefix( i18nc("Widget name. This string will be used to name widgets of this class. " "It must _not_ contain white spaces and non latin1 characters.", "linkButton")); wi->setDescription(i18n("A Link button for executing actions")); addClass(wi); } { KexiDataAwareWidgetInfo* wi = new KexiDataAwareWidgetInfo(this); wi->setPixmap("slider"); wi->setClassName("KexiDBSlider"); wi->setName(i18n("Slider")); wi->setNamePrefix( i18nc("Widget name. This string will be used to name widgets of this class. " "It must _not_ contain white spaces and non latin1 characters.", "slider")); wi->setDescription(i18n("A Slider widget")); addClass(wi); } { KexiDataAwareWidgetInfo* wi = new KexiDataAwareWidgetInfo(this); wi->setPixmap("progress-bar"); wi->setClassName("KexiDBProgressBar"); wi->setName(i18n("Progress Bar")); wi->setNamePrefix( i18nc("Widget name. This string will be used to name widgets of this class. " "It must _not_ contain white spaces and non latin1 characters.", "progressBar")); wi->setDescription(i18n("A Progress Bar widget")); addClass(wi); } + { + KexiDataAwareWidgetInfo* wi = new KexiDataAwareWidgetInfo(this); + wi->setPixmap("dateedit"); + wi->setClassName("KexiDBDatePicker"); + wi->setName(i18n("Date Picker")); + wi->setNamePrefix( + i18nc("Widget name. This string will be used to name widgets of this class. " + "It must _not_ contain white spaces and non latin1 characters.", "datePicker")); + wi->setDescription(i18n("A Date Picker widget")); + addClass(wi); + } m_propDesc["formName"] = i18n("Form Name"); m_propDesc["onClickAction"] = i18n("On Click"); m_propDesc["onClickActionOption"] = i18n("On Click Option"); m_propDesc["autoTabStops"] = i18n("Auto Tab Order"); m_propDesc["shadowEnabled"] = i18n("Shadow Enabled"); m_propDesc["on"] = i18nc("On: button", "On"); m_propDesc["widgetType"] = i18n("Editor Type"); //for autofield's type: inherit i18n from KexiDB m_propValDesc["Auto"] = i18nc("AutoField editor's type", "Auto"); m_propValDesc["Text"] = KexiDB::Field::typeName(KexiDB::Field::Text); m_propValDesc["Integer"] = KexiDB::Field::typeName(KexiDB::Field::Integer); m_propValDesc["Double"] = KexiDB::Field::typeName(KexiDB::Field::Double); m_propValDesc["Boolean"] = KexiDB::Field::typeName(KexiDB::Field::Boolean); m_propValDesc["Date"] = KexiDB::Field::typeName(KexiDB::Field::Date); m_propValDesc["Time"] = KexiDB::Field::typeName(KexiDB::Field::Time); m_propValDesc["DateTime"] = KexiDB::Field::typeName(KexiDB::Field::DateTime); m_propValDesc["MultiLineText"] = i18nc("AutoField editor's type", "Multiline Text"); m_propValDesc["ComboBox"] = i18nc("AutoField editor's type", "Drop-Down List"); m_propValDesc["Image"] = i18nc("AutoField editor's type", "Image"); // m_propDesc["labelCaption"] = i18n("Label Text"); m_propDesc["autoCaption"] = i18n("Auto Label"); m_propDesc["foregroundLabelColor"] = i18n("Label Text Color"); m_propDesc["backgroundLabelColor"] = i18nc("(a property name, keep the text narrow!)", "Label Background\nColor"); m_propDesc["labelPosition"] = i18n("Label Position"); m_propValDesc["Left"] = i18nc("Label Position", "Left"); m_propValDesc["Top"] = i18nc("Label Position", "Top"); m_propValDesc["NoLabel"] = i18nc("Label Position", "No Label"); m_propDesc["sizeInternal"] = i18n("Size"); m_propDesc["pixmapId"] = i18n("Image"); m_propDesc["scaledContents"] = i18n("Scaled Contents"); m_propDesc["smoothTransformation"] = i18nc("Smoothing when contents are scaled", "Smoothing"); m_propDesc["keepAspectRatio"] = i18nc("Keep Aspect Ratio (short)", "Keep Ratio"); //hide classes that are replaced by db-aware versions hideClass("KexiPictureLabel"); hideClass("KComboBox"); //used in labels, frames... m_propDesc["dropDownButtonVisible"] = i18nc("Drop-Down Button for Image Box Visible (a property name, keep the text narrow!)", "Drop-Down\nButton Visible"); //for checkbox m_propValDesc["TristateDefault"] = i18nc("Tristate checkbox, default", "Default"); m_propValDesc["TristateOn"] = i18nc("Tristate checkbox, yes", "Yes"); m_propValDesc["TristateOff"] = i18nc("Tristate checkbox, no", "No"); //for combobox m_propDesc["editable"] = i18nc("Editable combobox", "Editable"); } KexiDBFactory::~KexiDBFactory() { } QWidget* KexiDBFactory::createWidget(const QByteArray &c, QWidget *p, const char *n, KFormDesigner::Container *container, CreateWidgetOptions options) { kDebug() << this; QWidget *w = 0; QString text(container->form()->library()->textForWidgetName(n, c)); const bool designMode = options & KFormDesigner::WidgetFactory::DesignViewMode; bool createContainer = false; if (c == "KexiDBLineEdit") { w = new KexiDBLineEdit(p); //2.0 moved to FormWidgetInterface // if (designMode) // w->setCursor(QCursor(Qt::ArrowCursor)); } #ifndef KEXI_NO_SUBFORM if (c == "KexiDBSubForm") { w = new KexiDBSubForm(container->form(), p); } #endif else if (c == "KexiDBTextEdit") { w = new KexiDBTextEdit(p); //2.0 moved to FormWidgetInterface // if (designMode) // w->setCursor(QCursor(Qt::ArrowCursor)); } else if (c == "Q3Frame" || c == "QFrame" || c == "KexiFrame") { w = new KexiFrame(p); createContainer = true; } else if (c == "KexiDBLabel") w = new KexiDBLabel(text, p); #ifndef KEXI_NO_IMAGEBOX_WIDGET else if (c == "KexiDBImageBox") { w = new KexiDBImageBox(designMode, p); connect(w, SIGNAL(idChanged(long)), this, SLOT(slotImageBoxIdChanged(long))); } #endif #ifndef KEXI_NO_AUTOFIELD_WIDGET else if (c == "KexiDBAutoField") w = new KexiDBAutoField(p); #endif else if (c == "KexiDBCheckBox") w = new KexiDBCheckBox(text, p); else if (c == "KexiDBSlider") { w = new KexiDBSlider(p); } else if (c == "KexiDBProgressBar") { w = new KexiDBProgressBar(p); + } else if (c == "KexiDBDatePicker") { + w = new KexiDBDatePicker(p); } else if (c == "KexiDBComboBox") w = new KexiDBComboBox(p); /* else if(c == "KexiDBTimeEdit") w = new KexiDBTimeEdit(QTime::currentTime(), p, n); else if(c == "KexiDBDateEdit") w = new KexiDBDateEdit(QDate::currentDate(), p, n); else if(c == "KexiDBDateTimeEdit") w = new KexiDBDateTimeEdit(QDateTime::currentDateTime(), p, n);*/ // else if(c == "KexiDBIntSpinBox") // w = new KexiDBIntSpinBox(p, n); // else if(c == "KexiDBDoubleSpinBox") // w = new KexiDBDoubleSpinBox(p, n); else if (c == "KPushButton" || c == "KexiPushButton") w = new KexiPushButton(text, p); else if (c == "KexiDBCommandLinkButton" || c == "KexiCommandLinkButton") { w = new KexiDBCommandLinkButton(text, QString(), p); } if (w) w->setObjectName(n); if (createContainer) (void)new KFormDesigner::Container(container, w, container); return w; } bool KexiDBFactory::createMenuActions(const QByteArray &classname, QWidget *w, QMenu *menu, KFormDesigner::Container *) { if (m_assignAction->isEnabled()) { /*! @todo also call createMenuActions() for inherited factory! */ menu->addAction(m_assignAction); return true; } else if (classname == "KexiDBImageBox") { KexiDBImageBox *imageBox = static_cast(w); imageBox->contextMenu()->updateActionsAvailability(); KActionCollection *ac = imageBox->contextMenu()->actionCollection(); QMenu *subMenu = menu->addMenu(i18n("&Image")); //! @todo make these actions undoable/redoable subMenu->addAction(ac->action("insert")); subMenu->addAction(ac->action("file_save_as")); subMenu->addSeparator(); subMenu->addAction(ac->action("edit_cut")); subMenu->addAction(ac->action("edit_copy")); subMenu->addAction(ac->action("edit_paste")); subMenu->addAction(ac->action("delete")); if (ac->action("properties")) { subMenu->addSeparator(); subMenu->addAction(ac->action("properties")); } } return false; } void KexiDBFactory::createCustomActions(KActionCollection* col) { //this will create shared instance action for design mode (special collection is provided) col->addAction("widget_assign_action", m_assignAction = new KAction(KIcon("form_action"), i18n("&Assign Action..."), this)); } bool KexiDBFactory::startInlineEditing(InlineEditorCreationArguments& args) { //2.0 m_container = container; const KFormDesigner::WidgetInfo* wclass = args.container->form()->library()->widgetInfoForClassName(args.classname); const KexiDataAwareWidgetInfo* wDataAwareClass = dynamic_cast(wclass); if (wDataAwareClass && !wDataAwareClass->inlineEditingEnabledWhenDataSourceSet()) { KexiFormDataItemInterface* iface = dynamic_cast(args.widget); if (iface && !iface->dataSource().isEmpty()) { //! @todo reimplement inline editing for KexiDBLineEdit using combobox with data sources return false; } } if (args.classname == "KexiDBLineEdit") { //! @todo this code should not be copied here but //! just inherited StdWidgetFactory::startInlineEditing() should be called KLineEdit *lineedit = static_cast(args.widget); args.text = lineedit->text(); args.alignment = lineedit->alignment(); args.useFrame = true; return true; } else if (args.classname == "KexiDBTextEdit") { //! @todo this code should not be copied here but //! just inherited StdWidgetFactory::startInlineEditing() should be called KTextEdit *textedit = static_cast(args.widget); //! @todo rich text? args.text = textedit->toPlainText(); args.alignment = textedit->alignment(); args.useFrame = true; args.multiLine = true; //! @todo #if 0 //copy a few properties KTextEdit *ed = dynamic_cast(editor(w)); ed->setLineWrapMode(textedit->lineWrapMode()); ed->setLineWrapColumnOrWidth(textedit->lineWrapColumnOrWidth()); ed->setWordWrapMode(textedit->wordWrapMode()); ed->setTabStopWidth(textedit->tabStopWidth()); ed->setTextFormat(textedit->textFormat()); ed->setHorizontalScrollBarPolicy(textedit->horizontalScrollBarPolicy()); ed->setVerticalScrollBarPolicy(textedit->verticalScrollBarPolicy()); #endif return true; } // KexiDBCommandLinkButton else if (args.classname == "KexiDBCommandLinkButton" ){ KexiDBCommandLinkButton *linkButton=static_cast(args.widget); QStyleOption option; option.initFrom(linkButton); args.text = linkButton->text(); const QRect r(linkButton->style()->subElementRect( QStyle::SE_PushButtonContents, &option, linkButton)); args.geometry = QRect(linkButton->x() + r.x(), linkButton->y() + r.y(), r.width(), r.height()); return true; } else if (args.classname == "KexiDBLabel") { KexiDBLabel *label = static_cast(args.widget); //2.0 m_widget = w; if (label->textFormat() == Qt::RichText) { args.execute = false; // QString text = label->text(); if (wclass && wclass->inheritedClass()) { const QByteArray thisClassname = args.classname; //save args.classname = wclass->inheritedClass()->className(); //! @todo OK? const bool result = wclass->inheritedClass()->factory()->startInlineEditing(args); args.classname = thisClassname; return result; } else { return false; } //--> KFormDesigner::EditRichTextAction(args.container, label, 0, this).trigger(); //2.0 moved to EditRichTextAction: //2.0 if (editRichText(label, text)) { //2.0 changeProperty(args.container->form(), label, "textFormat", "RichText", ); //2.0 changeProperty("text", text, args.container->form()); //2.0 } //2.0 if (args.classname == "KexiDBLabel") //2.0 args.widget->resize(args.widget->sizeHint()); } else { args.text = label->text(); args.alignment = label->alignment(); args.multiLine = label->wordWrap(); } return true; } #ifndef KEXI_NO_SUBFORM else if (args.classname == "KexiDBSubForm") { //! @todo // open the form in design mode KexiDBSubForm *subform = static_cast(args.widget); args.execute = false; if (KexiMainWindowIface::global()) { bool openingCancelled; KexiMainWindowIface::global()->openObject( "org.kexi-project.form", subform->formName(), Kexi::DesignViewMode, openingCancelled); } return true; } #endif #if 0 else if ( args.classname == "KexiDBDateEdit" || args.classname == "KexiDBDateTimeEdit" || args.classname == "KexiDBTimeEdit" /*|| classname == "KexiDBIntSpinBox" || classname == "KexiDBDoubleSpinBox"*/) { disableFilter(w, container); return true; } #endif else if (args.classname == "KexiDBAutoField") { if (static_cast(args.widget)->hasAutoCaption()) return false; // caption is auto, abort editing QLabel *label = static_cast(args.widget)->label(); args.text = label->text(); args.widget = label; args.geometry = label->geometry(); args.alignment = label->alignment(); //2.0 createEditor(classname, label->text(), label, container, label, ); return true; } else if (args.classname == "KexiDBCheckBox") { KexiDBCheckBox *cb = static_cast(args.widget); QStyleOption option; option.initFrom(cb); QRect r(cb->geometry()); r.setLeft( r.left() + 2 + cb->style()->subElementRect(QStyle::SE_CheckBoxIndicator, &option, cb).width()); args.text = cb->text(); args.geometry = r; //2.0 createEditor(classname, cb->text(), cb, container, r, Qt::AlignAuto); return true; } else if (args.classname == "KexiDBImageBox") { KexiDBImageBox *image = static_cast(args.widget); image->insertFromFile(); args.execute = false; return true; } // else if (args.classname == "QPushButton" || args.classname == "KPushButton" || args.classname == "KexiPushButton") { // } return false; } bool KexiDBFactory::previewWidget(const QByteArray &, QWidget *, KFormDesigner::Container *) { return false; } bool KexiDBFactory::clearWidgetContent(const QByteArray & /*classname*/, QWidget *w) { //! @todo this code should not be copied here but //! just inherited StdWidgetFactory::clearWidgetContent() should be called KexiFormDataItemInterface *iface = dynamic_cast(w); if (iface) iface->clear(); return true; } bool KexiDBFactory::isPropertyVisibleInternal(const QByteArray& classname, QWidget *w, const QByteArray& property, bool isTopLevel) { //general bool ok = true; if (classname == "KexiPushButton") { ok = property != "isDragEnabled" #ifdef KEXI_NO_UNFINISHED && property != "onClickAction" /*! @todo reenable */ && property != "onClickActionOption" /*! @todo reenable */ && property != "iconSet" /*! @todo reenable */ && property != "iconSize" /*! @todo reenable */ && property != "stdItem" /*! @todo reenable stdItem */ #endif ; } else if (classname == "KexiDBCommandLinkButton") { ok = property != "isDragEnabled" #ifdef KEXI_NO_UNFINISHED && property != "onClickAction" /*! @todo reenable */ && property != "onClickActionOption" /*! @todo reenable */ && property != "iconSet" /*! @todo reenable */ && property != "iconSize" /*! @todo reenable */ && property != "stdItem" /*! @todo reenable stdItem */ #endif ; } else if (classname == "KexiDBSlider") { ok = property != "focusPolicy"; } else if (classname == "KexiDBProgressBar") { ok = property != "focusPolicy"; } else if (classname == "KexiDBLineEdit") ok = property != "urlDropsEnabled" && property != "vAlign" && property != "echoMode" #ifdef KEXI_NO_UNFINISHED && property != "inputMask" && property != "maxLength" //!< we may want to integrate this with db schema #endif ; else if (classname == "KexiDBComboBox") ok = property != "autoCaption" && property != "labelPosition" && property != "widgetType" && property != "fieldTypeInternal" && property != "fieldCaptionInternal"; //hide properties that come with KexiDBAutoField else if (classname == "KexiDBTextEdit") ok = property != "undoDepth" && property != "undoRedoEnabled" //always true! && property != "dragAutoScroll" //always true! && property != "overwriteMode" //always false! && property != "resizePolicy" && property != "autoFormatting" //too complex && property != "documentTitle" && property != "cursorWidth" #ifdef KEXI_NO_UNFINISHED && property != "paper" #endif && property != "textInteractionFlags" //! @todo support textInteractionFlags property of QLabel and QTextEdit ; #ifndef KEXI_NO_SUBFORM else if (classname == "KexiDBSubForm") ok = property != "dragAutoScroll" && property != "resizePolicy" && property != "focusPolicy"; #endif else if (classname == "KexiDBForm") ok = property != "iconText" && property != "geometry" /*nonsense for toplevel widget; for size, "size" property is used*/; else if (classname == "KexiDBLabel") ok = property != "focusPolicy" && property != "textInteractionFlags"; //! @todo support textInteractionFlags property of QLabel else if (classname == "KexiDBAutoField") { if (!isTopLevel && property == "caption") return true; //force if (property == "fieldTypeInternal" || property == "fieldCaptionInternal" //! @todo unhide in 2.0 || property == "widgetType") return false; ok = property != "text"; /* "text" is not needed as "caption" is used instead */ } else if (classname == "KexiDBImageBox") { ok = property != "font" && property != "wordbreak" && property != "pixmapId"; } else if (classname == "KexiDBCheckBox") { //hide text property if the widget is a child of an autofield beause there's already "caption" for this purpose if (property == "text" && w && dynamic_cast(w->parentWidget())) return false; ok = property != "autoRepeat"; } return ok && KexiDBFactoryBase::isPropertyVisibleInternal(classname, w, property, isTopLevel); } bool KexiDBFactory::propertySetShouldBeReloadedAfterPropertyChange(const QByteArray& classname, QWidget *w, const QByteArray& property) { Q_UNUSED(classname); Q_UNUSED(w); if (property == "fieldTypeInternal" || property == "widgetType") return true; return false; } bool KexiDBFactory::changeInlineText(KFormDesigner::Form *form, QWidget *widget, const QString &text, QString &oldText) { //2.0 if (!form) //2.0 return false; //2.0 if (!form->selectedWidget()) //2.0 return false; //2.0 QByteArray n(form->selectedWidget()->metaObject()->className()); const QByteArray n(widget->metaObject()->className()); // QWidget *w = WidgetFactory::widget(); if (n == "KexiDBAutoField") { oldText = widget->property("caption").toString(); changeProperty(form, widget, "caption", text); return true; } //! @todo check field's geometry return false; } void KexiDBFactory::resizeEditor(QWidget *editor, QWidget *w, const QByteArray &classname) { //QSize s = widget->size(); //QPoint p = widget->pos(); if (classname == "KexiDBAutoField") editor->setGeometry(static_cast(w)->label()->geometry()); } void KexiDBFactory::slotImageBoxIdChanged(KexiBLOBBuffer::Id_t id) { KexiFormView *formView = KexiUtils::findParent((QWidget*)sender()); if (formView) { changeProperty(formView->form(), formView, "pixmapId", (uint)/*! @todo unsafe */id); formView->setUnsavedLocalBLOB(formView->form()->selectedWidget(), id); } } K_EXPORT_KEXI_FORM_WIDGET_FACTORY_PLUGIN(KexiDBFactory, kexidbwidgets) #include "kexidbfactory.moc" diff --git a/kexi/plugins/forms/kexiformmanager.cpp b/kexi/plugins/forms/kexiformmanager.cpp index 521dfb62e30..0d78dff301c 100644 --- a/kexi/plugins/forms/kexiformmanager.cpp +++ b/kexi/plugins/forms/kexiformmanager.cpp @@ -1,566 +1,567 @@ /* This file is part of the KDE project Copyright (C) 2005-2011 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kexiformmanager.h" #include "widgets/kexidbform.h" #include "widgets/kexidbautofield.h" #include "kexiformscrollview.h" #include "kexiformview.h" #include "kexidatasourcepage.h" #include #include #include #include #include #include #include //2.0 #include //2.0 #include #include #include #include #include #include #include #include #include #include #include #include #include class KexiFormManagerPrivate { public: KexiFormManagerPrivate() : part(0) , q(this) { features = KFormDesigner::Form::NoFeatures; widgetActionGroup = new KFormDesigner::ActionGroup(&q); #ifdef KFD_SIGSLOTS dragConnectionAction = 0; #endif widgetTree = 0; collection = 0; } ~KexiFormManagerPrivate() { } KexiFormPart* part; KFormDesigner::WidgetLibrary* lib; KFormDesigner::ActionGroup* widgetActionGroup; KFormDesigner::WidgetTreeWidget *widgetTree; KActionCollection *collection; KFormDesigner::Form::Features features; KToggleAction *pointerAction; #ifdef KFD_SIGSLOTS KToggleAction *dragConnectionAction; #endif KToggleAction *snapToGridAction; KexiFormManager q; }; K_GLOBAL_STATIC(KexiFormManagerPrivate, g_private) KexiFormManager* KexiFormManager::self() { return &g_private->q; } KexiFormManager::KexiFormManager(KexiFormManagerPrivate *p) : QObject() , d( p ) { //2.0 unused m_emitSelectionSignalsUpdatesPropertySet = true; KexiCustomPropertyFactory::init(); } KexiFormManager::~KexiFormManager() { } void KexiFormManager::init(KexiFormPart *part, KFormDesigner::WidgetTreeWidget *widgetTree) { /* @todo add configuration for supported factory groups */ QStringList supportedFactoryGroups; supportedFactoryGroups += "kexi"; d->lib = new KFormDesigner::WidgetLibrary(this, supportedFactoryGroups); d->lib->setAdvancedPropertiesVisible(false); connect(d->lib, SIGNAL(widgetCreated(QWidget*)), this, SLOT(slotWidgetCreatedByFormsLibrary(QWidget*))); connect(d->lib, SIGNAL(widgetActionToggled(const QByteArray&)), this, SLOT(slotWidgetActionToggled(const QByteArray&))); d->part = part; KActionCollection *col = /*tmp*/ new KActionCollection(this); // 2.0 d->part->actionCollectionForMode(Kexi::DesignViewMode); if (col) { createActions( col ); //connect actions provided by widget factories //moved from KexiFormPart connect(col->action("widget_assign_action"), SIGNAL(activated()), this, SLOT(slotAssignAction())); } d->widgetTree = widgetTree; if (d->widgetTree) { #ifdef __GNUC__ #warning "Port this: connect()" #else #pragma WARNING( Port this: connect() ) #endif #ifdef __GNUC__ #warning "Port code related to KFormDesigner::FormManager::m_treeview here" #else #pragma WARNING( Port code related to KFormDesigner::FormManager::m_treeview here ) #endif //todo connect(m_propSet, SIGNAL(widgetNameChanged(const QByteArray&, const QByteArray&)), //todo m_treeview, SLOT(renameItem(const QByteArray&, const QByteArray&))); } } //moved from KFormDesigner::FormManager KFormDesigner::ActionGroup* KexiFormManager::widgetActionGroup() const { return d->widgetActionGroup; } //moved from KFormDesigner::FormManager void KexiFormManager::createActions(KActionCollection* collection) { d->collection = collection; // KXMLGUIClient* client = (KXMLGUIClient*)d->collection->parentGUIClient(); d->lib->createWidgetActions(d->widgetActionGroup); //! @todo insertWidget() slot? //2.0 d->lib->createWidgetActions(client, d->collection, //2.0 this, SLOT(insertWidget(const QByteArray &))); #ifdef KFD_SIGSLOTS if (d->features & KFormDesigner::Form::EnableConnections) { // nothing } else { d->dragConnectionAction = new KToggleAction( KIcon("signalslot"), i18n("Connect Signals/Slots"), d->collection); d->dragConnectionAction->setObjectName("drag_connection"); // d->widgetActionGroup->addAction(d->dragConnectionAction); connect(d->dragConnectionAction, SIGNAL(triggered()), this, SLOT(startCreatingConnection())); d->dragConnectionAction->setChecked(false); } #endif d->pointerAction = new KToggleAction( KIcon("mouse_pointer"), i18n("Pointer"), d->collection); d->pointerAction->setObjectName("edit_pointer"); d->widgetActionGroup->addAction(d->pointerAction); connect(d->pointerAction, SIGNAL(triggered()), this, SLOT(slotPointerClicked())); d->pointerAction->setChecked(true); d->snapToGridAction = new KToggleAction( i18n("Snap to Grid"), d->collection); d->snapToGridAction->setObjectName("snap_to_grid"); // d->widgetActionGroup->addAction(d->snapToGridAction); // d->snapToGridAction->setChecked(true); #if 0 // 2.0: todo // Create the Style selection action (with a combo box in toolbar and submenu items) KSelectAction *styleAction = new KSelectAction( i18n("Style"), d->collection); styleAction->setObjectName("change_style"); connect(styleAction, SIGNAL(triggered()), this, SLOT(slotStyle())); styleAction->setEditable(false); //js: unused? KGlobalGroup cg = KGlobal::config()->group("General"); QString currentStyle(kapp->style()->objectName().toLower()); const QStringList styles = QStyleFactory::keys(); styleAction->setItems(styles); styleAction->setCurrentItem(0); QStringList::ConstIterator endIt = styles.constEnd(); int idx = 0; for (QStringList::ConstIterator it = styles.constBegin(); it != endIt; ++it, ++idx) { if ((*it).toLower() == currentStyle) { styleAction->setCurrentItem(idx); break; } } styleAction->setToolTip(i18n("Set the current view style.")); styleAction->setMenuAccelsEnabled(true); #endif d->lib->addCustomWidgetActions(d->collection); #ifdef KEXI_DEBUG_GUI KConfigGroup generalGroup(KGlobal::config()->group("General")); if (generalGroup.readEntry("ShowInternalDebugger", false)) { KAction *a = new KAction(KIcon("run-build-file"), i18n("Show Form UI Code"), this); d->collection->addAction("show_form_ui", a); a->setShortcut(Qt::CTRL + Qt::Key_U); connect(a, SIGNAL(triggered()), this, SLOT(showFormUICode())); } #endif //! @todo move elsewhere { // (from obsolete kexiformpartinstui.rc) QStringList formActions; formActions << "edit_pointer" << QString() //sep #ifndef KEXI_NO_AUTOFIELD_WIDGET << "library_widget_KexiDBAutoField" #endif << "library_widget_KexiDBLabel" << "library_widget_KexiDBLineEdit" << "library_widget_KexiDBTextEdit" << "library_widget_KexiDBComboBox" << "library_widget_KexiDBCheckBox" << "library_widget_KexiDBImageBox" << QString() //sep << "library_widget_KPushButton" << QString() //sep << "library_widget_KexiFrame" << "library_widget_QGroupBox" << "library_widget_KFDTabWidget" << QString() //sep << "library_widget_Line" #ifndef KEXI_NO_FORM_LAYOUTS << "library_widget_Spacer" #endif #ifndef KEXI_NO_FORM_SPRING_ELEMENT << "library_widget_Spring" << QString() //sep #endif #ifdef CAN_USE_QTWEBKIT << "library_widget_WebBrowserWidget" #endif #ifdef CAN_USE_MARBLE << "library_widget_MapBrowserWidget" #endif << "library_widget_KexiDBSlider" << "library_widget_KexiDBProgressBar" << "library_widget_KexiDBCommandLinkButton" + << "library_widget_KexiDBDatePicker" << QString() //sep ; KexiMainWindowIface *win = KexiMainWindowIface::global(); foreach( const QString& actionName_, formActions ) { QAction *a; const QString actionName(actionName_.startsWith(':') ? actionName_.mid(1) : actionName_); if (actionName.isEmpty()) { a = new QAction(this); a->setSeparator(true); } else { a = d->widgetActionGroup->action(actionName); } if (actionName_.startsWith(':')) { // icon only KexiSmallToolButton *btn = new KexiSmallToolButton(a, win->toolBar("form")); btn->setToolButtonStyle(Qt::ToolButtonIconOnly); win->appendWidgetToToolbar("form", btn); } else { win->addToolBarAction("form", a); } } QSet iconOnlyActions; iconOnlyActions << "show_form_ui"; const QList actions( d->collection->actions() ); foreach( QAction *a, actions ) { if (iconOnlyActions.contains(a->objectName())) { // icon only KexiSmallToolButton *btn = new KexiSmallToolButton(a, win->toolBar("form")); btn->setToolButtonStyle(Qt::ToolButtonIconOnly); win->appendWidgetToToolbar("form", btn); } else { win->addToolBarAction("form", a); } } } } // moved from KexiFormPart void KexiFormManager::slotWidgetCreatedByFormsLibrary(QWidget* widget) { QList _signals(KexiUtils::methodsForMetaObject( widget->metaObject(), QMetaMethod::Signal)); if (!_signals.isEmpty()) { const char *handleDragMoveEventSignal = "handleDragMoveEvent(QDragMoveEvent*)"; const char *handleDropEventSignal = "handleDropEvent(QDropEvent*)"; KexiFormView *formView = KexiUtils::findParent(widget); foreach(const QMetaMethod& method, _signals) { if (0 == qstrcmp(method.signature(), handleDragMoveEventSignal)) { kDebug() << method.signature(); if (formView) { connect(widget, SIGNAL(handleDragMoveEvent(QDragMoveEvent*)), formView, SLOT(slotHandleDragMoveEvent(QDragMoveEvent*))); } } else if (0 == qstrcmp(method.signature(), handleDropEventSignal)) { kDebug() << method.signature(); if (formView) { connect(widget, SIGNAL(handleDropEvent(QDropEvent*)), formView, SLOT(slotHandleDropEvent(QDropEvent*))); } } } } } void KexiFormManager::slotWidgetActionToggled(const QByteArray& action) { KexiFormView* fv = activeFormViewWidget(); if (fv) { fv->form()->enterWidgetInsertingState(action); } } KFormDesigner::WidgetLibrary* KexiFormManager::library() const { return d->lib; } QAction* KexiFormManager::action(const char* name) { KActionCollection *col = d->part->actionCollectionForMode(Kexi::DesignViewMode); if (!col) return 0; QString n(translateName(name)); QAction *a = col->action(n); if (a) return a; if (activeFormViewWidget()) { a = KexiMainWindowIface::global()->actionCollection()->action(n); if (a) return a; } return d->collection->action(name); } KexiFormView* KexiFormManager::activeFormViewWidget() const { KexiWindow *currentWindow = KexiMainWindowIface::global()->currentWindow(); if (!currentWindow) return 0; KexiView *currentView = currentWindow->selectedView(); KFormDesigner::Form *form; if (!currentView || currentView->viewMode()!=Kexi::DesignViewMode || !dynamic_cast(currentView) || !(form = dynamic_cast(currentView)->form()) ) { return 0; } KexiDBForm *dbform = dynamic_cast(form->formWidget()); KexiFormScrollView *scrollViewWidget = dynamic_cast(dbform->dataAwareObject()); if (!scrollViewWidget) return 0; return dynamic_cast(scrollViewWidget->parent()); } void KexiFormManager::enableAction(const char* name, bool enable) { KexiFormView* formViewWidget = activeFormViewWidget(); if (!formViewWidget) return; formViewWidget->setAvailable(translateName(name).toLatin1(), enable); } void KexiFormManager::setFormDataSource(const QString& partClass, const QString& name) { KexiFormView* formViewWidget = activeFormViewWidget(); if (!formViewWidget) return; KexiDBForm* formWidget = dynamic_cast(formViewWidget->form()->widget()); if (!formWidget) return; QString oldDataSourcePartClass(formWidget->dataSourcePartClass()); QString oldDataSource(formWidget->dataSource()); if (partClass != oldDataSourcePartClass || name != oldDataSource) { QHash propValues; propValues.insert("dataSource", name); propValues.insert("dataSourcePartClass", partClass); KFormDesigner::PropertyCommandGroup *group = new KFormDesigner::PropertyCommandGroup( // *formViewWidget->form(), i18n("Set Form's Data Source to \"%1\"", name)); formViewWidget->form()->createPropertyCommandsInDesignMode( formWidget, propValues, group, true /*addToActiveForm*/); } } void KexiFormManager::setDataSourceFieldOrExpression( const QString& string, const QString& caption, KexiDB::Field::Type type) { KexiFormView* formViewWidget = activeFormViewWidget(); if (!formViewWidget) return; KoProperty::Set& set = formViewWidget->form()->propertySet(); if (!set.contains("dataSource")) return; set["dataSource"].setValue(string); if (set.propertyValue("autoCaption", false).toBool()) { set.changePropertyIfExists("fieldCaptionInternal", caption); } if (set.propertyValue("widgetType").toString() == "Auto") { set.changePropertyIfExists("fieldTypeInternal", type); } } void KexiFormManager::insertAutoFields(const QString& sourcePartClass, const QString& sourceName, const QStringList& fields) { KexiFormView* formViewWidget = activeFormViewWidget(); if (!formViewWidget || !formViewWidget->form() || !formViewWidget->form()->activeContainer()) return; formViewWidget->insertAutoFields(sourcePartClass, sourceName, fields, formViewWidget->form()->activeContainer()); } void KexiFormManager::slotHistoryCommandExecuted(KFormDesigner::Command *command) { // const KFormDesigner::CommandGroup *group = dynamic_cast(command); if (command->childCount() == 2) { KexiFormView* formViewWidget = activeFormViewWidget(); if (!formViewWidget) return; KexiDBForm* formWidget = dynamic_cast(formViewWidget->form()->widget()); if (!formWidget) return; const KFormDesigner::PropertyCommand* pc1 = dynamic_cast(command->child(0)); const KFormDesigner::PropertyCommand* pc2 = dynamic_cast(command->child(1)); if (pc1 && pc2 && pc1->propertyName() == "dataSource" && pc2->propertyName() == "dataSourcePartClass") { const QHash::const_iterator it1(pc1->oldValues().constBegin()); const QHash::const_iterator it2(pc2->oldValues().constBegin()); if (it1.key() == formWidget->objectName() && it2.key() == formWidget->objectName()) d->part->dataSourcePage()->setFormDataSource( formWidget->dataSourcePartClass(), formWidget->dataSource()); } } } // moved from FormManager void KexiFormManager::showFormUICode() { #ifdef KEXI_DEBUG_GUI KexiFormView* formView = activeFormViewWidget(); if (!formView) return; formView->form()->resetInlineEditor(); QString uiCode; const int indent = 2; if (!KFormDesigner::FormIO::saveFormToString(formView->form(), uiCode, indent)) { //! @todo show err? return; } KPageDialog uiCodeDialog; uiCodeDialog.setFaceType(KPageDialog::Tabbed); uiCodeDialog.setModal(true); uiCodeDialog.setWindowTitle(i18n("Form's UI Code")); uiCodeDialog.setButtons(KDialog::Close); uiCodeDialog.resize(700, 600); KTextEdit *currentUICodeDialogEditor = new KTextEdit(&uiCodeDialog); uiCodeDialog.addPage(currentUICodeDialogEditor, i18n("Current")); currentUICodeDialogEditor->setReadOnly(true); QFont f(currentUICodeDialogEditor->font()); f.setFamily("courier"); currentUICodeDialogEditor->setFont(f); KTextEdit *originalUICodeDialogEditor = new KTextEdit(&uiCodeDialog); uiCodeDialog.addPage(originalUICodeDialogEditor, i18n("Original")); originalUICodeDialogEditor->setReadOnly(true); originalUICodeDialogEditor->setFont(f); currentUICodeDialogEditor->setPlainText(uiCode); //indent and set our original doc as well: QDomDocument doc; doc.setContent(formView->form()->m_recentlyLoadedUICode); originalUICodeDialogEditor->setPlainText(doc.toString(indent)); uiCodeDialog.exec(); #endif } void KexiFormManager::slotAssignAction() { KexiFormView* formView = activeFormViewWidget(); if (!formView) return; KFormDesigner::Form *form = formView->form(); KexiDBForm *dbform = 0; if (form->mode() != KFormDesigner::Form::DesignMode || !(dbform = dynamic_cast(form->formWidget()))) { return; } KoProperty::Set& set = form->propertySet(); KexiFormEventAction::ActionData data; const KoProperty::Property &onClickActionProp = set.property("onClickAction"); if (!onClickActionProp.isNull()) data.string = onClickActionProp.value().toString(); const KoProperty::Property &onClickActionOptionProp = set.property("onClickActionOption"); if (!onClickActionOptionProp.isNull()) data.option = onClickActionOptionProp.value().toString(); KexiFormScrollView *scrollViewWidget = dynamic_cast(dbform->dataAwareObject()); if (!scrollViewWidget) return; KexiFormView* formViewWidget = dynamic_cast(scrollViewWidget->parent()); if (!formViewWidget) return; KexiActionSelectionDialog dlg(dbform, data, set.property("objectName").value().toString()); if (dlg.exec() == QDialog::Accepted) { data = dlg.currentAction(); //update property value set.changeProperty("onClickAction", data.string); set.changeProperty("onClickActionOption", data.option); } } void KexiFormManager::slotPointerClicked() { KexiFormView* formView = activeFormViewWidget(); if (!formView) return; formView->form()->enterWidgetSelectingState(); } #include "kexiformmanager.moc" diff --git a/kexi/plugins/forms/widgets/kexidbdatepicker.cpp b/kexi/plugins/forms/widgets/kexidbdatepicker.cpp new file mode 100644 index 00000000000..82d88ca5b29 --- /dev/null +++ b/kexi/plugins/forms/widgets/kexidbdatepicker.cpp @@ -0,0 +1,115 @@ +/* This file is part of the KDE project + Copyright (C) 2005 Cedric Pasteur + Copyright (C) 2004-2005 Jarosław Staniek + Copyright (C) 2012 Oleg Kukharchuk + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "kexidbdatepicker.h" +#include "klineedit.h" +#include + +KexiDBDatePicker::KexiDBDatePicker(QWidget *parent) + : KDatePicker(parent) + , KexiFormDataItemInterface() + , m_dateEditFocused(false) +{ + connect(this, SIGNAL(dateChanged(QDate)), this, SLOT(slotValueChanged())); + connect(this, SIGNAL(dateEntered(QDate)), this, SLOT(slotValueChanged())); +} + +KexiDBDatePicker::~KexiDBDatePicker() +{ +} + +void KexiDBDatePicker::setInvalidState(const QString& displayText) +{ + m_invalidState = true; + setEnabled(false); + setReadOnly(true); +//! @todo move this to KexiDataItemInterface::setInvalidStateInternal() ? + if (focusPolicy() & Qt::TabFocus) + setFocusPolicy(Qt::ClickFocus); + KDatePicker::setDate(QDate()); +} + +void KexiDBDatePicker::setEnabled(bool enabled) +{ + // prevent the user from reenabling the widget when it is in invalid state + if (enabled && m_invalidState) + return; + KDatePicker::setEnabled(enabled); +} + +void KexiDBDatePicker::setValueInternal(const QVariant&, bool) +{ + KDatePicker::setDate(m_origValue.toDate()); +} + +QVariant KexiDBDatePicker::value() +{ + return KDatePicker::date(); +} + +void KexiDBDatePicker::slotValueChanged() +{ + signalValueChanged(); +} + +bool KexiDBDatePicker::valueIsNull() +{ + return !KDatePicker::date().isValid(); +} + +bool KexiDBDatePicker::valueIsEmpty() +{ + return !KDatePicker::date().isValid(); +} + +bool KexiDBDatePicker::isReadOnly() const +{ + return m_readOnly; +} + +void KexiDBDatePicker::setReadOnly(bool set) +{ + m_readOnly = set; +} + +QWidget* KexiDBDatePicker::widget() +{ + return this; +} + +bool KexiDBDatePicker::cursorAtStart() +{ + const KLineEdit *lineEdit=findChild(); + return lineEdit && lineEdit->hasFocus() && lineEdit->cursorPosition() == 0; +} + +bool KexiDBDatePicker::cursorAtEnd() +{ + const KLineEdit *lineEdit=findChild(); + return lineEdit && lineEdit->hasFocus() && lineEdit->cursorPosition() == lineEdit->text().length(); + + +void KexiDBDatePicker::clear() +{ + KDatePicker::setDate(QDate()); +} + +#include "kexidbdatepicker.moc" diff --git a/kexi/plugins/forms/widgets/kexidbdatepicker.h b/kexi/plugins/forms/widgets/kexidbdatepicker.h new file mode 100644 index 00000000000..817b9615715 --- /dev/null +++ b/kexi/plugins/forms/widgets/kexidbdatepicker.h @@ -0,0 +1,96 @@ +/* This file is part of the KDE project + Copyright (C) 2005 Cedric Pasteur + Copyright (C) 2004-2005 Jarosław Staniek + Copyright (C) 2012 Oleg Kukharchuk + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef KexiDBDatePicker_H +#define KexiDBDatePicker_H + +#include +#include +#include + +//! @short A db-aware DatePicker +class KEXIFORMUTILS_EXPORT KexiDBDatePicker : public KDatePicker, + public KexiFormDataItemInterface, + public KFormDesigner::FormWidgetInterface +{ + Q_OBJECT + Q_PROPERTY(QString dataSource READ dataSource WRITE setDataSource) + Q_PROPERTY(QString dataSourcePartClass READ dataSourcePartClass WRITE setDataSourcePartClass) + Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) + +public: + KexiDBDatePicker(QWidget *parent); + virtual ~KexiDBDatePicker(); + + inline QString dataSource() const { + return KexiFormDataItemInterface::dataSource(); + } + inline QString dataSourcePartClass() const { + return KexiFormDataItemInterface::dataSourcePartClass(); + } + virtual QVariant value(); + virtual void setInvalidState(const QString& displayText); + + //! \return true if editor's value is null (not empty) + //! Used for checking if a given constraint within table of form is met. + virtual bool valueIsNull(); + + //! \return true if editor's value is empty (not necessary null). + //! Only few data types can accept "EMPTY" property + //! (use KexiDB::Field::hasEmptyProperty() to check this). + //! Used for checking if a given constraint within table or form is met. + virtual bool valueIsEmpty(); + + /*! \return 'readOnly' flag for this widget. */ + virtual bool isReadOnly() const; + + /*! \return the view widget of this item, e.g. line edit widget. */ + virtual QWidget* widget(); + + virtual bool cursorAtStart(); + virtual bool cursorAtEnd(); + virtual void clear(); + + virtual void setEnabled(bool enabled); + +public slots: + inline void setDataSource(const QString &ds) { + KexiFormDataItemInterface::setDataSource(ds); + } + inline void setDataSourcePartClass(const QString &partClass) { + KexiFormDataItemInterface::setDataSourcePartClass(partClass); + } + void slotValueChanged(); + virtual void setReadOnly(bool set); + +protected: + virtual void setValueInternal(const QVariant& add, bool removeOld); +// virtual bool eventFilter(QObject *o, QEvent *e); + +private: + bool m_invalidState; + bool m_cursorAtEnd; + bool m_cursorAtStart; + bool m_readOnly; + bool m_dateEditFocused; +}; + +#endif