diff --git a/README.md b/README.md index c43a070..f7778a3 100644 --- a/README.md +++ b/README.md @@ -4,22 +4,24 @@ ```shell -用法:./SparkWebAppRuntime [选项] +用法:./spark-webapp-runtime [选项] 描述: 星火网页应用运行时 选项: -h, --help 显示这个此帮助。 -v, --version 显示版本信息。 - -p, --parser 启用参数解析方式. 默认顺序解析方式. - -t, --title \<title\> 设置程序的运行标题. 默认是 星火网页应用运行时. - -u, --url \<url\> 设置要打开的目标URL. 默认是空. - -w, --width \<width\> 设置程序运行的宽度. 默认是 1024. - -H, --height \<height\> 设置程序运行的高度. 默认是 768 - -i, --ico \<ico\> 设置程序运行的图标. - -d, --desc \<desc\> 设置程序的描述信息. - -c, --cfg \<cfg\> 设置程序运行的配置文件. - -r, --root \<root\> 设置内置WebServer的根路径. - -P, --port \<port\> 设置内置WebServer的监听端口号. + -p, --parser 启用参数解析方式。默认顺序解析方式。 + -t, --title \<title\> 设置程序的运行标题。默认是 星火网页应用运行环境。 + -u, --url \<url\> 设置要打开的目标 URL。默认为空。 + -w, --width \<width\> 设置程序运行的宽度。默认为 1024。 + -H, --height \<height\> 设置程序运行的高度。默认为 768。 + --fix-size 固定窗口大小。默认关闭该功能。 + --hide-buttons 隐藏控制按钮。默认关闭该功能。 + -i, --ico \<ico\> 设置程序运行的图标。 + -d, --desc \<desc\> 设置程序的描述信息。 + -c, --cfg \<cfg\> 设置程序运行的配置文件。 + -r, --root \<root\> 设置内置 WebServer 的根路径。 + -P, --port \<port\> 设置内置 WebServer 的监听端口号。 ``` 这里给大家附送两个例子,帮助大家理解使用 @@ -56,7 +58,7 @@ 作为星火系列应用,我们的设计哲学是M.I.S.(Make it Simple)没错我就是从KISS抄的 -配置spark-webapp-runtime环境是非常简单的 +配置 spark-webapp-runtime 环境是非常简单的 只需要 diff --git a/spark-webapp-runtime/help/help.html b/spark-webapp-runtime/help/help.html index 86c40c6..d3affe9 100644 --- a/spark-webapp-runtime/help/help.html +++ b/spark-webapp-runtime/help/help.html @@ -28,6 +28,8 @@ -u, --url <url> 设置要打开的目标 URL。默认为空。 -w, --width <width> 设置应用的窗口宽度。默认为 1024。 -H, --height <height> 设置应用的窗口高度。默认为 768。 + --fix-size 固定窗口大小。默认关闭该功能。 + --hide-buttons 隐藏控制按钮。默认关闭该功能。 -i, --ico <ico> 设置应用的图标。 -d, --desc <desc> 设置应用的描述信息。 -c, --cfg <cfg> 设置应用的配置文件。 @@ -61,6 +63,8 @@ -u, --url <url> The target URL. Default is Blank. -w, --width <width> The Width of Application. Default is 1024. -H, --height <height> The Height of Application. Default is 768. + --fix-size Fix Window Size. Default is false. + --hide-buttons Hide Control Buttons. Default is false. -i, --ico <ico> The ICON of Application. -d, --desc <desc> The Description of Application. -c, --cfg <cfg> The Configuration file of Application. diff --git a/spark-webapp-runtime/main.cpp b/spark-webapp-runtime/main.cpp index 6653df5..4508629 100644 --- a/spark-webapp-runtime/main.cpp +++ b/spark-webapp-runtime/main.cpp @@ -8,7 +8,6 @@ #include "mainwindow.h" #include <DApplication> -#include <DWidgetUtil> #include <DMainWindow> #include <QCommandLineParser> @@ -89,6 +88,14 @@ int main(int argc, char *argv[]) QString::number(DEFAULT_HEIGHT)); parser.addOption(optHeight); + QCommandLineOption optFixSize("fix-size", + QObject::tr("Fix Window Size. Default is false.")); + parser.addOption(optFixSize); + + QCommandLineOption optHideButtons("hide-buttons", + QObject::tr("Hide Control Buttons. Default is false.")); + parser.addOption(optHideButtons); + QCommandLineOption optIcon(QStringList() << "i" << "ico", QObject::tr("The ICON of Application."), "ico", @@ -134,6 +141,8 @@ int main(int argc, char *argv[]) QString szUrl = DEFAULT_URL; int width = DEFAULT_WIDTH; int height = DEFAULT_HEIGHT; + bool fixSize = false; + bool hideButtons = false; QString szIcon = DEFAULT_ICON; QString szDesc = DEFAULT_DESC; QString szRootPath = DEFAULT_ROOT; @@ -152,18 +161,20 @@ int main(int argc, char *argv[]) if (fi.exists()) { QSettings settings(szCfgFile, QSettings::IniFormat); - szTitle = settings.value("SpartWebAppRuntime/Title", DEFAULT_TITLE).toString(); - szUrl = settings.value("SpartWebAppRuntime/URL", DEFAULT_TITLE).toString(); - width = settings.value("SpartWebAppRuntime/Width", DEFAULT_WIDTH).toUInt(); - height = settings.value("SpartWebAppRuntime/Height", DEFAULT_HEIGHT).toUInt(); - szIcon = settings.value("SpartWebAppRuntime/Ico", DEFAULT_ICON).toString(); + szTitle = settings.value("SparkWebAppRuntime/Title", DEFAULT_TITLE).toString(); + szUrl = settings.value("SparkWebAppRuntime/URL", DEFAULT_TITLE).toString(); + width = settings.value("SparkWebAppRuntime/Width", DEFAULT_WIDTH).toUInt(); + height = settings.value("SparkWebAppRuntime/Height", DEFAULT_HEIGHT).toUInt(); + fixSize = settings.value("SparkWebAppRunTime/FixSize", false).toBool(); + hideButtons = settings.value("SparkWebAppRunTime/HideButtons", false).toBool(); + szIcon = settings.value("SparkWebAppRuntime/Ico", DEFAULT_ICON).toString(); szDesc = QString("%1<br/><br/>%2") - .arg(settings.value("SpartWebAppRuntime/Desc", QString()).toString()) + .arg(settings.value("SparkWebAppRuntime/Desc", QString()).toString()) .arg(szDefaultDesc); - szRootPath = settings.value("SpartWebAppRuntime/RootPath", QString()).toString(); - u16Port = settings.value("SpartWebAppRuntime/Port", 0).toUInt(); + szRootPath = settings.value("SparkWebAppRuntime/RootPath", QString()).toString(); + u16Port = settings.value("SparkWebAppRuntime/Port", 0).toUInt(); #if SSL_SERVER - u16sslPort = settings.value("SpartWebAppRuntime/SSLPort", 0).toUInt(); + u16sslPort = settings.value("SparkWebAppRuntime/SSLPort", 0).toUInt(); #endif } } @@ -187,6 +198,15 @@ int main(int argc, char *argv[]) height = parser.value(optHeight).toInt(); } + if (parser.isSet(optFixSize)) + { + fixSize = true; + } + if (parser.isSet(optHideButtons)) + { + hideButtons = true; + } + if (parser.isSet(optDesc)) { szDesc = QString("%1<br/><br/>%2").arg(parser.value(optDesc)) @@ -230,30 +250,41 @@ int main(int argc, char *argv[]) { height = QString(argv[4]).toInt(); } + if (argc > 5) { - szIcon = QString(argv[5]); + fixSize = true; } if (argc > 6) - szDesc = QString("%1<br/><br/>%2").arg(QString(argv[6])) - .arg(szDefaultDesc);; + { + hideButtons = true; + } + if (argc > 7) { - szRootPath = QString(argv[7]); + szIcon = QString(argv[7]); } if (argc > 8) { - u16Port = QString(argv[8]).toUInt(); + szDesc = QString("%1<br/><br/>%2").arg(QString(argv[8])).arg(szDefaultDesc); } -#if SSL_SERVER if (argc > 9) { - u16sslPort = QString(argv[9]).toUInt(); + szRootPath = QString(argv[9]); + } + if (argc > 10) + { + u16Port = QString(argv[10]).toUInt(); + } +#if SSL_SERVER + if (argc > 11) + { + u16sslPort = QString(argv[11]).toUInt(); } #endif } - MainWindow w(szTitle, szUrl, width, height, dialog); + MainWindow w(szTitle, szUrl, width, height, fixSize, hideButtons, dialog); #if SSL_SERVER if (!szRootPath.isEmpty() && u16Port > 0 && u16sslPort > 0) @@ -287,7 +318,5 @@ int main(int argc, char *argv[]) } w.show(); - - Dtk::Widget::moveToCenter(&w); return a.exec(); } diff --git a/spark-webapp-runtime/mainwindow.cpp b/spark-webapp-runtime/mainwindow.cpp index 5d8567b..2d4dd34 100644 --- a/spark-webapp-runtime/mainwindow.cpp +++ b/spark-webapp-runtime/mainwindow.cpp @@ -1,6 +1,7 @@ #include "mainwindow.h" #include <DMainWindow> +#include <DWidgetUtil> #include <DTitlebar> #include <QLayout> @@ -11,6 +12,8 @@ MainWindow::MainWindow(QString szTitle, QString szUrl, int nWidth, int nHeight, + bool nFixSize, + bool nHideButtons, DAboutDialog *dialog, QWidget *parent) : DMainWindow(parent) @@ -25,13 +28,13 @@ MainWindow::MainWindow(QString szTitle, , m_width(nWidth) , m_height(nHeight) { - // setFixedSize(nWidth, nHeight); - // 应 shenmo 要求改成设置最小尺寸试试效果 - setMinimumSize(m_width, m_height); - setCentralWidget(m_widget); centralWidget()->layout()->setContentsMargins(0, 0, 0, 0); + resize(m_width, m_height); + + moveToCenter(this); + setWindowIcon(QIcon(":/images/spark-webapp-runtime.svg")); titlebar()->setTitle(szTitle); @@ -49,13 +52,18 @@ MainWindow::MainWindow(QString szTitle, titlebar()->addWidget(btnRefresh, Qt::AlignLeft); m_fixSize->setCheckable(true); - m_fixSize->setChecked(false); + m_fixSize->setChecked(nFixSize); + m_fixSize->setDisabled(nFixSize); // 建议使用命令行参数 --fix-size 或者 --hide-buttons 时直接禁止在 GUI 修改选项,主要因为最大化按钮无法刷新存在状态,干脆都禁用了...... m_hideButtons->setCheckable(true); - m_hideButtons->setChecked(false); + m_hideButtons->setChecked(nHideButtons); + m_hideButtons->setDisabled(nHideButtons); m_menu->addAction(m_fixSize); m_menu->addAction(m_hideButtons); titlebar()->setMenu(m_menu); + fixSize(); + hideButtons(); + connect(btnBackward, &DToolButton::clicked, this, [&]() { if (m_widget) @@ -122,19 +130,12 @@ void MainWindow::fixSize() { if(m_fixSize->isChecked()) { - setFixedSize(this->width(), this->height()); // setFixedSize() 等同于同时设置 MaximumSize 和 MinimumSize - resize(this->width(), this->height()); - - /* - * 尝试固定窗口大小后禁用最大化按钮,但是取消勾选后无法恢复 - * titlebar()->setDisableFlags(Qt::WindowMaximizeButtonHint); - */ + setFixedSize(this->width(), this->height()); } else { setMinimumSize(m_width, m_height); setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); - resize(this->width(), this->height()); } } @@ -142,15 +143,15 @@ void MainWindow::hideButtons() { if(m_hideButtons->isChecked()) { - titlebar()->removeWidget(btnBackward); - titlebar()->removeWidget(btnForward); - titlebar()->removeWidget(btnRefresh); + btnBackward->hide(); + btnForward->hide(); + btnRefresh->hide(); } else { - titlebar()->addWidget(btnBackward, Qt::AlignLeft); - titlebar()->addWidget(btnForward, Qt::AlignLeft); - titlebar()->addWidget(btnRefresh, Qt::AlignLeft); + btnBackward->show(); + btnForward->show(); + btnRefresh->show(); } } diff --git a/spark-webapp-runtime/mainwindow.h b/spark-webapp-runtime/mainwindow.h index 892ff6f..20361b1 100644 --- a/spark-webapp-runtime/mainwindow.h +++ b/spark-webapp-runtime/mainwindow.h @@ -19,6 +19,8 @@ public: QString szUrl = DEFAULT_URL, int nWidth = DEFAULT_WIDTH, int nHeight = DEFAULT_HEIGHT, + bool nFixSize = false, + bool nHideButtons = false, DAboutDialog *dialog = nullptr, QWidget *parent = nullptr); ~MainWindow(); diff --git a/spark-webapp-runtime/translations/spark-webapp-runtime_zh_CN.qm b/spark-webapp-runtime/translations/spark-webapp-runtime_zh_CN.qm index 35296ca..b79bbcb 100644 Binary files a/spark-webapp-runtime/translations/spark-webapp-runtime_zh_CN.qm and b/spark-webapp-runtime/translations/spark-webapp-runtime_zh_CN.qm differ diff --git a/spark-webapp-runtime/translations/spark-webapp-runtime_zh_CN.ts b/spark-webapp-runtime/translations/spark-webapp-runtime_zh_CN.ts index cd25dbc..8dd6e90 100644 --- a/spark-webapp-runtime/translations/spark-webapp-runtime_zh_CN.ts +++ b/spark-webapp-runtime/translations/spark-webapp-runtime_zh_CN.ts @@ -4,12 +4,12 @@ <context> <name>MainWindow</name> <message> - <location filename="../mainwindow.cpp" line="23"/> + <location filename="../mainwindow.cpp" line="28"/> <source>Fix Size</source> <translation>固定大小</translation> </message> <message> - <location filename="../mainwindow.cpp" line="24"/> + <location filename="../mainwindow.cpp" line="29"/> <source>Hide Buttons</source> <translation>隐藏按钮</translation> </message> @@ -17,77 +17,87 @@ <context> <name>QObject</name> <message> - <location filename="../main.cpp" line="49"/> + <location filename="../main.cpp" line="48"/> <source>Presented By Spark developers # HadesStudio</source> <translation>由 星火开发者联盟 @ 花心胡萝卜 提供</translation> </message> <message> - <location filename="../main.cpp" line="56"/> + <location filename="../main.cpp" line="55"/> <source>This program is open source under GPLv3</source> <translation>本程序按GPL第三版开源</translation> </message> <message> - <location filename="../main.cpp" line="42"/> + <location filename="../main.cpp" line="41"/> <source>Version</source> <translation>版本</translation> </message> <message> - <location filename="../main.cpp" line="60"/> + <location filename="../main.cpp" line="59"/> <source>Description: %1</source> <translation>描述:%1</translation> </message> <message> - <location filename="../main.cpp" line="65"/> + <location filename="../main.cpp" line="64"/> <source>Enable CommandLineParser. Default is false.</source> <translation>启用参数解析方式。默认顺序解析方式。</translation> </message> <message> - <location filename="../main.cpp" line="69"/> + <location filename="../main.cpp" line="68"/> <source>The Title of Application. Default is %1.</source> <translation>设置程序的运行标题。默认是 %1。</translation> </message> <message> - <location filename="../main.cpp" line="75"/> + <location filename="../main.cpp" line="74"/> <source>The target URL. Default is Blank.</source> <translation>设置要打开的目标 URL。默认是空。</translation> </message> <message> - <location filename="../main.cpp" line="81"/> + <location filename="../main.cpp" line="80"/> <source>The Width of Application. Default is %1.</source> <translation>设置应用的窗口宽度。默认是 %1。</translation> </message> <message> - <location filename="../main.cpp" line="87"/> + <location filename="../main.cpp" line="86"/> <source>The Height of Application. Default is %1.</source> <translation>设置应用的窗口高度。默认是 %1。</translation> </message> <message> - <location filename="../main.cpp" line="93"/> + <location filename="../main.cpp" line="92"/> + <source>Fix Window Size. Default is false.</source> + <translation>固定窗口大小。默认关闭该功能。</translation> + </message> + <message> + <location filename="../main.cpp" line="96"/> + <source>Hide Control Buttons. Default is false.</source> + <translation>隐藏控制按钮。默认关闭该此功能。</translation> + </message> + <message> + <location filename="../main.cpp" line="100"/> <source>The ICON of Application.</source> <translation>设置应用的图标。</translation> </message> <message> - <location filename="../main.cpp" line="99"/> + <location filename="../main.cpp" line="106"/> <source>The Description of Application.</source> <translation>设置应用的描述信息。</translation> </message> <message> - <location filename="../main.cpp" line="105"/> + <location filename="../main.cpp" line="112"/> <source>The Configuration file of Application.</source> <translation>设置应用的配置文件。</translation> </message> <message> - <location filename="../main.cpp" line="111"/> + <location filename="../main.cpp" line="118"/> <source>The root path of the program web service.</source> <translation>设置内置 WebServer 的根路径。</translation> </message> <message> - <location filename="../main.cpp" line="118"/> + <location filename="../main.cpp" line="125"/> <source>The port number of the program web service.</source> <translation>设置内置 WebServer 的监听端口号。</translation> </message> <message> - <location filename="../main.cpp" line="125"/> + <location filename="../main.cpp" line="132"/> <source>The ssl port number of the program web service.</source> <translation>设置内置 WebServer 的 SSL 协议的监听端口号。</translation> </message>