Пример #1
0
void PicViewerWindow::mouseMoveEvent(QMouseEvent *event)
{
    // 无边框窗体的边缘拖动resize方案参考了如下博客的代码
    // http://www.cnblogs.com/xufeiyang/p/3313104.html
    QPoint gloPoint = event->globalPos();
    QRect rect = this->rect();
    QPoint tl = mapToGlobal(rect.topLeft());
    QPoint rb = mapToGlobal(rect.bottomRight());

    if (event->buttons() & Qt::LeftButton && clickOnFrame)
    {

        if(mouseDir != NONE) {
            QRect rMove(tl, rb);

            switch(mouseDir) {
            case LEFT:
                if(rb.x() - gloPoint.x() <= this->minimumWidth())
                    rMove.setX(tl.x());
                else
                    rMove.setX(gloPoint.x());
                break;
            case RIGHT:
                rMove.setWidth(gloPoint.x() - tl.x());
                break;
            case UP:
                if(rb.y() - gloPoint.y() <= this->minimumHeight())
                    rMove.setY(tl.y());
                else
                    rMove.setY(gloPoint.y());
                break;
            case DOWN:
                rMove.setHeight(gloPoint.y() - tl.y());
                break;
            case LEFTTOP:
                if(rb.x() - gloPoint.x() <= this->minimumWidth())
                    rMove.setX(tl.x());
                else
                    rMove.setX(gloPoint.x());
                if(rb.y() - gloPoint.y() <= this->minimumHeight())
                    rMove.setY(tl.y());
                else
                    rMove.setY(gloPoint.y());
                break;
            case RIGHTTOP:
                rMove.setWidth(gloPoint.x() - tl.x());
                rMove.setY(gloPoint.y());
                break;
            case LEFTBOTTOM:
                rMove.setX(gloPoint.x());
                rMove.setHeight(gloPoint.y() - tl.y());
                break;
            case RIGHTBOTTOM:
                rMove.setWidth(gloPoint.x() - tl.x());
                rMove.setHeight(gloPoint.y() - tl.y());
                break;
            default:
                break;
            }
            this->setGeometry(rMove);
        } else {
            //滚动条宽度都改成了1px,以是否可见滚动条为判别移动图片还是窗体
            //尚不能判断拖动的是图片还是窗体
            if (vScrollBar->isVisible() || hScrollBar->isVisible()) {
                int xvalue = event->x()-drag_pos.x();
                int yvalue = event->y()-drag_pos.y();
                vScrollBar->setValue(scrollBarValue.y()-yvalue);
                hScrollBar->setValue(scrollBarValue.x()-xvalue);
            } else {
                move(gloPoint - drag_pos);
            }
        }
        event->accept();
    }
}
void QBasicFormMoveableWidget::mouseMoveEvent(QMouseEvent *event)
{
    if(move_plan_ == PLANA){
        QPoint gloPoint = event->globalPos();
        QRect rect = this->rect();
        QPoint tl = mapToGlobal(rect.topLeft());
        QPoint rb = mapToGlobal(rect.bottomRight());
        if(!isLeftPressDown_) {
            this->region(gloPoint);
        } else {
            if(dir_ != NONE) {
                QRect rMove(tl, rb);
                switch(dir_) {
                case LEFT:
                    if(rb.x() - gloPoint.x() <= this->minimumWidth())
                        rMove.setX(tl.x());
                    else
                        rMove.setX(gloPoint.x());
                    break;
                case RIGHT:
                    rMove.setWidth(gloPoint.x() - tl.x());
                    break;
                case UP:
                    if(rb.y() - gloPoint.y() <= this->minimumHeight())
                        rMove.setY(tl.y());
                    else
                        rMove.setY(gloPoint.y());
                    break;
                case DOWN:
                    rMove.setHeight(gloPoint.y() - tl.y());
                    break;
                case LEFTTOP:
                    if(rb.x() - gloPoint.x() <= this->minimumWidth())
                        rMove.setX(tl.x());
                    else
                        rMove.setX(gloPoint.x());
                    if(rb.y() - gloPoint.y() <= this->minimumHeight())
                        rMove.setY(tl.y());
                    else
                        rMove.setY(gloPoint.y());
                    break;
                case RIGHTTOP:
                    rMove.setWidth(gloPoint.x() - tl.x());
                    rMove.setY(gloPoint.y());
                    break;
                case LEFTBOTTOM:
                    rMove.setX(gloPoint.x());
                    rMove.setHeight(gloPoint.y() - tl.y());
                    break;
                case RIGHTBOTTOM:
                    rMove.setWidth(gloPoint.x() - tl.x());
                    rMove.setHeight(gloPoint.y() - tl.y());
                    break;
                default:
                    break;
                }
                this->setGeometry(rMove);
            } else {
                move(event->globalPos() - dragPosition_);
                event->accept();
            }
        }
    }
    QWidget::mouseMoveEvent(event);
}
void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
    if (windowState() & (Qt::WindowMaximized | Qt::WindowFullScreen))
        return;
    QPoint globalPoint = event->globalPos();
    if (isZoomReady && isLeftPressDown) {
        QRect rect = this->rect();
        QPoint topLeft = mapToGlobal(rect.topLeft());
        QPoint bottomRight = mapToGlobal(rect.bottomRight());

        QRect rMove(topLeft, bottomRight);

        switch (direction) {
        case Left:
            if (bottomRight.x() - globalPoint.x() <= minimumWidth())
                rMove.setX(topLeft.x());
            else
                rMove.setX(globalPoint.x());
            break;
        case Right:
            rMove.setWidth(globalPoint.x() - topLeft.x());
            break;
        case Up:
            if (bottomRight.y() - globalPoint.y() <= minimumHeight())
                rMove.setY(topLeft.y());
            else
                rMove.setY(globalPoint.y());
            break;
        case Down:
            rMove.setHeight(globalPoint.y() - topLeft.y());
            break;
        case LeftTop:
            if (bottomRight.x() - globalPoint.x() <= minimumWidth())
                rMove.setX(topLeft.x());
            else
                rMove.setX(globalPoint.x());
            if (bottomRight.y() - globalPoint.y() <= minimumHeight())
                rMove.setY(topLeft.y());
            else
                rMove.setY(globalPoint.y());
            break;
        case RightTop:
            rMove.setWidth(globalPoint.x() - topLeft.x());
            if (bottomRight.y() - globalPoint.y() <= minimumHeight())
                rMove.setY(topLeft.y());
            else
                rMove.setY(globalPoint.y());
            break;
        case LeftBottom:
            if (bottomRight.x() - globalPoint.x() <= minimumWidth())
                rMove.setX(topLeft.x());
            else
                rMove.setX(globalPoint.x());
            rMove.setHeight(globalPoint.y() - topLeft.y());
            break;
        case RightBottom:
            rMove.setWidth(globalPoint.x() - topLeft.x());
            rMove.setHeight(globalPoint.y() - topLeft.y());
            break;
        default:
            break;
        }
        setGeometry(rMove);
    } else if (isLeftPressDown && (event->buttons() & Qt::LeftButton)) {
        move(event->globalPos() - movePosition);
        event->accept();
    } else if (!isLeftPressDown) {
        region(globalPoint);
    }
}
Пример #4
0
void DropShadowWindow::mouseMoveEvent(QMouseEvent *event)
{
	BaseStyleWidget::mouseMoveEvent(event);

	/*if (!LeftMouseDown)
	{
		Dir = PointValid(event->x(), event->y());
		SetCursorStyle(Dir);
	}
	else
	{
		int nXGlobal = event->globalX();
		int nYGlobal = event->globalY(); 
		SetDrayMove(nXGlobal, nYGlobal, Dir); 
		DragPosition = QPoint(nXGlobal, nYGlobal);
	}*/

	//移动窗口
	/*if (LeftMouseDown)
	{
		QPoint move_pos = event->globalPos(); 
		move(move_pos - MovePoint);
	}
	*/

	QPoint gloPoint = event->globalPos();
	QRect rect = this->rect();
	QPoint tl = mapToGlobal(rect.topLeft());
	QPoint rb = mapToGlobal(rect.bottomRight());

	if (!m_LeftMouseDown)
	{
        this->__setCursorStyle(gloPoint);
	}
	else 
	{
		if (m_Dir != NONE) 
		{
			QRect rMove(tl, rb);

			switch (m_Dir) {
			case LEFT:
				if (rb.x() - gloPoint.x() <= this->minimumWidth())
					rMove.setX(tl.x());
				else
					rMove.setX(gloPoint.x());
				break;
			case RIGHT:
				rMove.setWidth(gloPoint.x() - tl.x());
				break;
			case UP:
				if (rb.y() - gloPoint.y() <= this->minimumHeight())
					rMove.setY(tl.y());
				else
					rMove.setY(gloPoint.y());
				break;
			case DOWN:
				rMove.setHeight(gloPoint.y() - tl.y());
				break;
			case LEFTTOP:
				if (rb.x() - gloPoint.x() <= this->minimumWidth())
					rMove.setX(tl.x());
				else
					rMove.setX(gloPoint.x());
				if (rb.y() - gloPoint.y() <= this->minimumHeight())
					rMove.setY(tl.y());
				else
					rMove.setY(gloPoint.y());
				break;
			case RIGHTTOP:
				rMove.setWidth(gloPoint.x() - tl.x());
				rMove.setY(gloPoint.y());
				break;
			case LEFTBOTTOM:
				rMove.setX(gloPoint.x());
				rMove.setHeight(gloPoint.y() - tl.y());
				break;
			case RIGHTBOTTOM:
				rMove.setWidth(gloPoint.x() - tl.x());
				rMove.setHeight(gloPoint.y() - tl.y());
				break;
			default:

				break;
			}
			this->setGeometry(rMove); 
		}
		else {
			move(event->globalPos() - m_DragPosition);
			event->accept();

			QPoint diff = event->pos() - m_DragPosition;
			QPoint newpos = this->pos() + diff; 
		}
	}
}
Пример #5
0
void note::mouseMoveEvent(QMouseEvent *event)//重写鼠标移动事件
{
    QPoint gloPoint = event->globalPos();
    QRect rect = this->rect();
    QPoint tl = mapToGlobal(rect.topLeft());
    QPoint rb = mapToGlobal(rect.bottomRight());

    if(!isLeftPressDown) {
        this->region(gloPoint);
    } else {

        if(dir != NONE) {
            QRect rMove(tl, rb);

            switch(dir) {
            case LEFT:
                if(rb.x() - gloPoint.x() <= this->minimumWidth())
                    rMove.setX(tl.x());
                else
                    rMove.setX(gloPoint.x());
                break;
            case RIGHT:
                rMove.setWidth(gloPoint.x() - tl.x());
                break;
            case UP:
                if(rb.y() - gloPoint.y() <= this->minimumHeight())
                    rMove.setY(tl.y());
                else
                    rMove.setY(gloPoint.y());
                break;
            case DOWN:
                rMove.setHeight(gloPoint.y() - tl.y());
                break;
            case LEFTTOP:
                if(rb.x() - gloPoint.x() <= this->minimumWidth())
                    rMove.setX(tl.x());
                else
                    rMove.setX(gloPoint.x());
                if(rb.y() - gloPoint.y() <= this->minimumHeight())
                    rMove.setY(tl.y());
                else
                    rMove.setY(gloPoint.y());
                break;
            case RIGHTTOP:
                rMove.setWidth(gloPoint.x() - tl.x());
                rMove.setY(gloPoint.y());
                break;
            case LEFTBOTTOM:
                rMove.setX(gloPoint.x());
                rMove.setHeight(gloPoint.y() - tl.y());
                break;
            case RIGHTBOTTOM:
                rMove.setWidth(gloPoint.x() - tl.x());
                rMove.setHeight(gloPoint.y() - tl.y());
                break;
            default:

                break;
            }
            this->setGeometry(rMove);
        } else {
            move(event->globalPos() - dragPosition);
            event->accept();
        }
    }
    QDialog::mouseMoveEvent(event);
}