From 58facbe744eeb2ca6442af7a69840c96d6005ac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Thu, 13 Sep 2018 00:07:07 +0200 Subject: [PATCH] Use theme in titled toolbar. --- YACReaderLibrary/theme.h | 13 ++++++ custom_widgets/yacreader_titled_toolbar.cpp | 47 ++++++--------------- custom_widgets/yacreader_titled_toolbar.h | 13 ++++-- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/YACReaderLibrary/theme.h b/YACReaderLibrary/theme.h index c1fc548a..483a9d45 100644 --- a/YACReaderLibrary/theme.h +++ b/YACReaderLibrary/theme.h @@ -52,6 +52,10 @@ public: t.sidebarBackgroundColor = "#F1F1F1"; t.sidebarSplitterStyle = "QSplitter::handle:vertical { height: 29px; background-color: transparent;}"; + + t.titledToolBarSeparatorColor = "#AFAFAF"; + t.titledToolBarTitleColor = "#808080"; + t.titledToolBarTitleShadowColor = "#00000000"; } else { t.isMacosNative = false; #ifdef Q_OS_MAC @@ -94,6 +98,10 @@ public: " image: none; background-color = black; " " }" "QSplitter::handle:vertical { height: 39px;}"*/ + + t.titledToolBarSeparatorColor = "#6F6F6F"; + t.titledToolBarTitleColor = "#BDBFBF"; + t.titledToolBarTitleShadowColor = "#000000"; } return t; @@ -126,6 +134,11 @@ public: //Sidebar QString sidebarBackgroundColor; QString sidebarSplitterStyle; + + //YACReaderTitledToolBar + QString titledToolBarSeparatorColor; + QString titledToolBarTitleColor; + QString titledToolBarTitleShadowColor; }; #endif // THEME_H diff --git a/custom_widgets/yacreader_titled_toolbar.cpp b/custom_widgets/yacreader_titled_toolbar.cpp index cd39462f..34b97687 100644 --- a/custom_widgets/yacreader_titled_toolbar.cpp +++ b/custom_widgets/yacreader_titled_toolbar.cpp @@ -40,9 +40,10 @@ void DropShadowLabel::paintEvent(QPaintEvent *event) QPainter painter(this); painter.setFont(font()); -#ifndef Q_OS_MAC - drawTextEffect(&painter, QPoint(contentsMargins().left(), 1)); -#endif + + if (!theme.isMacosNative) { + drawTextEffect(&painter, QPoint(contentsMargins().left(), 1)); + } drawText(&painter, QPoint(contentsMargins().left(), 0)); } @@ -68,15 +69,11 @@ YACReaderTitledToolBar::YACReaderTitledToolBar(const QString &title, QWidget *pa nameLabel = new DropShadowLabel(this); nameLabel->setText(title); -#ifdef Q_OS_MAC + QString nameLabelStyleSheet = "QLabel {padding:0 0 0 10px; margin:0px; font-size:11px; font-weight:bold;}"; - nameLabel->setColor(QColor("#808080")); - //nameLabel->setDropShadowColor(QColor("#F9FAFB")); -#else - QString nameLabelStyleSheet = "QLabel {padding:0 0 0 10px; margin:0px; font-size:11px; font-weight:bold;}"; - nameLabel->setColor(QColor("#BDBFBF")); - nameLabel->setDropShadowColor(QColor("#000000")); -#endif + nameLabel->setColor(QColor(theme.titledToolBarTitleColor)); + nameLabel->setDropShadowColor(QColor(theme.titledToolBarTitleShadowColor)); + nameLabel->setStyleSheet(nameLabelStyleSheet); mainLayout->addWidget(nameLabel, Qt::AlignLeft); @@ -91,28 +88,15 @@ YACReaderTitledToolBar::YACReaderTitledToolBar(const QString &title, QWidget *pa void YACReaderTitledToolBar::addAction(QAction *action) { - QHBoxLayout *mainLayout = dynamic_cast(layout()); + auto mainLayout = dynamic_cast(layout()); -//fix for QToolButton and retina support in OSX -#ifdef Q_OS_MAC - QPushButton *pb = new QPushButton(this); - pb->setCursor(QCursor(Qt::ArrowCursor)); - pb->setIcon(action->icon()); - pb->addAction(action); - - connect(pb, SIGNAL(clicked(bool)), action, SIGNAL(triggered(bool))); - - mainLayout->addWidget(pb); -#else - QToolButton *tb = new QToolButton(this); + auto tb = new QToolButton(this); tb->setCursor(QCursor(Qt::ArrowCursor)); tb->setDefaultAction(action); tb->setIconSize(QSize(16, 16)); tb->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - //tb->setStyleSheet("QToolButton:hover {background-color:#C5C5C5;}"); mainLayout->addWidget(tb); -#endif } void YACReaderTitledToolBar::addSpacing(int spacing) @@ -124,15 +108,12 @@ void YACReaderTitledToolBar::addSpacing(int spacing) void YACReaderTitledToolBar::addSepartor() { - QHBoxLayout *mainLayout = dynamic_cast(layout()); + auto mainLayout = dynamic_cast(layout()); - QWidget *w = new QWidget(this); + auto w = new QWidget(this); w->setFixedSize(1, 14); -#ifdef Q_OS_MAC - w->setStyleSheet("QWidget {background-color:#AFAFAF;}"); -#else - w->setStyleSheet("QWidget {background-color:#6F6F6F;}"); -#endif + + w->setStyleSheet(QString("QWidget {background-color:%1;}").arg(theme.titledToolBarSeparatorColor)); mainLayout->addSpacing(10); mainLayout->addWidget(w); diff --git a/custom_widgets/yacreader_titled_toolbar.h b/custom_widgets/yacreader_titled_toolbar.h index faa25021..ec0d89f0 100644 --- a/custom_widgets/yacreader_titled_toolbar.h +++ b/custom_widgets/yacreader_titled_toolbar.h @@ -1,6 +1,8 @@ #ifndef YACREADER_TITLED_TOOLBAR_H #define YACREADER_TITLED_TOOLBAR_H +#include "theme.h" + #include #include #include @@ -14,7 +16,7 @@ class DropShadowLabel : public QLabel Q_OBJECT public: - DropShadowLabel(QWidget *parent = 0); + DropShadowLabel(QWidget *parent = nullptr); void paintEvent(QPaintEvent *event); void setColor(const QColor &color); void setDropShadowColor(const QColor &color); @@ -23,14 +25,16 @@ private: QColor dropShadowColor; QColor textColor; void drawText(QPainter *painter, QPoint offset); - void drawTextEffect(QPainter *painter, QPoint offset); + void drawTextEffect(QPainter* painter, QPoint offset); + + Theme theme = Theme::currentTheme(); }; class YACReaderTitledToolBar : public QWidget { Q_OBJECT public: - explicit YACReaderTitledToolBar(const QString &title, QWidget *parent = 0); + explicit YACReaderTitledToolBar(const QString &title, QWidget *parent = nullptr); signals: @@ -40,7 +44,8 @@ public slots: void addSepartor(); private: - DropShadowLabel *nameLabel; + DropShadowLabel * nameLabel; + Theme theme = Theme::currentTheme(); }; #endif // YACREADER_TITLED_TOOLBAR_H