kexi

reportwidgets.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19#include <tqpainter.h>
20
21#include <form.h>
22#include <formIO.h>
23#include <formmanager.h>
24#include <kexidb/utils.h>
25#include <kexidb/connection.h>
26#include <kexipart.h>
27
28#include "kexireportview.h"
29#include "reportwidgets.h"
30
31Label::Label(const TQString &text, TQWidget *parent, const char *name)
32: TQLabel(text, parent, name)
33{
34 setPaletteBackgroundColor(white);
35}
36
38
39ReportLine::ReportLine(TQWidget *parent, const char *name)
40: TQWidget(parent, name)
41{
42 m_lineStyle = (ReportLineStyle)TQt::SolidLine;
43 m_lineWidth = 1;
44 m_capStyle = (CapStyle)TQt::FlatCap;
45 m_color = paletteForegroundColor();
46 setPaletteBackgroundColor(white);
47}
48
49ReportLine::ReportLineStyle
50ReportLine::lineStyle() const
51{
52 return m_lineStyle;
53}
54
55void
56ReportLine::setLineStyle(ReportLineStyle style)
57{
58 m_lineStyle = style;
59 update();
60}
61
62int
63ReportLine::lineWidth() const
64{
65 return m_lineWidth;
66}
67
68void
69ReportLine::setLineWidth(int width)
70{
71 m_lineWidth = width;
72 update();
73}
74
75TQColor
76ReportLine::color() const
77{
78 return m_color;
79}
80
81void
82ReportLine::setColor(const TQColor &color)
83{
84 m_color = color;
85 update();
86}
87
88ReportLine::CapStyle
89ReportLine::capStyle() const
90{
91 return m_capStyle;
92}
93
94void
95ReportLine::setCapStyle(CapStyle capStyle)
96{
97 m_capStyle = capStyle;
98 update();
99}
100
101void
102ReportLine::paintEvent (TQPaintEvent *ev)
103{
104 TQPainter p(this);
105 if(!ev->erased())
106 p.eraseRect(0, 0, width(), height());
107 TQPen pen(m_color, m_lineWidth, (TQt::PenStyle)m_lineStyle);
108 pen.setCapStyle((TQt::PenCapStyle)m_capStyle);
109 p.setPen(pen);
110 p.drawLine(0, 0, width() -1, height() - 1);
111}
112
114
115
116PicLabel::PicLabel(const TQPixmap &pix, TQWidget *parent, const char *name)
117 : TQLabel(parent, name)
118{
119 setPixmap(pix);
120 setScaledContents(false);
121 setPaletteBackgroundColor(white);
122}
123
124bool
125PicLabel::setProperty(const char *name, const TQVariant &value)
126{
127 if(TQString(name) == "pixmap")
128 resize(value.toPixmap().height(), value.toPixmap().width());
129 return TQLabel::setProperty(name, value);
130}
131
133
134KexiSubReport::KexiSubReport(TQWidget *parent, const char *name)
135: TQScrollView(parent, name), m_form(0), m_widget(0)
136{
137 setFrameStyle(TQFrame::Plain | TQFrame::Box);
138 viewport()->setPaletteBackgroundColor(white);
139}
140
141void
142KexiSubReport::setReportName(const TQString &name)
143{
144 if(name.isEmpty())
145 return;
146
147 // we need a KexiReportView*
148 TQWidget *w = parentWidget();
149 while(w && !w->isA("KexiReportView"))
150 w = w->parentWidget();
151 KexiReportView *view = (KexiReportView*)w;
152 if(!view)
153 return;
154
155 // we check if there is a form with this name
156 int id = KexiDB::idForObjectName(*(view->connection()), name, KexiPart::ReportObjectType);
157 if((id == 0) || (id == view->parentDialog()->id())) // == our form
158 return; // because of recursion when loading
159
160 // we create the container widget
161 delete m_widget;
162 m_widget = new TQWidget(viewport(), "kexisubreport_widget");
163 m_widget->show();
164 addChild(m_widget);
165 m_form = new Form(KexiReportPart::library(), this->name());
166 m_form->createToplevel(m_widget);
167
168 // and load the sub form
169 TQString data;
170 tristate res = view->connection()->loadDataBlock(id, data , TQString());
171 if(res != true)
172 return;
173
174 KFormDesigner::FormIO::loadFormFromString(m_form, m_widget, data);
175 m_form->setDesignMode(false);
176
177 m_reportName = name;
178}
179
180#include "reportwidgets.moc"
181
tristate loadDataBlock(int objectID, TQString &dataString, const TQString &dataID)
static KFormDesigner::WidgetLibrary * library()
KexiDialogBase * parentDialog() const
KEXI_DB_EXPORT int idForObjectName(Connection &conn, const TQString &objName, int objType)