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

« back to all changes in this revision

Viewing changes to plasma/desktop/shell/panelappletoverlay.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
 *   Copyright 2008 Aaron Seigo <aseigo@kde.org>
 
3
 *
 
4
 *   This program is free software; you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU General Public License as
 
6
 *   published by the Free Software Foundation; either version 2,
 
7
 *   or (at your option) any later version.
 
8
 *
 
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
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
#include "panelappletoverlay.h"
 
21
#include "panelapplethandle.h"
 
22
 
 
23
#include <QApplication>
 
24
#include <QGraphicsLinearLayout>
 
25
#include <QGraphicsSceneContextMenuEvent>
 
26
#include <QPainter>
 
27
#include <QTimer>
 
28
#include <QAction>
 
29
#include <QMenu>
 
30
 
 
31
#include <KDebug>
 
32
#include <KGlobalSettings>
 
33
#include <KIcon>
 
34
 
 
35
#include <Plasma/Applet>
 
36
#include <Plasma/Containment>
 
37
#include <Plasma/Corona>
 
38
#include <Plasma/PaintUtils>
 
39
#include <Plasma/Theme>
 
40
#include <Plasma/View>
 
41
 
 
42
 
 
43
PanelAppletHandle *PanelAppletOverlay::s_appletHandle = 0;
 
44
int PanelAppletOverlay::s_appletHandleCount = 0;
 
45
 
 
46
class AppletMoveSpacer : public QGraphicsWidget
 
47
{
 
48
public:
 
49
    AppletMoveSpacer(Plasma::Applet *applet)
 
50
        : QGraphicsWidget(applet->containment()),
 
51
          m_applet(applet)
 
52
    {
 
53
    }
 
54
 
 
55
protected:
 
56
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * widget = 0)
 
57
    {
 
58
        Q_UNUSED(option)
 
59
        Q_UNUSED(widget)
 
60
 
 
61
        /*
 
62
           results in odd painting corruption
 
63
        if (collidesWithItem(m_applet, Qt::IntersectsItemBoundingRect)) {
 
64
            painter->fillRect(contentsRect(), Qt::transparent);
 
65
            return;
 
66
        }
 
67
        */
 
68
 
 
69
        //TODO: make this a pretty gradient?
 
70
        painter->setRenderHint(QPainter::Antialiasing);
 
71
        QPainterPath p = Plasma::PaintUtils::roundedRectangle(contentsRect().adjusted(1, 1, -2, -2), 4);
 
72
        QColor c = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
 
73
        c.setAlphaF(0.3);
 
74
 
 
75
        painter->fillPath(p, c);
 
76
    }
 
77
 
 
78
private:
 
79
    QGraphicsWidget *m_applet;
 
80
};
 
81
 
 
82
PanelAppletOverlay::PanelAppletOverlay(Plasma::Applet *applet, QWidget *parent)
 
83
    : QWidget(parent),
 
84
      m_applet(applet),
 
85
      m_spacer(0),
 
86
      m_layout(dynamic_cast<QGraphicsLinearLayout*>(applet->containment()->layout())), // ++assumptions;
 
87
      m_index(0),
 
88
      m_clickDrag(false)
 
89
{
 
90
    if (!s_appletHandle) {
 
91
        s_appletHandle = new PanelAppletHandle();
 
92
    }
 
93
 
 
94
    ++s_appletHandleCount;
 
95
 
 
96
    connect(s_appletHandle, SIGNAL(mousePressed(Plasma::Applet *, QMouseEvent *)), 
 
97
            this, SLOT(handleMousePressed(Plasma::Applet *, QMouseEvent *)));
 
98
    connect(s_appletHandle, SIGNAL(mouseMoved(Plasma::Applet *, QMouseEvent *)), 
 
99
            this, SLOT(handleMouseMoved(Plasma::Applet *, QMouseEvent *)));
 
100
    connect(s_appletHandle, SIGNAL(mouseReleased(Plasma::Applet *, QMouseEvent *)), 
 
101
            this, SLOT(handleMouseReleased(Plasma::Applet *, QMouseEvent *)));
 
102
 
 
103
    syncIndex();
 
104
    syncOrientation();
 
105
    syncGeometry();
 
106
    setMouseTracking(true);
 
107
 
 
108
 
 
109
    connect(m_applet, SIGNAL(destroyed(QObject*)), this, SLOT(appletDestroyed()));
 
110
    connect(m_applet, SIGNAL(geometryChanged()), this, SLOT(delaySyncGeometry()));
 
111
}
 
