1 /***************************************************************************
2 * Copyright (C) 2005-2016 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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "chatviewsettings.h"
22 #include "qtuistyle.h"
25 #include <QTextStream>
27 QtUiStyle::QtUiStyle(QObject *parent) : UiStyle(parent)
30 s.notify("TimestampFormat", this, SLOT(updateTimestampFormatString()));
31 updateTimestampFormatString();
32 s.notify("ShowSenderBrackets", this, SLOT(updateShowSenderBrackets()));
33 updateShowSenderBrackets();
37 QtUiStyle::~QtUiStyle() {}
39 void QtUiStyle::updateTimestampFormatString()
42 setTimestampFormatString(s.timestampFormatString());
45 void QtUiStyle::updateShowSenderBrackets()
48 enableSenderBrackets(s.showSenderBrackets());
52 void QtUiStyle::generateSettingsQss() const
54 QFile settingsQss(Quassel::configDirPath() + "settings.qss");
55 if (!settingsQss.open(QFile::WriteOnly|QFile::Truncate)) {
56 qWarning() << "Could not open" << settingsQss.fileName() << "for writing!";
59 QTextStream out(&settingsQss);
61 out << "// Style settings made in Quassel's configuration dialog\n"
62 << "// This file is automatically generated, do not edit\n";
66 QtUiStyleSettings fs("Fonts");
67 if (fs.value("UseCustomChatViewFont").toBool())
68 out << "\n// ChatView Font\n"
69 << "ChatLine { " << fontDescription(fs.value("ChatView").value<QFont>()) << "; }\n";
71 QtUiStyleSettings s("Colors");
72 if (s.value("UseChatViewColors").toBool()) {
73 out << "\n// Custom ChatView Colors\n"
75 // markerline is special in that it always used to use a gradient, so we keep this behavior even with the new implementation
76 << "Palette { marker-line: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 " << color("MarkerLine", s) << ", stop: 0.1 transparent); }\n"
77 << "ChatView { background: " << color("ChatViewBackground", s) << "; }\n\n"
78 << "ChatLine[label=\"highlight\"] {\n"
79 << " foreground: " << color("Highlight", s) << ";\n"
80 << " background: " << color("HighlightBackground", s) << ";\n"
82 << "ChatLine::timestamp { foreground: " << color("Timestamp", s) << "; }\n\n"
84 << msgTypeQss("plain", "ChannelMsg", s)
85 << msgTypeQss("notice", "ServerMsg", s)
86 << msgTypeQss("action", "ActionMsg", s)
87 << msgTypeQss("nick", "CommandMsg", s)
88 << msgTypeQss("mode", "CommandMsg", s)
89 << msgTypeQss("join", "CommandMsg", s)
90 << msgTypeQss("part", "CommandMsg", s)
91 << msgTypeQss("quit", "CommandMsg", s)
92 << msgTypeQss("kick", "CommandMsg", s)
93 << msgTypeQss("kill", "CommandMsg", s)
94 << msgTypeQss("server", "ServerMsg", s)
95 << msgTypeQss("info", "ServerMsg", s)
96 << msgTypeQss("error", "ErrorMsg", s)
97 << msgTypeQss("daychange", "ServerMsg", s)
98 << msgTypeQss("topic", "CommandMsg", s)
99 << msgTypeQss("netsplit-join", "CommandMsg", s)
100 << msgTypeQss("netsplit-quit", "CommandMsg", s)
101 << msgTypeQss("invite", "CommandMsg", s)
105 if (s.value("UseSenderColors").toBool()) {
106 out << "\n// Sender Colors\n"
107 << "ChatLine::sender#plain[sender=\"self\"] { foreground: " << color("SenderSelf", s) << "; }\n\n";
109 // Matches qssparser.cpp for UiStyle::PlainMsg
110 for (int i = 0; i < 16; i++)
111 out << senderQss(i, s, "plain");
113 // Only color the nicks in CTCP ACTIONs if sender colors are enabled
114 if (s.value("UseSenderActionColors").toBool()) {
115 // For action messages, color the 'sender' column -and- the nick itself
116 out << "\n// Sender Nickname Colors for action messages\n"
117 << "ChatLine::sender#action[sender=\"self\"] { foreground: " << color("SenderSelf", s) << "; }\n"
118 << "ChatLine::nick#action[sender=\"self\"] { foreground: " << color("SenderSelf", s) << "; }\n\n";
120 // Matches qssparser.cpp for UiStyle::ActionMsg
121 for (int i = 0; i < 16; i++)
122 out << senderQss(i, s, "action", true);
129 UiStyleSettings uiFonts("Fonts");
130 if (uiFonts.value("UseCustomItemViewFont").toBool()) {
131 QString fontDesc = fontDescription(uiFonts.value("ItemView").value<QFont>());
132 out << "\n// ItemView Font\n"
133 << "ChatListItem { " << fontDesc << "; }\n"
134 << "NickListItem { " << fontDesc << "; }\n\n";
137 UiStyleSettings uiColors("Colors");
138 if (uiColors.value("UseBufferViewColors").toBool()) {
139 out << "\n// BufferView Colors\n"
140 << "ChatListItem { foreground: " << color("DefaultBuffer", uiColors) << "; }\n"
141 << chatListItemQss("inactive", "InactiveBuffer", uiColors)
142 << chatListItemQss("channel-event", "ActiveBuffer", uiColors)
143 << chatListItemQss("unread-message", "UnreadBuffer", uiColors)
144 << chatListItemQss("highlighted", "HighlightedBuffer", uiColors);
147 if (uiColors.value("UseNickViewColors").toBool()) {
148 out << "\n// NickView Colors\n"
149 << "NickListItem[type=\"category\"] { foreground: " << color("DefaultBuffer", uiColors) << "; }\n"
150 << "NickListItem[type=\"user\"] { foreground: " << color("OnlineNick", uiColors) << "; }\n"
151 << "NickListItem[type=\"user\", state=\"away\"] { foreground: " << color("AwayNick", uiColors) << "; }\n";
158 QString QtUiStyle::color(const QString &key, UiSettings &settings) const
160 return settings.value(key).value<QColor>().name();
164 QString QtUiStyle::fontDescription(const QFont &font) const
166 QString desc = "font: ";
171 if (!font.italic() && !font.bold())
173 desc += QString("%1pt \"%2\"").arg(font.pointSize()).arg(font.family());
178 QString QtUiStyle::msgTypeQss(const QString &msgType, const QString &key, UiSettings &settings) const
180 return QString("ChatLine#%1 { foreground: %2; }\n").arg(msgType, color(key, settings));
184 QString QtUiStyle::senderQss(int i, UiSettings &settings, const QString &messageType, bool includeNick) const
186 QString dez = QString::number(i);
187 if (dez.length() == 1) dez.prepend('0');
190 // Include the nickname in the color rules
191 return QString("ChatLine::sender#%1[sender=\"0%2\"] { foreground: %3; }\n"
192 "ChatLine::nick#%1[sender=\"0%2\"] { foreground: %3; }\n")
193 .arg(messageType, QString::number(i, 16), color("Sender"+dez, settings));
195 return QString("ChatLine::sender#%1[sender=\"0%2\"] { foreground: %3; }\n")
196 .arg(messageType, QString::number(i, 16), color("Sender"+dez, settings));
201 QString QtUiStyle::chatListItemQss(const QString &state, const QString &key, UiSettings &settings) const
203 return QString("ChatListItem[state=\"%1\"] { foreground: %2; }\n").arg(state, color(key, settings));