diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | bcb704366cb5e333a626c18c308c7e0448a8e69f (patch) | |
tree | f0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /kopete/libkopete/webcamwidget.cpp | |
download | tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.tar.gz tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kopete/libkopete/webcamwidget.cpp')
-rw-r--r-- | kopete/libkopete/webcamwidget.cpp | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/kopete/libkopete/webcamwidget.cpp b/kopete/libkopete/webcamwidget.cpp new file mode 100644 index 00000000..ae617ad5 --- /dev/null +++ b/kopete/libkopete/webcamwidget.cpp @@ -0,0 +1,107 @@ +/* + webcamwidget.h - A simple widget for displaying webcam frames + + Copyright (c) 2006 by Gustavo Pichorim Boiko <[email protected]> + Kopete (c) 2002-2006 by the Kopete developers <[email protected]> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "webcamwidget.h" + +#include <qcolor.h> +#include <qpainter.h> + +#include <kdebug.h> +namespace Kopete +{ + +WebcamWidget::WebcamWidget( QWidget* parent, const char* name ) +: QWidget( parent, name ) +{ + clear(); +} + +WebcamWidget::~WebcamWidget() +{ + // don't do anything either +} + +void WebcamWidget::updatePixmap(const QPixmap& pixmap) +{ + mPixmap = pixmap; + mText = ""; + + QPaintEvent *ev = new QPaintEvent( rect(), true ); + paintEvent( ev ); + delete ev; +} + +void WebcamWidget::clear() +{ + mText = ""; + if (!mPixmap.isNull()) + mPixmap.resize(0,0); + + QPaintEvent *ev = new QPaintEvent( rect(), true ); + paintEvent( ev ); + delete ev; +} + +void WebcamWidget::setText(const QString& text) +{ + mText = text; + + // for now redraw everything + QPaintEvent *ev = new QPaintEvent( rect(), true ); + paintEvent( ev ); + delete ev; +} + +void WebcamWidget::paintEvent( QPaintEvent* event ) +{ + QMemArray<QRect> rects = event->region().rects(); + + if (!mPixmap.isNull()) + { + for (unsigned int i = 0; i < rects.count(); ++i) + { + bitBlt(this, rects[i].topLeft(), &mPixmap, rects[i], Qt::CopyROP, true); + } + } + else + { + for (unsigned int i = 0; i < rects.count(); ++i) + { + QColor bgColor = paletteBackgroundColor(); + QPainter p(this); + p.fillRect(rects[i], bgColor); + } + } + + // TODO: draw the text + QPainter p(this); + QRect r = p.boundingRect(rect(), Qt::AlignCenter | Qt::WordBreak, mText ); + if ( !mText.isEmpty() && event->rect().intersects(r)) + { + p.setPen(Qt::black); + QRect rec = rect(); + rec.moveTopLeft(QPoint(1,1)); + p.drawText(rec, Qt::AlignCenter | Qt::WordBreak, mText, -1); + + rec.moveTopLeft(QPoint(-1,-1)); + p.setPen(Qt::white); + p.drawText(rec, Qt::AlignCenter | Qt::WordBreak, mText, -1); + } +} + +} // end namespace Kopete + +#include "webcamwidget.moc" |