112
 
 
113
PanelAppletOverlay::~PanelAppletOverlay()
 
114
{
 
115
    bool mover = mouseGrabber() == this;
 
116
    if (mover) {
 
117
        kDebug() << "MOVER!" << m_layout << m_index;
 
118
        releaseMouse();
 
119
        if (m_layout && m_applet) {
 
120
            m_layout->insertItem(m_index, m_applet);
 
121
        }
 
122
    }
 
123
 
 
124
    if (m_spacer) {
 
125
        if (m_layout) {
 
126
            m_layout->removeItem(m_spacer);
 
127
        }
 
128
 
 
129
        m_spacer->deleteLater();
 
130
        m_spacer = 0;
 
131
    }
 
132
 
 
133
    --s_appletHandleCount;
 
134
    if (s_appletHandleCount < 1) {
 
135
        delete s_appletHandle;
 
136
        s_appletHandle = 0;
 
137
        s_appletHandleCount = 0;
 
138
    }
 
139
}
 
140
 
 
141
void PanelAppletOverlay::paintEvent(QPaintEvent *event)
 
142
{
 
143
    Q_UNUSED(event)
 
144
 
 
145
    QStyleOption op;
 
146
    op.initFrom(this);
 
147
 
 
148
    bool hovered = op.state & QStyle::State_MouseOver;
 
149
    bool mover = mouseGrabber() == this;
 
150
    if (!hovered || mover) {
 
151
        return;
 
152
    }
 
153
 
 
154
    QPainter p(this);
 
155
    KIcon icon("transform-move");
 
156
    int iconSize;
 
157
    QRect iconRect;
 
158
 
 
159
 
 
160
    if (!m_applet) {
 
161
        return;
 
162
    }
 
163
 
 
164
    if (m_orientation == Qt::Horizontal) {
 
165
        iconSize = qMin(qMin(height(), int(m_applet->size().width())), 64);
 
166
        iconRect = QRect(rect().center() - QPoint(iconSize / 2, iconSize / 2), QSize(iconSize, iconSize));
 
167
    } else {
 
168
        iconSize = qMin(qMin(width(), int(m_applet->size().height())), 64);
 
169
        iconRect = QRect(rect().center() - QPoint(iconSize / 2, iconSize / 2), QSize(iconSize, iconSize));
 
170
    }
 
171
 
 
172
    p.drawPixmap(iconRect, icon.pixmap(iconSize, iconSize));
 
173
}
 
174
 
 
175
void PanelAppletOverlay::mousePressEvent(QMouseEvent *event)
 
176
{
 
177
    m_lastGlobalPos = event->globalPos();
 
178
    //kDebug() << m_clickDrag;
 
179
    if (m_clickDrag) {
 
180
        setMouseTracking(false);
 
181
        m_clickDrag = false;
 
182
        m_origin = QPoint();
 
183
        return;
 
184
    }
 
185
 
 
186
    if (!m_applet || event->button() != Qt::LeftButton) {
 
187
        return;
 
188
    }
 
189
 
 
190
    m_clickDrag = false;
 
191
    if (!m_spacer) {
 
192
        m_spacer = new AppletMoveSpacer(m_applet);
 
193
    } else if (m_layout) {
 
194
        m_layout->removeItem(m_spacer);
 
195
    }
 
196
 
 
197
    m_origin = mapToParent(event->pos());
 
198
    m_spacer->setMinimumSize(m_applet->geometry().size());
 
199
    m_spacer->setMaximumSize(m_applet->geometry().size());
 
200
    if (m_layout) {
 
201
        m_layout->removeItem(m_applet);
 
202
        m_layout->insertItem(m_index, m_spacer);
 
203
    }
 
204
    m_applet->raise();
 
205
 
 
206
    if (m_orientation == Qt::Horizontal) {
 
207
        m_offset = geometry().x() - m_origin.x();
 
208
    } else {
 
209
        m_offset = geometry().y() - m_origin.y();
 
210
    }
 
211
 
 
212
    m_dragAction = Move;
 
213
 
 
214
    const int margin = 9;
 
215
    if (m_applet->inherits("PanelSpacer")) {
 
216
        if (m_applet->formFactor() == Plasma::Horizontal) {
 
217
            if (event->pos().x() < margin) {
 
218
                m_dragAction = LeftResize;
 
219
            } else if (event->pos().x() > m_applet->size().width() - margin) {
 
220
                m_dragAction = RightResize;
 
221
            }
 
222
        } else if (m_applet->formFactor() == Plasma::Vertical) {
 
223
            if (event->pos().y() < margin) {
 
224
                m_dragAction = LeftResize;
 
225
            } else if (event->pos().y() > m_applet->size().height() - margin) {
 
226
                m_dragAction = RightResize;
 
227
            }
 
228
        }
 
229
    }
 
230
}
 
