|
1 #include "ScaleThreePainter.h" |
|
2 #include <QtGui> |
|
3 |
|
4 namespace GVA { |
|
5 |
|
6 ScaleThreePainter::ScaleThreePainter( |
|
7 const QString &leftFilename, |
|
8 const QString &middleFilename, |
|
9 const QString &rightFilename) |
|
10 : m_leftFilename(leftFilename), |
|
11 m_middleFilename(middleFilename), |
|
12 m_rightFilename(rightFilename), |
|
13 m_leftPixmap(0), |
|
14 m_middlePixmap(0), |
|
15 m_rightPixmap(0), |
|
16 m_pixmapsLoaded(false) |
|
17 { |
|
18 } |
|
19 |
|
20 ScaleThreePainter::~ScaleThreePainter() { |
|
21 unloadPixmaps(); |
|
22 } |
|
23 |
|
24 void ScaleThreePainter::loadPixmaps() { |
|
25 Q_ASSERT(!m_pixmapsLoaded); |
|
26 m_leftPixmap = new QPixmap(m_leftFilename); |
|
27 m_middlePixmap = new QPixmap(m_middleFilename); |
|
28 m_rightPixmap = new QPixmap(m_rightFilename); |
|
29 m_pixmapsLoaded = true; |
|
30 } |
|
31 |
|
32 void ScaleThreePainter::unloadPixmaps() { |
|
33 delete m_leftPixmap; m_leftPixmap = 0; |
|
34 delete m_middlePixmap; m_middlePixmap = 0; |
|
35 delete m_rightPixmap; m_rightPixmap = 0; |
|
36 m_pixmapsLoaded = false; |
|
37 } |
|
38 |
|
39 void ScaleThreePainter::paint(QPainter* painter, const QRect &rect, QWidget* widget) { |
|
40 Q_UNUSED(widget) |
|
41 |
|
42 if(!m_pixmapsLoaded) |
|
43 loadPixmaps(); |
|
44 |
|
45 // qDebug() << "ScaleThreePainter::paint: " << rect << qMin(m_middlePixmap->height(), rect.height()); |
|
46 |
|
47 painter->save(); |
|
48 |
|
49 // Draw left. |
|
50 if(m_leftPixmap->height() > rect.height()) |
|
51 painter->drawPixmap(0, 0, m_leftPixmap->width(), rect.height(), *m_leftPixmap); |
|
52 else |
|
53 painter->drawPixmap(0, 0, *m_leftPixmap); |
|
54 |
|
55 // Draw top middle -- fills in the space is between the left and right pixmaps. |
|
56 if(!m_middlePixmap->isNull()) { |
|
57 painter->drawTiledPixmap(m_leftPixmap->width(), |
|
58 0, |
|
59 rect.width() - (m_leftPixmap->width() + m_rightPixmap->width()), |
|
60 rect.height(), |
|
61 m_middlePixmap->scaledToHeight(rect.height())); |
|
62 } |
|
63 |
|
64 // Draw right. |
|
65 if(m_rightPixmap->height() > rect.height()) |
|
66 painter->drawPixmap(rect.right() - m_rightPixmap->width() + 1, 0, m_rightPixmap->width(), rect.height(), *m_rightPixmap); |
|
67 else |
|
68 painter->drawPixmap(rect.right() - m_rightPixmap->width() + 1, 0, *m_rightPixmap); |
|
69 |
|
70 painter->restore(); |
|
71 } |
|
72 |
|
73 |
|
74 } // GVA namespace |