- } else {
- switch (getMode(event->scenePos().toPoint())) {
- case ResizeTopLeft:
- case ResizeBottomRight:
- emit setCursor(QCursor(Qt::SizeFDiagCursor));
- break;
- case ResizeTopRight:
- case ResizeBottomLeft:
- emit setCursor(QCursor(Qt::SizeBDiagCursor));
- break;
- case ResizeTop:
- case ResizeBottom:
- emit setCursor(QCursor(Qt::SizeVerCursor));
- break;
- case ResizeLeft:
- case ResizeRight:
- emit setCursor(QCursor(Qt::SizeHorCursor));
- break;
- case Move:
- emit setCursor(QCursor(Qt::OpenHandCursor));
- break;
- default:
- emit setCursor(QCursor(Qt::ArrowCursor));
- break;
+
+ // Keep aspect ratio
+ if (event->modifiers() == Qt::ControlModifier) {
+ // compare to rect during mouse press:
+ // if we subtract rect() we'll get a whole lot of flickering
+ // because of diffWidth > diffHeight changing all the time
+ int diffWidth = qAbs(r.width() - m_oldRect.width());
+ int diffHeight = qAbs(r.height() - m_oldRect.height());
+
+ if (diffHeight != 0 || diffWidth != 0) {
+ if (diffWidth > diffHeight)
+ r.setBottom(r.width() / m_dar);
+ else
+ r.setRight(r.height() * m_dar);
+
+ // the rect's position changed
+ if (p - pos() != QPointF()) {
+ if (diffWidth > diffHeight) {
+ if (m_mode != ResizeBottomLeft)
+#if QT_VERSION >= 0x040600
+ setY(p.y() - r.height() + rect().normalized().height());
+#else
+ setPos(x(), p.y() - r.height() + rect().normalized().height());
+#endif
+ } else {
+ if (m_mode != ResizeTopRight)
+#if QT_VERSION >= 0x040600
+ setX(p.x() - r.width() + rect().normalized().width());
+#else
+ setPos(p.x() - r.width() + rect().normalized().width(), y());
+#endif
+ }
+ }
+ }