void DragProxy::SetBorderWidth(int top, int right, int bottom, int left) { m_top = top; m_right = right; m_bottom = bottom; m_left = left; MakeRegions(); }
Region *ComputeRegions(CImage *cimg, Image *mask) { Region *r=NULL; Graph *g; g = CreateGraph(cimg); r = MakeRegions(g, mask); DestroyGraph(&g); return(r); }
bool DragProxy::eventFilter(QObject* obj, QEvent* event) { QEvent::Type eventType = event->type(); if (eventType == QEvent::MouseMove) { QMouseEvent* mouseEvent = (QMouseEvent*)event; QPoint curPosLocal = mouseEvent->pos(); qDebug() << curPosLocal << "curPosLocal"; DragProxy::WidgetRegion regionType = HitTest(curPosLocal); // QPoint curPosGlobal = m_proxyWidget->mapToGlobal(curPosLocal); QPoint curPosGlobal = mouseEvent->globalPos(); qDebug() << curPosGlobal << "curPosGlobal"; if (!m_mousePressed) // 鼠标未按下 { switch (regionType) { case Top: case Bottom: m_proxyWidget->setCursor(Qt::SizeVerCursor); break; case TopRight: case LeftBottom: m_proxyWidget->setCursor(Qt::SizeBDiagCursor); break; case Right: case Left: m_proxyWidget->setCursor(Qt::SizeHorCursor); break; case RightBottom: case LeftTop: m_proxyWidget->setCursor(Qt::SizeFDiagCursor); break; default: m_proxyWidget->setCursor(Qt::ArrowCursor); break; } StartCursorTimer(); } else // 鼠标已按下 { QRect geo = m_proxyWidget->geometry(); if (m_regionPressed == Inner) { //m_proxyWidget->move(m_originGeo.topLeft() + curPosGlobal - m_originPosGlobal); // m_proxyWidget->move(curPosGlobal-(m_originPosGlobal - m_originGeo.topLeft())); } else if (m_regionPressed == Top) { m_proxyWidget->setCursor(Qt::SizeVerCursor); int dY = curPosGlobal.y() - m_originPosGlobal.y(); UpdateGeometry(m_originGeo.x(), m_originGeo.y() + dY, m_originGeo.width(), m_originGeo.height() - dY); } else if (m_regionPressed == TopRight) { m_proxyWidget->setCursor(Qt::SizeBDiagCursor); QPoint dXY = curPosGlobal - m_originPosGlobal; UpdateGeometry(m_originGeo.x(), m_originGeo.y() + dXY.y(), m_originGeo.width() + dXY.x(), m_originGeo.height() - dXY.y()); } else if (m_regionPressed == Right) { m_proxyWidget->setCursor(Qt::SizeHorCursor); int dX = curPosGlobal.x() - m_originPosGlobal.x(); UpdateGeometry(m_originGeo.x(), m_originGeo.y(), m_originGeo.width() + dX, m_originGeo.height()); } else if (m_regionPressed == RightBottom) { m_proxyWidget->setCursor(Qt::SizeFDiagCursor); QPoint dXY = curPosGlobal - m_originPosGlobal; UpdateGeometry(m_originGeo.x(), m_originGeo.y(), m_originGeo.width() + dXY.x(), m_originGeo.height() + dXY.y()); } else if (m_regionPressed == Bottom) { m_proxyWidget->setCursor(Qt::SizeVerCursor); int dY = curPosGlobal.y() - m_originPosGlobal.y(); UpdateGeometry(m_originGeo.x(), m_originGeo.y(), m_originGeo.width(), m_originGeo.height() + dY); } else if (m_regionPressed == LeftBottom) { m_proxyWidget->setCursor(Qt::SizeBDiagCursor); QPoint dXY = curPosGlobal - m_originPosGlobal; UpdateGeometry(m_originGeo.x() + dXY.x(), m_originGeo.y(), m_originGeo.width() - dXY.x(), m_originGeo.height() + dXY.y()); } else if (m_regionPressed == Left) { m_proxyWidget->setCursor(Qt::SizeHorCursor); int dX = curPosGlobal.x() - m_originPosGlobal.x(); UpdateGeometry(m_originGeo.x() + dX, m_originGeo.y(), m_originGeo.width() - dX, m_originGeo.height()); } else if (m_regionPressed == LeftTop) { m_proxyWidget->setCursor(Qt::SizeFDiagCursor); QPoint dXY = curPosGlobal - m_originPosGlobal; UpdateGeometry(m_originGeo.x() + dXY.x(), m_originGeo.y() + dXY.y(), m_originGeo.width() - dXY.x(), m_originGeo.height() - dXY.y()); } } } else if (eventType == QEvent::MouseButtonPress) { QMouseEvent* mouseEvent = (QMouseEvent*)event; if (mouseEvent->button() == Qt::LeftButton) { m_mousePressed = true; QPoint curPos = mouseEvent->pos(); m_regionPressed = HitTest(curPos); //m_originPosGlobal = m_proxyWidget->mapToGlobal(curPos); m_originPosGlobal = mouseEvent->globalPos(); qDebug() << m_originPosGlobal << "zj"; m_originGeo = m_proxyWidget->frameGeometry(); StopCursorTimer(); } } else if (eventType == QEvent::MouseButtonRelease) { m_mousePressed = false; m_regionPressed = Unknown; m_proxyWidget->setCursor(Qt::ArrowCursor); } else if (eventType == QEvent::Resize) { MakeRegions(); } else if (eventType == QEvent::Leave) { m_proxyWidget->setCursor(Qt::ArrowCursor); StopCursorTimer(); } else if (eventType == QEvent::Timer) { QTimerEvent* timerEvent = (QTimerEvent*)event; if (timerEvent->timerId() == m_cursorTimerId) { if (m_regions[Inner].contains(m_proxyWidget->mapFromGlobal(QCursor::pos()))) { m_proxyWidget->setCursor(Qt::ArrowCursor); StopCursorTimer(); } } } return QObject::eventFilter(obj, event); }