1 | #include "GitQlientStyles.h" |
2 | |
3 | #include <Colors.h> |
4 | #include <GitQlientSettings.h> |
5 | |
6 | #include <QFile> |
7 | |
8 | GitQlientStyles *GitQlientStyles::INSTANCE = nullptr; |
9 | |
10 | GitQlientStyles *GitQlientStyles::getInstance() |
11 | { |
12 | if (INSTANCE == nullptr) |
13 | INSTANCE = new GitQlientStyles(); |
14 | |
15 | return INSTANCE; |
16 | } |
17 | |
18 | QString GitQlientStyles::getStyles() |
19 | { |
20 | QString styles; |
21 | QFile stylesFile(":/stylesheet" ); |
22 | |
23 | if (stylesFile.open(QIODevice::ReadOnly)) |
24 | { |
25 | const auto colorSchema = GitQlientSettings().globalValue("colorSchema" , "dark" ).toString(); |
26 | QFile colorsFile(QString(":/colors_%1" ).arg(colorSchema)); |
27 | QString colorsCss; |
28 | |
29 | if (colorsFile.open(QIODevice::ReadOnly)) |
30 | { |
31 | colorsCss = QString::fromUtf8(colorsFile.readAll()); |
32 | colorsFile.close(); |
33 | } |
34 | |
35 | styles = stylesFile.readAll() + colorsCss; |
36 | |
37 | stylesFile.close(); |
38 | } |
39 | |
40 | return styles; |
41 | } |
42 | |
43 | QColor GitQlientStyles::getTextColor() |
44 | { |
45 | const auto colorSchema = GitQlientSettings().globalValue("colorSchema" , "dark" ).toString(); |
46 | |
47 | return colorSchema == "bright" ? textColorBright : textColorDark; |
48 | } |
49 | |
50 | QColor GitQlientStyles::getGraphSelectionColor() |
51 | { |
52 | const auto colorSchema = GitQlientSettings().globalValue("colorSchema" , "dark" ).toString(); |
53 | |
54 | return colorSchema == "dark" ? graphSelectionColorDark : graphSelectionColorBright; |
55 | } |
56 | |
57 | QColor GitQlientStyles::getGraphHoverColor() |
58 | { |
59 | const auto colorSchema = GitQlientSettings().globalValue("colorSchema" , "dark" ).toString(); |
60 | |
61 | return colorSchema == "dark" ? graphHoverColorDark : graphHoverColorBright; |
62 | } |
63 | |
64 | QColor GitQlientStyles::getBackgroundColor() |
65 | { |
66 | const auto colorSchema = GitQlientSettings().globalValue("colorSchema" , "dark" ).toString(); |
67 | |
68 | return colorSchema == "dark" ? graphBackgroundColorDark : graphBackgroundColorBright; |
69 | } |
70 | |
71 | QColor GitQlientStyles::getTabColor() |
72 | { |
73 | const auto colorSchema = GitQlientSettings().globalValue("colorSchema" , "dark" ).toString(); |
74 | |
75 | return colorSchema == "dark" ? graphHoverColorDark : graphBackgroundColorBright; |
76 | } |
77 | |
78 | QColor GitQlientStyles::getBlue() |
79 | { |
80 | const auto colorSchema = GitQlientSettings().globalValue("colorSchema" , "dark" ).toString(); |
81 | |
82 | return colorSchema == "dark" ? graphBlueDark : graphBlueBright; |
83 | } |
84 | |
85 | QColor GitQlientStyles::getRed() |
86 | { |
87 | return graphRed; |
88 | } |
89 | |
90 | QColor GitQlientStyles::getGreen() |
91 | { |
92 | return graphGreen; |
93 | } |
94 | |
95 | QColor GitQlientStyles::getOrange() |
96 | { |
97 | return graphOrange; |
98 | } |
99 | |
100 | std::array<QColor, GitQlientStyles::kBranchColors> GitQlientStyles::getBranchColors() |
101 | { |
102 | static std::array<QColor, kBranchColors> colors { { getTextColor(), graphRed, getBlue(), graphGreen, graphOrange, |
103 | graphGrey, graphPink, graphPastel } }; |
104 | |
105 | return colors; |
106 | } |
107 | |
108 | QColor GitQlientStyles::getBranchColorAt(int index) |
109 | { |
110 | if (index < kBranchColors && index >= 0) |
111 | return getBranchColors().at(static_cast<size_t>(index)); |
112 | |
113 | return QColor(); |
114 | } |
115 | |