Skip to content

Commit

Permalink
feat: 赋予项目一个增加功德的内核
Browse files Browse the repository at this point in the history
  • Loading branch information
zmoth committed Dec 2, 2023
1 parent e0de706 commit c1105a0
Show file tree
Hide file tree
Showing 23 changed files with 196 additions and 241 deletions.
40 changes: 21 additions & 19 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
---
BasedOnStyle: Google
IndentWidth: 4
Language: Cpp
AccessModifierOffset: -2
AllowShortBlocksOnASingleLine: Empty
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
BreakBeforeBraces: Mozilla
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
ColumnLimit: 120
DerivePointerAlignment: false
DisableFormat: false
PackConstructorInitializers: NextLine
PointerAlignment: Right
ReflowComments: true # 重排注释
SortIncludes: CaseSensitive
UseTab: Never
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
BasedOnStyle: Google # 基于Google的代码风格
IndentWidth: 4 # 缩进宽度为4个空格
Language: Cpp # 语言为C++
AccessModifierOffset: -2 # 访问修饰符偏移-2个空格
AllowShortBlocksOnASingleLine: Empty # 允许在单行上写短代码块(Empty表示不设置)
AllowShortFunctionsOnASingleLine: Inline # 允许在单行上写短函数(Inline表示与函数声明在同一行)
AllowShortIfStatementsOnASingleLine: Never # 禁止在单行上写短if语句
AllowShortLoopsOnASingleLine: false # 禁止在单行上写短循环
BreakBeforeBraces: Mozilla # 在大括号前换行,与Mozilla风格保持一致
BreakConstructorInitializers: BeforeComma # 在逗号前换行,适用于构造函数初始化列表
BreakInheritanceList: BeforeComma # 在逗号前换行,适用于继承列表
ColumnLimit: 120 # 限制每行代码的最大字符数为120个
DerivePointerAlignment: false # 不从指针对齐中派生(false表示不设置)
DisableFormat: false # 不禁用格式化(false表示不设置)
IndentPPDirectives: AfterHash # 在hash符号后缩进预处理指令
PackConstructorInitializers: NextLine # 在下一行打包构造函数初始化列表
PointerAlignment: Right # 指针对齐在右侧
ReflowComments: true # 重新排列注释(true表示开启)
SortIncludes: CaseSensitive # 按字母顺序排序包含文件(CaseSensitive表示区分大小写)
UseTab: Never # 从不使用制表符(Never表示不设置)
90 changes: 0 additions & 90 deletions .gitattributes

This file was deleted.

