#ifndef BUILD_CORE
// put client-only arguments here
+ cliParser->addOption("qss <file.qss>", 0, "Load a custom application stylesheet");
cliParser->addSwitch("debugbufferswitches", 0, "Enables debugging for bufferswitches");
cliParser->addSwitch("debugmodel", 0, "Enables debugging for models");
#endif
_paletteColorRoles["window-text"] = QPalette::WindowText;
}
-void QssParser::loadStyleSheet(const QString &styleSheet) {
- QString ss = styleSheet;
- ss = "file:////home/sputnick/devel/quassel/test.qss"; // FIXME
- if(ss.startsWith("file:///")) {
- ss.remove(0, 8);
- QFile file(ss);
- if(file.open(QFile::ReadOnly)) {
- QTextStream stream(&file);
- ss = stream.readAll();
- } else {
- qWarning() << tr("Could not read stylesheet \"%1\"!").arg(file.fileName());
- return;
- }
- }
+void QssParser::processStyleSheet(QString &ss) {
if(ss.isEmpty())
return;
public:
QssParser();
- void loadStyleSheet(const QString &sheet);
+ void processStyleSheet(QString &sheet);
inline QPalette palette() const { return _palette; }
inline const QHash<quint64, QTextCharFormat>& formats() const { return _formats; }
qDeleteAll(_metricsCache);
}
+void UiStyle::loadStyleSheet() {
+ qDeleteAll(_metricsCache);
+ _metricsCache.clear();
+ _formatCache.clear();
+
+ QString styleSheet;
+
+ styleSheet += loadStyleSheet("file:///" + Quassel::findDataFilePath("default.qss"));
+ styleSheet += loadStyleSheet("file:///" + Quassel::configDirPath() + "custom.qss");
+ // styleSheet += loadStyleSheet("file:///" + some custom file name); FIXME
+ styleSheet += loadStyleSheet("file:///" + Quassel::optionValue("qss"), true);
+
+ if(styleSheet.isEmpty())
+ return;
+
+ QssParser parser;
+ parser.processStyleSheet(styleSheet);
+ QApplication::setPalette(parser.palette());
+ _formatCache = parser.formats();
+
+ qApp->setStyleSheet(styleSheet); // pass the remaining sections to the application
+}
+
+QString UiStyle::loadStyleSheet(const QString &styleSheet, bool shouldExist) {
+ QString ss = styleSheet;
+ if(ss.startsWith("file:///")) {
+ ss.remove(0, 8);
+ if(ss.isEmpty())
+ return QString();
+
+ QFile file(ss);
+ if(file.open(QFile::ReadOnly)) {
+ QTextStream stream(&file);
+ ss = stream.readAll();
+ file.close();
+ } else {
+ if(shouldExist)
+ qWarning() << "Could not open stylesheet file:" << file.fileName();
+ return QString();
+ }
+ }
+ return ss;
+}
+
QTextCharFormat UiStyle::cachedFormat(quint64 key) const {
return _formatCache.value(key, QTextCharFormat());
}
}
return in;
}
-
-/***********************************************************************************/
-// Stylesheet handling
-/***********************************************************************************/
-
-void UiStyle::loadStyleSheet() {
- QssParser parser;
- parser.loadStyleSheet(qApp->styleSheet());
-
- // TODO handle results
- QApplication::setPalette(parser.palette());
-
- qDeleteAll(_metricsCache);
- _metricsCache.clear();
- _formatCache = parser.formats();
-}
class StyledMessage;
+ void loadStyleSheet();
+
static FormatType formatType(Message::Type msgType);
static StyledString styleString(const QString &string, quint32 baseFormat = None);
static QString mircToInternal(const QString &);
QList<QTextLayout::FormatRange> toTextLayoutList(const FormatList &, int textLength, quint32 messageLabel = 0);
protected:
- void loadStyleSheet();
-
- //! Determines the format set to be used for the given hostmask
- //int formatSetIndex(const QString &hostmask) const;
- //int formatSetIndexForSelf() const;
+ QString loadStyleSheet(const QString &name, bool shouldExist = false);
QTextCharFormat cachedFormat(quint64 key) const;
QTextCharFormat cachedFormat(quint32 formatType, quint32 messageLabel = 0) const;