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
|
#pragma once
#include <QPixmap>
#include <QHash>
#include <QSharedPointer>
#include <QSvgRenderer>
#include <QImage>
#include <QScopedPointer>
#include <QPainter>
#include <QRectF>
#include <QString>
#include "skin/legacy/imgsource.h"
#include "skin/legacy/pixmapsource.h"
// Wrapper around QImage and QSvgRenderer to support rendering SVG images in
// high fidelity.
class Paintable {
public:
enum DrawMode {
// Draw the image in its native dimensions with no stretching or tiling.
FIXED,
// Stretch the image.
STRETCH,
// Stretch the image maintaining its aspect ratio.
STRETCH_ASPECT,
// Tile the image.
TILE
};
Paintable(const PixmapSource& source, DrawMode mode, double scaleFactor);
QSize size() const;
int width() const;
int height() const;
QRectF rect() const;
QImage toImage() const;
DrawMode drawMode() const {
return m_drawMode;
}
void draw(int x, int y, QPainter* pPainter);
void draw(const QRectF& targetRect, QPainter* pPainter);
void draw(const QRectF& targetRect, QPainter* pPainter,
const QRectF& sourceRect);
void drawCentered(const QRectF& targetRect, QPainter* pPainter,
const QRectF& sourceRect);
bool isNull() const;
static DrawMode DrawModeFromString(const QString& str);
static QString DrawModeToString(DrawMode mode);
static QString getAltFileName(const QString& fileName);
private:
void drawInternal(const QRectF& targetRect, QPainter* pPainter,
const QRectF& sourceRect);
QScopedPointer<QPixmap> m_pPixmap;
QScopedPointer<QSvgRenderer> m_pSvg;
DrawMode m_drawMode;
PixmapSource m_source;
};
|