更新代码
This commit is contained in:
56
ui/core_base/appinit.cpp
Normal file
56
ui/core_base/appinit.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "appinit.h"
|
||||
#include "qmutex.h"
|
||||
#include "qapplication.h"
|
||||
#include "qevent.h"
|
||||
#include "qwidget.h"
|
||||
|
||||
QScopedPointer<AppInit> AppInit::self;
|
||||
AppInit *AppInit::Instance()
|
||||
{
|
||||
if (self.isNull()) {
|
||||
static QMutex mutex;
|
||||
QMutexLocker locker(&mutex);
|
||||
if (self.isNull()) {
|
||||
self.reset(new AppInit);
|
||||
}
|
||||
}
|
||||
|
||||
return self.data();
|
||||
}
|
||||
|
||||
AppInit::AppInit(QObject *parent) : QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
bool AppInit::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
QWidget *w = (QWidget *)watched;
|
||||
if (!w->property("canMove").toBool()) {
|
||||
return QObject::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
static QPoint mousePoint;
|
||||
static bool mousePressed = false;
|
||||
|
||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
||||
if (mouseEvent->type() == QEvent::MouseButtonPress) {
|
||||
if (mouseEvent->button() == Qt::LeftButton) {
|
||||
mousePressed = true;
|
||||
mousePoint = mouseEvent->globalPos() - w->pos();
|
||||
}
|
||||
} else if (mouseEvent->type() == QEvent::MouseButtonRelease) {
|
||||
mousePressed = false;
|
||||
} else if (mouseEvent->type() == QEvent::MouseMove) {
|
||||
if (mousePressed) {
|
||||
w->move(mouseEvent->globalPos() - mousePoint);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return QObject::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void AppInit::start()
|
||||
{
|
||||
qApp->installEventFilter(this);
|
||||
}
|
||||
Reference in New Issue
Block a user