void RegionGrabber::resizeEvent( QResizeEvent* e ) { Q_UNUSED( e ); if ( selection.isNull() ) return; QRect r = selection; r.setTopLeft( limitPointToRect( r.topLeft(), rect() ) ); r.setBottomRight( limitPointToRect( r.bottomRight(), rect() ) ); if ( r.width() <= 1 || r.height() <= 1 ) //this just results in ugly drawing... r = QRect(); selection = r; }
void RegionGrab::resizeEvent(QResizeEvent *event) { Q_UNUSED( event ); if (m_selection.isNull()) return; QRect r = m_selection; r.setTopLeft(limitPointToRect(r.topLeft(), rect())); r.setBottomRight(limitPointToRect(r.bottomRight(), rect())); if (r.width() <= 1 || r.height() <= 1) //this just results in ugly drawing... m_selection = QRect(); else m_selection = normalizeSelection(r); }
void RegionGrabber::mouseMoveEvent( QMouseEvent* e ) { bool shouldShowHelp = !helpTextRect.contains( e->pos() ); if (shouldShowHelp != showHelp) { showHelp = shouldShowHelp; update(); } if ( mouseDown ) { if ( newSelection ) { QPoint p = e->pos(); QRect r = rect(); selection = normalizeSelection(QRect( dragStartPoint, limitPointToRect( p, r ) )); } else if ( mouseOverHandle == 0 ) // moving the whole selection { QRect r = rect().normalized(), s = selectionBeforeDrag.normalized(); QPoint p = s.topLeft() + e->pos() - dragStartPoint; r.setBottomRight( r.bottomRight() - QPoint( s.width(), s.height() ) + QPoint( 1, 1 ) ); if ( !r.isNull() && r.isValid() ) selection.moveTo( limitPointToRect( p, r ) ); } else // dragging a handle { QRect r = selectionBeforeDrag; QPoint offset = e->pos() - dragStartPoint; if ( mouseOverHandle == &TLHandle || mouseOverHandle == &THandle || mouseOverHandle == &TRHandle ) // dragging one of the top handles { r.setTop( r.top() + offset.y() ); } if ( mouseOverHandle == &TLHandle || mouseOverHandle == &LHandle || mouseOverHandle == &BLHandle ) // dragging one of the left handles { r.setLeft( r.left() + offset.x() ); } if ( mouseOverHandle == &BLHandle || mouseOverHandle == &BHandle || mouseOverHandle == &BRHandle ) // dragging one of the bottom handles { r.setBottom( r.bottom() + offset.y() ); } if ( mouseOverHandle == &TRHandle || mouseOverHandle == &RHandle || mouseOverHandle == &BRHandle ) // dragging one of the right handles { r.setRight( r.right() + offset.x() ); } r.setTopLeft( limitPointToRect( r.topLeft(), rect() ) ); r.setBottomRight( limitPointToRect( r.bottomRight(), rect() ) ); selection = normalizeSelection(r); } update(); } else { if ( selection.isNull() ) return; bool found = false; foreach( QRect* r, handles ) { if ( r->contains( e->pos() ) ) { mouseOverHandle = r; found = true; break; } } if ( !found ) { mouseOverHandle = 0; if ( selection.contains( e->pos() ) ) setCursor( Qt::OpenHandCursor ); else setCursor( Qt::CrossCursor ); } else { if ( mouseOverHandle == &TLHandle || mouseOverHandle == &BRHandle ) setCursor( Qt::SizeFDiagCursor ); if ( mouseOverHandle == &TRHandle || mouseOverHandle == &BLHandle ) setCursor( Qt::SizeBDiagCursor ); if ( mouseOverHandle == &LHandle || mouseOverHandle == &RHandle ) setCursor( Qt::SizeHorCursor ); if ( mouseOverHandle == &THandle || mouseOverHandle == &BHandle ) setCursor( Qt::SizeVerCursor ); } } }
void RegionGrab::mouseMoveEvent(QMouseEvent *event) { const bool shouldShowHelp = !m_helpTextRect.contains(event->pos()); if (shouldShowHelp != m_showHelp) { m_showHelp = shouldShowHelp; update(); } if (m_mouseDown) { if (m_newSelection) { QPoint p = event->pos(); QRect r = rect(); m_selection = normalizeSelection(QRect(m_dragStartPoint, limitPointToRect(p, r))); } // moving the whole selection else if (m_mouseOverHandle == 0) { QRect r = rect().normalized(), s = m_selectionBeforeDrag.normalized(); QPoint p = s.topLeft() + event->pos() - m_dragStartPoint; r.setBottomRight(r.bottomRight() - QPoint(s.width(), s.height()) + QPoint(1, 1)); if (!r.isNull() && r.isValid()) m_selection.moveTo(limitPointToRect(p, r)); } // dragging a handle else { QRect r = m_selectionBeforeDrag; QPoint offset = event->pos() - m_dragStartPoint; // dragging one of the top handles if (m_mouseOverHandle == &m_TLHandle || m_mouseOverHandle == &m_THandle || m_mouseOverHandle == &m_TRHandle) r.setTop(r.top() + offset.y()); // dragging one of the left handles if (m_mouseOverHandle == &m_TLHandle || m_mouseOverHandle == &m_LHandle || m_mouseOverHandle == &m_BLHandle) r.setLeft(r.left() + offset.x()); // dragging one of the bottom handles if (m_mouseOverHandle == &m_BLHandle || m_mouseOverHandle == &m_BHandle || m_mouseOverHandle == &m_BRHandle) r.setBottom(r.bottom() + offset.y()); // dragging one of the right handles if (m_mouseOverHandle == &m_TRHandle || m_mouseOverHandle == &m_RHandle || m_mouseOverHandle == &m_BRHandle) r.setRight(r.right() + offset.x()); r.setTopLeft(limitPointToRect(r.topLeft(), rect())); r.setBottomRight(limitPointToRect(r.bottomRight(), rect())); m_selection = normalizeSelection(r); } update(); } else { if (m_selection.isNull()) return; bool found = false; foreach (QRect* r, m_handles) { if (r->contains(event->pos())) { m_mouseOverHandle = r; found = true; break; } } if (!found) { m_mouseOverHandle = 0; if (m_selection.contains(event->pos())) setCursor(Qt::OpenHandCursor); else setCursor(Qt::CrossCursor); } else { if (m_mouseOverHandle == &m_TLHandle || m_mouseOverHandle == &m_BRHandle) setCursor(Qt::SizeFDiagCursor); if (m_mouseOverHandle == &m_TRHandle || m_mouseOverHandle == &m_BLHandle) setCursor(Qt::SizeBDiagCursor); if (m_mouseOverHandle == &m_LHandle || m_mouseOverHandle == &m_RHandle) setCursor(Qt::SizeHorCursor); if (m_mouseOverHandle == &m_THandle || m_mouseOverHandle == &m_BHandle) setCursor(Qt::SizeVerCursor); } } }
void AreaDialog::mouseMoveEvent(QMouseEvent* e) { mMouseMagnifier = false; if (mMouseDown) { mMousePos = e->pos(); if (mNewSelection) { QRect r = rect(); mSelection = QRect(mDragStartPoint, limitPointToRect(mMousePos, r)).normalized(); } else if (mMouseOverHandle == 0) { // moving the whole selection QRect r = rect().normalized(), s = mSelectionBeforeDrag.normalized(); QPoint p = s.topLeft() + e->pos() - mDragStartPoint; r.setBottomRight(r.bottomRight() - QPoint(s.width(), s.height())); if (!r.isNull() && r.isValid()) mSelection.moveTo(limitPointToRect(p, r)); } else {// dragging a handle QRect r = mSelectionBeforeDrag; QPoint offset = e->pos() - mDragStartPoint; if (mMouseOverHandle == &mTLHandle || mMouseOverHandle == &mTHandle || mMouseOverHandle == &mTRHandle) // dragging one of the top handles { r.setTop(r.top() + offset.y()); } if (mMouseOverHandle == &mTLHandle || mMouseOverHandle == &mLHandle || mMouseOverHandle == &mBLHandle) // dragging one of the left handles { r.setLeft(r.left() + offset.x()); } if (mMouseOverHandle == &mBLHandle || mMouseOverHandle == &mBHandle || mMouseOverHandle == &mBRHandle) // dragging one of the bottom handles { r.setBottom(r.bottom() + offset.y()); } if (mMouseOverHandle == &mTRHandle || mMouseOverHandle == &mRHandle || mMouseOverHandle == &mBRHandle) // dragging one of the right handles { r.setRight(r.right() + offset.x()); } r = r.normalized(); r.setTopLeft(limitPointToRect(r.topLeft(), rect())); r.setBottomRight(limitPointToRect(r.bottomRight(), rect())); mSelection = r; } if (qApp->keyboardModifiers() & Qt::ControlModifier) { // The lazy 1:1 aspect ratio approach! mSelection.setHeight(mSelection.width()); } if (mAcceptWidget) { QPoint acceptPos = e->pos(); QRect acceptRect = QRect(acceptPos, QSize(120, 70)); // Prevent the widget from overlapping the handles if (acceptRect.intersects(mTLHandle)) { acceptPos = mTLHandle.bottomRight() + QPoint(2, 2); // Corner case } if (acceptRect.intersects(mBRHandle)) { acceptPos = mBRHandle.bottomRight(); } if (acceptRect.intersects(mBHandle)) { acceptPos = mBHandle.bottomRight(); } if (acceptRect.intersects(mRHandle)) { acceptPos = mRHandle.topRight(); } if (acceptRect.intersects(mTHandle)) { acceptPos = mTHandle.bottomRight(); } if ((acceptPos.x()+120) > mScreenshot->pixmap().rect().width()) acceptPos.setX(acceptPos.x()-120); if ((acceptPos.y()+70) > mScreenshot->pixmap().rect().height()) acceptPos.setY(acceptPos.y()-70); mAcceptWidget->move(acceptPos); } update(); } else { if (mSelection.isNull()) { mMouseMagnifier = true; update(); return; } bool found = false; foreach(QRect* r, mHandles) { if (r->contains(e->pos())) { mMouseOverHandle = r; found = true; break; } } if (!found) { mMouseOverHandle = 0; if (mSelection.contains(e->pos())) setCursor(Qt::OpenHandCursor); else if (mAcceptWidget && QRect(mAcceptWidget->mapToParent(mAcceptWidget->pos()), QSize(100, 60)).contains(e->pos())) setCursor(Qt::PointingHandCursor); else setCursor(Qt::CrossCursor); } else { if (mMouseOverHandle == &mTLHandle || mMouseOverHandle == &mBRHandle) setCursor(Qt::SizeFDiagCursor); if (mMouseOverHandle == &mTRHandle || mMouseOverHandle == &mBLHandle) setCursor(Qt::SizeBDiagCursor); if (mMouseOverHandle == &mLHandle || mMouseOverHandle == &mRHandle) setCursor(Qt::SizeHorCursor); if (mMouseOverHandle == &mTHandle || mMouseOverHandle == &mBHandle) setCursor(Qt::SizeVerCursor); } } }