~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy

« back to all changes in this revision

Viewing changes to kicker/applets/minipager/pagerbutton.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
ImportĀ upstreamĀ versionĀ 3.93.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************
 
2
 
 
3
Copyright (c) 1996-2000 the kicker authors. See file AUTHORS.
 
4
 
 
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:
 
11
 
 
12
The above copyright notice and this permission notice shall be included in
 
13
all copies or substantial portions of the Software.
 
14
 
 
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.
 
21
 
 
22
******************************************************************/
 
23
 
 
24
#include <QtGui/qdrawutil.h>
 
25
 
 
26
#include <QBitmap>
 
27
#include <QCursor>
 
28
#include <QDesktopWidget>
 
29
#include <QDragEnterEvent>
 
30
#include <QDragLeaveEvent>
 
31
#include <QDropEvent>
 
32
#include <QEvent>
 
33
#include <QResizeEvent>
 
34
#include <QLineEdit>
 
35
#include <QList>
 
36
#include <QMenu>
 
37
#include <QMouseEvent>
 
38
#include <QPaintEvent>
 
39
#include <QPainter>
 
40
#include <QPixmap>
 
41
 
 
42
#include <netwm.h>
 
43
 
 
44
#include <kwindowsystem.h>
 
45
#include <ksharedpixmap.h>
 
46
#include <kpixmapeffect.h>
 
47
#include <kstringhandler.h>
 
48
#include <kiconloader.h>
 
49
#include <QtDBus/QtDBus>
 
50
 
 
51
#include "utils.h"
 
52
#include "kickertip.h"
 
53
#include "kickerSettings.h"
 
54
#include "kshadowengine.h"
 
55
 
 
56
#include "pagerapplet.h"
 
57
#include "pagerbutton.h"
 
58
#include "pagerbutton.moc"
 
59
#include "pagersettings.h"
 
60
 
 
61
#ifdef FocusOut
 
62
#undef FocusOut
 
63
#endif
 
64
 
 
65
KSharedPixmap* KMiniPagerButton::s_commonSharedPixmap;
 
66
QPixmap* KMiniPagerButton::s_commonBgPixmap;
 
67
 
 
68
KMiniPagerButton::KMiniPagerButton(int desk, KMiniPager *parent, const char *name)
 
69
    : QAbstractButton(parent, name, Qt::WNoAutoErase),
 
70
      m_pager(parent),
 
71
      m_desktop(desk),
 
72
      m_lineEdit(0),
 
73
      m_sharedPixmap(0),
 
74
      m_bgPixmap(0),
 
75
      m_isCommon(false),
 
76
      m_currentWindow(0)
 
77
{
 
78
    setCheckable(true);
 
79
    setAcceptDrops(true);
 
80
 
 
81
    //setBackgroundOrigin(AncestorOrigin);
 
82
    installEventFilter(KickerTip::self());
 
83
 
 
84
    m_desktopName = KWindowSystem::desktopName(m_desktop);
 
85
 
 
86
    connect(this, SIGNAL(clicked()), SLOT(slotClicked()));
 
87
    connect(this, SIGNAL(toggled(bool)), SLOT(slotToggled(bool)));
 
88
    connect(&m_dragSwitchTimer, SIGNAL(timeout()), this, SLOT(slotDragSwitch()));
 
89
 
 
90
    m_dragSwitchTimer.setSingleShot(true);
 
91
 
 
92
    if (m_pager->desktopPreview())
 
93
    {
 
94
        setMouseTracking(true);
 
95
    }
 
96
    loadBgPixmap();
 
97
}
 
98
 
 
99
KMiniPagerButton::~KMiniPagerButton()
 
100
{
 
101
    delete m_sharedPixmap;
 
102
    delete m_bgPixmap;
 
103
}
 
104
 
 
105
bool KMiniPagerButton::shouldPaintWindow( KWindowSystem::WindowInfo *info )
 
