File: qpainterwrapper.cpp

package info (click to toggle)
olive-editor 20181223-2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 2,844 kB
  • sloc: cpp: 20,147; xml: 315; ansic: 16; makefile: 11
file content (43 lines) | stat: -rw-r--r-- 1,065 bytes parent folder | download
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
#include "qpainterwrapper.h"

#include <QPainter>
#include "debug.h"

// exposes several QPainter functions to QJSEngine

QPainterWrapper painter_wrapper;

QPainterWrapper::QPainterWrapper() {}

QColor get_color_from_string(const QString& s) {
	dout << s;

	// workaround for alpha
	if (s.at(0) == '#' && s.length() == 9) {
		QColor color(s.left(7));
		color.setAlpha(s.mid(7).toInt(NULL, 16));
		return color;
	} else {
		return QColor(s);
	}
}

void QPainterWrapper::fill(const QString& c) {
	img->fill(get_color_from_string(c));
}

void QPainterWrapper::fillRect(int x, int y, int width, int height, const QString& brush) {
	painter->fillRect(x, y, width, height, get_color_from_string(brush));
}

void QPainterWrapper::drawRect(int x, int y, int width, int height) {
	painter->drawRect(x, y, width, height);
}

void QPainterWrapper::setPen(const QString& pen) {
	painter->setPen(get_color_from_string(pen));
}

void QPainterWrapper::setBrush(const QString& brush) {
	painter->setBrush(get_color_from_string(brush));
}