From f44930d5809d6ca3f63ba733b1ce98f0c3b17c22 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 26 Sep 2015 20:28:30 +0200 Subject: [PATCH] unified dialog style sheet, removed hard coded colors --- aboutdialog/aboutdialog.cpp | 8 ++-- enterpassworddialog/enterpassworddialog.cpp | 8 ++-- misc/dialogutils.cpp | 42 +++++++++++++++++++++ misc/dialogutils.h | 15 ++++++-- settingsdialog/settingsdialog.cpp | 13 +++---- settingsdialog/settingsdialog.ui | 2 +- 6 files changed, 67 insertions(+), 21 deletions(-) diff --git a/aboutdialog/aboutdialog.cpp b/aboutdialog/aboutdialog.cpp index 589f8c6..948ea1e 100644 --- a/aboutdialog/aboutdialog.cpp +++ b/aboutdialog/aboutdialog.cpp @@ -1,4 +1,5 @@ #include "./aboutdialog.h" +#include "../misc/dialogutils.h" #include "gui/ui_aboutdialog.h" @@ -34,11 +35,8 @@ AboutDialog::AboutDialog(QWidget *parent, const QString &applicationName, const m_ui(new Ui::AboutDialog) { m_ui->setupUi(this); -#ifdef Q_OS_WIN32 - setStyleSheet(QStringLiteral("#mainWidget { color: black; background-color: white; border: none; } #productNameLabel { font-size: 12pt; color: #003399; }")); -#else - setStyleSheet(QStringLiteral("#productNameLabel { font-weight: bold; }")); -#endif + makeHeading(m_ui->productNameLabel); + setStyleSheet(dialogStyle()); setWindowFlags(Qt::Tool); if(!applicationName.isEmpty()) { m_ui->productNameLabel->setText(applicationName); diff --git a/enterpassworddialog/enterpassworddialog.cpp b/enterpassworddialog/enterpassworddialog.cpp index d40eeeb..4968613 100644 --- a/enterpassworddialog/enterpassworddialog.cpp +++ b/enterpassworddialog/enterpassworddialog.cpp @@ -1,4 +1,5 @@ #include "./enterpassworddialog.h" +#include "../misc/dialogutils.h" #include "gui/ui_enterpassworddialog.h" @@ -37,11 +38,8 @@ EnterPasswordDialog::EnterPasswordDialog(QWidget *parent) : { // setup ui m_ui->setupUi(this); -#ifdef Q_OS_WIN32 - setStyleSheet(QStringLiteral("#mainWidget { color: black; background-color: white; border: none; } #bottomWidget { background-color: #F0F0F0; border-top: 1px solid #DFDFDF; } QMessageBox QLabel, QInputDialog QLabel, #instructionLabel {font-size: 12pt; color: #003399; }")); -#else - setStyleSheet(QStringLiteral("#instructionLabel { font-weight: bold; }")); -#endif + makeHeading(m_ui->instructionLabel); + setStyleSheet(dialogStyle()); setDescription(); setPromptForUserName(false); setVerificationRequired(false); diff --git a/misc/dialogutils.cpp b/misc/dialogutils.cpp index ae37735..d8693c6 100644 --- a/misc/dialogutils.cpp +++ b/misc/dialogutils.cpp @@ -1,6 +1,12 @@ #include "./dialogutils.h" +#ifdef GUI_NONE #include +#else +#include +#include +#include +#endif #include #include @@ -30,5 +36,41 @@ QString generateWindowTitle(DocumentStatus documentStatus, const QString &docume } } +#ifndef GUI_NONE + +#ifdef Q_OS_WIN32 +QColor windowFrameColor() +{ + return QGuiApplication::palette().window().color().darker(108); +} + +QColor instructionTextColor() +{ + const auto baseColor = QGuiApplication::palette().base().color(); + return (baseColor.value() > 204 && baseColor.saturation() < 63) ? QColor(0x00, 0x33, 0x99) : QGuiApplication::palette().text().color(); +} + +#endif + +const QString &dialogStyle() +{ +#ifdef Q_OS_WIN32 + static const auto style = QStringLiteral(" #mainWidget { color: palette(text); background-color: palette(base); border: none; }" + " #bottomWidget { background-color: palette(window); color: palette(window-text); border-top: 1px solid %1; }" + " QMessageBox QLabel, QInputDialog QLabel, *[classNames~=\"heading\"] { font-size: 12pt; color: %2; } ").arg( + windowFrameColor().name(), instructionTextColor().name()); +#else + static const auto style = QStringLiteral(" *[classNames~=\"heading\"] { font-weight: bold; } "); +#endif + return style; +} + +void makeHeading(QWidget *widget) +{ + widget->setProperty("classNames", widget->property("classNames").toStringList() << QStringLiteral("heading")); +} + +#endif + } // namespace Dialogs diff --git a/misc/dialogutils.h b/misc/dialogutils.h index 9a1434a..10057e7 100644 --- a/misc/dialogutils.h +++ b/misc/dialogutils.h @@ -5,9 +5,9 @@ #include -QT_BEGIN_NAMESPACE -class QString; -QT_END_NAMESPACE +QT_FORWARD_DECLARE_CLASS(QString) +QT_FORWARD_DECLARE_CLASS(QWidget) +QT_FORWARD_DECLARE_CLASS(QColor) namespace Dialogs { @@ -19,6 +19,15 @@ enum class DocumentStatus { QString LIB_EXPORT generateWindowTitle(DocumentStatus documentStatus, const QString &documentPath); +#ifndef GUI_NONE +#ifdef Q_OS_WIN32 +QColor LIB_EXPORT windowFrameColor(); +QColor LIB_EXPORT instructionTextColor(); +#endif +const QString LIB_EXPORT &dialogStyle(); +void LIB_EXPORT makeHeading(QWidget *widget); +#endif + } // namespace Dialogs #endif // DIALOGS_DIALOGUTILS_H diff --git a/settingsdialog/settingsdialog.cpp b/settingsdialog/settingsdialog.cpp index b964626..61bd17c 100644 --- a/settingsdialog/settingsdialog.cpp +++ b/settingsdialog/settingsdialog.cpp @@ -5,6 +5,8 @@ #include "./optioncategory.h" #include "./optionpage.h" +#include "../misc/dialogutils.h" + #include "gui/ui_settingsdialog.h" #include @@ -31,11 +33,8 @@ SettingsDialog::SettingsDialog(QWidget *parent) : m_tabBarAlwaysVisible(true) { m_ui->setupUi(this); -#ifdef Q_OS_WIN32 - setStyleSheet(QStringLiteral("#mainWidget { color: black; background-color: white; border: none; } #bottomWidget { background-color: #F0F0F0; border-top: 1px solid #DFDFDF; } QMessageBox QLabel, QInputDialog QLabel, #instructionLabel {font-size: 12pt; color: #003399; }")); -#else - setStyleSheet(QStringLiteral("#instructionLabel { font-weight: bold; font-size: 12pt; }")); -#endif + makeHeading(m_ui->headingLabel); + setStyleSheet(dialogStyle()); // setup models m_categoryFilterModel->setSourceModel(m_categoryModel); m_ui->categoriesListView->setModel(m_categoryFilterModel); @@ -132,11 +131,11 @@ void SettingsDialog::showCategory(OptionCategory *category) if(category) { if(m_currentCategory != category) { m_currentCategory = category; - m_ui->instructionLabel->setText(category->displayName()); + m_ui->headingLabel->setText(category->displayName()); } } else { m_currentCategory = nullptr; - m_ui->instructionLabel->setText(tr("No category selected")); + m_ui->headingLabel->setText(tr("No category selected")); } updateTabWidget(); } diff --git a/settingsdialog/settingsdialog.ui b/settingsdialog/settingsdialog.ui index dd0fe75..b86112d 100644 --- a/settingsdialog/settingsdialog.ui +++ b/settingsdialog/settingsdialog.ui @@ -33,7 +33,7 @@ - + 0