From 1ca4fb46d67564aeca4d9208b4edd670f173b44a Mon Sep 17 00:00:00 2001 From: fourtf Date: Sun, 17 Dec 2017 16:45:15 +0100 Subject: [PATCH] added window always on top option --- src/colorscheme.cpp | 12 ++++++++---- src/colorscheme.hpp | 2 ++ src/widgets/accountpopup.cpp | 7 ++++--- src/widgets/accountpopup.hpp | 3 ++- src/widgets/basewidget.cpp | 11 +++++++++++ src/widgets/basewidget.hpp | 2 ++ src/widgets/qualitypopup.cpp | 22 ++++++++++++++-------- src/widgets/qualitypopup.hpp | 19 +++++++++++-------- src/widgets/settingsdialog.cpp | 8 ++++++-- src/widgets/settingsdialog.hpp | 4 +++- 10 files changed, 63 insertions(+), 27 deletions(-) diff --git a/src/colorscheme.cpp b/src/colorscheme.cpp index 24c1c2b61..21e9915be 100644 --- a/src/colorscheme.cpp +++ b/src/colorscheme.cpp @@ -28,10 +28,14 @@ double getMultiplierByTheme(const std::string &themeName) } // namespace detail +ColorScheme *ColorScheme::instance = nullptr; + ColorScheme::ColorScheme(WindowManager &windowManager) : themeName("/appearance/theme/name", "Dark") , themeHue("/appearance/theme/hue", 0.0) { + ColorScheme::instance = this; + this->update(); this->themeName.connectSimple([this](auto) { this->update(); }); @@ -135,10 +139,10 @@ void ColorScheme::normalizeColor(QColor &color) } if (color.lightnessF() < 0.6f && color.hueF() > 0.54444 && color.hueF() < 0.83333) { - color.setHslF( - color.hueF(), color.saturationF(), - color.lightnessF() + sin((color.hueF() - 0.54444) / (0.8333 - 0.54444) * 3.14159) * - color.saturationF() * 0.2); + color.setHslF(color.hueF(), color.saturationF(), + color.lightnessF() + + sin((color.hueF() - 0.54444) / (0.8333 - 0.54444) * 3.14159) * + color.saturationF() * 0.2); } } } diff --git a/src/colorscheme.hpp b/src/colorscheme.hpp index 5d84389b9..4186f7149 100644 --- a/src/colorscheme.hpp +++ b/src/colorscheme.hpp @@ -19,6 +19,8 @@ public: return this->lightTheme; } + static ColorScheme *instance; + QString InputStyleSheet; QColor SystemMessageColor; diff --git a/src/widgets/accountpopup.cpp b/src/widgets/accountpopup.cpp index bb0df02ee..3cbfdbf21 100644 --- a/src/widgets/accountpopup.cpp +++ b/src/widgets/accountpopup.cpp @@ -19,15 +19,16 @@ namespace chatterino { namespace widgets { AccountPopupWidget::AccountPopupWidget(std::shared_ptr channel) - : QWidget(nullptr) + : BaseWidget() , _ui(new Ui::AccountPopup) , _channel(channel) { _ui->setupUi(this); - resize(0, 0); - setWindowFlags(Qt::FramelessWindowHint); + this->initAsWindow(); + + resize(0, 0); SettingsManager &settings = SettingsManager::getInstance(); diff --git a/src/widgets/accountpopup.hpp b/src/widgets/accountpopup.hpp index e5eee9cb8..7097736c4 100644 --- a/src/widgets/accountpopup.hpp +++ b/src/widgets/accountpopup.hpp @@ -1,5 +1,6 @@ #pragma once +#include "basewidget.hpp" #include "concurrentmap.hpp" #include "twitch/twitchchannel.hpp" @@ -18,7 +19,7 @@ class Channel; namespace widgets { -class AccountPopupWidget : public QWidget +class AccountPopupWidget : public BaseWidget { Q_OBJECT public: diff --git a/src/widgets/basewidget.cpp b/src/widgets/basewidget.cpp index 9790b5687..4046db8ef 100644 --- a/src/widgets/basewidget.cpp +++ b/src/widgets/basewidget.cpp @@ -1,5 +1,6 @@ #include "widgets/basewidget.hpp" #include "colorscheme.hpp" +#include "settingsmanager.hpp" //#include #include @@ -28,6 +29,12 @@ BaseWidget::BaseWidget(BaseWidget *parent) this->init(); } +BaseWidget::BaseWidget(QWidget *parent) + : QWidget(parent) + , colorScheme(*ColorScheme::instance) +{ +} + float BaseWidget::getDpiMultiplier() { BaseWidget *baseWidget = dynamic_cast(this->window()); @@ -60,6 +67,10 @@ void BaseWidget::initAsWindow() this->dpiMultiplier = dpi.value() / 96.f; } #endif + + if (SettingsManager::getInstance().windowTopMost.getValue()) { + this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint); + } } void BaseWidget::refreshTheme() diff --git a/src/widgets/basewidget.hpp b/src/widgets/basewidget.hpp index af6bed0cb..5aa88d65e 100644 --- a/src/widgets/basewidget.hpp +++ b/src/widgets/basewidget.hpp @@ -21,6 +21,8 @@ public: explicit BaseWidget(BaseWidget *parent); + explicit BaseWidget(QWidget *parent = nullptr); + ColorScheme &colorScheme; float getDpiMultiplier(); diff --git a/src/widgets/qualitypopup.cpp b/src/widgets/qualitypopup.cpp index 06aa5e845..527baf76e 100644 --- a/src/widgets/qualitypopup.cpp +++ b/src/widgets/qualitypopup.cpp @@ -6,15 +6,19 @@ namespace chatterino { namespace widgets { QualityPopup::QualityPopup(const QString &channel, const QString &path, QStringList options) - : channel(channel) + : BaseWidget() + , channel(channel) , path(path) { + this->initAsWindow(); + this->ui.okButton.setText("OK"); this->ui.cancelButton.setText("Cancel"); - QObject::connect(&this->ui.okButton, &QPushButton::clicked, this, &QualityPopup::okButtonClicked); + QObject::connect(&this->ui.okButton, &QPushButton::clicked, this, + &QualityPopup::okButtonClicked); QObject::connect(&this->ui.cancelButton, &QPushButton::clicked, this, - &QualityPopup::cancelButtonClicked); + &QualityPopup::cancelButtonClicked); this->ui.buttonBox.addButton(&this->ui.okButton, QDialogButtonBox::ButtonRole::AcceptRole); this->ui.buttonBox.addButton(&this->ui.cancelButton, QDialogButtonBox::ButtonRole::RejectRole); @@ -29,7 +33,8 @@ QualityPopup::QualityPopup(const QString &channel, const QString &path, QStringL this->setLayout(&this->ui.vbox); } -void QualityPopup::showDialog(const QString &channel, const QString &path, QStringList options) { +void QualityPopup::showDialog(const QString &channel, const QString &path, QStringList options) +{ static QualityPopup *instance = new QualityPopup(channel, path, options); instance->show(); @@ -38,9 +43,10 @@ void QualityPopup::showDialog(const QString &channel, const QString &path, QStri instance->setFocus(); } -void QualityPopup::okButtonClicked() { +void QualityPopup::okButtonClicked() +{ QProcess::startDetached(this->path, - {"twitch.tv/" + this->channel, this->ui.selector.currentText()}); + {"twitch.tv/" + this->channel, this->ui.selector.currentText()}); this->close(); } @@ -49,5 +55,5 @@ void QualityPopup::cancelButtonClicked() this->close(); } -} // namespace widgets -} // namespace chatterino +} // namespace widgets +} // namespace chatterino diff --git a/src/widgets/qualitypopup.hpp b/src/widgets/qualitypopup.hpp index 28c444d88..11fd83164 100644 --- a/src/widgets/qualitypopup.hpp +++ b/src/widgets/qualitypopup.hpp @@ -1,22 +1,25 @@ #ifndef QUALITYPOPUP_H #define QUALITYPOPUP_H -#include -#include -#include #include #include +#include #include +#include +#include + +#include "basewidget.hpp" namespace chatterino { namespace widgets { -class QualityPopup : public QWidget +class QualityPopup : public BaseWidget { public: QualityPopup(const QString &channel, const QString &path, QStringList options); static void showDialog(const QString &channel, const QString &path, QStringList options); + private: struct { QVBoxLayout vbox; @@ -25,7 +28,7 @@ private: QPushButton okButton; QPushButton cancelButton; } ui; - + QString channel; QString path; @@ -33,7 +36,7 @@ private: void cancelButtonClicked(); }; -} // namespace widgets -} // namespace chatterino +} // namespace widgets +} // namespace chatterino -#endif // QUALITYPOPUP_H +#endif // QUALITYPOPUP_H diff --git a/src/widgets/settingsdialog.cpp b/src/widgets/settingsdialog.cpp index 64882254d..fed1f41fe 100644 --- a/src/widgets/settingsdialog.cpp +++ b/src/widgets/settingsdialog.cpp @@ -23,11 +23,14 @@ namespace chatterino { namespace widgets { SettingsDialog::SettingsDialog() - : snapshot(SettingsManager::getInstance().createSnapshot()) + : BaseWidget() + , snapshot(SettingsManager::getInstance().createSnapshot()) , usernameDisplayMode( "/appearance/messages/usernameDisplayMode", twitch::TwitchMessageBuilder::UsernameDisplayMode::UsernameAndLocalizedName) { + this->initAsWindow(); + QFile file(":/qss/settings.qss"); file.open(QFile::ReadOnly); QString styleSheet = QLatin1String(file.readAll()); @@ -328,7 +331,8 @@ QVBoxLayout *SettingsDialog::createBehaviourTab() auto form = new QFormLayout(); - form->addRow("Window:", createCheckbox("Window always on top", settings.windowTopMost)); + form->addRow("Window:", + createCheckbox("Window always on top (requires restart)", settings.windowTopMost)); // form->addRow("Messages:", createCheckbox("Mention users with a @ (except in // commands)", // settings.mentionUsersWithAt)); diff --git a/src/widgets/settingsdialog.hpp b/src/widgets/settingsdialog.hpp index ce3c918b0..e9888a57e 100644 --- a/src/widgets/settingsdialog.hpp +++ b/src/widgets/settingsdialog.hpp @@ -18,11 +18,13 @@ #include #include +#include "basewidget.hpp" + namespace chatterino { namespace widgets { -class SettingsDialog : public QWidget +class SettingsDialog : public BaseWidget { public: SettingsDialog();