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));
}
|