kexi

kexireportform.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Lucijan Busch <lucijan@kde.org>
3 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include <tqobjectlist.h>
22#include <tqpainter.h>
23#include <tqcursor.h>
24
25#include <kdebug.h>
26
27#include "kexireportform.h"
28
29KexiReportForm::KexiReportForm(TQWidget *parent, const char *name/*, KexiDB::Connection *conn*/)
30 : TQWidget(parent, name)
31{
32 //m_conn = conn;
33 kexipluginsdbg << "KexiReportForm::KexiReportForm(): " << endl;
34 setCursor(TQCursor(TQt::ArrowCursor)); //to avoid keeping Size cursor when moving from form's boundaries
35 setBackgroundColor(white);
36}
37
38KexiReportForm::~KexiReportForm()
39{
40 kexipluginsdbg << "KexiReportForm::~KexiReportForm(): close" << endl;
41}
42
43//repaint all children widgets
44static void repaintAll(TQWidget *w)
45{
46 TQObjectList *list = w->queryList("TQWidget");
47 TQObjectListIt it(*list);
48 for (TQObject *obj; (obj=it.current()); ++it ) {
49 static_cast<TQWidget*>(obj)->repaint();
50 }
51 delete list;
52}
53
54void
55KexiReportForm::drawRect(const TQRect& r, int type)
56{
57 TQValueList<TQRect> l;
58 l.append(r);
59 drawRects(l, type);
60}
61
62void
63KexiReportForm::drawRects(const TQValueList<TQRect> &list, int type)
64{
65 TQPainter p;
66 p.begin(this, true);
67 bool unclipped = testWFlags( WPaintUnclipped );
68 setWFlags( WPaintUnclipped );
69
70 if (prev_rect.isValid()) {
71 //redraw prev. selection's rectangle
72 p.drawPixmap( TQPoint(prev_rect.x()-2, prev_rect.y()-2), buffer, TQRect(prev_rect.x()-2, prev_rect.y()-2, prev_rect.width()+4, prev_rect.height()+4));
73 }
74 p.setBrush(TQBrush::NoBrush);
75 if(type == 1) // selection rect
76 p.setPen(TQPen(white, 1, TQt::DotLine));
77 else if(type == 2) // insert rect
78 p.setPen(TQPen(white, 2));
79 p.setRasterOp(XorROP);
80
81 prev_rect = TQRect();
82 TQValueList<TQRect>::ConstIterator endIt = list.constEnd();
83 for(TQValueList<TQRect>::ConstIterator it = list.constBegin(); it != endIt; ++it) {
84 p.drawRect(*it);
85 prev_rect = prev_rect.unite(*it);
86 }
87
88 if (!unclipped)
89 clearWFlags( WPaintUnclipped );
90 p.end();
91}
92
93void
95{
96 repaintAll(this);
97 buffer.resize( width(), height() );
98 buffer = TQPixmap::grabWindow( winId() );
99 prev_rect = TQRect();
100}
101
102void
104{
105 TQPainter p;
106 p.begin(this, true);
107 bool unclipped = testWFlags( WPaintUnclipped );
108 setWFlags( WPaintUnclipped );
109
110 //redraw entire form surface
111 p.drawPixmap( TQPoint(0,0), buffer, TQRect(0,0,buffer.width(), buffer.height()) );
112
113 if (!unclipped)
114 clearWFlags( WPaintUnclipped );
115 p.end();
116
117 repaintAll(this);
118}
119
120void
121KexiReportForm::highlightWidgets(TQWidget *from, TQWidget *to)//, const TQPoint &point)
122{
123 TQPoint fromPoint, toPoint;
124 if(from && from->parentWidget() && (from != this))
125 fromPoint = from->parentWidget()->mapTo(this, from->pos());
126 if(to && to->parentWidget() && (to != this))
127 toPoint = to->parentWidget()->mapTo(this, to->pos());
128
129 TQPainter p;
130 p.begin(this, true);
131 bool unclipped = testWFlags( WPaintUnclipped );
132 setWFlags( WPaintUnclipped );
133
134 if (prev_rect.isValid()) {
135 //redraw prev. selection's rectangle
136 p.drawPixmap( TQPoint(prev_rect.x(), prev_rect.y()), buffer, TQRect(prev_rect.x(), prev_rect.y(), prev_rect.width(), prev_rect.height()));
137 }
138
139 p.setPen( TQPen(TQt::red, 2) );
140
141 if(to)
142 {
143 TQPixmap pix1 = TQPixmap::grabWidget(from);
144 TQPixmap pix2 = TQPixmap::grabWidget(to);
145
146 if((from != this) && (to != this))
147 p.drawLine( from->parentWidget()->mapTo(this, from->geometry().center()), to->parentWidget()->mapTo(this, to->geometry().center()) );
148
149 p.drawPixmap(fromPoint.x(), fromPoint.y(), pix1);
150 p.drawPixmap(toPoint.x(), toPoint.y(), pix2);
151
152 if(to == this)
153 p.drawRoundRect(2, 2, width()-4, height()-4, 4, 4);
154 else
155 p.drawRoundRect(toPoint.x(), toPoint.y(), to->width(), to->height(), 5, 5);
156 }
157
158 if(from == this)
159 p.drawRoundRect(2, 2, width()-4, height()-4, 4, 4);
160 else
161 p.drawRoundRect(fromPoint.x(), fromPoint.y(), from->width(), from->height(), 5, 5);
162
163 if((to == this) || (from == this))
164 prev_rect = TQRect(0, 0, buffer.width(), buffer.height());
165 else if(to)
166 {
167 prev_rect.setX( (fromPoint.x() < toPoint.x()) ? (fromPoint.x() - 5) : (toPoint.x() - 5) );
168 prev_rect.setY( (fromPoint.y() < toPoint.y()) ? (fromPoint.y() - 5) : (toPoint.y() - 5) );
169 prev_rect.setRight( (fromPoint.x() < toPoint.x()) ? (toPoint.x() + to->width() + 10) : (fromPoint.x() + from->width() + 10) );
170 prev_rect.setBottom( (fromPoint.y() < toPoint.y()) ? (toPoint.y() + to->height() + 10) : (fromPoint.y() + from->height() + 10) ) ;
171 }
172 else
173 prev_rect = TQRect(fromPoint.x()- 5, fromPoint.y() -5, from->width() + 10, from->height() + 10);
174
175 if (!unclipped)
176 clearWFlags( WPaintUnclipped );
177 p.end();
178}
179
180TQSize
181KexiReportForm::sizeHint() const
182{
183 //todo: find better size (user configured?)
184 return TQSize(400,300);
185}
186
187#include "kexireportform.moc"
188
virtual void clearForm()
virtual void highlightWidgets(TQWidget *from, TQWidget *to)
virtual void drawRects(const TQValueList< TQRect > &list, int type)
virtual void initBuffer()