• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kopete/libkopete

  • sources
  • kde-4.14
  • kdenetwork
  • kopete
  • libkopete
  • ui
webcamwidget.cpp
Go to the documentation of this file.
1 /*
2  webcamwidget.h - A simple widget for displaying webcam frames
3 
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>
6 
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  *************************************************************************
15 */
16 
17 #include "webcamwidget.h"
18 
19 #include <QColor>
20 #include <QPainter>
21 #include <QPaintEvent>
22 
23 #include <kdebug.h>
24 namespace Kopete
25 {
26 
27 WebcamWidget::WebcamWidget(QWidget* parent)
28 : QWidget(parent)
29 {
30  clear();
31 }
32 
33 WebcamWidget::~WebcamWidget()
34 {
35  // don't do anything either
36 }
37 
38 void WebcamWidget::updatePixmap(const QPixmap& pixmap)
39 {
40  mPixmap = pixmap;
41  mText = "";
42 
43  update();
44 }
45 
46 void WebcamWidget::clear()
47 {
48  mText = "";
49  if (!mPixmap.isNull())
50  mPixmap = QPixmap(0,0);
51 
52  update();
53 }
54 
55 void WebcamWidget::setText(const QString& text)
56 {
57  mText = text;
58 
59  // for now redraw everything
60  update();
61 }
62 
63 void WebcamWidget::paintEvent( QPaintEvent* event )
64 {
65  QVector<QRect> rects = event->region().rects();
66 
67  QPainter p(this);
68  if (!mPixmap.isNull())
69  {
70  for (int i = 0; i < rects.count(); ++i)
71  {
72  p.drawPixmap(rects[i], mPixmap, rects[i]);
73  }
74  }
75  else
76  {
77  for (int i = 0; i < rects.count(); ++i)
78  {
79  QColor bgColor = palette().color(QPalette::Background);
80  p.fillRect(rects[i], bgColor);
81  }
82  }
83 
84  // TODO: draw the text
85  QRect r = p.boundingRect(rect(), Qt::AlignCenter | Qt::TextWordWrap, mText );
86  if ( !mText.isEmpty() && event->rect().intersects(r))
87  {
88  p.setPen(Qt::black);
89  QRect rec = rect();
90  rec.moveTopLeft(QPoint(1,1));
91  p.drawText(rec, Qt::AlignCenter | Qt::TextWordWrap, mText);
92 
93  rec.moveTopLeft(QPoint(-1,-1));
94  p.setPen(Qt::white);
95  p.drawText(rec, Qt::AlignCenter | Qt::TextWordWrap, mText);
96  }
97  p.end();
98 }
99 
100 } // end namespace Kopete
101 
102 #include "webcamwidget.moc"
QWidget
QWidget::palette
const QPalette & palette() const
QPainter::end
bool end()
QPainter::fillRect
void fillRect(const QRectF &rectangle, const QBrush &brush)
webcamwidget.h
Kopete::WebcamWidget::updatePixmap
void updatePixmap(const QPixmap &pixmap)
Updates the frame being displayed in the widget.
Definition: webcamwidget.cpp:38
QPalette::color
const QColor & color(ColorGroup group, ColorRole role) const
QPoint
QRect::moveTopLeft
void moveTopLeft(const QPoint &position)
QWidget::update
void update()
QRect
QPainter::boundingRect
QRectF boundingRect(const QRectF &rectangle, int flags, const QString &text)
QPainter::setPen
void setPen(const QColor &color)
QPainter::drawPixmap
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
QPainter
Kopete::WebcamWidget::paintEvent
void paintEvent(QPaintEvent *event)
Definition: webcamwidget.cpp:63
QString::isEmpty
bool isEmpty() const
Kopete::WebcamWidget::WebcamWidget
WebcamWidget(QWidget *parent=0)
WebcamWidget constructor.
Definition: webcamwidget.cpp:27
QPainter::drawText
void drawText(const QPointF &position, const QString &text)
QString
QColor
QWidget::rect
QRect rect() const
QPixmap
QPixmap::isNull
bool isNull() const
Kopete::WebcamWidget::clear
void clear()
Clear the widget.
Definition: webcamwidget.cpp:46
QVector
Kopete::WebcamWidget::~WebcamWidget
~WebcamWidget()
Definition: webcamwidget.cpp:33
QVector::count
int count(const T &value) const
QPaintEvent
Kopete::WebcamWidget::setText
void setText(const QString &text)
Set a text to be displayed in the widget.
Definition: webcamwidget.cpp:55
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:29:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/libkopete

Skip menu "kopete/libkopete"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal