From 4409fb88b0687c4bb8496a81b01cc109aa991d05 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Sun, 29 Dec 2019 08:54:55 -0500 Subject: [PATCH] custom opacity message --- extensions/extrawindow.cpp | 14 +++++++++++--- text.cpp | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/extensions/extrawindow.cpp b/extensions/extrawindow.cpp index 687300b..b8d0749 100644 --- a/extensions/extrawindow.cpp +++ b/extensions/extrawindow.cpp @@ -15,6 +15,7 @@ extern const char* EXTRA_WINDOW_INFO; extern const char* TOPMOST; +extern const char* OPACITY; extern const char* SHOW_ORIGINAL; extern const char* SHOW_ORIGINAL_INFO; extern const char* SIZE_LOCK; @@ -31,6 +32,13 @@ extern const char* SAVE_SETTINGS; constexpr auto DICTIONARY_SAVE_FILE = u8"SavedDictionary.txt"; +QColor colorPrompt(QWidget* parent, QColor default, const QString& title, bool customOpacity = true) +{ + QColor color = QColorDialog::getColor(default, parent, title); + if (customOpacity) color.setAlpha(255 * QInputDialog::getDouble(parent, title, OPACITY, default.alpha() / 255.0, 0, 1, 3, nullptr, Qt::WindowCloseButtonHint)); + return color; +} + struct PrettyWindow : QDialog { PrettyWindow(const char* name) @@ -48,8 +56,8 @@ struct PrettyWindow : QDialog outliner.color = settings.value(OUTLINE_COLOR, outliner.color).value(); outliner.size = settings.value(OUTLINE_SIZE, outliner.size).toDouble(); menu.addAction(FONT, this, &PrettyWindow::RequestFont); - menu.addAction(BG_COLOR, [this] { setBgColor(QColorDialog::getColor(bgColor, this, BG_COLOR, QColorDialog::ShowAlphaChannel)); }); - menu.addAction(TEXT_COLOR, [this] { setTextColor(QColorDialog::getColor(textColor(), this, TEXT_COLOR, QColorDialog::ShowAlphaChannel)); }); + menu.addAction(BG_COLOR, [this] { setBgColor(colorPrompt(this, bgColor, BG_COLOR)); }); + menu.addAction(TEXT_COLOR, [this] { setTextColor(colorPrompt(this, textColor(), TEXT_COLOR)); }); QAction* outlineAction = menu.addAction(TEXT_OUTLINE, this, &PrettyWindow::setOutline); outlineAction->setCheckable(true); outlineAction->setChecked(outliner.size >= 0); @@ -102,7 +110,7 @@ private: { if (enable) { - QColor color = QColorDialog::getColor(outliner.color, this, OUTLINE_COLOR, QColorDialog::ShowAlphaChannel); + QColor color = colorPrompt(this, outliner.color, OUTLINE_COLOR); if (color.isValid()) outliner.color = color; outliner.size = QInputDialog::getDouble(this, OUTLINE_SIZE, OUTLINE_SIZE_INFO, 0.5, 0, INT_MAX, 2, nullptr, Qt::WindowCloseButtonHint); } diff --git a/text.cpp b/text.cpp index cdfd47f..7aff73a 100644 --- a/text.cpp +++ b/text.cpp @@ -133,6 +133,7 @@ const char* SHOW_ORIGINAL = u8"Original text"; const char* SHOW_ORIGINAL_INFO = u8R"(Original text will not be shown Only works if this extension is used directly after a translation extension)"; const char* SIZE_LOCK = u8"Size lock"; +const char* OPACITY = u8"Opacity"; const char* BG_COLOR = u8"Background color"; const char* TEXT_COLOR = u8"Text color"; const char* TEXT_OUTLINE = u8"Text outline";