You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.1 KiB
44 lines
1.1 KiB
#include "appinit.h"
|
|
#include "qapplication.h"
|
|
#include "qevent.h"
|
|
|
|
AppInit *AppInit::self = 0;
|
|
AppInit::AppInit(QObject *parent) : QObject(parent)
|
|
{
|
|
}
|
|
|
|
bool AppInit::eventFilter(QObject *obj, QEvent *evt)
|
|
{
|
|
QWidget *w = (QWidget *)obj;
|
|
if (!w->property("canMove").toBool()) {
|
|
return QObject::eventFilter(obj, evt);
|
|
}
|
|
|
|
static QPoint mousePoint;
|
|
static bool mousePressed = false;
|
|
|
|
QMouseEvent *event = static_cast<QMouseEvent *>(evt);
|
|
if (event->type() == QEvent::MouseButtonPress) {
|
|
if (event->button() == Qt::LeftButton) {
|
|
mousePressed = true;
|
|
mousePoint = event->globalPos() - w->pos();
|
|
return true;
|
|
}
|
|
} else if (event->type() == QEvent::MouseButtonRelease) {
|
|
mousePressed = false;
|
|
return true;
|
|
} else if (event->type() == QEvent::MouseMove) {
|
|
if (mousePressed && (event->buttons() && Qt::LeftButton)) {
|
|
w->move(event->globalPos() - mousePoint);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return QObject::eventFilter(obj, evt);
|
|
}
|
|
|
|
void AppInit::start()
|
|
{
|
|
qApp->installEventFilter(this);
|
|
}
|