Sine Striker
2023-12-17 eda513356b8eb58b3069ddceb8c3dbc63c7fcdcd
Update resources
6个文件已修改
2个文件已添加
2 文件已重命名
1个文件已删除
58 ■■■■ 已修改文件
README.md 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
examples/CMakeLists.txt 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
examples/mainwindow/CMakeLists.txt 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
examples/mainwindow/dark-style.qss 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
examples/mainwindow/mainwindow.cpp 23 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
examples/qml/main.qml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
examples/shared/resources/app/example.icns 补丁 | 查看 | 原始文档 | blame | 历史
examples/shared/resources/app/example.ico 补丁 | 查看 | 原始文档 | blame | 历史
examples/shared/resources/app/example.png 补丁 | 查看 | 原始文档 | blame | 历史
examples/shared/resources/shared.qrc 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
examples/shared/resources/window-bar/icon.svg 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
README.md
@@ -64,7 +64,7 @@
```
#### QMake Project
```qmake
```cmake
# WidgetsApp.pro
include("/path/install/share/QWindowKit/qmake/QWKWidgets.pri")
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)
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
)
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;
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
}
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: {
examples/shared/resources/app/example.icns
Binary files differ
examples/shared/resources/app/example.ico

examples/shared/resources/app/example.png
examples/shared/resources/shared.qrc
File was renamed from examples/shared/resources/window-bar.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>
examples/shared/resources/window-bar/icon.svg
File was deleted