00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qobjectlist.h>
00022 #include <qpainter.h>
00023 #include <qcursor.h>
00024
00025 #include <kdebug.h>
00026
00027 #include "kexireportform.h"
00028
00029 KexiReportForm::KexiReportForm(QWidget *parent, const char *name)
00030 : QWidget(parent, name)
00031 {
00032
00033 kexipluginsdbg << "KexiReportForm::KexiReportForm(): " << endl;
00034 setCursor(QCursor(Qt::ArrowCursor));
00035 setBackgroundColor(white);
00036 }
00037
00038 KexiReportForm::~KexiReportForm()
00039 {
00040 kexipluginsdbg << "KexiReportForm::~KexiReportForm(): close" << endl;
00041 }
00042
00043
00044 static void repaintAll(QWidget *w)
00045 {
00046 QObjectList *list = w->queryList("QWidget");
00047 QObjectListIt it(*list);
00048 for (QObject *obj; (obj=it.current()); ++it ) {
00049 static_cast<QWidget*>(obj)->repaint();
00050 }
00051 delete list;
00052 }
00053
00054 void
00055 KexiReportForm::drawRect(const QRect& r, int type)
00056 {
00057 QValueList<QRect> l;
00058 l.append(r);
00059 drawRects(l, type);
00060 }
00061
00062 void
00063 KexiReportForm::drawRects(const QValueList<QRect> &list, int type)
00064 {
00065 QPainter p;
00066 p.begin(this, true);
00067 bool unclipped = testWFlags( WPaintUnclipped );
00068 setWFlags( WPaintUnclipped );
00069
00070 if (prev_rect.isValid()) {
00071
00072 p.drawPixmap( QPoint(prev_rect.x()-2, prev_rect.y()-2), buffer, QRect(prev_rect.x()-2, prev_rect.y()-2, prev_rect.width()+4, prev_rect.height()+4));
00073 }
00074 p.setBrush(QBrush::NoBrush);
00075 if(type == 1)
00076 p.setPen(QPen(white, 1, Qt::DotLine));
00077 else if(type == 2)
00078 p.setPen(QPen(white, 2));
00079 p.setRasterOp(XorROP);
00080
00081 prev_rect = QRect();
00082 QValueList<QRect>::ConstIterator endIt = list.constEnd();
00083 for(QValueList<QRect>::ConstIterator it = list.constBegin(); it != endIt; ++it) {
00084 p.drawRect(*it);
00085 prev_rect = prev_rect.unite(*it);
00086 }
00087
00088 if (!unclipped)
00089 clearWFlags( WPaintUnclipped );
00090 p.end();
00091 }
00092
00093 void
00094 KexiReportForm::initBuffer()
00095 {
00096 repaintAll(this);
00097 buffer.resize( width(), height() );
00098 buffer = QPixmap::grabWindow( winId() );
00099 prev_rect = QRect();
00100 }
00101
00102 void
00103 KexiReportForm::clearForm()
00104 {
00105 QPainter p;
00106 p.begin(this, true);
00107 bool unclipped = testWFlags( WPaintUnclipped );
00108 setWFlags( WPaintUnclipped );
00109
00110
00111 p.drawPixmap( QPoint(0,0), buffer, QRect(0,0,buffer.width(), buffer.height()) );
00112
00113 if (!unclipped)
00114 clearWFlags( WPaintUnclipped );
00115 p.end();
00116
00117 repaintAll(this);
00118 }
00119
00120 void
00121 KexiReportForm::highlightWidgets(QWidget *from, QWidget *to)
00122 {
00123 QPoint fromPoint, toPoint;
00124 if(from && from->parentWidget() && (from != this))
00125 fromPoint = from->parentWidget()->mapTo(this, from->pos());
00126 if(to && to->parentWidget() && (to != this))
00127 toPoint = to->parentWidget()->mapTo(this, to->pos());
00128
00129 QPainter p;
00130 p.begin(this, true);
00131 bool unclipped = testWFlags( WPaintUnclipped );
00132 setWFlags( WPaintUnclipped );
00133
00134 if (prev_rect.isValid()) {
00135
00136 p.drawPixmap( QPoint(prev_rect.x(), prev_rect.y()), buffer, QRect(prev_rect.x(), prev_rect.y(), prev_rect.width(), prev_rect.height()));
00137 }
00138
00139 p.setPen( QPen(Qt::red, 2) );
00140
00141 if(to)
00142 {
00143 QPixmap pix1 = QPixmap::grabWidget(from);
00144 QPixmap pix2 = QPixmap::grabWidget(to);
00145
00146 if((from != this) && (to != this))
00147 p.drawLine( from->parentWidget()->mapTo(this, from->geometry().center()), to->parentWidget()->mapTo(this, to->geometry().center()) );
00148
00149 p.drawPixmap(fromPoint.x(), fromPoint.y(), pix1);
00150 p.drawPixmap(toPoint.x(), toPoint.y(), pix2);
00151
00152 if(to == this)
00153 p.drawRoundRect(2, 2, width()-4, height()-4, 4, 4);
00154 else
00155 p.drawRoundRect(toPoint.x(), toPoint.y(), to->width(), to->height(), 5, 5);
00156 }
00157
00158 if(from == this)
00159 p.drawRoundRect(2, 2, width()-4, height()-4, 4, 4);
00160 else
00161 p.drawRoundRect(fromPoint.x(), fromPoint.y(), from->width(), from->height(), 5, 5);
00162
00163 if((to == this) || (from == this))
00164 prev_rect = QRect(0, 0, buffer.width(), buffer.height());
00165 else if(to)
00166 {
00167 prev_rect.setX( (fromPoint.x() < toPoint.x()) ? (fromPoint.x() - 5) : (toPoint.x() - 5) );
00168 prev_rect.setY( (fromPoint.y() < toPoint.y()) ? (fromPoint.y() - 5) : (toPoint.y() - 5) );
00169 prev_rect.setRight( (fromPoint.x() < toPoint.x()) ? (toPoint.x() + to->width() + 10) : (fromPoint.x() + from->width() + 10) );
00170 prev_rect.setBottom( (fromPoint.y() < toPoint.y()) ? (toPoint.y() + to->height() + 10) : (fromPoint.y() + from->height() + 10) ) ;
00171 }
00172 else
00173 prev_rect = QRect(fromPoint.x()- 5, fromPoint.y() -5, from->width() + 10, from->height() + 10);
00174
00175 if (!unclipped)
00176 clearWFlags( WPaintUnclipped );
00177 p.end();
00178 }
00179
00180 QSize
00181 KexiReportForm::sizeHint() const
00182 {
00183
00184 return QSize(400,300);
00185 }
00186
00187 #include "kexireportform.moc"
00188