106
{
 
107
    if (!info)
 
108
      return false;
 
109
 
 
110
//  if (info->mappingState != NET::Visible)
 
111
//    return false;
 
112
 
 
113
    NET::WindowType type = info->windowType( NET::NormalMask | NET::DesktopMask
 
114
        | NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DialogMask
 
115
        | NET::OverrideMask | NET::TopMenuMask | NET::UtilityMask | NET::SplashMask );
 
116
 
 
117
    if (type == NET::Desktop || type == NET::Dock || type == NET::TopMenu)
 
118
      return false;
 
119
 
 
120
    if (!info->isOnDesktop(m_desktop))
 
121
      return false;
 
122
 
 
123
    if (info->state() & NET::SkipPager || info->state() & NET::Shaded )
 
124
      return false;
 
125
 
 
126
    if (info->win() == m_pager->winId())
 
127
      return false;
 
128
 
 
129
    if ( info->isMinimized() )
 
130
      return false;
 
131
 
 
132
    return true;
 
133
}
 
134
 
 
135
void KMiniPagerButton::resizeEvent(QResizeEvent *ev)
 
136
{
 
137
    if (m_lineEdit)
 
138
    {
 
139
        m_lineEdit->setGeometry(rect());
 
140
    }
 
141
 
 
142
    delete m_bgPixmap;
 
143
    m_bgPixmap = 0;
 
144
 
 
145
    QAbstractButton::resizeEvent(ev);
 
146
}
 
147
 
 
148
void KMiniPagerButton::windowsChanged()
 
149
{
 
150
    m_currentWindow = 0;
 
151
    update();
 
152
}
 
153
 
 
154
void KMiniPagerButton::backgroundChanged()
 
155
{
 
156
    delete s_commonSharedPixmap;
 
157
    s_commonSharedPixmap = 0;
 
158
    delete s_commonBgPixmap;
 
159
    s_commonBgPixmap = 0;
 
160
    loadBgPixmap();
 
161
}
 
162
 
 
163
void KMiniPagerButton::loadBgPixmap()
 
164
{
 
165
    if (m_pager->bgType() != PagerSettings::EnumBackgroundType::BgLive)
 
166
        return; // not needed
 
167
 
 
168
 
 
169
    bool isCommon;
 
170
    QDBusInterface kdesktop("org.kde.kdesktop", "/Background", "org.kde.kdesktop.KBackground");
 
171
    QDBusReply<bool> reply = kdesktop.call("isCommon");
 
172
    if (reply.isValid())
 
173
    {
 
174
        m_isCommon = reply;
 
175
    }
 
176
 
 
177
    if (m_isCommon)
 
178
    {
 
179
        if (s_commonBgPixmap)
 
180
        { // pixmap is already ready, just use it
 
181
            backgroundLoaded( true );
 
182
            return;
 
183
        }
 
184
        else if (s_commonSharedPixmap)
 
185
        { // other button is already fetching the pixmap
 
186
            connect(s_commonSharedPixmap, SIGNAL(done(bool)),
 
187
                    SLOT(backgroundLoaded(bool)));
 
188
            return;
 
189
        }
 
190
    }
 
191
 
 
192
    kdesktop.call("setExport", 1);
 
193
 
 
194
    if (m_isCommon)
 
195
    {
 
196
        if (!s_commonSharedPixmap)
 
197
        {
 
198
            s_commonSharedPixmap = new KSharedPixmap;
 
199
            connect(s_commonSharedPixmap, SIGNAL(done(bool)),
 
200
                    SLOT(backgroundLoaded(bool)));
 
201
        }
 
202
        s_commonSharedPixmap->loadFromShared(QString("DESKTOP1"));
 
203
    }
 
204
    else
 
205
    {
 
206
        if (!m_sharedPixmap)
 
207
        {
 
208
            m_sharedPixmap = new KSharedPixmap;
 
209
            connect(m_sharedPixmap, SIGNAL(done(bool)),
 
210
                    SLOT(backgroundLoaded(bool)));
 
211
        }
 
212
        m_sharedPixmap->loadFromShared(QString("DESKTOP%1").arg(m_desktop));
 
213
    }
 
214
}
 
215
 
 
216
static QPixmap scalePixmap(const QPixmap &pixmap, int width, int height)
 
