summaryrefslogtreecommitdiff
path: root/libsowatch/watch.cpp
blob: e8da790a2f4f247548e25b3838ae4c29c5b442c9 (plain)
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
#include "watch.h"
#include "watchpaintengine.h"

using namespace sowatch;

Watch::Watch(const QImage& image, QObject* parent) :
	QObject(parent), _image(image), _paintEngine(0)
{

}

Watch::~Watch()
{
	if (_paintEngine) {
		delete _paintEngine;
	}
}

QPaintEngine* Watch::paintEngine() const
{
	if (!_paintEngine) {
		_paintEngine = new WatchPaintEngine(const_cast<Watch*>(this),
											const_cast<QImage*>(&_image));
	}

	return _paintEngine;
}

int Watch::metric(PaintDeviceMetric metric) const
{
	switch (metric) {
	case PdmWidth:
		return _image.width();
	case PdmHeight:
		return _image.height();
	case PdmWidthMM:
		return _image.widthMM();
	case PdmHeightMM:
		return _image.heightMM();
	case PdmNumColors:
		return _image.numColors();
	case PdmDepth:
		return _image.depth();
	case PdmDpiX:
		return _image.logicalDpiX();
	case PdmDpiY:
		return _image.logicalDpiY();
	case PdmPhysicalDpiX:
		return _image.physicalDpiX();
	case PdmPhysicalDpiY:
		return _image.physicalDpiY();
	}

	return -1;
}

void Watch::update(const QRect &rect)
{
	QList<QRect> rects;
	rects << rect;
	update(rects);
}