-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
153 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef STYLEREPOSITORY_H | ||
#define STYLEREPOSITORY_H | ||
|
||
#include <QObject> | ||
#include "scopy-core_export.h" | ||
|
||
namespace scopy { | ||
class SCOPY_CORE_EXPORT StyleRepository : public QObject | ||
{ | ||
Q_OBJECT | ||
protected: | ||
StyleRepository(QObject *parent = nullptr); | ||
~StyleRepository(); | ||
|
||
public: | ||
StyleRepository(StyleRepository &other) = delete; | ||
void operator=(const StyleRepository &) = delete; | ||
static StyleRepository *GetInstance(); | ||
|
||
QString getAttribute(char *key); | ||
QColor getColor(char *key); | ||
int getDimension(char *key); | ||
|
||
protected: | ||
void applyStyle(); | ||
|
||
private: | ||
static StyleRepository *pinstance_; | ||
QJsonDocument *m_json; | ||
QString m_jsonPath; | ||
QString m_qssPath; | ||
}; | ||
} // namespace scopy | ||
|
||
#endif // STYLEREPOSITORY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "stylerepository.h" | ||
#include "qcolor.h" | ||
#include "qjsonobject.h" | ||
|
||
#include <QApplication> | ||
#include <QFile> | ||
#include <QJsonDocument> | ||
#include <iostream> | ||
|
||
using namespace scopy; | ||
|
||
StyleRepository *StyleRepository::pinstance_{nullptr}; | ||
|
||
StyleRepository::StyleRepository(QObject *parent) | ||
: QObject(parent), | ||
m_jsonPath("style_variables.json"), | ||
m_qssPath("style.qss") | ||
|
||
{ | ||
QFile file(m_jsonPath); | ||
file.open(QIODevice::ReadOnly); | ||
QByteArray data = file.readAll(); | ||
file.close(); | ||
m_json = new QJsonDocument(QJsonDocument::fromJson(data)); | ||
|
||
applyStyle(); | ||
} | ||
|
||
StyleRepository::~StyleRepository() {} | ||
|
||
StyleRepository *StyleRepository::GetInstance() | ||
{ | ||
if(pinstance_ == nullptr) { | ||
pinstance_ = new StyleRepository(QApplication::instance()); // singleton has the app as parent | ||
} | ||
return pinstance_; | ||
} | ||
|
||
QString StyleRepository::getAttribute(char *key) { return m_json->object().value(key).toString(); } | ||
|
||
QColor StyleRepository::getColor(char *key) { return QColor(getAttribute(key)); } | ||
|
||
int StyleRepository::getDimension(char *key) { return getAttribute(key).toInt(); } | ||
|
||
void StyleRepository::applyStyle() | ||
{ | ||
QFile file(m_qssPath); | ||
file.open(QIODevice::ReadOnly); | ||
QString style = QString(file.readAll()); | ||
file.close(); | ||
|
||
for(const QString &key: m_json->object().keys()) { | ||
QJsonValue value = m_json->object().value(key); | ||
style.replace("&" + key + "&", value.toString()); | ||
} | ||
|
||
qApp->setStyleSheet(style); | ||
std::cout << style.toStdString() << std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"unit_pixel_1": "12" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
QPushButton[&&property&&="true"] { | ||
width: &unit_pixel_1&; // 48px | ||
height: &unit_pixel_1&; // 48px | ||
QPushButton[&&property&&=true] { | ||
width: &json_globals_dimensions_unit_pixel_1&; | ||
height: &json_globals_dimensions_unit_pixel_1&; | ||
|
||
&add_border_small& | ||
// border-radius: 0px 2px 2px 0px; | ||
// border-style: outset; | ||
border-radius: 0px 2px 2px 0px; | ||
border-style: outset; | ||
|
||
qproperty-iconSize: &1pixel_unit&; // 48px | ||
background-color: &color_highlight_1&; // #272730 | ||
qproperty-iconSize: &json_globals_dimensions_unit_pixel_1&; | ||
background-color: &theme_dark_colors_highlight&; | ||
|
||
&add_font_small& | ||
// color: white; | ||
// font-weight: 700; | ||
// font-size: 14px; | ||
|
||
color: &theme_dark_colors_highlight&; | ||
font-weight: 700; | ||
font-size: 14px; | ||
|
||
height: &unit_pixel_1&; | ||
height: &json_globals_dimensions_unit_pixel_1&; | ||
} | ||
|
||
QPushButton[&&property&&=true]:hover { | ||
background-color: &theme_dark_colors_background&; | ||
} | ||
|
||
QPushButton[&&property&&="true"]:checked { | ||
background-color: &color_highlight_2&; // #4A64FF | ||
QPushButton[&&property&&=true]:pressed { | ||
background-color: &theme_dark_colors_background&; | ||
} | ||
|
||
QPushButton[&&property&&="true"]:pressed { | ||
background-color: &color_highlight_2&; // #4A64FF | ||
QPushButton{ | ||
color: &theme_dark_colors_highlight&; | ||
} |