Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
quick: PIMPL refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwenx190 committed Aug 24, 2023
1 parent 15212ab commit 5c8ac27
Show file tree
Hide file tree
Showing 15 changed files with 481 additions and 880 deletions.
6 changes: 0 additions & 6 deletions examples/dialog/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <FramelessHelper/Widgets/standardtitlebar.h>
#include <FramelessHelper/Widgets/framelesswidgetshelper.h>
#include <FramelessHelper/Widgets/standardsystembutton.h>
#include <FramelessHelper/Widgets/private/framelesswidgetshelper_p.h>
#include "../shared/settings.h"

extern template void Settings::set<QRect>(const QString &, const QString &, const QRect &);
Expand Down Expand Up @@ -138,11 +137,6 @@ void Dialog::setupUi()
helper->setSystemButton(titleBar->maximizeButton(), SystemButtonType::Maximize);
helper->setSystemButton(titleBar->closeButton(), SystemButtonType::Close);
#endif // Q_OS_MACOS
// Special hack to disable the overriding of the mouse cursor, it's totally different
// with making the window un-resizable: we still want the window be able to resize
// programatically, but we also want the user not able to resize the window manually.
// So apparently we can't use QWidget::setFixedWidth/Height/Size() here.
FramelessWidgetsHelperPrivate::get(helper)->setProperty(kDontOverrideCursorVar, true);
}

void Dialog::waitReady()
Expand Down
2 changes: 1 addition & 1 deletion include/FramelessHelper/Quick/framelessquickutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class FRAMELESSHELPER_QUICK_API FramelessQuickUtils : public QObject, public QQm
Q_NODISCARD QColor defaultSystemButtonBackgroundColor() const;
Q_NODISCARD QColor defaultSystemCloseButtonBackgroundColor() const;

Q_NODISCARD Q_INVOKABLE QColor getSystemButtonBackgroundColor(
Q_NODISCARD Q_SLOT QColor getSystemButtonBackgroundColor(
const QuickGlobal::SystemButtonType button, const QuickGlobal::ButtonState state);

protected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,9 @@ class FRAMELESSHELPER_QUICK_API FramelessQuickApplicationWindowPrivate : public
Q_NODISCARD static FramelessQuickApplicationWindowPrivate *get(FramelessQuickApplicationWindow *pub);
Q_NODISCARD static const FramelessQuickApplicationWindowPrivate *get(const FramelessQuickApplicationWindow *pub);

Q_INVOKABLE Q_NODISCARD bool isHidden() const;
Q_INVOKABLE Q_NODISCARD bool isNormal() const;
Q_INVOKABLE Q_NODISCARD bool isMinimized() const;
Q_INVOKABLE Q_NODISCARD bool isMaximized() const;
Q_INVOKABLE Q_NODISCARD bool isZoomed() const;
Q_INVOKABLE Q_NODISCARD bool isFullScreen() const;

public Q_SLOTS:
void showMinimized2();
void toggleMaximized();
void toggleFullScreen();

private:
void initialize();

private:
FramelessQuickApplicationWindow *q_ptr = nullptr;
QuickWindowBorder *m_windowBorder = nullptr;
QQuickWindow::Visibility m_savedVisibility = QQuickWindow::Windowed;
QuickWindowBorder *windowBorder = nullptr;
QQuickWindow::Visibility savedVisibility = QQuickWindow::Windowed;
};

FRAMELESSHELPER_END_NAMESPACE
Expand Down
38 changes: 5 additions & 33 deletions include/FramelessHelper/Quick/private/framelessquickhelper_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,11 @@ class FRAMELESSHELPER_QUICK_API FramelessQuickHelperPrivate : public QObject
Q_NODISCARD static FramelessQuickHelperPrivate *get(FramelessQuickHelper *pub);
Q_NODISCARD static const FramelessQuickHelperPrivate *get(const FramelessQuickHelper *pub);

