FluentUI/src/FluFrameless.h

48 lines
1.2 KiB
C
Raw Normal View History

2023-12-11 23:47:03 +08:00
#ifndef FLUFRAMELESS_H
#define FLUFRAMELESS_H
#include <QObject>
#include <QQuickWindow>
#include <QtQml/qqml.h>
#include <QAbstractNativeEventFilter>
#include "stdafx.h"
2023-12-13 21:28:21 +08:00
#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
class FramelessEventFilter : public QAbstractNativeEventFilter
{
public:
FramelessEventFilter(QQuickWindow* window);
bool nativeEventFilter(const QByteArray &eventType, void *message, QT_NATIVE_EVENT_RESULT_TYPE *result) override;
public:
QQuickWindow* _window = nullptr;
qint64 _current = 0;
};
2023-12-11 23:47:03 +08:00
class FluFrameless : public QObject, public QQmlParserStatus
{
Q_OBJECT
2023-12-15 22:41:11 +08:00
Q_PROPERTY_AUTO(bool,stayTop)
2023-12-11 23:47:03 +08:00
QML_NAMED_ELEMENT(FluFrameless)
public:
explicit FluFrameless(QObject *parent = nullptr);
~FluFrameless();
void classBegin() override;
void componentComplete() override;
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
private:
2023-12-13 16:20:09 +08:00
void updateCursor(int edges);
2023-12-11 23:47:03 +08:00
private:
QPointer<QQuickWindow> _window = nullptr;
2023-12-13 21:28:21 +08:00
FramelessEventFilter* _nativeEvent = nullptr;
2023-12-11 23:47:03 +08:00
};
#endif // FLUFRAMELESS_H