2
* Copyright 2008 by Petri Damsten <damu@iki.fi>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Library General Public License as
6
* published by the Free Software Foundation; either version 2, or
7
* (at your option) any later version.
9
* This program 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
12
* GNU General Public License for more details
14
* You should have received a copy of the GNU Library General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
#include <QLinearGradient>
24
#include <QRadialGradient>
37
Color::Color(QObject *parent, const QVariantList &args)
38
: Plasma::Wallpaper(parent, args)
42
void Color::init(const KConfigGroup &config)
44
m_color1 = config.readEntry("color1", QColor(Qt::white));
45
m_color2 = config.readEntry("color2", QColor(Qt::black));
46
m_backgroundMode = config.readEntry("backgroundMode", (int)SOLID);
47
emit update(boundingRect());
50
void Color::paint(QPainter *painter, const QRectF& exposedRect)
52
switch (m_backgroundMode) {
54
painter->fillRect(exposedRect, m_color1);
59
QLinearGradient gradient = QLinearGradient(boundingRect().topLeft(),
60
boundingRect().topRight());
61
gradient.setColorAt(0, m_color1);
62
gradient.setColorAt(1, m_color2);
63
painter->fillRect(exposedRect, gradient);
68
QLinearGradient gradient = QLinearGradient(boundingRect().topLeft(),
69
boundingRect().bottomLeft());
70
gradient.setColorAt(0, m_color1);
71
gradient.setColorAt(1, m_color2);
72
painter->fillRect(exposedRect, gradient);
77
// First draw a horizontal gradient covering the whole view/screen
78
QLinearGradient horizontalGradient = QLinearGradient(boundingRect().topLeft(),
79
boundingRect().topRight());
80
horizontalGradient.setColorAt(0, m_color2);
81
horizontalGradient.setColorAt(0.5, m_color1);
82
horizontalGradient.setColorAt(1, m_color2);
84
painter->fillRect(exposedRect, horizontalGradient);
86
// Then draw two triangles with vertical gradient
87
QLinearGradient verticalGradient = QLinearGradient(boundingRect().topLeft(),
88
boundingRect().bottomLeft());
89
verticalGradient.setColorAt(0, m_color2);
90
verticalGradient.setColorAt(0.5, m_color1);
91
verticalGradient.setColorAt(1, m_color2);
92
painter->setBrush(verticalGradient);
93
painter->setPen(Qt::NoPen);
95
QPolygon triangle = QPolygon(3);
97
// Draw a triangle which starts from the top edge to the center
98
triangle.append(boundingRect().topLeft().toPoint());
99
triangle.append(boundingRect().topRight().toPoint());
100
triangle.append(boundingRect().center().toPoint());
101
painter->drawPolygon(triangle);
105
// Draw a triangle which starts from the bottom edge to the center
106
triangle.append(boundingRect().bottomLeft().toPoint());
107
triangle.append(boundingRect().bottomRight().toPoint());
108
triangle.append(boundingRect().center().toPoint());
109
painter->drawPolygon(triangle);
115
// The diameter of the gradient will be the max screen dimension
116
int maxDimension = qMax(boundingRect().height(), boundingRect().width());
118
QRadialGradient gradient = QRadialGradient(boundingRect().center(),
120
boundingRect().center());
121
gradient.setColorAt(0, m_color1);
122
gradient.setColorAt(1, m_color2);
123
painter->fillRect(exposedRect, gradient);
127
case TOP_LEFT_DIAGONAL: {
128
QLinearGradient gradient = QLinearGradient(boundingRect().topLeft(),
129
boundingRect().bottomRight());
130
gradient.setColorAt(0, m_color1);
131
gradient.setColorAt(1, m_color2);
132
painter->fillRect(exposedRect, gradient);
136
case TOP_RIGHT_DIAGONAL: {
137
QLinearGradient gradient = QLinearGradient(boundingRect().topRight(),
138
boundingRect().bottomLeft());
139
gradient.setColorAt(0, m_color1);
140
gradient.setColorAt(1, m_color2);
141
painter->fillRect(exposedRect, gradient);
148
QWidget* Color::createConfigurationInterface(QWidget* parent)
150
QWidget *widget = new QWidget(parent);
151
m_ui.setupUi(widget);
153
m_ui.m_color1->setColor(m_color1);
154
m_ui.m_color2->setColor(m_color2);
155
m_ui.m_backgroundMode->setCurrentIndex(m_backgroundMode);
157
if (m_backgroundMode == SOLID) {
158
m_ui.m_color2->setEnabled(false);
160
m_ui.m_color2->setEnabled(true);
163
connect(m_ui.m_color1, SIGNAL(changed(const QColor&)), this, SLOT(settingsModified()));
164
connect(m_ui.m_color2, SIGNAL(changed(const QColor&)), this, SLOT(settingsModified()));
165
connect(m_ui.m_backgroundMode, SIGNAL(currentIndexChanged(int)), this, SLOT(settingsModified()));
167
connect(this, SIGNAL(settingsChanged(bool)), parent, SLOT(settingsChanged(bool)));
172
void Color::save(KConfigGroup &config)
174
config.writeEntry("color1", m_color1);
175
config.writeEntry("color2", m_color2);
176
config.writeEntry("backgroundMode", m_backgroundMode);
179
void Color::settingsModified()
181
m_color1 = m_ui.m_color1->color();
182
m_color2 = m_ui.m_color2->color();
183
m_backgroundMode = m_ui.m_backgroundMode->currentIndex();
185
if (m_backgroundMode == SOLID) {
186
m_ui.m_color2->setEnabled(false);
188
m_ui.m_color2->setEnabled(true);
191
emit settingsChanged(true);
192
emit update(boundingRect());