summaryrefslogtreecommitdiffstats
path: root/kopete/libkopete/webcamwidget.cpp
blob: ae617ad591bfdbc22e2bf32a1076077addd1ceaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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"