33 #include "../include/QtTextReader.h"
40 QtTextReader::QtTextReader() : width(1024), height(768), x_offset(0), y_offset(0), text(
""), font(QFont(
"Arial", 10)), text_color(
"#ffffff"), background_color(
"#000000"), is_open(false), gravity(
GRAVITY_CENTER)
48 : width(width), height(height), x_offset(x_offset), y_offset(y_offset), text(text), font(font), text_color(text_color), background_color(background_color), is_open(false), gravity(gravity)
56 text_background_color = color;
70 image = std::shared_ptr<QImage>(
new QImage(width, height, QImage::Format_RGBA8888));
71 image->fill(QColor(background_color.c_str()));
74 if (!painter.begin(image.get())) {
79 if (!text_background_color.empty()) {
80 painter.setBackgroundMode(Qt::OpaqueMode);
81 painter.setBackground(QBrush(text_background_color.c_str()));
85 painter.setPen(QPen(text_color.c_str()));
88 painter.setFont(font);
95 align_flag = Qt::AlignLeft | Qt::AlignTop;
98 align_flag = Qt::AlignHCenter | Qt::AlignTop;
101 align_flag = Qt::AlignRight | Qt::AlignTop;
104 align_flag = Qt::AlignVCenter | Qt::AlignLeft;
107 align_flag = Qt::AlignCenter;
110 align_flag = Qt::AlignVCenter | Qt::AlignRight;
113 align_flag = Qt::AlignLeft | Qt::AlignBottom;
116 align_flag = Qt::AlignHCenter | Qt::AlignBottom;
119 align_flag = Qt::AlignRight | Qt::AlignBottom;
124 painter.drawText(x_offset, y_offset, width, height, align_flag, text.c_str());
182 std::shared_ptr<Frame> image_frame(
new Frame(requested_frame, image->size().width(), image->size().height(), background_color, 0, 2));
191 std::shared_ptr<Frame> image_frame(
new Frame(1, 640, 480, background_color, 0, 2));
211 root[
"type"] =
"QtTextReader";
212 root[
"width"] = width;
213 root[
"height"] = height;
214 root[
"x_offset"] = x_offset;
215 root[
"y_offset"] = y_offset;
217 root[
"font"] = font.toString().toStdString();
218 root[
"text_color"] = text_color;
219 root[
"background_color"] = background_color;
220 root[
"text_background_color"] = text_background_color;
221 root[
"gravity"] = gravity;
237 catch (
const std::exception& e)
240 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
251 if (!root[
"width"].isNull())
252 width = root[
"width"].asInt();
253 if (!root[
"height"].isNull())
254 height = root[
"height"].asInt();
255 if (!root[
"x_offset"].isNull())
256 x_offset = root[
"x_offset"].asInt();
257 if (!root[
"y_offset"].isNull())
258 y_offset = root[
"y_offset"].asInt();
259 if (!root[
"text"].isNull())
260 text = root[
"text"].asString();
261 if (!root[
"font"].isNull())
262 font.fromString(QString::fromStdString(root[
"font"].asString()));
263 if (!root[
"text_color"].isNull())
264 text_color = root[
"text_color"].asString();
265 if (!root[
"background_color"].isNull())
266 background_color = root[
"background_color"].asString();
267 if (!root[
"text_background_color"].isNull())
268 text_background_color = root[
"text_background_color"].asString();
269 if (!root[
"gravity"].isNull())