ref #304, reloadable style sheets

This commit is contained in:
Klaus Basan
2014-07-27 15:01:17 +02:00
parent bc6bbf3d79
commit edf4a6b80e
7 changed files with 620 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
QWidget {
color: white;
font-family: "Arial";
font-size: 8pt;
font-style: normal;
font-weight: bold;
}

View File

View File

@@ -0,0 +1,312 @@
/** http://qt-project.org/doc/qt-5.3/stylesheet-examples.html **/
QWidget {
background-color: black;
}
QProgressBar {
border: 1px solid green;
border-radius: 5px;
text-align: center;
padding: 0px;
height: 16px;
}
QProgressBar::chunk {
background-color: darkblue;
width: 10px;
margin: 0.5px;
}
#wi_CentralWidgetOutside {
/** there is no opacity with background image, so we need semitransparent images **/
/** background-image: url(:/blackgui/icons/titaniumtexture.jpg) **/
/** border: 2px solid green; **/
/** border-radius: 20px; **/
background-color: darkslategray;
margin: 0px;
padding: 5px;
}
#fr_CentralFrameInside {
background-color: darkslategray;
margin: 5px;
}
#wi_MainKeypadArea {
background-color: darkslategray;
}
#gb_AtcStationsOnlineInfo {
border-style: none;
}
#sw_MainMiddle {
padding: 3px;
border: 0px;
border-radius: 10px;
}
#sw_MainMiddle QPushButton {
background-color: rgba(0, 0, 255, 128);
border-style: none;
border-radius:3px;
color: yellow;
padding: 3px;
}
/* No style for Dial
#sw_MainMiddel QDial {
background-color: rgba(0, 0, 255, 128);
}
*/
#wi_MainKeypadArea QPushButton {
background-color: black;
border-style: solid;
border-width:1px;
border-radius:6px;
border-color: green;
max-height:20px;
min-width:60px;
min-height:20px;
}
#wi_MainKeypadAreaWindow {
background-color: darkslategray;
}
#le_CommandLineInput {
margin-bottom: 5px;
padding: 3px;
border-radius: 5px;
}
QTabWidget::pane { /* The tab widget frame */
border: none;
}
QTabWidget::tab-bar {
left: 5px; /* move to the right by 5px */
}
QTabBar::tab {
border: 1px solid green;
border-top-left-radius: 6px;
border-top-right-radius: 6px;
min-width: 30px;
padding: 2px;
padding-left: 4px;
padding-right: 4px;
margin-right: 3px;
}
QTabBar::tab::selected {
background-color: rgba(0, 0, 255, 128);
}
QLabel {
background: transparent;
}
QLineEdit {
background: black;
border: 1px solid green;
border-radius: 5px;
}
QLineEdit[readOnly="true"] {
background: black;
}
QCheckBox {
border: 0px solid green;
background: transparent;
}
QTextEdit {
border: 1px solid green;
background: transparent;
border-radius: 5px;
}
QPlainTextEdit {
border: 1px solid green;
background: transparent;
border-radius: 5px;
}
QGroupBox {
border: 1px solid green;
margin-top: 2ex; /* leave space at the top for the title */
}
QGroupBox::title {
subcontrol-origin: margin;
subcontrol-position: middle center; /* position at the top center */
padding: 0 3px;
}
QToolBox {
border: none;
}
QToolBox::tab {
border: 1px solid green;
border-radius: 6px;
min-width: 30px;
padding: 2px;
padding-left: 4px;
padding-right: 4px;
}
QToolBox::tab::selected {
background-color: rgba(0, 0, 255, 128);
}
QComboBox {
border: 1px solid green;
border-radius: 5px;
padding: 1px;
background: transparent;
}
QDoubleSpinBox {
border: 1px solid green;
border-radius: 5px;
padding: 1px;
background: transparent;
}
QMenuBar {
background: darkslategray;
}
QMenuBar::item {
spacing: 3px; /* spacing between menu bar items */
padding: 1px 4px;
background: transparent;
border-radius: 4px;
}
QMenuBar::item:selected { /* when selected using mouse or keyboard */
background: black;
}
QMenuBar::item:pressed {
background: black;
}
QMenu {
border: 2px solid darkslategray; /* reserve space for selection border */
background: lightgray;
color: black;
padding: 2px;
}
QScrollBar:horizontal {
border: 2px solid gray;
background: slategray;
height: 10px;
margin: 0px 5px 0 5px;
}
QScrollBar:vertical {
border: 2px solid gray;
background: slategray;
width: 10px;
margin: 5px 0 5px 0;
}
QScrollBar::handle:horizontal {
background: black;
min-width: 15px;
}
QScrollBar::handle:vertical {
background: black;
min-height: 15px;
}
QScrollBar::add-line:horizontal {
border: 2px solid gray;
background: blue;
width: 5px;
subcontrol-position: right;
subcontrol-origin: margin;
}
QScrollBar::sub-line:horizontal {
border: 2px solid gray;
background: blue;
width: 5px;
subcontrol-position: left;
subcontrol-origin: margin;
}
QScrollBar::add-line:vertical {
border: 2px solid gray;
background: blue;
height: 5px;
subcontrol-position: bottom;
subcontrol-origin: margin;
}
QScrollBar::sub-line:vertical {
border: 2px solid gray;
background: blue;
height: 5px;
subcontrol-position: top;
subcontrol-origin: margin;
}
QHeaderView::section {
border: 1px solid black;
background-color: darkslategray;
padding: 1px;
margin: 0px;
}
QTableView {
border: 1px solid green;
border-radius: 5px;
background-color: black;
alternate-background-color: darkslategray;
selection-background-color: blue;
margin-left: 2px;
margin-top: 1px;
margin-bottom: 0;
padding:0;
}
QSlider::groove:horizontal {
border: 1px solid gray;
height: 4px; /* the groove expands to the size of the slider by default. by giving it a height, it has a fixed size */
background: darkslategray;
}
QSlider::handle:horizontal {
background: lightgray;
border: 1px solid darkslategray;
width: 18px;
margin: -2px 0; /* handle is placed by default on the contents rect of the groove. Expand outside the groove */
border-radius: 3px;
}
QSizeGrip {
image: url(:/diagona/icons/diagona/icons/arrow-resize-135.png);
width: 16px;
height: 16px;
}
QStatusBar {
background: darkslategray;
}
QStatusBar::item {
border: none;
}
QStatusBar QLabel {
border: none;
}

