2 webcamwidget.h - A simple widget for displaying webcam frames
4 Copyright (c) 2006 by Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
5 Kopete (c) 2002-2006 by the Kopete developers <kopete-devel@kde.org>
7 *************************************************************************
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
14 *************************************************************************
17 #include "webcamwidget.h"
21 #include <QPaintEvent>
27 WebcamWidget::WebcamWidget(QWidget
* parent
)
33 WebcamWidget::~WebcamWidget()
35 // don't do anything either
38 void WebcamWidget::updatePixmap(const QPixmap
& pixmap
)
46 void WebcamWidget::clear()
49 if (!mPixmap
.isNull())
50 mPixmap
= QPixmap(0,0);
55 void WebcamWidget::setText(const QString
& text
)
59 // for now redraw everything
63 void WebcamWidget::paintEvent( QPaintEvent
* event
)
65 QVector
<QRect
> rects
= event
->region().rects();
68 if (!mPixmap
.isNull())
70 for (int i
= 0; i
< rects
.count(); ++i
)
72 p
.drawPixmap(rects
[i
], mPixmap
, rects
[i
]);
77 for (int i
= 0; i
< rects
.count(); ++i
)
79 QColor bgColor
= palette().color(QPalette::Background
);
80 p
.fillRect(rects
[i
], bgColor
);
84 // TODO: draw the text
85 QRect r
= p
.boundingRect(rect(), Qt::AlignCenter
| Qt::TextWordWrap
, mText
);
86 if ( !mText
.isEmpty() && event
->rect().intersects(r
))
90 rec
.moveTopLeft(QPoint(1,1));
91 p
.drawText(rec
, Qt::AlignCenter
| Qt::TextWordWrap
, mText
);
93 rec
.moveTopLeft(QPoint(-1,-1));
95 p
.drawText(rec
, Qt::AlignCenter
| Qt::TextWordWrap
, mText
);
100 } // end namespace Kopete
102 #include "webcamwidget.moc"