chore: baseline usable version
23
libs/qwindowkit/examples/CMakeLists.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
set(QWK_EXAMPLES_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
macro(qwk_add_example _target)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
add_executable(${_target})
|
||||
qm_configure_target(${_target} ${ARGN})
|
||||
qm_add_win_rc(${_target} ICON ${QWK_EXAMPLES_DIR}/shared/resources/app/example.ico)
|
||||
qm_add_win_manifest(${_target})
|
||||
qm_add_mac_bundle(${_target} ICON ${QWK_EXAMPLES_DIR}/shared/resources/app/example.icns)
|
||||
endmacro()
|
||||
|
||||
add_subdirectory(shared)
|
||||
|
||||
if(QWINDOWKIT_BUILD_WIDGETS)
|
||||
add_subdirectory(mainwindow)
|
||||
endif()
|
||||
|
||||
if(QWINDOWKIT_BUILD_QUICK)
|
||||
add_subdirectory(qml)
|
||||
endif()
|
||||
10
libs/qwindowkit/examples/mainwindow/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
project(QWKExample_MainWindow)
|
||||
|
||||
file(GLOB _src *.h *.cpp)
|
||||
|
||||
qwk_add_example(${PROJECT_NAME}
|
||||
FEATURES cxx_std_17
|
||||
SOURCES ${_src} mainwindow.qrc ../shared/resources/shared.qrc
|
||||
QT_LINKS Core Gui Widgets # MultimediaWidgets
|
||||
LINKS QWKWidgets WidgetFrame
|
||||
)
|
||||
170
libs/qwindowkit/examples/mainwindow/dark-style.qss
Normal file
@@ -0,0 +1,170 @@
|
||||
/* Window bar */
|
||||
|
||||
QWK--WindowBar[bar-active=true] {
|
||||
/*background-color: #3C3C3C;*/
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
QWK--WindowBar[bar-active=false] {
|
||||
/*background-color: #505050;*/
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
|
||||
/* Title label */
|
||||
|
||||
QWK--WindowBar>QLabel#win-title-label {
|
||||
padding: 0;
|
||||
border: none;
|
||||
color: #ECECEC;
|
||||
background-color: transparent;
|
||||
min-height: 28px;
|
||||
}
|
||||
|
||||
|
||||
/* System buttons */
|
||||
|
||||
QWK--WindowBar>QAbstractButton[system-button=true] {
|
||||
qproperty-iconSize: 12px 12px;
|
||||
min-width: 50px;
|
||||
border: none;
|
||||
padding: 0;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
QWK--WindowBar>QAbstractButton#pin-button {
|
||||
qproperty-iconNormal: url(":/window-bar/pin.svg");
|
||||
qproperty-iconChecked: url(":/window-bar/pin-fill.svg");
|
||||
qproperty-iconSize: 15px 15px;
|
||||
}
|
||||
|
||||
QWK--WindowBar>QAbstractButton#pin-button:hover,
|
||||
QWK--WindowBar>QAbstractButton#pin-button:pressed {
|
||||
background-color: rgba(255, 255, 255, 15%);
|
||||
}
|
||||
|
||||
QWK--WindowBar>QAbstractButton#min-button {
|
||||
qproperty-iconNormal: url(":/window-bar/minimize.svg");
|
||||
}
|
||||
|
||||
QWK--WindowBar>QAbstractButton#min-button:hover,
|
||||
QWK--WindowBar>QAbstractButton#min-button:pressed {
|
||||
background-color: rgba(255, 255, 255, 15%);
|
||||
}
|
||||
|
||||
QWK--WindowBar>QAbstractButton#max-button {
|
||||
qproperty-iconNormal: url(":/window-bar/maximize.svg");
|
||||
qproperty-iconChecked: url(":/window-bar/restore.svg");
|
||||
}
|
||||
|
||||
QWK--WindowBar>QAbstractButton#max-button:hover,
|
||||
QWK--WindowBar>QAbstractButton#max-button:pressed {
|
||||
background-color: rgba(255, 255, 255, 15%);
|
||||
}
|
||||
|
||||
QWK--WindowBar>QAbstractButton#close-button {
|
||||
qproperty-iconNormal: url(":/window-bar/close.svg");
|
||||
}
|
||||
|
||||
QWK--WindowBar>QAbstractButton#close-button:hover,
|
||||
QWK--WindowBar>QAbstractButton#close-button:pressed {
|
||||
background-color: #e81123;
|
||||
}
|
||||
|
||||
|
||||
/* Icon button */
|
||||
|
||||
QWK--WindowBar>QAbstractButton#icon-button {
|
||||
qproperty-iconNormal: url(":/app/example.png");
|
||||
qproperty-iconSize: 18px 18px;
|
||||
min-width: 40px;
|
||||
border: none;
|
||||
padding: 0;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
|
||||
/* Menu Bar */
|
||||
|
||||
QMenuBar {
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
}
|
||||
|
||||
QMenuBar>QToolButton#qt_menubar_ext_button {
|
||||
qproperty-icon: url(":/window-bar/more-line.svg");
|
||||
}
|
||||
|
||||
QMenuBar>QToolButton#qt_menubar_ext_button:hover,
|
||||
QMenuBar>QToolButton#qt_menubar_ext_button:pressed {
|
||||
background-color: rgba(255, 255, 255, 10%);
|
||||
}
|
||||
|
||||
QMenuBar::item {
|
||||
color: #CCCCCC;
|
||||
border: none;
|
||||
padding: 8px 12px;
|
||||
}
|
||||
|
||||
QMenuBar::item:selected {
|
||||
background-color: rgba(255, 255, 255, 10%);
|
||||
}
|
||||
|
||||
|
||||
/* Menu */
|
||||
|
||||
QMenu {
|
||||
padding: 4px;
|
||||
background: #303030;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
|
||||
QMenu::indicator {
|
||||
left: 6px;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
QMenu::icon {
|
||||
left: 6px;
|
||||
}
|
||||
|
||||
QMenu::item {
|
||||
background: transparent;
|
||||
color: #CCCCCC;
|
||||
padding: 6px 24px;
|
||||
}
|
||||
|
||||
QMenu::item:selected {
|
||||
color: white;
|
||||
background-color: #0060C0;
|
||||
}
|
||||
|
||||
QMenu::item:disabled {
|
||||
color: #666666;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
QMenu::separator {
|
||||
height: 2px;
|
||||
background-color: #5B5B5B;
|
||||
margin: 6px 0;
|
||||
}
|
||||
|
||||
|
||||
/* Window */
|
||||
|
||||
MainWindow {
|
||||
background-color: #1E1E1E;
|
||||
}
|
||||
|
||||
MainWindow[custom-style=true] {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
QWidget#clock-widget {
|
||||
font-size: 75px;
|
||||
color: #FEFEFE;
|
||||
font-weight: bold;
|
||||
background-color: transparent;
|
||||
}
|
||||
168
libs/qwindowkit/examples/mainwindow/light-style.qss
Normal file
@@ -0,0 +1,168 @@
|
||||
/* Window bar */
|
||||
|
||||
QWK--WindowBar[bar-active=true] {
|
||||
background-color: #195ABE;
|
||||
/* background-color: transparent; */
|
||||
}
|
||||
|
||||
QWK--WindowBar[bar-active=false] {
|
||||
background-color: #195ABE;
|
||||
/* background-color: transparent; */
|
||||
}
|
||||
|
||||
|
||||
/* Title label */
|
||||
|
||||
QWK--WindowBar>QLabel#win-title-label {
|
||||
padding: 0;
|
||||
border: none;
|
||||
color: #ECECEC;
|
||||
background-color: transparent;
|
||||
min-height: 28px;
|
||||
}
|
||||
|
||||
|
||||
/* System buttons */
|
||||
|
||||
QWK--WindowBar>QAbstractButton[system-button=true] {
|
||||
qproperty-iconSize: 12px 12px;
|
||||
min-width: 50px;
|
||||
border: none;
|
||||
padding: 0;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
QWK--WindowBar>QAbstractButton#pin-button {
|
||||
qproperty-iconNormal: url(":/window-bar/pin.svg");
|
||||
qproperty-iconChecked: url(":/window-bar/pin-fill.svg");
|
||||
qproperty-iconSize: 15px 15px;
|
||||
}
|
||||
|
||||
QWK--WindowBar>QAbstractButton#pin-button:hover,
|
||||
QWK--WindowBar>QAbstractButton#pin-button:pressed {
|
||||
background-color: rgba(0, 0, 0, 15%);
|
||||
}
|
||||
|
||||
QWK--WindowBar>QAbstractButton#min-button {
|
||||
qproperty-iconNormal: url(":/window-bar/minimize.svg");
|
||||
}
|
||||
|
||||
QWK--WindowBar>QAbstractButton#min-button:hover,
|
||||
QWK--WindowBar>QAbstractButton#min-button:pressed {
|
||||
background-color: rgba(0, 0, 0, 15%);
|
||||
}
|
||||
|
||||
QWK--WindowBar>QAbstractButton#max-button {
|
||||
qproperty-iconNormal: url(":/window-bar/maximize.svg");
|
||||
qproperty-iconChecked: url(":/window-bar/restore.svg");
|
||||
}
|
||||
|
||||
QWK--WindowBar>QAbstractButton#max-button:hover,
|
||||
QWK--WindowBar>QAbstractButton#max-button:pressed {
|
||||
background-color: rgba(0, 0, 0, 15%);
|
||||
}
|
||||
|
||||
QWK--WindowBar>QAbstractButton#close-button {
|
||||
qproperty-iconNormal: url(":/window-bar/close.svg");
|
||||
}
|
||||
|
||||
QWK--WindowBar>QAbstractButton#close-button:hover,
|
||||
QWK--WindowBar>QAbstractButton#close-button:pressed {
|
||||
background-color: #e81123;
|
||||
}
|
||||
|
||||
|
||||
/* Icon button */
|
||||
|
||||
QWK--WindowBar>QAbstractButton#icon-button {
|
||||
qproperty-iconNormal: url(":/app/example.png");
|
||||
qproperty-iconSize: 18px 18px;
|
||||
min-width: 40px;
|
||||
border: none;
|
||||
padding: 0;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
|
||||
/* Menu Bar */
|
||||
|
||||
QMenuBar {
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
}
|
||||
|
||||
QMenuBar>QToolButton#qt_menubar_ext_button {
|
||||
qproperty-icon: url(":/window-bar/more-line.svg");
|
||||
}
|
||||
|
||||
QMenuBar>QToolButton#qt_menubar_ext_button:hover,
|
||||
QMenuBar>QToolButton#qt_menubar_ext_button:pressed {
|
||||
background-color: rgba(255, 255, 255, 10%);
|
||||
}
|
||||
|
||||
QMenuBar::item {
|
||||
color: #EEEEEE;
|
||||
border: none;
|
||||
padding: 8px 12px;
|
||||
}
|
||||
|
||||
QMenuBar::item:selected {
|
||||
background-color: rgba(255, 255, 255, 10%);
|
||||
}
|
||||
|
||||
|
||||
/* Menu */
|
||||
|
||||
QMenu {
|
||||
padding: 4px;
|
||||
background: white;
|
||||
border: 1px solid #E0E0E0;
|
||||
}
|
||||
|
||||
QMenu::indicator {
|
||||
left: 6px;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
QMenu::icon {
|
||||
left: 6px;
|
||||
}
|
||||
|
||||
QMenu::item {
|
||||
background: transparent;
|
||||
color: #333333;
|
||||
padding: 6px 24px;
|
||||
}
|
||||
|
||||
QMenu::item:selected {
|
||||
background-color: rgba(0, 0, 0, 10%);
|
||||
}
|
||||
|
||||
QMenu::item:disabled {
|
||||
color: #CCCCCC;
|
||||
}
|
||||
|
||||
QMenu::separator {
|
||||
height: 2px;
|
||||
background-color: #CCCCCC;
|
||||
margin: 6px 0;
|
||||
}
|
||||
|
||||
|
||||
/* Window */
|
||||
|
||||
MainWindow {
|
||||
background-color: #F3F3F3;
|
||||
}
|
||||
|
||||
MainWindow[custom-style=true] {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
QWidget#clock-widget {
|
||||
font-size: 75px;
|
||||
color: #333333;
|
||||
font-weight: bold;
|
||||
background-color: transparent;
|
||||
}
|
||||
34
libs/qwindowkit/examples/mainwindow/main.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// 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 <QtWidgets/QApplication>
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
qputenv("QT_WIN_DEBUG_CONSOLE", "attach");
|
||||
qputenv("QSG_INFO", "1");
|
||||
//qputenv("QT_WIDGETS_HIGHDPI_DOWNSCALE", "1");
|
||||
//qputenv("QT_WIDGETS_RHI", "1");
|
||||
//qputenv("QSG_RHI_BACKEND", "d3d12");
|
||||
//qputenv("QSG_RHI_HDR", "scrgb");
|
||||
//qputenv("QT_QPA_DISABLE_REDIRECTION_SURFACE", "1");
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(
|
||||
Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
#endif
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
#endif
|
||||
|
||||
QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
|
||||
QApplication a(argc, argv);
|
||||
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
385
libs/qwindowkit/examples/mainwindow/mainwindow.cpp
Normal file
@@ -0,0 +1,385 @@
|
||||
// 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 "mainwindow.h"
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QTime>
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QWindow>
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QtWidgets/QStyle>
|
||||
#include <QtWidgets/QPushButton>
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
# include <QtGui/QActionGroup>
|
||||
#else
|
||||
# include <QtWidgets/QActionGroup>
|
||||
#endif
|
||||
|
||||
// #include <QtWebEngineWidgets/QWebEngineView>
|
||||
|
||||
#include <QWKWidgets/widgetwindowagent.h>
|
||||
|
||||
#include <widgetframe/windowbar.h>
|
||||
#include <widgetframe/windowbutton.h>
|
||||
|
||||
class ClockWidget : public QLabel {
|
||||
public:
|
||||
explicit ClockWidget(QWidget *parent = nullptr) : QLabel(parent) {
|
||||
startTimer(100);
|
||||
setAlignment(Qt::AlignCenter);
|
||||
}
|
||||
|
||||
~ClockWidget() override = default;
|
||||
|
||||
protected:
|
||||
void timerEvent(QTimerEvent *event) override {
|
||||
QLabel::timerEvent(event);
|
||||
setText(QTime::currentTime().toString(QStringLiteral("hh:mm:ss")));
|
||||
}
|
||||
};
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
||||
setAttribute(Qt::WA_DontCreateNativeAncestors);
|
||||
|
||||
installWindowAgent();
|
||||
|
||||
#if 1
|
||||
auto clockWidget = new ClockWidget();
|
||||
clockWidget->setObjectName(QStringLiteral("clock-widget"));
|
||||
clockWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
setCentralWidget(clockWidget);
|
||||
#else
|
||||
auto webView = new QWebEngineView();
|
||||
webView->load(QUrl("https://www.baidu.com"));
|
||||
setCentralWidget(webView);
|
||||
#endif
|
||||
|
||||
loadStyleSheet(Dark);
|
||||
|
||||
setWindowTitle(tr("Example MainWindow"));
|
||||
resize(800, 600);
|
||||
|
||||
// setFixedHeight(600);
|
||||
// windowAgent->centralize();
|
||||
}
|
||||
|
||||
static inline void emulateLeaveEvent(QWidget *widget) {
|
||||
Q_ASSERT(widget);
|
||||
if (!widget) {
|
||||
return;
|
||||
}
|
||||
QTimer::singleShot(0, widget, [widget]() {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
const QScreen *screen = widget->screen();
|
||||
#else
|
||||
const QScreen *screen = widget->windowHandle()->screen();
|
||||
#endif
|
||||
const QPoint globalPos = QCursor::pos(screen);
|
||||
if (!QRect(widget->mapToGlobal(QPoint{0, 0}), widget->size()).contains(globalPos)) {
|
||||
QCoreApplication::postEvent(widget, new QEvent(QEvent::Leave));
|
||||
if (widget->testAttribute(Qt::WA_Hover)) {
|
||||
const QPoint localPos = widget->mapFromGlobal(globalPos);
|
||||
const QPoint scenePos = widget->window()->mapFromGlobal(globalPos);
|
||||
static constexpr const auto oldPos = QPoint{};
|
||||
const Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers();
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 4, 0))
|
||||
const auto event =
|
||||
new QHoverEvent(QEvent::HoverLeave, scenePos, globalPos, oldPos, modifiers);
|
||||
Q_UNUSED(localPos);
|
||||
#elif (QT_VERSION >= QT_VERSION_CHECK(6, 3, 0))
|
||||
const auto event = new QHoverEvent(QEvent::HoverLeave, localPos, globalPos, oldPos, modifiers);
|
||||
Q_UNUSED(scenePos);
|
||||
#else
|
||||
const auto event = new QHoverEvent(QEvent::HoverLeave, localPos, oldPos, modifiers);
|
||||
Q_UNUSED(scenePos);
|
||||
#endif
|
||||
QCoreApplication::postEvent(widget, event);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() = default;
|
||||
|
||||
bool MainWindow::event(QEvent *event) {
|
||||
switch (event->type()) {
|
||||
case QEvent::WindowActivate: {
|
||||
auto menu = menuWidget();
|
||||
if (menu) {
|
||||
menu->setProperty("bar-active", true);
|
||||
style()->polish(menu);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case QEvent::WindowDeactivate: {
|
||||
auto menu = menuWidget();
|
||||
if (menu) {
|
||||
menu->setProperty("bar-active", false);
|
||||
style()->polish(menu);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QMainWindow::event(event);
|
||||
}
|
||||
|
||||
void MainWindow::installWindowAgent() {
|
||||
// 1. Setup window agent
|
||||
windowAgent = new QWK::WidgetWindowAgent(this);
|
||||
windowAgent->setup(this);
|
||||
|
||||
// 2. Construct your title bar
|
||||
auto menuBar = [this]() {
|
||||
auto menuBar = new QMenuBar(this);
|
||||
|
||||
// Virtual menu
|
||||
auto file = new QMenu(tr("File(&F)"), menuBar);
|
||||
file->addAction(new QAction(tr("New(&N)"), menuBar));
|
||||
file->addAction(new QAction(tr("Open(&O)"), menuBar));
|
||||
file->addSeparator();
|
||||
|
||||
auto edit = new QMenu(tr("Edit(&E)"), menuBar);
|
||||
edit->addAction(new QAction(tr("Undo(&U)"), menuBar));
|
||||
edit->addAction(new QAction(tr("Redo(&R)"), menuBar));
|
||||
|
||||
// Theme action
|
||||
auto darkAction = new QAction(tr("Enable dark theme"), menuBar);
|
||||
darkAction->setCheckable(true);
|
||||
connect(darkAction, &QAction::triggered, this, [this](bool checked) {
|
||||
loadStyleSheet(checked ? Dark : Light); //
|
||||
});
|
||||
connect(this, &MainWindow::themeChanged, darkAction, [this, darkAction]() {
|
||||
darkAction->setChecked(currentTheme == Dark); //
|
||||
});
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
auto noneAction = new QAction(tr("None"), menuBar);
|
||||
noneAction->setData(QStringLiteral("none"));
|
||||
noneAction->setCheckable(true);
|
||||
noneAction->setChecked(true);
|
||||
|
||||
auto dwmBlurAction = new QAction(tr("Enable DWM blur"), menuBar);
|
||||
dwmBlurAction->setData(QStringLiteral("dwm-blur"));
|
||||
dwmBlurAction->setCheckable(true);
|
||||
|
||||
auto acrylicAction = new QAction(tr("Enable acrylic material"), menuBar);
|
||||
acrylicAction->setData(QStringLiteral("acrylic-material"));
|
||||
acrylicAction->setCheckable(true);
|
||||
|
||||
auto micaAction = new QAction(tr("Enable mica"), menuBar);
|
||||
micaAction->setData(QStringLiteral("mica"));
|
||||
micaAction->setCheckable(true);
|
||||
|
||||
auto micaAltAction = new QAction(tr("Enable mica alt"), menuBar);
|
||||
micaAltAction->setData(QStringLiteral("mica-alt"));
|
||||
micaAltAction->setCheckable(true);
|
||||
|
||||
auto winStyleGroup = new QActionGroup(menuBar);
|
||||
winStyleGroup->addAction(noneAction);
|
||||
winStyleGroup->addAction(dwmBlurAction);
|
||||
winStyleGroup->addAction(acrylicAction);
|
||||
winStyleGroup->addAction(micaAction);
|
||||
winStyleGroup->addAction(micaAltAction);
|
||||
connect(winStyleGroup, &QActionGroup::triggered, this,
|
||||
[this, winStyleGroup](QAction *action) {
|
||||
// Unset all custom style attributes first, otherwise the style will not display
|
||||
// correctly
|
||||
for (const QAction *_act : winStyleGroup->actions()) {
|
||||
const QString data = _act->data().toString();
|
||||
if (data.isEmpty() || data == QStringLiteral("none")) {
|
||||
continue;
|
||||
}
|
||||
windowAgent->setWindowAttribute(data, false);
|
||||
}
|
||||
const QString data = action->data().toString();
|
||||
if (data == QStringLiteral("none")) {
|
||||
setProperty("custom-style", false);
|
||||
} else if (!data.isEmpty()) {
|
||||
windowAgent->setWindowAttribute(data, true);
|
||||
setProperty("custom-style", true);
|
||||
}
|
||||
style()->polish(this);
|
||||
});
|
||||
|
||||
#elif defined(Q_OS_MAC)
|
||||
// Set whether to use system buttons (close/minimize/zoom)
|
||||
// - true: Hide system buttons (use custom UI controls)
|
||||
// - false: Show native system buttons (default behavior)
|
||||
windowAgent->setWindowAttribute(QStringLiteral("no-system-buttons"), false);
|
||||
|
||||
auto darkBlurAction = new QAction(tr("Dark blur"), menuBar);
|
||||
darkBlurAction->setCheckable(true);
|
||||
connect(darkBlurAction, &QAction::toggled, this, [this](bool checked) {
|
||||
if (!windowAgent->setWindowAttribute(QStringLiteral("blur-effect"), "dark")) {
|
||||
return;
|
||||
}
|
||||
if (checked) {
|
||||
setProperty("custom-style", true);
|
||||
style()->polish(this);
|
||||
}
|
||||
});
|
||||
|
||||
auto lightBlurAction = new QAction(tr("Light blur"), menuBar);
|
||||
lightBlurAction->setCheckable(true);
|
||||
connect(lightBlurAction, &QAction::toggled, this, [this](bool checked) {
|
||||
if (!windowAgent->setWindowAttribute(QStringLiteral("blur-effect"), "light")) {
|
||||
return;
|
||||
}
|
||||
if (checked) {
|
||||
setProperty("custom-style", true);
|
||||
style()->polish(this);
|
||||
}
|
||||
});
|
||||
|
||||
auto noBlurAction = new QAction(tr("No blur"), menuBar);
|
||||
noBlurAction->setCheckable(true);
|
||||
connect(noBlurAction, &QAction::toggled, this, [this](bool checked) {
|
||||
if (!windowAgent->setWindowAttribute(QStringLiteral("blur-effect"), "none")) {
|
||||
return;
|
||||
}
|
||||
if (checked) {
|
||||
setProperty("custom-style", false);
|
||||
style()->polish(this);
|
||||
}
|
||||
});
|
||||
|
||||
auto macStyleGroup = new QActionGroup(menuBar);
|
||||
macStyleGroup->addAction(darkBlurAction);
|
||||
macStyleGroup->addAction(lightBlurAction);
|
||||
macStyleGroup->addAction(noBlurAction);
|
||||
#endif
|
||||
|
||||
// Real menu
|
||||
auto settings = new QMenu(tr("Settings(&S)"), menuBar);
|
||||
settings->addAction(darkAction);
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
settings->addSeparator();
|
||||
settings->addAction(noneAction);
|
||||
settings->addAction(dwmBlurAction);
|
||||
settings->addAction(acrylicAction);
|
||||
settings->addAction(micaAction);
|
||||
settings->addAction(micaAltAction);
|
||||
#elif defined(Q_OS_MAC)
|
||||
settings->addAction(darkBlurAction);
|
||||
settings->addAction(lightBlurAction);
|
||||
settings->addAction(noBlurAction);
|
||||
#endif
|
||||
|
||||
menuBar->addMenu(file);
|
||||
menuBar->addMenu(edit);
|
||||
menuBar->addMenu(settings);
|
||||
return menuBar;
|
||||
}();
|
||||
menuBar->setObjectName(QStringLiteral("win-menu-bar"));
|
||||
|
||||
auto titleLabel = new QLabel();
|
||||
titleLabel->setAlignment(Qt::AlignCenter);
|
||||
titleLabel->setObjectName(QStringLiteral("win-title-label"));
|
||||
|
||||
#ifndef Q_OS_MAC
|
||||
auto iconButton = new QWK::WindowButton();
|
||||
iconButton->setObjectName(QStringLiteral("icon-button"));
|
||||
iconButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
|
||||
auto pinButton = new QWK::WindowButton();
|
||||
pinButton->setCheckable(true);
|
||||
pinButton->setObjectName(QStringLiteral("pin-button"));
|
||||
pinButton->setProperty("system-button", true);
|
||||
pinButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
|
||||
auto minButton = new QWK::WindowButton();
|
||||
minButton->setObjectName(QStringLiteral("min-button"));
|
||||
minButton->setProperty("system-button", true);
|
||||
minButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
|
||||
auto maxButton = new QWK::WindowButton();
|
||||
maxButton->setCheckable(true);
|
||||
maxButton->setObjectName(QStringLiteral("max-button"));
|
||||
maxButton->setProperty("system-button", true);
|
||||
maxButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
|
||||
auto closeButton = new QWK::WindowButton();
|
||||
closeButton->setObjectName(QStringLiteral("close-button"));
|
||||
closeButton->setProperty("system-button", true);
|
||||
closeButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
#endif
|
||||
|
||||
auto windowBar = new QWK::WindowBar();
|
||||
#ifndef Q_OS_MAC
|
||||
windowBar->setIconButton(iconButton);
|
||||
windowBar->setPinButton(pinButton);
|
||||
windowBar->setMinButton(minButton);
|
||||
windowBar->setMaxButton(maxButton);
|
||||
windowBar->setCloseButton(closeButton);
|
||||
#endif
|
||||
windowBar->setMenuBar(menuBar);
|
||||
windowBar->setTitleLabel(titleLabel);
|
||||
windowBar->setHostWidget(this);
|
||||
|
||||
windowAgent->setTitleBar(windowBar);
|
||||
#ifndef Q_OS_MAC
|
||||
windowAgent->setHitTestVisible(pinButton, true);
|
||||
windowAgent->setSystemButton(QWK::WindowAgentBase::WindowIcon, iconButton);
|
||||
windowAgent->setSystemButton(QWK::WindowAgentBase::Minimize, minButton);
|
||||
windowAgent->setSystemButton(QWK::WindowAgentBase::Maximize, maxButton);
|
||||
windowAgent->setSystemButton(QWK::WindowAgentBase::Close, closeButton);
|
||||
#endif
|
||||
windowAgent->setHitTestVisible(menuBar, true);
|
||||
|
||||
#if defined(Q_OS_MAC) && 0
|
||||
windowAgent->setSystemButtonAreaCallback([](const QSize &size) {
|
||||
static constexpr const int width = 75;
|
||||
return QRect(QPoint(size.width() - width, 0), QSize(width, size.height())); //
|
||||
});
|
||||
#endif
|
||||
|
||||
setMenuWidget(windowBar);
|
||||
|
||||
|
||||
#ifndef Q_OS_MAC
|
||||
connect(windowBar, &QWK::WindowBar::pinRequested, this, [this, pinButton](bool pin) {
|
||||
if (isHidden() || isMinimized() || isMaximized() || isFullScreen()) {
|
||||
return;
|
||||
}
|
||||
setWindowFlag(Qt::WindowStaysOnTopHint, pin);
|
||||
show();
|
||||
pinButton->setChecked(pin);
|
||||
});
|
||||
connect(windowBar, &QWK::WindowBar::minimizeRequested, this, &QWidget::showMinimized);
|
||||
connect(windowBar, &QWK::WindowBar::maximizeRequested, this, [this, maxButton](bool max) {
|
||||
if (max) {
|
||||
showMaximized();
|
||||
} else {
|
||||
showNormal();
|
||||
}
|
||||
|
||||
// It's a Qt issue that if a QAbstractButton::clicked triggers a window's maximization,
|
||||
// the button remains to be hovered until the mouse move. As a result, we need to
|
||||
// manually send leave events to the button.
|
||||
emulateLeaveEvent(maxButton);
|
||||
});
|
||||
connect(windowBar, &QWK::WindowBar::closeRequested, this, &QWidget::close);
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::loadStyleSheet(Theme theme) {
|
||||
if (!styleSheet().isEmpty() && theme == currentTheme)
|
||||
return;
|
||||
currentTheme = theme;
|
||||
|
||||
if (QFile qss(theme == Dark ? QStringLiteral(":/dark-style.qss")
|
||||
: QStringLiteral(":/light-style.qss"));
|
||||
qss.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
setStyleSheet(QString::fromUtf8(qss.readAll()));
|
||||
Q_EMIT themeChanged();
|
||||
}
|
||||
}
|
||||
42
libs/qwindowkit/examples/mainwindow/mainwindow.h
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
|
||||
// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QtWidgets/QMainWindow>
|
||||
|
||||
namespace QWK {
|
||||
class WidgetWindowAgent;
|
||||
class StyleAgent;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow() override;
|
||||
|
||||
enum Theme {
|
||||
Dark,
|
||||
Light,
|
||||
};
|
||||
Q_ENUM(Theme)
|
||||
|
||||
Q_SIGNALS:
|
||||
void themeChanged();
|
||||
|
||||
protected:
|
||||
bool event(QEvent *event) override;
|
||||
|
||||
private:
|
||||
void installWindowAgent();
|
||||
void loadStyleSheet(Theme theme);
|
||||
|
||||
Theme currentTheme{};
|
||||
|
||||
QWK::WidgetWindowAgent *windowAgent;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
6
libs/qwindowkit/examples/mainwindow/mainwindow.qrc
Normal file
@@ -0,0 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>dark-style.qss</file>
|
||||
<file>light-style.qss</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,7 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>main.qml</file>
|
||||
<file>QWKButton.qml</file>
|
||||
<file>FramelessWindow.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
1
libs/qwindowkit/examples/shared/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
||||
add_subdirectory(widgetframe)
|
||||
BIN
libs/qwindowkit/examples/shared/resources/app/example.icns
Normal file
BIN
libs/qwindowkit/examples/shared/resources/app/example.ico
Normal file
|
After Width: | Height: | Size: 52 KiB |
BIN
libs/qwindowkit/examples/shared/resources/app/example.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
13
libs/qwindowkit/examples/shared/resources/shared.qrc
Normal file
@@ -0,0 +1,13 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>window-bar/close.svg</file>
|
||||
<file>window-bar/fullscreen.svg</file>
|
||||
<file>window-bar/maximize.svg</file>
|
||||
<file>window-bar/minimize.svg</file>
|
||||
<file>window-bar/restore.svg</file>
|
||||
<file>window-bar/more-line.svg</file>
|
||||
<file>window-bar/pin.svg</file>
|
||||
<file>window-bar/pin-fill.svg</file>
|
||||
<file>app/example.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
@@ -0,0 +1,15 @@
|
||||
<svg id="图层_1" data-name="图层 1" xmlns="http://www.w3.org/2000/svg" width="10.88" height="10.88"
|
||||
viewBox="0 0 10.88 10.88">
|
||||
<defs>
|
||||
<style>
|
||||
.cls-1 {
|
||||
fill: none;
|
||||
stroke: white;
|
||||
stroke-miterlimit: 10;
|
||||
stroke-width: 1.25px;
|
||||
}
|
||||
</style>
|
||||
</defs>
|
||||
<line class="cls-1" x1="0.44" y1="0.44" x2="10.44" y2="10.44" />
|
||||
<line class="cls-1" x1="0.44" y1="10.44" x2="10.44" y2="0.44" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 444 B |
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1594017175519"
|
||||
class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1933"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16">
|
||||
<defs>
|
||||
<style type="text/css"></style>
|
||||
</defs>
|
||||
<path
|
||||
d="M874.666667 128h-170.666667a21.333333 21.333333 0 0 0 0 42.666667h119.168l-176.917333 176.917333a21.333333 21.333333 0 1 0 30.165333 30.165333L853.333333 200.832V320a21.333333 21.333333 0 0 0 42.666667 0V149.333333a21.333333 21.333333 0 0 0-21.333333-21.333333zM347.584 646.250667L170.666667 823.168V704a21.333333 21.333333 0 0 0-42.666667 0v170.666667a21.333333 21.333333 0 0 0 21.333333 21.333333h170.666667a21.333333 21.333333 0 0 0 0-42.666667H200.832l176.917333-176.917333a21.333333 21.333333 0 0 0-30.165333-30.165333zM874.666667 682.666667a21.333333 21.333333 0 0 0-21.333334 21.333333v119.168l-176.917333-176.917333a21.333333 21.333333 0 0 0-30.165333 30.165333L823.168 853.333333H704a21.333333 21.333333 0 0 0 0 42.666667h170.666667a21.333333 21.333333 0 0 0 21.333333-21.333333v-170.666667a21.333333 21.333333 0 0 0-21.333333-21.333333zM200.832 170.666667H320a21.333333 21.333333 0 0 0 0-42.666667H149.333333a21.333333 21.333333 0 0 0-21.333333 21.333333v170.666667a21.333333 21.333333 0 0 0 42.666667 0V200.832l176.917333 176.917333a21.333333 21.333333 0 0 0 30.165333-30.165333z"
|
||||
fill="#ffffff" p-id="1934"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,12 @@
|
||||
<svg id="图层_1" data-name="图层 1" xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 10 10">
|
||||
<defs>
|
||||
<style>
|
||||
.cls-1 {
|
||||
fill: none;
|
||||
stroke: white;
|
||||
stroke-miterlimit: 10;
|
||||
}
|
||||
</style>
|
||||
</defs>
|
||||
<rect class="cls-1" x="0.5" y="0.5" width="9" height="9" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 328 B |
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 24.3.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px"
|
||||
y="0px" viewBox="0 0 10 10" style="enable-background:new 0 0 10 10;" xml:space="preserve">
|
||||
<style type="text/css">
|
||||
.st0 {
|
||||
fill: white;
|
||||
}
|
||||
</style>
|
||||
<rect y="4.5" class="st0" width="10" height="1" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 467 B |
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
|
||||
<path fill="none" d="M0 0h24v24H0z" />
|
||||
<path fill="white"
|
||||
d="M4.5 10.5c-.825 0-1.5.675-1.5 1.5s.675 1.5 1.5 1.5S6 12.825 6 12s-.675-1.5-1.5-1.5zm15 0c-.825 0-1.5.675-1.5 1.5s.675 1.5 1.5 1.5S21 12.825 21 12s-.675-1.5-1.5-1.5zm-7.5 0c-.825 0-1.5.675-1.5 1.5s.675 1.5 1.5 1.5 1.5-.675 1.5-1.5-.675-1.5-1.5-1.5z" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 419 B |
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg t="1735286082742" class="icon" viewBox="0 0 1024 1024" version="1.1"
|
||||
xmlns="http://www.w3.org/2000/svg" p-id="2501" width="512" height="512"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<path
|
||||
d="M648.728381 130.779429a73.142857 73.142857 0 0 1 22.674286 15.433142l191.561143 191.756191a73.142857 73.142857 0 0 1-22.137905 118.564571l-67.876572 30.061715-127.341714 127.488-10.093714 140.239238a73.142857 73.142857 0 0 1-124.684191 46.445714l-123.66019-123.782095-210.724572 211.699809-51.833904-51.614476 210.846476-211.821714-127.926857-128.024381a73.142857 73.142857 0 0 1 46.299428-124.635429l144.237715-10.776381 125.074285-125.220571 29.379048-67.779048a73.142857 73.142857 0 0 1 96.207238-38.034285z"
|
||||
p-id="2502" fill="white"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 932 B |
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg t="1735285955420" class="icon" viewBox="0 0 1024 1024" version="1.1"
|
||||
xmlns="http://www.w3.org/2000/svg" p-id="2053" width="512" height="512"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<path
|
||||
d="M648.728381 130.779429a73.142857 73.142857 0 0 1 22.674286 15.433142l191.561143 191.756191a73.142857 73.142857 0 0 1-22.137905 118.564571l-67.876572 30.061715-127.341714 127.488-10.093714 140.239238a73.142857 73.142857 0 0 1-124.684191 46.445714l-123.66019-123.782095-210.724572 211.699809-51.833904-51.614476 210.846476-211.821714-127.926857-128.024381a73.142857 73.142857 0 0 1 46.299428-124.635429l144.237715-10.776381 125.074285-125.220571 29.379048-67.779048a73.142857 73.142857 0 0 1 96.207238-38.034285z m-29.086476 67.120761l-34.913524 80.530286-154.087619 154.331429-171.398095 12.751238 303.323428 303.542857 12.044191-167.399619 156.233143-156.428191 80.384-35.59619-191.585524-191.73181z"
|
||||
p-id="2054" fill="white"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,16 @@
|
||||
<svg id="图层_1" data-name="图层 1" xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12">
|
||||
<defs>
|
||||
<style>
|
||||
.cls-1 {
|
||||
fill: none;
|
||||
stroke: white;
|
||||
stroke-miterlimit: 10;
|
||||
}
|
||||
</style>
|
||||
</defs>
|
||||
<rect class="cls-1" x="0.5" y="2.5" width="9" height="9" />
|
||||
<line class="cls-1" x1="2.5" y1="2.5" x2="2.5" y2="0.5" />
|
||||
<line class="cls-1" x1="12" y1="0.5" x2="2" y2="0.5" />
|
||||
<line class="cls-1" x1="11.5" y1="10" x2="11.5" />
|
||||
<line class="cls-1" x1="10" y1="9.5" x2="12" y2="9.5" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 559 B |
17
libs/qwindowkit/examples/shared/widgetframe/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
project(WidgetFrame)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
file(GLOB _src *.h *.cpp)
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC)
|
||||
|
||||
qm_configure_target(${PROJECT_NAME}
|
||||
FEATURES cxx_std_17
|
||||
SOURCES ${_src}
|
||||
QT_LINKS Core Gui Widgets
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC . ..)
|
||||
408
libs/qwindowkit/examples/shared/widgetframe/windowbar.cpp
Normal file
@@ -0,0 +1,408 @@
|
||||
// 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 "windowbar.h"
|
||||
#include "windowbar_p.h"
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QLocale>
|
||||
#include <QtGui/QtEvents>
|
||||
|
||||
namespace QWK {
|
||||
|
||||
WindowBarPrivate::WindowBarPrivate() {
|
||||
w = nullptr;
|
||||
autoTitle = true;
|
||||
autoIcon = false;
|
||||
}
|
||||
|
||||
WindowBarPrivate::~WindowBarPrivate() = default;
|
||||
|
||||
void WindowBarPrivate::init() {
|
||||
Q_Q(WindowBar);
|
||||
layout = new QHBoxLayout();
|
||||
if (QLocale::system().textDirection() == Qt::RightToLeft) {
|
||||
layout->setDirection(QBoxLayout::RightToLeft);
|
||||
}
|
||||
|
||||
layout->setContentsMargins(QMargins());
|
||||
layout->setSpacing(0);
|
||||
for (int i = IconButton; i <= CloseButton; ++i) {
|
||||
insertDefaultSpace(i);
|
||||
}
|
||||
q->setLayout(layout);
|
||||
}
|
||||
|
||||
void WindowBarPrivate::setWidgetAt(int index, QWidget *widget) {
|
||||
auto item = layout->takeAt(index);
|
||||
auto orgWidget = item->widget();
|
||||
if (orgWidget) {
|
||||
orgWidget->deleteLater();
|
||||
}
|
||||
delete item;
|
||||
if (!widget) {
|
||||
insertDefaultSpace(index);
|
||||
} else {
|
||||
layout->insertWidget(index, widget);
|
||||
}
|
||||
}
|
||||
|
||||
QWidget *WindowBarPrivate::takeWidgetAt(int index) {
|
||||
auto item = layout->itemAt(index);
|
||||
auto orgWidget = item->widget();
|
||||
if (orgWidget) {
|
||||
item = layout->takeAt(index);
|
||||
delete item;
|
||||
insertDefaultSpace(index);
|
||||
}
|
||||
return orgWidget;
|
||||
}
|
||||
|
||||
WindowBar::WindowBar(QWidget *parent) : WindowBar(*new WindowBarPrivate(), parent) {
|
||||
}
|
||||
|
||||
WindowBar::~WindowBar() = default;
|
||||
|
||||
QMenuBar *WindowBar::menuBar() const {
|
||||
Q_D(const WindowBar);
|
||||
return static_cast<QMenuBar *>(d->widgetAt(WindowBarPrivate::MenuWidget));
|
||||
}
|
||||
|
||||
QLabel *WindowBar::titleLabel() const {
|
||||
Q_D(const WindowBar);
|
||||
return static_cast<QLabel *>(d->widgetAt(WindowBarPrivate::TitleLabel));
|
||||
}
|
||||
|
||||
QAbstractButton *WindowBar::iconButton() const {
|
||||
Q_D(const WindowBar);
|
||||
return static_cast<QAbstractButton *>(d->widgetAt(WindowBarPrivate::IconButton));
|
||||
}
|
||||
|
||||
QAbstractButton *WindowBar::backButton() const {
|
||||
Q_D(const WindowBar);
|
||||
return static_cast<QAbstractButton *>(d->widgetAt(WindowBarPrivate::BackButton));
|
||||
}
|
||||
|
||||
QAbstractButton *WindowBar::homeButton() const {
|
||||
Q_D(const WindowBar);
|
||||
return static_cast<QAbstractButton *>(d->widgetAt(WindowBarPrivate::HomeButton));
|
||||
}
|
||||
|
||||
QAbstractButton *WindowBar::favButton() const {
|
||||
Q_D(const WindowBar);
|
||||
return static_cast<QAbstractButton *>(d->widgetAt(WindowBarPrivate::FavButton));
|
||||
}
|
||||
|
||||
QWidget *WindowBar::centerWidget() const {
|
||||
Q_D(const WindowBar);
|
||||
return d->widgetAt(WindowBarPrivate::CenterWidget);
|
||||
}
|
||||
|
||||
QAbstractButton *WindowBar::pinButton() const {
|
||||
Q_D(const WindowBar);
|
||||
return static_cast<QAbstractButton *>(d->widgetAt(WindowBarPrivate::PinButton));
|
||||
}
|
||||
|
||||
QAbstractButton *WindowBar::minButton() const {
|
||||
Q_D(const WindowBar);
|
||||
return static_cast<QAbstractButton *>(d->widgetAt(WindowBarPrivate::MinimizeButton));
|
||||
}
|
||||
|
||||
QAbstractButton *WindowBar::maxButton() const {
|
||||
Q_D(const WindowBar);
|
||||
return static_cast<QAbstractButton *>(d->widgetAt(WindowBarPrivate::MaximizeButton));
|
||||
}
|
||||
|
||||
QAbstractButton *WindowBar::closeButton() const {
|
||||
Q_D(const WindowBar);
|
||||
return static_cast<QAbstractButton *>(d->widgetAt(WindowBarPrivate::CloseButton));
|
||||
}
|
||||
|
||||
void WindowBar::setMenuBar(QMenuBar *menuBar) {
|
||||
Q_D(WindowBar);
|
||||
auto org = takeMenuBar();
|
||||
if (org)
|
||||
org->deleteLater();
|
||||
if (!menuBar)
|
||||
return;
|
||||
d->setWidgetAt(WindowBarPrivate::MenuWidget, menuBar);
|
||||
menuBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
|
||||
}
|
||||
|
||||
void WindowBar::setTitleLabel(QLabel *label) {
|
||||
Q_D(WindowBar);
|
||||
auto org = takeTitleLabel();
|
||||
if (org)
|
||||
org->deleteLater();
|
||||
if (!label)
|
||||
return;
|
||||
d->setWidgetAt(WindowBarPrivate::TitleLabel, label);
|
||||
if (d->autoTitle && d->w)
|
||||
label->setText(d->w->windowTitle());
|
||||
label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
}
|
||||
|
||||
void WindowBar::setIconButton(QAbstractButton *btn) {
|
||||
Q_D(WindowBar);
|
||||
auto org = takeIconButton();
|
||||
if (org)
|
||||
org->deleteLater();
|
||||
if (!btn)
|
||||
return;
|
||||
d->setWidgetAt(WindowBarPrivate::IconButton, btn);
|
||||
if (d->autoIcon && d->w)
|
||||
btn->setIcon(d->w->windowIcon());
|
||||
btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
}
|
||||
|
||||
void WindowBar::setBackButton(QAbstractButton *btn) {
|
||||
Q_D(WindowBar);
|
||||
auto org = takeBackButton();
|
||||
if (org)
|
||||
org->deleteLater();
|
||||
if (!btn)
|
||||
return;
|
||||
d->setWidgetAt(WindowBarPrivate::BackButton, btn);
|
||||
btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
}
|
||||
|
||||
void WindowBar::setHomeButton(QAbstractButton *btn) {
|
||||
Q_D(WindowBar);
|
||||
auto org = takeHomeButton();
|
||||
if (org)
|
||||
org->deleteLater();
|
||||
if (!btn)
|
||||
return;
|
||||
d->setWidgetAt(WindowBarPrivate::HomeButton, btn);
|
||||
btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
}
|
||||
|
||||
void WindowBar::setFavButton(QAbstractButton *btn) {
|
||||
Q_D(WindowBar);
|
||||
auto org = takeFavButton();
|
||||
if (org)
|
||||
org->deleteLater();
|
||||
if (!btn)
|
||||
return;
|
||||
d->setWidgetAt(WindowBarPrivate::FavButton, btn);
|
||||
btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
}
|
||||
|
||||
void WindowBar::setCenterWidget(QWidget *widget) {
|
||||
Q_D(WindowBar);
|
||||
auto org = takeCenterWidget();
|
||||
if (org)
|
||||
org->deleteLater();
|
||||
if (!widget)
|
||||
return;
|
||||
d->setWidgetAt(WindowBarPrivate::CenterWidget, widget);
|
||||
widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
}
|
||||
|
||||
void WindowBar::setPinButton(QAbstractButton *btn) {
|
||||
Q_D(WindowBar);
|
||||
auto org = takePinButton();
|
||||
if (org)
|
||||
org->deleteLater();
|
||||
if (!btn)
|
||||
return;
|
||||
d->setWidgetAt(WindowBarPrivate::PinButton, btn);
|
||||
connect(btn, &QAbstractButton::clicked, this, &WindowBar::pinRequested);
|
||||
}
|
||||
|
||||
void WindowBar::setMinButton(QAbstractButton *btn) {
|
||||
Q_D(WindowBar);
|
||||
auto org = takeMinButton();
|
||||
if (org)
|
||||
org->deleteLater();
|
||||
if (!btn)
|
||||
return;
|
||||
d->setWidgetAt(WindowBarPrivate::MinimizeButton, btn);
|
||||
connect(btn, &QAbstractButton::clicked, this, &WindowBar::minimizeRequested);
|
||||
}
|
||||
|
||||
void WindowBar::setMaxButton(QAbstractButton *btn) {
|
||||
Q_D(WindowBar);
|
||||
auto org = takeMaxButton();
|
||||
if (org)
|
||||
org->deleteLater();
|
||||
if (!btn)
|
||||
return;
|
||||
d->setWidgetAt(WindowBarPrivate::MaximizeButton, btn);
|
||||
connect(btn, &QAbstractButton::clicked, this, &WindowBar::maximizeRequested);
|
||||
}
|
||||
|
||||
void WindowBar::setCloseButton(QAbstractButton *btn) {
|
||||
Q_D(WindowBar);
|
||||
auto org = takeCloseButton();
|
||||
if (org)
|
||||
org->deleteLater();
|
||||
if (!btn)
|
||||
return;
|
||||
d->setWidgetAt(WindowBarPrivate::CloseButton, btn);
|
||||
connect(btn, &QAbstractButton::clicked, this, &WindowBar::closeRequested);
|
||||
}
|
||||
|
||||
QMenuBar *WindowBar::takeMenuBar() {
|
||||
Q_D(WindowBar);
|
||||
return static_cast<QMenuBar *>(d->takeWidgetAt(WindowBarPrivate::MenuWidget));
|
||||
}
|
||||
|
||||
QLabel *WindowBar::takeTitleLabel() {
|
||||
Q_D(WindowBar);
|
||||
return static_cast<QLabel *>(d->takeWidgetAt(WindowBarPrivate::TitleLabel));
|
||||
}
|
||||
|
||||
QAbstractButton *WindowBar::takeIconButton() {
|
||||
Q_D(WindowBar);
|
||||
return static_cast<QAbstractButton *>(d->takeWidgetAt(WindowBarPrivate::IconButton));
|
||||
}
|
||||
|
||||
QAbstractButton *WindowBar::takeBackButton() {
|
||||
Q_D(WindowBar);
|
||||
return static_cast<QAbstractButton *>(d->takeWidgetAt(WindowBarPrivate::BackButton));
|
||||
}
|
||||
|
||||
QAbstractButton *WindowBar::takeHomeButton() {
|
||||
Q_D(WindowBar);
|
||||
return static_cast<QAbstractButton *>(d->takeWidgetAt(WindowBarPrivate::HomeButton));
|
||||
}
|
||||
|
||||
QAbstractButton *WindowBar::takeFavButton() {
|
||||
Q_D(WindowBar);
|
||||
return static_cast<QAbstractButton *>(d->takeWidgetAt(WindowBarPrivate::FavButton));
|
||||
}
|
||||
|
||||
QWidget *WindowBar::takeCenterWidget() {
|
||||
Q_D(WindowBar);
|
||||
return d->takeWidgetAt(WindowBarPrivate::CenterWidget);
|
||||
}
|
||||
|
||||
QAbstractButton *WindowBar::takePinButton() {
|
||||
Q_D(WindowBar);
|
||||
auto btn = static_cast<QAbstractButton *>(d->takeWidgetAt(WindowBarPrivate::PinButton));
|
||||
if (!btn) {
|
||||
return nullptr;
|
||||
}
|
||||
disconnect(btn, &QAbstractButton::clicked, this, &WindowBar::pinRequested);
|
||||
return btn;
|
||||
}
|
||||
|
||||
QAbstractButton *WindowBar::takeMinButton() {
|
||||
Q_D(WindowBar);
|
||||
auto btn = static_cast<QAbstractButton *>(d->takeWidgetAt(WindowBarPrivate::MinimizeButton));
|
||||
if (!btn) {
|
||||
return nullptr;
|
||||
}
|
||||
disconnect(btn, &QAbstractButton::clicked, this, &WindowBar::minimizeRequested);
|
||||
return btn;
|
||||
}
|
||||
|
||||
QAbstractButton *WindowBar::takeMaxButton() {
|
||||
Q_D(WindowBar);
|
||||
auto btn = static_cast<QAbstractButton *>(d->takeWidgetAt(WindowBarPrivate::MaximizeButton));
|
||||
if (!btn) {
|
||||
return nullptr;
|
||||
}
|
||||
disconnect(btn, &QAbstractButton::clicked, this, &WindowBar::maximizeRequested);
|
||||
return btn;
|
||||
}
|
||||
|
||||
QAbstractButton *WindowBar::takeCloseButton() {
|
||||
Q_D(WindowBar);
|
||||
auto btn = static_cast<QAbstractButton *>(d->takeWidgetAt(WindowBarPrivate::CloseButton));
|
||||
if (!btn) {
|
||||
return nullptr;
|
||||
}
|
||||
disconnect(btn, &QAbstractButton::clicked, this, &WindowBar::closeRequested);
|
||||
return btn;
|
||||
}
|
||||
|
||||
QWidget *WindowBar::hostWidget() const {
|
||||
Q_D(const WindowBar);
|
||||
return d->w;
|
||||
}
|
||||
|
||||
void WindowBar::setHostWidget(QWidget *w) {
|
||||
Q_D(WindowBar);
|
||||
|
||||
QWidget *org = d->w;
|
||||
if (org) {
|
||||
org->removeEventFilter(this);
|
||||
}
|
||||
d_ptr->w = w;
|
||||
if (w) {
|
||||
w->installEventFilter(this);
|
||||
}
|
||||
}
|
||||
|
||||
bool WindowBar::titleFollowWindow() const {
|
||||
Q_D(const WindowBar);
|
||||
return d->autoTitle;
|
||||
}
|
||||
|
||||
void WindowBar::setTitleFollowWindow(bool value) {
|
||||
Q_D(WindowBar);
|
||||
d->autoTitle = value;
|
||||
}
|
||||
|
||||
bool WindowBar::iconFollowWindow() const {
|
||||
Q_D(const WindowBar);
|
||||
return d->autoIcon;
|
||||
}
|
||||
|
||||
void WindowBar::setIconFollowWindow(bool value) {
|
||||
Q_D(WindowBar);
|
||||
d->autoIcon = value;
|
||||
}
|
||||
|
||||
bool WindowBar::eventFilter(QObject *obj, QEvent *event) {
|
||||
Q_D(WindowBar);
|
||||
auto w = d->w;
|
||||
if (obj == w) {
|
||||
QAbstractButton *iconBtn = iconButton();
|
||||
QLabel *label = titleLabel();
|
||||
QAbstractButton *maxBtn = maxButton();
|
||||
switch (event->type()) {
|
||||
case QEvent::WindowIconChange: {
|
||||
if (d_ptr->autoIcon && iconBtn) {
|
||||
iconBtn->setIcon(w->windowIcon());
|
||||
iconChanged(w->windowIcon());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QEvent::WindowTitleChange: {
|
||||
if (d_ptr->autoTitle && label) {
|
||||
label->setText(w->windowTitle());
|
||||
titleChanged(w->windowTitle());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QEvent::WindowStateChange: {
|
||||
if (maxBtn) {
|
||||
maxBtn->setChecked(w->isMaximized());
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return QWidget::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void WindowBar::titleChanged(const QString &text) {
|
||||
Q_UNUSED(text)
|
||||
}
|
||||
|
||||
void WindowBar::iconChanged(const QIcon &icon){Q_UNUSED(icon)}
|
||||
|
||||
WindowBar::WindowBar(WindowBarPrivate &d, QWidget *parent)
|
||||
: QFrame(parent), d_ptr(&d) {
|
||||
d.q_ptr = this;
|
||||
|
||||
d.init();
|
||||
}
|
||||
|
||||
}
|
||||
91
libs/qwindowkit/examples/shared/widgetframe/windowbar.h
Normal file
@@ -0,0 +1,91 @@
|
||||
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
|
||||
// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#ifndef WINDOWBAR_H
|
||||
#define WINDOWBAR_H
|
||||
|
||||
#include <QFrame>
|
||||
#include <QAbstractButton>
|
||||
#include <QMenuBar>
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
|
||||
namespace QWK {
|
||||
|
||||
class WindowBarPrivate;
|
||||
|
||||
class WindowBar : public QFrame {
|
||||
Q_OBJECT
|
||||
Q_DECLARE_PRIVATE(WindowBar)
|
||||
public:
|
||||
explicit WindowBar(QWidget *parent = nullptr);
|
||||
~WindowBar();
|
||||
|
||||
public:
|
||||
QMenuBar *menuBar() const;
|
||||
QLabel *titleLabel() const;
|
||||
QAbstractButton *iconButton() const;
|
||||
QAbstractButton *backButton() const;
|
||||
QAbstractButton *homeButton() const;
|
||||
QAbstractButton *favButton() const;
|
||||
QWidget *centerWidget() const;
|
||||
QAbstractButton *pinButton() const;
|
||||
QAbstractButton *minButton() const;
|
||||
QAbstractButton *maxButton() const;
|
||||
QAbstractButton *closeButton() const;
|
||||
|
||||
void setMenuBar(QMenuBar *menuBar);
|
||||
void setTitleLabel(QLabel *label);
|
||||
void setIconButton(QAbstractButton *btn);
|
||||
void setBackButton(QAbstractButton *btn);
|
||||
void setHomeButton(QAbstractButton *btn);
|
||||
void setFavButton(QAbstractButton *btn);
|
||||
void setCenterWidget(QWidget *widget);
|
||||
void setPinButton(QAbstractButton *btn);
|
||||
void setMinButton(QAbstractButton *btn);
|
||||
void setMaxButton(QAbstractButton *btn);
|
||||
void setCloseButton(QAbstractButton *btn);
|
||||
|
||||
QMenuBar *takeMenuBar();
|
||||
QLabel *takeTitleLabel();
|
||||
QAbstractButton *takeIconButton();
|
||||
QAbstractButton *takeBackButton();
|
||||
QAbstractButton *takeHomeButton();
|
||||
QAbstractButton *takeFavButton();
|
||||
QWidget *takeCenterWidget();
|
||||
QAbstractButton *takePinButton();
|
||||
QAbstractButton *takeMinButton();
|
||||
QAbstractButton *takeMaxButton();
|
||||
QAbstractButton *takeCloseButton();
|
||||
|
||||
QWidget *hostWidget() const;
|
||||
void setHostWidget(QWidget *w);
|
||||
|
||||
bool titleFollowWindow() const;
|
||||
void setTitleFollowWindow(bool value);
|
||||
|
||||
bool iconFollowWindow() const;
|
||||
void setIconFollowWindow(bool value);
|
||||
|
||||
Q_SIGNALS:
|
||||
void pinRequested(bool pin = false);
|
||||
void minimizeRequested();
|
||||
void maximizeRequested(bool max = false);
|
||||
void closeRequested();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
|
||||
virtual void titleChanged(const QString &text);
|
||||
virtual void iconChanged(const QIcon &icon);
|
||||
|
||||
protected:
|
||||
WindowBar(WindowBarPrivate &d, QWidget *parent = nullptr);
|
||||
|
||||
QScopedPointer<WindowBarPrivate> d_ptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // WINDOWBAR_H
|
||||
62
libs/qwindowkit/examples/shared/widgetframe/windowbar_p.h
Normal file
@@ -0,0 +1,62 @@
|
||||
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
|
||||
// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#ifndef WINDOWBARPRIVATE_H
|
||||
#define WINDOWBARPRIVATE_H
|
||||
|
||||
#include <QBoxLayout>
|
||||
|
||||
#include "windowbar.h"
|
||||
|
||||
namespace QWK {
|
||||
|
||||
class WindowBarPrivate {
|
||||
Q_DECLARE_PUBLIC(WindowBar)
|
||||
public:
|
||||
WindowBarPrivate();
|
||||
virtual ~WindowBarPrivate();
|
||||
|
||||
void init();
|
||||
|
||||
WindowBar *q_ptr;
|
||||
|
||||
QWidget *w;
|
||||
bool autoTitle;
|
||||
bool autoIcon;
|
||||
|
||||
enum WindowBarItem {
|
||||
IconButton,
|
||||
MenuWidget,
|
||||
TitleLabel,
|
||||
BackButton,
|
||||
HomeButton,
|
||||
FavButton,
|
||||
CenterWidget,
|
||||
PinButton,
|
||||
MinimizeButton,
|
||||
MaximizeButton,
|
||||
CloseButton,
|
||||
};
|
||||
|
||||
QHBoxLayout *layout;
|
||||
|
||||
inline QWidget *widgetAt(int index) const {
|
||||
return layout->itemAt(index)->widget();
|
||||
}
|
||||
|
||||
void setWidgetAt(int index, QWidget *widget);
|
||||
|
||||
QWidget *takeWidgetAt(int index);
|
||||
|
||||
inline void insertDefaultSpace(int index) {
|
||||
layout->insertSpacerItem(index, new QSpacerItem(0, 0));
|
||||
}
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(WindowBarPrivate)
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // WINDOWBARPRIVATE_H
|
||||
94
libs/qwindowkit/examples/shared/widgetframe/windowbutton.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
// 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 "windowbutton.h"
|
||||
#include "windowbutton_p.h"
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtGui/QtEvents>
|
||||
|
||||
namespace QWK {
|
||||
|
||||
WindowButtonPrivate::WindowButtonPrivate() = default;
|
||||
|
||||
WindowButtonPrivate::~WindowButtonPrivate() = default;
|
||||
|
||||
void WindowButtonPrivate::init() {
|
||||
}
|
||||
|
||||
void WindowButtonPrivate::reloadIcon() {
|
||||
Q_Q(WindowButton);
|
||||
|
||||
if (!q->isEnabled() && !iconDisabled.isNull()) {
|
||||
q->setIcon(iconDisabled);
|
||||
return;
|
||||
}
|
||||
|
||||
if (q->isChecked() && !iconChecked.isNull()) {
|
||||
q->setIcon(iconChecked);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!iconNormal.isNull()) {
|
||||
q->setIcon(iconNormal);
|
||||
}
|
||||
}
|
||||
|
||||
WindowButton::WindowButton(QWidget *parent) : WindowButton(*new WindowButtonPrivate(), parent) {
|
||||
}
|
||||
|
||||
WindowButton::~WindowButton() = default;
|
||||
|
||||
QIcon WindowButton::iconNormal() const {
|
||||
Q_D(const WindowButton);
|
||||
return d->iconNormal;
|
||||
}
|
||||
|
||||
void WindowButton::setIconNormal(const QIcon &icon) {
|
||||
Q_D(WindowButton);
|
||||
d->iconNormal = icon;
|
||||
d->reloadIcon();
|
||||
}
|
||||
|
||||
QIcon WindowButton::iconChecked() const {
|
||||
Q_D(const WindowButton);
|
||||
return d->iconChecked;
|
||||
}
|
||||
|
||||
void WindowButton::setIconChecked(const QIcon &icon) {
|
||||
Q_D(WindowButton);
|
||||
d->iconChecked = icon;
|
||||
d->reloadIcon();
|
||||
}
|
||||
|
||||
QIcon WindowButton::iconDisabled() const {
|
||||
Q_D(const WindowButton);
|
||||
return d->iconDisabled;
|
||||
}
|
||||
|
||||
void WindowButton::setIconDisabled(const QIcon &icon) {
|
||||
Q_D(WindowButton);
|
||||
d->iconDisabled = icon;
|
||||
d->reloadIcon();
|
||||
}
|
||||
|
||||
void WindowButton::checkStateSet() {
|
||||
Q_D(WindowButton);
|
||||
d->reloadIcon();
|
||||
}
|
||||
|
||||
void WindowButton::mouseDoubleClickEvent(QMouseEvent *event) {
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
Q_EMIT doubleClicked();
|
||||
}
|
||||
}
|
||||
|
||||
WindowButton::WindowButton(WindowButtonPrivate &d, QWidget *parent)
|
||||
: QPushButton(parent), d_ptr(&d) {
|
||||
d.q_ptr = this;
|
||||
|
||||
d.init();
|
||||
}
|
||||
|
||||
}
|
||||
50
libs/qwindowkit/examples/shared/widgetframe/windowbutton.h
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
|
||||
// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#ifndef WINDOWBUTTON_H
|
||||
#define WINDOWBUTTON_H
|
||||
|
||||
#include <QtWidgets/QPushButton>
|
||||
|
||||
namespace QWK {
|
||||
|
||||
class WindowButtonPrivate;
|
||||
|
||||
class WindowButton : public QPushButton {
|
||||
Q_OBJECT
|
||||
Q_DECLARE_PRIVATE(WindowButton)
|
||||
Q_PROPERTY(QIcon iconNormal READ iconNormal WRITE setIconNormal FINAL)
|
||||
Q_PROPERTY(QIcon iconChecked READ iconChecked WRITE setIconChecked FINAL)
|
||||
Q_PROPERTY(QIcon iconDisabled READ iconDisabled WRITE setIconDisabled FINAL)
|
||||
public:
|
||||
explicit WindowButton(QWidget *parent = nullptr);
|
||||
~WindowButton();
|
||||
|
||||
public:
|
||||
QIcon iconNormal() const;
|
||||
void setIconNormal(const QIcon &icon);
|
||||
|
||||
QIcon iconChecked() const;
|
||||
void setIconChecked(const QIcon &icon);
|
||||
|
||||
QIcon iconDisabled() const;
|
||||
void setIconDisabled(const QIcon &icon);
|
||||
|
||||
Q_SIGNALS:
|
||||
void doubleClicked();
|
||||
|
||||
protected:
|
||||
void checkStateSet() override;
|
||||
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
||||
protected:
|
||||
WindowButton(WindowButtonPrivate &d, QWidget *parent = nullptr);
|
||||
|
||||
QScopedPointer<WindowButtonPrivate> d_ptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // WINDOWBUTTON_H
|
||||
31
libs/qwindowkit/examples/shared/widgetframe/windowbutton_p.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
|
||||
// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#ifndef WINDOWBUTTONPRIVATE_H
|
||||
#define WINDOWBUTTONPRIVATE_H
|
||||
|
||||
#include "windowbutton.h"
|
||||
|
||||
namespace QWK {
|
||||
|
||||
class WindowButtonPrivate {
|
||||
Q_DECLARE_PUBLIC(WindowButton)
|
||||
public:
|
||||
WindowButtonPrivate();
|
||||
virtual ~WindowButtonPrivate();
|
||||
|
||||
void init();
|
||||
|
||||
WindowButton *q_ptr;
|
||||
|
||||
QIcon iconNormal;
|
||||
QIcon iconChecked;
|
||||
QIcon iconDisabled;
|
||||
|
||||
void reloadIcon();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // WINDOWBUTTONPRIVATE_H
|
||||