Q_NODISCARD bool isContentExtendedIntoTitleBar() const;
void extendsContentIntoTitleBar(const bool value);

Q_NODISCARD QQuickItem *getTitleBarItem() const;
void setTitleBarItem(QQuickItem *value);

void attach();
void detach();
void setSystemButton(QQuickItem *item, const QuickGlobal::SystemButtonType buttonType);
void setHitTestVisible(QQuickItem *item, const bool visible = true);
void setHitTestVisible(const QRect &rect, const bool visible = true);
void setHitTestVisible(QObject *object, const bool visible = true);
void showSystemMenu(const QPoint &pos);
void windowStartSystemMove2(const QPoint &pos);
void windowStartSystemResize2(const Qt::Edges edges, const QPoint &pos);

void moveWindowToDesktopCenter();
void bringWindowToFront();

Q_NODISCARD bool isWindowFixedSize() const;
void setWindowFixedSize(const bool value);

void emitSignalForAllInstances(const char *signal);

Q_NODISCARD bool isBlurBehindWindowEnabled() const;
void setBlurBehindWindowEnabled(const bool value, const QColor &color);

void setProperty(const char *name, const QVariant &value);
Q_NODISCARD QVariant getProperty(const char *name, const QVariant &defaultValue = {});

Expand All @@ -86,15 +64,11 @@ class FRAMELESSHELPER_QUICK_API FramelessQuickHelperPrivate : public QObject

Q_NODISCARD static FramelessQuickHelper *findOrCreateFramelessHelper(QObject *object);

Q_NODISCARD bool isReady() const;
void waitForReady();

void repaintAllChildren(const quint32 delay = 0) const;

Q_NODISCARD quint32 readyWaitTime() const;
void setReadyWaitTime(const quint32 time);

private:
Q_NODISCARD QRect mapItemGeometryToScene(const QQuickItem * const item) const;
Q_NODISCARD bool isInSystemButtons(const QPoint &pos, QuickGlobal::SystemButtonType *button) const;
Q_NODISCARD bool isInTitleBarDraggableArea(const QPoint &pos) const;
Expand All @@ -104,14 +78,12 @@ class FRAMELESSHELPER_QUICK_API FramelessQuickHelperPrivate : public QObject
Q_NODISCARD FramelessQuickHelperData *getWindowDataMutable() const;
void rebindWindow();

private:
FramelessQuickHelper *q_ptr = nullptr;
QColor m_savedWindowBackgroundColor = {};
bool m_blurBehindWindowEnabled = false;
std::optional<bool> m_extendIntoTitleBar = std::nullopt;
bool m_destroying = false;
bool m_qpaReady = false;
quint32 m_qpaWaitTime = 0;
QColor savedWindowBackgroundColor = {};
bool blurBehindWindowEnabled = false;
std::optional<bool> extendIntoTitleBar = std::nullopt;
bool qpaReady = false;
quint32 qpaWaitTime = 0;
};

FRAMELESSHELPER_END_NAMESPACE
20 changes: 2 additions & 18 deletions include/FramelessHelper/Quick/private/framelessquickwindow_p_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,9 @@ class FRAMELESSHELPER_QUICK_API FramelessQuickWindowPrivate : public QObject
Q_NODISCARD static FramelessQuickWindowPrivate *get(FramelessQuickWindow *pub);
Q_NODISCARD static const FramelessQuickWindowPrivate *get(const FramelessQuickWindow *pub);

Q_INVOKABLE Q_NODISCARD bool isHidden() const;
Q_INVOKABLE Q_NODISCARD bool isNormal() const;
Q_INVOKABLE Q_NODISCARD bool isMinimized() const;
Q_INVOKABLE Q_NODISCARD bool isMaximized() const;
Q_INVOKABLE Q_NODISCARD bool isZoomed() const;
Q_INVOKABLE Q_NODISCARD bool isFullScreen() const;

public Q_SLOTS:
void showMinimized2();
void toggleMaximized();
void toggleFullScreen();

