| | |
| | | #include <QtCore/QDebug> |
| | | |
| | | #include "qwkglobal_p.h" |
| | | #include "systemwindow_p.h" |
| | | |
| | | namespace QWK { |
| | | |
| | |
| | | #endif |
| | | } |
| | | |
| | | #ifdef Q_OS_LINUX |
| | | class WindowMoveManipulator : public QObject { |
| | | class QtWindowEventFilter : public SharedEventFilter { |
| | | public: |
| | | explicit WindowMoveManipulator(QWindow *targetWindow) |
| | | : QObject(targetWindow), target(targetWindow), initialMousePosition(QCursor::pos()), |
| | | initialWindowPosition(targetWindow->position()) { |
| | | target->installEventFilter(this); |
| | | } |
| | | |
| | | protected: |
| | | bool eventFilter(QObject *obj, QEvent *event) override { |
| | | switch (event->type()) { |
| | | case QEvent::MouseMove: { |
| | | auto mouseEvent = static_cast<QMouseEvent *>(event); |
| | | QPoint delta = getMouseEventGlobalPos(mouseEvent) - initialMousePosition; |
| | | target->setPosition(initialWindowPosition + delta); |
| | | return true; |
| | | } |
| | | |
| | | case QEvent::MouseButtonRelease: { |
| | | if (target->y() < 0) { |
| | | target->setPosition(target->x(), 0); |
| | | } |
| | | target->removeEventFilter(this); |
| | | this->deleteLater(); |
| | | } |
| | | |
| | | default: |
| | | break; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private: |
| | | QWindow *target; |
| | | QPoint initialMousePosition; |
| | | QPoint initialWindowPosition; |
| | | }; |
| | | #endif |
| | | |
| | | #if defined(Q_OS_MAC) || defined(Q_OS_LINUX) |
| | | class WindowResizeManipulator : public QObject { |
| | | public: |
| | | WindowResizeManipulator(QWindow *targetWindow, Qt::Edges edges) |
| | | : QObject(targetWindow), target(targetWindow), resizeEdges(edges), |
| | | initialMousePosition(QCursor::pos()), initialWindowRect(target->geometry()) { |
| | | target->installEventFilter(this); |
| | | } |
| | | |
| | | protected: |
| | | bool eventFilter(QObject *obj, QEvent *event) override { |
| | | switch (event->type()) { |
| | | case QEvent::MouseMove: { |
| | | auto mouseEvent = static_cast<QMouseEvent *>(event); |
| | | QPoint globalMousePos = getMouseEventGlobalPos(mouseEvent); |
| | | QRect windowRect = initialWindowRect; |
| | | |
| | | if (resizeEdges & Qt::LeftEdge) { |
| | | int delta = globalMousePos.x() - initialMousePosition.x(); |
| | | windowRect.setLeft(initialWindowRect.left() + delta); |
| | | } |
| | | if (resizeEdges & Qt::RightEdge) { |
| | | int delta = globalMousePos.x() - initialMousePosition.x(); |
| | | windowRect.setRight(initialWindowRect.right() + delta); |
| | | } |
| | | if (resizeEdges & Qt::TopEdge) { |
| | | int delta = globalMousePos.y() - initialMousePosition.y(); |
| | | windowRect.setTop(initialWindowRect.top() + delta); |
| | | } |
| | | if (resizeEdges & Qt::BottomEdge) { |
| | | int delta = globalMousePos.y() - initialMousePosition.y(); |
| | | windowRect.setBottom(initialWindowRect.bottom() + delta); |
| | | } |
| | | |
| | | target->setGeometry(windowRect); |
| | | return true; |
| | | } |
| | | |
| | | case QEvent::MouseButtonRelease: { |
| | | target->removeEventFilter(this); |
| | | this->deleteLater(); |
| | | } |
| | | |
| | | default: |
| | | break; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private: |
| | | QWindow *target; |
| | | QPoint initialMousePosition; |
| | | QRect initialWindowRect; |
| | | Qt::Edges resizeEdges; |
| | | }; |
| | | #endif |
| | | |
| | | static inline void startSystemMove(QWindow *window) { |
| | | #ifdef Q_OS_LINUX |
| | | if (window->startSystemMove()) { |
| | | return; |
| | | } |
| | | std::ignore = new WindowMoveManipulator(window); |
| | | #else |
| | | window->startSystemMove(); |
| | | #endif |
| | | } |
| | | |
| | | static inline void startSystemResize(QWindow *window, Qt::Edges edges) { |
| | | #if defined(Q_OS_MAC) || defined(Q_OS_LINUX) |
| | | if (window->startSystemResize(edges)) { |
| | | return; |
| | | } |
| | | std::ignore = new WindowResizeManipulator(window, edges); |
| | | #else |
| | | window->startSystemResize(edges); |
| | | #endif |
| | | } |
| | | |
| | | class QtWindowEventFilter : public QObject { |
| | | public: |
| | | explicit QtWindowEventFilter(AbstractWindowContext *context, QObject *parent = nullptr); |
| | | explicit QtWindowEventFilter(AbstractWindowContext *context); |
| | | ~QtWindowEventFilter() override; |
| | | |
| | | enum WindowStatus { |
| | |
| | | }; |
| | | |
| | | protected: |
| | | bool eventFilter(QObject *object, QEvent *event) override; |
| | | bool sharedEventFilter(QObject *object, QEvent *event) override; |
| | | |
| | | private: |
| | | AbstractWindowContext *m_context; |
| | |
| | | WindowStatus m_windowStatus; |
| | | }; |
| | | |
| | | QtWindowEventFilter::QtWindowEventFilter(AbstractWindowContext *context, QObject *parent) |
| | | : QObject(parent), m_context(context), m_cursorShapeChanged(false), m_windowStatus(Idle) { |
| | | m_context->window()->installEventFilter(this); |
| | | QtWindowEventFilter::QtWindowEventFilter(AbstractWindowContext *context) |
| | | : m_context(context), m_cursorShapeChanged(false), m_windowStatus(Idle) { |
| | | m_context->installSharedEventFilter(this); |
| | | } |
| | | |
| | | QtWindowEventFilter::~QtWindowEventFilter() = default; |
| | | |
| | | bool QtWindowEventFilter::eventFilter(QObject *obj, QEvent *event) { |
| | | bool QtWindowEventFilter::sharedEventFilter(QObject *obj, QEvent *event) { |
| | | Q_UNUSED(obj) |
| | | |
| | | auto type = event->type(); |
| | | if (type < QEvent::MouseButtonPress || type > QEvent::MouseMove) { |
| | | return false; |
| | | } |
| | | QObject *host = m_context->host(); |
| | | QWindow *window = m_context->window(); |
| | | WindowItemDelegate *delegate = m_context->delegate(); |
| | | bool fixedSize = delegate->isHostSizeFixed(host); |
| | | auto host = m_context->host(); |
| | | auto window = m_context->window(); |
| | | auto delegate = m_context->delegate(); |
| | | auto me = static_cast<const QMouseEvent *>(event); |
| | | bool fixedSize = delegate->isHostSizeFixed(host); |
| | | |
| | | QPoint scenePos = getMouseEventScenePos(me); |
| | | QPoint globalPos = getMouseEventGlobalPos(me); |
| | |
| | | } |
| | | |
| | | QtWindowContext::QtWindowContext() : AbstractWindowContext() { |
| | | qtWindowEventFilter = std::make_unique<QtWindowEventFilter>(this); |
| | | } |
| | | |
| | | QtWindowContext::~QtWindowContext() = default; |
| | |
| | | } |
| | | |
| | | void QtWindowContext::virtual_hook(int id, void *data) { |
| | | switch (id) { |
| | | case ShowSystemMenuHook: |
| | | return; |
| | | default: |
| | | break; |
| | | } |
| | | AbstractWindowContext::virtual_hook(id, data); |
| | | } |
| | | |
| | | void QtWindowContext::winIdChanged(QWindow *oldWindow) { |
| | | Q_UNUSED(oldWindow) |
| | | void QtWindowContext::winIdChanged() { |
| | | if (!m_windowHandle) { |
| | | m_delegate->setWindowFlags(m_host, m_delegate->getWindowFlags(m_host) & |
| | | ~Qt::FramelessWindowHint); |
| | | return; |
| | | } |
| | | |
| | | // Allocate new resources |
| | | m_delegate->setWindowFlags(m_host, |
| | | m_delegate->getWindowFlags(m_host) | Qt::FramelessWindowHint); |
| | | qtWindowEventFilter = std::make_unique<QtWindowEventFilter>(this); |
| | | } |
| | | |
| | | } |