View File

@@ -0,0 +1,23 @@
QWidget {
font-family: arial-rounded;
font: bold 10px;
color: black; /** font **/
}
QPushButton {
background-color: rgba(255, 255, 0, 175);
border-style: solid;
border-width:1px;
border-radius:0px;
border-color: green;
max-height:20px;
}
QTextEdit {
background-color: rgba(255, 255, 0, 175);
border-style: solid;
border-width:1px;
border-radius:6px;
border-color: green;
opacity: 0.5;
}

View File

@@ -0,0 +1,23 @@
QWidget {
font-family: arial-rounded;
font: bold 10px;
color: black; /** font **/
}
QPushButton {
background-color: rgba(255, 255, 0, 175);
border-style: solid;
border-width:1px;
border-radius:0px;
border-color: green;
max-height:20px;
}
QTextEdit {
background-color: rgba(255, 255, 0, 175);
border-style: solid;
border-width:1px;
border-radius:6px;
border-color: green;
opacity: 0.5;
}

View File

@@ -0,0 +1,156 @@
/* Copyright (C) 2013
* swift Project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "stylesheetutility.h"
#include <QCoreApplication>
#include <QDir>
#include <QTextStream>
#include <QDebug>
namespace BlackGui
{
CStyleSheetUtility::CStyleSheetUtility(QObject *parent) : QObject(parent)
{
this->read();
}
const QString CStyleSheetUtility::fontStyleAsString(const QFont &font)
{
switch (font.style())
{
case QFont::StyleNormal: return "normal";
case QFont::StyleItalic: return "italic";
case QFont::StyleOblique: return "oblique";
default: return "";
}
}
const QString CStyleSheetUtility::fontWeightAsString(const QFont &font)
{
if (font.weight() < static_cast<int>(QFont::Normal))
{
return "light";
}
else if (font.weight() < static_cast<int>(QFont::DemiBold))
{
return "normal";
}
else if (font.weight() < static_cast<int>(QFont::Bold))
{
return "demibold";
}
else if (font.weight() < static_cast<int>(QFont::Black))
{
return "bold";
}
else
{
return "black";
}
}
bool CStyleSheetUtility::read()
{
QDir directory(qssDirectory());
if (!directory.exists()) return false;
directory.setNameFilters({"*.qss"});
directory.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
QFileInfoList fileInfoList = directory.entryInfoList();
for (int i = 0; i < fileInfoList.size(); ++i)
{
QFileInfo fileInfo = fileInfoList.at(i);
QFile file(fileInfo.absoluteFilePath());
if (file.open(QFile::QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream in(&file);
QString c = in.readAll();
QString f = fileInfo.fileName().toLower();
// keep even empty files as placeholders
this->m_styleSheets.insert(f, c);
}
file.close();
}
emit this->styleSheetsChanged();
return true;
}
QString CStyleSheetUtility::style(const QString &fileName) const
{
if (!this->containsStyle(fileName)) return QString();
return this->m_styleSheets[fileName.toLower()];
}
QString CStyleSheetUtility::styles(const QStringList &fileNames) const
{
QString style;
foreach(QString fileName, fileNames)
{
if (!this->containsStyle(fileName)) continue;
QString s = this->m_styleSheets[fileName.toLower()];
if (s.isEmpty()) continue;
if (!style.isEmpty()) style.append("\n\n");
style.append("/** file: %1 **/\n").arg(fileName);
style.append(s);
}
return style;
}
bool CStyleSheetUtility::containsStyle(const QString &fileName) const
{
if (fileName.isEmpty()) return false;
return this->m_styleSheets.contains(fileName.toLower());
}
bool CStyleSheetUtility::updateFonts(const QFont &font)
{
const QString indent(" ");
QString fontStyleSheet;
fontStyleSheet.append(indent).append("font-family: \"").append(font.family()).append("\";\n");
fontStyleSheet.append(indent).append("font-size: ");
if (font.pixelSize() >= 0)
{
fontStyleSheet.append(font.pixelSize()).append("px\n");
}
else
{
fontStyleSheet.append(QString::number(font.pointSizeF())).append("pt;\n");
}
fontStyleSheet.append(indent).append("font-style: ").append(fontStyleAsString(font)).append(";\n");
fontStyleSheet.append(indent).append("font-weight: ").append(fontWeightAsString(font)).append(";\n");
qDebug() << fontStyleSheet;
QString qss("QWidget {\n");
qss.append(indent).append("color: white;\n");
qss.append(fontStyleSheet);
qss.append("}\n");
QFile fontFile(qssDirectory().append("/").append(fileNameFonts()));
bool ok = fontFile.open(QFile::Text | QFile::WriteOnly);
if (ok)
{
QTextStream out(&fontFile);
out << qss;
fontFile.close();
ok = this->read();
}
return ok;
}
QString CStyleSheetUtility::qssDirectory()
{
QString dirPath = QCoreApplication::applicationDirPath();
if (!dirPath.endsWith('/')) dirPath.append('/');
dirPath.append("qss");
return dirPath;
}
}