217
{
 
218
    return pixmap.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
 
219
}
 
220
 
 
221
QPixmap fastScalePixmap(const QPixmap &pixmap, int width, int height)
 
222
{
 
223
    QMatrix m;
 
224
    m.scale( (width / (double)pixmap.width()), (height / (double)pixmap.height()) );
 
225
    return pixmap.transformed(m);
 
226
}
 
227
 
 
228
void KMiniPagerButton::backgroundLoaded( bool loaded )
 
229
{
 
230
    if (loaded)
 
231
    {
 
232
        if (!m_bgPixmap)
 
233
        {
 
234
            m_bgPixmap = new QPixmap;
 
235
        }
 
236
        if (m_isCommon)
 
237
        {
 
238
            if (!s_commonBgPixmap)
 
239
            {
 
240
                s_commonBgPixmap = new QPixmap;
 
241
                *s_commonBgPixmap = scalePixmap(s_commonSharedPixmap->pixmap(), width(), height());
 
242
                s_commonSharedPixmap->deleteLater(); // let others get the signal too
 
243
                s_commonSharedPixmap = 0;
 
244
            }
 
245
            *m_bgPixmap = *s_commonBgPixmap;
 
246
        }
 
247
        else
 
248
        {
 
249
            *m_bgPixmap = scalePixmap(m_sharedPixmap->pixmap(), width(), height());
 
250
            delete m_sharedPixmap;
 
251
            m_sharedPixmap = 0L;
 
252
        }
 
253
 
 
254
/*        delete m_sharedPixmap;
 
255
        m_sharedPixmap = 0L;
 
256
*/
 
257
        update();
 
258
    }
 
259
    else
 
260
    {
 
261
        kDebug() << "Error getting the background\n";
 
262
    }
 
263
}
 
264
 
 
265
void KMiniPagerButton::paintEvent(QPaintEvent *)
 
