forked from github_mirror/framelesshelper
Minor improvements.
Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
7c255ea79e
commit
1c0e4a4657
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
import QtQuick 2.15
|
import QtQuick 2.15
|
||||||
import QtQuick.Window 2.15
|
import QtQuick.Window 2.15
|
||||||
|
import QtQuick.Controls 2.15
|
||||||
|
import QtQuick.Layouts 1.15
|
||||||
import wangwenx190.Utils 1.0
|
import wangwenx190.Utils 1.0
|
||||||
|
|
||||||
Window {
|
Window {
|
||||||
|
@ -32,6 +34,7 @@ Window {
|
||||||
width: 800
|
width: 800
|
||||||
height: 600
|
height: 600
|
||||||
title: qsTr("Hello, World!")
|
title: qsTr("Hello, World!")
|
||||||
|
color: blurEffectCheckBox.checked ? "transparent" : "#f0f0f0"
|
||||||
|
|
||||||
FramelessHelper {
|
FramelessHelper {
|
||||||
id: framelessHelper
|
id: framelessHelper
|
||||||
|
@ -40,14 +43,14 @@ Window {
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: titleBar
|
id: titleBar
|
||||||
height: framelessHelper.titleBarHeight
|
height: framelessHelper.titleBarHeight
|
||||||
color: (window.active && framelessHelper.colorizationEnabled) ? framelessHelper.colorizationColor : "white"
|
color: extendToTitleBarCheckBox.checked ? "transparent" : ((window.active && framelessHelper.colorizationEnabled) ? framelessHelper.colorizationColor : "white")
|
||||||
anchors {
|
anchors {
|
||||||
top: parent.top
|
top: parent.top
|
||||||
left: parent.left
|
left: parent.left
|
||||||
right: parent.right
|
right: parent.right
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Label {
|
||||||
id: titleBarText
|
id: titleBarText
|
||||||
text: window.title
|
text: window.title
|
||||||
font.pointSize: 13
|
font.pointSize: 13
|
||||||
|
@ -93,13 +96,66 @@ Window {
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: content
|
id: content
|
||||||
color: "#f0f0f0"
|
color: "transparent"
|
||||||
anchors {
|
anchors {
|
||||||
top: titleBar.bottom
|
top: titleBar.bottom
|
||||||
bottom: parent.bottom
|
bottom: parent.bottom
|
||||||
left: parent.left
|
left: parent.left
|
||||||
right: parent.right
|
right: parent.right
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ColumnLayout {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
spacing: 25
|
||||||
|
|
||||||
|
Label {
|
||||||
|
Layout.alignment: Qt.AlignCenter
|
||||||
|
font.pointSize: 15
|
||||||
|
font.bold: true
|
||||||
|
text: qsTr("Current system theme: %1").arg(framelessHelper.darkThemeEnabled ? "dark theme" : "light theme")
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
Layout.alignment: Qt.AlignCenter
|
||||||
|
font.pointSize: 15
|
||||||
|
font.bold: true
|
||||||
|
text: qsTr("Transparency effect: %1").arg(framelessHelper.transparencyEffectEnabled ? "enabled" : "disabled")
|
||||||
|
}
|
||||||
|
|
||||||
|
CheckBox {
|
||||||
|
id: blurEffectCheckBox
|
||||||
|
Layout.alignment: Qt.AlignCenter
|
||||||
|
font.pointSize: 15
|
||||||
|
font.bold: true
|
||||||
|
text: qsTr("Enable blur effect")
|
||||||
|
onCheckedChanged: framelessHelper.setBlurEffectEnabled(checked, forceAcrylicCheckBox.checked)
|
||||||
|
}
|
||||||
|
|
||||||
|
CheckBox {
|
||||||
|
id: forceAcrylicCheckBox
|
||||||
|
Layout.alignment: Qt.AlignCenter
|
||||||
|
font.pointSize: 15
|
||||||
|
font.bold: true
|
||||||
|
text: qsTr("Force enabling Acrylic effect")
|
||||||
|
enabled: framelessHelper.canHaveWindowFrame
|
||||||
|
}
|
||||||
|
|
||||||
|
CheckBox {
|
||||||
|
id: extendToTitleBarCheckBox
|
||||||
|
Layout.alignment: Qt.AlignCenter
|
||||||
|
font.pointSize: 15
|
||||||
|
font.bold: true
|
||||||
|
text: qsTr("Extend to title bar")
|
||||||
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
Layout.alignment: Qt.AlignCenter
|
||||||
|
text: qsTr("Move to desktop center")
|
||||||
|
font.pointSize: 15
|
||||||
|
font.bold: true
|
||||||
|
onClicked: framelessHelper.moveWindowToDesktopCenter(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
|
|
@ -36,6 +36,7 @@ namespace {
|
||||||
|
|
||||||
const char g_sPreserveWindowFrame[] = "WNEF_FORCE_PRESERVE_WINDOW_FRAME";
|
const char g_sPreserveWindowFrame[] = "WNEF_FORCE_PRESERVE_WINDOW_FRAME";
|
||||||
const char g_sDontExtendFrame[] = "WNEF_DO_NOT_EXTEND_FRAME";
|
const char g_sDontExtendFrame[] = "WNEF_DO_NOT_EXTEND_FRAME";
|
||||||
|
const char g_sForceUseAcrylicEffect[] = "WNEF_FORCE_ACRYLIC_ON_WIN10";
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
#endif
|
#endif
|
||||||
|
@ -117,6 +118,31 @@ QColor FramelessQuickHelper::colorizationColor() const
|
||||||
{
|
{
|
||||||
return WinNativeEventFilter::colorizationColor();
|
return WinNativeEventFilter::colorizationColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FramelessQuickHelper::lightThemeEnabled() const
|
||||||
|
{
|
||||||
|
return WinNativeEventFilter::lightThemeEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FramelessQuickHelper::darkThemeEnabled() const
|
||||||
|
{
|
||||||
|
return WinNativeEventFilter::darkThemeEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FramelessQuickHelper::highContrastModeEnabled() const
|
||||||
|
{
|
||||||
|
return WinNativeEventFilter::highContrastModeEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FramelessQuickHelper::darkFrameEnabled() const
|
||||||
|
{
|
||||||
|
return WinNativeEventFilter::darkFrameEnabled(rawHandle());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FramelessQuickHelper::transparencyEffectEnabled() const
|
||||||
|
{
|
||||||
|
return WinNativeEventFilter::transparencyEffectEnabled();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QSize FramelessQuickHelper::minimumSize() const
|
QSize FramelessQuickHelper::minimumSize() const
|
||||||
|
@ -194,6 +220,20 @@ void FramelessQuickHelper::timerEvent(QTimerEvent *event)
|
||||||
QQuickItem::timerEvent(event);
|
QQuickItem::timerEvent(event);
|
||||||
Q_EMIT colorizationEnabledChanged(colorizationEnabled());
|
Q_EMIT colorizationEnabledChanged(colorizationEnabled());
|
||||||
Q_EMIT colorizationColorChanged(colorizationColor());
|
Q_EMIT colorizationColorChanged(colorizationColor());
|
||||||
|
Q_EMIT lightThemeEnabledChanged(lightThemeEnabled());
|
||||||
|
Q_EMIT darkThemeEnabledChanged(darkThemeEnabled());
|
||||||
|
Q_EMIT highContrastModeEnabledChanged(highContrastModeEnabled());
|
||||||
|
Q_EMIT darkFrameEnabledChanged(darkFrameEnabled());
|
||||||
|
Q_EMIT transparencyEffectEnabledChanged(transparencyEffectEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
void *FramelessQuickHelper::rawHandle() const
|
||||||
|
{
|
||||||
|
QWindow *win = window();
|
||||||
|
if (win) {
|
||||||
|
return reinterpret_cast<void *>(win->winId());
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramelessQuickHelper::setWindowFrameVisible(const bool value)
|
void FramelessQuickHelper::setWindowFrameVisible(const bool value)
|
||||||
|
@ -206,4 +246,21 @@ void FramelessQuickHelper::setWindowFrameVisible(const bool value)
|
||||||
qunsetenv(g_sDontExtendFrame);
|
qunsetenv(g_sDontExtendFrame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FramelessQuickHelper::displaySystemMenu(const int x, const int y, const bool isRtl)
|
||||||
|
{
|
||||||
|
WinNativeEventFilter::displaySystemMenu(rawHandle(), isRtl, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FramelessQuickHelper::setBlurEffectEnabled(const bool enabled,
|
||||||
|
const bool forceAcrylic,
|
||||||
|
const QColor &gradientColor)
|
||||||
|
{
|
||||||
|
if (forceAcrylic) {
|
||||||
|
qputenv(g_sForceUseAcrylicEffect, "1");
|
||||||
|
} else {
|
||||||
|
qunsetenv(g_sForceUseAcrylicEffect);
|
||||||
|
}
|
||||||
|
WinNativeEventFilter::setBlurEffectEnabled(rawHandle(), enabled, gradientColor);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -62,6 +62,13 @@ class FRAMELESSHELPER_EXPORT FramelessQuickHelper : public QQuickItem
|
||||||
Q_PROPERTY(bool canHaveWindowFrame READ canHaveWindowFrame CONSTANT)
|
Q_PROPERTY(bool canHaveWindowFrame READ canHaveWindowFrame CONSTANT)
|
||||||
Q_PROPERTY(bool colorizationEnabled READ colorizationEnabled NOTIFY colorizationEnabledChanged)
|
Q_PROPERTY(bool colorizationEnabled READ colorizationEnabled NOTIFY colorizationEnabledChanged)
|
||||||
Q_PROPERTY(QColor colorizationColor READ colorizationColor NOTIFY colorizationColorChanged)
|
Q_PROPERTY(QColor colorizationColor READ colorizationColor NOTIFY colorizationColorChanged)
|
||||||
|
Q_PROPERTY(bool lightThemeEnabled READ lightThemeEnabled NOTIFY lightThemeEnabledChanged)
|
||||||
|
Q_PROPERTY(bool darkThemeEnabled READ darkThemeEnabled NOTIFY darkThemeEnabledChanged)
|
||||||
|
Q_PROPERTY(bool highContrastModeEnabled READ highContrastModeEnabled NOTIFY
|
||||||
|
highContrastModeEnabledChanged)
|
||||||
|
Q_PROPERTY(bool darkFrameEnabled READ darkFrameEnabled NOTIFY darkFrameEnabledChanged)
|
||||||
|
Q_PROPERTY(bool transparencyEffectEnabled READ transparencyEffectEnabled NOTIFY
|
||||||
|
transparencyEffectEnabledChanged)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -93,6 +100,11 @@ public:
|
||||||
bool canHaveWindowFrame() const;
|
bool canHaveWindowFrame() const;
|
||||||
bool colorizationEnabled() const;
|
bool colorizationEnabled() const;
|
||||||
QColor colorizationColor() const;
|
QColor colorizationColor() const;
|
||||||
|
bool lightThemeEnabled() const;
|
||||||
|
bool darkThemeEnabled() const;
|
||||||
|
bool highContrastModeEnabled() const;
|
||||||
|
bool darkFrameEnabled() const;
|
||||||
|
bool transparencyEffectEnabled() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
@ -112,11 +124,18 @@ public Q_SLOTS:
|
||||||
|
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
void setWindowFrameVisible(const bool value = true);
|
void setWindowFrameVisible(const bool value = true);
|
||||||
|
void displaySystemMenu(const int x, const int y, const bool isRtl = false);
|
||||||
|
void setBlurEffectEnabled(const bool enabled = true,
|
||||||
|
const bool forceAcrylic = false,
|
||||||
|
const QColor &gradientColor = Qt::white);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
protected:
|
protected:
|
||||||
void timerEvent(QTimerEvent *event) override;
|
void timerEvent(QTimerEvent *event) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void *rawHandle() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
@ -130,5 +149,10 @@ Q_SIGNALS:
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
void colorizationEnabledChanged(bool);
|
void colorizationEnabledChanged(bool);
|
||||||
void colorizationColorChanged(const QColor &);
|
void colorizationColorChanged(const QColor &);
|
||||||
|
void lightThemeEnabledChanged(bool);
|
||||||
|
void darkThemeEnabledChanged(bool);
|
||||||
|
void highContrastModeEnabledChanged(bool);
|
||||||
|
void darkFrameEnabledChanged(bool);
|
||||||
|
void transparencyEffectEnabledChanged(bool);
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue