From 745225ad6257e6e8fc1f02f2407af717a4a9a497 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Tue, 13 Aug 2019 21:18:55 +1000 Subject: [PATCH 1/4] Rename variable to font_size. Add docs for QApplication --- include/QtHtmlReader.h | 3 +++ include/QtTextReader.h | 11 +++++++---- src/QtTextReader.cpp | 22 +++++++++++----------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/include/QtHtmlReader.h b/include/QtHtmlReader.h index ef9ad570..3c6b7528 100644 --- a/include/QtHtmlReader.h +++ b/include/QtHtmlReader.h @@ -55,6 +55,9 @@ namespace openshot * Supports HTML/CSS subset available via Qt libraries, see: https://doc.qt.io/qt-5/richtext-html-subset.html * * @code + * // Any application using this class must instantiate either QGuiApplication or QApplication + * QApplication a(argc, argv); + * * // Create a reader to generate an openshot::Frame containing text * QtHtmlReader r(720, // width * 480, // height diff --git a/include/QtTextReader.h b/include/QtTextReader.h index 741fe74c..316825b7 100644 --- a/include/QtTextReader.h +++ b/include/QtTextReader.h @@ -56,6 +56,9 @@ namespace openshot * alignment, padding, etc... * * @code + * // Any application using this class must instantiate either QGuiApplication or QApplication + * QApplication a(argc, argv); + * * // Create a reader to generate an openshot::Frame containing text * QtTextReader r(720, // width * 480, // height @@ -64,7 +67,7 @@ namespace openshot * GRAVITY_CENTER, // gravity * "Check out this Text!", // text * "Arial", // font - * 15.0, // size + * 15.0, // font size * "#fff000", // text_color * "#000000" // background_color * ); @@ -89,7 +92,7 @@ namespace openshot int y_offset; std::string text; std::string font; - double size; + double font_size; std::string text_color; std::string background_color; std::shared_ptr image; @@ -109,10 +112,10 @@ namespace openshot /// @param gravity The alignment / gravity of the text /// @param text The text you want to generate / display /// @param font The font of the text - /// @param size The size of the text + /// @param font_size The size of the text /// @param text_color The color of the text /// @param background_color The background color of the text (also supports Transparent) - QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string text, std::string font, double size, std::string text_color, std::string background_color); + QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string text, std::string font, double font_size, std::string text_color, std::string background_color); /// Close Reader void Close(); diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp index 7527894d..a287bc43 100644 --- a/src/QtTextReader.cpp +++ b/src/QtTextReader.cpp @@ -35,15 +35,15 @@ using namespace openshot; /// Default constructor (blank text) -QtTextReader::QtTextReader() : width(1024), height(768), x_offset(0), y_offset(0), text(""), font("Arial"), size(10.0), text_color("#ffffff"), background_color("#000000"), is_open(false), gravity(GRAVITY_CENTER) +QtTextReader::QtTextReader() : width(1024), height(768), x_offset(0), y_offset(0), text(""), font("Arial"), font_size(10.0), text_color("#ffffff"), background_color("#000000"), is_open(false), gravity(GRAVITY_CENTER) { // Open and Close the reader, to populate it's attributes (such as height, width, etc...) Open(); Close(); } -QtTextReader::QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string text, std::string font, double size, std::string text_color, std::string background_color) -: width(width), height(height), x_offset(x_offset), y_offset(y_offset), text(text), font(font), size(size), text_color(text_color), background_color(background_color), is_open(false), gravity(gravity) +QtTextReader::QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string text, std::string font, double font_size, std::string text_color, std::string background_color) +: width(width), height(height), x_offset(x_offset), y_offset(y_offset), text(text), font(font), font_size(font_size), text_color(text_color), background_color(background_color), is_open(false), gravity(gravity) { // Open and Close the reader, to populate it's attributes (such as height, width, etc...) Open(); @@ -72,7 +72,7 @@ void QtTextReader::Open() painter.setPen(QPen(text_color.c_str())); // set font - painter.setFont(QFont(font.c_str(), size)); + painter.setFont(QFont(font.c_str(), font_size)); // Set gravity (map between OpenShot and Qt) int align_flag = 0; @@ -129,14 +129,14 @@ void QtTextReader::Open() info.video_length = round(info.duration * info.fps.ToDouble()); // Calculate the DAR (display aspect ratio) - Fraction size(info.width * info.pixel_ratio.num, info.height * info.pixel_ratio.den); + Fraction font_size(info.width * info.pixel_ratio.num, info.height * info.pixel_ratio.den); // Reduce size fraction - size.Reduce(); + font_size.Reduce(); // Set the ratio based on the reduced fraction - info.display_ratio.num = size.num; - info.display_ratio.den = size.den; + info.display_ratio.num = font_size.num; + info.display_ratio.den = font_size.den; // Mark as "open" is_open = true; @@ -196,7 +196,7 @@ Json::Value QtTextReader::JsonValue() { root["y_offset"] = y_offset; root["text"] = text; root["font"] = font; - root["size"] = size; + root["font_size"] = font_size; root["text_color"] = text_color; root["background_color"] = background_color; root["gravity"] = gravity; @@ -251,8 +251,8 @@ void QtTextReader::SetJsonValue(Json::Value root) { text = root["text"].asString(); if (!root["font"].isNull()) font = root["font"].asString(); - if (!root["size"].isNull()) - size = root["size"].asDouble(); + if (!root["font_size"].isNull()) + font_size = root["font_size"].asDouble(); if (!root["text_color"].isNull()) text_color = root["text_color"].asString(); if (!root["background_color"].isNull()) From c8f2c08d344dd402ee55476bf3417c2b97f1a7d5 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Tue, 13 Aug 2019 21:24:42 +1000 Subject: [PATCH 2/4] Add authors to docs --- include/QtHtmlReader.h | 2 ++ include/QtTextReader.h | 2 ++ src/QtHtmlReader.cpp | 2 ++ src/QtTextReader.cpp | 2 ++ 4 files changed, 8 insertions(+) diff --git a/include/QtHtmlReader.h b/include/QtHtmlReader.h index 3c6b7528..456b5f1d 100644 --- a/include/QtHtmlReader.h +++ b/include/QtHtmlReader.h @@ -2,6 +2,8 @@ * @file * @brief Header file for QtHtmlReader class * @author Jonathan Thomas + * @author Sergei Kolesov (jediserg) + * @author Jeff Shillitto (jeffski) * * @ref License */ diff --git a/include/QtTextReader.h b/include/QtTextReader.h index 316825b7..85187afe 100644 --- a/include/QtTextReader.h +++ b/include/QtTextReader.h @@ -2,6 +2,8 @@ * @file * @brief Header file for QtTextReader class * @author Jonathan Thomas + * @author Sergei Kolesov (jediserg) + * @author Jeff Shillitto (jeffski) * * @ref License */ diff --git a/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp index c81508db..9bda8a18 100644 --- a/src/QtHtmlReader.cpp +++ b/src/QtHtmlReader.cpp @@ -2,6 +2,8 @@ * @file * @brief Source file for QtHtmlReader class * @author Jonathan Thomas + * @author Sergei Kolesov (jediserg) + * @author Jeff Shillitto (jeffski) * * @ref License */ diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp index a287bc43..4205eb81 100644 --- a/src/QtTextReader.cpp +++ b/src/QtTextReader.cpp @@ -2,6 +2,8 @@ * @file * @brief Source file for QtTextReader class * @author Jonathan Thomas + * @author Sergei Kolesov (jediserg) + * @author Jeff Shillitto (jeffski) * * @ref License */ From 78f370ee14eb2f1b78b96dc597b2942f823798ea Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Tue, 13 Aug 2019 22:11:55 +1000 Subject: [PATCH 3/4] Add ability to apply style sheet/css to format HTML --- include/QtHtmlReader.h | 4 +++- src/QtHtmlReader.cpp | 12 +++++++----- src/examples/ExampleHtml.cpp | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/QtHtmlReader.h b/include/QtHtmlReader.h index 456b5f1d..01defa8c 100644 --- a/include/QtHtmlReader.h +++ b/include/QtHtmlReader.h @@ -67,6 +67,7 @@ namespace openshot * 5, // y_offset * GRAVITY_CENTER, // gravity * "Check out this Text!", // html + * "b { color: #ff0000 }", // css * "#000000" // background_color * ); * r.Open(); // Open the reader @@ -89,6 +90,7 @@ namespace openshot int x_offset; int y_offset; std::string html; + std::string css; std::string background_color; std::shared_ptr image; bool is_open; @@ -106,7 +108,7 @@ namespace openshot /// @param gravity The alignment / gravity of the text /// @param html The html you want to render / display /// @param background_color The background color of the text (also supports Transparent) - QtHtmlReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string html, std::string background_color); + QtHtmlReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string html, std::string css, std::string background_color); /// Close Reader void Close(); diff --git a/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp index 9bda8a18..d73554cb 100644 --- a/src/QtHtmlReader.cpp +++ b/src/QtHtmlReader.cpp @@ -40,15 +40,15 @@ using namespace openshot; /// Default constructor (blank text) -QtHtmlReader::QtHtmlReader() : width(1024), height(768), x_offset(0), y_offset(0), html(""), background_color("#000000"), is_open(false), gravity(GRAVITY_CENTER) +QtHtmlReader::QtHtmlReader() : width(1024), height(768), x_offset(0), y_offset(0), html(""), css(""), background_color("#000000"), is_open(false), gravity(GRAVITY_CENTER) { // Open and Close the reader, to populate it's attributes (such as height, width, etc...) Open(); Close(); } -QtHtmlReader::QtHtmlReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string html, std::string background_color) -: width(width), height(height), x_offset(x_offset), y_offset(y_offset), gravity(gravity), html(html), background_color(background_color), is_open(false) +QtHtmlReader::QtHtmlReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string html, std::string css, std::string background_color) +: width(width), height(height), x_offset(x_offset), y_offset(y_offset), gravity(gravity), html(html), css(css), background_color(background_color), is_open(false) { // Open and Close the reader, to populate it's attributes (such as height, width, etc...) Open(); @@ -77,6 +77,7 @@ void QtHtmlReader::Open() //draw text QTextDocument text_document; text_document.setTextWidth(width); + text_document.setDefaultStyleSheet(css.c_str()); text_document.setHtml(html.c_str()); int td_height = text_document.documentLayout()->documentSize().height(); @@ -185,6 +186,7 @@ Json::Value QtHtmlReader::JsonValue() { root["x_offset"] = x_offset; root["y_offset"] = y_offset; root["html"] = html; + root["css"] = css; root["background_color"] = background_color; root["gravity"] = gravity; @@ -236,10 +238,10 @@ void QtHtmlReader::SetJsonValue(Json::Value root) { y_offset = root["y_offset"].asInt(); if (!root["html"].isNull()) html = root["html"].asString(); - + if (!root["css"].isNull()) + css = root["css"].asString(); if (!root["background_color"].isNull()) background_color = root["background_color"].asString(); - if (!root["gravity"].isNull()) gravity = (GravityType) root["gravity"].asInt(); diff --git a/src/examples/ExampleHtml.cpp b/src/examples/ExampleHtml.cpp index 0148b6f7..3f466df0 100644 --- a/src/examples/ExampleHtml.cpp +++ b/src/examples/ExampleHtml.cpp @@ -45,6 +45,7 @@ int main(int argc, char* argv[]) { 5, // y_offset GRAVITY_CENTER, // gravity "Check out this Text!", // html + "b { color: #ff0000; }", "#000000" // background_color ); r.Open(); // Open the reader From ada13ddebd80d135f41be2a7d517ef57004b3356 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Tue, 13 Aug 2019 22:17:49 +1000 Subject: [PATCH 4/4] Disable undo/redo stack --- src/QtHtmlReader.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp index d73554cb..0d71c658 100644 --- a/src/QtHtmlReader.cpp +++ b/src/QtHtmlReader.cpp @@ -76,6 +76,11 @@ void QtHtmlReader::Open() //draw text QTextDocument text_document; + + //disable redo/undo stack as not needed + text_document.setUndoRedoEnabled(false); + + //create the HTML/CSS document text_document.setTextWidth(width); text_document.setDefaultStyleSheet(css.c_str()); text_document.setHtml(html.c_str());