266
{
 
267
    int w = width();
 
268
    int h = height();
 
269
    bool on = isEnabled();
 
270
    bool down = isChecked();
 
271
    QPixmap buffer(w, h);
 
272
    QBitmap mask(w, h, true);
 
273
    QPainter bp(&buffer); //### copied attrs from this
 
274
    QPainter mp(&mask);
 
275
 
 
276
    QBrush background;
 
277
 
 
278
    bool liveBkgnd = m_pager->bgType() == PagerSettings::EnumBackgroundType::BgLive;
 
279
    bool transparent = m_pager->bgType() == PagerSettings::EnumBackgroundType::BgTransparent;
 
280
 
 
281
    // background...
 
282
    if (liveBkgnd)
 
283
    {
 
284
        if (m_bgPixmap && !m_bgPixmap->isNull())
 
285
        {
 
286
            if (on)
 
287
            {
 
288
                QPixmap tmp = *m_bgPixmap;
 
289
                KPixmapEffect::intensity(tmp, 0.33);
 
290
                bp.drawPixmap(0, 0, tmp);
 
291
            }
 
292
            else
 
293
            {
 
294
                bp.drawPixmap(0, 0, *m_bgPixmap);
 
295
            }
 
296
        }
 
297
        else
 
298
        {
 
299
            liveBkgnd = false;
 
300
        }
 
301
 
 
302
    }
 
303
 
 
304
    if (!liveBkgnd)
 
305
    {
 
306
        if (transparent)
 
307
        {
 
308
            // transparent windows get an 1 pixel frame...
 
309
            if (on)
 
310
            {
 
311
                bp.setPen(palette().color( QPalette::Midlight ) );
 
312
            }
 
313
            else if (down)
 
314
            {
 
315
                bp.setPen(Plasma::blendColors(palette().color( QPalette::Mid ),
 
316
                                              palette().color( QPalette::Midlight ) ) );
 
317
            }
 
318
            else
 
319
            {
 
320
                bp.setPen( palette().color( QPalette::Dark ) );
 
321
            }
 
322
 
 
323
            bp.drawRect( buffer.rect() );
 
324
            mp.setPen( Qt::color1 );
 
325
            mp.drawRect( buffer.rect() );
 
326
        }
 
327
        else
 
328
        {
 
329
            QBrush background;
 
330
 
 
331
            if (on)
 
332
            {
 
333
                background = palette().brush(QPalette::Midlight);
 
334
            }
 
335
            else if (down)
 
336
            {
 
337
                background = Plasma::blendColors(palette().color( QPalette::Mid ),
 
338
                                                 palette().color( QPalette::Midlight ) );
 
339
            }
 
340
            else
 
341
            {
 
342
                background = palette().brush(QPalette::Mid);
 
343
            }
 
344
 
 
345
            bp.fillRect(buffer.rect(), background);
 
346
        }
 
347
    }
 
348
 
 
349
    // window preview...
 
350
    if (m_pager->desktopPreview())
 
351
    {
 
352
        KWindowSystem::WindowInfo *info = 0;
 
353
        int dw = QApplication::desktop()->width();
 
354
        int dh = QApplication::desktop()->height();
 
355
 
 
356
        QList<WId> windows = KWindowSystem::stackingOrder();
 
357
        QList<WId>::const_iterator itEnd = windows.constEnd();
 
358
        for (QList<WId>::ConstIterator it = windows.constBegin(); it != itEnd; ++it)
 
359
        {
 
360
            info = m_pager->info(*it);
 
361
 
 
362
            if (shouldPaintWindow(info))
 
363
            {
 
364
                QRect r =  info->frameGeometry();
 
365
                r = QRect(r.x() * width() / dw, 2 + r.y() * height() / dh,
 
366
                          r.width() * width() / dw, r.height() * height() / dh);
 
367
 
 
368
                if (KWindowSystem::activeWindow() == info->win())
 
369
                {
 
370
                    QBrush brush = palette().brush(QPalette::Highlight);
 
371
                    qDrawShadeRect(&bp, r, palette(), false, 1, 0, &brush);
 
372
                }
 
373
                else
 
374
                {
 
375
                    QBrush brush = palette().brush(QPalette::Button);
 
376
 
 
377
                    if (on)
 
378
                    {
 
379
                        brush.setColor(brush.color().light(120));
 
380
                    }
 
381
 
 
382
                    bp.fillRect(r, brush);
 
383
                    qDrawShadeRect(&bp, r, palette(), true, 1, 0);
 
384
                }
 
385
 
 
386
                if (transparent)
 
387
                {
 
388
                    mp.fillRect(r, Qt::color1);
 
389
                }
 
390
 
 
391
                if (m_pager->windowIcons() && r.width() > 15 && r.height() > 15)
 
392
                {
 
393
                    QPixmap icon = KWindowSystem::icon(*it, 16, 16, true);
 
394
                    if (!icon.isNull())
 
395
                    {
 
396
                        bp.drawPixmap(r.left() + ((r.width() - 16) / 2),
 
397
                                      r.top() + ((r.height() - 16) / 2),
 
398
                                      icon);
 
399
                    }
 
400
                }
 
401
            }
 
402
        }
 
403
    }
 
404
 
 
405
    if (liveBkgnd)
 
406
    {
 
407
        // draw a little border around the individual buttons
 
408
        // makes it look a bit more finished.
 
409
        if (on)
 
410
        {
 
411
            bp.setPen(palette().midlight());
 
412
        }
 
413
        else
 
414
        {
 
415
            bp.setPen(palette().mid());
 
416
        }
 
417
 
 
418
        bp.drawRect(0, 0, w, h);
 
419
    }
 
420
 
 
421
    mp.end();
 
422
 
 
423
    if (transparent)
 
424
    {
 
425
        bp.end();
 
426
        buffer.setMask(mask);
 
427
 
 
428
        bp.begin(this);
 
429
        bp.eraseRect(rect());
 
430
        bp.drawPixmap(0, 0, buffer);
 
431
    }
 
432
 
 
433
    if (m_pager->labelType() != PagerSettings::EnumLabelType::LabelNone)
 
434
    {
 
435
        QString label = (m_pager->labelType() == PagerSettings::EnumLabelType::LabelNumber) ?
 
436
                            QString::number(m_desktop) : m_desktopName;
 
437
        QPainter tp;
 
438
        QPixmap textPixmap(width(), height());
 
439
 
 
440
        textPixmap.fill(QColor(0,0,0));
 
441
        textPixmap.setMask(textPixmap.createHeuristicMask(true));
 
442
 
 
443
        // draw text
 
444
        tp.begin(&textPixmap);
 
445
        tp.setPen(Qt::white);
 
446
        tp.setFont(font()); // get the font from the root painter
 
447
        tp.drawText(0, 0, w, h, Qt::AlignCenter, label);
 
448
        tp.end();
 
449
 
 
450
        // draw shadow
 
451
        QImage img = m_pager->shadowEngine()->makeShadow(textPixmap,
 
452
                                                         liveBkgnd ? Qt::black
 
453
                                                                   : Qt::white);
 
454
 
 
455
        bp.drawImage(0, 0, img);
 
456
        bp.drawText(0, 0, w, h, Qt::AlignCenter, label);
 
457
    }
 
458
 
 
459
    if (!transparent)
 
460
    {
 
461
        bp.end();
 
462
        bp.begin(this);
 
463
        bp.drawPixmap(0, 0, buffer);
 
464
    }
 
465
 
 
466
    bp.end();
 
467
}
 
