chore: baseline usable version
This commit is contained in:
10
libs/qwindowkit/examples/qml/CMakeLists.txt
Normal file
10
libs/qwindowkit/examples/qml/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
project(QWKExample_QML)
|
||||
|
||||
file(GLOB _src *.h *.cpp *.qrc)
|
||||
|
||||
qwk_add_example(${PROJECT_NAME}
|
||||
FEATURES cxx_std_17
|
||||
SOURCES ${_src} ../shared/resources/shared.qrc
|
||||
QT_LINKS Core Gui Qml Quick
|
||||
LINKS QWKQuick
|
||||
)
|
||||
260
libs/qwindowkit/examples/qml/FramelessWindow.qml
Normal file
260
libs/qwindowkit/examples/qml/FramelessWindow.qml
Normal file
@@ -0,0 +1,260 @@
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Window 2.15
|
||||
import QtQuick.Controls 2.15
|
||||
import Qt.labs.platform 1.1
|
||||
import QWindowKit 1.0
|
||||
|
||||
Window {
|
||||
property bool showWhenReady: true
|
||||
property alias titleBar: titleBar
|
||||
|
||||
id: window
|
||||
width: 800
|
||||
height: 600
|
||||
color: darkStyle.windowBackgroundColor
|
||||
title: qsTr("QWindowKit QtQuick Demo")
|
||||
Component.onCompleted: {
|
||||
windowAgent.setup(window)
|
||||
windowAgent.setWindowAttribute("dark-mode", true)
|
||||
if (window.showWhenReady) {
|
||||
window.visible = true
|
||||
}
|
||||
}
|
||||
|
||||
QtObject {
|
||||
id: lightStyle
|
||||
}
|
||||
|
||||
QtObject {
|
||||
id: darkStyle
|
||||
readonly property color windowBackgroundColor: "#1E1E1E"
|
||||
}
|
||||
|
||||
Timer {
|
||||
interval: 100
|
||||
running: true
|
||||
repeat: true
|
||||
onTriggered: timeLabel.text = Qt.formatTime(new Date(), "hh:mm:ss")
|
||||
}
|
||||
|
||||
WindowAgent {
|
||||
id: windowAgent
|
||||
}
|
||||
|
||||
TapHandler {
|
||||
acceptedButtons: Qt.RightButton
|
||||
onTapped: contextMenu.open()
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: titleBar
|
||||
anchors {
|
||||
top: parent.top
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
}
|
||||
height: 32
|
||||
//color: window.active ? "#3C3C3C" : "#505050"
|
||||
color: "transparent"
|
||||
Component.onCompleted: windowAgent.setTitleBar(titleBar)
|
||||
|
||||
Image {
|
||||
id: iconButton
|
||||
anchors {
|
||||
verticalCenter: parent.verticalCenter
|
||||
left: parent.left
|
||||
leftMargin: 10
|
||||
}
|
||||
width: 18
|
||||
height: 18
|
||||
mipmap: true
|
||||
source: "qrc:///app/example.png"
|
||||
fillMode: Image.PreserveAspectFit
|
||||
Component.onCompleted: windowAgent.setSystemButton(WindowAgent.WindowIcon, iconButton)
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors {
|
||||
verticalCenter: parent.verticalCenter
|
||||
left: iconButton.right
|
||||
leftMargin: 10
|
||||
}
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: window.title
|
||||
font.pixelSize: 14
|
||||
color: "#ECECEC"
|
||||
}
|
||||
|
||||
Row {
|
||||
anchors {
|
||||
top: parent.top
|
||||
right: parent.right
|
||||
}
|
||||
height: parent.height
|
||||
|
||||
QWKButton {
|
||||
id: minButton
|
||||
height: parent.height
|
||||
source: "qrc:///window-bar/minimize.svg"
|
||||
onClicked: window.showMinimized()
|
||||
Component.onCompleted: windowAgent.setSystemButton(WindowAgent.Minimize, minButton)
|
||||
}
|
||||
|
||||
QWKButton {
|
||||
id: maxButton
|
||||
height: parent.height
|
||||
source: window.visibility === Window.Maximized ? "qrc:///window-bar/restore.svg" : "qrc:///window-bar/maximize.svg"
|
||||
onClicked: {
|
||||
if (window.visibility === Window.Maximized) {
|
||||
window.showNormal()
|
||||
} else {
|
||||
window.showMaximized()
|
||||
}
|
||||
}
|
||||
Component.onCompleted: windowAgent.setSystemButton(WindowAgent.Maximize, maxButton)
|
||||
}
|
||||
|
||||
QWKButton {
|
||||
id: closeButton
|
||||
height: parent.height
|
||||
source: "qrc:///window-bar/close.svg"
|
||||
background: Rectangle {
|
||||
color: {
|
||||
if (!closeButton.enabled) {
|
||||
return "gray";
|
||||
}
|
||||
if (closeButton.pressed) {
|
||||
return "#e81123";
|
||||
}
|
||||
if (closeButton.hovered) {
|
||||
return "#e81123";
|
||||
}
|
||||
return "transparent";
|
||||
}
|
||||
}
|
||||
onClicked: window.close()
|
||||
Component.onCompleted: windowAgent.setSystemButton(WindowAgent.Close, closeButton)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
id: timeLabel
|
||||
anchors.centerIn: parent
|
||||
font {
|
||||
pointSize: 75
|
||||
bold: true
|
||||
}
|
||||
color: "#FEFEFE"
|
||||
Component.onCompleted: {
|
||||
if ($curveRenderingAvailable) {
|
||||
console.log("Curve rendering for text is available.")
|
||||
timeLabel.renderType = Text.CurveRendering
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Menu {
|
||||
id: contextMenu
|
||||
|
||||
Menu {
|
||||
id: themeMenu
|
||||
title: qsTr("Theme")
|
||||
|
||||
MenuItemGroup {
|
||||
id: themeMenuGroup
|
||||
items: themeMenu.items
|
||||
}
|
||||
|
||||
MenuItem {
|
||||
text: qsTr("Light")
|
||||
checkable: true
|
||||
onTriggered: windowAgent.setWindowAttribute("dark-mode", false)
|
||||
}
|
||||
|
||||
MenuItem {
|
||||
text: qsTr("Dark")
|
||||
checkable: true
|
||||
checked: true
|
||||
onTriggered: windowAgent.setWindowAttribute("dark-mode", true)
|
||||
}
|
||||
}
|
||||
|
||||
Menu {
|
||||
id: specialEffectMenu
|
||||
title: qsTr("Special effect")
|
||||
|
||||
MenuItemGroup {
|
||||
id: specialEffectMenuGroup
|
||||
items: specialEffectMenu.items
|
||||
}
|
||||
|
||||
MenuItem {
|
||||
enabled: Qt.platform.os === "windows"
|
||||
text: qsTr("None")
|
||||
checkable: true
|
||||
checked: true
|
||||
onTriggered: {
|
||||
window.color = darkStyle.windowBackgroundColor
|
||||
windowAgent.setWindowAttribute("dwm-blur", false)
|
||||
windowAgent.setWindowAttribute("acrylic-material", false)
|
||||
windowAgent.setWindowAttribute("mica", false)
|
||||
windowAgent.setWindowAttribute("mica-alt", false)
|
||||
}
|
||||
}
|
||||
|
||||
MenuItem {
|
||||
enabled: Qt.platform.os === "windows"
|
||||
text: qsTr("DWM blur")
|
||||
checkable: true
|
||||
onTriggered: {
|
||||
window.color = "transparent"
|
||||
windowAgent.setWindowAttribute("acrylic-material", false)
|
||||
windowAgent.setWindowAttribute("mica", false)
|
||||
windowAgent.setWindowAttribute("mica-alt", false)
|
||||
windowAgent.setWindowAttribute("dwm-blur", true)
|
||||
}
|
||||
}
|
||||
|
||||
MenuItem {
|
||||
enabled: Qt.platform.os === "windows"
|
||||
text: qsTr("Acrylic material")
|
||||
checkable: true
|
||||
onTriggered: {
|
||||
window.color = "transparent"
|
||||
windowAgent.setWindowAttribute("dwm-blur", false)
|
||||
windowAgent.setWindowAttribute("mica", false)
|
||||
windowAgent.setWindowAttribute("mica-alt", false)
|
||||
windowAgent.setWindowAttribute("acrylic-material", true)
|
||||
}
|
||||
}
|
||||
|
||||
MenuItem {
|
||||
enabled: Qt.platform.os === "windows"
|
||||
text: qsTr("Mica")
|
||||
checkable: true
|
||||
onTriggered: {
|
||||
window.color = "transparent"
|
||||
windowAgent.setWindowAttribute("dwm-blur", false)
|
||||
windowAgent.setWindowAttribute("acrylic-material", false)
|
||||
windowAgent.setWindowAttribute("mica-alt", false)
|
||||
windowAgent.setWindowAttribute("mica", true)
|
||||
}
|
||||
}
|
||||
|
||||
MenuItem {
|
||||
enabled: Qt.platform.os === "windows"
|
||||
text: qsTr("Mica Alt")
|
||||
checkable: true
|
||||
onTriggered: {
|
||||
window.color = "transparent"
|
||||
windowAgent.setWindowAttribute("dwm-blur", false)
|
||||
windowAgent.setWindowAttribute("acrylic-material", false)
|
||||
windowAgent.setWindowAttribute("mica", false)
|
||||
windowAgent.setWindowAttribute("mica-alt", true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
40
libs/qwindowkit/examples/qml/QWKButton.qml
Normal file
40
libs/qwindowkit/examples/qml/QWKButton.qml
Normal file
@@ -0,0 +1,40 @@
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15
|
||||
|
||||
Button {
|
||||
id: root
|
||||
width: height * 1.5
|
||||
leftPadding: 0
|
||||
topPadding: 0
|
||||
rightPadding: 0
|
||||
bottomPadding: 0
|
||||
leftInset: 0
|
||||
topInset: 0
|
||||
rightInset: 0
|
||||
bottomInset: 0
|
||||
property alias source: image.source
|
||||
contentItem: Item {
|
||||
Image {
|
||||
id: image
|
||||
anchors.centerIn: parent
|
||||
mipmap: true
|
||||
width: 12
|
||||
height: 12
|
||||
fillMode: Image.PreserveAspectFit
|
||||
}
|
||||
}
|
||||
background: Rectangle {
|
||||
color: {
|
||||
if (!root.enabled) {
|
||||
return "gray";
|
||||
}
|
||||
if (root.pressed) {
|
||||
return Qt.rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
if (root.hovered) {
|
||||
return Qt.rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
return "transparent";
|
||||
}
|
||||
}
|
||||
}
|
||||
54
libs/qwindowkit/examples/qml/main.cpp
Normal file
54
libs/qwindowkit/examples/qml/main.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
|
||||
// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#include <QtGui/QGuiApplication>
|
||||
#include <QtQml/QQmlApplicationEngine>
|
||||
#include <QtQml/QQmlContext>
|
||||
#include <QtQuick/QQuickWindow>
|
||||
|
||||
#include <QWKQuick/qwkquickglobal.h>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
// Indicates to hybrid graphics systems to prefer the discrete part by default.
|
||||
extern "C" {
|
||||
Q_DECL_EXPORT unsigned long NvOptimusEnablement = 0x00000001;
|
||||
Q_DECL_EXPORT int AmdPowerXpressRequestHighPerformance = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
qputenv("QT_WIN_DEBUG_CONSOLE", "attach"); // or "new": create a separate console window
|
||||
qputenv("QSG_INFO", "1");
|
||||
qputenv("QSG_NO_VSYNC", "1");
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
qputenv("QT_QUICK_CONTROLS_STYLE", "Basic");
|
||||
#else
|
||||
qputenv("QT_QUICK_CONTROLS_STYLE", "Default");
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
qputenv("QSG_RHI_BACKEND", "d3d11"); // options: d3d11, d3d12, opengl, vulkan
|
||||
qputenv("QT_QPA_DISABLE_REDIRECTION_SURFACE", "1");
|
||||
#endif
|
||||
//qputenv("QSG_RHI_HDR", "scrgb"); // other options: hdr10, p3
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(
|
||||
Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
#endif
|
||||
QGuiApplication application(argc, argv);
|
||||
// Make sure alpha channel is requested, our special effects on Windows depends on it.
|
||||
QQuickWindow::setDefaultAlphaBuffer(true);
|
||||
QQmlApplicationEngine engine;
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
|
||||
const bool curveRenderingAvailable = true;
|
||||
#else
|
||||
const bool curveRenderingAvailable = false;
|
||||
#endif
|
||||
engine.rootContext()->setContextProperty(QStringLiteral("$curveRenderingAvailable"), QVariant(curveRenderingAvailable));
|
||||
QWK::registerTypes(&engine);
|
||||
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
|
||||
return application.exec();
|
||||
}
|
||||
42
libs/qwindowkit/examples/qml/main.qml
Normal file
42
libs/qwindowkit/examples/qml/main.qml
Normal file
@@ -0,0 +1,42 @@
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Window 2.15
|
||||
import QtQuick.Controls 2.15
|
||||
|
||||
FramelessWindow {
|
||||
property FramelessWindow childWindow: FramelessWindow {
|
||||
showWhenReady: false
|
||||
}
|
||||
|
||||
Drawer {
|
||||
id: drawer
|
||||
width: 0.66 * parent.width
|
||||
height: parent.height
|
||||
edge: Qt.RightEdge
|
||||
onAboutToShow: titleBar.enabled = false
|
||||
onAboutToHide: titleBar.enabled = true
|
||||
|
||||
Label {
|
||||
text: "Content goes here!"
|
||||
anchors.centerIn: parent
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
anchors {
|
||||
horizontalCenter: parent.horizontalCenter
|
||||
bottom: parent.bottom
|
||||
bottomMargin: 20
|
||||
}
|
||||
spacing: 10
|
||||
|
||||
Button {
|
||||
text: qsTr("Open Child Window")
|
||||
onClicked: childWindow.visible = true
|
||||
}
|
||||
|
||||
Button {
|
||||
text: qsTr("Open Drawer")
|
||||
onClicked: drawer.visible = true
|
||||
}
|
||||
}
|
||||
}
|
||||
7
libs/qwindowkit/examples/qml/qml.qrc
Normal file
7
libs/qwindowkit/examples/qml/qml.qrc
Normal file
@@ -0,0 +1,7 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>main.qml</file>
|
||||
<file>QWKButton.qml</file>
|
||||
<file>FramelessWindow.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
Reference in New Issue
Block a user