feat(ssh-tunnel-qt): add application icon support for cross-platform display

- Add Contents.json for macOS icon asset catalog with multiple resolutions
- Configure project.yml to include Windows PE icon resource
- Include QIcon header and implement applicationIcon() function
- Set window icons for main application and tunnel windows
- Add qrc file to embed icon resources into the application
- Update README to document multi-DPI icon support across platforms
pull/40/head
韩天峰 4 weeks ago
parent f89a7d69b9
commit 2a1a11d1b5
  1. 2
      examples/ssh-tunnel-qt/README.md
  2. 15
      examples/ssh-tunnel-qt/cpp-src/qt_tunnel.cc
  3. 4022
      examples/ssh-tunnel-qt/cpp-src/ssh_tunnel_icons.cc
  4. 18
      examples/ssh-tunnel-qt/icon/Contents.json
  5. BIN
      examples/ssh-tunnel-qt/icon/icon_1024.png
  6. BIN
      examples/ssh-tunnel-qt/icon/icon_128.png
  7. BIN
      examples/ssh-tunnel-qt/icon/icon_16.png
  8. BIN
      examples/ssh-tunnel-qt/icon/icon_256.png
  9. BIN
      examples/ssh-tunnel-qt/icon/icon_32.png
  10. BIN
      examples/ssh-tunnel-qt/icon/icon_512.png
  11. BIN
      examples/ssh-tunnel-qt/icon/icon_64.png
  12. 11
      examples/ssh-tunnel-qt/icon/ssh_tunnel_icons.qrc
  13. BIN
      examples/ssh-tunnel-qt/icon/ssh_tunnel_manager.ico
  14. 5
      examples/ssh-tunnel-qt/project.yml

@ -24,6 +24,8 @@
- 启动时检查全部持久化规则,未运行的隧道会自动启动。 - 启动时检查全部持久化规则,未运行的隧道会自动启动。
- JSON 配置原子写入、`fsync` 和双份备份,主配置损坏时自动恢复。 - JSON 配置原子写入、`fsync` 和双份备份,主配置损坏时自动恢复。
- 使用 `QProcess(program, arguments)`,不经过 shell。 - 使用 `QProcess(program, arguments)`,不经过 shell。
- 应用图标内嵌到程序中,支持 Linux、macOS 和 Windows 多 DPI 显示;Windows
可执行文件同时携带 PE 图标资源。
## 分层 ## 分层

@ -14,6 +14,7 @@
#include <QGroupBox> #include <QGroupBox>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QHeaderView> #include <QHeaderView>
#include <QIcon>
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
#include <QMainWindow> #include <QMainWindow>
@ -48,6 +49,18 @@ static char qt_program_name[] = "typephp-ssh-tunnel-manager";
static char *qt_argv[] = {qt_program_name, nullptr}; static char *qt_argv[] = {qt_program_name, nullptr};
static QApplication *qt_application = nullptr; static QApplication *qt_application = nullptr;
QIcon applicationIcon() {
QIcon icon;
icon.addFile(":/icons/icon_16.png");
icon.addFile(":/icons/icon_32.png");
icon.addFile(":/icons/icon_64.png");
icon.addFile(":/icons/icon_128.png");
icon.addFile(":/icons/icon_256.png");
icon.addFile(":/icons/icon_512.png");
icon.addFile(":/icons/icon_1024.png");
return icon;
}
QString toQString(const Variant &value) { QString toQString(const Variant &value) {
if (value.isNull() || value.isUndef()) { if (value.isNull() || value.isUndef()) {
return {}; return {};
@ -235,6 +248,7 @@ class TunnelWindowBox final : public Box {
explicit TunnelWindowBox(const QString &title) { explicit TunnelWindowBox(const QString &title) {
window_ = new QMainWindow(); window_ = new QMainWindow();
window_->setWindowTitle(title); window_->setWindowTitle(title);
window_->setWindowIcon(QApplication::windowIcon());
window_->resize(1120, 720); window_->resize(1120, 720);
auto *central = new QWidget(); auto *central = new QWidget();
@ -698,6 +712,7 @@ var php_qt_tunnel_create(String title) {
qt_application = new QApplication(qt_argc, qt_argv); qt_application = new QApplication(qt_argc, qt_argv);
qt_application->setApplicationName("TypePHP SSH Tunnel Manager"); qt_application->setApplicationName("TypePHP SSH Tunnel Manager");
qt_application->setOrganizationName("TypePHP"); qt_application->setOrganizationName("TypePHP");
qt_application->setWindowIcon(applicationIcon());
} }
return {new TunnelWindowBox(toQString(title))}; return {new TunnelWindowBox(toQString(title))};
} }

File diff suppressed because it is too large Load Diff

@ -0,0 +1,18 @@
{
"images" : [
{ "filename" : "icon_16.png", "idiom" : "mac", "scale" : "1x", "size" : "16x16" },
{ "filename" : "icon_32.png", "idiom" : "mac", "scale" : "2x", "size" : "16x16" },
{ "filename" : "icon_32.png", "idiom" : "mac", "scale" : "1x", "size" : "32x32" },
{ "filename" : "icon_64.png", "idiom" : "mac", "scale" : "2x", "size" : "32x32" },
{ "filename" : "icon_128.png", "idiom" : "mac", "scale" : "1x", "size" : "128x128" },
{ "filename" : "icon_256.png", "idiom" : "mac", "scale" : "2x", "size" : "128x128" },
{ "filename" : "icon_256.png", "idiom" : "mac", "scale" : "1x", "size" : "256x256" },
{ "filename" : "icon_512.png", "idiom" : "mac", "scale" : "2x", "size" : "256x256" },
{ "filename" : "icon_512.png", "idiom" : "mac", "scale" : "1x", "size" : "512x512" },
{ "filename" : "icon_1024.png", "idiom" : "mac", "scale" : "2x", "size" : "512x512" }
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 976 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

@ -0,0 +1,11 @@
<RCC>
<qresource prefix="/icons">
<file>icon_16.png</file>
<file>icon_32.png</file>
<file>icon_64.png</file>
<file>icon_128.png</file>
<file>icon_256.png</file>
<file>icon_512.png</file>
<file>icon_1024.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

@ -8,6 +8,11 @@ sources:
- php-src - php-src
- cpp-src - cpp-src
resource:
# Used as the Windows PE/Explorer icon. Qt's in-window icon is embedded in
# cpp-src/ssh_tunnel_icons.cc so it also works on Linux and macOS.
icon: icon/ssh_tunnel_manager.ico
# Debian/Ubuntu Qt 6 development package layout. For a non-system Qt SDK, # Debian/Ubuntu Qt 6 development package layout. For a non-system Qt SDK,
# replace these flags with the paths printed by: # replace these flags with the paths printed by:
# pkg-config --cflags --libs Qt6Widgets # pkg-config --cflags --libs Qt6Widgets

Loading…
Cancel
Save