468
 
 
469
void KMiniPagerButton::mousePressEvent(QMouseEvent * e)
 
470
{
 
471
    if (e->button() == Qt::RightButton)
 
472
    {
 
473
        // prevent LMB down -> RMB down -> LMB up sequence
 
474
        if ((e->state() & Qt::MouseButtonMask ) == Qt::NoButton)
 
475
        {
 
476
            emit showMenu(e->globalPos(), m_desktop);
 
477
            return;
 
478
        }
 
479
    }
 
480
 
 
481
    if (m_pager->desktopPreview())
 
482
    {
 
483
        m_pager->clickPos = e->pos();
 
484
    }
 
485
 
 
486
    QAbstractButton::mouseReleaseEvent(e);
 
487
}
 
488
 
 
489
void KMiniPagerButton::mouseReleaseEvent(QMouseEvent* e)
 
490
{
 
491
    m_pager->clickPos = QPoint();
 
492
    QAbstractButton::mouseReleaseEvent(e);
 
493
}
 
494
 
 
495
void KMiniPagerButton::mouseMoveEvent(QMouseEvent* e)
 
496
{
 
497
    if (!m_pager->desktopPreview())
 
498
    {
 
499
        return;
 
500
    }
 
501
 
 
502
    int dw = QApplication::desktop()->width();
 
503
    int dh = QApplication::desktop()->height();
 
504
    int w = width();
 
505
    int h = height();
 
506
 
 
507
    QPoint pos(m_pager->clickPos.isNull() ? mapFromGlobal(QCursor::pos()) : m_pager->clickPos);
 
508
    QPoint p(pos.x() * dw / w, pos.y() * dh / h);
 
509
    Task::TaskPtr wasWindow = m_currentWindow;
 
510
    m_currentWindow = TaskManager::self()->findTask(m_desktop, p);
 
511
 
 
512
    if (wasWindow != m_currentWindow)
 
513
    {
 
514
        KickerTip::Client::updateTip();
 
515
    }
 
516
 
 
517
    if (m_currentWindow && !m_pager->clickPos.isNull() &&
 
518
        (m_pager->clickPos - e->pos()).manhattanLength() > KGlobalSettings::dndEventDelay())
 
519
    {
 
520
        QRect r = m_currentWindow->geometry();
 
521
 
 
522
        // preview window height, window width
 
523
        int ww = r.width() * w / dw;
 
524
        int wh = r.height() * h / dh;
 
525
        QPixmap windowImage(ww, wh);
 
526
        QPainter bp(&windowImage); //### copied attributes from this
 
527
 
 
528
        bp.setPen( palette().color( QPalette::Foreground ) );
 
529
        bp.drawRect(0, 0, ww, wh);
 
530
        bp.fillRect(1, 1, ww - 2, wh - 2, palette().color( QPalette::Background) );
 
531
 
 
532
        Task::List tasklist;
 
533
        tasklist.append(m_currentWindow);
 
534
        TaskDrag* drag = new TaskDrag(tasklist, this);
 
535
        QPoint offset(m_pager->clickPos.x() - (r.x() * w / dw),
 
536
                m_pager->clickPos.y() - (r.y() * h / dh));
 
537
        drag->setPixmap(windowImage);
 
538
        drag->setHotSpot(offset);
 
539
        drag->start();
 
540
 
 
541
        if (isDown())
 
542
        {
 
543
            setDown(false);
 
544
        }
 
545
 
 
546
        m_pager->clickPos = QPoint();
 
547
    }
 
548
}
 
