kexi

reportwidgets.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 <qpainter.h>
00020 
00021 #include <form.h>
00022 #include <formIO.h>
00023 #include <formmanager.h>
00024 #include <kexidb/utils.h>
00025 #include <kexidb/connection.h>
00026 #include <kexipart.h>
00027 
00028 #include "kexireportview.h"
00029 #include "reportwidgets.h"
00030 
00031 Label::Label(const QString &text, QWidget *parent, const char *name)
00032 : QLabel(text, parent, name)
00033 {
00034     setPaletteBackgroundColor(white);
00035 }
00036 
00038 
00039 ReportLine::ReportLine(QWidget *parent, const char *name)
00040 : QWidget(parent, name)
00041 {
00042     m_lineStyle = (ReportLineStyle)Qt::SolidLine;
00043     m_lineWidth = 1;
00044     m_capStyle = (CapStyle)Qt::FlatCap;
00045     m_color = paletteForegroundColor();
00046     setPaletteBackgroundColor(white);
00047 }
00048 
00049 ReportLine::ReportLineStyle
00050 ReportLine::lineStyle() const
00051 {
00052     return m_lineStyle;
00053 }
00054 
00055 void
00056 ReportLine::setLineStyle(ReportLineStyle style)
00057 {
00058     m_lineStyle = style;
00059     update();
00060 }
00061 
00062 int
00063 ReportLine::lineWidth() const
00064 {
00065     return m_lineWidth;
00066 }
00067 
00068 void
00069 ReportLine::setLineWidth(int width)
00070 {
00071     m_lineWidth = width;
00072     update();
00073 }
00074 
00075 QColor
00076 ReportLine::color() const
00077 {
00078     return m_color;
00079 }
00080 
00081 void
00082 ReportLine::setColor(const QColor &color)
00083 {
00084     m_color = color;
00085     update();
00086 }
00087 
00088 ReportLine::CapStyle
00089 ReportLine::capStyle() const
00090 {
00091     return m_capStyle;
00092 }
00093 
00094 void
00095 ReportLine::setCapStyle(CapStyle capStyle)
00096 {
00097     m_capStyle = capStyle;
00098     update();
00099 }
00100 
00101 void
00102 ReportLine::paintEvent (QPaintEvent *ev)
00103 {
00104     QPainter p(this);
00105     if(!ev->erased())
00106         p.eraseRect(0, 0, width(), height());
00107     QPen pen(m_color, m_lineWidth, (Qt::PenStyle)m_lineStyle);
00108     pen.setCapStyle((Qt::PenCapStyle)m_capStyle);
00109     p.setPen(pen);
00110     p.drawLine(0, 0, width() -1, height() - 1);
00111 }
00112 
00114 
00115 
00116 PicLabel::PicLabel(const QPixmap &pix, QWidget *parent, const char *name)
00117  : QLabel(parent, name)
00118 {
00119     setPixmap(pix);
00120     setScaledContents(false);
00121     setPaletteBackgroundColor(white);
00122 }
00123 
00124 bool
00125 PicLabel::setProperty(const char *name, const QVariant &value)
00126 {
00127     if(QString(name) == "pixmap")
00128         resize(value.toPixmap().height(), value.toPixmap().width());
00129     return QLabel::setProperty(name, value);
00130 }
00131 
00133 
00134 KexiSubReport::KexiSubReport(QWidget *parent, const char *name)
00135 : QScrollView(parent, name), m_form(0), m_widget(0)
00136 {
00137     setFrameStyle(QFrame::Plain | QFrame::Box);
00138     viewport()->setPaletteBackgroundColor(white);
00139 }
00140 
00141 void
00142 KexiSubReport::setReportName(const QString &name)
00143 {
00144     if(name.isEmpty())
00145         return;
00146 
00147     // we need a KexiReportView*
00148     QWidget *w = parentWidget();
00149     while(w && !w->isA("KexiReportView"))
00150         w = w->parentWidget();
00151     KexiReportView *view = (KexiReportView*)w;
00152     if(!view)
00153         return;
00154 
00155     // we check if there is a form with this name
00156     int id = KexiDB::idForObjectName(*(view->connection()), name, KexiPart::ReportObjectType);
00157     if((id == 0) || (id == view->parentDialog()->id())) // == our form
00158         return; // because of recursion when loading
00159 
00160     // we create the container widget
00161     delete m_widget;
00162     m_widget = new QWidget(viewport(), "kexisubreport_widget");
00163     m_widget->show();
00164     addChild(m_widget);
00165     m_form = new Form(KexiReportPart::library(), this->name());
00166     m_form->createToplevel(m_widget);
00167 
00168     // and load the sub form
00169     QString data;
00170     tristate res = view->connection()->loadDataBlock(id, data , QString::null);
00171     if(res != true)
00172         return;
00173 
00174     KFormDesigner::FormIO::loadFormFromString(m_form, m_widget, data);
00175     m_form->setDesignMode(false);
00176 
00177     m_reportName = name;
00178 }
00179 
00180 #include "reportwidgets.moc"
00181 
KDE Home | KDE Accessibility Home | Description of Access Keys