231
 
 
232
void PanelAppletOverlay::mouseMoveEvent(QMouseEvent *event)
 
233
{
 
234
    if (!m_layout || !m_applet) {
 
235
        //kDebug() << "no layout";
 
236
        return;
 
237
    }
 
238
 
 
239
    const int margin = 9;
 
240
    if (m_applet->inherits("PanelSpacer")) {
 
241
        if (m_applet->formFactor() == Plasma::Horizontal) {
 
242
            if (event->pos().x() < margin || event->pos().x() > m_applet->size().width() - margin) {
 
243
                setCursor(Qt::SizeHorCursor);
 
244
            } else {
 
245
                setCursor(Qt::ArrowCursor);
 
246
            }
 
247
        } else if (m_applet->formFactor() == Plasma::Vertical) {
 
248
            if (event->pos().y() < margin || event->pos().y() > m_applet->size().height() - margin) {
 
249
                setCursor(Qt::SizeVerCursor);
 
250
            } else {
 
251
                setCursor(Qt::ArrowCursor);
 
252
            }
 
253
        }
 
254
    }
 
255
 
 
256
    if (!m_clickDrag && !(event->buttons() & Qt::LeftButton)) {
 
257
        //kDebug() << "no left button and we aren't click dragging";
 
258
        return;
 
259
    }
 
260
 
 
261
    Plasma::FormFactor f = m_applet->formFactor();
 
262
 
 
263
 
 
264
    if (!m_applet->inherits("PanelSpacer") &&
 
265
          (((f != Plasma::Horizontal && f != Plasma::Vertical) && rect().intersects(m_applet->rect().toRect())) ||
 
266
          ((f == Plasma::Horizontal || f == Plasma::Vertical) && !rect().contains(event->globalPos()))) ) {
 
267
        Plasma::View *view = Plasma::View::topLevelViewAt(event->globalPos());
 
268
        //kDebug() << "checking view" << view << m_applet->view();
 
269
 
 
270
        if (!view) {
 
271
            view = dynamic_cast<Plasma::View*>(parent());
 
272
        }
 
273
 
 
274
        if (!view) {
 
275
            return;
 
276
        }
 
277
 
 
278
        QPointF pos = view->mapFromGlobal(event->globalPos());
 
279
        if (view != m_applet->view() && (event->buttons() & Qt::LeftButton)) {
 
280
            Plasma::Containment *c = view->containment();
 
281
            if (!c) {
 
282
                return;
 
283
            }
 
284
 
 
285
            syncOrientation();
 
286
            syncGeometry();
 
287
 
 
288
            if (m_spacer) {
 
289
                if (m_layout) {
 
290
                    m_layout->removeItem(m_spacer);
 
291
                }
 
292
                m_spacer->deleteLater();
 
293
                m_spacer = 0;
 
294
            }
 
295
 
 
296
            QPointF pos = c->view()->mapFromGlobal(event->globalPos());
 
297
            QRectF g = m_applet->geometry();
 
298
            pos += QPoint(m_offset, m_offset);
 
299
            g.moveTo(pos);
 
300
            m_applet->setGeometry(g);
 
301
            m_layout = 0;
 
302
            c->addApplet(m_applet, pos, true);
 
303
            m_applet->flushPendingConstraintsEvents();
 
304
            m_applet->setPos(pos);
 
305
            releaseMouse();
 
306
            emit moved(this);
 
307
            return;
 
308
        }
 
309
    } else if (m_applet->inherits("PanelSpacer") && m_dragAction != Move) {
 
310
        if (m_applet->formFactor() == Plasma::Horizontal) {
 
311
            if (m_dragAction == LeftResize) {
 
312
                int fixedWidth = m_applet->size().width()+(m_lastGlobalPos.x() - event->globalPos().x());
 
313
                m_applet->setPos(m_applet->pos().x()-(fixedWidth-m_applet->size().width()), m_applet->pos().y());
 
314
                m_applet->setMinimumWidth(fixedWidth);
 
315
                m_applet->setMaximumWidth(fixedWidth);
 
316
            } else if (m_dragAction == RightResize) {
 
317
                int fixedWidth = m_applet->size().width()-(m_lastGlobalPos.x() - event->globalPos().x());
 
318
                m_applet->setMinimumWidth(fixedWidth);
 
319
                m_applet->setMaximumWidth(fixedWidth);
 
320
            }
 
321
        } else if (m_applet->formFactor() == Plasma::Vertical) {
 
322
            if (m_dragAction == LeftResize) {
 
323
                int fixedHeight = m_applet->size().height()+(m_lastGlobalPos.y() - event->globalPos().y());
 
324
                m_applet->setPos(m_applet->pos().x(), m_applet->pos().y()-(fixedHeight-m_applet->size().height()));
 
325
                m_applet->setMinimumHeight(fixedHeight);
 
326
                m_applet->setMaximumHeight(fixedHeight);
 
327
            } else if (m_dragAction == RightResize) {
 
328
                int fixedHeight = m_applet->size().height()-(m_lastGlobalPos.y() - event->globalPos().y());
 
329
                m_applet->setMinimumHeight(fixedHeight);
 
330
                m_applet->setMaximumHeight(fixedHeight);
 
331
            }
 
332
        }
 
333
        m_lastGlobalPos = event->globalPos();
 
334
        return;
 
335
    }
 
336
 
 
337
    if (!m_spacer) {
 
338
        m_spacer = new AppletMoveSpacer(m_applet);
 
339
        m_spacer->setMinimumSize(m_applet->geometry().size());
 
340
        m_spacer->setMaximumSize(m_applet->geometry().size());
 
341
        if (m_layout) {
 
342
            m_layout->removeItem(m_applet);
 
343
            m_layout->insertItem(m_index, m_spacer);
 
344
        }
 
345
    }
 
346
 
 
347
    QPoint p = mapToParent(event->pos());
 
348
    QRectF g = m_applet->geometry();
 
349
 
 
350
    //kDebug() << p << g << "<-- movin'?";
 
351
    if (m_orientation == Qt::Horizontal) {
 
352
        g.moveLeft(p.x() + m_offset);
 
353
    } else {
 
354
        g.moveTop(p.y() + m_offset);
 
355
    }
 
356
 
 
357
    m_applet->setGeometry(g);
 
358
 
 
359
    //FIXME: assumption on how panel containment works, presence of a non applet spacer in last position (if they were swapped would be impossible to save and restore)
 
360
    if ((m_index > 0 && m_layout->itemAt(m_index - 1)) || m_index == 0) {
 
361
        const bool prevIsApplet = dynamic_cast<Plasma::Applet*>(m_layout->itemAt(m_index - 1)) != 0;
 
362
        const bool nextIsApplet = dynamic_cast<Plasma::Applet*>(m_layout->itemAt(m_index + 1)) != 0;
 
363
 
 
364
        QPointF mousePos = event->pos() + g.topLeft();
 
365
 
 
366
        // swap items if we pass completely over the next/previous item or cross
 
367
        // more than halfway across it, whichever comes first
 
368
        if (m_orientation == Qt::Horizontal) {
 
369
            //kDebug() << prevIsApplet << m_prevGeom << g << nextIsApplet << m_nextGeom;
 
370
            if (QApplication::layoutDirection() == Qt::RightToLeft) {
 
371
                if (prevIsApplet && m_prevGeom.isValid() && mousePos.x() >= m_prevGeom.right()) {
 
372
                    swapWithPrevious();
 
373
                } else if (nextIsApplet && m_nextGeom.isValid() && mousePos.x() <= m_nextGeom.left()) {
 
374
                    swapWithNext();
 
375
                }
 
376
            } else if (prevIsApplet && m_prevGeom.isValid() && mousePos.x() <= m_prevGeom.left()) {
 
377
                swapWithPrevious();
 
378
            } else if (nextIsApplet && m_nextGeom.isValid() && mousePos.x() >= m_nextGeom.right()) {
 
379
                swapWithNext();
 
380
            }
 
381
 
 
382
        } else if (prevIsApplet && m_prevGeom.isValid() && mousePos.y() <= m_prevGeom.top()) {
 
383
            swapWithPrevious();
 
384
        } else if (nextIsApplet && m_nextGeom.isValid() && mousePos.y() >= m_nextGeom.bottom()) {
 
385
            swapWithNext();
 
386
        }
 
387
    }
 
388
 
 
389
    m_lastGlobalPos = event->globalPos();
 
390
    //kDebug() << "=================================";
 
391
}
 