549
 
 
550
void KMiniPagerButton::dragEnterEvent(QDragEnterEvent* e)
 
551
{
 
552
    kDebug() << "received drag " << e->format();
 
553
    if (TaskDrag::canDecode(e->mimeData()))
 
554
    {
 
555
        // if it's a task drag don't switch the desktop, just accept it
 
556
        e->accept();
 
557
        setDown(true);
 
558
    }
 
559
    else
 
560
    {
 
561
        // if a dragitem is held for over a pager button for two seconds,
 
562
        // activate corresponding desktop
 
563
        m_dragSwitchTimer.start(1000);
 
564
        QAbstractButton::dragEnterEvent( e );
 
565
    }
 
566
}
 
567
 
 
568
void KMiniPagerButton::dropEvent(QDropEvent* e)
 
569
{
 
570
    if (TaskDrag::canDecode(e->mimeData()))
 
571
    {
 
572
        e->accept();
 
573
        Task::List tasks(TaskDrag::decode(e->mimeData()));
 
574
 
 
575
        if (e->source() == this && tasks.count() == 1)
 
576
        {
 
577
            Task::TaskPtr task = tasks[0];
 
578
            int dw = QApplication::desktop()->width();
 
579
            int dh = QApplication::desktop()->height();
 
580
            int w = width();
 
581
            int h = height();
 
582
            QRect location = task->geometry();
 
583
            location.translate((e->pos().x() - m_pager->clickPos.x()) * dw / w,
 
584
                            (e->pos().y() - m_pager->clickPos.y()) * dh / h);
 
585
 
 
586
            XMoveWindow(x11Display(), task->window(), location.x(), location.y());
 
587
            if ((e->source() != this || !task->isOnAllDesktops()) &&
 
588
                task->desktop() != m_desktop)
 
589
            {
 
590
                task->toDesktop(m_desktop);
 
591
            }
 
592
        }
 
593
        else
 
594
        {
 
595
            Task::List::iterator itEnd = tasks.end();
 
596
            for (Task::List::iterator it = tasks.begin(); it != itEnd; ++it)
 
597
            {
 
598
                (*it)->toDesktop(m_desktop);
 
599
            }
 
600
        }
 
601
 
 
602
        setDown(false);
 
603
    }
 
604
 
 
605
    QAbstractButton::dropEvent( e );
 
606
}
 
607
 
 
608
void KMiniPagerButton::enabledChange( bool oldEnabled )
 
609
{
 
610
    if (m_pager->bgType() == PagerSettings::EnumBackgroundType::BgLive)
 
611
    {
 
612
        m_pager->refresh();
 
613
    }
 
614
 
 
615
    QAbstractButton::enabledChange( oldEnabled );
 
616
}
 
617
 
 
618
void KMiniPagerButton::dragLeaveEvent( QDragLeaveEvent* e )
 
619
{
 
620
    m_dragSwitchTimer.stop();
 
621
 
 
622
    if (KWindowSystem::currentDesktop() != m_desktop)
 
623
    {
 
624
        setDown(false);
 
625
    }
 
626
 
 
627
    QAbstractButton::dragLeaveEvent( e );
 
628
}
 
629
 
 
630
void KMiniPagerButton::slotDragSwitch()
 
631
{
 
632
    emit buttonSelected(m_desktop);
 
633
}
 
