Show invite menu in wlm chat window immediately
[kdenetwork.git] / kopete / libkopete / ui / webcamwidget.cpp
blob7116e9e3f351505c601d1ba3962f03f3205fbadf
1 /*
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 *************************************************************************
8 * *
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. *
13 * *
14 *************************************************************************
17 #include "webcamwidget.h"
19 #include <QColor>
20 #include <QPainter>
21 #include <QPaintEvent>
23 #include <kdebug.h>
24 namespace Kopete
27 WebcamWidget::WebcamWidget(QWidget* parent)
28 : QWidget(parent)
30 clear();
33 WebcamWidget::~WebcamWidget()
35 // don't do anything either
38 void WebcamWidget::updatePixmap(const QPixmap& pixmap)
40 mPixmap = pixmap;
41 mText = "";
43 update();
46 void WebcamWidget::clear()
48 mText = "";
49 if (!mPixmap.isNull())
50 mPixmap = QPixmap(0,0);
52 update();
55 void WebcamWidget::setText(const QString& text)
57 mText = text;
59 // for now redraw everything
60 update();
63 void WebcamWidget::paintEvent( QPaintEvent* event )
65 QVector<QRect> rects = event->region().rects();
67 QPainter p(this);
68 if (!mPixmap.isNull())
70 for (int i = 0; i < rects.count(); ++i)
72 p.drawPixmap(rects[i], mPixmap, rects[i]);
75 else
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))
88 p.setPen(Qt::black);
89 QRect rec = rect();
90 rec.moveTopLeft(QPoint(1,1));
91 p.drawText(rec, Qt::AlignCenter | Qt::TextWordWrap, mText);
93 rec.moveTopLeft(QPoint(-1,-1));
94 p.setPen(Qt::white);
95 p.drawText(rec, Qt::AlignCenter | Qt::TextWordWrap, mText);
97 p.end();
100 } // end namespace Kopete
102 #include "webcamwidget.moc"