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

List:       kde-commits
Subject:    KDE/kdelibs/plasma/private
From:       Ambroz Bizjak <ambro () b4ever ! net>
Date:       2008-12-24 21:23:28
Message-ID: 1230153808.417873.10556.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 901264 by abizjak:

Make sure aspect ratio is preserved when size limits are hit, minor 
cleanup


 M  +14 -9     applethandle.cpp  
 M  +0 -2      applethandle_p.h  


--- trunk/KDE/kdelibs/plasma/private/applethandle.cpp #901263:901264
@@ -469,7 +469,6 @@
             }
             m_resizeGrabPoint = mapToScene(event->pos());                
             QPointF cursorRelativeToStatic = m_resizeGrabPoint - \
                m_resizeStaticPoint;
-            m_aspectResizeOrigRadius = sqrt(pow(cursorRelativeToStatic.x(), 2) + \
pow(cursorRelativeToStatic.y(), 2));  
             // rotate
             m_rotateAngleOffset = m_angle - _k_pointAngle(mapToScene(event->pos()) - \
m_origAppletCenter); @@ -578,7 +577,7 @@
 
 qreal _k_pointAngle(QPointF in)
 {
-    qreal r = sqrt(pow(in.x(), 2) + pow(in.y(), 2));
+    qreal r = sqrt(in.x()*in.x() + in.y()*in.y());
     qreal cosine = in.x()/r;
     qreal sine = in.y()/r;
 
@@ -591,7 +590,7 @@
 
 QPointF _k_rotatePoint(QPointF in, qreal rotateAngle)
 {
-    qreal r = sqrt(pow(in.x(), 2) + pow(in.y(), 2));
+    qreal r = sqrt(in.x()*in.x() + in.y()*in.y());
     qreal cosine = in.x()/r;
     qreal sine = in.y()/r;
 
@@ -688,15 +687,21 @@
                 qreal sx = newSize.x();
                 qreal sy = newSize.y();
 
-                qreal x = ox*(sx*ox+sy*oy)/(pow(ox,2)+pow(oy,2));
-                qreal y = oy*x/ox;
+                qreal x = ox*(sx*ox+sy*oy)/(ox*ox+oy*oy);
+                qreal y = (oy/ox)*x;
                 newSize = QPointF(x, y);
+
+                // limit size, preserve ratio
+                newSize.rx() = qMin(max.width(), qMax(min.width(), newSize.x()));
+                newSize.ry() = newSize.x()*(oy/ox);
+                newSize.ry() = qMin(max.height(), qMax(min.height(), newSize.y()));
+                newSize.rx() = newSize.y()/(oy/ox);
+            } else {
+                // limit size
+                newSize.rx() = qMin(max.width(), qMax(min.width(), newSize.x()));
+                newSize.ry() = qMin(max.height(), qMax(min.height(), newSize.y()));
             }
 
-            // limit size
-            newSize.rx() = qMin(max.width(), qMax(min.width(), newSize.x()));
-            newSize.ry() = qMin(max.height(), qMax(min.height(), newSize.y()));
-
             // move center such that the static corner remains in the same place
             if (m_buttonsOnRight) {
                 newCenter =  _k_rotatePoint(QPointF(rStaticPoint.x() + \
                newSize.x()/2, rStaticPoint.y() - newSize.y()/2), m_angle);
--- trunk/KDE/kdelibs/plasma/private/applethandle_p.h #901263:901264
@@ -135,8 +135,6 @@
         // used for resize
         QPointF m_resizeStaticPoint;
         QPointF m_resizeGrabPoint;
-        // used during aspect-ratio preserving resize
-        qreal m_aspectResizeOrigRadius;
         // used for rotate
         qreal m_rotateAngleOffset; // applet angle minus cursor angle
 


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

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