private:
void initialize();

private:
FramelessQuickWindow *q_ptr = nullptr;
QuickWindowBorder *m_windowBorder = nullptr;
QQuickWindow::Visibility m_savedVisibility = QQuickWindow::Windowed;
QuickWindowBorder *windowBorder = nullptr;
QQuickWindow::Visibility savedVisibility = QQuickWindow::Windowed;
};

FRAMELESSHELPER_END_NAMESPACE
Expand Down
10 changes: 1 addition & 9 deletions include/FramelessHelper/Quick/private/quickimageitem_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,15 @@ class FRAMELESSHELPER_QUICK_API QuickImageItemPrivate : public QObject
Q_NODISCARD static QuickImageItemPrivate *get(QuickImageItem *q);
Q_NODISCARD static const QuickImageItemPrivate *get(const QuickImageItem *q);

void paint(QPainter *painter) const;

Q_NODISCARD QVariant source() const;
void setSource(const QVariant &value);

private:
void initialize();
void fromUrl(const QUrl &value, QPainter *painter) const;
void fromString(const QString &value, QPainter *painter) const;
void fromImage(const QImage &value, QPainter *painter) const;
void fromPixmap(const QPixmap &value, QPainter *painter) const;
void fromIcon(const QIcon &value, QPainter *painter) const;
Q_NODISCARD QRectF paintArea() const;

private:
QuickImageItem *q_ptr = nullptr;
QVariant m_source = {};
QVariant source = {};
};

FRAMELESSHELPER_END_NAMESPACE
14 changes: 5 additions & 9 deletions include/FramelessHelper/Quick/private/quickmicamaterial_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,15 @@ class FRAMELESSHELPER_QUICK_API QuickMicaMaterialPrivate : public QObject
Q_NODISCARD static QuickMicaMaterialPrivate *get(QuickMicaMaterial *q);
Q_NODISCARD static const QuickMicaMaterialPrivate *get(const QuickMicaMaterial *q);

public Q_SLOTS:
void rebindWindow();
void repaint(QPainter *painter);
Q_SLOT void rebindWindow();

private:
void initialize();

private:
QuickMicaMaterial *q_ptr = nullptr;
QMetaObject::Connection m_rootWindowXChangedConnection = {};
QMetaObject::Connection m_rootWindowYChangedConnection = {};
QMetaObject::Connection m_rootWindowActiveChangedConnection = {};
MicaMaterial *m_micaMaterial = nullptr;
QMetaObject::Connection rootWindowXChangedConnection = {};
QMetaObject::Connection rootWindowYChangedConnection = {};
QMetaObject::Connection rootWindowActiveChangedConnection = {};
MicaMaterial *micaMaterial = nullptr;
};

FRAMELESSHELPER_END_NAMESPACE
13 changes: 4 additions & 9 deletions include/FramelessHelper/Quick/private/quickwindowborder_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,15 @@ class FRAMELESSHELPER_QUICK_API QuickWindowBorderPrivate : public QObject
Q_NODISCARD static QuickWindowBorderPrivate *get(QuickWindowBorder *q);
Q_NODISCARD static const QuickWindowBorderPrivate *get(const QuickWindowBorder *q);

void paint(QPainter *painter) const;
Q_SLOT void update();

public Q_SLOTS:
void update();

private:
void initialize();
void rebindWindow();

private:
QuickWindowBorder *q_ptr = nullptr;
WindowBorderPainter *m_borderPainter = nullptr;
QMetaObject::Connection m_activeChangeConnection = {};
QMetaObject::Connection m_visibilityChangeConnection = {};
WindowBorderPainter *borderPainter = nullptr;
QMetaObject::Connection activeChangeConnection = {};
QMetaObject::Connection visibilityChangeConnection = {};
};

FRAMELESSHELPER_END_NAMESPACE
Loading

0 comments on commit 5c8ac27

Please sign in to comment.