[Panel-devel] Layouts

Petri Damstén petri.damsten at iki.fi
Thu Sep 27 10:43:53 CEST 2007


On Wednesday 26 September 2007 15:18:26 Robert Knight wrote:
> > Shouldn't the widgets be inside the content rect?
>
> Yes, I think the easiest solution would be to reimplement
> setGeometry() inside the Applet class and then take account of the
> border size there.

This duplicates the code from widget and I had to add setSize for the widget, 
but it fixes the problem. Diff also includes fix for the boxlayout. Should I 
commit?

Petri

-- 
printk("VFS: Busy inodes after unmount. "
        "Self-destruct in 5 seconds.  Have a nice day...\n");
        2.3.99-pre8 /usr/src/linux/fs/super.c
-------------- next part --------------
Index: applet.h
===================================================================
--- applet.h	(revision 717592)
+++ applet.h	(working copy)
@@ -67,6 +67,7 @@
     Q_PROPERTY( bool failedToLaunch READ failedToLaunch WRITE setFailedToLaunch )
     Q_PROPERTY( bool needsConfiguring READ needsConfiguring WRITE setNeedsConfiguring )
     Q_PROPERTY( QRectF boundingRect READ boundingRect )
+    Q_PROPERTY( QRectF geometry READ geometry WRITE setGeometry )
 
     public:
         typedef QList<Applet*> List;
@@ -469,9 +470,18 @@
 
         // reimplemented from LayoutItem
         // value is the same as contentSizeHint() if drawStandardBackground() is false
-        // or contentSizeHint() plus the size of the border otherwise. 
+        // or contentSizeHint() plus the size of the border otherwise.
         virtual QSizeF sizeHint() const;
 
+        /**
+        * Sets the geometry of this Applet.
+        */
+        /**
+        * Sets the geometry of this Plasma::Applet
+        * @param geometry the geometry to apply to this Plasma::Applet.
+        */
+        void setGeometry(const QRectF &geometry);
+
     Q_SIGNALS:
         /**
          * Emitted when the applet needs to take (or lose) keyboard focus.
Index: widgets/widget.h
===================================================================
--- widgets/widget.h	(revision 717592)
+++ widgets/widget.h	(working copy)
@@ -256,6 +256,7 @@
      */
     virtual void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
     void contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent);
+    void setSize(const QSizeF& size);
 
 private:
     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
Index: widgets/widget.cpp
===================================================================
--- widgets/widget.cpp	(revision 717592)
+++ widgets/widget.cpp	(working copy)
@@ -222,6 +222,11 @@
     update();
 }
 
+void Widget::setSize(const QSizeF& size)
+{
+    d->size = size;
+}
+
 void Widget::updateGeometry()
 {
     if ( managingLayout() ) {
Index: widgets/boxlayout.cpp
===================================================================
--- widgets/boxlayout.cpp	(revision 717592)
+++ widgets/boxlayout.cpp	(working copy)
@@ -77,27 +77,27 @@
                 Q_ASSERT(false);
                 return Qt::Horizontal;
         }
-    } 
+    }
 
     // returns the position from which layouting should
     // begin depending on the direction of this layout
-    qreal startPos(const QRectF& geometry) const 
+    qreal startPos(const QRectF& geometry) const
     {
         switch ( direction ) {
             case LeftToRight:
             case TopToBottom:
-                return 0;
+                return q->margin();
             case RightToLeft:
-                return geometry.width();
+                return geometry.width() - q->margin();
             case BottomToTop:
-                return geometry.height();
+                return geometry.height() - q->margin();
             default:
                 Q_ASSERT(false);
                 return 0;
         }
     }
 
-    // lays out an item 
+    // lays out an item
     //
     // 'geometry' the geometry of the layout
     // 'item' the item whoose geometry should be altered
Index: applet.cpp
===================================================================
--- applet.cpp	(revision 717592)
+++ applet.cpp	(working copy)
@@ -1073,6 +1073,24 @@
     return QGraphicsItem::itemChange(change, value);
 }
 
+void Applet::setGeometry(const QRectF& geometry)
+{
+    if (size() != geometry.size()) {
+        prepareGeometryChange();
+        qreal width = qBound(minimumSize().width(), geometry.size().width(), maximumSize().width());
+        qreal height = qBound(minimumSize().height(), geometry.size().height(), maximumSize().height());
+
+        setSize(QSizeF(width, height));
+
+        if (layout()) {
+            layout()->setGeometry(QRectF(QPoint(0, 0), contentSize()));
+        }
+    }
+
+    setPos(geometry.topLeft());
+    update();
+}
+
 void Applet::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
 {
     //kDebug() << "context menu event!";
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://mail.kde.org/pipermail/panel-devel/attachments/20070927/12ce29f8/attachment-0001.pgp 


More information about the Panel-devel mailing list