mirror of
https://gitee.com/drabel/LibQQt.git
synced 2025-01-04 10:18:44 +08:00
73 lines
1.7 KiB
C++
73 lines
1.7 KiB
C++
#include "qqtbodymover_p.h"
|
|
#include "qqtbodymover.h"
|
|
|
|
#include <QWidget>
|
|
#include <QMouseEvent>
|
|
#ifdef Q_OS_WIN
|
|
//#pragma comment(lib, "user32.lib")
|
|
#include <qt_windows.h>
|
|
#endif
|
|
#include <qqtcore.h>
|
|
|
|
QQtBodyMoverPrivate::QQtBodyMoverPrivate ( QQtBodyMover* q )
|
|
{
|
|
q_ptr = q;
|
|
}
|
|
|
|
QQtBodyMoverPrivate::~QQtBodyMoverPrivate()
|
|
{
|
|
}
|
|
|
|
void QQtBodyMoverPrivate::mousePressEvent ( QMouseEvent* event, QWidget* target )
|
|
{
|
|
Q_ASSERT ( target );
|
|
|
|
#ifdef Q_OS_WIN
|
|
if ( ReleaseCapture() )
|
|
{
|
|
QWidget* pWindow = target;
|
|
if ( pWindow->isTopLevel() )
|
|
{
|
|
//SC_MOVE 移动命令
|
|
//HTCAPTION 捕获鼠标命令,否则,会跑到标题栏上去。
|
|
SendMessage ( HWND ( pWindow->winId() ), WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0 );
|
|
}
|
|
}
|
|
event->accept();
|
|
#else
|
|
if ( event->button() == Qt::LeftButton )
|
|
{
|
|
bMousePressed = true;
|
|
pressedPoint = event->globalPos();
|
|
}
|
|
event->accept();
|
|
#endif
|
|
}
|
|
|
|
void QQtBodyMoverPrivate::mouseReleaseEvent ( QMouseEvent* event, QWidget* target )
|
|
{
|
|
Q_ASSERT ( target );
|
|
#ifdef Q_OS_WIN
|
|
#else
|
|
bMousePressed = false;
|
|
event->accept();
|
|
#endif
|
|
}
|
|
|
|
void QQtBodyMoverPrivate::mouseMoveEvent ( QMouseEvent* event, QWidget* target )
|
|
{
|
|
Q_ASSERT ( target );
|
|
#ifdef Q_OS_WIN
|
|
#else
|
|
QWidget* win = target;
|
|
if ( bMousePressed && !win->isMaximized() )
|
|
{
|
|
QPoint movePoint = event->globalPos() - pressedPoint;
|
|
QPoint widgetPos = win->pos();
|
|
pressedPoint = event->globalPos();
|
|
win->move ( widgetPos.x() + movePoint.x(), widgetPos.y() + movePoint.y() );
|
|
}
|
|
event->accept();
|
|
#endif
|
|
}
|