392
 
 
393
void PanelAppletOverlay::mouseReleaseEvent(QMouseEvent *event)
 
394
{
 
395
    Q_UNUSED(event)
 
396
    if (!m_spacer || !m_applet) {
 
397
        //kDebug() << "releasing as we don't have a spacer";
 
398
        releaseMouse();
 
399
        setMouseTracking(false);
 
400
        return;
 
401
    }
 
402
 
 
403
    if (!m_origin.isNull()) {
 
404
        //kDebug() << m_clickDrag << m_origin << mapToParent(event->pos());
 
405
        if (m_orientation == Qt::Horizontal) {
 
406
            m_clickDrag = abs(mapToParent(event->pos()).x() - m_origin.x()) < KGlobalSettings::dndEventDelay();
 
407
        } else {
 
408
            m_clickDrag = abs(mapToParent(event->pos()).y() - m_origin.y()) < KGlobalSettings::dndEventDelay();
 
409
        }
 
410
 
 
411
        if (m_clickDrag) {
 
412
            //kDebug() << "click dragging." << this << mouseGrabber();
 
413
            grabMouse();
 
414
            setMouseTracking(true);
 
415
            event->setAccepted(false);
 
416
            return;
 
417
        }
 
418
    }
 
419
 
 
420
    releaseMouse();
 
421
    //kDebug() << "released mouse";
 
422
    if (m_layout) {
 
423
        m_layout->removeItem(m_spacer);
 
424
    }
 
425
 
 
426
    m_spacer->deleteLater();
 
427
    m_spacer = 0;
 
428
 
 
429
    if (m_layout) {
 
430
        m_layout->insertItem(m_index, m_applet);
 
431
    }
 
432
 
 
433
    m_applet->setZValue(m_applet->zValue() - 1);
 
434
}
 
