kexi

kexireportfactory.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 #include <qpopupmenu.h>
00020 #include <qvaluevector.h>
00021 
00022 #include <kgenericfactory.h>
00023 #include <klocale.h>
00024 #include <kiconloader.h>
00025 #include <kdebug.h>
00026 #include <klineedit.h>
00027 
00028 #include <container.h>
00029 #include <form.h>
00030 #include <formmanager.h>
00031 #include <widgetlibrary.h>
00032 
00033 #include "reportwidgets.h"
00034 #include "kexireportfactory.h"
00035 
00036 KexiReportFactory::KexiReportFactory(QObject *parent, const char *name, const QStringList &)
00037  : KFormDesigner::WidgetFactory(parent, name)
00038 {
00039     KFormDesigner::WidgetInfo *wView = new KFormDesigner::WidgetInfo(this);
00040     wView->setPixmap("report");
00041     wView->setClassName("KexiReportForm");
00042     wView->setName(i18n("Report"));
00043     wView->setNamePrefix(
00044         i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "report"));
00045     wView->setDescription(i18n("A report"));
00046     addClass(wView);
00047 
00048     KFormDesigner::WidgetInfo *wLabel = new KFormDesigner::WidgetInfo(this);
00049     wLabel->setPixmap("label");
00050     wLabel->setClassName("Label");
00051     wLabel->setName(i18n("Label"));
00052     wLabel->setNamePrefix(
00053         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"));
00054     wLabel->setDescription(i18n("A label to display text"));
00055     addClass(wLabel);
00056 
00057     KFormDesigner::WidgetInfo *wPicLabel = new KFormDesigner::WidgetInfo(this);
00058     wPicLabel->setPixmap("pixmaplabel");
00059     wPicLabel->setClassName("PicLabel");
00060     wPicLabel->setName(i18n("Picture Label"));
00061     wPicLabel->setNamePrefix(
00062         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"));
00063     wPicLabel->setDescription(i18n("A label to display images or icons"));
00064     addClass(wPicLabel);
00065 
00066     KFormDesigner::WidgetInfo *wLine = new KFormDesigner::WidgetInfo(this);
00067     wLine->setPixmap("line");
00068     wLine->setClassName("ReportLine");
00069     wLine->setName(i18n("Line"));
00070     wLine->setNamePrefix(
00071         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"));
00072     wLine->setDescription(i18n("A simple line"));
00073     addClass(wLine);
00074 
00075     KFormDesigner::WidgetInfo *wSubReport = new KFormDesigner::WidgetInfo(this);
00076     wSubReport->setPixmap("report");
00077     wSubReport->setClassName("KexiSubReport");
00078     wSubReport->setName(i18n("Sub Report"));
00079     wSubReport->setNamePrefix(
00080         i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "subReport"));
00081     wSubReport->setDescription(i18n("A report embedded in another report"));
00082     addClass(wSubReport);
00083 }
00084 
00085 KexiReportFactory::~KexiReportFactory()
00086 {
00087 }
00088 
00089 QString
00090 KexiReportFactory::name()
00091 {
00092     return "kexireportwidgets";
00093 }
00094 
00095 QWidget*
00096 KexiReportFactory::createWidget(const QCString &c, QWidget *p, const char *n, 
00097     KFormDesigner::Container *container, int options)
00098 {
00099     Q_UNUSED(options);
00100     kexipluginsdbg << "KexiReportFactory::create() " << this << endl;
00101 
00102     QString text( container->form()->library()->textForWidgetName(n, c) );
00103 
00104     if(c == "Label")
00105         return new Label(text, p, n);
00106     else if(c == "PicLabel")
00107         return new PicLabel(DesktopIcon("image"), p, n);
00108     else if(c == "ReportLine")
00109         return new ReportLine(p, n);
00110     else if(c == "KexiSubReport")
00111         return new KexiSubReport(p, n);
00112 
00113     return 0;
00114 }
00115 
00116 bool
00117 KexiReportFactory::createMenuActions(const QCString &classname, QWidget *w, 
00118     QPopupMenu *menu,   KFormDesigner::Container *container)
00119 {
00120     Q_UNUSED(w);
00121     Q_UNUSED(container);
00122     if(classname == "Label") {
00124         menu->insertItem(SmallIconSet("edit"), i18n("Edit Rich Text"), this, SLOT(editText()));
00125         return true;
00126     }
00127     return false;
00128 }
00129 
00130 bool
00131 KexiReportFactory::startEditing(const QCString &c, QWidget *w, KFormDesigner::Container *container)
00132 {
00133     m_container = container;
00134 
00135     if(c == "Label") {
00136         QLabel *label = static_cast<QLabel*>(w);
00137         if(label->textFormat() == RichText) {
00138             m_widget = w;
00139             editText();
00140         }
00141         else
00142             createEditor(c, label->text(), label, container, label->geometry(), label->alignment());
00143         return true;
00144     }
00145     return false;
00146 }
00147 
00148 bool
00149 KexiReportFactory::isPropertyVisibleInternal(const QCString &classname, QWidget *w, const QCString &property, bool isTopLevel)
00150 {
00151     if(classname == "Label") {
00152         if(property == "pixmap")
00153             return false;
00154     }
00155     else if(classname == "PicLabel") {
00156         if((property == "text") || (property == "indent") || (property == "textFormat") || (property == "font") || (property == "alignment"))
00157             return false;
00158     }
00159 
00160     return WidgetFactory::isPropertyVisibleInternal(classname, w, property, isTopLevel);
00161 }
00162 
00163 QValueList<QCString>
00164 KexiReportFactory::autoSaveProperties(const QCString &classname)
00165 {
00166     QValueList<QCString> l;
00167 
00168     if(classname == "Label")
00169         l << "text";
00170     else if(classname == "PicLabel")
00171         l << "pixmap";
00172 
00173     return l;
00174 }
00175 
00176 /*
00177 void
00178 KexiReportFactory::changeText(const QString &text)
00179 {
00180     QWidget *w = WidgetFactory::m_widget;
00181     changeProperty("text", text, m_container);
00182 
00183     int width = w->sizeHint().width();
00184 
00185     if(w->width() < width)
00186         w->resize(width, w->height() );
00187 }
00188 
00189 void
00190 KexiReportFactory::resizeEditor(QWidget *widget, const QCString &)
00191 {
00192     QSize s = widget->size();
00193     QPoint p = widget->pos();
00194     QRect r;
00195 
00196     m_editor->resize(s);
00197     m_editor->move(p);
00198 }*/
00199 
00200 void
00201 KexiReportFactory::editText()
00202 {
00203     QCString classname = m_widget->className();
00204     QString text;
00205 
00206     if(classname == "Label")
00207         text = ((QLabel*)m_widget)->text();
00208 
00209     if(editRichText(m_widget, text)) {
00210         changeProperty("textFormat", "RichText", m_container->form());
00211         changeProperty("text", text, m_container->form());
00212     }
00213 
00214     if(classname == "Label")
00215         m_widget->resize(m_widget->sizeHint());
00216 }
00217 
00218 bool
00219 KexiReportFactory::previewWidget(const QCString &, QWidget *, KFormDesigner::Container *)
00220 {
00221     return false;
00222 }
00223 
00224 KFORMDESIGNER_WIDGET_FACTORY(KexiReportFactory, kexireportwidgets)
00225 
00226 #include "kexireportfactory.moc"
00227 
KDE Home | KDE Accessibility Home | Description of Access Keys