From 7fa8e8e1c0b9a79483d4af9e3ba06ca87001a5f6 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Tue, 27 Nov 2007 23:14:49 +0000 Subject: [PATCH] respect min and max sizes svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=742405 --- applethandle.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/applethandle.cpp b/applethandle.cpp index 84f93f0a9..a72d7ba08 100644 --- a/applethandle.cpp +++ b/applethandle.cpp @@ -303,10 +303,26 @@ void AppletHandle::mouseMoveEvent(QGraphicsSceneMouseEvent *event) m_angle = m_angle - remainder(m_originalAngle+m_angle, snapAngle); } - m_scale = _k_distanceForPoint(event->pos()-center) / _k_distanceForPoint(pressPos-center); + qreal newScale = _k_distanceForPoint(event->pos()-center) / _k_distanceForPoint(pressPos-center); - if (qAbs(m_scale-1.0)<=0.1) { - m_scale = 1.0; + if (qAbs(newScale-1.0)<=0.1) { + newScale = 1.0; + } + + qreal w = m_applet->size().width(); + qreal h = m_applet->size().height(); + QSizeF min = m_applet->minimumSize(); + QSizeF max = m_applet->maximumSize(); + + //FIXME: this code will only work if we are keeping the aspect ratio, as we currently do + // as it resets only on the width, which will break if we allow resizing of width + // and height independantly + if (newScale * w < min.width() || newScale * h < min.height()) { + m_scale = min.width() / w; + } else if (newScale * w > max.width() && newScale * h > max.height()) { + m_scale = max.width() / w; + } else { + m_scale = newScale; } QTransform matrix;