435
 
 
436
void PanelAppletOverlay::handleMousePressed(Plasma::Applet *applet, QMouseEvent *event)
 
437
{
 
438
    if (applet == m_applet) {
 
439
        QMouseEvent ownEvent(event->type(), mapFromGlobal(event->globalPos()), event->globalPos(), event->button(), event->buttons(), event->modifiers());
 
440
        mousePressEvent(&ownEvent);
 
441
    }
 
442
}
 
443
 
 
444
void PanelAppletOverlay::handleMouseMoved(Plasma::Applet *applet, QMouseEvent *event)
 
445
{
 
446
    if (applet == m_applet) {
 
447
        QMouseEvent ownEvent(event->type(), mapFromGlobal(event->globalPos()), event->globalPos(), event->button(), event->buttons(), event->modifiers());
 
448
        mouseMoveEvent(&ownEvent);
 
449
    }
 
450
}
 
451
 
 
452
void PanelAppletOverlay::handleMouseReleased(Plasma::Applet *applet, QMouseEvent *event)
 
453
{
 
454
    if (applet == m_applet) {
 
455
        QMouseEvent ownEvent(event->type(), mapFromGlobal(event->globalPos()), event->globalPos(), event->button(), event->buttons(), event->modifiers());
 
456
        mouseReleaseEvent(&ownEvent);
 
457
    }
 
458
}
 
459
 
 
460
void PanelAppletOverlay::contextMenuEvent(QContextMenuEvent *event)
 
461
{
 
462
    if (m_applet) {
 
463
        Plasma::Containment *c = m_applet->containment();
 
464
        if (c) {
 
465
            c->showContextMenu(mapToParent(event->pos()), event->globalPos());
 
466
        }
 
467
    }
 
468
}
 
469
 
 
470
void PanelAppletOverlay::enterEvent(QEvent *event)
 
471
{
 
472
    Q_UNUSED(event)
 
473
    update();
 
474
    s_appletHandle->setApplet(m_applet);
 
475
}
 
476
 
 
477
void PanelAppletOverlay::leaveEvent(QEvent *event)
 
478
{
 
479
    setCursor(Qt::ArrowCursor);
 
480
    Q_UNUSED(event)
 
481
    s_appletHandle->startHideTimeout();
 
482
    update();
 
483
}
 
484
 
 
485
void PanelAppletOverlay::swapWithPrevious()
 
