From kde-commits Sat Jul 31 21:51:51 2010 From: Marco Martin Date: Sat, 31 Jul 2010 21:51:51 +0000 To: kde-commits Subject: playground/base/plasma/shells/mobile/containments/mobiledesktop Message-Id: <20100731215151.31426AC7A9 () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=128061305010947 SVN commit 1157696 by mart: a + button that moves around the containment after the last applet, tied to the "add widgets" action M +42 -1 appletscontainer.cpp M +2 -0 appletscontainer.h --- trunk/playground/base/plasma/shells/mobile/containments/mobiledesktop/appletscontainer.cpp #1157695:1157696 @@ -32,15 +32,27 @@ #include #include +#include using namespace Plasma; AppletsContainer::AppletsContainer(QGraphicsItem *parent, Plasma::Containment *containment) : QGraphicsWidget(parent), m_containment(containment), + m_addWidgetsButton(0), m_appletsOverlay(0), m_startupCompleted(false) { + + QAction *a = containment->action("add widgets"); + if (a) { + m_addWidgetsButton = new Plasma::IconWidget(this); + m_addWidgetsButton->setAction(a); + m_addWidgetsButton->setText(QString()); + m_addWidgetsButton->setSvg("widgets/action-overlays", "add-normal"); + m_addWidgetsButton->resize(KIconLoader::SizeMedium, KIconLoader::SizeMedium); + } + m_relayoutTimer = new QTimer(this); m_relayoutTimer->setSingleShot(true); connect(m_relayoutTimer, SIGNAL(timeout()), this, SLOT(relayout())); @@ -101,6 +113,12 @@ void AppletsContainer::relayout() { + if (m_applets.isEmpty()) { + resize(KIconLoader::SizeMedium, KIconLoader::SizeMedium); + m_addWidgetsButton->setPos(0,0); + return; + } + const int squareSize = 350; int columns = qMax(1, (int)m_containment->size().width() / squareSize); int rows = qMax(1, (int)m_containment->size().height() / squareSize); @@ -124,9 +142,32 @@ applet->setGeometry((i%columns)*maximumAppletSize.width() + offset.width(), (i/columns)*maximumAppletSize.height() + offset.height(), appletSize.width(), appletSize.height()); i++; } - resize(size().width(), (ceil((qreal)m_containment->applets().count()/columns))*maximumAppletSize.height()); + + int extraHeight = 0; + + if (m_addWidgetsButton) { + QRectF buttonGeom = m_addWidgetsButton->geometry(); + + if (m_applets.count() % columns != 0) { + QRectF geom = m_applets.last()->geometry(); + geom = QRectF(geom.topRight(), + QSizeF(size().width() - geom.right(), geom.height())); + + buttonGeom.moveCenter(geom.center()); + } else { + QRectF geom(QPointF(0, maximumAppletSize.height() * rows), + QSizeF(size().width(), maximumAppletSize.height())); + buttonGeom.moveCenter(geom.center()); + extraHeight = maximumAppletSize.height(); } + m_addWidgetsButton->setPos(buttonGeom.topLeft()); + + } + + resize(size().width(), (ceil((qreal)m_containment->applets().count()/columns))*maximumAppletSize.height() + extraHeight); +} + void AppletsContainer::resizeEvent(QGraphicsSceneResizeEvent *event) { if (!qFuzzyCompare(event->oldSize().width(), event->newSize().width()) && !m_relayoutTimer->isActive()) { --- trunk/playground/base/plasma/shells/mobile/containments/mobiledesktop/appletscontainer.h #1157695:1157696 @@ -28,6 +28,7 @@ { class Applet; class Containment; + class IconWidget; } class QGraphicsLinearLayout; @@ -71,6 +72,7 @@ private: QGraphicsLinearLayout *m_layout; Plasma::Containment *m_containment; + Plasma::IconWidget *m_addWidgetsButton; QTimer *m_relayoutTimer; QWeakPointer m_currentApplet; AppletsOverlay *m_appletsOverlay;