Raven Core  3.0.0
P2P Digital Currency
darkstyle.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 # #
4 # The MIT License #
5 # #
6 # Copyright (C) 2017 by Juergen Skrotzky (JorgenVikingGod@gmail.com) #
7 # >> https://github.com/Jorgen-VikingGod #
8 # #
9 # Sources: https://github.com/Jorgen-VikingGod/Qt-Frameless-Window-DarkStyle #
10 # #
11 ###############################################################################
12 */
13 
14 #include <QDebug>
15 #include "darkstyle.h"
16 
18  DarkStyle(styleBase())
19 { }
20 
21 DarkStyle::DarkStyle(QStyle *style):
22  QProxyStyle(style)
23 { }
24 
25 QStyle *DarkStyle::styleBase(QStyle *style) const {
26  static QStyle *base = !style ? QStyleFactory::create(QStringLiteral("Fusion")) : style;
27  return base;
28 }
29 
30 QStyle *DarkStyle::baseStyle() const
31 {
32  return styleBase();
33 }
34 
35 void DarkStyle::polish(QPalette &palette)
36 {
37  // modify palette to dark
38  palette.setColor(QPalette::Window,QColor(53,53,53));
39  palette.setColor(QPalette::WindowText,Qt::white);/*
40 ###############################################################################
41 # #
42 # The MIT License #
43 # #
44 # Copyright (C) 2017 by Juergen Skrotzky (JorgenVikingGod@gmail.com) #
45 # >> https://github.com/Jorgen-VikingGod #
46 # #
47 # Sources: https://github.com/Jorgen-VikingGod/Qt-Frameless-Window-DarkStyle #
48 # #
49 ###############################################################################
50 */
51  palette.setColor(QPalette::Disabled,QPalette::WindowText,QColor(127,127,127));
52  palette.setColor(QPalette::Base,QColor(42,42,42));
53  palette.setColor(QPalette::AlternateBase,QColor(66,66,66));
54  palette.setColor(QPalette::ToolTipBase,Qt::white);
55  palette.setColor(QPalette::ToolTipText,QColor(53,53,53));
56  palette.setColor(QPalette::Text,Qt::white);
57  palette.setColor(QPalette::Disabled,QPalette::Text,QColor(127,127,127));
58  palette.setColor(QPalette::Dark,QColor(35,35,35));
59  palette.setColor(QPalette::Shadow,QColor(20,20,20));
60  palette.setColor(QPalette::Button,QColor(53,53,53));
61  palette.setColor(QPalette::ButtonText,Qt::white);
62  palette.setColor(QPalette::Disabled,QPalette::ButtonText,QColor(127,127,127));
63  palette.setColor(QPalette::BrightText,Qt::red);
64  palette.setColor(QPalette::Link,QColor(42,130,218));
65  palette.setColor(QPalette::Highlight,QColor(42,130,218));
66  palette.setColor(QPalette::Disabled,QPalette::Highlight,QColor(80,80,80));
67  palette.setColor(QPalette::HighlightedText,Qt::white);
68  palette.setColor(QPalette::Disabled,QPalette::HighlightedText,QColor(127,127,127));
69 }
70 
71 void DarkStyle::polish(QApplication *app)
72 {
73  if (!app) return;
74 
75  // increase font size for better reading,
76  // setPointSize was reduced from +2 because when applied this way in Qt5, the font is larger than intended for some reason
77  QFont defaultFont = QApplication::font();
78  defaultFont.setPointSize(defaultFont.pointSize()+1);
79  app->setFont(defaultFont);
80 
81  // loadstylesheet
82  QFile qfDarkstyle(QStringLiteral(":/darkstyle/qss"));
83  if (qfDarkstyle.open(QIODevice::ReadOnly | QIODevice::Text))
84  {
85  // set stylesheet
86  QString qsStylesheet = QString::fromLatin1(qfDarkstyle.readAll());
87  app->setStyleSheet(qsStylesheet);
88  qfDarkstyle.close();
89  }
90 }
QStyle * baseStyle() const
Definition: darkstyle.cpp:30
void polish(QPalette &palette) override
Definition: darkstyle.cpp:35
QStyle * styleBase(QStyle *style=Q_NULLPTR) const
Definition: darkstyle.cpp:25