634
 
 
635
void KMiniPagerButton::slotClicked()
 
636
{
 
637
    emit buttonSelected(m_desktop);
 
638
}
 
639
 
 
640
void KMiniPagerButton::rename()
 
641
{
 
642
  if ( !m_lineEdit ) {
 
643
    m_lineEdit = new QLineEdit( this );
 
644
    connect( m_lineEdit, SIGNAL( returnPressed() ), m_lineEdit, SLOT( hide() ) );
 
645
    m_lineEdit->installEventFilter( this );
 
646
  }
 
647
  m_lineEdit->setGeometry( rect() );
 
648
  m_lineEdit->setText(m_desktopName);
 
649
  m_lineEdit->show();
 
650
  m_lineEdit->setFocus();
 
651
  m_lineEdit->selectAll();
 
652
  m_pager->emitRequestFocus();
 
653
}
 
654
 
 
655
void KMiniPagerButton::slotToggled( bool b )
 
656
{
 
657
    if ( !b && m_lineEdit )
 
658
    {
 
659
        m_lineEdit->hide();
 
660
    }
 
661
}
 
662
 
 
663
bool KMiniPagerButton::eventFilter( QObject *o, QEvent * e)
 
664
{
 
665
    if (o && o == m_lineEdit &&
 
666
        (e->type() == QEvent::FocusOut || e->type() == QEvent::Hide))
 
667
    {
 
668
        KWindowSystem::setDesktopName( m_desktop, m_lineEdit->text() );
 
669
        m_desktopName = m_lineEdit->text();
 
670
        QTimer::singleShot( 0, m_lineEdit, SLOT( deleteLater() ) );
 
671
        m_lineEdit = 0;
 
672
        return true;
 
673
    }
 
674
 
 
675
    return QAbstractButton::eventFilter(o, e);
 
676
}
 
677
 
 
678
void KMiniPagerButton::updateTipData(KickerTip::Data &data)
 
679
{
 
680
    Task::Dict tasks = TaskManager::self()->tasks();
 
681
    Task::Dict::iterator taskEnd = tasks.end();
 
682
    uint taskCounter = 0;
 
683
    uint taskLimiter = 4;
 
684
    QString lastWindow;
 
685
 
 
686
    for (Task::Dict::iterator it = tasks.begin(); it != taskEnd; ++it)
 
687
    {
 
688
        if (it.value()->desktop() == m_desktop || it.value()->isOnAllDesktops())
 
689
        {
 
690
            taskCounter++;
 
691
            if (taskCounter > taskLimiter)
 
692
            {
 
693
                lastWindow = it.value()->visibleName();
 
694
                continue;
 
695
            }
 
696
 
 
697
            if (it.value() == m_currentWindow)
 
698
            {
 
699
                data.subtext.append("<br>&bull; <u>").append(it.value()->visibleName()).append("</u>");
 
700
            }
 
701
            else
 
702
            {
 
703
                data.subtext.append("<br>&bull; ").append(it.value()->visibleName());
 
704
            }
 
705
        }
 
706
    }
 
707
 
 
708
    if (taskCounter > taskLimiter)
 
709
    {
 
710
        if (taskCounter - taskLimiter == 1)
 
711
        {
 
712
            data.subtext.append("<br>&bull; ").append(lastWindow);
 
713
        }
 
714
        else
 
715
        {
 
716
            data.subtext.append("<br>&bull; <i>")
 
717
                        .append(i18n("and %1 others",
 
718
                                     taskCounter - taskLimiter))
 
719
                        .append("</i>");
 
720
        }
 
721
    }
 
722
 
 
723
    if (taskCounter > 0)
 
724
    {
 
725
        data.subtext.prepend(i18np("One window:",
 
726
                                  "%1 Windows:",
 
727
                                  taskCounter));
 
728
    }
 
729
 
 
730
    data.icon = DesktopIcon("window_list", K3Icon::SizeMedium);
 
731
    data.message = m_desktopName;
 
732
    data.direction = m_pager->popupDirection();
 
733
}
 
734