Kylin/Fluent/Frameless.h

92 lines
3.0 KiB
C
Raw Normal View History

2024-08-21 23:26:43 +08:00
#ifndef FRAMELESS_H
#define FRAMELESS_H
2024-08-31 04:13:21 +08:00
#include "Utilities.h"
2024-08-21 23:26:43 +08:00
#include <QAbstractNativeEventFilter>
#include <QQuickItem>
class Frameless : public QQuickItem, QAbstractNativeEventFilter {
Q_OBJECT
QML_ELEMENT
2024-08-31 04:13:21 +08:00
Q_PROPERTY_AUTO(QString, effect)
Q_PROPERTY_READONLY_AUTO(bool, effective)
Q_PROPERTY_READONLY_AUTO(QStringList, availableEffects)
2024-08-21 23:26:43 +08:00
Q_PROPERTY(QQuickItem *appBar READ appBar WRITE setAppBar NOTIFY appBarChanged)
Q_PROPERTY(QQuickItem *maximizeButton READ maximizeButton WRITE setMaximizeButton NOTIFY maximizeButtonChanged)
2024-08-23 00:04:16 +08:00
Q_PROPERTY(QQuickItem *minimizedButton READ minimizedButton WRITE setMinimizedButton NOTIFY minimizedButtonChanged)
Q_PROPERTY(QQuickItem *closeButton READ closeButton WRITE setCloseButton NOTIFY closeButtonChanged)
2024-08-21 23:26:43 +08:00
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);
2024-08-23 00:04:16 +08:00
QQuickItem *minimizedButton() const;
void setMinimizedButton(QQuickItem *button);
QQuickItem *closeButton() const;
void setCloseButton(QQuickItem *button);
2024-08-21 23:26:43 +08:00
bool fixSize() const;
void setFixSize(bool fix);
bool topmost() const;
void setTopmost(bool topmost);
bool disabled() const;
void setDisabled(bool disabled);
2024-08-31 04:13:21 +08:00
Q_INVOKABLE void showMaximized();
Q_INVOKABLE void showMinimized();
Q_INVOKABLE void showNormal();
2024-08-21 23:26:43 +08:00
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();
2024-08-23 00:04:16 +08:00
void minimizedButtonChanged();
void closeButtonChanged();
2024-08-21 23:26:43 +08:00
void fixSizeChanged();
void topmostChanged();
void disabledChanged();
2024-08-23 00:04:16 +08:00
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;
2024-08-21 23:26:43 +08:00
private:
2024-08-23 00:04:16 +08:00
quint64 m_current = 0;
2024-08-21 23:26:43 +08:00
QQuickItem *m_appBar = nullptr;
QQuickItem *m_maximizeButton = nullptr;
2024-08-23 00:04:16 +08:00
QQuickItem *m_minimizedButton = nullptr;
QQuickItem *m_closeButton = nullptr;
2024-08-21 23:26:43 +08:00
bool m_fixSize = false;
bool m_topmost = false;
bool m_disabled = false;
2024-08-23 00:04:16 +08:00
int m_margins = 8;
2024-08-21 23:26:43 +08:00
QList<QPointer<QQuickItem>> m_hitTestList;
2024-08-23 00:04:16 +08:00
bool m_isWindows11OrGreater = false;
2024-08-31 04:13:21 +08:00
QString m_currentEffect;
2024-08-21 23:26:43 +08:00
};
#endif // FRAMELESS_H