| | |
| | | #include "widgetwindowagent_p.h" |
| | | |
| | | #include <QtCore/QDebug> |
| | | |
| | | namespace QWK { |
| | | |
| | | class TitleBarEventFilter : public QObject { |
| | | Q_OBJECT |
| | | |
| | | public: |
| | | explicit TitleBarEventFilter(AbstractWindowContext *context, QObject *parent = nullptr); |
| | | ~TitleBarEventFilter() override; |
| | |
| | | private: |
| | | AbstractWindowContext *m_context; |
| | | bool m_leftButtonPressed; |
| | | } |
| | | bool m_moving; |
| | | }; |
| | | |
| | | TitleBarEventFilter::TitleBarEventFilter(QObject *parent) : QObject(parent), m_context(context), m_leftButtonPressed(false) {} |
| | | TitleBarEventFilter::TitleBarEventFilter(AbstractWindowContext *context, QObject *parent) |
| | | : QObject(parent), m_context(context), m_leftButtonPressed(false), m_moving(false) { |
| | | } |
| | | |
| | | TitleBarEventFilter::~TitleBarEventFilter() = default; |
| | | |
| | |
| | | const QPoint scenePos = mouseEvent->scenePosition().toPoint(); |
| | | const QPoint globalPos = mouseEvent->globalPosition().toPoint(); |
| | | #else |
| | | const QPoint scenePos = mouseEvent->windowPos().toPoint(); |
| | | const QPoint globalPos = mouseEvent->screenPos().toPoint(); |
| | | const QPoint scenePos = me->windowPos().toPoint(); |
| | | const QPoint globalPos = me->screenPos().toPoint(); |
| | | #endif |
| | | if (!m_context->isInTitleBarDraggableArea(scenePos)) { |
| | | return false; |
| | |
| | | case QEvent::MouseButtonPress: { |
| | | if (me->button() == Qt::LeftButton) { |
| | | m_leftButtonPressed = true; |
| | | m_moving = false; |
| | | event->accept(); |
| | | return true; |
| | | } |
| | |
| | | case QEvent::MouseButtonRelease: { |
| | | if (me->button() == Qt::LeftButton) { |
| | | m_leftButtonPressed = false; |
| | | m_moving = false; |
| | | event->accept(); |
| | | return true; |
| | | } |
| | |
| | | } |
| | | case QEvent::MouseMove: { |
| | | if (m_leftButtonPressed) { |
| | | const auto widget = static_cast<QWidget *>(object); |
| | | widget->windowHandle()->startSystemMove(); |
| | | if (!m_moving) { |
| | | m_moving = true; |
| | | m_context->window()->startSystemMove(); |
| | | } |
| | | event->accept(); |
| | | return true; |
| | | } |
| | |
| | | } |
| | | case QEvent::MouseButtonDblClick: { |
| | | if (me->button() == Qt::LeftButton) { |
| | | if (!widget->isFullScreen()) { |
| | | if (widget->isMaximized()) { |
| | | widget->showNormal(); |
| | | auto window = static_cast<QWidget *>(object)->window(); |
| | | if (!window->isFullScreen()) { |
| | | if (window->isMaximized()) { |
| | | window->showNormal(); |
| | | } else { |
| | | widget->showMaximized(); |
| | | window->showMaximized(); |
| | | } |
| | | event->accept(); |
| | | return true; |
| | |
| | | } |
| | | break; |
| | | } |
| | | default: |
| | | break; |
| | | default: { |
| | | Q_UNREACHABLE(); |
| | | return false; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | #include "widgetwindowagent_cocoa.moc" |