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

List:       kde-panel-devel
Subject:    Re: [PATCH] Re: Applet positions
From:       Ivan =?utf-8?B?xIx1a2nEhw==?= <ivan.cukic () gmail ! com>
Date:       2008-03-25 8:54:19
Message-ID: 200803250954.23256.ivan.cukic () gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


> one thing i would request, however, is adding a comment that explains what
> is going on. it's not going to be immediately apparent to most people what
> you were thinking, so for maintainability a comment is pretty much required
> here.

You mean something like "we are multiplying newGeometry.left() with the 
subtracted newSize.width() from geometry().width()...

Just joking :)

Here's the fixed patch - with comments and a small fix (I always forget that 
the layout is not a parenting element so that it has it's own topLeft location 
which doesn't need to be 0,0)

If nobody complains, I'll commit it later today...

-- 
Those people who think they know everything are a great annoyance to those of 
us who do.
   -- Isaac Asimov


["freelayout-relative.diff" (text/x-patch)]

Index: layouts/freelayout.cpp
===================================================================
--- layouts/freelayout.cpp	(revision 789112)
+++ layouts/freelayout.cpp	(working copy)
@@ -94,12 +94,57 @@
 {
     foreach (LayoutItem *child , d->children) {
         if (child->geometry().size() != child->sizeHint()) {
+            /*
+             * We are setting the new geometry to have the desired size (sizeHint()),
+             * and we are changing the position of the topLeft corner so that the
+             * ratio
+             *    d(widgetLeft, layoutLeft) / d(widgetRight, layoutRight)
+             * is kept constant (where d(X,Y) is the distance between X and Y)
+             *
+             * The same goes for the vertical distances.
+             */
+
             const QSizeF newSize = child->sizeHint().expandedTo(minimumSize()).boundedTo(maximumSize());
-            child->setGeometry(QRectF(child->geometry().topLeft(), newSize));
+
+            /*
+             * Since the layout doesn't have to be originated at (0, 0), we are switching
+             * to local coordinates.
+             */
+            QRectF newGeometry = QRectF(child->geometry().topLeft() - geometry().topLeft(), newSize);
+
+            /*
+             * newWidgetLeft   layoutWidth - newWidgetWidth
+             * ------------- = ----------------------------
+             * oldWidgetLeft   layoutWidth - oldWidgetWidth
+             */
+            newGeometry.moveLeft(
+                    newGeometry.left() *
+                    (geometry().width() - newSize.width()) /
+                    (geometry().width() - child->size().width())
+            );
+
+            /*
+             * newWidgetTop   layoutHeight - newWidgetHeight
+             * ------------ = ------------------------------
+             * oldWidgetTop   layoutHeight - oldWidgetHeight
+             */
+            newGeometry.moveTop(
+                    newGeometry.top() *
+                    (geometry().height() - newSize.height()) /
+                    (geometry().height() - child->size().height())
+            );
+
+            /*
+             * Moving back from local coordinates to global
+             */
+            newGeometry.moveTopLeft(newGeometry.topLeft() + geometry().topLeft());
+
+            child->setGeometry(newGeometry);
         }
     }
 }
 
+
 void FreeLayout::releaseManagedItems()
 {
     foreach (LayoutItem *item, d->children) {
Index: layouts/freelayout.h
===================================================================
--- layouts/freelayout.h	(revision 789112)
+++ layouts/freelayout.h	(working copy)
@@ -35,7 +35,8 @@
  * to determine their own size.
  *
  * Whenever this layout is updated, all child items are resized to
- * their sizeHint() and left in their existing positions.
+ * their sizeHint() and left in their existing positions relative
+ * to the layout borders.
  */
 class PLASMA_EXPORT FreeLayout : public Layout
 {

["signature.asc" (application/pgp-signature)]

_______________________________________________
Panel-devel mailing list
Panel-devel@kde.org
https://mail.kde.org/mailman/listinfo/panel-devel


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

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