1
/*****************************************************************
3
Copyright (c) 1996-2000 the kicker authors. See file AUTHORS.
5
Permission is hereby granted, free of charge, to any person obtaining a copy
6
of this software and associated documentation files (the "Software"), to deal
7
in the Software without restriction, including without limitation the rights
8
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
copies of the Software, and to permit persons to whom the Software is
10
furnished to do so, subject to the following conditions:
12
The above copyright notice and this permission notice shall be included in
13
all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
******************************************************************/
24
#include <QApplication>
27
#include <QDesktopWidget>
31
#include <kiconeffect.h>
32
#include <kiconloader.h>
33
#include <kio/netaccess.h>
34
#include <kstandarddirs.h>
38
#include "kickerSettings.h"
43
Position arrowToDirection(Qt::ArrowType p)
62
Position popupDirectionForPosition(Position p)
79
return Right; // FIXME?
81
return Right; //FIXME ?
84
int sizeValue(Plasma::Size s)
88
case Plasma::SizeTiny:
91
case Plasma::SizeSmall:
94
case Plasma::SizeNormal:
97
case Plasma::SizeLarge:
105
return (2 * KickerSettings::iconMargin()) + K3Icon::SizeLarge;
108
QString newDesktopFile(const KUrl& url)
110
QString base = url.fileName();
111
if (base.endsWith(".desktop"))
112
base.truncate(base.length()-8);
113
QRegExp r("(.*)(?=-\\d+)");
114
if (r.indexIn(base) > -1)
117
QString file = base + ".desktop";
119
for(int n = 1; ++n; )
121
QString path = KStandardDirs::locate("appdata", file);
125
file = QString("%2-%1.desktop").arg(n).arg(base);
127
file = KStandardDirs::locateLocal("appdata", file);
131
QString copyDesktopFile(const KUrl& url)
133
QString file = newDesktopFile(url);
136
KIO::NetAccess::upload(url.path(), dest, 0);
140
QMenu* reduceMenu(QMenu *menu)
142
if (menu->actions().count() != 1)
147
QAction *act = menu->actions().value(0);
151
return reduceMenu(act->menu());
157
QPoint popupPosition(Plasma::Position d,
158
const QWidget* popup,
159
const QWidget* source,
160
const QPoint& offset)
163
if (source->isTopLevel())
165
r = source->geometry();
169
r = QRect(source->mapToGlobal(QPoint(0, 0)),
170
source->mapToGlobal(QPoint(source->width(), source->height())));
176
r.setLeft( source->topLevelWidget()->x() );
177
r.setWidth( source->topLevelWidget()->width() );
181
r.setTop( source->topLevelWidget()->y() );
182
r.setHeight( source->topLevelWidget()->height() );
185
//badbadbad - should never happen
195
QDesktopWidget* desktop = QApplication::desktop();
196
QRect screen = desktop->screenGeometry(desktop->screenNumber(const_cast<QWidget*>(source)));
197
int x = (d == Plasma::Left) ? r.left() - popup->width() :
199
int y = r.top() + offset.y();
201
// try to keep this on screen
202
if (y + popup->height() > screen.bottom())
204
y = r.bottom() - popup->height() + offset.y();
206
if (y < screen.top())
208
y = screen.bottom() - popup->height();
210
if (y < screen.top())
224
int y = (d == Plasma::Up) ? r.top() - popup->height() :
227
if (QApplication::isRightToLeft())
229
x = r.right() - popup->width() + 1;
233
x -= r.width() - offset.x();
236
// try to keep this on the screen
237
if (x - popup->width() < 0)
246
QDesktopWidget* desktop = QApplication::desktop();
247
QRect screen = desktop->screenGeometry(desktop->screenNumber(const_cast<QWidget*>(source)));
248
x = r.left() + offset.x();
250
// try to keep this on the screen
251
if (x + popup->width() > screen.right())
253
x = r.right() - popup->width() + 1 + offset.x();
255
if (x < screen.left())
267
void colorize(QImage& image)
269
KConfigGroup config(KGlobal::config(), "WM");
270
QPalette pal = QApplication::palette();
271
pal.setCurrentColorGroup( QPalette::Active );
272
QColor color = pal.color( QPalette::Highlight );
273
QColor activeTitle = config.readEntry("activeBackground", color);
274
QColor inactiveTitle = config.readEntry("inactiveBackground", color);
276
// figure out which color is most suitable for recoloring to
277
int h1, s1, v1, h2, s2, v2, h3, s3, v3;
278
activeTitle.getHsv(&h1, &s1, &v1);
279
inactiveTitle.getHsv(&h2, &s2, &v2);
280
QApplication::palette().color(QPalette::Active, QPalette::Window).getHsv(&h3, &s3, &v3);
282
if ( (qAbs(h1-h3)+qAbs(s1-s3)+qAbs(v1-v3) < qAbs(h2-h3)+qAbs(s2-s3)+qAbs(v2-v3)) &&
283
((qAbs(h1-h3)+qAbs(s1-s3)+qAbs(v1-v3) < 32) || (s1 < 32)) && (s2 > s1))
284
color = inactiveTitle;
288
// limit max/min brightness
290
color.getRgb(&r, &g, &b);
291
int gray = qGray(r, g, b);
293
r = (r - (gray - 180) < 0 ? 0 : r - (gray - 180));
294
g = (g - (gray - 180) < 0 ? 0 : g - (gray - 180));
295
b = (b - (gray - 180) < 0 ? 0 : b - (gray - 180));
296
} else if (gray < 76) {
297
r = (r + (76 - gray) > 255 ? 255 : r + (76 - gray));
298
g = (g + (76 - gray) > 255 ? 255 : g + (76 - gray));
299
b = (b + (76 - gray) > 255 ? 255 : b + (76 - gray));
301
color.setRgb(r, g, b);
302
KIconEffect::colorize(image, color, 1.0);
305
QColor blendColors(const QColor& c1, const QColor& c2)
310
c1.getRgb(&r1, &g1, &b1);
311
c2.getRgb(&r2, &g2, &b2);
313
r1 += (int) (.5 * (r2 - r1));
314
g1 += (int) (.5 * (g2 - g1));
315
b1 += (int) (.5 * (b2 - b1));
317
return QColor(r1, g1, b1);
320
QColor shadowColor(const QColor& c)
341
return QColor( r, g, b );
344
QIcon menuIconSet(const QString& icon)
347
int iconSize = KickerSettings::menuEntryHeight();
350
iconset = KIconLoader::global()->loadIconSet(icon,
354
else if (iconSize == 0)
356
QPixmap normal = KIconLoader::global()->loadIcon(icon,
359
K3Icon::DefaultState,
363
QPixmap active = KIconLoader::global()->loadIcon(icon,
369
// make sure they are not larger than 20x20
370
if (normal.width() > 20 || normal.height() > 20)
372
normal = normal.scaled(20,20, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
375
if (active.width() > 20 || active.height() > 20)
377
active = active.scaled(20,20, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
380
iconset.addPixmap(normal, QIcon::Normal, QIcon::On);
381
iconset.addPixmap(active, QIcon::Active, QIcon::Off);