[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/base/plasma/shells/mobile/containments/mobiledesktop
From:       Marco Martin <notmart () gmail ! com>
Date:       2010-12-06 16:58:43
Message-ID: 20101206165843.61204AC8A4 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1204294 by mart:

a configurable horizontal mode, now the default


 M  +71 -9     appletscontainer.cpp  
 M  +4 -0      appletscontainer.h  
 M  +20 -0     appletsview.cpp  
 M  +3 -0      appletsview.h  
 M  +7 -0      mobiledesktop.cpp  
 M  +1 -0      mobiledesktop.h  


--- trunk/playground/base/plasma/shells/mobile/containments/mobiledesktop/appletscontainer.cpp \
#1204293:1204294 @@ -83,7 +83,8 @@
    m_containment(containment),
    m_toolBox(0),
    m_appletsOverlay(0),
-   m_startupCompleted(false)
+   m_startupCompleted(false),
+   m_orientation(Qt::Horizontal)
 {
     setFlag(QGraphicsItem::ItemHasNoContents);
 
@@ -108,6 +109,21 @@
 {
 }
 
+void AppletsContainer::setOrientation(const Qt::Orientation orientation)
+{
+    if (m_orientation == orientation) {
+        return;
+    }
+
+    m_orientation = orientation;
+    relayout();
+}
+
+Qt::Orientation AppletsContainer::orientation() const
+{
+    return m_orientation;
+}
+
 Plasma::Containment *AppletsContainer::containment() const
 {
     return m_containment;
@@ -179,7 +195,9 @@
     int rows = qMax(1, (int)m_containment->size().height() / squareSize);
     const QSizeF maximumAppletSize(m_containment->size().width()/columns, \
m_containment->size().height()/rows);  
+#ifndef NO_ANIMATIONS
     QParallelAnimationGroup *group = new QParallelAnimationGroup(this);
+#endif
 
     int i = 0;
     foreach (Plasma::Applet *applet, m_applets) {
@@ -193,6 +211,8 @@
         appletSize = appletSize.expandedTo(QSize(250, 250));
         QSizeF offset(QSizeF(maximumAppletSize - appletSize)/2);
 
+        QRectF targetGeom;
+        if (m_orientation == Qt::Vertical) {
         if ((m_containment->applets().count() - i < columns) &&
             (i/columns == m_containment->applets().count()/columns) &&
             ((i+1)%columns != 0)) {
@@ -200,7 +220,17 @@
         }
 
 
-        const QRectF targetGeom((i%columns)*maximumAppletSize.width() + \
offset.width(), (i/columns)*maximumAppletSize.height() + offset.height(), \
appletSize.width(), appletSize.height()); +            targetGeom = \
QRectF((i%columns)*maximumAppletSize.width() + offset.width(), \
(i/columns)*maximumAppletSize.height() + offset.height(), appletSize.width(), \
appletSize.height()); +        } else {
+            if ((m_containment->applets().count() - i < rows) &&
+                (i/rows == m_containment->applets().count()/rows) &&
+                ((i+1)%rows != 0)) {
+                offset.rheight() += ((i+1)%rows * maximumAppletSize.height())/rows;
+            }
+
+
+            targetGeom = QRectF((i/rows)*maximumAppletSize.width() + offset.width(), \
(i%rows)*maximumAppletSize.height() + offset.height(), appletSize.width(), \
appletSize.height()); +        }
 #ifndef NO_ANIMATIONS
         Animation *anim = \
Plasma::Animator::create(Plasma::Animator::GeometryAnimation);  \
anim->setTargetWidget(applet); @@ -213,16 +243,23 @@
         i++;
     }
 
+    if (m_orientation == Qt::Vertical) {
+        resize(size().width(),
+            (ceil((qreal)m_containment->applets().count()/columns))
+                * (maximumAppletSize.height() + \
(m_applets.count()%2==0?maximumAppletSize.height():0))); +    } else {
+        resize((ceil((qreal)m_containment->applets().count()/rows))
+                * (maximumAppletSize.width() + \
(m_applets.count()%2==0?maximumAppletSize.width():0)), +                \
size().height() +              );
+    }
+
 #ifndef NO_ANIMATIONS
     group->start(QAbstractAnimation::DeleteWhenStopped);
     connect(group, SIGNAL(finished()), this, SLOT(repositionToolBox()));
 #else
     repositionToolBox();
 #endif
-
-    resize(size().width(),
-           (ceil((qreal)m_containment->applets().count()/columns))
-            * (maximumAppletSize.height() + \
(m_applets.count()%2==0?maximumAppletSize.height():0)));  }
 
 void AppletsContainer::repositionToolBox()
@@ -232,11 +269,12 @@
     const int rows = qMax(1, (int)m_containment->size().height() / squareSize);
     const QSizeF maximumAppletSize(m_containment->size().width()/columns, \
m_containment->size().height()/rows);  
-    int extraHeight = 0;
 
     if (m_toolBox) {
+        int extraHeight = 0;
         QRectF buttonGeom = m_toolBox->geometry();
 
+        if (m_orientation == Qt::Vertical) {
         if (m_applets.count() % columns != 0) {
             QRectF geom = m_applets.last()->geometry();
             geom = QRectF(geom.topRight(),
@@ -252,15 +290,39 @@
         }
 
         m_toolBox->setPos(buttonGeom.topLeft());
+
+            resize(size().width(), \
(ceil((qreal)m_containment->applets().count()/columns))*maximumAppletSize.height() + \
extraHeight); +        } else {
+            int extraWidth = 0;
+            if (m_applets.count() % rows != 0) {
+                QRectF geom = m_applets.last()->geometry();
+                geom = QRectF(geom.bottomLeft(),
+                            QSizeF(geom.width(), size().height() - geom.bottom()));
+
+                buttonGeom.moveCenter(geom.center());
+            } else {
+                QRectF geom(QPointF(maximumAppletSize.width() * (m_applets.count() / \
rows), 0), +                            QSizeF(maximumAppletSize.width(), \
size().height())); +
+                buttonGeom.moveCenter(geom.center());
+                extraWidth = maximumAppletSize.width();
     }
 
-    resize(size().width(), \
(ceil((qreal)m_containment->applets().count()/columns))*maximumAppletSize.height() + \
extraHeight); +            m_toolBox->setPos(buttonGeom.topLeft());
+
+            resize((ceil((qreal)m_containment->applets().count()/rows))*maximumAppletSize.width() \
+ extraWidth, +                   size().height());
+        }
+    }
+
     m_relayoutTimer->stop();
 }
 
 void AppletsContainer::resizeEvent(QGraphicsSceneResizeEvent *event)
 {
-    if (!qFuzzyCompare(event->oldSize().width(), event->newSize().width()) && \
!m_relayoutTimer->isActive()) { +    if (((m_orientation == Qt::Vertical && \
!qFuzzyCompare(event->oldSize().width(), event->newSize().width())) || +         \
(m_orientation == Qt::Horizontal && !qFuzzyCompare(event->oldSize().height(), \
event->newSize().height()))) +        && !m_relayoutTimer->isActive()) {
         m_relayoutTimer->start(300);
     }
 
--- trunk/playground/base/plasma/shells/mobile/containments/mobiledesktop/appletscontainer.h \
#1204293:1204294 @@ -59,6 +59,9 @@
 
     void completeStartup();
 
+    void setOrientation(const Qt::Orientation orientation);
+    Qt::Orientation orientation() const;
+
 public Q_SLOTS:
     void layoutApplet(Plasma::Applet *applet, const QPointF &post);
     void appletRemoved(Plasma::Applet*);
@@ -86,6 +89,7 @@
     //used only at restore, then thrown away
     QMap<int, Plasma::Applet *>m_startingApplets;
     bool m_startupCompleted;
+    Qt::Orientation m_orientation;
 };
 
 #endif
--- trunk/playground/base/plasma/shells/mobile/containments/mobiledesktop/appletsview.cpp \
#1204293:1204294 @@ -54,13 +54,33 @@
 {
     m_appletsContainer = appletsContainer;
     setWidget(appletsContainer);
+    if (appletsContainer->orientation() == Qt::Vertical) {
+        appletsContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+    } else {
+        appletsContainer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
 }
+}
 
 AppletsContainer *AppletsView::appletsContainer() const
 {
     return m_appletsContainer;
 }
 
+void AppletsView::setOrientation(const Qt::Orientation orientation)
+{
+    m_appletsContainer->setOrientation(orientation);
+    if (m_appletsContainer->orientation() == Qt::Vertical) {
+        m_appletsContainer->setSizePolicy(QSizePolicy::Expanding, \
QSizePolicy::Fixed); +    } else {
+        m_appletsContainer->setSizePolicy(QSizePolicy::Fixed, \
QSizePolicy::Expanding); +    }
+}
+
+Qt::Orientation AppletsView::orientation() const
+{
+    return m_appletsContainer->orientation();
+}
+
 void AppletsView::appletDragRequested()
 {
     m_movingApplets = true;
--- trunk/playground/base/plasma/shells/mobile/containments/mobiledesktop/appletsview.h \
#1204293:1204294 @@ -45,6 +45,9 @@
     void setAppletsContainer(AppletsContainer *appletsContainer);
     AppletsContainer *appletsContainer() const;
 
+    void setOrientation(const Qt::Orientation orientation);
+    Qt::Orientation orientation() const;
+
 protected Q_SLOTS:
     void appletDragRequested();
     void scrollTimeout();
--- trunk/playground/base/plasma/shells/mobile/containments/mobiledesktop/mobiledesktop.cpp \
#1204293:1204294 @@ -70,8 +70,15 @@
     setAcceptsHoverEvents(false);
     setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
     setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, false);
+    configChanged();
 }
 
+void MobileDesktop::configChanged()
+{
+    KConfigGroup cg = config();
+    m_appletsView->setOrientation((Qt::Orientation)cg.readEntry("Orientation", \
(int)Qt::Horizontal)); +}
+
 void MobileDesktop::constraintsEvent(Plasma::Constraints constraints)
 {
     if (constraints & Plasma::SizeConstraint) {
--- trunk/playground/base/plasma/shells/mobile/containments/mobiledesktop/mobiledesktop.h \
#1204293:1204294 @@ -42,6 +42,7 @@
     void init();
 
     void constraintsEvent(Plasma::Constraints constraints);
+    void configChanged();
 
 protected:
     void dragEnterEvent(QGraphicsSceneDragDropEvent *event);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic