unified dialog style sheet, removed hard coded colors

This commit is contained in:
Martchus 2015-09-26 20:28:30 +02:00
parent 8b4574de97
commit f44930d580
6 changed files with 67 additions and 21 deletions

View File

@ -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);

View File

@ -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);

View File

@ -1,6 +1,12 @@
#include "./dialogutils.h"
#ifdef GUI_NONE
#include <QCoreApplication>
#else
#include <QGuiApplication>
#include <QPalette>
#include <QWidget>
#endif
#include <QFileInfo>
#include <QDir>
@ -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

View File

@ -5,9 +5,9 @@
#include <QtGlobal>
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

View File

@ -5,6 +5,8 @@
#include "./optioncategory.h"
#include "./optionpage.h"
#include "../misc/dialogutils.h"
#include "gui/ui_settingsdialog.h"
#include <QItemSelectionModel>
@ -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();
}

View File

@ -33,7 +33,7 @@
<widget class="QWidget" name="mainWidget" native="true">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QLabel" name="instructionLabel">
<widget class="QLabel" name="headingLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>