refactor(FramelessWindow): use Qt API for window resizing (#81)

No longer use Win32API for window resizing. This should work under all platforms that support window resizing.
This commit is contained in:
2023-06-24 14:37:54 +08:00
committed by GitHub
parent 6f28878837
commit 6fc9534184
3 changed files with 114 additions and 90 deletions

View File

@ -7,12 +7,6 @@
#include <QWidget>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
typedef qintptr NATIVE_RESULT;
#else
typedef long NATIVE_RESULT;
#endif // QT_VERSION_CHECK(6, 0, 0)
QT_BEGIN_NAMESPACE
class QVBoxLayout;
QT_END_NAMESPACE
@ -24,11 +18,20 @@ public:
explicit FramelessWindow(QWidget *parent = nullptr);
void setCentralWidget(QWidget * widget);
void installResizeCapture(QObject* widget);
protected:
bool nativeEvent(const QByteArray& eventType, void* message, NATIVE_RESULT* result) override;
bool eventFilter(QObject *o, QEvent *e) override;
bool mouseHover(QHoverEvent* event, QWidget* wg);
bool mousePress(QMouseEvent* event);
private:
Qt::Edges m_oldEdges;
Qt::CursorShape m_oldCursorShape;
Qt::CursorShape getCursorByEdge(const Qt::Edges& edges, Qt::CursorShape default_cursor);
Qt::Edges getEdgesByPos(const QPoint pos, const QRect& winrect);
QVBoxLayout * m_centralLayout = nullptr;
QWidget * m_centralWidget = nullptr; // just a pointer, doesn't take the ownership.
};