~ubuntu-branches/ubuntu/maverick/plasma-mobile/maverick

« back to all changes in this revision

Viewing changes to containments/mobiledesktop/appletscontainer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Belem
  • Date: 2010-08-30 23:41:22 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100830234122-3q94e0vf1qfl4e2c
Tags: 0.0~svn20100830-0ubuntu1
* New svn snapshot, revision 1170070. (LP: #627205)
* Updated Standards-Version to 3.9.1.
* Updated the build-dep kdebase-workspace-dev to >= 4.5.
* Removed the patches kubuntu_02_enable_mobilesystray_build.diff and
  kubuntu_03_add_mobilesystray_to_all_desktops.diff since upstream
  already enables the systray build and it is by default on all
  desktops.
* Switch to dpkg-source 3.0 (quilt) format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include <QGraphicsLinearLayout>
28
28
#include <QGraphicsSceneResizeEvent>
29
29
#include <QTimer>
 
30
#include <QParallelAnimationGroup>
30
31
 
31
32
#include <KIconLoader>
32
33
 
 
34
#include <Plasma/Animation>
33
35
#include <Plasma/Applet>
34
36
#include <Plasma/Containment>
35
37
#include <Plasma/IconWidget>
43
45
   m_appletsOverlay(0),
44
46
   m_startupCompleted(false)
45
47
{
46
 
 
 
48
    setFlag(QGraphicsItem::ItemHasNoContents);
47
49
    QAction *a = containment->action("add widgets");
48
50
    if (a) {
49
51
        m_addWidgetsButton = new Plasma::IconWidget(this);
130
132
    int rows = qMax(1, (int)m_containment->size().height() / squareSize);
131
133
    const QSizeF maximumAppletSize(m_containment->size().width()/columns, m_containment->size().height()/rows);
132
134
 
 
135
    QParallelAnimationGroup *group = new QParallelAnimationGroup(this);
 
136
 
133
137
    int i = 0;
134
138
    foreach (Plasma::Applet *applet, m_applets) {
135
139
        if (applet == m_currentApplet.data()) {
141
145
        appletSize = appletSize.expandedTo(QSize(250, 250));
142
146
        QSizeF offset(QSizeF(maximumAppletSize - appletSize)/2);
143
147
 
144
 
        if ((m_containment->applets().count() - i < columns)  && ((i+1)%columns != 0)) {
145
 
            offset.rwidth() += ((i+1)%columns * maximumAppletSize.width())/2;
 
148
        if ((m_containment->applets().count() - i < columns) &&
 
149
            (i/columns == m_containment->applets().count()/columns) &&
 
150
            ((i+1)%columns != 0)) {
 
151
            offset.rwidth() += ((i+1)%columns * maximumAppletSize.width())/columns;
146
152
        }
147
153
 
148
 
        applet->setGeometry((i%columns)*maximumAppletSize.width() + offset.width(), (i/columns)*maximumAppletSize.height() + offset.height(), appletSize.width(), appletSize.height());
 
154
 
 
155
        const QRectF targetGeom((i%columns)*maximumAppletSize.width() + offset.width(), (i/columns)*maximumAppletSize.height() + offset.height(), appletSize.width(), appletSize.height());
 
156
        Animation *anim = Plasma::Animator::create(Plasma::Animator::GeometryAnimation);
 
157
        anim->setTargetWidget(applet);
 
158
        anim->setProperty("startGeometry", applet->geometry());
 
159
        anim->setProperty("targetGeometry", targetGeom);
 
160
        group->addAnimation(anim);
149
161
        i++;
150
162
    }
151
163
 
 
164
    group->start(QAbstractAnimation::DeleteWhenStopped);
 
165
    connect(group, SIGNAL(finished()), this, SLOT(repositionToolBox()));
 
166
 
 
167
    resize(size().width(), (ceil((qreal)m_containment->applets().count()/columns))*maximumAppletSize.height());
 
168
}
 
169
 
 
170
void AppletsContainer::repositionToolBox()
 
171
{
 
172
    const int squareSize = 350;
 
173
    const int columns = qMax(1, (int)m_containment->size().width() / squareSize);
 
174
    const int rows = qMax(1, (int)m_containment->size().height() / squareSize);
 
175
    const QSizeF maximumAppletSize(m_containment->size().width()/columns, m_containment->size().height()/rows);
 
176
 
152
177
    int extraHeight = 0;
153
178
 
154
179
    if (m_addWidgetsButton) {
169
194
        }
170
195
 
171
196
        m_addWidgetsButton->setPos(buttonGeom.topLeft());
172
 
        
173
197
    }
174
198
 
175
199
    resize(size().width(), (ceil((qreal)m_containment->applets().count()/columns))*maximumAppletSize.height() + extraHeight);
 
200
    m_relayoutTimer->stop();
176
201
}
177
202
 
178
203
void AppletsContainer::resizeEvent(QGraphicsSceneResizeEvent *event)
253
278
    if (m_currentApplet) {
254
279
        const int margin = KIconLoader::SizeHuge;
255
280
 
256
 
        m_currentApplet.data()->setGeometry(mapFromItem(m_containment, m_containment->boundingRect()).boundingRect().adjusted(margin, margin/2, -margin, -margin/2));
 
281
        QRectF targetGeom(mapFromItem(m_containment, m_containment->boundingRect()).boundingRect().adjusted(margin, margin/2, -margin, -margin/2));
 
282
        Animation *anim = Plasma::Animator::create(Plasma::Animator::GeometryAnimation);
 
283
        anim->setTargetWidget(m_currentApplet.data());
 
284
        anim->setProperty("startGeometry", m_currentApplet.data()->geometry());
 
285
        anim->setProperty("targetGeometry", targetGeom);
 
286
        anim->start(QAbstractAnimation::DeleteWhenStopped);
257
287
    }
258
288
 
259
289
    if (m_appletsOverlay) {