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

cleanup

svn path=/trunk/KDE/kdelibs/; revision=901264
This commit is contained in:
Ambroz Bizjak 2008-12-24 21:23:27 +00:00
parent 9598dc5982
commit 69eccb04ce
2 changed files with 14 additions and 11 deletions

View File

@ -469,7 +469,6 @@ void AppletHandle::mousePressEvent(QGraphicsSceneMouseEvent *event)
} }
m_resizeGrabPoint = mapToScene(event->pos()); m_resizeGrabPoint = mapToScene(event->pos());
QPointF cursorRelativeToStatic = m_resizeGrabPoint - m_resizeStaticPoint; QPointF cursorRelativeToStatic = m_resizeGrabPoint - m_resizeStaticPoint;
m_aspectResizeOrigRadius = sqrt(pow(cursorRelativeToStatic.x(), 2) + pow(cursorRelativeToStatic.y(), 2));
// rotate // rotate
m_rotateAngleOffset = m_angle - _k_pointAngle(mapToScene(event->pos()) - m_origAppletCenter); m_rotateAngleOffset = m_angle - _k_pointAngle(mapToScene(event->pos()) - m_origAppletCenter);
@ -578,7 +577,7 @@ qreal _k_distanceForPoint(QPointF point)
qreal _k_pointAngle(QPointF in) 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 cosine = in.x()/r;
qreal sine = in.y()/r; qreal sine = in.y()/r;
@ -591,7 +590,7 @@ qreal _k_pointAngle(QPointF in)
QPointF _k_rotatePoint(QPointF in, qreal rotateAngle) 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 cosine = in.x()/r;
qreal sine = in.y()/r; qreal sine = in.y()/r;
@ -688,14 +687,20 @@ void AppletHandle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
qreal sx = newSize.x(); qreal sx = newSize.x();
qreal sy = newSize.y(); qreal sy = newSize.y();
qreal x = ox*(sx*ox+sy*oy)/(pow(ox,2)+pow(oy,2)); qreal x = ox*(sx*ox+sy*oy)/(ox*ox+oy*oy);
qreal y = oy*x/ox; qreal y = (oy/ox)*x;
newSize = QPointF(x, y); newSize = QPointF(x, y);
}
// limit size // limit size, preserve ratio
newSize.rx() = qMin(max.width(), qMax(min.width(), newSize.x())); newSize.rx() = qMin(max.width(), qMax(min.width(), newSize.x()));
newSize.ry() = qMin(max.height(), qMax(min.height(), newSize.y())); 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()));
}
// move center such that the static corner remains in the same place // move center such that the static corner remains in the same place
if (m_buttonsOnRight) { if (m_buttonsOnRight) {

View File

@ -135,8 +135,6 @@ class AppletHandle : public QObject, public QGraphicsItem
// used for resize // used for resize
QPointF m_resizeStaticPoint; QPointF m_resizeStaticPoint;
QPointF m_resizeGrabPoint; QPointF m_resizeGrabPoint;
// used during aspect-ratio preserving resize
qreal m_aspectResizeOrigRadius;
// used for rotate // used for rotate
qreal m_rotateAngleOffset; // applet angle minus cursor angle qreal m_rotateAngleOffset; // applet angle minus cursor angle