|
1 /*************************************************************************** |
|
2 * Copyright (C) 2006-2008 by Tomasz Ziobrowski * |
|
3 * http://www.3electrons.com * |
|
4 * e-mail: t.ziobrowski@3electrons.com * |
|
5 * * |
|
6 * * |
|
7 * This program is free software; you can redistribute it and/or modify * |
|
8 * it under the terms of the GNU General Public License as published by * |
|
9 * the Free Software Foundation; either version 2 of the License, or * |
|
10 * (at your option) any later version. * |
|
11 * * |
|
12 * This program is distributed in the hope that it will be useful, * |
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
|
15 * GNU General Public License for more details. * |
|
16 * * |
|
17 * You should have received a copy of the GNU General Public License * |
|
18 * along with this program; if not, write to the * |
|
19 * Free Software Foundation, Inc., * |
|
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
|
21 ***************************************************************************/ |
|
22 |
|
23 #include <QtGui> |
|
24 #include "widgetwithbackground.h" |
|
25 |
|
26 WidgetWithBackground::WidgetWithBackground(QWidget * parent) : QWidget(parent) |
|
27 { |
|
28 m_pixmap = new QPixmap(size()); |
|
29 m_modified = false; |
|
30 } |
|
31 |
|
32 WidgetWithBackground::~WidgetWithBackground() |
|
33 { |
|
34 if (m_pixmap) |
|
35 { |
|
36 delete m_pixmap; |
|
37 m_pixmap = NULL; |
|
38 } |
|
39 } |
|
40 |
|
41 void WidgetWithBackground::drawBackground() |
|
42 { |
|
43 if (m_pixmap->size() != size() || m_modified ) |
|
44 { |
|
45 delete m_pixmap; |
|
46 m_pixmap = new QPixmap(size()); |
|
47 m_modified=true; // by wiadomo bylo że jest przemalowywane tlo |
|
48 repaintBackground(); |
|
49 m_modified=false; |
|
50 } |
|
51 QPainter painter(this); |
|
52 painter.drawPixmap(0,0,*m_pixmap); |
|
53 } |
|
54 |
|
55 void WidgetWithBackground::updateWithBackground() |
|
56 { |
|
57 m_modified=true; |
|
58 update(); |
|
59 } |
|
60 |
|
61 bool WidgetWithBackground::doRepaintBackground() |
|
62 { |
|
63 return m_modified; |
|
64 } |
|
65 |
|
66 void WidgetWithBackground::repaintBackground() |
|
67 { |
|
68 m_pixmap->fill(QColor(0,0,0,0)); |
|
69 QPainter painter(m_pixmap); |
|
70 paintBackground(painter); |
|
71 } |