diff --git a/CMakeLists.txt b/CMakeLists.txt index 9bd0159..cfb87ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,7 +123,7 @@ include(BasicConfig) set(CONFIGURATION_PACKAGE_SUFFIX_QTUTILITIES "${CONFIGURATION_PACKAGE_SUFFIX}" CACHE STRING "sets the suffix for qtutilities") -find_package(qtutilities${CONFIGURATION_PACKAGE_SUFFIX_QTUTILITIES} 6.11.0 REQUIRED) +find_package(qtutilities${CONFIGURATION_PACKAGE_SUFFIX_QTUTILITIES} 6.12.0 REQUIRED) use_qt_utilities() # find passwordfile diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 9eaffbc..abc4a35 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -106,6 +106,19 @@ void MainWindow::setSomethingChanged(bool somethingChanged) } } +/*! + * \brief Updates the style sheet. + */ +void MainWindow::updateStyleSheet() +{ +#ifdef Q_OS_WINDOWS + const auto p = palette(); + setStyleSheet(QStringLiteral("%1 #splitter QWidget { background-color: palette(base); color: palette(text); } #splitter QWidget *, #splitter " + "QWidget * { background-color: none; } #leftWidget { border-right: 1px solid %2; }") + .arg(dialogStyleForPalette(p), windowFrameColorForPalette(p).name())); +#endif +} + /*! * \brief Constructs a new main window. */ @@ -120,12 +133,9 @@ MainWindow::MainWindow(QSettings &settings, QtUtilities::QtSettings *qtSettings, , m_settingsDlg(nullptr) { // setup ui + updateStyleSheet(); m_ui->setupUi(this); -#ifdef Q_OS_WIN32 - setStyleSheet(QStringLiteral("%1 #splitter QWidget { background-color: palette(base); color: palette(text); } #splitter QWidget *, #splitter " - "QWidget * { background-color: none; } #leftWidget { border-right: 1px solid %2; }") - .arg(dialogStyle(), windowFrameColor().name())); -#endif + // set default values setSomethingChanged(false); m_dontUpdateSelection = false; @@ -240,6 +250,17 @@ MainWindow::~MainWindow() { } +bool MainWindow::event(QEvent *event) +{ + switch (event->type()) { + case QEvent::PaletteChange: + updateStyleSheet(); + break; + default:; + } + return QMainWindow::event(event); +} + bool MainWindow::eventFilter(QObject *obj, QEvent *event) { if (obj == m_undoView) { diff --git a/gui/mainwindow.h b/gui/mainwindow.h index b607ae2..a0e0e90 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -74,6 +74,7 @@ public: bool openFile(const QString &path, Io::PasswordFileOpenFlags openFlags); // can not be a slot in Qt 6 without further effort, see QTBUG-86424 protected: + bool event(QEvent *event) override; bool eventFilter(QObject *obj, QEvent *event) override; void closeEvent(QCloseEvent *event) override; void timerEvent(QTimerEvent *event) override; @@ -108,6 +109,7 @@ private Q_SLOTS: void clearClipboard(); void setSomethingChanged(); void setSomethingChanged(bool somethingChanged); + void updateStyleSheet(); private: // showing conditional messages/prompts diff --git a/gui/passwordgeneratordialog.cpp b/gui/passwordgeneratordialog.cpp index 20dd422..2ed2e7c 100644 --- a/gui/passwordgeneratordialog.cpp +++ b/gui/passwordgeneratordialog.cpp @@ -43,11 +43,8 @@ PasswordGeneratorDialog::PasswordGeneratorDialog(QWidget *parent) : QDialog(parent) , m_ui(new Ui::PasswordGeneratorDialog) { + updateStyleSheet(); m_ui->setupUi(this); -#ifdef Q_OS_WIN32 - setStyleSheet(QStringLiteral("%1 QCommandLinkButton { font-size: 12pt; color: %2; font-weight: normal; }") - .arg(dialogStyle(), instructionTextColor().name())); -#endif setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); connect(m_ui->generatePassowordCommandLinkButton, &QCommandLinkButton::clicked, this, &PasswordGeneratorDialog::generateNewPassword); @@ -75,6 +72,17 @@ PasswordGeneratorDialog::~PasswordGeneratorDialog() { } +bool PasswordGeneratorDialog::event(QEvent *event) +{ + switch (event->type()) { + case QEvent::PaletteChange: + updateStyleSheet(); + break; + default:; + } + return QDialog::event(event); +} + /*! * \brief Generates and shows a new password. */ @@ -162,6 +170,17 @@ void PasswordGeneratorDialog::handlePasswordChanged() m_ui->copyPasswordCommandLinkButton->setEnabled(m_ui->passwordLineEdit->text().size() > 0); } +/*! + * \brief Updates the style sheet. + */ +void PasswordGeneratorDialog::updateStyleSheet() +{ +#ifdef Q_OS_WINDOWS + setStyleSheet(QStringLiteral("%1 QCommandLinkButton { font-size: 12pt; color: %2; font-weight: normal; }") + .arg(dialogStyleForPalette(palette()), instructionTextColor().name())); +#endif +} + #ifndef QT_NO_CLIPBOARD /*! * \brief Copies the current password to the clipboard. diff --git a/gui/passwordgeneratordialog.h b/gui/passwordgeneratordialog.h index 580b64c..8ecd901 100644 --- a/gui/passwordgeneratordialog.h +++ b/gui/passwordgeneratordialog.h @@ -21,10 +21,14 @@ public: explicit PasswordGeneratorDialog(QWidget *parent = nullptr); ~PasswordGeneratorDialog() override; +protected: + bool event(QEvent *event) override; + private Q_SLOTS: void generateNewPassword(); void handleCheckedCategoriesChanged(); void handlePasswordChanged(); + void updateStyleSheet(); #ifndef QT_NO_CLIPBOARD void copyPassword(); #endif