1 /***************************************************************************
2 * Copyright (C) 2008-2009 by ������ �.�. *
3 * valexlin@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21 #include "blinklabel.h"
22
23 #include <QTimer>
24 #include <QPainter>
25
QBlinkLabel(QWidget * parent)26 QBlinkLabel::QBlinkLabel(QWidget* parent)
27 : QLabel(parent, 0)
28 {
29 BlinkTimer = new QTimer(this);
30 BlinkPos = 0;
31 connect(BlinkTimer, SIGNAL(timeout()), this, SLOT(slotTimer()));
32 }
33
QBlinkLabel(const QString & text,QWidget * parent)34 QBlinkLabel::QBlinkLabel(const QString& text, QWidget* parent)
35 : QLabel(text, parent, 0)
36 {
37 BlinkTimer = new QTimer(this);
38 BlinkPos = 0;
39 connect(BlinkTimer, SIGNAL(timeout()), this, SLOT(slotTimer()));
40 }
41
~QBlinkLabel()42 QBlinkLabel::~QBlinkLabel()
43 {
44 // ????????????
45 delete BlinkTimer;
46 }
47
start()48 void QBlinkLabel::start()
49 {
50 BlinkTimer->start(700);
51 }
52
stop()53 void QBlinkLabel::stop()
54 {
55 BlinkTimer->stop();
56 BlinkPos = 0;
57 update();
58 }
59
slotTimer()60 void QBlinkLabel::slotTimer()
61 {
62 BlinkPos = 1 - BlinkPos;
63 update();
64 }
65
paintEvent(QPaintEvent * event)66 void QBlinkLabel::paintEvent(QPaintEvent* event)
67 {
68 QPainter p(this);
69 p.setBackgroundMode(Qt::TransparentMode);
70 QRect r = rect();
71 if (BlinkPos > 0)
72 {
73 QBrush b(QColor(211, 30, 30), Qt::SolidPattern);
74 QPen pen(QColor(255, 255, 255));
75 p.fillRect(r, b);
76 p.setPen(pen);
77 p.drawText(r, Qt::AlignHCenter | Qt::AlignVCenter, text());
78 }
79 else
80 p.drawText(r, Qt::AlignHCenter | Qt::AlignVCenter, text());
81 }
82