diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
commit | 8362bf63dea22bbf6736609b0f49c152f975eb63 (patch) | |
tree | 0eea3928e39e50fae91d4e68b21b1e6cbae25604 /kexi/formeditor/factories | |
download | koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip |
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kexi/formeditor/factories')
-rw-r--r-- | kexi/formeditor/factories/Makefile.am | 20 | ||||
-rw-r--r-- | kexi/formeditor/factories/containerfactory.cpp | 936 | ||||
-rw-r--r-- | kexi/formeditor/factories/containerfactory.h | 271 | ||||
-rw-r--r-- | kexi/formeditor/factories/kformdesigner_containers.desktop | 53 | ||||
-rw-r--r-- | kexi/formeditor/factories/kformdesigner_stdwidgets.desktop | 55 | ||||
-rw-r--r-- | kexi/formeditor/factories/stdwidgetfactory.cpp | 984 | ||||
-rw-r--r-- | kexi/formeditor/factories/stdwidgetfactory.h | 99 |
7 files changed, 2418 insertions, 0 deletions
diff --git a/kexi/formeditor/factories/Makefile.am b/kexi/formeditor/factories/Makefile.am new file mode 100644 index 00000000..e19bf6b3 --- /dev/null +++ b/kexi/formeditor/factories/Makefile.am @@ -0,0 +1,20 @@ +include $(top_srcdir)/kexi/Makefile.global + +INCLUDES = -I$(top_srcdir)/kexi -I$(top_srcdir)/kexi/formeditor \ + -I$(top_srcdir)/kexi/core \ + -I$(top_srcdir)/lib -I$(top_srcdir)/lib/koproperty -I$(top_srcdir)/lib/kofficecore $(all_includes) +kde_module_LTLIBRARIES = kformdesigner_containers.la kformdesigner_stdwidgets.la +kformdesigner_containers_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) $(VER_INFO) -module +kformdesigner_containers_la_SOURCES = containerfactory.cpp +kformdesigner_containers_la_LIBADD = $(top_builddir)/kexi/formeditor/libkformdesigner.la + +kformdesigner_stdwidgets_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) $(VER_INFO) -module +kformdesigner_stdwidgets_la_SOURCES = stdwidgetfactory.cpp +kformdesigner_stdwidgets_la_LIBADD = $(top_builddir)/kexi/formeditor/libkformdesigner.la + + +servicesdir=$(kde_servicesdir)/kformdesigner +services_DATA = kformdesigner_containers.desktop kformdesigner_stdwidgets.desktop + +METASOURCES = AUTO + diff --git a/kexi/formeditor/factories/containerfactory.cpp b/kexi/formeditor/factories/containerfactory.cpp new file mode 100644 index 00000000..d098c290 --- /dev/null +++ b/kexi/formeditor/factories/containerfactory.cpp @@ -0,0 +1,936 @@ +/* This file is part of the KDE project + Copyright (C) 2003 Lucijan Busch <lucijan@kde.org> + Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr> + Copyright (C) 2006-2007 Jaroslaw Staniek <js@iidea.pl> + + 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 <qwidgetstack.h> +#include <qframe.h> +#include <qbuttongroup.h> +#include <qwidget.h> +#include <qhbox.h> +#include <qvbox.h> +#include <qstring.h> +#include <qpopupmenu.h> +#include <qdom.h> +#include <qevent.h> +#include <qobjectlist.h> +#include <qpainter.h> +#include <qvaluevector.h> +#include <qfileinfo.h> +#include <qscrollview.h> +#include <qtabbar.h> +#include <qsplitter.h> +#include <qlayout.h> + +#include <kiconloader.h> +#include <kgenericfactory.h> +#include <ktextedit.h> +#include <klineedit.h> +#include <klocale.h> +#include <kdebug.h> +#include <kdeversion.h> + +#include "containerfactory.h" +#include "container.h" +#include "form.h" +#include "formIO.h" +#include "objecttree.h" +#include "commands.h" +#include "formmanager.h" +#include "widgetlibrary.h" +#include <formeditor/utils.h> + +#if KDE_VERSION < KDE_MAKE_VERSION(3,1,9) +# define KInputDialog QInputDialog +# include <qinputdialog.h> +# include <qlineedit.h> +#else +# include <kinputdialog.h> +#endif + +ContainerWidget::ContainerWidget(QWidget *parent, const char *name) + : QWidget(parent, name) +{ +} + +ContainerWidget::~ContainerWidget() +{ +} + +QSize ContainerWidget::sizeHint() const +{ + return QSize(30,30); //default +} + +void ContainerWidget::dragMoveEvent( QDragMoveEvent *e ) +{ + QWidget::dragMoveEvent(e); + emit handleDragMoveEvent(e); +} + +void ContainerWidget::dropEvent( QDropEvent *e ) +{ + QWidget::dropEvent(e); + emit handleDropEvent(e); +} + +//////////////////////// + +GroupBox::GroupBox(const QString & title, QWidget *parent, const char *name) + : QGroupBox(title, parent, name) +{ +} + +GroupBox::~GroupBox() +{ +} + +void GroupBox::dragMoveEvent( QDragMoveEvent *e ) +{ + QGroupBox::dragMoveEvent(e); + emit handleDragMoveEvent(e); +} + +void GroupBox::dropEvent( QDropEvent *e ) +{ + QGroupBox::dropEvent(e); + emit handleDropEvent(e); +} + +//////////////////////// + +KFDTabWidget::KFDTabWidget(QWidget *parent, const char *name) + : KFormDesigner::TabWidget(parent, name) +{ +} + +KFDTabWidget::~KFDTabWidget() +{ +} + +QSize +KFDTabWidget::sizeHint() const +{ + QSize s(30,30); // default min size + for(int i=0; i < count(); i++) + s = s.expandedTo( KFormDesigner::getSizeFromChildren(page(i)) ); + + return s + QSize(10/*margin*/, tabBar()->height() + 20/*margin*/); +} + +void KFDTabWidget::dragMoveEvent( QDragMoveEvent *e ) +{ + TabWidgetBase::dragMoveEvent( e ); + if (dynamic_cast<ContainerWidget*>(currentPage())) + emit dynamic_cast<ContainerWidget*>(currentPage())->handleDragMoveEvent(e); + emit handleDragMoveEvent(e); +} + +void KFDTabWidget::dropEvent( QDropEvent *e ) +{ + TabWidgetBase::dropEvent( e ); + if (dynamic_cast<ContainerWidget*>(currentPage())) + emit dynamic_cast<ContainerWidget*>(currentPage())->handleDropEvent(e); + emit handleDropEvent(e); +} + +/// Various layout widgets /////////////////: + +HBox::HBox(QWidget *parent, const char *name) + : QFrame(parent, name), m_preview(false) +{} + +void +HBox::paintEvent(QPaintEvent *) +{ + if(m_preview) return; + QPainter p(this); + p.setPen(QPen(red, 2, Qt::DashLine)); + p.drawRect(1, 1, width()-1, height() - 1); +} + +VBox::VBox(QWidget *parent, const char *name) + : QFrame(parent, name), m_preview(false) +{} + +void +VBox::paintEvent(QPaintEvent *) +{ + if(m_preview) return; + QPainter p(this); + p.setPen(QPen(blue, 2, Qt::DashLine)); + p.drawRect(1, 1, width()-1, height() - 1); +} + +Grid::Grid(QWidget *parent, const char *name) + : QFrame(parent, name), m_preview(false) +{} + +void +Grid::paintEvent(QPaintEvent *) +{ + if(m_preview) return; + QPainter p(this); + p.setPen(QPen(darkGreen, 2, Qt::DashLine)); + p.drawRect(1, 1, width()-1, height() - 1); +} + +HFlow::HFlow(QWidget *parent, const char *name) + : QFrame(parent, name), m_preview(false) +{} + +void +HFlow::paintEvent(QPaintEvent *) +{ + if(m_preview) return; + QPainter p(this); + p.setPen(QPen(magenta, 2, Qt::DashLine)); + p.drawRect(1, 1, width()-1, height() - 1); +} + +VFlow::VFlow(QWidget *parent, const char *name) + : QFrame(parent, name), m_preview(false) +{} + +void +VFlow::paintEvent(QPaintEvent *) +{ + if(m_preview) return; + QPainter p(this); + p.setPen(QPen(cyan, 2, Qt::DashLine)); + p.drawRect(1, 1, width()-1, height() - 1); +} + +QSize +VFlow::sizeHint() const +{ + if(layout()) + return layout()->sizeHint(); + else + return QSize(700, 50); // default +} + +/////// Tab related KCommand (to allow tab creation/deletion undoing) + +InsertPageCommand::InsertPageCommand(KFormDesigner::Container *container, QWidget *parent) + : KCommand() +{ + m_containername = container->widget()->name(); + m_form = container->form(); + m_parentname = parent->name(); + m_pageid = -1; +} + +void +InsertPageCommand::execute() +{ + KFormDesigner::Container *container = m_form->objectTree()->lookup(m_containername)->container(); + QWidget *parent = m_form->objectTree()->lookup(m_parentname)->widget(); + if(m_name.isEmpty()) { + m_name = container->form()->objectTree()->generateUniqueName( + container->form()->library()->displayName("QWidget").latin1(), + /*!numberSuffixRequired*/false); + } + + QWidget *page = container->form()->library()->createWidget("QWidget", parent, m_name.latin1(), container); +// QWidget *page = new ContainerWidget(parent, m_name.latin1()); +// new KFormDesigner::Container(container, page, parent); + + QCString classname = parent->className(); + if(classname == "KFDTabWidget") + { + TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(parent); + QString n = i18n("Page %1").arg(tab->count() + 1); + tab->addTab(page, n); + tab->showPage(page); + + KFormDesigner::ObjectTreeItem *item = container->form()->objectTree()->lookup(m_name); + item->addModifiedProperty("title", n); + } + else if(classname == "QWidgetStack") + { + QWidgetStack *stack = (QWidgetStack*)parent; + stack->addWidget(page, m_pageid); + stack->raiseWidget(page); + m_pageid = stack->id(page); + + KFormDesigner::ObjectTreeItem *item = container->form()->objectTree()->lookup(m_name); + item->addModifiedProperty("id", stack->id(page)); + } +} + +void +InsertPageCommand::unexecute() +{ + QWidget *page = m_form->objectTree()->lookup(m_name)->widget(); + QWidget *parent = m_form->objectTree()->lookup(m_parentname)->widget(); + + KFormDesigner::WidgetList list; + list.append(page); + KCommand *com = new KFormDesigner::DeleteWidgetCommand(list, m_form); + + QCString classname = parent->className(); + if(classname == "KFDTabWidget") + { + TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(parent); + tab->removePage(page); + } + else if(classname == "QWidgetStack") + { + QWidgetStack *stack = (QWidgetStack*)parent; + int id = stack->id(page) - 1; + while(!stack->widget(id)) + id--; + + stack->raiseWidget(id); + stack->removeWidget(page); + } + + com->execute(); + delete com; +} + +QString +InsertPageCommand::name() const +{ + return i18n("Add Page"); +} + +/////// Sub forms ////////////////////////: + +SubForm::SubForm(QWidget *parent, const char *name) +: QScrollView(parent, name), m_form(0), m_widget(0) +{ + setFrameStyle(QFrame::WinPanel | QFrame::Sunken); + viewport()->setPaletteBackgroundColor(colorGroup().mid()); +} + +void +SubForm::setFormName(const QString &name) +{ + if(name.isEmpty()) + return; + + QFileInfo info(name); + if(!info.exists() + || (KFormDesigner::FormManager::self()->activeForm() + && (info.fileName() == KFormDesigner::FormManager::self()->activeForm()->filename()) ) ) + return; // we check if this is valid form + + // we create the container widget + delete m_widget; + m_widget = new QWidget(viewport(), "subform_widget"); +// m_widget->show(); + addChild(m_widget); + m_form = new KFormDesigner::Form( + KFormDesigner::FormManager::self()->activeForm()->library(), this->name()); + m_form->createToplevel(m_widget); + + // and load the sub form + KFormDesigner::FormIO::loadFormFromFile(m_form, m_widget, name); + m_form->setDesignMode(false); + + m_formName = name; + +} + +///// The factory ///////////////////////// + +ContainerFactory::ContainerFactory(QObject *parent, const char *, const QStringList &) + : KFormDesigner::WidgetFactory(parent, "containers") +{ + KFormDesigner::WidgetInfo *wBtnGroup = new KFormDesigner::WidgetInfo(this); + wBtnGroup->setPixmap("frame"); + wBtnGroup->setClassName("QButtonGroup"); + wBtnGroup->setName(i18n("Button Group")); + wBtnGroup->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.", "buttonGroup")); + wBtnGroup->setDescription(i18n("A simple container to group buttons")); + addClass(wBtnGroup); + + KFormDesigner::WidgetInfo *wTabWidget = new KFormDesigner::WidgetInfo(this); + wTabWidget->setPixmap("tabwidget"); + wTabWidget->setClassName("KFDTabWidget"); +#if KDE_VERSION >= KDE_MAKE_VERSION(3,1,9) + wTabWidget->addAlternateClassName("KTabWidget"); + wTabWidget->addAlternateClassName("QTabWidget"); +//tmp: wTabWidget->setSavingName("QTabWidget"); + wTabWidget->setSavingName("KTabWidget"); +#else + wTabWidget->setSavingName("QTabWidget"); +#endif + wTabWidget->setIncludeFileName("ktabwidget.h"); + wTabWidget->setName(i18n("Tab Widget")); + wTabWidget->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.", "tabWidget")); + wTabWidget->setDescription(i18n("A widget to display multiple pages using tabs")); + addClass(wTabWidget); + + KFormDesigner::WidgetInfo *wWidget = new KFormDesigner::WidgetInfo(this); + wWidget->setPixmap("frame"); + wWidget->setClassName("QWidget"); + wWidget->addAlternateClassName("ContainerWidget"); + wWidget->setName(i18n("Basic container")); + wWidget->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.", "container")); + wWidget->setDescription(i18n("An empty container with no frame")); + addClass(wWidget); + + KFormDesigner::WidgetInfo *wGroupBox = new KFormDesigner::WidgetInfo(this); + wGroupBox->setPixmap("groupbox"); + wGroupBox->setClassName("QGroupBox"); + wGroupBox->addAlternateClassName("GroupBox"); + wGroupBox->setName(i18n("Group Box")); + wGroupBox->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.", "groupBox")); + wGroupBox->setDescription(i18n("A container to group some widgets")); + addClass(wGroupBox); + + KFormDesigner::WidgetInfo *wFrame = new KFormDesigner::WidgetInfo(this); + wFrame->setPixmap("frame"); + wFrame->setClassName("QFrame"); + wFrame->setName(i18n("Frame")); + wFrame->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.", "frame")); + wFrame->setDescription(i18n("A simple frame container")); + addClass(wFrame); + + KFormDesigner::WidgetInfo *wWidgetStack = new KFormDesigner::WidgetInfo(this); + wWidgetStack->setPixmap("widgetstack"); + wWidgetStack->setClassName("QWidgetStack"); + wWidgetStack->setName(i18n("Widget Stack")); + wWidgetStack->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.", "widgetStack")); + wWidgetStack->setDescription(i18n("A container with multiple pages")); + addClass(wWidgetStack); + + KFormDesigner::WidgetInfo *wHBox = new KFormDesigner::WidgetInfo(this); + wHBox->setPixmap("frame"); + wHBox->setClassName("HBox"); + wHBox->setName(i18n("Horizontal Box")); + wHBox->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.", "horizontalBox")); + wHBox->setDescription(i18n("A simple container to group widgets horizontally")); + addClass(wHBox); + + KFormDesigner::WidgetInfo *wVBox = new KFormDesigner::WidgetInfo(this); + wVBox->setPixmap("frame"); + wVBox->setClassName("VBox"); + wVBox->setName(i18n("Vertical Box")); + wVBox->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.", "verticalBox")); + wVBox->setDescription(i18n("A simple container to group widgets vertically")); + addClass(wVBox); + + KFormDesigner::WidgetInfo *wGrid = new KFormDesigner::WidgetInfo(this); + wGrid->setPixmap("frame"); + wGrid->setClassName("Grid"); + wGrid->setName(i18n("Grid Box")); + wGrid->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.", "gridBox")); + wGrid->setDescription(i18n("A simple container to group widgets in a grid")); + addClass(wGrid); + + KFormDesigner::WidgetInfo *wSplitter = new KFormDesigner::WidgetInfo(this); +//! @todo horizontal/vertical splitter icons + wSplitter->setPixmap("frame"); + wSplitter->setClassName("Splitter"); + wSplitter->addAlternateClassName("QSplitter"); + wSplitter->setName(i18n("Splitter")); + wSplitter->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.", "splitter")); + wSplitter->setDescription(i18n("A container that enables user to resize its children")); + addClass(wSplitter); + + KFormDesigner::WidgetInfo *wHFlow = new KFormDesigner::WidgetInfo(this); +//! @todo hflow icon + wHFlow->setPixmap("frame"); + wHFlow->setClassName("HFlow"); + wHFlow->setName(i18n("Row Layout")); + wHFlow->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.", "rowLayout")); + wHFlow->setDescription(i18n("A simple container to group widgets by rows")); + addClass(wHFlow); + + KFormDesigner::WidgetInfo *wVFlow = new KFormDesigner::WidgetInfo(this); +//! @todo vflow icon + wVFlow->setPixmap("frame"); + wVFlow->setClassName("VFlow"); + wVFlow->setName(i18n("Column Layout")); + wVFlow->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.", "columnLayout")); + wVFlow->setDescription(i18n("A simple container to group widgets by columns")); + addClass(wVFlow); + + KFormDesigner::WidgetInfo *wSubForm = new KFormDesigner::WidgetInfo(this); + wSubForm->setPixmap("form"); + wSubForm->setClassName("SubForm"); + wSubForm->setName(i18n("Sub Form")); + wSubForm->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.", "subForm")); + wSubForm->setDescription(i18n("A form widget included in another Form")); + wSubForm->setAutoSyncForProperty( "formName", false ); + addClass(wSubForm); + + //groupbox + m_propDesc["title"] = i18n("Title"); + m_propDesc["flat"] = i18n("Flat"); + + //tab widget + m_propDesc["tabPosition"] = i18n("Tab Position"); + m_propDesc["currentPage"] = i18n("Current Page"); + m_propDesc["tabShape"] = i18n("Tab Shape"); + + m_propDesc["tabPosition"] = i18n("Tab Position"); + m_propDesc["tabPosition"] = i18n("Tab Position"); + + m_propValDesc["Rounded"] = i18n("for Tab Shape", "Rounded"); + m_propValDesc["Triangular"] = i18n("for Tab Shape", "Triangular"); +} + +QWidget* +ContainerFactory::createWidget(const QCString &c, QWidget *p, const char *n, + KFormDesigner::Container *container, int options) +{ + if(c == "QButtonGroup") + { + QString text = container->form()->library()->textForWidgetName(n, c); + QButtonGroup *w = new QButtonGroup(/*i18n("Button Group")*/text, p, n); + new KFormDesigner::Container(container, w, container); + return w; + } + else if(c == "KFDTabWidget") + { + KFDTabWidget *tab = new KFDTabWidget(p, n); +#if defined(USE_KTabWidget) && KDE_VERSION >= KDE_MAKE_VERSION(3,1,9) + tab->setTabReorderingEnabled(true); + connect(tab, SIGNAL(movedTab(int,int)), this, SLOT(reorderTabs(int,int))); +#endif + container->form()->objectTree()->addItem(container->objectTree(), + new KFormDesigner::ObjectTreeItem( + container->form()->library()->displayName(c), n, tab, container)); +// m_manager = container->form()->manager(); + + // if we are loading, don't add this tab + if(container->form()->interactiveMode()) + { + //m_widget=tab; + setWidget(tab, container); +// m_container=container; + addTabPage(); + } + + return tab; + } + else if(c == "QWidget" || c=="ContainerWidget") + { + QWidget *w = new ContainerWidget(p, n); + new KFormDesigner::Container(container, w, p); + return w; + } + else if(c == "QGroupBox" || c == "GroupBox") + { + QString text = container->form()->library()->textForWidgetName(n, c); + QGroupBox *w = new GroupBox(text, p, n); + new KFormDesigner::Container(container, w, container); + return w; + } + else if(c == "QFrame") + { + QFrame *w = new QFrame(p, n); + w->setLineWidth(2); + w->setFrameStyle(QFrame::StyledPanel|QFrame::Raised); + new KFormDesigner::Container(container, w, container); + return w; + } + else if(c == "QWidgetStack") + { + QWidgetStack *stack = new QWidgetStack(p, n); + stack->setLineWidth(2); + stack->setFrameStyle(QFrame::StyledPanel|QFrame::Raised); + container->form()->objectTree()->addItem( container->objectTree(), + new KFormDesigner::ObjectTreeItem( + container->form()->library()->displayName(c), n, stack, container)); + + if(container->form()->interactiveMode()) + { + //m_widget = stack; + setWidget(stack, container); +// m_container = container; + addStackPage(); + } + return stack; + } + else if(c == "HBox") { + HBox *w = new HBox(p, n); + new KFormDesigner::Container(container, w, container); + return w; + } + else if(c == "VBox") { + VBox *w = new VBox(p, n); + new KFormDesigner::Container(container, w, container); + return w; + } + else if(c == "Grid") { + Grid *w = new Grid(p, n); + new KFormDesigner::Container(container, w, container); + return w; + } + else if(c == "HFlow") { + HFlow *w = new HFlow(p, n); + new KFormDesigner::Container(container, w, container); + return w; + } + else if(c == "VFlow") { + VFlow *w = new VFlow(p, n); + new KFormDesigner::Container(container, w, container); + return w; + } + else if(c == "SubForm") { + SubForm *subform = new SubForm(p, n); + return subform; + } + else if(c == "QSplitter") { + QSplitter *split = new QSplitter(p, n); + if (0 == (options & WidgetFactory::AnyOrientation)) + split->setOrientation( + (options & WidgetFactory::VerticalOrientation) ? Qt::Vertical : Qt::Horizontal); + new KFormDesigner::Container(container, split, container); + return split; + } + + return 0; +} + +bool +ContainerFactory::previewWidget(const QCString &classname, QWidget *widget, KFormDesigner::Container *container) +{ + if(classname == "WidgetStack") + { + QWidgetStack *stack = ((QWidgetStack*)widget); + KFormDesigner::ObjectTreeItem *tree = container->form()->objectTree()->lookup(widget->name()); + if(!tree->modifiedProperties()->contains("frameShape")) + stack->setFrameStyle(QFrame::NoFrame); + } + else if(classname == "HBox") + ((HBox*)widget)->setPreviewMode(); + else if(classname == "VBox") + ((VBox*)widget)->setPreviewMode(); + else if(classname == "Grid") + ((Grid*)widget)->setPreviewMode(); + else if(classname == "HFlow") + ((HFlow*)widget)->setPreviewMode(); + else if(classname == "VFlow") + ((VFlow*)widget)->setPreviewMode(); + else + return false; + return true; +} + +bool +ContainerFactory::createMenuActions(const QCString &classname, QWidget *w, QPopupMenu *menu, + KFormDesigner::Container *container) +{ + setWidget(w, container); + //m_widget = w; +// m_container = container; + + if((classname == "KFDTabWidget") || (w->parentWidget()->parentWidget()->inherits("QTabWidget"))) + { + if(w->parentWidget()->parentWidget()->inherits("QTabWidget")) + { + //m_widget = w->parentWidget()->parentWidget(); + setWidget(w->parentWidget()->parentWidget(), m_container->toplevel()); +// m_container = m_container->toplevel(); + } + + int id = menu->insertItem(SmallIconSet("tab_new"), i18n("Add Page"), this, SLOT(addTabPage()) ); + id = menu->insertItem(SmallIconSet("edit"), i18n("Rename Page..."), this, SLOT(renameTabPage())); + id = menu->insertItem(SmallIconSet("tab_remove"), i18n("Remove Page"), this, SLOT(removeTabPage())); +// if( dynamic_cast<TabWidgetBase*>(m_widget)->count() == 1) + if( dynamic_cast<TabWidgetBase*>(widget())->count() == 1) + menu->setItemEnabled(id, false); + return true; + } + else if(w->parentWidget()->isA("QWidgetStack") && !w->parentWidget()->parentWidget()->inherits("QTabWidget")) + { + //m_widget = w->parentWidget(); + QWidgetStack *stack = (QWidgetStack*)w->parentWidget(); //m_widget; + setWidget( + w->parentWidget(), + container->form()->objectTree()->lookup(stack->name())->parent()->container() + ); +// m_container = container->form()->objectTree()->lookup(m_widget->name())->parent()->container(); +// m_container = container->form()->objectTree()->lookup(stack->name())->parent()->container(); + + int id = menu->insertItem(SmallIconSet("tab_new"), i18n("Add Page"), this, SLOT(addStackPage()) ); + + id = menu->insertItem(SmallIconSet("tab_remove"), i18n("Remove Page"), this, SLOT(removeStackPage()) ); +// if( ((QWidgetStack*)m_widget)->children()->count() == 4) // == the stack has only one page + if(stack->children()->count() == 4) // == the stack has only one page + menu->setItemEnabled(id, false); + + id = menu->insertItem(SmallIconSet("next"), i18n("Jump to Next Page"), this, SLOT(nextStackPage())); + if(!stack->widget(stack->id(stack->visibleWidget())+1)) + menu->setItemEnabled(id, false); + + id = menu->insertItem(SmallIconSet("previous"), i18n("Jump to Previous Page"), this, SLOT(prevStackPage())); + if(!stack->widget(stack->id(stack->visibleWidget()) -1) ) + menu->setItemEnabled(id, false); + return true; + } + return false; +} + +bool +ContainerFactory::startEditing(const QCString &classname, QWidget *w, KFormDesigner::Container *container) +{ + m_container = container; + if(classname == "QButtonGroup") + { + QButtonGroup *group = static_cast<QButtonGroup*>(w); + QRect r = QRect(group->x()+2, group->y()-5, group->width()-10, w->fontMetrics().height() + 10); + createEditor(classname, group->title(), group, container, r, Qt::AlignAuto); + return true; + } + if(classname == "QGroupBox" || classname == "GroupBox") + { + QGroupBox *group = static_cast<QGroupBox*>(w); + QRect r = QRect(group->x()+2, group->y()-5, group->width()-10, w->fontMetrics().height() + 10); + createEditor(classname, group->title(), group, container, r, Qt::AlignAuto); + return true; + } + return false; +} + +bool +ContainerFactory::saveSpecialProperty(const QCString &, const QString &name, const QVariant &, QWidget *w, QDomElement &parentNode, QDomDocument &parent) +{ + if((name == "title") && (w->parentWidget()->parentWidget()->inherits("QTabWidget"))) + { + TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(w->parentWidget()->parentWidget()); + KFormDesigner::FormIO::savePropertyElement(parentNode, parent, "attribute", "title", tab->tabLabel(w)); + } + else if((name == "id") && (w->parentWidget()->isA("QWidgetStack"))) + { + QWidgetStack *stack = (QWidgetStack*)w->parentWidget(); + KFormDesigner::FormIO::savePropertyElement(parentNode, parent, "attribute", "id", stack->id(w)); + } + else + return false; + return true; +} + +bool +ContainerFactory::readSpecialProperty(const QCString &, QDomElement &node, QWidget *w, KFormDesigner::ObjectTreeItem *item) +{ + QString name = node.attribute("name"); + if((name == "title") && (item->parent()->widget()->inherits("QTabWidget"))) + { + TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(w->parentWidget()); + tab->addTab(w, node.firstChild().toElement().text()); + item->addModifiedProperty("title", node.firstChild().toElement().text()); + return true; + } + + if((name == "id") && (w->parentWidget()->isA("QWidgetStack"))) + { + QWidgetStack *stack = (QWidgetStack*)w->parentWidget(); + int id = KFormDesigner::FormIO::readPropertyValue(node.firstChild(), w, name).toInt(); + stack->addWidget(w, id); + stack->raiseWidget(w); + item->addModifiedProperty("id", id); + return true; + } + + return false; +} + +QValueList<QCString> +ContainerFactory::autoSaveProperties(const QCString &c) +{ + QValueList<QCString> lst; +// if(c == "SubForm") +// lst << "formName"; + if(c == "QSplitter") + lst << "orientation"; + return lst; +} + +bool +ContainerFactory::isPropertyVisibleInternal(const QCString &classname, + QWidget *w, const QCString &property, bool isTopLevel) +{ + bool ok = true; + + if((classname == "HBox") || (classname == "VBox") || (classname == "Grid") || + (classname == "HFlow") || (classname == "VFlow")) + { + return property == "name" || property == "geometry"; + } + else if (classname == "QGroupBox" || classname=="GroupBox") { + ok = +#ifdef KEXI_NO_UNFINISHED +/*! @todo Hidden for now in Kexi. "checkable" and "checked" props need adding +a fake properties which will allow to properly work in design mode, otherwise +child widgets become frozen when checked==true */ + (m_showAdvancedProperties || (property != "checkable" && property != "checked")) && +#endif + true + ; + } + else if (classname == "KFDTabWidget") { + ok = (m_showAdvancedProperties || (property != "tabReorderingEnabled" && property != "hoverCloseButton" && property != "hoverCloseButtonDelayed")); + } + + return ok && WidgetFactory::isPropertyVisibleInternal(classname, w, property, isTopLevel); +} + +bool +ContainerFactory::changeText(const QString &text) +{ + changeProperty("title", text, m_container->form()); + return true; +} + +void +ContainerFactory::resizeEditor(QWidget *editor, QWidget *widget, const QCString &) +{ + QSize s = widget->size(); + editor->move(widget->x() + 2, widget->y() - 5); + editor->resize(s.width() - 20, widget->fontMetrics().height() +10); +} + +// Widget Specific slots used in menu items + +void ContainerFactory::addTabPage() +{ +// if (!m_widget->inherits("QTabWidget")) + if (!widget()->inherits("QTabWidget")) + return; + KCommand *com = new InsertPageCommand(m_container, widget()); + if(dynamic_cast<TabWidgetBase*>(widget())->count() == 0) + { + com->execute(); + delete com; + } + else + m_container->form()->addCommand(com, true); +} + +void ContainerFactory::removeTabPage() +{ + if (!widget()->inherits("QTabWidget")) + return; + TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(widget()); + QWidget *w = tab->currentPage(); + + KFormDesigner::WidgetList list; + list.append(w); + KCommand *com = new KFormDesigner::DeleteWidgetCommand(list, m_container->form()); + tab->removePage(w); + m_container->form()->addCommand(com, true); +} + +void ContainerFactory::renameTabPage() +{ + if (!widget()->inherits("QTabWidget")) + return; + TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(widget()); + QWidget *w = tab->currentPage(); + bool ok; + + QString name = KInputDialog::getText(i18n("New Page Title"), i18n("Enter a new title for the current page:"), +#if KDE_VERSION < KDE_MAKE_VERSION(3,1,9) + QLineEdit::Normal, +#endif + tab->tabLabel(w), &ok, w->topLevelWidget()); + if(ok) + tab->changeTab(w, name); +} + +void ContainerFactory::reorderTabs(int oldpos, int newpos) +{ + KFormDesigner::ObjectTreeItem *tab + = KFormDesigner::FormManager::self()->activeForm()->objectTree()->lookup(sender()->name()); + if(!tab) + return; + + KFormDesigner::ObjectTreeItem *item = tab->children()->take(oldpos); + tab->children()->insert(newpos, item); +} + +void ContainerFactory::addStackPage() +{ + if (!widget()->isA("QWidgetStack")) + return; + KCommand *com = new InsertPageCommand(m_container, widget()); + if(!((QWidgetStack*)widget())->visibleWidget()) + { + com->execute(); + delete com; + } + else + m_container->form()->addCommand(com, true); +} + +void ContainerFactory::removeStackPage() +{ + if (!widget()->isA("QWidgetStack")) + return; + QWidgetStack *stack = (QWidgetStack*)widget(); + QWidget *page = stack->visibleWidget(); + + KFormDesigner::WidgetList list; + list.append(page); + KCommand *com = new KFormDesigner::DeleteWidgetCommand(list, m_container->form()); + + // raise prev widget + int id = stack->id(page) - 1; + while(!stack->widget(id)) + id--; + stack->raiseWidget(id); + + stack->removeWidget(page); + m_container->form()->addCommand(com, true); +} + +void ContainerFactory::prevStackPage() +{ + QWidgetStack *stack = (QWidgetStack*)widget(); + int id = stack->id(stack->visibleWidget()) - 1; + if(stack->widget(id)) + stack->raiseWidget(id); +} + +void ContainerFactory::nextStackPage() +{ + QWidgetStack *stack = (QWidgetStack*)widget(); + int id = stack->id(stack->visibleWidget()) + 1; + if(stack->widget(id)) + stack->raiseWidget(id); +} + +ContainerFactory::~ContainerFactory() +{ +} + +KFORMDESIGNER_WIDGET_FACTORY(ContainerFactory, containers) + +#include "containerfactory.moc" diff --git a/kexi/formeditor/factories/containerfactory.h b/kexi/formeditor/factories/containerfactory.h new file mode 100644 index 00000000..1092d852 --- /dev/null +++ b/kexi/formeditor/factories/containerfactory.h @@ -0,0 +1,271 @@ +/* This file is part of the KDE project + Copyright (C) 2003 Lucijan Busch <lucijan@kde.org> + Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr> + Copyright (C) 2006-2007 Jaroslaw Staniek <js@iidea.pl> + + 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. +*/ + +#ifndef CONTAINERFACTORY_H +#define CONTAINERFACTORY_H + +#include <kcommand.h> + +#include "widgetfactory.h" +#include "../utils.h" + +namespace KFormDesigner +{ + class Form; + class FormManager; + class Container; +} + +class InsertPageCommand : public KCommand +{ + public: + InsertPageCommand(KFormDesigner::Container *container, QWidget *widget); + + virtual void execute(); + virtual void unexecute(); + virtual QString name() const; + + protected: + KFormDesigner::Form *m_form; + QString m_containername; + QString m_name; + QString m_parentname; + int m_pageid; +}; + +//! Helper widget (used when using 'Lay out horizontally') +class KFORMEDITOR_EXPORT HBox : public QFrame +{ + Q_OBJECT + + public: + HBox(QWidget *parent, const char *name); + virtual ~HBox(){;} + void setPreviewMode() {m_preview = true;} + virtual void paintEvent(QPaintEvent *ev); + + protected: + bool m_preview; +}; + +//! Helper widget (used when using 'Lay out vertically') +class KFORMEDITOR_EXPORT VBox : public QFrame +{ + Q_OBJECT + + public: + VBox(QWidget *parent, const char *name); + virtual ~VBox(){;} + void setPreviewMode() {m_preview = true;} + virtual void paintEvent(QPaintEvent *ev); + + protected: + bool m_preview; +}; + +//! Helper widget (used when using 'Lay out in a grid') +class KFORMEDITOR_EXPORT Grid : public QFrame +{ + Q_OBJECT + + public: + Grid(QWidget *parent, const char *name); + virtual ~Grid(){;} + void setPreviewMode() {m_preview = true;} + virtual void paintEvent(QPaintEvent *ev); + + protected: + bool m_preview; +}; + +//! Helper widget (used when using 'Lay out with horizontal flow') +class KFORMEDITOR_EXPORT HFlow : public QFrame +{ + Q_OBJECT + + public: + HFlow(QWidget *parent, const char *name); + virtual ~HFlow(){;} + void setPreviewMode() {m_preview = true;} + virtual void paintEvent(QPaintEvent *ev); + + protected: + bool m_preview; +}; + +//! Helper widget (used when using 'Lay out with horizontal flow') +class KFORMEDITOR_EXPORT VFlow : public QFrame +{ + Q_OBJECT + + public: + VFlow(QWidget *parent, const char *name); + virtual ~VFlow(){;} + void setPreviewMode() {m_preview = true;} + virtual void paintEvent(QPaintEvent *ev); + virtual QSize sizeHint() const; + + protected: + bool m_preview; +}; + +//! A simple container widget +class KFORMEDITOR_EXPORT ContainerWidget : public QWidget +{ + Q_OBJECT + + friend class KFDTabWidget; + + public: + ContainerWidget(QWidget *parent, const char *name); + virtual ~ContainerWidget(); + + virtual QSize sizeHint() const; + + //! Used to emit handleDragMoveEvent() signal needed to control dragging over the container's surface + virtual void dragMoveEvent( QDragMoveEvent *e ); + + //! Used to emit handleDropEvent() signal needed to control dropping on the container's surface + virtual void dropEvent( QDropEvent *e ); + + signals: + //! Needed to control dragging over the container's surface + void handleDragMoveEvent(QDragMoveEvent *e); + + //! Needed to control dropping on the container's surface + void handleDropEvent(QDropEvent *e); +}; + +//! A tab widget +class KFORMEDITOR_EXPORT KFDTabWidget : public KFormDesigner::TabWidget +{ + Q_OBJECT + + public: + KFDTabWidget(QWidget *parent, const char *name); + virtual ~KFDTabWidget(); + + virtual QSize sizeHint() const; + + //! Used to emit handleDragMoveEvent() signal needed to control dragging over the container's surface + virtual void dragMoveEvent( QDragMoveEvent *e ); + + //! Used to emit handleDropEvent() signal needed to control dropping on the container's surface + virtual void dropEvent( QDropEvent *e ); + + signals: + //! Needed to control dragging over the container's surface + void handleDragMoveEvent(QDragMoveEvent *e); + + //! Needed to control dropping on the container's surface + void handleDropEvent(QDropEvent *e); +}; + +//! A group box widget +class KFORMEDITOR_EXPORT GroupBox : public QGroupBox +{ + Q_OBJECT + + public: + GroupBox(const QString & title, QWidget *parent, const char *name); + virtual ~GroupBox(); + + //! Used to emit handleDragMoveEvent() signal needed to control dragging over the container's surface + virtual void dragMoveEvent( QDragMoveEvent *e ); + + //! Used to emit handleDropEvent() signal needed to control dropping on the container's surface + virtual void dropEvent( QDropEvent *e ); + + signals: + //! Needed to control dragging over the container's surface + void handleDragMoveEvent(QDragMoveEvent *e); + + //! Needed to control dropping on the container's surface + void handleDropEvent(QDropEvent *e); +}; + +//! A form embedded as a widget inside other form +class KFORMEDITOR_EXPORT SubForm : public QScrollView +{ + Q_OBJECT + Q_PROPERTY(QString formName READ formName WRITE setFormName DESIGNABLE true) + + public: + SubForm(QWidget *parent, const char *name); + ~SubForm() {} + + //! \return the name of the subform inside the db + QString formName() const { return m_formName; } + void setFormName(const QString &name); + + private: +// KFormDesigner::FormManager *m_manager; + KFormDesigner::Form *m_form; + QWidget *m_widget; + QString m_formName; +}; + +//! Standard Factory for all container widgets +class ContainerFactory : public KFormDesigner::WidgetFactory +{ + Q_OBJECT + + public: + ContainerFactory(QObject *parent, const char *name, const QStringList &args); + virtual ~ContainerFactory(); + + virtual QWidget *createWidget(const QCString & classname, QWidget *parent, const char *name, KFormDesigner::Container *container, + int options = DefaultOptions); + virtual bool createMenuActions(const QCString& classname, QWidget *w, QPopupMenu *menu, + KFormDesigner::Container *container); + virtual bool startEditing(const QCString &classname, QWidget *w, + KFormDesigner::Container *container); + virtual bool previewWidget(const QCString &classname, QWidget *widget, + KFormDesigner::Container *container); + virtual bool saveSpecialProperty(const QCString &classname, const QString &name, + const QVariant &value, QWidget *w, QDomElement &parentNode, QDomDocument &parent); + virtual bool readSpecialProperty(const QCString &classname, QDomElement &node, QWidget *w, + KFormDesigner::ObjectTreeItem *item); + virtual QValueList<QCString> autoSaveProperties(const QCString &classname); + + protected: + virtual bool isPropertyVisibleInternal(const QCString &classname, QWidget *w, + const QCString &property, bool isTopLevel); + virtual bool changeText(const QString &newText); + virtual void resizeEditor(QWidget *editor, QWidget *widget, const QCString &classname); + + public slots: + void addTabPage(); + void addStackPage(); + void renameTabPage(); + void removeTabPage(); + void removeStackPage(); + void prevStackPage(); + void nextStackPage(); + void reorderTabs(int oldpos, int newpos); + + private: +// QWidget *m_widget; +// KFormDesigner::Container *m_container; +// KFormDesigner::FormManager *m_manager; +}; + +#endif diff --git a/kexi/formeditor/factories/kformdesigner_containers.desktop b/kexi/formeditor/factories/kformdesigner_containers.desktop new file mode 100644 index 00000000..ae30820c --- /dev/null +++ b/kexi/formeditor/factories/kformdesigner_containers.desktop @@ -0,0 +1,53 @@ +[Desktop Entry] +Type=Service +ServiceTypes=KFormDesigner/WidgetFactory + +Name=Container Widgets +Name[bg]=Контейнери +Name[ca]=Estris contenidors +Name[cy]=Celfigion Cynhwysydd +Name[da]=Container-kontroller +Name[de]=Container-Elemente +Name[el]=Γραφικά συστατικά υποδοχείς +Name[eo]=Ujaj fenestraĵoj +Name[es]=Widgets contenedores +Name[et]=Konteinervidinad +Name[eu]=Trepeta edukitzaileak +Name[fa]=عناصر محتوی +Name[fi]=Säiliön osat +Name[fr]=Conteneur d'éléments graphiques +Name[fy]=Kontainerwidgets +Name[gl]=Elementos Contedores +Name[he]=כלי קיבול +Name[hr]=Sadržajni widgeti +Name[hu]=Tartóelemek +Name[is]=Geymihlutir +Name[it]=Oggetti contenitori +Name[ja]=コンテナウィジェット +Name[km]=ធាតុក្រាហ្វិកកុងតឺន័រ +Name[lv]=Konteinera logdaļa +Name[ms]=Widget Bekas +Name[nb]=Beholder-elementer +Name[nds]=Gelaatselementen +Name[ne]=कन्टेनर विजेट +Name[nl]=Containerwidgets +Name[nn]=Kjeraldelement +Name[pl]=Kontrolki pojemników +Name[pt]=Elementos Contentores +Name[pt_BR]=Widgets Recipientes +Name[ru]=Контейнеры +Name[se]=Lihtteáđat +Name[sk]=Kontajnerové komponenty +Name[sl]=Vsebovalni gradniki +Name[sr]=Контејнерске контроле +Name[sr@Latn]=Kontejnerske kontrole +Name[sv]=Omgivande komponenter +Name[ta]=கொள்கலன் சாளர உருக்கள் +Name[tr]= Containers +Name[uk]=Віджети контейнера +Name[zh_CN]=容器部件 +Name[zh_TW]=容器視窗元件 + +X-KDE-Library=kformdesigner_containers +X-KFormDesigner-FactoryGroup= +X-KFormDesigner-WidgetFactoryVersion=2 diff --git a/kexi/formeditor/factories/kformdesigner_stdwidgets.desktop b/kexi/formeditor/factories/kformdesigner_stdwidgets.desktop new file mode 100644 index 00000000..d5d599fa --- /dev/null +++ b/kexi/formeditor/factories/kformdesigner_stdwidgets.desktop @@ -0,0 +1,55 @@ +[Desktop Entry] +Type=Service +ServiceTypes=KFormDesigner/WidgetFactory + +Name=Basic Widgets +Name[bg]=Основни графични обекти +Name[br]=Widgets Diazez +Name[ca]=Estris estàndard +Name[cy]=Celfigion Sylfaenol +Name[da]=Basale kontroller +Name[de]=Basis-Elemente +Name[el]=Βασικά γραφικά συστατικά +Name[eo]=Bazaj fenestraĵoj +Name[es]=Widgets básicos +Name[et]=Standardvidinad +Name[eu]=Oinarrizko trepetak +Name[fa]=عناصر پایهای +Name[fi]=yleiset elementit +Name[fr]=Éléments graphiques basiques +Name[fy]=Basiswidgets +Name[gl]=Elementos Básicos +Name[he]=פריטים בסיסיים +Name[hr]=Osnovni widgeti +Name[hu]=Alapelemek +Name[is]=Grunnhlutir +Name[it]=Oggetti di base +Name[ja]=基本的なウィジェット +Name[km]=ធាតុក្រាហ្វិកមូលដ្ឋាន +Name[lv]=Pamata logdaļas +Name[ms]=Widget Asas +Name[nb]=Elementære elementer +Name[nds]=Grundelementen +Name[ne]=आधारभूत विजेट +Name[nl]=Basiswidgets +Name[nn]=Grunnleggjande element +Name[pl]=Proste kontrolki +Name[pt]=Elementos Básicos +Name[pt_BR]=Widgets Básicos +Name[ru]=Стандартные виджеты +Name[se]=Oktageardanis áđat +Name[sk]=Základné komponenty +Name[sl]=Osnovni gradniki +Name[sr]=Основне контроле +Name[sr@Latn]=Osnovne kontrole +Name[sv]=Standardkomponenter +Name[ta]=அடிப்படை சாளர உருக்கள் +Name[uk]=Основні віджети +Name[uz]=Oddiy vidjetlar +Name[uz@cyrillic]=Оддий виджетлар +Name[zh_CN]=基本部件 +Name[zh_TW]=基本視窗元件 + +X-KDE-Library=kformdesigner_stdwidgets +X-KFormDesigner-FactoryGroup= +X-KFormDesigner-WidgetFactoryVersion=2 diff --git a/kexi/formeditor/factories/stdwidgetfactory.cpp b/kexi/formeditor/factories/stdwidgetfactory.cpp new file mode 100644 index 00000000..fade100a --- /dev/null +++ b/kexi/formeditor/factories/stdwidgetfactory.cpp @@ -0,0 +1,984 @@ +/*************************************************************************** + * Copyright (C) 2003 by Lucijan Busch <lucijan@kde.org> * + * Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr> * + * 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. * + ***************************************************************************/ + +#include <qlabel.h> +#include <qpopupmenu.h> +#include <qcursor.h> +#include <qradiobutton.h> +#include <qcheckbox.h> +#include <qslider.h> +#include <qobjectlist.h> +#include <qstring.h> +#include <qvariant.h> +#include <qheader.h> +#include <qdom.h> +#include <qstyle.h> +#include <qvaluevector.h> + +#include <klineedit.h> +#include <kpushbutton.h> +#include <knuminput.h> +#include <kcombobox.h> +#include <klistbox.h> +#include <ktextedit.h> +#include <klistview.h> +#include <kprogress.h> +#include <kiconloader.h> +#include <kgenericfactory.h> +#include <klocale.h> +#include <kdebug.h> +#include <kdeversion.h> + +#if KDE_VERSION < KDE_MAKE_VERSION(3,1,9) +# include <qdatetimeedit.h> +# define KTimeWidget QTimeEdit +# define KDateWidget QDateEdit +# define KDateTimeWidget QDateTimeEdit +#else +# include <ktimewidget.h> +# include <kdatewidget.h> +# include <kdatetimewidget.h> +#endif + +#include "spring.h" +#include "formIO.h" +#include "form.h" +#include "formmanager.h" +#include "widgetlibrary.h" +#include "widgetpropertyset.h" +#include <koproperty/property.h> + +#include "stdwidgetfactory.h" + +// Some widgets subclass to allow event filtering and some other things +KexiPictureLabel::KexiPictureLabel(const QPixmap &pix, QWidget *parent, const char *name) + : QLabel(parent, name) +{ + setPixmap(pix); + setScaledContents(false); +} + +bool +KexiPictureLabel::setProperty(const char *name, const QVariant &value) +{ + if(QString(name) == "pixmap") + resize(value.toPixmap().height(), value.toPixmap().width()); + return QLabel::setProperty(name, value); +} + +Line::Line(Qt::Orientation orient, QWidget *parent, const char *name) + : QFrame(parent, name) +{ + setFrameShadow(Sunken); + if(orient == Horizontal) + setFrameShape(HLine); + else + setFrameShape(VLine); +} + +void +Line::setOrientation(Qt::Orientation orient) +{ + if(orient == Horizontal) + setFrameShape(HLine); + else + setFrameShape(VLine); +} + +Qt::Orientation +Line::orientation() const +{ + if(frameShape() == HLine) + return Horizontal; + else + return Vertical; +} + +// The factory itself + +StdWidgetFactory::StdWidgetFactory(QObject *parent, const char *, const QStringList &) + : KFormDesigner::WidgetFactory(parent, "stdwidgets") +{ + KFormDesigner::WidgetInfo *wFormWidget = new KFormDesigner::WidgetInfo(this); + wFormWidget->setPixmap("form"); + wFormWidget->setClassName("FormWidgetBase"); + wFormWidget->setName(i18n("Form")); + wFormWidget->setNamePrefix(i18n("This string will be used to name widgets of this class. It must _not_ contain white " + "spaces and non latin1 characters.", "form")); + wFormWidget->setDescription(i18n("A simple form widget")); + addClass(wFormWidget); + + KFormDesigner::WidgetInfo *wCustomWidget = new KFormDesigner::WidgetInfo(this); + wCustomWidget->setPixmap("unknown_widget"); + wCustomWidget->setClassName("CustomWidget"); + wCustomWidget->setName(i18n("Custom Widget")); + wCustomWidget->setNamePrefix(i18n("This string will be used to name widgets of this class. It must _not_ contain white " + "spaces and non latin1 characters.", "customWidget")); + wCustomWidget->setDescription(i18n("A custom or non-supported widget")); + addClass(wCustomWidget); + + KFormDesigner::WidgetInfo *wLabel = new KFormDesigner::WidgetInfo(this); + wLabel->setPixmap("label"); + wLabel->setClassName("QLabel"); + wLabel->setName(i18n("Text Label")); + wLabel->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.", "label")); + wLabel->setDescription(i18n("A widget to display text")); + addClass(wLabel); + + KFormDesigner::WidgetInfo *wPixLabel = new KFormDesigner::WidgetInfo(this); + wPixLabel->setPixmap("pixmaplabel"); + wPixLabel->setClassName("KexiPictureLabel"); + wPixLabel->setName(i18n("Picture Label")); +//! @todo Qt designer compatibility: maybe use this class when QLabel has a pixmap set...? + //wPixLabel->addAlternateClassName("QLabel"); + wPixLabel->setSavingName("KexiPictureLabel"); + wPixLabel->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.", "picture")); + wPixLabel->setDescription(i18n("A widget to display pictures")); + addClass(wPixLabel); + + KFormDesigner::WidgetInfo *wLineEdit = new KFormDesigner::WidgetInfo(this); + wLineEdit->setPixmap("lineedit"); + wLineEdit->setClassName("KLineEdit"); + wLineEdit->addAlternateClassName("QLineEdit"); + wLineEdit->setIncludeFileName("klineedit.h"); + wLineEdit->setName(i18n("Line Edit")); + wLineEdit->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.", "lineEdit")); + wLineEdit->setDescription(i18n("A widget to input text")); + addClass(wLineEdit); + + KFormDesigner::WidgetInfo *wSpring = new KFormDesigner::WidgetInfo(this); + wSpring->setPixmap("spring"); + wSpring->setClassName("Spring"); + wSpring->setName(i18n("Spring")); + wSpring->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.", "spring")); + wSpring->setDescription(i18n("A spring to place between widgets")); + addClass(wSpring); + + KFormDesigner::WidgetInfo *wPushButton = new KFormDesigner::WidgetInfo(this); + wPushButton->setPixmap("button"); + wPushButton->setClassName("KPushButton"); + wPushButton->addAlternateClassName("QPushButton"); + wPushButton->setIncludeFileName("kpushbutton.h"); + wPushButton->setName(i18n("Push Button")); + wPushButton->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.", "button")); + wPushButton->setDescription(i18n("A simple push button to execute actions")); + addClass(wPushButton); + + KFormDesigner::WidgetInfo *wRadioButton = new KFormDesigner::WidgetInfo(this); + wRadioButton->setPixmap("radio"); + wRadioButton->setClassName("QRadioButton"); + wRadioButton->setName(i18n("Option Button")); + wRadioButton->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.", "optionButton")); + wRadioButton->setDescription(i18n("An option button with text or pixmap label")); + addClass(wRadioButton); + + KFormDesigner::WidgetInfo *wCheckBox = new KFormDesigner::WidgetInfo(this); + wCheckBox->setPixmap("check"); + wCheckBox->setClassName("QCheckBox"); + wCheckBox->setName(i18n("Check Box")); + wCheckBox->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.", "checkBox")); + wCheckBox->setDescription(i18n("A check box with text or pixmap label")); + addClass(wCheckBox); + + KFormDesigner::WidgetInfo *wSpinBox = new KFormDesigner::WidgetInfo(this); + wSpinBox->setPixmap("spin"); + wSpinBox->setClassName("KIntSpinBox"); + wSpinBox->addAlternateClassName("QSpinBox"); + wSpinBox->setIncludeFileName("knuminput.h"); + wSpinBox->setName(i18n("Spin Box")); + wSpinBox->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.", "spinBox")); + wSpinBox->setDescription(i18n("A spin box widget")); + addClass(wSpinBox); + + KFormDesigner::WidgetInfo *wComboBox = new KFormDesigner::WidgetInfo(this); + wComboBox->setPixmap("combo"); + wComboBox->setClassName("KComboBox"); + wComboBox->addAlternateClassName("QComboBox"); + wComboBox->setIncludeFileName("kcombobox.h"); + wComboBox->setName(i18n("Combo Box")); + wComboBox->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.", "comboBox")); + wComboBox->setDescription(i18n("A combo box widget")); + addClass(wComboBox); + + KFormDesigner::WidgetInfo *wListBox = new KFormDesigner::WidgetInfo(this); + wListBox->setPixmap("listbox"); + wListBox->setClassName("KListBox"); + wListBox->addAlternateClassName("QListBox"); + wListBox->setIncludeFileName("klistbox.h"); + wListBox->setName(i18n("List Box")); + wListBox->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.", "listBox")); + wListBox->setDescription(i18n("A simple list widget")); + addClass(wListBox); + + KFormDesigner::WidgetInfo *wTextEdit = new KFormDesigner::WidgetInfo(this); + wTextEdit->setPixmap("textedit"); + wTextEdit->setClassName("KTextEdit"); + wTextEdit->addAlternateClassName("QTextEdit"); + wTextEdit->setIncludeFileName("ktextedit.h"); + wTextEdit->setName(i18n("Text Editor")); + wTextEdit->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.", "textEditor")); + wTextEdit->setDescription(i18n("A simple single-page rich text editor")); + addClass(wTextEdit); + + KFormDesigner::WidgetInfo *wListView = new KFormDesigner::WidgetInfo(this); + wListView->setPixmap("listview"); + wListView->setClassName("KListView"); + wListView->addAlternateClassName("QListView"); + wListView->setIncludeFileName("klistview.h"); + wListView->setName(i18n("List View")); + wListView->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.", "listView")); + wListView->setDescription(i18n("A list (or tree) widget")); + addClass(wListView); + + KFormDesigner::WidgetInfo *wSlider = new KFormDesigner::WidgetInfo(this); + wSlider->setPixmap("slider"); + wSlider->setClassName("QSlider"); + wSlider->setName(i18n("Slider")); + wSlider->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.", "slider")); + wSlider->setDescription(i18n("An horizontal slider")); + addClass(wSlider); + + KFormDesigner::WidgetInfo *wProgressBar = new KFormDesigner::WidgetInfo(this); + wProgressBar->setPixmap("progress"); + wProgressBar->setClassName("KProgress"); + wProgressBar->addAlternateClassName("QProgressBar"); + wProgressBar->setIncludeFileName("kprogress.h"); + wProgressBar->setName(i18n("Progress Bar")); + wProgressBar->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.", "progressBar")); + wProgressBar->setDescription(i18n("A progress indicator widget")); + addClass(wProgressBar); + + KFormDesigner::WidgetInfo *wLine = new KFormDesigner::WidgetInfo(this); + wLine->setPixmap("line"); + wLine->setClassName("Line"); + wLine->setName(i18n("Line")); + wLine->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.", "line")); + wLine->setDescription(i18n("A line to be used as a separator")); + addClass(wLine); + + KFormDesigner::WidgetInfo *wDate = new KFormDesigner::WidgetInfo(this); + wDate->setPixmap("dateedit"); + wDate->setClassName("KDateWidget"); +#if KDE_VERSION >= KDE_MAKE_VERSION(3,1,9) + wDate->addAlternateClassName("QDateEdit"); + wDate->setIncludeFileName("kdatewidget.h"); +#endif + 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); + + KFormDesigner::WidgetInfo *wTime = new KFormDesigner::WidgetInfo(this); + wTime->setPixmap("timeedit"); + wTime->setClassName("KTimeWidget"); +#if KDE_VERSION >= KDE_MAKE_VERSION(3,1,9) + wTime->addAlternateClassName("QTimeEdit"); + wTime->setIncludeFileName("ktimewidget.h"); +#endif + 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); + + KFormDesigner::WidgetInfo *wDateTime = new KFormDesigner::WidgetInfo(this); + wDateTime->setPixmap("datetimeedit"); + wDateTime->setClassName("KDateTimeWidget"); +#if KDE_VERSION >= KDE_MAKE_VERSION(3,1,9) + wDateTime->addAlternateClassName("QDateTimeEdit"); + wDateTime->setIncludeFileName("kdatetimewidget.h"); +#endif + 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 time and a date")); + addClass(wDateTime); + + m_propDesc["toggleButton"] = i18n("Toggle"); + m_propDesc["autoRepeat"] = i18n("Auto Repeat"); + m_propDesc["autoDefault"] = i18n("Auto Default"); + m_propDesc["default"] = i18n("Default"); + m_propDesc["flat"] = i18n("Flat"); + m_propDesc["echoMode"] = + i18n("Echo mode for Line Edit widget eg. Normal, NoEcho, Password","Echo Mode"); + m_propDesc["indent"] = i18n("Indent"); + //line + m_propDesc["orientation"] = i18n("Orientation"); + //checkbox + m_propDesc["checked"] = i18n("Checked checkbox", "Checked"); + m_propDesc["tristate"] = i18n("Tristate checkbox", "Tristate"); + + //for EchoMode + m_propValDesc["Normal"] = i18n("For Echo Mode", "Normal"); + m_propValDesc["NoEcho"] = i18n("For Echo Mode", "No Echo"); + m_propValDesc["Password"] = i18n("For Echo Mode", "Password"); + + //for spring + m_propDesc["sizeType"] = i18n("Size Type"); + + //for labels + m_propDesc["textFormat"] = i18n("Text Format"); + m_propValDesc["PlainText"] = i18n("For Text Format", "Plain"); + m_propValDesc["RichText"] = i18n("For Text Format", "Hypertext"); + m_propValDesc["AutoText"] = i18n("For Text Format", "Auto"); + m_propValDesc["LogText"] = i18n("For Text Format", "Log"); + + //KTextEdit + m_propDesc["tabStopWidth"] = i18n("Tab Stop Width"); + m_propDesc["tabChangesFocus"] = i18n("Tab Changes Focus"); + m_propDesc["wrapPolicy"] = i18n("Word Wrap Policy"); + m_propValDesc["AtWordBoundary"] = i18n("For Word Wrap Policy", "At Word Boundary"); + m_propValDesc["Anywhere"] = i18n("For Word Wrap Policy", "Anywhere"); + m_propValDesc["AtWordOrDocumentBoundary"] = i18n("For Word Wrap Policy", "At Word Boundary If Possible"); + m_propDesc["wordWrap"] = i18n("Word Wrapping"); + m_propDesc["wrapColumnOrWidth"] = i18n("Word Wrap Position"); + m_propValDesc["NoWrap"] = i18n("For Word Wrap Position", "None"); + m_propValDesc["WidgetWidth"] = i18n("For Word Wrap Position", "Widget's Width"); + m_propValDesc["FixedPixelWidth"] = i18n("For Word Wrap Position", "In Pixels"); + m_propValDesc["FixedColumnWidth"] = i18n("For Word Wrap Position", "In Columns"); + m_propDesc["linkUnderline"] = i18n("Links Underlined"); + + //internal props + setInternalProperty("Line","orientationSelectionPopup","1"); + setInternalProperty("Line","orientationSelectionPopup:horizontalIcon","line_horizontal"); + setInternalProperty("Line","orientationSelectionPopup:verticalIcon","line_vertical"); + setInternalProperty("Line","orientationSelectionPopup:horizontalText",i18n("Insert &Horizontal Line")); + setInternalProperty("Line","orientationSelectionPopup:verticalText",i18n("Insert &Vertical Line")); + setInternalProperty("Spring","orientationSelectionPopup","1"); + setInternalProperty("Spring","orientationSelectionPopup:horizontalIcon","spring"); + setInternalProperty("Spring","orientationSelectionPopup:verticalIcon","spring_vertical"); + setInternalProperty("Spring","orientationSelectionPopup:horizontalText",i18n("Insert &Horizontal Spring")); + setInternalProperty("Spring","orientationSelectionPopup:verticalText",i18n("Insert &Vertical Spring")); +} + +StdWidgetFactory::~StdWidgetFactory() +{ +} + +QWidget* +StdWidgetFactory::createWidget(const QCString &c, QWidget *p, const char *n, + KFormDesigner::Container *container, int options) +{ + QWidget *w=0; + QString text( container->form()->library()->textForWidgetName(n, c) ); + const bool designMode = options & KFormDesigner::WidgetFactory::DesignViewMode; + + if(c == "QLabel") + w = new QLabel(text, p, n); + else if(c == "KexiPictureLabel") + w = new KexiPictureLabel(DesktopIcon("image"), p, n); + + else if(c == "KLineEdit") + { + w = new KLineEdit(p, n); + if (designMode) + w->setCursor(QCursor(Qt::ArrowCursor)); + } + else if(c == "KPushButton") + w = new KPushButton(/*i18n("Button")*/text, p, n); + + else if(c == "QRadioButton") + w = new QRadioButton(/*i18n("Radio Button")*/text, p, n); + + else if(c == "QCheckBox") + w = new QCheckBox(/*i18n("Check Box")*/text, p, n); + + else if(c == "KIntSpinBox") + w = new KIntSpinBox(p, n); + + else if(c == "KComboBox") + w = new KComboBox(p, n); + + else if(c == "KListBox") + w = new KListBox(p, n); + + else if(c == "KTextEdit") + w = new KTextEdit(/*i18n("Enter your text here")*/text, QString::null, p, n); + + else if(c == "KListView") + { + w = new KListView(p, n); + if(container->form()->interactiveMode()) + ((KListView*)w)->addColumn(i18n("Column 1")); + ((KListView*)w)->setRootIsDecorated(true); + } + else if(c == "QSlider") + w = new QSlider(Qt::Horizontal, p, n); + + else if(c == "KProgress") + w = new KProgress(p, n); + + else if(c == "KDateWidget") + w = new KDateWidget(QDate::currentDate(), p, n); + + else if(c == "KTimeWidget") + w = new KTimeWidget(QTime::currentTime(), p, n); + + else if(c == "KDateTimeWidget") + w = new KDateTimeWidget(QDateTime::currentDateTime(), p, n); + + else if(c == "Line") + w = new Line(options & WidgetFactory::VerticalOrientation ? Line::Vertical : Line::Horizontal, p, n); + + else if(c == "Spring") { + w = new Spring(p, n); + if (0 == (options & WidgetFactory::AnyOrientation)) + static_cast<Spring*>(w)->setOrientation( + (options & WidgetFactory::VerticalOrientation) ? Qt::Vertical : Qt::Horizontal); + } + + if(w) + return w; + + kdDebug() << "WARNING :: w == 0 " << endl; + return 0; +} + +bool +StdWidgetFactory::previewWidget(const QCString &classname, QWidget *widget, KFormDesigner::Container *) +{ + if(classname == "Spring") { + ((Spring*)widget)->setPreviewMode(); + return true; + } + return false; +} + +bool +StdWidgetFactory::createMenuActions(const QCString &classname, QWidget *, QPopupMenu *menu, + KFormDesigner::Container *) +{ + if((classname == "QLabel") || (classname == "KTextEdit")) + { + menu->insertItem(SmallIconSet("edit"), i18n("Edit Rich Text"), this, SLOT(editText())); + return true; + } + else if(classname == "KListView") + { + menu->insertItem(SmallIconSet("edit"), i18n("Edit Listview Contents"), this, SLOT(editListContents())); + return true; + } + + return false; +} + +bool +StdWidgetFactory::startEditing(const QCString &classname, QWidget *w, KFormDesigner::Container *container) +{ + setWidget(w, container); +// m_container = container; + if(classname == "KLineEdit") + { + KLineEdit *lineedit = static_cast<KLineEdit*>(w); + createEditor(classname, lineedit->text(), lineedit, container, lineedit->geometry(), lineedit->alignment(), true); + return true; + } + else if(classname == "QLabel") + { + QLabel *label = static_cast<QLabel*>(w); + if(label->textFormat() == RichText) + { + //m_widget = w; +// setWidget(w, container); + editText(); + } + else + createEditor(classname, label->text(), label, container, label->geometry(), label->alignment()); + return true; + } + else if(classname == "KPushButton") + { + KPushButton *push = static_cast<KPushButton*>(w); + QRect r = w->style().subRect(QStyle::SR_PushButtonContents, w); + QRect editorRect = QRect(push->x() + r.x(), push->y() + r.y(), r.width(), r.height()); + //r.setX(r.x() + 5); + //r.setY(r.y() + 5); + //r.setWidth(r.width()-10); + //r.setHeight(r.height() - 10); + createEditor(classname, push->text(), push, container, editorRect, Qt::AlignCenter, false, false, Qt::PaletteButton); + return true; + } + else if(classname == "QRadioButton") + { + QRadioButton *radio = static_cast<QRadioButton*>(w); + QRect r = w->style().subRect(QStyle::SR_RadioButtonContents, w); + QRect editorRect = QRect(radio->x() + r.x(), radio->y() + r.y(), r.width(), r.height()); + createEditor(classname, radio->text(), radio, container, editorRect, Qt::AlignAuto); + return true; + } + else if(classname == "QCheckBox") + { + QCheckBox *check = static_cast<QCheckBox*>(w); + //QRect r(check->geometry()); + //r.setX(r.x() + 20); + QRect r = w->style().subRect(QStyle::SR_CheckBoxContents, w); + QRect editorRect = QRect(check->x() + r.x(), check->y() + r.y(), r.width(), r.height()); + createEditor(classname, check->text(), check, container, editorRect, Qt::AlignAuto); + return true; + } + else if((classname == "KComboBox") || (classname == "KListBox")) + { + QStringList list; + if(classname == "KListBox") + { + KListBox *listbox = (KListBox*)w; + for(uint i=0; i < listbox->count(); i++) + list.append(listbox->text(i)); + } + else if(classname == "KComboBox") + { + KComboBox *combo = (KComboBox*)w; + for(int i=0; i < combo->count(); i++) + list.append(combo->text(i)); + } + + if(editList(w, list)) + { + if(classname == "KListBox") + { + ((KListBox*)w)->clear(); + ((KListBox*)w)->insertStringList(list); + } + else if(classname == "KComboBox") + { + ((KComboBox*)w)->clear(); + ((KComboBox*)w)->insertStringList(list); + } + } + return true; + } + else if((classname == "KTextEdit") || (classname == "KDateTimeWidget") || (classname == "KTimeWidget") || + (classname == "KDateWidget") || (classname == "KIntSpinBox")) { + disableFilter(w, container); + return true; + } + return false; +} + +bool +StdWidgetFactory::clearWidgetContent(const QCString &classname, QWidget *w) +{ + if(classname == "KLineEdit") + ((KLineEdit*)w)->clear(); + else if(classname == "KListBox") + ((KListBox*)w)->clear(); + else if(classname == "KListView") + ((KListView*)w)->clear(); + else if(classname == "KComboBox") + ((KComboBox*)w)->clear(); + else if(classname == "KTextEdit") + ((KTextEdit*)w)->clear(); + else + return false; + return true; +} + +bool +StdWidgetFactory::changeText(const QString &text) +{ + QCString n = WidgetFactory::widget()->className(); + QWidget *w = WidgetFactory::widget(); + if(n == "KIntSpinBox") + ((KIntSpinBox*)w)->setValue(text.toInt()); + else + changeProperty("text", text, m_container->form()); + + /* By-hand method not needed as sizeHint() can do that for us + QFontMetrics fm = w->fontMetrics(); + QSize s(fm.width( text ), fm.height()); + int width; + if(n == "QLabel") // labels are resized to fit the text + { + w->resize(w->sizeHint()); + WidgetFactory::m_editor->resize(w->size()); + return; + } + // and other widgets are just enlarged if needed + else if(n == "KPushButton") + width = w->style().sizeFromContents( QStyle::CT_PushButton, w, s).width(); + else if(n == "QCheckBox") + width = w->style().sizeFromContents( QStyle::CT_CheckBox, w, s).width(); + else if(n == "QRadioButton") + width = w->style().sizeFromContents( QStyle::CT_RadioButton, w, s).width(); + else + return; + int width = w->sizeHint().width();*/ + +#if 0 //not needed here, size hint is used on creation in InsertWidgetCommand::execute() + if(w->width() < width) + { + w->resize(width, w->height() ); + //WidgetFactory::m_editor->resize(w->size()); + } +#endif + return true; +} + +void +StdWidgetFactory::resizeEditor(QWidget *editor, QWidget *widget, const QCString &classname) +{ + QSize s = widget->size(); + QPoint p = widget->pos(); + QRect r; + + if(classname == "QRadioButton") + { + r = widget->style().subRect(QStyle::SR_RadioButtonContents, widget); + p += r.topLeft(); + s.setWidth(r.width()); + } + else if(classname == "QCheckBox") + { + r = widget->style().subRect(QStyle::SR_CheckBoxContents, widget); + p += r.topLeft(); + s.setWidth(r.width()); + } + else if(classname == "KPushButton") + { + r = widget->style().subRect(QStyle::SR_PushButtonContents, widget); + p += r.topLeft(); + s = r.size(); + } + + editor->resize(s); + editor->move(p); +} + +bool +StdWidgetFactory::saveSpecialProperty(const QCString &classname, const QString &name, const QVariant &, QWidget *w, QDomElement &parentNode, QDomDocument &domDoc) +{ + if(name == "list_items" && classname == "KComboBox") + { + KComboBox *combo = (KComboBox*)w; + for(int i=0; i < combo->count(); i++) + { + QDomElement item = domDoc.createElement("item"); + KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "text", combo->text(i)); + parentNode.appendChild(item); + } + return true; + } + else if(name == "list_items" && classname == "KListBox") + { + KListBox *listbox = (KListBox*)w; + for(uint i=0; i < listbox->count(); i++) + { + QDomElement item = domDoc.createElement("item"); + KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "text", listbox->text(i)); + parentNode.appendChild(item); + } + return true; + } + else if(name == "list_contents" && classname == "KListView") + { + KListView *listview = (KListView*)w; + // First we save the columns + for(int i = 0; i < listview->columns(); i++) + { + QDomElement item = domDoc.createElement("column"); + KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "text", listview->columnText(i)); + KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "width", listview->columnWidth(i)); + KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "resizable", listview->header()->isResizeEnabled(i)); + KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "clickable", listview->header()->isClickEnabled(i)); + KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "fullwidth", listview->header()->isStretchEnabled(i)); + parentNode.appendChild(item); + } + + // Then we save the list view items + QListViewItem *item = listview->firstChild(); + while(item) + { + saveListItem(item, parentNode, domDoc); + item = item->nextSibling(); + } + return true; + } + + return false; +} + +void +StdWidgetFactory::saveListItem(QListViewItem *item, QDomNode &parentNode, QDomDocument &domDoc) +{ + QDomElement element = domDoc.createElement("item"); + parentNode.appendChild(element); + + // We save the text of each column + for(int i = 0; i < item->listView()->columns(); i++) + KFormDesigner::FormIO::savePropertyElement(element, domDoc, "property", "text", item->text(i)); + + // Then we save every sub items + QListViewItem *child = item->firstChild(); + while(child) + { + saveListItem(child, element, domDoc); + child = child->nextSibling(); + } +} + +bool +StdWidgetFactory::readSpecialProperty(const QCString &classname, QDomElement &node, QWidget *w, KFormDesigner::ObjectTreeItem *) +{ + QString tag = node.tagName(); + QString name = node.attribute("name"); + + if((tag == "item") && (classname == "KComboBox")) + { + KComboBox *combo = (KComboBox*)w; + QVariant val = KFormDesigner::FormIO::readPropertyValue(node.firstChild().firstChild(), w, name); + if(val.canCast(QVariant::Pixmap)) + combo->insertItem(val.toPixmap()); + else + combo->insertItem(val.toString()); + return true; + } + + if((tag == "item") && (classname == "KListBox")) + { + KListBox *listbox = (KListBox*)w; + QVariant val = KFormDesigner::FormIO::readPropertyValue(node.firstChild().firstChild(), w, name); + if(val.canCast(QVariant::Pixmap)) + listbox->insertItem(val.toPixmap()); + else + listbox->insertItem(val.toString()); + return true; + } + + if((tag == "column") && (classname == "KListView")) + { + KListView *listview = (KListView*)w; + int id=0; + for(QDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling()) + { + QString prop = n.toElement().attribute("name"); + QVariant val = KFormDesigner::FormIO::readPropertyValue(n.firstChild(), w, name); + if(prop == "text") + id = listview->addColumn(val.toString()); + else if(prop == "width") + listview->setColumnWidth(id, val.toInt()); + else if(prop == "resizable") + listview->header()->setResizeEnabled(val.toBool(), id); + else if(prop == "clickable") + listview->header()->setClickEnabled(val.toBool(), id); + else if(prop == "fullwidth") + listview->header()->setStretchEnabled(val.toBool(), id); + } + return true; + } + else if((tag == "item") && (classname == "KListView")) + { + KListView *listview = (KListView*)w; + readListItem(node, 0, listview); + return true; + } + + return false; +} + +void +StdWidgetFactory::readListItem(QDomElement &node, QListViewItem *parent, KListView *listview) +{ + QListViewItem *item; + if(parent) + item = new KListViewItem(parent); + else + item = new KListViewItem(listview); + + // We need to move the item at the end of the list + QListViewItem *last; + if(parent) + last = parent->firstChild(); + else + last = listview->firstChild(); + + while(last->nextSibling()) + last = last->nextSibling(); + item->moveItem(last); + + int i = 0; + for(QDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling()) + { + QDomElement childEl = n.toElement(); + QString prop = childEl.attribute("name"); + QString tag = childEl.tagName(); + + // We read sub items + if(tag == "item") + { + item->setOpen(true); + readListItem(childEl, item, listview); + } + // and column texts + else if((tag == "property") && (prop == "text")) + { + QVariant val = KFormDesigner::FormIO::readPropertyValue(n.firstChild(), listview, "item"); + item->setText(i, val.toString()); + i++; + } + } +} + +bool +StdWidgetFactory::isPropertyVisibleInternal(const QCString &classname, + QWidget *w, const QCString &property, bool isTopLevel) +{ + bool ok = true; + if(classname == "FormWidgetBase") + { + if(property == "iconText" + || property == "geometry" /*nonsense for toplevel widget*/) + return false; + } + else if (classname == "CustomWidget") + { + } + else if(classname == "Spring") + { + return Spring::isPropertyVisible(property); + } + else if(classname == "KexiPictureLabel") + { + if((property == "text") || (property == "indent") || (property == "textFormat") || (property == "font") || (property == "alignment")) + return false; + } + else if(classname == "QLabel") + { + if(property == "pixmap") + return false; + } + else if(classname == "KLineEdit") + { + if(property == "vAlign") + return false; + } + else if(classname == "KTextEdit") + ok = m_showAdvancedProperties || + property!="undoDepth" + && property!="undoRedoEnabled" //always true! + && property!="dragAutoScroll" //always true! + && property!="overwriteMode" //always false! + && property!="resizePolicy" + && property!="autoFormatting" //too complex +#ifdef KEXI_NO_UNFINISHED + && property!="paper" +#endif + ; + else if(classname == "Line") + { + if((property == "frameShape") || (property == "font") || (property == "margin")) + return false; + } + else if(classname=="QCheckBox") + { + ok = m_showAdvancedProperties || (property != "autoRepeat"); + } + else if(classname=="QRadioButton") + { + ok = m_showAdvancedProperties || (property != "autoRepeat"); + } + else if(classname=="KPushButton") + { +//! @todo reenable autoDefault / default if the top level window is dialog... + ok = m_showAdvancedProperties || (property != "autoDefault" && property != "default"); + } + return ok && WidgetFactory::isPropertyVisibleInternal(classname, w, property, isTopLevel); +} + +QValueList<QCString> +StdWidgetFactory::autoSaveProperties(const QCString &classname) +{ + QValueList<QCString> l; + + if(classname == "QLabel") + l << "text"; + if(classname == "KPushButton") + l << "text"; + else if(classname == "KexiPictureLabel") + l << "pixmap"; + else if(classname == "KComboBox") + l << "list_items"; + else if(classname == "KListBox") + l << "list_items"; + else if(classname == "KListView") + l << "list_contents"; + else if(classname == "Line") + l << "orientation"; + else if(classname == "KTimeWidget") + l << "time"; + else if(classname == "KDateWidget") + l << "date"; + else if(classname == "KDateTimeWidget") + l << "dateTime"; + else if(classname == "Spring") + l << "sizeType" << "orientation"; + else if(classname == "KTextEdit") + l << "textFormat" << "text"; + + return l; +} + +void +StdWidgetFactory::editText() +{ + QCString classname = widget()->className(); + QString text; + if(classname == "KTextEdit") + text = ((KTextEdit*)widget())->text(); + else if(classname == "QLabel") + text = ((QLabel*)widget())->text(); + + if(editRichText(widget(), text)) + { + changeProperty("textFormat", "RichText", m_container->form()); + changeProperty("text", text, m_container->form()); + } + + if(classname == "QLabel") + widget()->resize(widget()->sizeHint()); +} + +void +StdWidgetFactory::editListContents() +{ + if(widget()->inherits("QListView")) + editListView((QListView*)widget()); +} + +void +StdWidgetFactory::setPropertyOptions( KFormDesigner::WidgetPropertySet& buf, const KFormDesigner::WidgetInfo& info, QWidget *w ) +{ + Q_UNUSED( info ); + Q_UNUSED( w ); + + if (buf.contains("indent")) { + buf["indent"].setOption("min", -1); + buf["indent"].setOption("minValueText", i18n("default indent value", "default")); + } +} + +KFORMDESIGNER_WIDGET_FACTORY(StdWidgetFactory, stdwidgets) + +#include "stdwidgetfactory.moc" + diff --git a/kexi/formeditor/factories/stdwidgetfactory.h b/kexi/formeditor/factories/stdwidgetfactory.h new file mode 100644 index 00000000..c0e56c5b --- /dev/null +++ b/kexi/formeditor/factories/stdwidgetfactory.h @@ -0,0 +1,99 @@ +/* This file is part of the KDE project + Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr> + + 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. +*/ + +#ifndef STDWIDGETFACTORY_H +#define STDWIDGETFACTORY_H + +#include <qframe.h> + +#include "widgetfactory.h" +#include "container.h" + +class KFORMEDITOR_EXPORT KexiPictureLabel : public QLabel +{ + Q_OBJECT + + public: + KexiPictureLabel(const QPixmap &pix, QWidget *parent, const char *name); + ~KexiPictureLabel(){;} + + virtual bool setProperty(const char *name, const QVariant &value); +}; + +class KFORMEDITOR_EXPORT Line : public QFrame +{ + Q_OBJECT + Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation) + + public: + Line(Orientation orient, QWidget *parent, const char *name); + ~Line(){;} + + void setOrientation(Orientation orient); + Orientation orientation() const; +}; + +//! Factory for all basic widgets, including Spring (not containers) +class StdWidgetFactory : public KFormDesigner::WidgetFactory +{ + Q_OBJECT + + public: + StdWidgetFactory(QObject *parent, const char *name, const QStringList &args); + ~StdWidgetFactory(); + + virtual QWidget *createWidget(const QCString &c, QWidget *p, const char *n, + KFormDesigner::Container *container, int options = DefaultOptions); + + virtual bool createMenuActions(const QCString &classname, QWidget *w, QPopupMenu *menu, + KFormDesigner::Container *container); + virtual bool startEditing(const QCString &classname, QWidget *w, + KFormDesigner::Container *container); + virtual bool previewWidget(const QCString &classname, QWidget *widget, + KFormDesigner::Container *container); + virtual bool clearWidgetContent(const QCString &classname, QWidget *w); + + virtual bool saveSpecialProperty(const QCString &classname, + const QString &name, const QVariant &value, QWidget *w, + QDomElement &parentNode, QDomDocument &parent); + virtual bool readSpecialProperty(const QCString &classname, QDomElement &node, + QWidget *w, KFormDesigner::ObjectTreeItem *item); + virtual QValueList<QCString> autoSaveProperties(const QCString &classname); + + virtual void setPropertyOptions( KFormDesigner::WidgetPropertySet& buf, + const KFormDesigner::WidgetInfo& info, QWidget *w ); + + public slots: + void editText(); + void editListContents(); + + protected: + virtual bool isPropertyVisibleInternal(const QCString &classname, QWidget *w, + const QCString &property, bool isTopLevel); + virtual bool changeText(const QString &newText); + virtual void resizeEditor(QWidget *editor, QWidget *widget, const QCString &classname); + void saveListItem(QListViewItem *item, QDomNode &parentNode, QDomDocument &domDoc); + void readListItem(QDomElement &node, QListViewItem *parent, KListView *listview); + + private: +// KFormDesigner::Container *m_container; +// QWidget *m_widget; +}; + +#endif |