void ShapeResizeStrategy::handleCustomEvent( KoPointerEvent * event ) { QPointF center = 0.5 * QPointF( m_initialSize.width(), m_initialSize.height() ); qreal zoom = pow(1.01, -0.1 * event->z() ); m_lastScale *= zoom; resizeBy( center, m_lastScale.x(), m_lastScale.y() ); }
void ShapeResizeStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardModifiers modifiers) { tool()->canvas()->updateCanvas(tool()->canvas()->snapGuide()->boundingRect()); QPointF newPos = tool()->canvas()->snapGuide()->snap( point, modifiers ); tool()->canvas()->updateCanvas(tool()->canvas()->snapGuide()->boundingRect()); bool keepAspect = modifiers & Qt::ShiftModifier; foreach(KoShape *shape, m_selectedShapes) keepAspect = keepAspect || shape->keepAspectRatio(); qreal startWidth = m_initialSize.width(); if (startWidth < std::numeric_limits<qreal>::epsilon()) startWidth = std::numeric_limits<qreal>::epsilon(); qreal startHeight = m_initialSize.height(); if (startHeight < std::numeric_limits<qreal>::epsilon()) startHeight = std::numeric_limits<qreal>::epsilon(); QPointF distance = m_unwindMatrix.map(newPos) - m_unwindMatrix.map( m_start ); // guard against resizing zero width shapes, which would result in huge zoom factors if (m_initialSize.width() < std::numeric_limits<qreal>::epsilon()) { distance.rx() = 0.0; } // guard against resizing zero height shapes, which would result in huge zoom factors if (m_initialSize.height() < std::numeric_limits<qreal>::epsilon()) { distance.ry() = 0.0; } const bool scaleFromCenter = modifiers & Qt::ControlModifier; if (scaleFromCenter) { distance *= 2.0; } qreal zoomX=1, zoomY=1; if (m_left) zoomX = (startWidth - distance.x()) / startWidth; else if (m_right) zoomX = (startWidth + distance.x()) / startWidth; if (m_top) zoomY = (startHeight - distance.y()) / startHeight; else if (m_bottom) zoomY = (startHeight + distance.y()) / startHeight; if (keepAspect) { const bool cornerUsed = ((m_bottom?1:0) + (m_top?1:0) + (m_left?1:0) + (m_right?1:0)) == 2; if ((cornerUsed && startWidth < startHeight) || m_left || m_right) zoomY = zoomX; else zoomX = zoomY; } QPointF move; if (scaleFromCenter) move = QPointF(startWidth / 2.0, startHeight / 2.0); else move = QPointF(m_left?startWidth:0, m_top?startHeight:0); resizeBy( move, zoomX, zoomY ); }
void CQIllustratorShape:: resizeTo(double w, double h) { const CBBox2D &bbox = getFlatBBox(); double dw = w - bbox.getWidth (); double dh = h - bbox.getHeight(); resizeBy(dw, dh); }
void Selection::mouseMoveEvent(QGraphicsSceneMouseEvent * event) { if(isReadOnly()) return; QPointF move_delta = event->pos() - event->lastPos(); if(isResizing()) resizeBy(move_delta); else moveBy(move_delta); event->accept(); }
void AnimatedSplitter::addWidget( AnimatedWidget* widget ) { QSplitter::addWidget( widget ); connect( widget, SIGNAL( showWidget() ), SLOT( onShowRequest() ) ); connect( widget, SIGNAL( hideWidget() ), SLOT( onHideRequest() ) ); connect( widget, SIGNAL( sizeHintChanged( QSize ) ), SLOT( onShowRequest() ) ); connect( widget, SIGNAL( sizeChanged( QSize ) ), SLOT( onSizeChanged( QSize ) ) ); connect( widget, SIGNAL( resizeBy( QPoint ) ), SLOT( onResizeRequest( QPoint ) ) ); connect( this, SIGNAL( shown( QWidget*, bool ) ), widget, SLOT( onShown( QWidget*, bool ) ) ); connect( this, SIGNAL( hidden( QWidget*, bool ) ), widget, SLOT( onHidden( QWidget*, bool ) ) ); }
void ShapeResizeStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardModifiers modifiers) { tool()->canvas()->updateCanvas(tool()->canvas()->snapGuide()->boundingRect()); QPointF newPos = tool()->canvas()->snapGuide()->snap( point, modifiers ); tool()->canvas()->updateCanvas(tool()->canvas()->snapGuide()->boundingRect()); bool keepAspect = modifiers & Qt::ShiftModifier; foreach(KoShape *shape, m_selectedShapes) keepAspect = keepAspect || shape->keepAspectRatio(); qreal startWidth = m_initialSize.width(); if (startWidth < std::numeric_limits<qreal>::epsilon()) startWidth = std::numeric_limits<qreal>::epsilon(); qreal startHeight = m_initialSize.height(); if (startHeight < std::numeric_limits<qreal>::epsilon()) startHeight = std::numeric_limits<qreal>::epsilon(); QPointF distance = m_unwindMatrix.map(newPos) - m_unwindMatrix.map( m_start ); // guard against resizing zero width shapes, which would result in huge zoom factors if (m_initialSize.width() < std::numeric_limits<qreal>::epsilon()) { distance.rx() = 0.0; } // guard against resizing zero height shapes, which would result in huge zoom factors if (m_initialSize.height() < std::numeric_limits<qreal>::epsilon()) { distance.ry() = 0.0; } const bool scaleFromCenter = modifiers & Qt::ControlModifier; if (scaleFromCenter) { distance *= 2.0; } qreal newWidth = startWidth; qreal newHeight = startHeight; if (m_left) { newWidth = startWidth - distance.x(); } else if (m_right) { newWidth = startWidth + distance.x(); } if (m_top) { newHeight = startHeight - distance.y(); } else if (m_bottom) { newHeight = startHeight + distance.y(); } /** * Do not let a shape be less than 1px in size in current view * coordinates. If the user wants it to be smaller, he can just * zoom-in a bit. */ QSizeF minViewSize(1.0, 1.0); QSizeF minDocSize = tool()->canvas()->viewConverter()->viewToDocument(minViewSize); if (qAbs(newWidth) < minDocSize.width()) { int sign = newWidth >= 0.0 ? 1 : -1; // zero -> '1' newWidth = sign * minDocSize.width(); } if (qAbs(newHeight) < minDocSize.height()) { int sign = newHeight >= 0.0 ? 1 : -1; // zero -> '1' newHeight = sign * minDocSize.height(); } qreal zoomX = newWidth / startWidth; qreal zoomY = newHeight / startHeight; if (keepAspect) { const bool cornerUsed = ((m_bottom?1:0) + (m_top?1:0) + (m_left?1:0) + (m_right?1:0)) == 2; if ((cornerUsed && startWidth < startHeight) || m_left || m_right) zoomY = zoomX; else zoomX = zoomY; } QPointF move; if (scaleFromCenter) move = QPointF(startWidth / 2.0, startHeight / 2.0); else move = QPointF(m_left?startWidth:0, m_top?startHeight:0); resizeBy( move, zoomX, zoomY ); }