X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fqtuistyle.cpp;h=c3f405de498ac25705006e221e2cc93ecbbde1ab;hb=d7e94af265bd78598bf52ce5fde6c7a1eba9e149;hp=af47119e113b7cf5f3afc33ff2144d791d55b69e;hpb=ac4f4b2e1aa24cc3f0418531abab14314b2be12c;p=quassel.git diff --git a/src/qtui/qtuistyle.cpp b/src/qtui/qtuistyle.cpp index af47119e..c3f405de 100644 --- a/src/qtui/qtuistyle.cpp +++ b/src/qtui/qtuistyle.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel Project * + * Copyright (C) 2005-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -18,91 +18,102 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "chatviewsettings.h" #include "qtuistyle.h" -QtUiStyle::QtUiStyle() : UiStyle("QtUiStyleNew") { // FIXME QtUiStyleNew naming - // We need to just set our internal formats; everything else is done by the base class... - - // Internal message formats - QTextCharFormat plainMsg; - plainMsg.setForeground(QBrush("black")); - setFormat(PlainMsg, plainMsg, Settings::Default); - - QTextCharFormat notice; - notice.setForeground(QBrush("navy")); - setFormat(NoticeMsg, notice, Settings::Default); - - QTextCharFormat server; - server.setForeground(QBrush("navy")); - setFormat(ServerMsg, server, Settings::Default); - - QTextCharFormat error; - error.setForeground(QBrush("red")); - setFormat(ErrorMsg, error, Settings::Default); - - QTextCharFormat join; - join.setForeground(QBrush("green")); - setFormat(JoinMsg, join, Settings::Default); - - QTextCharFormat part; - part.setForeground(QBrush("indianred")); - setFormat(PartMsg, part, Settings::Default); - - QTextCharFormat quit; - quit.setForeground(QBrush("indianred")); - setFormat(QuitMsg, quit, Settings::Default); - - QTextCharFormat kick; - kick.setForeground(QBrush("indianred")); - setFormat(KickMsg, kick, Settings::Default); - - QTextCharFormat nren; - nren.setForeground(QBrush("magenta")); - setFormat(RenameMsg, nren, Settings::Default); - - QTextCharFormat mode; - mode.setForeground(QBrush("steelblue")); - setFormat(ModeMsg, mode, Settings::Default); - - QTextCharFormat action; - action.setFontItalic(true); - action.setForeground(QBrush("darkmagenta")); - setFormat(ActionMsg, action, Settings::Default); - - // Internal message element formats - QTextCharFormat ts; - ts.setForeground(QBrush("grey")); - setFormat(Timestamp, ts, Settings::Default); - - QTextCharFormat sender; - sender.setAnchor(true); - sender.setForeground(QBrush("navy")); - setFormat(Sender, sender, Settings::Default); - - QTextCharFormat nick; - nick.setAnchor(true); - nick.setFontWeight(QFont::Bold); - setFormat(Nick, nick, Settings::Default); - - QTextCharFormat hostmask; - hostmask.setFontItalic(true); - setFormat(Hostmask, hostmask, Settings::Default); - - QTextCharFormat channel; - channel.setAnchor(true); - channel.setFontWeight(QFont::Bold); - setFormat(ChannelName, channel, Settings::Default); - - QTextCharFormat flags; - flags.setFontWeight(QFont::Bold); - setFormat(ModeFlags, flags, Settings::Default); - - QTextCharFormat url; - url.setFontUnderline(true); - url.setAnchor(true); - setFormat(Url, url, Settings::Default); - - _highlightColor = QColor(Qt::red); +#include +#include + +QtUiStyle::QtUiStyle(QObject *parent) : UiStyle(parent) { + ChatViewSettings s; + s.notify("TimestampFormat", this, SLOT(updateTimestampFormatString())); + updateTimestampFormatString(); } QtUiStyle::~QtUiStyle() {} + +void QtUiStyle::updateTimestampFormatString() { + ChatViewSettings s; + setTimestampFormatString(s.timestampFormatString()); +} + +void QtUiStyle::generateSettingsQss() const { + QFile settingsQss(Quassel::configDirPath() + "settings.qss"); + if(!settingsQss.open(QFile::WriteOnly|QFile::Truncate)) { + qWarning() << "Could not open" << settingsQss.fileName() << "for writing!"; + return; + } + QTextStream out(&settingsQss); + + out << "// Style settings made in Quassel's configuration dialog\n" + << "// This file is automatically generated, do not edit\n\n"; + + QtUiStyleSettings fs("Fonts"); + QFont font = fs.value("ChatView").value(); + QString desc = "font: "; + if(font.italic()) + desc += "italic "; + if(font.bold()) + desc += "bold "; + if(!font.italic() && !font.bold()) + desc += "normal "; + desc += QString("%1pt \"%2\"").arg(font.pointSize()).arg(font.family()); + + if(fs.value("UseCustomChatViewFont").toBool()) + out << "// ChatView Font\n\n" + << "ChatLine { " << desc << "; }\n\n"; + + QtUiStyleSettings s("Colors"); + if(s.value("UseChatViewColors").toBool()) { + out << "// Custom ChatView Colors\n\n" + + << "Palette { marker-line: " << color("MarkerLine", s) << "; }\n" + << "ChatView { background: " << color("ChatViewBackground", s) << "; }\n\n" + << "ChatLine[label=\"highlight\"] {\n" + << " foreground: " << color("Highlight",s) << ";\n" + << " background: " << color("HighlightBackground", s) << ";\n" + << "}\n\n" + << "ChatLine::timestamp { foreground: " << color("Timestamp", s) << "; }\n\n" + + << msgTypeQss("plain", "ChannelMsg", s) + << msgTypeQss("notice", "ServerMsg", s) + << msgTypeQss("action", "ActionMsg", s) + << msgTypeQss("nick", "CommandMsg", s) + << msgTypeQss("mode", "CommandMsg", s) + << msgTypeQss("join", "CommandMsg", s) + << msgTypeQss("part", "CommandMsg", s) + << msgTypeQss("quit", "CommandMsg", s) + << msgTypeQss("kick", "CommandMsg", s) + << msgTypeQss("kill", "CommandMsg", s) + << msgTypeQss("server", "ServerMsg", s) + << msgTypeQss("info", "ServerMsg", s) + << msgTypeQss("error", "ErrorMsg", s) + << msgTypeQss("daychange", "ServerMsg", s) + << "\n\n"; + } + + if(s.value("UseSenderColors").toBool()) { + out << "// Sender Colors\n\n" + << "ChatLine::sender#plain[sender=\"self\"] { foreground: " << color("SenderSelf", s) << "; }\n\n"; + + for(int i = 0; i < 16; i++) + out << senderQss(i, s); + } + + settingsQss.close(); +} + +QString QtUiStyle::color(const QString &key, QtUiStyleSettings &settings) const { + return settings.value(key).value().name(); +} + +QString QtUiStyle::msgTypeQss(const QString &msgType, const QString &key, QtUiStyleSettings &settings) const { + return QString("ChatLine#%1 { foreground: %2; }\n").arg(msgType, color(key, settings)); +} + +QString QtUiStyle::senderQss(int i, QtUiStyleSettings &settings) const { + QString dez = QString::number(i); + if(dez.length() == 1) dez.prepend('0'); + + return QString("ChatLine::sender#plain[sender=\"0%1\"] { foreground: %2; }\n").arg(QString::number(i, 16), color("Sender"+dez, settings)); +}