26 changes: 20 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
build*/
.vscode/
/*[Bb]uild*

# clangd
.cache

# JetBrains
.idea/

# Visual Studio
.vs/
html/
latex/
*.lnk
CMakeLists.txt.user

# Visual Studio Code
.vscode/*
!.vscode/launch.json

# QtCreator
*.user
*.user.*

# MacOS
.DS_Store
34 changes: 21 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ set(PROJECT_HOMEPAGE_URL "https://zmoth.top")
# 配置工程信息
#
project(
dlldemo
knock
VERSION ${PROJECT_VERSION}
DESCRIPTION ${PROJECT_DESCRIPTION}
HOMEPAGE_URL ${PROJECT_HOMEPAGE_URL}
Expand Down Expand Up @@ -96,12 +96,14 @@ message(STATUS "[${PROJECT_NAME}] 可执行文件的文件夹位置: ${CMAKE_RUN
#
# ########### 构建 ###########
#

# Qt
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) # 识别是Qt6还是Qt5
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
message(STATUS "QT_VERSION: ${QT_VERSION}; QT_DIR: ${QT_DIR}")
message(STATUS "[${PROJECT_NAME}] QT_VERSION: ${QT_VERSION}; QT_DIR: ${QT_DIR}")

if(${QT_VERSION} VERSION_LESS 5.11.0)
message(FATAL_ERROR "Requires qt version >= 5.11.0, Your current version is ${QT_VERSION}")
message(FATAL_ERROR "[${PROJECT_NAME}] Requires qt version >= 5.11.0, Your current version is ${QT_VERSION}")
endif()

if(${${PROJECT_NAME}_BUILD_POLICY} STREQUAL "SHARED")
Expand All @@ -114,15 +116,6 @@ else()
add_library(${PROJECT_NAME})
endif()

add_subdirectory(src) # 添加源文件

if(${MSVC})
target_sources(
${PROJECT_NAME}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/resources/win.rc
)
endif()

# 添加配置头文件,将CMake中的版本等信息转换为头文件
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/Config.h.in"
Expand All @@ -136,6 +129,21 @@ generate_export_header(
EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/include/Export.h"
)

add_subdirectory(src) # 添加源文件

file(GLOB_RECURSE INCS ${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}/internal/*.h)
target_sources(
${PROJECT_NAME}
PRIVATE ${INCS}
)

if(${MSVC})
target_sources(
${PROJECT_NAME}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/resources/win.rc
)
endif()

# 头文件路径
target_include_directories(
${PROJECT_NAME}
Expand All @@ -147,7 +155,7 @@ target_include_directories(
# 所有头文件都希望能够直接调用到
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/demo/internal>
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}/internal>
)

target_link_libraries(
Expand Down
36 changes: 4 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,7 @@
<h1 align="center">QT CMAKE DEMO</h1>
# QT CMAKE DEMO

<!-- 目录 -->
# Content
- [Content](#content)
- [Build \& Install](#build--install)
- [Dependencies](#dependencies)
- [Build](#build)
- [Example](#example)
- [Origin \& References](#origin--references)
这是基于 Qt 的 C++项目工程模板。用于制作库文件。

# Build & Install
## Dependencies
这也是一个点击就能增加功德的利器。

Qt >= 5.15.2

## Build

```bash
git clone --recurse-submodules [email protected]:QianMoth/qt-cmake-project.git
cd nodeeditor-p
mkdir build

# Release
cmake -S . -Bbuild -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release

# Debug
cmake -S . -Bbuild -DCMAKE_BUILD_TYPE=Debug
cmake --build build --config Debug
```
# Example


# Origin & References
![WoodenFish](./docs/WoodenFish.png)
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 文档
Binary file added docs/WoodenFish.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add_subdirectory(demo)
add_subdirectory(WoodenFish)
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
project(exedemo)
project(WoodenFish)

message(STATUS "[example] 项目名称 ${PROJECT_NAME}")

# qt
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) # 识别是Qt6还是Qt5
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)

file(GLOB_RECURSE CPP_SOURCE_FILES *.cpp *.cxx *.cc)
file(GLOB_RECURSE CPP_INCLUDE_FILES *.hpp *.h)
file(GLOB_RECURSE RESOURCES *.qrc *.rc *.ui)

set(PROJECT_SOURCES ${CPP_SOURCE_FILES} ${CPP_INCLUDE_FILES} ${RESOURCES})

file(GLOB_RECURSE SRCS *.cpp)
file(GLOB_RECURSE INCS *.hpp *.h)
file(GLOB_RECURSE RESOURCES *.qrc *.ui)
Expand All @@ -22,11 +16,11 @@ target_include_directories(
${PROJECT_NAME}
PRIVATE $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
PRIVATE $<BUILD_INTERFACE:${dlldemo_SOURCE_DIR}/include>
PRIVATE $<BUILD_INTERFACE:${knock_SOURCE_DIR}/include>
)

target_link_libraries(${PROJECT_NAME}
PRIVATE dlldemo
PRIVATE knock
PRIVATE Qt${QT_VERSION_MAJOR}::Widgets
)

Expand Down
48 changes: 48 additions & 0 deletions examples/WoodenFish/MainWindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "MainWindow.h"

#include <QApplication>
#include <QIcon>
#include <QKeyEvent>
#include <QLabel>
#include <QMessageBox>
#include <QPushButton>
#include <QString>
#include <QVBoxLayout>
#include <knock/Knock>

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
setWindowTitle(tr("About ") + qAppName());
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);

auto *w = new QWidget(this);
auto *layout = new QVBoxLayout(w);
setCentralWidget(w);

// logo显示
auto *logo = new QLabel(this);
layout->addWidget(logo, 0, Qt::AlignCenter);
logo->setPixmap(QApplication::windowIcon().pixmap(64));

// 点击会功德+1的计数按钮
auto *c = new knock::Knock();
auto *btn = new QPushButton(this);
layout->addWidget(btn, 0, Qt::AlignCenter);
connect(c, &knock::Knock::num_changed, btn, [btn](int num) { btn->setText("功德: " + QString::number(num)); });
c->set_num(0);
connect(btn, &QPushButton::clicked, c, &knock::Knock::num_Knock);

// 版本&系统信息
QString str("<h1>" + qAppName() + " " + qApp->applicationVersion() + "</h1>");
str += R"(<div>Created by <a href="https://zmoth.top" target="_blank">Moth</a>; </div>)";
str += "<div>Locale : " + QLocale::system().name() + "</div>";
str += "<div>OS : " + QSysInfo::prettyProductName() + "</div>";
str += "<div>CPU : " + QSysInfo::currentCpuArchitecture() + "</div>";

auto *info = new QLabel(str, this);
layout->addWidget(info);
info->setOpenExternalLinks(true);

setFixedSize(sizeHint());
show();
}
11 changes: 11 additions & 0 deletions examples/WoodenFish/MainWindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <QMainWindow>

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = nullptr);
};
File renamed without changes.
7 changes: 5 additions & 2 deletions examples/demo/main.cpp → examples/WoodenFish/main.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include <Config.h>

#include <QApplication>

#include "MainWindow.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QApplication::setApplicationVersion(PROJECT_VERSION);

QApplication const app(argc, argv);

app.setWindowIcon(QIcon(":/icon.ico")); // 给app添加图标

Expand Down
File renamed without changes.
Loading

0 comments on commit c1105a0

Please sign in to comment.