From 662ca45321e003a4d5acc1c874f8b1b307bb9c5c Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Fri, 15 Jan 2021 09:53:57 -0700 Subject: [PATCH] add styler extension --- extensions/CMakeLists.txt | 3 +++ extensions/lua.cpp | 4 +-- extensions/styler.cpp | 56 +++++++++++++++++++++++++++++++++++++++ text.cpp | 10 +++---- 4 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 extensions/styler.cpp diff --git a/extensions/CMakeLists.txt b/extensions/CMakeLists.txt index b6ebbbc..cddff5b 100644 --- a/extensions/CMakeLists.txt +++ b/extensions/CMakeLists.txt @@ -17,6 +17,7 @@ add_library(Remove\ Repeated\ Phrases MODULE removerepeatphrase.cpp extensionimp add_library(Remove\ Repeated\ Phrases\ 2 MODULE removerepeatphrase2.cpp extensionimpl.cpp) add_library(Remove\ 30\ Repeated\ Sentences MODULE removerepeatsentence.cpp extensionimpl.cpp) add_library(Replacer MODULE replacer.cpp extensionimpl.cpp) +add_library(Styler MODULE styler.cpp extensionimpl.cpp) add_library(Thread\ Linker MODULE threadlinker.cpp extensionimpl.cpp) target_precompile_headers(Bing\ Translate REUSE_FROM pch) @@ -33,6 +34,7 @@ target_precompile_headers(Remove\ Repeated\ Phrases REUSE_FROM pch) target_precompile_headers(Remove\ Repeated\ Phrases\ 2 REUSE_FROM pch) target_precompile_headers(Remove\ 30\ Repeated\ Sentences REUSE_FROM pch) target_precompile_headers(Replacer REUSE_FROM pch) +target_precompile_headers(Styler REUSE_FROM pch) target_precompile_headers(Thread\ Linker REUSE_FROM pch) target_link_libraries(Bing\ Translate winhttp Qt5::Widgets) @@ -42,6 +44,7 @@ target_link_libraries(Extra\ Window Qt5::Widgets) target_link_libraries(Google\ Translate winhttp Qt5::Widgets) target_link_libraries(Lua lua53 Qt5::Widgets) target_link_libraries(Regex\ Filter Qt5::Widgets) +target_link_libraries(Styler Qt5::Widgets) target_link_libraries(Thread\ Linker Qt5::Widgets) if (NOT EXISTS ${CMAKE_FINAL_OUTPUT_DIRECTORY}/Qt5WebSockets.dll AND NOT EXISTS ${CMAKE_FINAL_OUTPUT_DIRECTORY}/Qt5WebSocketsd.dll) diff --git a/extensions/lua.cpp b/extensions/lua.cpp index 9d5c272..0188896 100644 --- a/extensions/lua.cpp +++ b/extensions/lua.cpp @@ -4,7 +4,7 @@ #include extern const char* LUA_INTRO; -extern const char* LOAD_LUA_SCRIPT; +extern const char* LOAD_SCRIPT; extern const wchar_t* LUA_ERROR; constexpr auto LUA_SAVE_FILE = u8"Textractor.lua"; @@ -81,7 +81,7 @@ private: QHBoxLayout layout{ this }; QPlainTextEdit scriptEditor{ QTextFile(LUA_SAVE_FILE, QIODevice::ReadOnly).readAll(), this }; - QPushButton loadButton{ LOAD_LUA_SCRIPT, this }; + QPushButton loadButton{ LOAD_SCRIPT, this }; } window; bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) diff --git a/extensions/styler.cpp b/extensions/styler.cpp new file mode 100644 index 0000000..433024b --- /dev/null +++ b/extensions/styler.cpp @@ -0,0 +1,56 @@ +#include "qtcommon.h" +#include "extension.h" +#include +#include +#include + +extern const char* LOAD_SCRIPT; + +constexpr auto STYLE_SAVE_FILE = u8"Textractor.css"; + +class Window : public QDialog +{ +public: + Window() + : QDialog(nullptr, Qt::WindowMinMaxButtonsHint) + { + Localize(); + connect(&loadButton, &QPushButton::clicked, this, &Window::LoadScript); + + if (scriptEditor.toPlainText().isEmpty()) scriptEditor.setPlainText("/*https://doc.qt.io/qt-5/stylesheet-syntax.html*/"); + layout.addWidget(&scriptEditor); + layout.addWidget(&loadButton); + + resize(800, 600); + setWindowTitle("Styler"); + QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection); + + LoadScript(); + } + + ~Window() + { + Save(); + } + +private: + void LoadScript() + { + qApp->setStyleSheet(scriptEditor.toPlainText()); + Save(); + } + + void Save() + { + QTextFile(STYLE_SAVE_FILE, QIODevice::WriteOnly | QIODevice::Truncate).write(scriptEditor.toPlainText().toUtf8()); + } + + QHBoxLayout layout{ this }; + QPlainTextEdit scriptEditor{ QTextFile(STYLE_SAVE_FILE, QIODevice::ReadOnly).readAll(), this }; + QPushButton loadButton{ LOAD_SCRIPT, this }; +} window; + +bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) +{ + return false; +} diff --git a/text.cpp b/text.cpp index 34d39b8..0757595 100644 --- a/text.cpp +++ b/text.cpp @@ -204,7 +204,7 @@ Properties in sentenceInfo: function ProcessSentence(sentence, sentenceInfo) --Your code here... end)"; -const char* LOAD_LUA_SCRIPT = u8"Load script"; +const char* LOAD_SCRIPT = u8"Load script"; const wchar_t* LUA_ERROR = L"Lua error: %s"; const char* REGEX_FILTER = u8"Regex Filter"; const char* INVALID_REGEX = u8"Invalid regex"; @@ -454,7 +454,7 @@ sentenceInfo有以下成员: function ProcessSentence(sentence, sentenceInfo) --在此处添加你的代码... end)"; - LOAD_LUA_SCRIPT = u8"加载脚本"; + LOAD_SCRIPT = u8"加载脚本"; LUA_ERROR = L"Lua 错误"; REGEX_FILTER = u8"正则表达式过滤器"; INVALID_REGEX = u8"无效的正则表达式"; @@ -648,7 +648,7 @@ Param sentenceInfo: таблица различной информации о п function ProcessSentence(sentence, sentenceInfo) --Ваш код здесь... end)"; - LOAD_LUA_SCRIPT = u8"Загрузить скрипт"; + LOAD_SCRIPT = u8"Загрузить скрипт"; LUA_ERROR = L"Ошибка Lua: %s"; REGEX_FILTER = u8"Фильтр Regex"; INVALID_REGEX = u8"Неверный regex"; @@ -908,7 +908,7 @@ Proprietà in sentenceInfo: function ProcessSentence(sentence, sentenceInfo) --Tuo codice qui... end)"; - LOAD_LUA_SCRIPT = u8"Carica script"; + LOAD_SCRIPT = u8"Carica script"; LUA_ERROR = L"Errore Lua: %s"; REGEX_FILTER = u8"Filtro regex"; INVALID_REGEX = u8"Regex non valido"; @@ -1323,7 +1323,7 @@ Properties in sentenceInfo: function ProcessSentence(sentence, sentenceInfo) --Your code here... end)"; - LOAD_LUA_SCRIPT = u8"Charger le script"; + LOAD_SCRIPT = u8"Charger le script"; LUA_ERROR = L"Erreur Lua: %s"; REGEX_FILTER = u8"Filtre regex"; INVALID_REGEX = u8"Regex invalide";