1 /***************************************************************************
2 * Copyright (C) 2005-09 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * 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 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "chatviewsettings.h"
22 #include "qtuistyle.h"
25 #include <QTextStream>
27 QtUiStyle::QtUiStyle(QObject *parent) : UiStyle(parent) {
29 s.notify("TimestampFormat", this, SLOT(updateTimestampFormatString()));
30 updateTimestampFormatString();
33 QtUiStyle::~QtUiStyle() {}
35 void QtUiStyle::updateTimestampFormatString() {
37 setTimestampFormatString(s.timestampFormatString());
40 void QtUiStyle::generateSettingsQss() const {
41 QFile settingsQss(Quassel::configDirPath() + "settings.qss");
42 if(!settingsQss.open(QFile::WriteOnly|QFile::Truncate)) {
43 qWarning() << "Could not open" << settingsQss.fileName() << "for writing!";
46 QTextStream out(&settingsQss);
48 out << "// Style settings made in Quassel's configuration dialog\n"
49 << "// This file is automatically generated, do not edit\n\n";
51 QtUiStyleSettings fs("Fonts");
52 QFont font = fs.value("ChatView").value<QFont>();
53 QString desc = "font: ";
58 if(!font.italic() && !font.bold())
60 desc += QString("%1pt \"%2\"").arg(font.pointSize()).arg(font.family());
62 out << "// ChatView Font\n\n"
63 << "ChatLine { " << desc << "; }\n\n";
65 QtUiStyleSettings s("Colors");
66 if(s.value("UseChatViewColors").toBool()) {
67 out << "// Custom ChatView Colors\n\n"
69 << "Palette { marker-line: " << color("MarkerLine", s) << "; }\n"
70 << "ChatView { background: " << color("ChatViewBackground", s) << "; }\n\n"
71 << "ChatLine[label=\"highlight\"] {\n"
72 << " foreground: " << color("Highlight",s) << ";\n"
73 << " background: " << color("HighlightBackground", s) << ";\n"
75 << "ChatLine::timestamp { foreground: " << color("Timestamp", s) << "; }\n\n"
77 << msgTypeQss("plain", "ChannelMsg", s)
78 << msgTypeQss("notice", "ServerMsg", s)
79 << msgTypeQss("action", "ActionMsg", s)
80 << msgTypeQss("nick", "CommandMsg", s)
81 << msgTypeQss("mode", "CommandMsg", s)
82 << msgTypeQss("join", "CommandMsg", s)
83 << msgTypeQss("part", "CommandMsg", s)
84 << msgTypeQss("quit", "CommandMsg", s)
85 << msgTypeQss("kick", "CommandMsg", s)
86 << msgTypeQss("kill", "CommandMsg", s)
87 << msgTypeQss("server", "ServerMsg", s)
88 << msgTypeQss("info", "ServerMsg", s)
89 << msgTypeQss("error", "ErrorMsg", s)
90 << msgTypeQss("daychange", "ServerMsg", s)
94 if(s.value("UseSenderColors").toBool()) {
95 out << "// Sender Colors\n\n"
96 << "ChatLine::sender[sender=\"self\"] { foreground: " << color("SenderSelf", s) << "; }\n\n";
98 for(int i = 0; i < 16; i++)
99 out << senderQss(i, s);
105 QString QtUiStyle::color(const QString &key, QtUiStyleSettings &settings) const {
106 return settings.value(key).value<QColor>().name();
109 QString QtUiStyle::msgTypeQss(const QString &msgType, const QString &key, QtUiStyleSettings &settings) const {
110 return QString("ChatLine#%1 { foreground: %2; }\n").arg(msgType, color(key, settings));
113 QString QtUiStyle::senderQss(int i, QtUiStyleSettings &settings) const {
114 QString dez = QString::number(i);
115 if(dez.length() == 1) dez.prepend('0');
117 return QString("ChatLine::sender[sender=\"0%1\"] { foreground: %2; }\n").arg(QString::number(i, 16), color("Sender"+dez, settings));