2
Copyright 2009 by Sebastian Kügler <sebas@kde.org>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
20
#include "stylesheet.h"
28
#include <KGlobalSettings>
29
#include <KStandardDirs>
32
#include <Plasma/Theme>
35
using namespace Plasma;
37
StyleSheet::StyleSheet(QObject *parent)
40
//m_cssFile = "/home/sebas/kdesvn/src/attica/plasma/opendesktop/user.css"; // For debugging quicker
41
m_cssFile = KStandardDirs::locate("data", "plasma-applet-opendesktop/user.css");
43
m_cssWatch = new KDirWatch(this);
44
m_cssWatch->addFile(m_cssFile);
45
connect(m_cssWatch,SIGNAL(dirty(QString)),this,SLOT(load(QString)));
46
connect(m_cssWatch,SIGNAL(created(QString)),this,SLOT(load(QString)));
47
connect(m_cssWatch,SIGNAL(deleted(QString)),this,SLOT(load(QString)));
49
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(update()));
50
connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), SLOT(update()));
53
StyleSheet::~StyleSheet()
57
QString StyleSheet::styleSheet() const
62
void StyleSheet::setFileName(const QString &cssFile)
64
if (m_cssFile != cssFile) {
65
// change watch file watch and load new CSS ...
66
m_cssWatch->removeFile(m_cssFile);
69
m_cssWatch->addFile(m_cssFile);
73
void StyleSheet::setStyleSheet(const QString &css)
75
m_rawStyleSheet = css;
79
void StyleSheet::load(const QString &cssFile)
83
if (cssFile.isEmpty()) {
84
f.setFileName(m_cssFile);
86
f.setFileName(cssFile);
88
kDebug() << "(Re)loading CSS" << cssFile;
89
if (f.open(QIODevice::ReadOnly)) {
91
m_rawStyleSheet = t.readAll();
95
kDebug() << "CSS File not loaded, error reading file";
99
void StyleSheet::update()
101
QPalette p = QPalette();
103
QColor text = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
104
QColor link = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
105
QColor background = Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor);
106
link.setAlphaF(qreal(.8));
107
QColor linkvisited = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
108
linkvisited.setAlphaF(qreal(.6));
110
m_colors["%textcolor"] = text.name();
111
m_colors["%background"] = background.name();
112
m_colors["%visitedlink"] = linkvisited.name();
113
m_colors["%activatedlink"] = linkvisited.name();
114
m_colors["%hoveredlink"] = linkvisited.name();
115
m_colors["%link"] = link.name();
116
m_colors["%smallfontsize"] = QString("%1pt").arg(KGlobalSettings::smallestReadableFont().pointSize());
117
m_colors["%fontsize"] = QString("%1pt").arg(KGlobalSettings::generalFont().pointSize());
119
m_styleSheet = m_rawStyleSheet;
120
foreach(const QString &k, m_colors.keys()) {
121
m_styleSheet.replace(k, m_colors[k]);
123
//kDebug() << "CSS:" << m_styleSheet;
125
emit styleSheetChanged(m_styleSheet);
128
#include "stylesheet.moc"