1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00
LibQQt/test/testbodymover/qqtbodymover.cpp
tianduanrui 61f1dae97b add qqtbodymover.
press on window body and move window.
support: windows \ unix \ linux \ e-linux
2019-08-25 11:14:05 +08:00

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 );
}