~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/desktopchangeosd.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************
 
2
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 2009 Martin Gräßlin <kde@martin-graesslin.com>
 
6
 
 
7
This program is free software; you can redistribute it and/or modify
 
8
it under the terms of the GNU General Public License as published by
 
9
the Free Software Foundation; either version 2 of the License, or
 
10
(at your option) any later version.
 
11
 
 
12
This program is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
GNU General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU General Public License
 
18
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
*********************************************************************/
 
20
 
 
21
 
 
22
#include "desktopchangeosd.h"
 
23
#include <QTextStream>
 
24
#include "workspace.h"
 
25
 
 
26
#include <X11/extensions/shape.h>
 
27
 
 
28
#include <QDebug>
 
29
#include <QEasingCurve>
 
30
#include <QPropertyAnimation>
 
31
#include <QHash>
 
32
#include <QGraphicsScene>
 
33
#include <QRect>
 
34
#include <KDE/Plasma/Theme>
 
35
#include <KDE/Plasma/PaintUtils>
 
36
#include <kiconloader.h>
 
37
 
 
38
namespace KWin
 
39
{
 
40
 
 
41
DesktopChangeOSD::DesktopChangeOSD(Workspace* ws)
 
42
    : QGraphicsView()
 
43
    , m_wspace(ws)
 
44
    , m_scene(0)
 
45
    , m_active(false)
 
46
    , m_show(false)
 
47
    , m_delayTime(0)
 
48
    , m_textOnly(false)
 
49
{
 
50
    setWindowFlags(Qt::X11BypassWindowManagerHint);
 
51
    setFrameStyle(QFrame::NoFrame);
 
52
    viewport()->setAutoFillBackground(false);
 
53
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 
54
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 
55
    setAttribute(Qt::WA_TranslucentBackground);
 
56
    m_frame.setImagePath("dialogs/background");
 
57
    m_frame.setCacheAllRenderedFrames(true);
 
58
    m_frame.setEnabledBorders(Plasma::FrameSvg::AllBorders);
 
59
 
 
60
    m_item_frame.setImagePath("widgets/pager");
 
61
    m_item_frame.setCacheAllRenderedFrames(true);
 
62
    m_item_frame.setEnabledBorders(Plasma::FrameSvg::AllBorders);
 
63
 
 
64
    m_delayedHideTimer.setSingleShot(true);
 
65
    connect(&m_delayedHideTimer, SIGNAL(timeout()), this, SLOT(hide()));
 
66
 
 
67
    m_scene = new QGraphicsScene(0);
 
68
    setScene(m_scene);
 
69
 
 
70
    reconfigure();
 
71
 
 
72
    m_scene->addItem(new DesktopChangeText(m_wspace));
 
73
}
 
74
 
 
75
DesktopChangeOSD::~DesktopChangeOSD()
 
76
{
 
77
    delete m_scene;
 
78
}
 
79
 
 
80
void DesktopChangeOSD::reconfigure()
 
81
{
 
82
    KSharedConfigPtr c(KGlobal::config());
 
83
    const KConfigGroup cg = c->group("PopupInfo");
 
84
    m_show = cg.readEntry("ShowPopup", false);
 
85
    m_delayTime = cg.readEntry("PopupHideDelay", 1000);
 
86
    m_textOnly = cg.readEntry("TextOnly", false);
 
87
    numberDesktopsChanged();
 
88
}
 
89
 
 
90
void DesktopChangeOSD::desktopChanged(int old)
 
91
{
 
92
    if (!m_show)
 
93
        return;
 
94
    // we have to stop in case the old desktop does not exist anymore
 
95
    if (old > m_wspace->numberOfDesktops())
 
96
        return;
 
97
    // calculate where icons have to be shown
 
98
    QPoint diff = m_wspace->desktopGridCoords(m_wspace->currentDesktop()) - m_wspace->desktopGridCoords(old);
 
99
    QHash< int, DesktopChangeItem::Arrow > hash = QHash< int, DesktopChangeItem::Arrow>();
 
100
    int desktop = old;
 
101
    int target = m_wspace->currentDesktop();
 
102
    int x = diff.x();
 
103
    int y = diff.y();
 
104
    if (y >= 0) {
 
105
        // first go in x direction, then in y
 
106
        while (desktop != target) {
 
107
            if (x != 0) {
 
108
                if (x < 0) {
 
109
                    x++;
 
110
                    hash.insert(desktop, DesktopChangeItem::LEFT);
 
111
                    desktop = m_wspace->desktopToLeft(desktop);
 
112
                } else {
 
113
                    x--;
 
114
                    hash.insert(desktop, DesktopChangeItem::RIGHT);
 
115
                    desktop = m_wspace->desktopToRight(desktop);
 
116
                }
 
117
                continue;
 
118
            }
 
119
            y--;
 
120
            hash.insert(desktop, DesktopChangeItem::DOWN);
 
121
            desktop = m_wspace->desktopBelow(desktop);
 
122
        }
 
123
    } else {
 
124
        // first go in y direction, then in x
 
125
        while (target != desktop) {
 
126
            if (y != 0) {
 
127
                // only go upward
 
128
                y++;
 
129
                hash.insert(desktop, DesktopChangeItem::UP);
 
130
                desktop = m_wspace->desktopAbove(desktop);
 
131
                continue;
 
132
            }
 
133
            if (x != 0) {
 
134
                if (x < 0) {
 
135
                    x++;
 
136
                    hash.insert(desktop, DesktopChangeItem::LEFT);
 
137
                    desktop = m_wspace->desktopToLeft(desktop);
 
138
                } else {
 
139
                    x--;
 
140
                    hash.insert(desktop, DesktopChangeItem::RIGHT);
 
141
                    desktop = m_wspace->desktopToRight(desktop);
 
142
                }
 
143
            }
 
144
        }
 
145
    }
 
146
    // now we know which desktop has to show an arrow -> set the arrow for each desktop
 
147
    int numberOfArrows = qAbs(diff.x()) + qAbs(diff.y());
 
148
    foreach (QGraphicsItem * it, m_scene->items()) {
 
149
        DesktopChangeItem* item = qgraphicsitem_cast< DesktopChangeItem* >(it);
 
150
        if (item) {
 
151
            if (hash.contains(item->desktop())) {
 
152
                QPoint distance = m_wspace->desktopGridCoords(m_wspace->currentDesktop())
 
153
                                  - m_wspace->desktopGridCoords(item->desktop());
 
154
                int desktopDistance = numberOfArrows - (qAbs(distance.x()) + qAbs(distance.y()));
 
155
                int start = m_delayTime / numberOfArrows * desktopDistance - m_delayTime * 0.15f;
 
156
                int stop = m_delayTime / numberOfArrows * (desktopDistance + 1) + m_delayTime * 0.15f;
 
157
                start = qMax(start, 0);
 
158
                item->setArrow(hash[ item->desktop()], start, stop);
 
159
            } else {
 
160
                item->setArrow(DesktopChangeItem::NONE, 0, 0);
 
161
            }
 
162
            if (old != m_wspace->currentDesktop()) {
 
163
                if (item->desktop() == m_wspace->currentDesktop())
 
164
                    item->startDesktopHighLightAnimation(m_delayTime * 0.33);
 
165
                if (m_active && item->desktop() == old)
 
166
                    item->stopDesktopHighLightAnimation();
 
167
            }
 
168
        }
 
169
    }
 
170
    if (m_active) {
 
171
        // for text only we need to resize
 
172
        if (m_textOnly)
 
173
            resize();
 
174
        // already active - just update and reset timer
 
175
        update();
 
176
    } else {
 
177
        m_active = true;
 
178
        resize();
 
179
        show();
 
180
        raise();
 
181
    }
 
182
    // Set a zero inputmask, effectively making clicks go "through" the popup
 
183
    // For those who impatiently wait to click on a dialog behind the it
 
184
    XShapeCombineRectangles(display(), winId(), ShapeInput, 0, 0, NULL, 0, ShapeSet, Unsorted);
 
185
    m_delayedHideTimer.start(m_delayTime);
 
186
}
 
187
 
 
188
void DesktopChangeOSD::hideEvent(QHideEvent*)
 
189
{
 
190
    m_delayedHideTimer.stop();
 
191
    m_active = false;
 
192
}
 
193
 
 
194
void DesktopChangeOSD::drawBackground(QPainter* painter, const QRectF& rect)
 
195
{
 
196
    painter->save();
 
197
    painter->setCompositionMode(QPainter::CompositionMode_Source);
 
198
    qreal left, top, right, bottom;
 
199
    m_frame.getMargins(left, top, right, bottom);
 
200
    m_frame.paintFrame(painter, rect.adjusted(-left, -top, right, bottom));
 
201
    painter->restore();
 
202
}
 
203
 
 
204
void DesktopChangeOSD::numberDesktopsChanged()
 
205
{
 
206
    foreach (QGraphicsItem * it, m_scene->items()) {
 
207
        DesktopChangeItem* item = qgraphicsitem_cast<DesktopChangeItem*>(it);
 
208
        if (item) {
 
209
            m_scene->removeItem(item);
 
210
        }
 
211
    }
 
212
 
 
213
    if (!m_textOnly) {
 
214
        for (int i = 1; i <= m_wspace->numberOfDesktops(); i++) {
 
215
            DesktopChangeItem* item = new DesktopChangeItem(m_wspace, this, i);
 
216
            m_scene->addItem(item);
 
217
        }
 
218
    }
 
219
}
 
220
 
 
221
void DesktopChangeOSD::resize()
 
222
{
 
223
    QRect screenRect = m_wspace->clientArea(ScreenArea, m_wspace->activeScreen(), m_wspace->currentDesktop());
 
224
    QRect fullRect = m_wspace->clientArea(FullArea, m_wspace->activeScreen(), m_wspace->currentDesktop());
 
225
    qreal left, top, right, bottom;
 
226
    m_frame.getMargins(left, top, right, bottom);
 
227
 
 
228
    QSize desktopGridSize = m_wspace->desktopGridSize();
 
229
    float itemWidth = fullRect.width() * 0.1f;
 
230
    float itemHeight = fullRect.height() * 0.1f;
 
231
    // 2 px distance between each desktop + each desktop a width of 5 % of full screen + borders
 
232
    float width = (desktopGridSize.width() - 1) * 2 + desktopGridSize.width() * itemWidth + left + right;
 
233
    float height = (desktopGridSize.height() - 1) * 2 + top + bottom;
 
234
 
 
235
    // bound width between ten and 33 percent of active screen
 
236
    float tempWidth = qBound(screenRect.width() * 0.25f, width, screenRect.width() * 0.5f);
 
237
    if (tempWidth != width) {
 
238
        // have to adjust the height
 
239
        width = tempWidth;
 
240
        itemWidth = (width - (desktopGridSize.width() - 1) * 2 - left - right) / desktopGridSize.width();
 
241
        itemHeight = itemWidth * (float)((float)fullRect.height() / (float)fullRect.width());
 
242
    }
 
243
    height += itemHeight * desktopGridSize.height();
 
244
    height += fontMetrics().height() + 4;
 
245
 
 
246
    // we do not increase height, but it's bound to a third of screen height
 
247
    float tempHeight = qMin(height, screenRect.height() * 0.5f);
 
248
    float itemOffset = 0.0f;
 
249
    if (tempHeight != height) {
 
250
        // have to adjust item width
 
251
        height = tempHeight;
 
252
        itemHeight = (height - (fontMetrics().height() + 4) - top - bottom - (desktopGridSize.height() - 1) * 2) /
 
253
                     desktopGridSize.height();
 
254
        itemOffset = itemWidth;
 
255
        itemWidth = itemHeight * (float)((float)fullRect.width() / (float)fullRect.height());
 
256
        itemOffset -= itemWidth;
 
257
        itemOffset *= (float)desktopGridSize.width() * 0.5f;
 
258
    }
 
259
 
 
260
    // set size to the desktop name if the "pager" is not shown
 
261
    if (m_textOnly) {
 
262
        height = fontMetrics().height() + 4 + top + bottom;
 
263
        width = fontMetrics().boundingRect(m_wspace->desktopName(m_wspace->currentDesktop())).width() +
 
264
                4 + left + right;
 
265
    }
 
266
 
 
267
    QRect rect = QRect(screenRect.x() + (screenRect.width() - width) / 2,
 
268
                       screenRect.y() + (screenRect.height() - height) / 2,
 
269
                       width,
 
270
                       height);
 
271
    setGeometry(rect);
 
272
    m_scene->setSceneRect(0, 0, width, height);
 
273
    m_frame.resizeFrame(QSize(width, height));
 
274
 
 
275
    if (Plasma::Theme::defaultTheme()->windowTranslucencyEnabled()) {
 
276
        // blur background
 
277
        Plasma::WindowEffects::enableBlurBehind(winId(), true, m_frame.mask());
 
278
        Plasma::WindowEffects::overrideShadow(winId(), true);
 
279
    } else {
 
280
        // do not trim to mask with compositing enabled, otherwise shadows are cropped
 
281
        setMask(m_frame.mask());
 
282
    }
 
283
 
 
284
    // resize item frame
 
285
    m_item_frame.setElementPrefix("normal");
 
286
    m_item_frame.resizeFrame(QSize(itemWidth, itemHeight));
 
287
    m_item_frame.setElementPrefix("hover");
 
288
    m_item_frame.resizeFrame(QSize(itemWidth, itemHeight));
 
289
 
 
290
    // reset the items
 
291
    foreach (QGraphicsItem * it, m_scene->items()) {
 
292
        DesktopChangeItem* item = qgraphicsitem_cast<DesktopChangeItem*>(it);
 
293
        if (item) {
 
294
            item->setWidth(itemWidth);
 
295
            item->setHeight(itemHeight);
 
296
            QPoint coords = m_wspace->desktopGridCoords(item->desktop());
 
297
            item->setPos(left + itemOffset + coords.x()*(itemWidth + 2),
 
298
                         top + fontMetrics().height() + 4 + coords.y()*(itemHeight + 4));
 
299
        }
 
300
        DesktopChangeText* text = qgraphicsitem_cast<DesktopChangeText*>(it);
 
301
        if (text) {
 
302
            text->setPos(left, top);
 
303
            text->setWidth(width - left - right);
 
304
            if (m_textOnly)
 
305
                text->setHeight(fontMetrics().height() + 4);
 
306
            else
 
307
                text->setHeight(fontMetrics().height());
 
308
        }
 
309
    }
 
310
}
 
311
 
 
312
//*******************************
 
313
// DesktopChangeText
 
314
//*******************************
 
315
DesktopChangeText::DesktopChangeText(Workspace* ws)
 
316
    : QGraphicsItem()
 
317
    , m_wspace(ws)
 
318
    , m_width(0.0f)
 
319
    , m_height(0.0f)
 
320
{
 
321
}
 
322
 
 
323
DesktopChangeText::~DesktopChangeText()
 
324
{
 
325
}
 
326
 
 
327
QRectF DesktopChangeText::boundingRect() const
 
328
{
 
329
    return QRectF(0, 0, m_width, m_height);
 
330
}
 
331
 
 
332
void DesktopChangeText::paint(QPainter* painter, const QStyleOptionGraphicsItem* , QWidget*)
 
333
{
 
334
    painter->setPen(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
 
335
    painter->drawText(boundingRect(), Qt::AlignCenter | Qt:: AlignVCenter,
 
336
                      m_wspace->desktopName(m_wspace->currentDesktop()));
 
337
}
 
338
 
 
339
//*******************************
 
340
// DesktopChangeItem
 
341
//*******************************
 
342
DesktopChangeItem::DesktopChangeItem(Workspace* ws, DesktopChangeOSD* parent, int desktop)
 
343
    : QGraphicsItem()
 
344
    , m_wspace(ws)
 
345
    , m_parent(parent)
 
346
    , m_desktop(desktop)
 
347
    , m_width(0.0f)
 
348
    , m_height(0.0f)
 
349
    , m_arrow(NONE)
 
350
    , m_arrowShown(false)
 
351
    , m_fadeInArrow(false)
 
352
    , m_fadeInHighLight(false)
 
353
    , m_arrowValue(0.0)
 
354
    , m_highLightValue(0.0)
 
355
{
 
356
    m_delayed_show_arrow_timer.setSingleShot(true);
 
357
    m_delayed_hide_arrow_timer.setSingleShot(true);
 
358
    connect(&m_delayed_show_arrow_timer, SIGNAL(timeout()), this, SLOT(showArrow()));
 
359
    connect(&m_delayed_hide_arrow_timer, SIGNAL(timeout()), this, SLOT(hideArrow()));
 
360
}
 
361
 
 
362
DesktopChangeItem::~DesktopChangeItem()
 
363
{
 
364
}
 
365
 
 
366
QRectF DesktopChangeItem::boundingRect() const
 
367
{
 
368
    return QRectF(0, 0, m_width, m_height);
 
369
}
 
370
 
 
371
void DesktopChangeItem::setArrow(Arrow arrow, int start_delay, int hide_delay)
 
372
{
 
373
    // stop timers
 
374
    m_delayed_show_arrow_timer.stop();
 
375
    m_delayed_hide_arrow_timer.stop();
 
376
 
 
377
    QPropertyAnimation *arrowAnimation = m_arrowAnimation.data();
 
378
    if (arrowAnimation) {
 
379
        arrowAnimation->stop();
 
380
        m_arrowAnimation.clear();
 
381
    }
 
382
 
 
383
    m_arrowShown = false;
 
384
    m_arrow = arrow;
 
385
    if (m_arrow != NONE) {
 
386
        m_delayed_show_arrow_timer.start(start_delay);
 
387
        m_delayed_hide_arrow_timer.start(hide_delay);
 
388
    }
 
389
}
 
390
 
 
391
qreal DesktopChangeItem::arrowValue() const
 
392
{
 
393
    qCritical() << __func__ << m_arrowValue;
 
394
    return m_arrowValue;
 
395
}
 
396
 
 
397
qreal DesktopChangeItem::highLightValue() const
 
398
{
 
399
    return m_highLightValue;
 
400
}
 
401
 
 
402
void DesktopChangeItem::setArrowValue(qreal value)
 
403
{
 
404
    m_arrowValue = value;
 
405
 
 
406
    update();
 
407
}
 
408
 
 
409
void DesktopChangeItem::setHighLightValue(qreal value)
 
410
{
 
411
    m_highLightValue = value;
 
412
 
 
413
    update();
 
414
}
 
415
 
 
416
void DesktopChangeItem::showArrow()
 
417
{
 
418
    m_arrowShown = true;
 
419
 
 
420
    QPropertyAnimation *arrowAnimation = m_arrowAnimation.data();
 
421
    if (!arrowAnimation) {
 
422
        arrowAnimation = new QPropertyAnimation(this, "arrowValue");
 
423
        arrowAnimation->setDuration(m_parent->getDelayTime() * 0.15f);
 
424
        arrowAnimation->setStartValue(0.0);
 
425
        arrowAnimation->setEndValue(1.0);
 
426
 
 
427
        m_arrowAnimation = arrowAnimation;
 
428
    }
 
429
 
 
430
    m_fadeInArrow = true;
 
431
 
 
432
    arrowAnimation->setEasingCurve(QEasingCurve::InQuad);
 
433
    arrowAnimation->setDirection(QAbstractAnimation::Forward);
 
434
    arrowAnimation->start();
 
435
}
 
436
 
 
437
void DesktopChangeItem::hideArrow()
 
438
{
 
439
    m_fadeInArrow = false;
 
440
 
 
441
    QPropertyAnimation *arrowAnimation = m_arrowAnimation.data();
 
442
    if (arrowAnimation) {
 
443
        arrowAnimation->setEasingCurve(QEasingCurve::OutQuad);
 
444
        arrowAnimation->setDirection(QAbstractAnimation::Backward);
 
445
        arrowAnimation->start(QAbstractAnimation::DeleteWhenStopped);
 
446
 
 
447
        connect(arrowAnimation, SIGNAL(finished()), this, SLOT(arrowAnimationFinished()));
 
448
    }
 
449
}
 
450
 
 
451
void DesktopChangeItem::startDesktopHighLightAnimation(int time)
 
452
{
 
453
    QPropertyAnimation *highLightAnimation = m_highLightAnimation.data();
 
454
    if (!highLightAnimation) {
 
455
        highLightAnimation = new QPropertyAnimation(this, "highLightValue");
 
456
        highLightAnimation->setDuration(time);
 
457
        highLightAnimation->setStartValue(0.0);
 
458
        highLightAnimation->setEndValue(1.0);
 
459
 
 
460
        m_highLightAnimation = highLightAnimation;
 
461
    }
 
462
 
 
463
    m_fadeInHighLight = true;
 
464
 
 
465
    highLightAnimation->setEasingCurve(QEasingCurve::InQuad);
 
466
    highLightAnimation->setDirection(QAbstractAnimation::Forward);
 
467
    highLightAnimation->start();
 
468
}
 
469
 
 
470
void DesktopChangeItem::stopDesktopHighLightAnimation()
 
471
{
 
472
    m_fadeInHighLight = false;
 
473
 
 
474
    QPropertyAnimation *highLightAnimation = m_highLightAnimation.data();
 
475
    if (highLightAnimation) {
 
476
        highLightAnimation->setEasingCurve(QEasingCurve::OutQuad);
 
477
        highLightAnimation->setDirection(QAbstractAnimation::Backward);
 
478
        highLightAnimation->start(QAbstractAnimation::DeleteWhenStopped);
 
479
    }
 
480
}
 
481
 
 
482
void DesktopChangeItem::arrowAnimationFinished()
 
483
{
 
484
    if (!m_fadeInArrow)
 
485
        m_arrowShown = false;
 
486
}
 
487
 
 
488
void DesktopChangeItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* , QWidget*)
 
489
{
 
490
    if (m_wspace->currentDesktop() == m_desktop || (!m_highLightAnimation.isNull() &&
 
491
            m_highLightAnimation.data()->state() == QAbstractAnimation::Running)) {
 
492
        qreal left, top, right, bottom;
 
493
        m_parent->itemFrame()->getMargins(left, top, right, bottom);
 
494
        if (!m_highLightAnimation.isNull() &&
 
495
                m_highLightAnimation.data()->state() == QAbstractAnimation::Running) {
 
496
            // there is an animation - so we use transition from normal to active or vice versa
 
497
            if (m_fadeInHighLight) {
 
498
                m_parent->itemFrame()->setElementPrefix("normal");
 
499
                QPixmap normal = m_parent->itemFrame()->framePixmap();
 
500
                m_parent->itemFrame()->setElementPrefix("hover");
 
501
                QPixmap result = Plasma::PaintUtils::transition(normal,
 
502
                                 m_parent->itemFrame()->framePixmap(), m_highLightValue);
 
503
                painter->drawPixmap(boundingRect().toRect(), result);
 
504
            } else {
 
505
                m_parent->itemFrame()->setElementPrefix("hover");
 
506
                QPixmap normal = m_parent->itemFrame()->framePixmap();
 
507
                m_parent->itemFrame()->setElementPrefix("normal");
 
508
                QPixmap result = Plasma::PaintUtils::transition(normal,
 
509
                                 m_parent->itemFrame()->framePixmap(), 1.0 - m_highLightValue);
 
510
                painter->drawPixmap(boundingRect().toRect(), result);
 
511
            }
 
512
        } else {
 
513
            // no animation - just render the active frame
 
514
            m_parent->itemFrame()->setElementPrefix("hover");
 
515
            m_parent->itemFrame()->paintFrame(painter, boundingRect());
 
516
        }
 
517
        QColor rectColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
 
518
        rectColor.setAlphaF(0.6 * m_highLightValue);
 
519
        QBrush rectBrush = QBrush(rectColor);
 
520
        painter->fillRect(boundingRect().adjusted(left, top, -right, -bottom), rectBrush);
 
521
    } else {
 
522
        m_parent->itemFrame()->setElementPrefix("normal");
 
523
        m_parent->itemFrame()->paintFrame(painter, boundingRect());
 
524
    }
 
525
 
 
526
    if (!m_arrowShown)
 
527
        return;
 
528
    // paint the arrow
 
529
    QPixmap icon;
 
530
    int iconWidth = 32;
 
531
    qreal maxsize = qMin(boundingRect().width(), boundingRect().height());
 
532
    if (maxsize > 128.0)
 
533
        iconWidth = 128;
 
534
    else if (maxsize > 64.0)
 
535
        iconWidth = 64.0;
 
536
    else if (maxsize > 32.0)
 
537
        iconWidth = 32.0;
 
538
    else
 
539
        iconWidth = 16.0;
 
540
    QRect iconRect = QRect(boundingRect().x() + boundingRect().width() / 2 - iconWidth / 2,
 
541
                           boundingRect().y() + boundingRect().height() / 2 - iconWidth / 2,
 
542
                           iconWidth, iconWidth);
 
543
    switch(m_arrow) {
 
544
    case UP:
 
545
        icon = KIconLoader::global()->loadIcon("go-up", KIconLoader::Desktop, iconWidth);
 
546
        break;
 
547
    case DOWN:
 
548
        icon = KIconLoader::global()->loadIcon("go-down", KIconLoader::Desktop, iconWidth);
 
549
        break;
 
550
    case LEFT:
 
551
        icon = KIconLoader::global()->loadIcon("go-previous", KIconLoader::Desktop, iconWidth);
 
552
        break;
 
553
    case RIGHT:
 
554
        icon = KIconLoader::global()->loadIcon("go-next", KIconLoader::Desktop, iconWidth);
 
555
        break;
 
556
    default:
 
557
        break;
 
558
    }
 
559
    if (m_arrow != NONE) {
 
560
        if (!m_arrowAnimation.isNull() &&
 
561
                m_arrowAnimation.data()->state() == QAbstractAnimation::Running &&
 
562
                !qFuzzyCompare(m_arrowValue, qreal(1.0))) {
 
563
            QPixmap temp(icon.size());
 
564
            temp.fill(Qt::transparent);
 
565
 
 
566
            QPainter p(&temp);
 
567
            p.setCompositionMode(QPainter::CompositionMode_Source);
 
568
            p.drawPixmap(0, 0, icon);
 
569
            p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
 
570
            p.fillRect(temp.rect(), QColor(0, 0, 0, 255 * m_arrowValue));
 
571
            p.end();
 
572
 
 
573
            icon = temp;
 
574
        }
 
575
        painter->drawPixmap(iconRect, icon);
 
576
    }
 
577
}
 
578
}
 
579
 
 
580
#include "desktopchangeosd.moc"