486
{
 
487
    if (!m_layout) {
 
488
        return;
 
489
    }
 
490
 
 
491
    //kDebug();
 
492
    --m_index;
 
493
 
 
494
    if (m_index > 0) {
 
495
        m_prevGeom = m_layout->itemAt(m_index - 1)->geometry();
 
496
    } else {
 
497
        m_prevGeom = QRectF();
 
498
    }
 
499
 
 
500
    m_nextGeom = m_layout->itemAt(m_index + 1)->geometry();
 
501
    m_layout->removeItem(m_spacer);
 
502
    m_layout->insertItem(m_index, m_spacer);
 
503
    emit moved(this);
 
504
}
 
505
 
 
506
void PanelAppletOverlay::swapWithNext()
 
507
{
 
508
    if (!m_layout) {
 
509
        return;
 
510
    }
 
511
 
 
512
    //kDebug();
 
513
    ++m_index;
 
514
 
 
515
    if (m_index < m_layout->count() - 1) {
 
516
        m_nextGeom = m_layout->itemAt(m_index + 1)->geometry();
 
517
    } else {
 
518
        m_nextGeom = QRectF();
 
519
    }
 
520
 
 
521
    m_prevGeom = m_layout->itemAt(m_index - 1)->geometry();
 
522
    m_layout->removeItem(m_spacer);
 
523
    m_layout->insertItem(m_index, m_spacer);
 
524
    emit moved(this);
 
525
}
 
526
 
 
527
void PanelAppletOverlay::appletDestroyed()
 
528
{
 
529
    m_applet = 0;
 
530
    emit removedWithApplet(this);
 
531
    deleteLater();
 
532
}
 
533
 
 
534
void PanelAppletOverlay::delaySyncGeometry()
 
535
{
 
536
    // we need to do this because it gets called in a round-about-way
 
537
    // from our own mouseMoveEvent. if we call syncGeometry directly,
 
538
    // we end up with a maze of duplicated and confused mouseMoveEvents
 
539
    // of which only half are real (the other half being caused by the
 
540
    // immediate call to syncGeometry!)
 
541
    QTimer::singleShot(0, this, SLOT(syncGeometry()));
 
542
}
 
543
 
 
544
void PanelAppletOverlay::syncGeometry()
 
545
{
 
546
    if (!m_layout || !m_applet) {
 
547
        return;
 
548
    }
 
549
 
 
550
    //kDebug();
 
551
    setGeometry(m_applet->geometry().toRect());
 
552
 
 
553
    if (m_index > 0 && m_layout->itemAt(m_index - 1)) {
 
554
        m_prevGeom = m_layout->itemAt(m_index - 1)->geometry();
 
555
    } else {
 
556
        m_prevGeom = QRectF();
 
557
    }
 
558
 
 
559
    //kDebug() << m_index << m_layout->count();
 
560
    if (m_index < m_layout->count() - 1) {
 
561
        m_nextGeom = m_layout->itemAt(m_index + 1)->geometry();
 
562
    } else {
 
563
        m_nextGeom = QRectF();
 
564
    }
 
565
 
 
566
    if (m_applet->containment() && m_applet->containment()->corona()) {
 
567
        s_appletHandle->move(m_applet->containment()->corona()->popupPosition(m_applet, s_appletHandle->size(), Qt::AlignCenter));
 
568
    }
 
569
}
 
570
 
 
571
void PanelAppletOverlay::syncIndex()
 
572
{
 
573
    if (!m_layout || !m_applet) {
 
574
        m_index = -1;
 
575
        return;
 
576
    }
 
577
 
 
578
    for (int i = 0; i < m_layout->count(); ++i) {
 
579
        QGraphicsWidget *w = dynamic_cast<QGraphicsWidget*>(m_layout->itemAt(i));
 
580
        if (w == m_applet) {
 
581
            m_index = i;
 
582
            break;
 
583
        }
 
584
    }
 
585
}
 
586
 
 
587
void PanelAppletOverlay::syncOrientation()
 
588
{
 
589
    if (!m_applet) {
 
590
        return;
 
591
    }
 
592
 
 
593
    m_orientation = m_applet->formFactor() == Plasma::Horizontal ? Qt::Horizontal : Qt::Vertical;
 
594
}
 
595
 
 
596
Plasma::Applet *PanelAppletOverlay::applet() const
 
597
{
 
598
    return m_applet;
 
599
}
 
600
 
 
601
#include "panelappletoverlay.moc"
 
602