View File

@@ -0,0 +1,99 @@
/* Copyright (C) 2014
* swift Project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#ifndef BLACKGUI_STYLESHEETUTILITY_H
#define BLACKGUI_STYLESHEETUTILITY_H
//! \file
#include <QMap>
#include <QObject>
#include <QFont>
namespace BlackGui
{
//! Reads and provides style sheets
class CStyleSheetUtility : public QObject
{
Q_OBJECT
public:
//! Read the *.qss files
bool read();
//! Style for file name
QString style(const QString &fileName) const;
//! Multiple styles concatenated
QString styles(const QStringList &fileNames) const;
//! Contains style for name
bool containsStyle(const QString &fileName) const;
//! Update the fonts
bool updateFonts(const QFont &font);
//! Central reader
static CStyleSheetUtility &instance()
{
static CStyleSheetUtility r;
return r;
}
//! File name fonts.qss
static const QString &fileNameFonts()
{
static const QString f("fonts.qss");
return f;
}
//! File name mainwindow.qss
static const QString &fileNameMainWindow()
{
static const QString f("mainwindow.qss");
return f;
}
//! File name dockwidgettab.qss
static const QString &fileNameDockWidgetTab()
{
static const QString f("dockwidgettab.qss");
return f;
}
//! File name maininfoarea.qss
static const QString &fileNameMainInfoArea()
{
static const QString f("maininfoarea.qss");
return f;
}
//! qss directory
static QString qssDirectory();
signals:
//! Sheets have been changed
void styleSheetsChanged();
private:
QMap<QString, QString> m_styleSheets; //!< filename, stylesheet
//! Constructor
explicit CStyleSheetUtility(QObject *parent = nullptr);
//! Font style as string
static const QString fontStyleAsString(const QFont &font);
//! Font weight as string
static const QString fontWeightAsString(const QFont &font);
};
}
#endif // guard