Kylin/Fluent/Frameless.h
2024-08-31 04:13:21 +08:00

92 lines
3.0 KiB
C++

#ifndef FRAMELESS_H
#define FRAMELESS_H
#include "Utilities.h"
#include <QAbstractNativeEventFilter>
#include <QQuickItem>
class Frameless : public QQuickItem, QAbstractNativeEventFilter {
Q_OBJECT
QML_ELEMENT
Q_PROPERTY_AUTO(QString, effect)
Q_PROPERTY_READONLY_AUTO(bool, effective)
Q_PROPERTY_READONLY_AUTO(QStringList, availableEffects)
Q_PROPERTY(QQuickItem *appBar READ appBar WRITE setAppBar NOTIFY appBarChanged)
Q_PROPERTY(QQuickItem *maximizeButton READ maximizeButton WRITE setMaximizeButton NOTIFY maximizeButtonChanged)
Q_PROPERTY(QQuickItem *minimizedButton READ minimizedButton WRITE setMinimizedButton NOTIFY minimizedButtonChanged)
Q_PROPERTY(QQuickItem *closeButton READ closeButton WRITE setCloseButton NOTIFY closeButtonChanged)
Q_PROPERTY(bool fixSize READ fixSize WRITE setFixSize NOTIFY fixSizeChanged)
Q_PROPERTY(bool topmost READ topmost WRITE setTopmost NOTIFY topmostChanged)
Q_PROPERTY(bool disabled READ disabled WRITE setDisabled NOTIFY disabledChanged)
public:
Frameless(QQuickItem *parent = nullptr);
QQuickItem *appBar() const;
void setAppBar(QQuickItem *appBar);
QQuickItem *maximizeButton() const;
void setMaximizeButton(QQuickItem *button);
QQuickItem *minimizedButton() const;
void setMinimizedButton(QQuickItem *button);
QQuickItem *closeButton() const;
void setCloseButton(QQuickItem *button);
bool fixSize() const;
void setFixSize(bool fix);
bool topmost() const;
void setTopmost(bool topmost);
bool disabled() const;
void setDisabled(bool disabled);
Q_INVOKABLE void showMaximized();
Q_INVOKABLE void showMinimized();
Q_INVOKABLE void showNormal();
Q_INVOKABLE void setHitTestVisible(QQuickItem *item);
Q_INVOKABLE void onDestruction();
void componentComplete() final;
bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) final;
signals:
void appBarChanged();
void maximizeButtonChanged();
void minimizedButtonChanged();
void closeButtonChanged();
void fixSizeChanged();
void topmostChanged();
void disabledChanged();
protected:
bool isFullScreen();
bool isMaximized();
void setMaximizeHovered(bool val);
void setMaximizePressed(bool val);
void setWindowTopmost(bool topmost);
bool hitMaximizeButton();
bool hitAppBar();
void showSystemMenu(QPoint point);
bool eventFilter(QObject *obj, QEvent *event) final;
private:
quint64 m_current = 0;
QQuickItem *m_appBar = nullptr;
QQuickItem *m_maximizeButton = nullptr;
QQuickItem *m_minimizedButton = nullptr;
QQuickItem *m_closeButton = nullptr;
bool m_fixSize = false;
bool m_topmost = false;
bool m_disabled = false;
int m_margins = 8;
QList<QPointer<QQuickItem>> m_hitTestList;
bool m_isWindows11OrGreater = false;
QString m_currentEffect;
};
#endif // FRAMELESS_H