mirror of
https://gitee.com/drabel/LibQQt.git
synced 2025-01-04 10:18:44 +08:00
61f1dae97b
press on window body and move window. support: windows \ unix \ linux \ e-linux
62 lines
1.6 KiB
C++
62 lines
1.6 KiB
C++
#include "qqtbodymover.h"
|
|
#include "qqtbodymover_p.h"
|
|
|
|
#include <QWidget>
|
|
#include <QMouseEvent>
|
|
|
|
QQtBodyMover::QQtBodyMover ( QObject* parent ) : QObject ( parent )
|
|
{
|
|
d_ptr = new QQtBodyMoverPrivate ( this );
|
|
}
|
|
|
|
QQtBodyMover::~QQtBodyMover()
|
|
{
|
|
delete d_ptr;
|
|
}
|
|
|
|
bool QQtBodyMover::eventFilter ( QObject* watched, QEvent* event )
|
|
{
|
|
//过滤掉不是QWidget
|
|
if ( !watched->inherits ( "QWidget" ) )
|
|
return QObject::eventFilter ( watched, event );
|
|
|
|
//修复 paint bug
|
|
/*fix the parent handled bug terminally*/
|
|
if ( event->type() == QEvent::Paint )
|
|
return QObject::eventFilter ( watched, event );
|
|
|
|
//修复鼠标穿透。
|
|
bool atti = ( ( QWidget* ) watched )->testAttribute ( Qt::WA_TransparentForMouseEvents );
|
|
if ( atti )
|
|
return QObject::eventFilter ( watched, event );
|
|
|
|
Q_D ( QQtBodyMover ) ;
|
|
|
|
switch ( event->type() )
|
|
{
|
|
case QEvent::MouseButtonPress:
|
|
{
|
|
QMouseEvent* e = ( QMouseEvent* ) event;
|
|
d->mousePressEvent ( e, ( QWidget* ) watched );
|
|
return true;
|
|
}
|
|
case QEvent::MouseButtonRelease:
|
|
{
|
|
QMouseEvent* e = ( QMouseEvent* ) event;
|
|
d->mouseReleaseEvent ( e, ( QWidget* ) watched );
|
|
return true;
|
|
}
|
|
case QEvent::MouseMove:
|
|
{
|
|
QMouseEvent* e = ( QMouseEvent* ) event;
|
|
d->mouseMoveEvent ( e, ( QWidget* ) watched );
|
|
return true;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return QObject::eventFilter ( watched, event );
|
|
|
|
}
|