Quick: make the titleBarItem become a property

By making it a Q_PROPERTY we can use it more conveniently.

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-04-25 14:50:41 +08:00
parent fd2b3f5e84
commit 2f629a9e5b
6 changed files with 29 additions and 9 deletions

View File

@ -78,6 +78,7 @@ Please refer to the demo applications to see more detailed usages: [examples](./
- Force your application use the ANGLE backend instead of the Desktop OpenGL. - Force your application use the ANGLE backend instead of the Desktop OpenGL.
- Force your application use pure software rendering instead of rendering through OpenGL. - Force your application use pure software rendering instead of rendering through OpenGL.
- Or just don't use OpenGL at all, try to use Direct3D/Vulkan/Metal instead. - Or just don't use OpenGL at all, try to use Direct3D/Vulkan/Metal instead.
- Due to there are many sub-versions of Windows 10, it's highly recommended to use the latest version of Windows 10, at least no older than Windows 10 1809. If you try to use this framework on some very old Windows 10 versions such as 1507 or 1607, there may be some compatibility issues. Using this framework on Windows 7 is also supported but not recommended. To get the most stable behavior and the best appearance, you should use it on the latest version of Windows 10 or Windows 11.
### Linux ### Linux

View File

@ -78,7 +78,7 @@ FramelessWindow {
window.snapToTopBorder(titleBar, FramelessHelper.Top, FramelessHelper.Bottom); window.snapToTopBorder(titleBar, FramelessHelper.Top, FramelessHelper.Bottom);
// Make our homemade title bar draggable, and on Windows, open the system menu // Make our homemade title bar draggable, and on Windows, open the system menu
// when the user right clicks on the title bar area. // when the user right clicks on the title bar area.
window.setTitleBarItem(titleBar); window.titleBarItem = titleBar;
// Make our homemade system buttons visible to hit test. // Make our homemade system buttons visible to hit test.
// The call to "setHitTestVisible()" is necessary, don't forget to do it. // The call to "setHitTestVisible()" is necessary, don't forget to do it.
window.setHitTestVisible(minimizeButton); window.setHitTestVisible(minimizeButton);

View File

@ -45,9 +45,10 @@ class FRAMELESSHELPER_QUICK_API FramelessQuickWindow : public QQuickWindow
Q_PROPERTY(bool minimized READ isMinimized NOTIFY minimizedChanged FINAL) Q_PROPERTY(bool minimized READ isMinimized NOTIFY minimizedChanged FINAL)
Q_PROPERTY(bool zoomed READ isZoomed NOTIFY zoomedChanged FINAL) Q_PROPERTY(bool zoomed READ isZoomed NOTIFY zoomedChanged FINAL)
Q_PROPERTY(bool fullScreen READ isFullScreen NOTIFY fullScreenChanged FINAL) Q_PROPERTY(bool fullScreen READ isFullScreen NOTIFY fullScreenChanged FINAL)
Q_PROPERTY(bool fixedSize READ fixedSize WRITE setFixedSize NOTIFY fixedSizeChanged FINAL) Q_PROPERTY(bool fixedSize READ isFixedSize WRITE setFixedSize NOTIFY fixedSizeChanged FINAL)
Q_PROPERTY(QColor frameBorderColor READ frameBorderColor NOTIFY frameBorderColorChanged FINAL) Q_PROPERTY(QColor frameBorderColor READ frameBorderColor NOTIFY frameBorderColorChanged FINAL)
Q_PROPERTY(QuickGlobal::Options options READ options WRITE setOptions NOTIFY optionsChanged FINAL) Q_PROPERTY(QuickGlobal::Options options READ options WRITE setOptions NOTIFY optionsChanged FINAL)
Q_PROPERTY(QQuickItem* titleBarItem READ titleBarItem WRITE setTitleBarItem NOTIFY titleBarItemChanged FINAL)
public: public:
explicit FramelessQuickWindow(QWindow *parent = nullptr, const Global::UserSettings &settings = {}); explicit FramelessQuickWindow(QWindow *parent = nullptr, const Global::UserSettings &settings = {});
@ -59,7 +60,7 @@ public:
Q_NODISCARD bool isZoomed() const; Q_NODISCARD bool isZoomed() const;
Q_NODISCARD bool isFullScreen() const; Q_NODISCARD bool isFullScreen() const;
Q_NODISCARD bool fixedSize() const; Q_NODISCARD bool isFixedSize() const;
void setFixedSize(const bool value); void setFixedSize(const bool value);
Q_NODISCARD QColor frameBorderColor() const; Q_NODISCARD QColor frameBorderColor() const;
@ -67,6 +68,9 @@ public:
Q_NODISCARD QuickGlobal::Options options() const; Q_NODISCARD QuickGlobal::Options options() const;
void setOptions(const QuickGlobal::Options value); void setOptions(const QuickGlobal::Options value);
Q_NODISCARD QQuickItem *titleBarItem() const;
void setTitleBarItem(QQuickItem *item);
public Q_SLOTS: public Q_SLOTS:
void showMinimized2(); void showMinimized2();
void toggleMaximized(); void toggleMaximized();
@ -74,7 +78,6 @@ public Q_SLOTS:
void showSystemMenu(const QPoint &pos); void showSystemMenu(const QPoint &pos);
void startSystemMove2(const QPoint &pos); void startSystemMove2(const QPoint &pos);
void startSystemResize2(const Qt::Edges edges, const QPoint &pos); void startSystemResize2(const Qt::Edges edges, const QPoint &pos);
void setTitleBarItem(QQuickItem *item);
void setHitTestVisible(QQuickItem *item); void setHitTestVisible(QQuickItem *item);
void moveToDesktopCenter(); void moveToDesktopCenter();
void bringToFront(); void bringToFront();
@ -90,6 +93,7 @@ Q_SIGNALS:
void frameBorderColorChanged(); void frameBorderColorChanged();
void systemButtonStateChanged(const QuickGlobal::SystemButtonType, const QuickGlobal::ButtonState); void systemButtonStateChanged(const QuickGlobal::SystemButtonType, const QuickGlobal::ButtonState);
void optionsChanged(); void optionsChanged();
void titleBarItemChanged();
private: private:
QScopedPointer<FramelessQuickWindowPrivate> d_ptr; QScopedPointer<FramelessQuickWindowPrivate> d_ptr;

View File

@ -1178,8 +1178,8 @@ void Utils::tryToEnableHighestDpiAwarenessLevel()
// Any attempt to change the DPI awareness level through API will always fail, // Any attempt to change the DPI awareness level through API will always fail,
// so we treat this situation as succeeded. // so we treat this situation as succeeded.
if (dwError == ERROR_ACCESS_DENIED) { if (dwError == ERROR_ACCESS_DENIED) {
qDebug() << "FramelessHelper doesn't have access to change this process's DPI awareness level," qDebug() << "FramelessHelper doesn't have access to change the current process's DPI awareness level,"
" most likely due to it has been setted externally."; " most likely due to it has been set externally already.";
return true; return true;
} }
qWarning() << __getSystemErrorMessage(kSetProcessDpiAwarenessContext, dwError); qWarning() << __getSystemErrorMessage(kSetProcessDpiAwarenessContext, dwError);
@ -1211,8 +1211,8 @@ void Utils::tryToEnableHighestDpiAwarenessLevel()
// Any attempt to change the DPI awareness level through API will always fail, // Any attempt to change the DPI awareness level through API will always fail,
// so we treat this situation as succeeded. // so we treat this situation as succeeded.
if (hr == E_ACCESSDENIED) { if (hr == E_ACCESSDENIED) {
qDebug() << "FramelessHelper doesn't have access to change this process's DPI awareness level," qDebug() << "FramelessHelper doesn't have access to change the current process's DPI awareness level,"
" most likely due to it has been setted externally."; " most likely due to it has been set externally already.";
return true; return true;
} }
qWarning() << __getSystemErrorMessage(kSetProcessDpiAwareness, hr); qWarning() << __getSystemErrorMessage(kSetProcessDpiAwareness, hr);

View File

@ -225,6 +225,8 @@ void FramelessQuickWindowPrivate::setTitleBarItem(QQuickItem *item)
return; return;
} }
m_titleBarItem = item; m_titleBarItem = item;
Q_Q(FramelessQuickWindow);
Q_EMIT q->titleBarItemChanged();
} }
void FramelessQuickWindowPrivate::setHitTestVisible(QQuickItem *item) void FramelessQuickWindowPrivate::setHitTestVisible(QQuickItem *item)
@ -773,6 +775,11 @@ QuickGlobal::Options FramelessQuickWindowPrivate::getOptions() const
return m_quickOptions; return m_quickOptions;
} }
QQuickItem *FramelessQuickWindowPrivate::getTitleBarItem() const
{
return m_titleBarItem;
}
void FramelessQuickWindowPrivate::updateTopBorderColor() void FramelessQuickWindowPrivate::updateTopBorderColor()
{ {
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
@ -831,7 +838,7 @@ bool FramelessQuickWindow::isFullScreen() const
return d->isFullScreen(); return d->isFullScreen();
} }
bool FramelessQuickWindow::fixedSize() const bool FramelessQuickWindow::isFixedSize() const
{ {
Q_D(const FramelessQuickWindow); Q_D(const FramelessQuickWindow);
return d->isFixedSize(); return d->isFixedSize();
@ -861,6 +868,12 @@ void FramelessQuickWindow::setOptions(const QuickGlobal::Options value)
d->setOptions(value); d->setOptions(value);
} }
QQuickItem *FramelessQuickWindow::titleBarItem() const
{
Q_D(const FramelessQuickWindow);
return d->getTitleBarItem();
}
void FramelessQuickWindow::setTitleBarItem(QQuickItem *item) void FramelessQuickWindow::setTitleBarItem(QQuickItem *item)
{ {
Q_ASSERT(item); Q_ASSERT(item);

View File

@ -73,6 +73,8 @@ public:
Q_INVOKABLE Q_NODISCARD QuickGlobal::Options getOptions() const; Q_INVOKABLE Q_NODISCARD QuickGlobal::Options getOptions() const;
Q_INVOKABLE Q_NODISCARD QQuickItem *getTitleBarItem() const;
public Q_SLOTS: public Q_SLOTS:
void showMinimized2(); void showMinimized2();
void toggleMaximized(); void toggleMaximized();