|
a/HelperStructs/Style.cpp |
|
b/HelperStructs/Style.cpp |
1 |
/* Copyright (C) 2011 Lucio Carreras
|
1 |
/* Copyright (C) 2011 Lucio Carreras
|
|
|
2 |
* Copyright (C) 2017 J.F. Dockes
|
2 |
*
|
3 |
*
|
3 |
* This file is part of sayonara player
|
4 |
* This file is part of Upplay
|
4 |
*
|
5 |
*
|
5 |
* This program is free software: you can redistribute it and/or modify
|
6 |
* This program is free software: you can redistribute it and/or modify
|
6 |
* it under the terms of the GNU General Public License as published by
|
7 |
* it under the terms of the GNU General Public License as published by
|
7 |
* the Free Software Foundation, either version 3 of the License, or
|
8 |
* the Free Software Foundation, either version 3 of the License, or
|
8 |
* (at your option) any later version.
|
9 |
* (at your option) any later version.
|
|
... |
|
... |
19 |
#include <QString>
|
20 |
#include <QString>
|
20 |
#include <QDebug>
|
21 |
#include <QDebug>
|
21 |
|
22 |
|
22 |
#include "HelperStructs/Helper.h"
|
23 |
#include "HelperStructs/Helper.h"
|
23 |
#include "HelperStructs/Style.h"
|
24 |
#include "HelperStructs/Style.h"
|
|
|
25 |
#include "upadapt/upputils.h"
|
|
|
26 |
#include "utils/smallut.h"
|
24 |
|
27 |
|
|
|
28 |
#include <iostream>
|
|
|
29 |
#include <string>
|
|
|
30 |
#include <regex>
|
|
|
31 |
#include <array>
|
25 |
|
32 |
|
|
|
33 |
using namespace std;
|
|
|
34 |
|
|
|
35 |
/* font-size: 10pt; */
|
|
|
36 |
static const string fntszexp(R"((\s*font-size\s*:\s*)([0-9]+)(pt\s*;\s*))");
|
|
|
37 |
static regex fntszregex(fntszexp);
|
|
|
38 |
|
26 |
QString Style::get_style(bool dark)
|
39 |
QString Style::get_style(bool dark, float multiplier)
|
27 |
{
|
40 |
{
|
28 |
#if !defined(Q_OS_MACOS) && !defined(Q_OS_MAC)
|
41 |
#if !defined(Q_OS_MACOS) && !defined(Q_OS_MAC)
|
29 |
QString dir = Helper::getSharePath();
|
42 |
QString dir = Helper::getSharePath();
|
30 |
#else
|
43 |
#else
|
31 |
QString dir = Helper::getSharePath() + "/Resources/";
|
44 |
QString dir = Helper::getSharePath() + "/Resources/";
|
32 |
#endif
|
45 |
#endif
|
33 |
|
46 |
|
34 |
QString commonstyle;
|
47 |
QString commonstyle;
|
35 |
Helper::read_file_into_str(dir + "/common.qss", &commonstyle);
|
48 |
Helper::read_file_into_str(dir + "/common.qss", &commonstyle);
|
|
|
49 |
|
|
|
50 |
commonstyle = u8s2qs(scale_fonts(qs2utf8s(commonstyle), multiplier));
|
|
|
51 |
|
36 |
QString style;
|
52 |
QString style;
|
37 |
if (!dark) {
|
53 |
if (!dark) {
|
38 |
Helper::read_file_into_str(dir + "/standard.qss", &style);
|
54 |
Helper::read_file_into_str(dir + "/standard.qss", &style);
|
39 |
} else {
|
55 |
} else {
|
40 |
Helper::read_file_into_str(dir + "/dark.qss", &style);
|
56 |
Helper::read_file_into_str(dir + "/dark.qss", &style);
|
41 |
}
|
57 |
}
|
42 |
|
58 |
|
43 |
return commonstyle + style;
|
59 |
return commonstyle + style;
|
44 |
}
|
60 |
}
|
45 |
|
61 |
|
46 |
|
62 |
// The hell if I'm studying yet another regexp syntax, let's go std
|
47 |
QString Style::get_tv_style(bool /*dark*/, QPalette*)
|
63 |
string Style::scale_fonts(const string& style, float multiplier)
|
48 |
{
|
64 |
{
|
49 |
return "";
|
65 |
vector<string> lines;
|
|
|
66 |
stringToTokens(style, lines, "\n");
|
|
|
67 |
for (unsigned int ln = 0; ln < lines.size(); ln++) {
|
|
|
68 |
const string& line = lines[ln];
|
|
|
69 |
smatch m;
|
|
|
70 |
if (regex_match(line, m, fntszregex)) {
|
|
|
71 |
//cerr << "Got match (sz " << m.size() << ") for " << line << endl;
|
|
|
72 |
if (m.size() == 4) {
|
|
|
73 |
int fs = atoi(m[2].str().c_str());
|
|
|
74 |
int nfs = round(fs * multiplier);
|
|
|
75 |
char buf[20];
|
|
|
76 |
snprintf(buf, 20, "%d", nfs);
|
|
|
77 |
lines[ln] = m[1].str() + buf + m[3].str();
|
|
|
78 |
//cerr << "New line: [" << lines[ln] << "]\n";
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
string nstyle = string();
|
|
|
83 |
for (auto& ln : lines) {
|
|
|
84 |
nstyle += ln + "\n";
|
|
|
85 |
}
|
|
|
86 |
return nstyle;
|
50 |
}
|
87 |
}
|
51 |
|
|
|
52 |
|
|
|
53 |
QString Style::get_v_slider_style(bool dark, int percent)
|
|
|
54 |
{
|
|
|
55 |
if (!dark) {
|
|
|
56 |
return "";
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
percent = 0;
|
|
|
60 |
QString darker_grey = "#2B2B2B";
|
|
|
61 |
QString dark_grey = "#555555";
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
QString orange = "#e8841a";
|
|
|
66 |
QString back_col = orange;
|
|
|
67 |
|
|
|
68 |
if (percent > 0) {
|
|
|
69 |
double p = percent * 1.0 / 100.0;
|
|
|
70 |
int r, g, b;
|
|
|
71 |
b = 0;
|
|
|
72 |
if (p < 0.6) {
|
|
|
73 |
r = 255;
|
|
|
74 |
} else {
|
|
|
75 |
r = (-255.0 / 0.6) * (p - 0.6) + 255;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
g = (255.0) * p;
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
QString s_r;
|
|
|
82 |
QString s_g;
|
|
|
83 |
QString s_b;
|
|
|
84 |
|
|
|
85 |
s_r.sprintf("%02X", r);
|
|
|
86 |
s_g.sprintf("%02X", g);
|
|
|
87 |
s_b.sprintf("%02X", b);
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
back_col = "#" + s_g.left(2) + s_r.left(2) + s_b.left(2);
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
QString style = QString("QSlider {") +
|
|
|
95 |
"border-radius: 4px; " +
|
|
|
96 |
"background: #383838; " +
|
|
|
97 |
|
|
|
98 |
"}" +
|
|
|
99 |
|
|
|
100 |
"QSlider::handle:vertical {" +
|
|
|
101 |
" background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, " +
|
|
|
102 |
" stop: 0 #6B6B6B, stop: 0.4 " + dark_grey + ");" +
|
|
|
103 |
" height: 10px;" +
|
|
|
104 |
" margin-left: -5px; " +
|
|
|
105 |
" margin-right: -5px; " +
|
|
|
106 |
" min-width: 12px;" +
|
|
|
107 |
" border: 1px solid #2C2C2C; " +
|
|
|
108 |
" border-radius: 4px; " +
|
|
|
109 |
"}" +
|
|
|
110 |
|
|
|
111 |
"QSlider::handle:vertical:disabled {" +
|
|
|
112 |
" background: transparent;"
|
|
|
113 |
" height: 0px;"
|
|
|
114 |
" border-width: 0px;"
|
|
|
115 |
"}" +
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
"QSlider::groove:vertical { " +
|
|
|
119 |
" background: #383838;" +
|
|
|
120 |
" width: 6px; " +
|
|
|
121 |
" left: 10px; right: 10px; " +
|
|
|
122 |
"}" +
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
"QSlider::add-page:vertical {" +
|
|
|
126 |
/*" background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0, " +
|
|
|
127 |
" stop:0 #E88417, stop: 0.3 #C46600, " +
|
|
|
128 |
" stop: 0.7 #C46600, stop:1 #E88417); " +*/
|
|
|
129 |
//" background-color: qlineargradient(spread:pad, x1:0, y1:1, x2:0, y2:0, stop:0 rgba(255, 0, 0, 255), stop:0.505051 rgba(255, 228, 0, 255), stop:1 rgba(55, 239, 78, 255)); "
|
|
|
130 |
|
|
|
131 |
" background-color: " + back_col + "; "
|
|
|
132 |
" border-radius: 2px;" +
|
|
|
133 |
|
|
|
134 |
"}" +
|
|
|
135 |
|
|
|
136 |
"QSlider::sub-page:vertical, QSlider::add-page:vertical:disabled {" +
|
|
|
137 |
" background: " + darker_grey + ";" +
|
|
|
138 |
// " background-color: " + back_col + "; "
|
|
|
139 |
" border-radius: 2px;" +
|
|
|
140 |
|
|
|
141 |
"}";
|
|
|
142 |
|
|
|
143 |
return style;
|
|
|
144 |
}
|
|
|