FluentUI/src/FluFrameless.h

79 lines
1.9 KiB
C
Raw Normal View History

2024-04-11 14:51:43 +08:00
#pragma once
2024-03-28 19:18:56 +08:00
#include <QObject>
#include <QQuickItem>
#include <QAbstractNativeEventFilter>
2024-04-17 15:11:14 +08:00
#include <QQmlProperty>
2024-03-28 19:18:56 +08:00
#include "stdafx.h"
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
using QT_NATIVE_EVENT_RESULT_TYPE = qintptr;
using QT_ENTER_EVENT_TYPE = QEnterEvent;
#else
using QT_NATIVE_EVENT_RESULT_TYPE = long;
using QT_ENTER_EVENT_TYPE = QEvent;
#endif
2024-04-11 14:51:43 +08:00
class FluFrameless : public QQuickItem, QAbstractNativeEventFilter {
2024-06-28 17:09:23 +08:00
Q_OBJECT
Q_PROPERTY_AUTO_P(QQuickItem *, appbar)
Q_PROPERTY_AUTO_P(QQuickItem *, maximizeButton)
Q_PROPERTY_AUTO_P(QQuickItem *, minimizedButton)
Q_PROPERTY_AUTO_P(QQuickItem *, closeButton)
Q_PROPERTY_AUTO(bool, topmost)
Q_PROPERTY_AUTO(bool, disabled)
Q_PROPERTY_AUTO(bool, fixSize)
2024-03-28 19:18:56 +08:00
QML_NAMED_ELEMENT(FluFrameless)
public:
2024-04-11 14:51:43 +08:00
explicit FluFrameless(QQuickItem *parent = nullptr);
~FluFrameless() override;
2024-03-28 19:18:56 +08:00
void componentComplete() override;
2024-04-11 14:51:43 +08:00
2024-06-28 17:09:23 +08:00
[[maybe_unused]] bool nativeEventFilter(const QByteArray &eventType, void *message,
QT_NATIVE_EVENT_RESULT_TYPE *result) override;
2024-04-11 14:51:43 +08:00
2024-04-11 19:18:37 +08:00
[[maybe_unused]] Q_INVOKABLE void showFullScreen();
2024-04-11 14:51:43 +08:00
2024-03-28 19:18:56 +08:00
Q_INVOKABLE void showMaximized();
2024-04-11 14:51:43 +08:00
2024-04-11 19:18:37 +08:00
[[maybe_unused]] Q_INVOKABLE void showMinimized();
2024-04-11 14:51:43 +08:00
2024-03-28 19:18:56 +08:00
Q_INVOKABLE void showNormal();
2024-04-11 14:51:43 +08:00
Q_INVOKABLE void setHitTestVisible(QQuickItem *);
2024-04-11 19:18:37 +08:00
[[maybe_unused]] Q_INVOKABLE void onDestruction();
2024-04-11 14:51:43 +08:00
2024-03-28 19:18:56 +08:00
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
2024-04-11 14:51:43 +08:00
2024-03-28 19:18:56 +08:00
private:
bool _isFullScreen();
2024-04-11 14:51:43 +08:00
2024-03-28 19:18:56 +08:00
bool _isMaximized();
2024-04-11 14:51:43 +08:00
2024-03-28 19:18:56 +08:00
void _updateCursor(int edges);
2024-04-11 14:51:43 +08:00
2024-03-28 19:18:56 +08:00
void _setWindowTopmost(bool topmost);
2024-04-11 14:51:43 +08:00
2024-03-28 19:18:56 +08:00
void _showSystemMenu(QPoint point);
2024-04-11 14:51:43 +08:00
2024-03-28 19:18:56 +08:00
bool _hitAppBar();
2024-04-11 14:51:43 +08:00
2024-03-28 19:18:56 +08:00
bool _hitMaximizeButton();
2024-04-11 14:51:43 +08:00
2024-03-31 10:59:15 +08:00
void _setMaximizePressed(bool val);
2024-04-11 14:51:43 +08:00
2024-03-31 21:52:06 +08:00
void _setMaximizeHovered(bool val);
2024-04-11 14:51:43 +08:00
2024-03-28 19:18:56 +08:00
private:
2024-04-11 14:51:43 +08:00
quint64 _current = 0;
2024-03-28 19:18:56 +08:00
int _edges = 0;
int _margins = 8;
2024-04-11 14:51:43 +08:00
quint64 _clickTimer = 0;
2024-04-23 13:41:26 +08:00
bool _isWindows11OrGreater = false;
2024-03-28 19:18:56 +08:00
QList<QPointer<QQuickItem>> _hitTestList;
2024-04-11 19:18:37 +08:00
};