FluentUI/src/FluFrameless.h

58 lines
1.7 KiB
C
Raw Normal View History

2024-03-28 19:18:56 +08:00
#ifndef FLUFRAMELESS_H
#define FLUFRAMELESS_H
#include <QObject>
#include <QQuickItem>
#include <QAbstractNativeEventFilter>
#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
class FluFrameless : public QQuickItem,QAbstractNativeEventFilter
{
Q_OBJECT
Q_PROPERTY_AUTO(QQuickItem*,appbar)
Q_PROPERTY_AUTO(bool,topmost)
Q_PROPERTY_AUTO(QQuickItem*,maximizeButton)
Q_PROPERTY_AUTO(QQuickItem*,minimizedButton)
Q_PROPERTY_AUTO(QQuickItem*,closeButton)
Q_PROPERTY_AUTO(bool,disabled)
Q_PROPERTY_AUTO(bool,fixSize)
QML_NAMED_ELEMENT(FluFrameless)
public:
explicit FluFrameless(QQuickItem* parent = nullptr);
~FluFrameless();
void componentComplete() override;
bool nativeEventFilter(const QByteArray &eventType, void *message, QT_NATIVE_EVENT_RESULT_TYPE *result) override;
Q_INVOKABLE void showFullScreen();
Q_INVOKABLE void showMaximized();
Q_INVOKABLE void showMinimized();
Q_INVOKABLE void showNormal();
Q_INVOKABLE void setHitTestVisible(QQuickItem*);
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
private:
bool _isFullScreen();
bool _isMaximized();
void _updateCursor(int edges);
void _setWindowTopmost(bool topmost);
void _showSystemMenu(QPoint point);
bool _containsCursorToItem(QQuickItem* item);
bool _hitAppBar();
bool _hitMaximizeButton();
private:
2024-03-29 00:48:58 +08:00
qint64 _current;
2024-03-28 19:18:56 +08:00
int _edges = 0;
int _margins = 8;
QList<QPointer<QQuickItem>> _hitTestList;
};
#endif // FLUFRAMELESS_H