void WidgetHandle::mouseMoveEvent(QMouseEvent *e) { if (!(m_widget && m_active && e->buttons() & Qt::LeftButton)) return; e->accept(); QWidget *container = m_widget->parentWidget(); const QPoint rp = container->mapFromGlobal(e->globalPos()); const QPoint d = rp - m_origPressPos; const QRect pr = container->rect(); qdesigner_internal::Grid grid; if (const qdesigner_internal::FormWindowBase *fwb = qobject_cast<const qdesigner_internal::FormWindowBase*>(m_formWindow)) grid = fwb->designerGrid(); switch (m_type) { case LeftTop: { if (rp.x() > pr.width() - 2 * width() || rp.y() > pr.height() - 2 * height()) return; int w = m_origGeom.width() - d.x(); m_geom.setWidth(w); w = grid.widgetHandleAdjustX(w); int h = m_origGeom.height() - d.y(); m_geom.setHeight(h); h = grid.widgetHandleAdjustY(h); const int dx = m_widget->width() - w; const int dy = m_widget->height() - h; trySetGeometry(m_widget, m_widget->x() + dx, m_widget->y() + dy, w, h); } break; case Top: { if (rp.y() > pr.height() - 2 * height()) return; int h = m_origGeom.height() - d.y(); m_geom.setHeight(h); h = grid.widgetHandleAdjustY(h); const int dy = m_widget->height() - h; trySetGeometry(m_widget, m_widget->x(), m_widget->y() + dy, m_widget->width(), h); } break; case RightTop: { if (rp.x() < 2 * width() || rp.y() > pr.height() - 2 * height()) return; int h = m_origGeom.height() - d.y(); m_geom.setHeight(h); h = grid.widgetHandleAdjustY(h); const int dy = m_widget->height() - h; int w = m_origGeom.width() + d.x(); m_geom.setWidth(w); w = grid.widgetHandleAdjustX(w); trySetGeometry(m_widget, m_widget->x(), m_widget->y() + dy, w, h); } break; case Right: { if (rp.x() < 2 * width()) return; int w = m_origGeom.width() + d.x(); m_geom.setWidth(w); w = grid.widgetHandleAdjustX(w); tryResize(m_widget, w, m_widget->height()); } break; case RightBottom: { if (rp.x() < 2 * width() || rp.y() < 2 * height()) return; int w = m_origGeom.width() + d.x(); m_geom.setWidth(w); w = grid.widgetHandleAdjustX(w); int h = m_origGeom.height() + d.y(); m_geom.setHeight(h); h = grid.widgetHandleAdjustY(h); tryResize(m_widget, w, h); } break; case Bottom: { if (rp.y() < 2 * height()) return; int h = m_origGeom.height() + d.y(); m_geom.setHeight(h); h = grid.widgetHandleAdjustY(h); tryResize(m_widget, m_widget->width(), h); } break; case LeftBottom: { if (rp.x() > pr.width() - 2 * width() || rp.y() < 2 * height()) return; int w = m_origGeom.width() - d.x(); m_geom.setWidth(w); w = grid.widgetHandleAdjustX(w); int h = m_origGeom.height() + d.y(); m_geom.setHeight(h); h = grid.widgetHandleAdjustY(h); int dx = m_widget->width() - w; trySetGeometry(m_widget, m_widget->x() + dx, m_widget->y(), w, h); } break; case Left: { if (rp.x() > pr.width() - 2 * width()) return; int w = m_origGeom.width() - d.x(); m_geom.setWidth(w); w = grid.widgetHandleAdjustX(w); const int dx = m_widget->width() - w; trySetGeometry(m_widget, m_widget->x() + dx, m_widget->y(), w, m_widget->height()); } break; default: break; } // end switch m_sel->updateGeometry(); if (LayoutInfo::layoutType(m_formWindow->core(), m_widget) != LayoutInfo::NoLayout) m_formWindow->updateChildSelections(m_widget); }
void SizeHandle::mouseMoveEvent( QMouseEvent *e ) { if ( !widget || ( e->state() & LeftButton ) != LeftButton || !active ) return; QPoint rp = mapFromGlobal( e->globalPos() ); QPoint d = oldPressPos - rp; oldPressPos = rp; QPoint checkPos = widget->parentWidget()->mapFromGlobal( e->globalPos() ); QRect pr = widget->parentWidget()->rect(); // ##### move code around a bit to reduce duplicated code here switch ( dir ) { case LeftTop: { if ( checkPos.x() > pr.width() - 2 * width() || checkPos.y() > pr.height() - 2 * height() ) return; int w = geom.width() + d.x(); geom.setWidth( w ); w = ( w / formWindow->grid().x() ) * formWindow->grid().x(); int h = geom.height() + d.y(); geom.setHeight( h ); h = ( h / formWindow->grid().y() ) * formWindow->grid().y(); int dx = widget->width() - w; int dy = widget->height() - h; trySetGeometry( widget, widget->x() + dx, widget->y() + dy, w, h ); } break; case Top: { if ( checkPos.y() > pr.height() - 2 * height() ) return; int h = geom.height() + d.y(); geom.setHeight( h ); h = ( h / formWindow->grid().y() ) * formWindow->grid().y(); int dy = widget->height() - h; trySetGeometry( widget, widget->x(), widget->y() + dy, widget->width(), h ); } break; case RightTop: { if ( checkPos.x() < 2 * width() || checkPos.y() > pr.height() - 2 * height() ) return; int h = geom.height() + d.y(); geom.setHeight( h ); h = ( h / formWindow->grid().y() ) * formWindow->grid().y(); int dy = widget->height() - h; int w = geom.width() - d.x(); geom.setWidth( w ); w = ( w / formWindow->grid().x() ) * formWindow->grid().x(); trySetGeometry( widget, widget->x(), widget->y() + dy, w, h ); } break; case Right: { if ( checkPos.x() < 2 * width() ) return; int w = geom.width() - d.x(); geom.setWidth( w ); w = ( w / formWindow->grid().x() ) * formWindow->grid().x(); tryResize( widget, w, widget->height() ); } break; case RightBottom: { if ( checkPos.x() < 2 * width() || checkPos.y() < 2 * height() ) return; int w = geom.width() - d.x(); geom.setWidth( w ); w = ( w / formWindow->grid().x() ) * formWindow->grid().x(); int h = geom.height() - d.y(); geom.setHeight( h ); h = ( h / formWindow->grid().y() ) * formWindow->grid().y(); tryResize( widget, w, h ); } break; case Bottom: { if ( checkPos.y() < 2 * height() ) return; int h = geom.height() - d.y(); geom.setHeight( h ); h = ( h / formWindow->grid().y() ) * formWindow->grid().y(); tryResize( widget, widget->width(), h ); } break; case LeftBottom: { if ( checkPos.x() > pr.width() - 2 * width() || checkPos.y() < 2 * height() ) return; int w = geom.width() + d.x(); geom.setWidth( w ); w = ( w / formWindow->grid().x() ) * formWindow->grid().x(); int dx = widget->width() - w; int h = geom.height() - d.y(); geom.setHeight( h ); h = ( h / formWindow->grid().y() ) * formWindow->grid().y(); trySetGeometry( widget, widget->x() + dx, widget->y(), w, h ); } break; case Left: { if ( checkPos.x() > pr.width() - 2 * width() ) return; int w = geom.width() + d.x(); geom.setWidth( w ); w = ( w / formWindow->grid().x() ) * formWindow->grid().x(); int dx = widget->width() - w; trySetGeometry( widget, widget->x() + dx, widget->y(), w, widget->height() ); } break; } QPoint p = pos(); sel->updateGeometry(); oldPressPos += ( p - pos() ); formWindow->sizePreview()->setText( tr( "%1/%2" ).arg( widget->width() ).arg( widget->height() ) ); formWindow->sizePreview()->adjustSize(); QRect lg( formWindow->mapFromGlobal( e->globalPos() ) + QPoint( 16, 16 ), formWindow->sizePreview()->size() ); formWindow->checkPreviewGeometry( lg ); formWindow->sizePreview()->setGeometry( lg ); formWindow->sizePreview()->show(); formWindow->sizePreview()->raise(); if ( WidgetFactory::layoutType( widget ) != WidgetFactory::NoLayout ) formWindow->updateChildSelections( widget ); }