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";
53 QtUiStyleSettings fs("Fonts");
54 if(fs.value("UseCustomChatViewFont").toBool())
55 out << "\n// ChatView Font\n"
56 << "ChatLine { " << fontDescription(fs.value("ChatView").value<QFont>()) << "; }\n";
58 QtUiStyleSettings s("Colors");
59 if(s.value("UseChatViewColors").toBool()) {
60 out << "\n// Custom ChatView Colors\n"
62 << "Palette { marker-line: " << color("MarkerLine", s) << "; }\n"
63 << "ChatView { background: " << color("ChatViewBackground", s) << "; }\n\n"
64 << "ChatLine[label=\"highlight\"] {\n"
65 << " foreground: " << color("Highlight",s) << ";\n"
66 << " background: " << color("HighlightBackground", s) << ";\n"
68 << "ChatLine::timestamp { foreground: " << color("Timestamp", s) << "; }\n\n"
70 << msgTypeQss("plain", "ChannelMsg", s)
71 << msgTypeQss("notice", "ServerMsg", s)
72 << msgTypeQss("action", "ActionMsg", s)
73 << msgTypeQss("nick", "CommandMsg", s)
74 << msgTypeQss("mode", "CommandMsg", s)
75 << msgTypeQss("join", "CommandMsg", s)
76 << msgTypeQss("part", "CommandMsg", s)
77 << msgTypeQss("quit", "CommandMsg", s)
78 << msgTypeQss("kick", "CommandMsg", s)
79 << msgTypeQss("kill", "CommandMsg", s)
80 << msgTypeQss("server", "ServerMsg", s)
81 << msgTypeQss("info", "ServerMsg", s)
82 << msgTypeQss("error", "ErrorMsg", s)
83 << msgTypeQss("daychange", "ServerMsg", s)
84 << msgTypeQss("topic", "CommandMsg", s)
85 << msgTypeQss("netsplit-join", "CommandMsg", s)
86 << msgTypeQss("netsplit-quit", "CommandMsg", s)
90 if(s.value("UseSenderColors").toBool()) {
91 out << "\n// Sender Colors\n"
92 << "ChatLine::sender#plain[sender=\"self\"] { foreground: " << color("SenderSelf", s) << "; }\n\n";
94 for(int i = 0; i < 16; i++)
95 out << senderQss(i, s);
101 UiStyleSettings uiFonts("Fonts");
102 if(uiFonts.value("UseCustomItemViewFont").toBool()) {
103 QString fontDesc = fontDescription(uiFonts.value("ItemView").value<QFont>());
104 out << "\n// ItemView Font\n"
105 << "ChatListItem { " << fontDesc << "; }\n"
106 << "NickListItem { " << fontDesc << "; }\n\n";
109 UiStyleSettings uiColors("Colors");
110 if(uiColors.value("UseBufferViewColors").toBool()) {
111 out << "\n// BufferView Colors\n"
112 << "ChatListItem { foreground: " << color("DefaultBuffer", uiColors) << "; }\n"
113 << chatListItemQss("inactive", "InactiveBuffer", uiColors)
114 << chatListItemQss("channel-event", "ActiveBuffer", uiColors)
115 << chatListItemQss("unread-message", "UnreadBuffer", uiColors)
116 << chatListItemQss("highlighted", "HighlightedBuffer", uiColors);
119 if(uiColors.value("UseNickViewColors").toBool()) {
120 out << "\n// NickView Colors\n"
121 << "NickListItem[type=\"category\"] { foreground: " << color("DefaultBuffer", uiColors) << "; }\n"
122 << "NickListItem[type=\"user\"] { foreground: " << color("OnlineNick", uiColors) << "; }\n"
123 << "NickListItem[type=\"user\", state=\"away\"] { foreground: " << color("AwayNick", uiColors) << "; }\n";
129 QString QtUiStyle::color(const QString &key, UiSettings &settings) const {
130 return settings.value(key).value<QColor>().name();
133 QString QtUiStyle::fontDescription(const QFont &font) const {
134 QString desc = "font: ";
139 if(!font.italic() && !font.bold())
141 desc += QString("%1pt \"%2\"").arg(font.pointSize()).arg(font.family());
145 QString QtUiStyle::msgTypeQss(const QString &msgType, const QString &key, UiSettings &settings) const {
146 return QString("ChatLine#%1 { foreground: %2; }\n").arg(msgType, color(key, settings));
149 QString QtUiStyle::senderQss(int i, UiSettings &settings) const {
150 QString dez = QString::number(i);
151 if(dez.length() == 1) dez.prepend('0');
153 return QString("ChatLine::sender#plain[sender=\"0%1\"] { foreground: %2; }\n").arg(QString::number(i, 16), color("Sender"+dez, settings));
156 QString QtUiStyle::chatListItemQss(const QString &state, const QString &key, UiSettings &settings) const {
157 return QString("ChatListItem[state=\"%1\"] { foreground: %2; }\n").arg(state, color(key, settings));