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

Commit

Permalink
quick: simplify implementation
Browse files Browse the repository at this point in the history
1. Merge the three system buttons into one class.
2. Fixed some color calculation errors of system button.
3. Removed some not used bundled resources.
4. Added function to retrieve runtime version of FramelessHelper.

Signed-off-by: Yuhang Zhao <[email protected]>
  • Loading branch information
wangwenx190 committed May 13, 2022
1 parent 8042a78 commit d13d747
Show file tree
Hide file tree
Showing 24 changed files with 272 additions and 613 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
cmake_minimum_required(VERSION 3.20)

project(FramelessHelper
VERSION 2.1.0.0
VERSION 2.1.1.0
DESCRIPTION "Cross-platform window customization framework for Qt Widgets and Qt Quick."
HOMEPAGE_URL "https://github.com/wangwenx190/framelesshelper/"
LANGUAGES CXX
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ void MyWidget::myFunction2()
}
```

**IMPORTANT NOTE**: Some functionalities may only be available when `FramelessHelper` has finished the window customization process, such as changing window geometry/flags/state. In this case you can connect to the public `void ready()` signal of `FramelessHelper` to get the accurate time point and do your rest initialization process afterwards.

### Qt Quick

#### Code snippet
Expand Down Expand Up @@ -223,6 +225,26 @@ If you find any of `FramelessHelper` functions have no effect after calling, the

There's also a QML type called `FramelessWindow`, it's only a simple wrapper of `FramelessHelper`, you can absolutely use plain `Window` instead.

**IMPORTANT NOTE**: Some functionalities may only be available when `FramelessHelper` has finished the window customization process, such as changing window geometry/flags/state. In this case you can connect to the public `void ready()` signal of `FramelessHelper` to get the accurate time point and do your rest initialization process afterwards.

```qml
Window {
FramelessHelper.onReady: {
// do something here ...
}
}
```

```qml
Window {
FramelessHelper {
onReady: {
// do something here ...
}
}
}
```

### More

Please refer to the demo projects to see more detailed usages: [examples](./examples/)
Expand Down
24 changes: 24 additions & 0 deletions include/FramelessHelper/Core/framelesshelpercore_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,31 @@ QT_END_NAMESPACE
# define FRAMELESSHELPER_PREPEND_NAMESPACE(X) ::FRAMELESSHELPER_NAMESPACE::X
#endif

#ifndef FRAMELESSHELPER_MAKE_VERSION
# define FRAMELESSHELPER_MAKE_VERSION(Major, Minor, Patch, Tweak) \
(((Major & 0xff) << 24) | ((Minor & 0xff) << 16) | ((Patch & 0xff) << 8) | (Tweak & 0xff))
#endif

#ifndef FRAMELESSHELPER_EXTRACT_VERSION
# define FRAMELESSHELPER_EXTRACT_VERSION(Version, Major, Minor, Patch, Tweak) \
{ \
Major = ((Version & 0xff) >> 24); \
Minor = ((Version & 0xff) >> 16); \
Patch = ((Version & 0xff) >> 8); \
Tweak = (Version & 0xff); \
}
#endif

FRAMELESSHELPER_BEGIN_NAMESPACE

[[maybe_unused]] static constexpr const int FRAMELESSHELPER_VERSION_MAJOR = 2;
[[maybe_unused]] static constexpr const int FRAMELESSHELPER_VERSION_MINOR = 1;
[[maybe_unused]] static constexpr const int FRAMELESSHELPER_VERSION_PATCH = 1;
[[maybe_unused]] static constexpr const int FRAMELESSHELPER_VERSION_TWEAK = 0;
[[maybe_unused]] static constexpr const int FRAMELESSHELPER_VERSION =
FRAMELESSHELPER_MAKE_VERSION(FRAMELESSHELPER_VERSION_MAJOR, FRAMELESSHELPER_VERSION_MINOR,
FRAMELESSHELPER_VERSION_PATCH, FRAMELESSHELPER_VERSION_TWEAK);

namespace Global
{

Expand Down Expand Up @@ -471,6 +494,7 @@ static_assert(std::size(WindowsVersions) == (static_cast<int>(WindowsVersion::_1
namespace FramelessHelper::Core
{
FRAMELESSHELPER_CORE_API void initialize();
[[nodiscard]] FRAMELESSHELPER_CORE_API int version();
} // namespace FramelessHelper::Core

FRAMELESSHELPER_END_NAMESPACE
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,39 @@ QT_END_NAMESPACE

FRAMELESSHELPER_BEGIN_NAMESPACE

class FRAMELESSHELPER_QUICK_API QuickStandardCloseButton : public QQuickButton
class FRAMELESSHELPER_QUICK_API QuickStandardSystemButton : public QQuickButton
{
Q_OBJECT
#ifdef QML_NAMED_ELEMENT
QML_NAMED_ELEMENT(StandardCloseButton)
QML_NAMED_ELEMENT(StandardSystemButton)
#endif
Q_DISABLE_COPY_MOVE(QuickStandardCloseButton)
Q_DISABLE_COPY_MOVE(QuickStandardSystemButton)

public:
explicit QuickStandardCloseButton(QQuickItem *parent = nullptr);
~QuickStandardCloseButton() override;
explicit QuickStandardSystemButton(QQuickItem *parent = nullptr);
explicit QuickStandardSystemButton(const QuickGlobal::SystemButtonType type, QQuickItem *parent = nullptr);
~QuickStandardSystemButton() override;

public Q_SLOTS:
void updateForeground();
void updateBackground();
void setInactive(const bool value);
void setButtonType(const QuickGlobal::SystemButtonType type);

private:
void initialize();
void checkInactive();

private:
QScopedPointer<QQuickItem> m_contentItem;
QScopedPointer<QQuickImage> m_image;
QScopedPointer<QQuickImage> m_contentItem;
QScopedPointer<QQuickRectangle> m_backgroundItem;
bool m_forceLightTheme = false;
bool m_shouldCheck = false;
bool m_checkFlag = false;
QuickGlobal::SystemButtonType m_buttonType = QuickGlobal::SystemButtonType::Unknown;
};

FRAMELESSHELPER_END_NAMESPACE

QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardCloseButton))
QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardSystemButton))
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
22 changes: 10 additions & 12 deletions include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ QT_END_NAMESPACE

FRAMELESSHELPER_BEGIN_NAMESPACE

class QuickStandardMinimizeButton;
class QuickStandardMaximizeButton;
class QuickStandardCloseButton;
class QuickStandardSystemButton;

class FRAMELESSHELPER_QUICK_API QuickStandardTitleBar : public QQuickRectangle
{
Expand All @@ -48,9 +46,9 @@ class FRAMELESSHELPER_QUICK_API QuickStandardTitleBar : public QQuickRectangle
Q_DISABLE_COPY_MOVE(QuickStandardTitleBar)
Q_PROPERTY(Qt::Alignment titleLabelAlignment READ titleLabelAlignment WRITE setTitleLabelAlignment NOTIFY titleLabelAlignmentChanged FINAL)
Q_PROPERTY(QQuickLabel* titleLabel READ titleLabel CONSTANT FINAL)
Q_PROPERTY(QuickStandardMinimizeButton* minimizeButton READ minimizeButton CONSTANT FINAL)
Q_PROPERTY(QuickStandardMaximizeButton* maximizeButton READ maximizeButton CONSTANT FINAL)
Q_PROPERTY(QuickStandardCloseButton* closeButton READ closeButton CONSTANT FINAL)
Q_PROPERTY(QuickStandardSystemButton* minimizeButton READ minimizeButton CONSTANT FINAL)
Q_PROPERTY(QuickStandardSystemButton* maximizeButton READ maximizeButton CONSTANT FINAL)
Q_PROPERTY(QuickStandardSystemButton* closeButton READ closeButton CONSTANT FINAL)
Q_PROPERTY(bool extended READ isExtended WRITE setExtended NOTIFY extendedChanged FINAL)

public:
Expand All @@ -61,9 +59,9 @@ class FRAMELESSHELPER_QUICK_API QuickStandardTitleBar : public QQuickRectangle
void setTitleLabelAlignment(const Qt::Alignment value);

Q_NODISCARD QQuickLabel *titleLabel() const;
Q_NODISCARD QuickStandardMinimizeButton *minimizeButton() const;
Q_NODISCARD QuickStandardMaximizeButton *maximizeButton() const;
Q_NODISCARD QuickStandardCloseButton *closeButton() const;
Q_NODISCARD QuickStandardSystemButton *minimizeButton() const;
Q_NODISCARD QuickStandardSystemButton *maximizeButton() const;
Q_NODISCARD QuickStandardSystemButton *closeButton() const;

Q_NODISCARD bool isExtended() const;
void setExtended(const bool value);
Expand Down Expand Up @@ -93,9 +91,9 @@ private Q_SLOTS:
Qt::Alignment m_labelAlignment = {};
QScopedPointer<QQuickLabel> m_windowTitleLabel;
QScopedPointer<QQuickRow> m_systemButtonsRow;
QScopedPointer<QuickStandardMinimizeButton> m_minimizeButton;
QScopedPointer<QuickStandardMaximizeButton> m_maximizeButton;
QScopedPointer<QuickStandardCloseButton> m_closeButton;
QScopedPointer<QuickStandardSystemButton> m_minimizeButton;
QScopedPointer<QuickStandardSystemButton> m_maximizeButton;
QScopedPointer<QuickStandardSystemButton> m_closeButton;
QMetaObject::Connection m_windowStateChangeConnection = {};
QMetaObject::Connection m_windowActiveChangeConnection = {};
QMetaObject::Connection m_windowTitleChangeConnection = {};
Expand Down
4 changes: 2 additions & 2 deletions src/core/framelesshelpercore.rc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,0,0,0
PRODUCTVERSION 2,1,0,0
PRODUCTVERSION 2,1,1,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
Expand All @@ -51,7 +51,7 @@ BEGIN
VALUE "OriginalFilename", "FramelessHelperCore.dll"
#endif
VALUE "ProductName", "FramelessHelper"
VALUE "ProductVersion", "2.1.0.0"
VALUE "ProductVersion", "2.1.1.0"
VALUE "InternalName", "FramelessHelperCore"
END
END
Expand Down
5 changes: 5 additions & 0 deletions src/core/framelessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,9 @@ void FramelessHelper::Core::initialize()
qRegisterMetaType<SystemParameters>();
}

int FramelessHelper::Core::version()
{
return FRAMELESSHELPER_VERSION;
}

FRAMELESSHELPER_END_NAMESPACE
8 changes: 2 additions & 6 deletions src/quick/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,12 @@ set(SOURCES
${INCLUDE_PREFIX}/framelessquickmodule.h
${INCLUDE_PREFIX}/framelessquickhelper.h
${INCLUDE_PREFIX}/framelessquickutils.h
${INCLUDE_PREFIX}/private/quickstandardminimizebutton_p.h
${INCLUDE_PREFIX}/private/quickstandardmaximizebutton_p.h
${INCLUDE_PREFIX}/private/quickstandardclosebutton_p.h
${INCLUDE_PREFIX}/private/quickstandardsystembutton_p.h
${INCLUDE_PREFIX}/private/quickstandardtitlebar_p.h
${INCLUDE_PREFIX}/private/framelessquickhelper_p.h
${INCLUDE_PREFIX}/private/framelessquickwindow_p.h
${INCLUDE_PREFIX}/private/framelessquickwindow_p_p.h
quickstandardminimizebutton.cpp
quickstandardmaximizebutton.cpp
quickstandardclosebutton.cpp
quickstandardsystembutton.cpp
quickstandardtitlebar.cpp
framelessquickutils.cpp
framelessquickmodule.cpp
Expand Down
3 changes: 0 additions & 3 deletions src/quick/framelesshelperquick.qrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<RCC>
<qresource prefix="/org/wangwenx190/FramelessHelper">
<file alias="qmldir">module/qmldir</file>
</qresource>
<qresource prefix="/org.wangwenx190.FramelessHelper">
<file alias="images/dark/chrome-close.svg">../core/images/dark/chrome-close.svg</file>
<file alias="images/dark/chrome-maximize.svg">../core/images/dark/chrome-maximize.svg</file>
Expand Down
Loading

0 comments on commit d13d747

Please sign in to comment.