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.Window 2.15
|
||||
import QtQuick.Controls 2.15
|
||||
import QtQuick.Layouts 1.15
|
||||
import wangwenx190.Utils 1.0
|
||||
|
||||
Window {
|
||||
|
@ -32,6 +34,7 @@ Window {
|
|||
width: 800
|
||||
height: 600
|
||||
title: qsTr("Hello, World!")
|
||||
color: blurEffectCheckBox.checked ? "transparent" : "#f0f0f0"
|
||||
|
||||
FramelessHelper {
|
||||
id: framelessHelper
|
||||
|
@ -40,14 +43,14 @@ Window {
|
|||
Rectangle {
|
||||
id: titleBar
|
||||
height: framelessHelper.titleBarHeight
|
||||
color: (window.active && framelessHelper.colorizationEnabled) ? framelessHelper.colorizationColor : "white"
|
||||
color: extendToTitleBarCheckBox.checked ? "transparent" : ((window.active && framelessHelper.colorizationEnabled) ? framelessHelper.colorizationColor : "white")
|
||||
anchors {
|
||||
top: parent.top
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
}
|
||||
|
||||
Text {
|
||||
Label {
|
||||
id: titleBarText
|
||||
text: window.title
|
||||
font.pointSize: 13
|
||||
|
@ -93,13 +96,66 @@ Window {
|
|||
|
||||
Rectangle {
|
||||
id: content
|
||||
color: "#f0f0f0"
|
||||
color: "transparent"
|
||||
anchors {
|
||||
top: titleBar.bottom
|
||||
bottom: parent.bottom
|
||||
left: parent.left
|
||||
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 {
|
||||
|
|
|
@ -36,6 +36,7 @@ namespace {
|
|||
|
||||
const char g_sPreserveWindowFrame[] = "WNEF_FORCE_PRESERVE_WINDOW_FRAME";
|
||||
const char g_sDontExtendFrame[] = "WNEF_DO_NOT_EXTEND_FRAME";
|
||||
const char g_sForceUseAcrylicEffect[] = "WNEF_FORCE_ACRYLIC_ON_WIN10";
|
||||
|
||||
} // namespace
|
||||
#endif
|
||||
|
@ -117,6 +118,31 @@ QColor FramelessQuickHelper::colorizationColor() const
|
|||
{
|
||||
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
|
||||
|
||||
QSize FramelessQuickHelper::minimumSize() const
|
||||
|
@ -194,6 +220,20 @@ void FramelessQuickHelper::timerEvent(QTimerEvent *event)
|
|||
QQuickItem::timerEvent(event);
|
||||
Q_EMIT colorizationEnabledChanged(colorizationEnabled());
|
||||
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)
|
||||
|
@ -206,4 +246,21 @@ void FramelessQuickHelper::setWindowFrameVisible(const bool value)
|
|||
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
|
||||
|
|
|
@ -62,6 +62,13 @@ class FRAMELESSHELPER_EXPORT FramelessQuickHelper : public QQuickItem
|
|||
Q_PROPERTY(bool canHaveWindowFrame READ canHaveWindowFrame CONSTANT)
|
||||
Q_PROPERTY(bool colorizationEnabled READ colorizationEnabled NOTIFY colorizationEnabledChanged)
|
||||
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
|
||||
|
||||
public:
|
||||
|
@ -93,6 +100,11 @@ public:
|
|||
bool canHaveWindowFrame() const;
|
||||
bool colorizationEnabled() const;
|
||||
QColor colorizationColor() const;
|
||||
bool lightThemeEnabled() const;
|
||||
bool darkThemeEnabled() const;
|
||||
bool highContrastModeEnabled() const;
|
||||
bool darkFrameEnabled() const;
|
||||
bool transparencyEffectEnabled() const;
|
||||
#endif
|
||||
|
||||
public Q_SLOTS:
|
||||
|
@ -112,11 +124,18 @@ public Q_SLOTS:
|
|||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
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
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
protected:
|
||||
void timerEvent(QTimerEvent *event) override;
|
||||
|
||||
private:
|
||||
void *rawHandle() const;
|
||||
#endif
|
||||
|
||||
Q_SIGNALS:
|
||||
|
@ -130,5 +149,10 @@ Q_SIGNALS:
|
|||
#ifdef Q_OS_WINDOWS
|
||||
void colorizationEnabledChanged(bool);
|
||||
void colorizationColorChanged(const QColor &);
|
||||
void lightThemeEnabledChanged(bool);
|
||||
void darkThemeEnabledChanged(bool);
|
||||
void highContrastModeEnabledChanged(bool);
|
||||
void darkFrameEnabledChanged(bool);
|
||||
void transparencyEffectEnabledChanged(bool);
|
||||
#endif
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue