Use theme in titled toolbar.

This commit is contained in:
Luis Ángel San Martín 2018-09-13 00:07:07 +02:00 committed by Luis Ángel San Martín
parent cc73b27388
commit 58facbe744
3 changed files with 36 additions and 37 deletions

View File

@ -52,6 +52,10 @@ public:
t.sidebarBackgroundColor = "#F1F1F1"; t.sidebarBackgroundColor = "#F1F1F1";
t.sidebarSplitterStyle = "QSplitter::handle:vertical { height: 29px; background-color: transparent;}"; t.sidebarSplitterStyle = "QSplitter::handle:vertical { height: 29px; background-color: transparent;}";
t.titledToolBarSeparatorColor = "#AFAFAF";
t.titledToolBarTitleColor = "#808080";
t.titledToolBarTitleShadowColor = "#00000000";
} else { } else {
t.isMacosNative = false; t.isMacosNative = false;
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
@ -94,6 +98,10 @@ public:
" image: none; background-color = black; " " image: none; background-color = black; "
" }" " }"
"QSplitter::handle:vertical { height: 39px;}"*/ "QSplitter::handle:vertical { height: 39px;}"*/
t.titledToolBarSeparatorColor = "#6F6F6F";
t.titledToolBarTitleColor = "#BDBFBF";
t.titledToolBarTitleShadowColor = "#000000";
} }
return t; return t;
@ -126,6 +134,11 @@ public:
//Sidebar //Sidebar
QString sidebarBackgroundColor; QString sidebarBackgroundColor;
QString sidebarSplitterStyle; QString sidebarSplitterStyle;
//YACReaderTitledToolBar
QString titledToolBarSeparatorColor;
QString titledToolBarTitleColor;
QString titledToolBarTitleShadowColor;
}; };
#endif // THEME_H #endif // THEME_H

View File

@ -40,9 +40,10 @@ void DropShadowLabel::paintEvent(QPaintEvent *event)
QPainter painter(this); QPainter painter(this);
painter.setFont(font()); painter.setFont(font());
#ifndef Q_OS_MAC
drawTextEffect(&painter, QPoint(contentsMargins().left(), 1)); if (!theme.isMacosNative) {
#endif drawTextEffect(&painter, QPoint(contentsMargins().left(), 1));
}
drawText(&painter, QPoint(contentsMargins().left(), 0)); drawText(&painter, QPoint(contentsMargins().left(), 0));
} }
@ -68,15 +69,11 @@ YACReaderTitledToolBar::YACReaderTitledToolBar(const QString &title, QWidget *pa
nameLabel = new DropShadowLabel(this); nameLabel = new DropShadowLabel(this);
nameLabel->setText(title); nameLabel->setText(title);
#ifdef Q_OS_MAC
QString nameLabelStyleSheet = "QLabel {padding:0 0 0 10px; margin:0px; font-size:11px; font-weight:bold;}"; QString nameLabelStyleSheet = "QLabel {padding:0 0 0 10px; margin:0px; font-size:11px; font-weight:bold;}";
nameLabel->setColor(QColor("#808080")); nameLabel->setColor(QColor(theme.titledToolBarTitleColor));
//nameLabel->setDropShadowColor(QColor("#F9FAFB")); nameLabel->setDropShadowColor(QColor(theme.titledToolBarTitleShadowColor));
#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->setStyleSheet(nameLabelStyleSheet); nameLabel->setStyleSheet(nameLabelStyleSheet);
mainLayout->addWidget(nameLabel, Qt::AlignLeft); mainLayout->addWidget(nameLabel, Qt::AlignLeft);
@ -91,28 +88,15 @@ YACReaderTitledToolBar::YACReaderTitledToolBar(const QString &title, QWidget *pa
void YACReaderTitledToolBar::addAction(QAction *action) void YACReaderTitledToolBar::addAction(QAction *action)
{ {
QHBoxLayout *mainLayout = dynamic_cast<QHBoxLayout *>(layout()); auto mainLayout = dynamic_cast<QHBoxLayout *>(layout());
//fix for QToolButton and retina support in OSX auto tb = new QToolButton(this);
#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);
tb->setCursor(QCursor(Qt::ArrowCursor)); tb->setCursor(QCursor(Qt::ArrowCursor));
tb->setDefaultAction(action); tb->setDefaultAction(action);
tb->setIconSize(QSize(16, 16)); tb->setIconSize(QSize(16, 16));
tb->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); tb->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
//tb->setStyleSheet("QToolButton:hover {background-color:#C5C5C5;}");
mainLayout->addWidget(tb); mainLayout->addWidget(tb);
#endif
} }
void YACReaderTitledToolBar::addSpacing(int spacing) void YACReaderTitledToolBar::addSpacing(int spacing)
@ -124,15 +108,12 @@ void YACReaderTitledToolBar::addSpacing(int spacing)
void YACReaderTitledToolBar::addSepartor() void YACReaderTitledToolBar::addSepartor()
{ {
QHBoxLayout *mainLayout = dynamic_cast<QHBoxLayout *>(layout()); auto mainLayout = dynamic_cast<QHBoxLayout *>(layout());
QWidget *w = new QWidget(this); auto w = new QWidget(this);
w->setFixedSize(1, 14); w->setFixedSize(1, 14);
#ifdef Q_OS_MAC
w->setStyleSheet("QWidget {background-color:#AFAFAF;}"); w->setStyleSheet(QString("QWidget {background-color:%1;}").arg(theme.titledToolBarSeparatorColor));
#else
w->setStyleSheet("QWidget {background-color:#6F6F6F;}");
#endif
mainLayout->addSpacing(10); mainLayout->addSpacing(10);
mainLayout->addWidget(w); mainLayout->addWidget(w);

View File

@ -1,6 +1,8 @@
#ifndef YACREADER_TITLED_TOOLBAR_H #ifndef YACREADER_TITLED_TOOLBAR_H
#define YACREADER_TITLED_TOOLBAR_H #define YACREADER_TITLED_TOOLBAR_H
#include "theme.h"
#include <QWidget> #include <QWidget>
#include <QLabel> #include <QLabel>
#include <QPaintEvent> #include <QPaintEvent>
@ -14,7 +16,7 @@ class DropShadowLabel : public QLabel
Q_OBJECT Q_OBJECT
public: public:
DropShadowLabel(QWidget *parent = 0); DropShadowLabel(QWidget *parent = nullptr);
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
void setColor(const QColor &color); void setColor(const QColor &color);
void setDropShadowColor(const QColor &color); void setDropShadowColor(const QColor &color);
@ -23,14 +25,16 @@ private:
QColor dropShadowColor; QColor dropShadowColor;
QColor textColor; QColor textColor;
void drawText(QPainter *painter, QPoint offset); 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 class YACReaderTitledToolBar : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit YACReaderTitledToolBar(const QString &title, QWidget *parent = 0); explicit YACReaderTitledToolBar(const QString &title, QWidget *parent = nullptr);
signals: signals:
@ -40,7 +44,8 @@ public slots:
void addSepartor(); void addSepartor();
private: private:
DropShadowLabel *nameLabel; DropShadowLabel * nameLabel;
Theme theme = Theme::currentTheme();
}; };
#endif // YACREADER_TITLED_TOOLBAR_H #endif // YACREADER_TITLED_TOOLBAR_H