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
|
#include "waveformrenderbackground.h"
#include "waveformwidgetrenderer.h"
#include "widget/wskincolor.h"
#include "widget/wwidget.h"
#include "widget/wimagestore.h"
WaveformRenderBackground::WaveformRenderBackground(
WaveformWidgetRenderer* waveformWidgetRenderer)
: WaveformRendererAbstract(waveformWidgetRenderer),
m_backgroundColor(0, 0, 0) {
}
WaveformRenderBackground::~WaveformRenderBackground() {
}
void WaveformRenderBackground::setup(const QDomNode& node,
const SkinContext& context) {
m_backgroundColor = m_waveformRenderer->getWaveformSignalColors()->getBgColor();
QString backgroundPixmapPath = context.selectString(node, "BgPixmap");
if (!backgroundPixmapPath.isEmpty()) {
m_backgroundPixmapPath = context.makeSkinPath(backgroundPixmapPath);
}
setDirty(true);
}
bool WaveformRenderBackground::hasImage() {
if (isDirty()) {
generateImage();
}
return !m_backgroundImage.isNull();
}
void WaveformRenderBackground::drawImage(QPainter* painter) {
// since we use opaque widget we need to draw the background !
painter->drawImage(QPoint(0, 0), m_backgroundImage);
// This produces a white back ground with Linux QT 4.6 QGlWidget and
// Intel i915 driver and has peroformance issues on other setups. See #6363
//painter->drawPixmap(QPoint(0, 0), m_backgroundPixmap);
return true;
}
void WaveformRenderBackground::draw(QPainter* painter,
QPaintEvent* /*event*/) {
if (hasImage()) {
drawImage(painter);
return;
}
// If there is no background image, just fill the painter with the
// background color.
painter->fillRect(0,
0,
m_waveformRenderer->getWidth(),
m_waveformRenderer->getHeight(),
m_backgroundColor);
}
void WaveformRenderBackground::generateImage() {
m_backgroundImage = QImage();
if (!m_backgroundPixmapPath.isEmpty()) {
QImage backgroundImage = *WImageStore::getImage(
m_backgroundPixmapPath,
scaleFactor());
if (!backgroundImage.isNull()) {
if (backgroundImage.width() == m_waveformRenderer->getWidth() &&
backgroundImage.height() == m_waveformRenderer->getHeight()) {
m_backgroundImage = backgroundImage.convertToFormat(QImage::Format_RGB32);
} else {
m_backgroundImage = QImage(m_waveformRenderer->getWidth(),
m_waveformRenderer->getHeight(),
QImage::Format_RGB32);
QPainter painter(&m_backgroundImage);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
painter.drawImage(m_backgroundImage.rect(),
backgroundImage, backgroundImage.rect());
}
}
}
setDirty(false);
}
|