From eda513356b8eb58b3069ddceb8c3dbc63c7fcdcd Mon Sep 17 00:00:00 2001 From: Sine Striker <trueful@163.com> Date: 周日, 17 12月 2023 15:58:49 +0800 Subject: [PATCH] Update resources --- examples/qml/main.qml | 4 ++-- /dev/null | 18 ------------------ examples/shared/resources/app/example.png | 0 examples/mainwindow/CMakeLists.txt | 2 +- examples/mainwindow/dark-style.qss | 4 ++-- examples/shared/resources/app/example.icns | 0 examples/mainwindow/mainwindow.cpp | 23 ++++++++++++++++++----- README.md | 2 +- examples/CMakeLists.txt | 3 ++- examples/shared/resources/app/example.ico | 0 examples/shared/resources/shared.qrc | 2 +- 11 files changed, 27 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 5b9b809..e895b0f 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ ``` #### QMake Project -```qmake +```cmake # WidgetsApp.pro include("/path/install/share/QWindowKit/qmake/QWKWidgets.pri") diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 4b35d4e..5d27181 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -7,8 +7,9 @@ add_executable(${_target}) qm_configure_target(${_target} ${ARGN}) - qm_add_win_rc(${_target} ICON ${QWK_EXAMPLES_DIR}/shared/resources/example.ico) + 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) diff --git a/examples/mainwindow/CMakeLists.txt b/examples/mainwindow/CMakeLists.txt index 62845fa..c29f2b8 100644 --- a/examples/mainwindow/CMakeLists.txt +++ b/examples/mainwindow/CMakeLists.txt @@ -3,7 +3,7 @@ file(GLOB _src *.h *.cpp) qwk_add_example(${PROJECT_NAME} - SOURCES ${_src} mainwindow.qrc ../shared/resources/window-bar.qrc + SOURCES ${_src} mainwindow.qrc ../shared/resources/shared.qrc QT_LINKS Core Gui Widgets LINKS QWKWidgets WidgetFrame ) diff --git a/examples/mainwindow/dark-style.qss b/examples/mainwindow/dark-style.qss index 43ea3ee..275613b 100644 --- a/examples/mainwindow/dark-style.qss +++ b/examples/mainwindow/dark-style.qss @@ -62,8 +62,8 @@ /* Icon button */ QWK--WindowBar>QAbstractButton#icon-button { - qproperty-iconNormal: url(":/window-bar/icon.svg"); - qproperty-iconSize: 20px 20px; + qproperty-iconNormal: url(":/app/example.png"); + qproperty-iconSize: 18px 18px; min-width: 40px; border: none; padding: 0; diff --git a/examples/mainwindow/mainwindow.cpp b/examples/mainwindow/mainwindow.cpp index 80a4c3a..96736de 100644 --- a/examples/mainwindow/mainwindow.cpp +++ b/examples/mainwindow/mainwindow.cpp @@ -36,12 +36,13 @@ clockWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setCentralWidget(clockWidget); - if (QFile qss(QStringLiteral(":/dark-style.qss")); qss.open(QIODevice::ReadOnly | QIODevice::Text)) { + if (QFile qss(QStringLiteral(":/dark-style.qss")); + qss.open(QIODevice::ReadOnly | QIODevice::Text)) { setStyleSheet(QString::fromUtf8(qss.readAll())); } setWindowTitle(tr("Example MainWindow")); - resize(640, 480); + resize(800, 600); } static inline void emulateLeaveEvent(QWidget *widget) { @@ -105,11 +106,13 @@ } void MainWindow::installWindowAgent() { + // 1. Setup window agent auto agent = new QWK::WidgetWindowAgent(this); if (!agent->setup(this)) { qFatal("QWK failed to initialize."); } + // 2. Construct your title bar auto menuBar = []() { auto menuBar = new QMenuBar(); auto file = new QMenu(tr("File(&F)"), menuBar); @@ -130,6 +133,7 @@ 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); @@ -149,30 +153,38 @@ 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->setMinButton(minButton); windowBar->setMaxButton(maxButton); windowBar->setCloseButton(closeButton); +#endif windowBar->setMenuBar(menuBar); windowBar->setTitleLabel(titleLabel); windowBar->setHostWidget(this); agent->setTitleBar(windowBar); +#ifndef Q_OS_MAC agent->setSystemButton(QWK::WindowAgentBase::WindowIcon, iconButton); agent->setSystemButton(QWK::WindowAgentBase::Minimize, minButton); agent->setSystemButton(QWK::WindowAgentBase::Maximize, maxButton); agent->setSystemButton(QWK::WindowAgentBase::Close, closeButton); +#endif agent->setHitTestVisible(menuBar, true); + setMenuWidget(windowBar); + + // 3. Adds simulated mouse events to the title bar buttons #ifdef Q_OS_WINDOWS // Emulate Window system menu button behaviors - connect(iconButton, &QAbstractButton::clicked, this, [iconButton, agent] { + connect(iconButton, &QAbstractButton::clicked, agent, [iconButton, agent] { iconButton->setProperty("double-click-close", false); // Pick a suitable time threshold - QTimer::singleShot(75, [iconButton, agent]() { + QTimer::singleShot(75, agent, [iconButton, agent]() { if (iconButton->property("double-click-close").toBool()) return; agent->showSystemMenu(iconButton->mapToGlobal(QPoint{0, iconButton->height()})); @@ -184,6 +196,7 @@ }); #endif +#ifndef Q_OS_MAC connect(windowBar, &QWK::WindowBar::minimizeRequested, this, &QWidget::showMinimized); connect(windowBar, &QWK::WindowBar::maximizeRequested, this, [this, maxButton](bool max) { if (max) { @@ -198,5 +211,5 @@ emulateLeaveEvent(maxButton); }); connect(windowBar, &QWK::WindowBar::closeRequested, this, &QWidget::close); - setMenuWidget(windowBar); +#endif } diff --git a/examples/qml/main.qml b/examples/qml/main.qml index 7f5c228..4ed90f1 100644 --- a/examples/qml/main.qml +++ b/examples/qml/main.qml @@ -5,8 +5,8 @@ Window { id: window - width: 640 - height: 480 + width: 800 + height: 600 color: "#f0f0f0" title: qsTr("Hello, world!") Component.onCompleted: { diff --git a/examples/shared/resources/app/example.icns b/examples/shared/resources/app/example.icns new file mode 100644 index 0000000..bc4bb61 --- /dev/null +++ b/examples/shared/resources/app/example.icns Binary files differ diff --git a/examples/shared/resources/example.ico b/examples/shared/resources/app/example.ico similarity index 100% rename from examples/shared/resources/example.ico rename to examples/shared/resources/app/example.ico Binary files differ diff --git a/examples/shared/resources/app/example.png b/examples/shared/resources/app/example.png new file mode 100644 index 0000000..61bf23c --- /dev/null +++ b/examples/shared/resources/app/example.png Binary files differ diff --git a/examples/shared/resources/window-bar.qrc b/examples/shared/resources/shared.qrc similarity index 88% rename from examples/shared/resources/window-bar.qrc rename to examples/shared/resources/shared.qrc index 894de7f..5aec715 100644 --- a/examples/shared/resources/window-bar.qrc +++ b/examples/shared/resources/shared.qrc @@ -2,10 +2,10 @@ <qresource prefix="/"> <file>window-bar/close.svg</file> <file>window-bar/fullscreen.svg</file> - <file>window-bar/icon.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>app/example.png</file> </qresource> </RCC> diff --git a/examples/shared/resources/window-bar/icon.svg b/examples/shared/resources/window-bar/icon.svg deleted file mode 100644 index d56bf51..0000000 --- a/examples/shared/resources/window-bar/icon.svg +++ /dev/null @@ -1,18 +0,0 @@ -<?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="1597412561411" - class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="780" - xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16"> - <defs> - <style type="text/css"></style> - </defs> - <path d="M512 384m-170.666667 0a170.666667 170.666667 0 1 0 341.333334 0 170.666667 170.666667 0 1 0-341.333334 0Z" - fill="#009688" p-id="781"></path> - <path d="M341.333333 384h341.333334v128H341.333333z" fill="#E89419" p-id="782"></path> - <path - d="M661.333333 106.666667v85.333333h-46.933333c-51.2 0-25.6-21.333333-102.4-21.333333V85.333333c76.8 0 51.2 21.333333 102.4 21.333334H661.333333z" - fill="#2196F3" p-id="783"></path> - <path d="M85.333333 512h853.333334v362.666667H85.333333z" fill="#FFB74D" p-id="784"></path> - <path - d="M661.333333 725.333333h85.333334v106.666667h-85.333334zM533.333333 725.333333h85.333334v106.666667h-85.333334zM405.333333 725.333333h85.333334v106.666667h-85.333334zM789.333333 725.333333h85.333334v106.666667h-85.333334zM277.333333 725.333333h85.333334v106.666667h-85.333334zM149.333333 725.333333h85.333334v106.666667H149.333333zM661.333333 576h85.333334v106.666667h-85.333334zM533.333333 576h85.333334v106.666667h-85.333334zM405.333333 576h85.333334v106.666667h-85.333334zM618.666667 512h-85.333334v-64c0-23.466667 19.2-42.666667 42.666667-42.666667s42.666667 19.2 42.666667 42.666667v64zM490.666667 512h-85.333334v-64c0-23.466667 19.2-42.666667 42.666667-42.666667s42.666667 19.2 42.666667 42.666667v64zM789.333333 576h85.333334v106.666667h-85.333334zM277.333333 576h85.333334v106.666667h-85.333334zM149.333333 576h85.333334v106.666667H149.333333z" - fill="#B07424" p-id="785"></path> -</svg> \ No newline at end of file -- Gitblit v1.9.1