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.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

View File

@ -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<QHBoxLayout *>(layout());
auto mainLayout = dynamic_cast<QHBoxLayout *>(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<QHBoxLayout *>(layout());
auto mainLayout = dynamic_cast<QHBoxLayout *>(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);

View File

@ -1,6 +1,8 @@
#ifndef YACREADER_TITLED_TOOLBAR_H
#define YACREADER_TITLED_TOOLBAR_H
#include "theme.h"
#include <QWidget>
#include <QLabel>
#include <QPaintEvent>
@ -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