mirror of
https://gitee.com/spark-store-project/spark-web-app-runtime.git
synced 2025-06-02 13:19:51 +08:00
fix: 修复退出全屏模式后菜单状态不同步的问题
重载 resizeEvent,根据窗口状态手动同步菜单状态。 Log: 修复退出全屏模式后菜单状态不同步的问题
This commit is contained in:
parent
2f38b9dd76
commit
2453752bd7
spark-webapp-runtime
@ -3,18 +3,19 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#define DEFAULT_TITLE QObject::tr("SparkWebAppRuntime")
|
||||
#define DEFAULT_URL QString("qrc:/help/help.html")
|
||||
#define DEFAULT_WIDTH (1024)
|
||||
#define DEFAULT_HEIGHT (768)
|
||||
#define DEFAULT_TITLE QObject::tr("SparkWebAppRuntime")
|
||||
//#define DEFAULT_URL QString("qrc:/help/help.html")
|
||||
#define DEFAULT_URL QString("https://www.baidu.com")
|
||||
#define DEFAULT_WIDTH (1024)
|
||||
#define DEFAULT_HEIGHT (768)
|
||||
|
||||
#define DEFAULT_DESC QString()
|
||||
#define DEFAULT_ICON QString()
|
||||
#define DEFAULT_CFG QString()
|
||||
#define DEFAULT_DESC QString()
|
||||
#define DEFAULT_ICON QString()
|
||||
#define DEFAULT_CFG QString()
|
||||
|
||||
#define DEFAULT_ROOT QString()
|
||||
#define DEFAULT_PORT 0
|
||||
#define DEFAULT_ROOT QString()
|
||||
#define DEFAULT_PORT 0
|
||||
|
||||
#define CURRENT_VER (1.6)
|
||||
#define CURRENT_VER (1.6)
|
||||
|
||||
#endif // GLOBALDEFINE_H
|
||||
|
@ -22,7 +22,7 @@ int main(int argc, char *argv[])
|
||||
a.setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
|
||||
a.setApplicationVersion(QString::number(CURRENT_VER));
|
||||
a.setOrganizationName("spark-union"); // 添加组织名称,和商店主体的文件夹同在 ~/.local/share/spark-union 文件夹下
|
||||
a.setOrganizationName("spark-union"); // 添加组织名称,和商店主体的文件夹同在 ~/.local/share/spark-union 文件夹下
|
||||
a.setApplicationName("SparkWebAppRuntime"); // 这里不要翻译,否则 ~/.local/share 中文件夹名也会被翻译
|
||||
|
||||
DAboutDialog *dialog = new DAboutDialog;
|
||||
@ -41,15 +41,15 @@ int main(int argc, char *argv[])
|
||||
// Description
|
||||
QString szDefaultDesc = QString("<a href='https://gitee.com/deepin-community-store/spark-web-app-runtime'><span style='font-size:12pt;font-weight:500;'>%1</span></a><br/>"
|
||||
"<span style='font-size:12pt;'>%2</span>")
|
||||
.arg(DEFAULT_TITLE)
|
||||
.arg(QObject::tr("Presented By Spark developers # HadesStudio"));
|
||||
.arg(DEFAULT_TITLE)
|
||||
.arg(QObject::tr("Presented By Spark developers # HadesStudio"));
|
||||
dialog->setDescription(szDefaultDesc);
|
||||
// WebsiteName
|
||||
dialog->setWebsiteName("Spark Project");
|
||||
// WebsiteLink
|
||||
dialog->setWebsiteLink("https://gitee.com/deepin-community-store/");
|
||||
// License
|
||||
dialog->setLicense(QObject::tr("This program is open source under GPLv3")); // 本程序按GPL第三版开源
|
||||
dialog->setLicense(QObject::tr("This program is open source under GPLv3")); // 本程序按GPL第三版开源
|
||||
|
||||
QCommandLineParser parser;
|
||||
|
||||
@ -57,40 +57,46 @@ int main(int argc, char *argv[])
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
|
||||
QCommandLineOption optParser(QStringList() << "p" << "parser",
|
||||
QCommandLineOption optParser(QStringList() << "p"
|
||||
<< "parser",
|
||||
QObject::tr("Enable CommandLineParser. Default is false."));
|
||||
parser.addOption(optParser);
|
||||
|
||||
QCommandLineOption optTitle(QStringList() << "t" << "title",
|
||||
QCommandLineOption optTitle(QStringList() << "t"
|
||||
<< "title",
|
||||
QObject::tr("The Title of Application. Default is %1.").arg(DEFAULT_TITLE),
|
||||
"title",
|
||||
DEFAULT_TITLE);
|
||||
parser.addOption(optTitle);
|
||||
|
||||
QCommandLineOption optUrl(QStringList() << "u" << "url",
|
||||
QCommandLineOption optUrl(QStringList() << "u"
|
||||
<< "url",
|
||||
QObject::tr("The target URL. Default is Blank."),
|
||||
"url",
|
||||
DEFAULT_URL);
|
||||
parser.addOption(optUrl);
|
||||
|
||||
QCommandLineOption optWidth(QStringList() << "w" << "width",
|
||||
QCommandLineOption optWidth(QStringList() << "w"
|
||||
<< "width",
|
||||
QObject::tr("The Width of Application. Default is %1.").arg(DEFAULT_WIDTH),
|
||||
"width",
|
||||
QString::number(DEFAULT_WIDTH));
|
||||
parser.addOption(optWidth);
|
||||
|
||||
QCommandLineOption optHeight(QStringList() << "H" << "height",
|
||||
QCommandLineOption optHeight(QStringList() << "H"
|
||||
<< "height",
|
||||
QObject::tr("The Height of Application. Default is %1.").arg(DEFAULT_HEIGHT),
|
||||
"height",
|
||||
QString::number(DEFAULT_HEIGHT));
|
||||
parser.addOption(optHeight);
|
||||
|
||||
QCommandLineOption optTray(QStringList() << "T" << "tray",
|
||||
QObject::tr("Enable Tray Icon. Default is false."));
|
||||
QCommandLineOption optTray(QStringList() << "T"
|
||||
<< "tray",
|
||||
QObject::tr("Enable Tray Icon. Default is false."));
|
||||
parser.addOption(optTray);
|
||||
|
||||
QCommandLineOption optFullScreen("full-screen",
|
||||
QObject::tr("Run in Fullscreen Mode. Default is false."));
|
||||
QObject::tr("Run in Fullscreen Mode. Default is false."));
|
||||
parser.addOption(optFullScreen);
|
||||
|
||||
QCommandLineOption optFixSize("fix-size",
|
||||
@ -98,42 +104,47 @@ int main(int argc, char *argv[])
|
||||
parser.addOption(optFixSize);
|
||||
|
||||
QCommandLineOption optHideButtons("hide-buttons",
|
||||
QObject::tr("Hide Control Buttons. Default is false."));
|
||||
QObject::tr("Hide Control Buttons. Default is false."));
|
||||
parser.addOption(optHideButtons);
|
||||
|
||||
QCommandLineOption optIcon(QStringList() << "i" << "ico",
|
||||
QCommandLineOption optIcon(QStringList() << "i"
|
||||
<< "ico",
|
||||
QObject::tr("The ICON of Application."),
|
||||
"ico",
|
||||
DEFAULT_ICON);
|
||||
parser.addOption(optIcon);
|
||||
|
||||
QCommandLineOption optDesc(QStringList() << "d" << "desc",
|
||||
QCommandLineOption optDesc(QStringList() << "d"
|
||||
<< "desc",
|
||||
QObject::tr("The Description of Application."),
|
||||
"desc",
|
||||
DEFAULT_DESC);
|
||||
parser.addOption(optDesc);
|
||||
|
||||
QCommandLineOption optCfgFile(QStringList() << "c" << "cfg",
|
||||
QCommandLineOption optCfgFile(QStringList() << "c"
|
||||
<< "cfg",
|
||||
QObject::tr("The Configuration file of Application."),
|
||||
"cfg",
|
||||
DEFAULT_CFG);
|
||||
parser.addOption(optCfgFile);
|
||||
|
||||
QCommandLineOption optRootPath(QStringList() << "r" << "root",
|
||||
QCommandLineOption optRootPath(QStringList() << "r"
|
||||
<< "root",
|
||||
QObject::tr("The root path of the program web service."),
|
||||
"root",
|
||||
DEFAULT_ROOT);
|
||||
parser.addOption(optRootPath);
|
||||
|
||||
|
||||
QCommandLineOption optPort(QStringList() << "P" << "port",
|
||||
QCommandLineOption optPort(QStringList() << "P"
|
||||
<< "port",
|
||||
QObject::tr("The port number of the program web service."),
|
||||
"port",
|
||||
DEFAULT_PORT);
|
||||
parser.addOption(optPort);
|
||||
|
||||
#if SSL_SERVER
|
||||
QCommandLineOption optSSLPort(QStringList() << "s" << "sslport",
|
||||
QCommandLineOption optSSLPort(QStringList() << "s"
|
||||
<< "sslport",
|
||||
QObject::tr("The ssl port number of the program web service."),
|
||||
"sslport",
|
||||
DEFAULT_PORT);
|
||||
@ -159,13 +170,10 @@ int main(int argc, char *argv[])
|
||||
#endif
|
||||
|
||||
QString szCfgFile = DEFAULT_CFG;
|
||||
if (parser.isSet(optCfgFile))
|
||||
{
|
||||
if (parser.isSet(optCfgFile)) {
|
||||
szCfgFile = parser.value(optCfgFile);
|
||||
if (!szCfgFile.isEmpty())
|
||||
{
|
||||
if (QFileInfo(szCfgFile).exists())
|
||||
{
|
||||
if (!szCfgFile.isEmpty()) {
|
||||
if (QFileInfo(szCfgFile).exists()) {
|
||||
QSettings settings(szCfgFile, QSettings::IniFormat);
|
||||
szTitle = settings.value("SparkWebAppRuntime/Title", DEFAULT_TITLE).toString();
|
||||
szUrl = settings.value("SparkWebAppRuntime/URL", DEFAULT_TITLE).toString();
|
||||
@ -177,8 +185,8 @@ int main(int argc, char *argv[])
|
||||
hideButtons = settings.value("SparkWebAppRunTime/HideButtons", false).toBool();
|
||||
szIcon = settings.value("SparkWebAppRuntime/Ico", DEFAULT_ICON).toString();
|
||||
szDesc = QString("%1<br/><br/>%2")
|
||||
.arg(settings.value("SparkWebAppRuntime/Desc", QString()).toString())
|
||||
.arg(szDefaultDesc);
|
||||
.arg(settings.value("SparkWebAppRuntime/Desc", QString()).toString())
|
||||
.arg(szDefaultDesc);
|
||||
szRootPath = settings.value("SparkWebAppRuntime/RootPath", QString()).toString();
|
||||
u16Port = settings.value("SparkWebAppRuntime/Port", 0).toUInt();
|
||||
#if SSL_SERVER
|
||||
@ -189,162 +197,130 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// 命令行级别优先, 覆盖配置文件的设置
|
||||
if (parser.isSet(optTitle))
|
||||
{
|
||||
if (parser.isSet(optTitle)) {
|
||||
szTitle = parser.value(optTitle);
|
||||
}
|
||||
if (parser.isSet(optUrl))
|
||||
{
|
||||
if (parser.isSet(optUrl)) {
|
||||
szUrl = parser.value(optUrl);
|
||||
}
|
||||
if (parser.isSet(optWidth))
|
||||
{
|
||||
if (parser.isSet(optWidth)) {
|
||||
width = parser.value(optWidth).toInt();
|
||||
}
|
||||
if (parser.isSet(optHeight))
|
||||
{
|
||||
if (parser.isSet(optHeight)) {
|
||||
height = parser.value(optHeight).toInt();
|
||||
}
|
||||
|
||||
if (parser.isSet(optTray))
|
||||
{
|
||||
if (parser.isSet(optTray)) {
|
||||
tray = true;
|
||||
}
|
||||
if (parser.isSet(optFullScreen))
|
||||
{
|
||||
if (parser.isSet(optFullScreen)) {
|
||||
fullScreen = true;
|
||||
}
|
||||
if (parser.isSet(optFixSize))
|
||||
{
|
||||
if (parser.isSet(optFixSize)) {
|
||||
fixSize = true;
|
||||
}
|
||||
if (parser.isSet(optHideButtons))
|
||||
{
|
||||
if (parser.isSet(optHideButtons)) {
|
||||
hideButtons = true;
|
||||
}
|
||||
|
||||
if (parser.isSet(optDesc))
|
||||
{
|
||||
szDesc = QString("%1<br/><br/>%2").arg(parser.value(optDesc))
|
||||
.arg(szDefaultDesc);
|
||||
if (parser.isSet(optDesc)) {
|
||||
szDesc = QString("%1<br/><br/>%2").arg(parser.value(optDesc)).arg(szDefaultDesc);
|
||||
}
|
||||
|
||||
if (parser.isSet(optRootPath))
|
||||
{
|
||||
if (parser.isSet(optRootPath)) {
|
||||
szRootPath = parser.value(optRootPath);
|
||||
}
|
||||
|
||||
if (parser.isSet(optPort))
|
||||
{
|
||||
if (parser.isSet(optPort)) {
|
||||
u16Port = parser.value(optPort).toUInt();
|
||||
}
|
||||
|
||||
#if SSL_SERVER
|
||||
if (parser.isSet(optSSLPort))
|
||||
{
|
||||
if (parser.isSet(optSSLPort)) {
|
||||
u16sslPort = parser.value(optSSLPort).toUInt();
|
||||
}
|
||||
#endif
|
||||
|
||||
// 没设置 -p 并且参数个数 > 1 并且第一个参数不是 - 开始的
|
||||
if (!parser.isSet(optParser) && argc > 1 && !QString(argv[1]).startsWith("-"))
|
||||
{
|
||||
if (!parser.isSet(optParser) && argc > 1 && !QString(argv[1]).startsWith("-")) {
|
||||
// 按照固定顺序级别最优先
|
||||
if (argc > 1)
|
||||
{
|
||||
if (argc > 1) {
|
||||
szTitle = argv[1];
|
||||
}
|
||||
if (argc > 2)
|
||||
{
|
||||
if (argc > 2) {
|
||||
szUrl = argv[2];
|
||||
}
|
||||
if (argc > 3)
|
||||
{
|
||||
if (argc > 3) {
|
||||
width = QString(argv[3]).toInt();
|
||||
}
|
||||
if (argc > 4)
|
||||
{
|
||||
if (argc > 4) {
|
||||
height = QString(argv[4]).toInt();
|
||||
}
|
||||
|
||||
if (argc > 5)
|
||||
{
|
||||
if (argc > 5) {
|
||||
tray = true;
|
||||
}
|
||||
if (argc > 6)
|
||||
{
|
||||
if (argc > 6) {
|
||||
fullScreen = true;
|
||||
}
|
||||
if (argc > 7)
|
||||
{
|
||||
if (argc > 7) {
|
||||
fixSize = true;
|
||||
}
|
||||
if (argc > 8)
|
||||
{
|
||||
if (argc > 8) {
|
||||
hideButtons = true;
|
||||
}
|
||||
|
||||
if (argc > 9)
|
||||
{
|
||||
if (argc > 9) {
|
||||
szIcon = QString(argv[9]);
|
||||
}
|
||||
if (argc > 10)
|
||||
{
|
||||
if (argc > 10) {
|
||||
szDesc = QString("%1<br/><br/>%2").arg(QString(argv[10])).arg(szDefaultDesc);
|
||||
}
|
||||
if (argc > 11)
|
||||
{
|
||||
if (argc > 11) {
|
||||
szRootPath = QString(argv[11]);
|
||||
}
|
||||
if (argc > 12)
|
||||
{
|
||||
if (argc > 12) {
|
||||
u16Port = QString(argv[12]).toUInt();
|
||||
}
|
||||
#if SSL_SERVER
|
||||
if (argc > 13)
|
||||
{
|
||||
if (argc > 13) {
|
||||
u16sslPort = QString(argv[13]).toUInt();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if(fixSize)
|
||||
{
|
||||
fullScreen = false; // 固定窗口大小时禁用全屏模式,避免标题栏按钮 BUG
|
||||
if (fixSize) {
|
||||
fullScreen = false; // 固定窗口大小时禁用全屏模式,避免标题栏按钮 BUG
|
||||
}
|
||||
|
||||
a.setQuitOnLastWindowClosed(!tray); // 启用托盘时,退出程序后服务不终止
|
||||
|
||||
MainWindow w(szTitle, szUrl, width, height, tray, fullScreen, fixSize, hideButtons, dialog);
|
||||
// qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-features=UseModernMediaControls");
|
||||
|
||||
#if SSL_SERVER
|
||||
if (!szRootPath.isEmpty() && u16Port > 0 && u16sslPort > 0)
|
||||
{
|
||||
if (!szRootPath.isEmpty() && u16Port > 0 && u16sslPort > 0) {
|
||||
HttpD httpd(szRootPath, u16Port, u16sslPort);
|
||||
httpd.start();
|
||||
}
|
||||
#else
|
||||
if (!szRootPath.isEmpty() && u16Port > 0)
|
||||
{
|
||||
if (!szRootPath.isEmpty() && u16Port > 0) {
|
||||
static HttpD httpd(szRootPath, u16Port);
|
||||
QObject::connect(&w, &MainWindow::sigQuit, &httpd, &HttpD::stop);
|
||||
httpd.start();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (parser.isSet(optIcon))
|
||||
{
|
||||
if (parser.isSet(optIcon)) {
|
||||
szIcon = parser.value(optIcon);
|
||||
}
|
||||
|
||||
if (!szIcon.isEmpty())
|
||||
{
|
||||
if (!szIcon.isEmpty()) {
|
||||
dialog->setWindowIcon(QIcon(szIcon));
|
||||
dialog->setProductIcon(QIcon(szIcon));
|
||||
w.setIcon(szIcon);
|
||||
}
|
||||
if (!szDesc.isEmpty())
|
||||
{
|
||||
if (!szDesc.isEmpty()) {
|
||||
dialog->setDescription(szDesc);
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ MainWindow::MainWindow(QString szTitle,
|
||||
|
||||
m_fullScreen->setCheckable(true);
|
||||
m_fullScreen->setChecked(nFullScreen);
|
||||
m_fullScreen->setDisabled(nFixSize); // 固定窗口大小时禁用全屏模式,避免标题栏按钮 BUG
|
||||
m_fullScreen->setDisabled(nFixSize); // 固定窗口大小时禁用全屏模式,避免标题栏按钮 BUG
|
||||
m_fixSize->setCheckable(true);
|
||||
m_fixSize->setChecked(nFixSize);
|
||||
m_fixSize->setDisabled(nFixSize);
|
||||
@ -84,13 +84,11 @@ MainWindow::MainWindow(QString szTitle,
|
||||
m_hideButtons->setChecked(nHideButtons);
|
||||
m_hideButtons->setDisabled(nHideButtons);
|
||||
/* 命令行设置参数后 GUI 中隐藏对应选项 */
|
||||
if(!nFixSize)
|
||||
{
|
||||
if (!nFixSize) {
|
||||
m_menu->addAction(m_fullScreen);
|
||||
m_menu->addAction(m_fixSize);
|
||||
}
|
||||
if(!nHideButtons)
|
||||
{
|
||||
if (!nHideButtons) {
|
||||
m_menu->addAction(m_hideButtons);
|
||||
}
|
||||
titlebar()->setMenu(m_menu);
|
||||
@ -108,8 +106,7 @@ MainWindow::MainWindow(QString szTitle,
|
||||
m_tray->setToolTip(szTitle);
|
||||
m_tray->setIcon(QIcon(":/images/spark-webapp-runtime.svg"));
|
||||
|
||||
if(tray)
|
||||
{
|
||||
if (tray) {
|
||||
m_tray->show(); // 启用托盘时显示
|
||||
}
|
||||
|
||||
@ -124,52 +121,42 @@ MainWindow::MainWindow(QString szTitle,
|
||||
message->setIcon(QIcon::fromTheme("deepin-download").pixmap(64, 64));
|
||||
message->setWidget(downloadProgressBar);
|
||||
|
||||
connect(btnBack, &DToolButton::clicked, this, [&]()
|
||||
{
|
||||
connect(btnBack, &DToolButton::clicked, this, [&]() {
|
||||
m_widget->goBack();
|
||||
});
|
||||
connect(btnForward, &DToolButton::clicked, this, [&]()
|
||||
{
|
||||
connect(btnForward, &DToolButton::clicked, this, [&]() {
|
||||
m_widget->goForward();
|
||||
});
|
||||
connect(btnRefresh, &DToolButton::clicked, this, [&]()
|
||||
{
|
||||
connect(btnRefresh, &DToolButton::clicked, this, [&]() {
|
||||
m_widget->refresh();
|
||||
});
|
||||
|
||||
connect(m_fullScreen, &QAction::triggered, this, [=]()
|
||||
{
|
||||
connect(m_fullScreen, &QAction::triggered, this, [=]() {
|
||||
fullScreen();
|
||||
});
|
||||
connect(m_fixSize, &QAction::triggered, this, [=]()
|
||||
{
|
||||
connect(m_fixSize, &QAction::triggered, this, [=]() {
|
||||
fixSize();
|
||||
});
|
||||
connect(m_hideButtons, &QAction::triggered, this, [=]()
|
||||
{
|
||||
connect(m_hideButtons, &QAction::triggered, this, [=]() {
|
||||
hideButtons();
|
||||
});
|
||||
|
||||
connect(t_show, &QAction::triggered, this, [=]()
|
||||
{
|
||||
connect(t_show, &QAction::triggered, this, [=]() {
|
||||
this->activateWindow();
|
||||
fixSize();
|
||||
});
|
||||
connect(t_about, &QAction::triggered, this, [=]()
|
||||
{
|
||||
connect(t_about, &QAction::triggered, this, [=]() {
|
||||
m_dialog->activateWindow();
|
||||
m_dialog->show();
|
||||
});
|
||||
connect(t_exit, &QAction::triggered, this, [=]()
|
||||
{
|
||||
connect(t_exit, &QAction::triggered, this, [=]() {
|
||||
exit(0);
|
||||
});
|
||||
connect(m_tray, &QSystemTrayIcon::activated, this, &MainWindow::trayIconActivated);
|
||||
|
||||
connect(m_widget->getPage()->profile(), &QWebEngineProfile::downloadRequested, this, &MainWindow::on_downloadStart);
|
||||
|
||||
connect(m_widget->getPage(), &QWebEnginePage::windowCloseRequested, this, [=]()
|
||||
{
|
||||
connect(m_widget->getPage(), &QWebEnginePage::windowCloseRequested, this, [=]() {
|
||||
this->close();
|
||||
});
|
||||
}
|
||||
@ -184,29 +171,58 @@ MainWindow::~MainWindow()
|
||||
|
||||
void MainWindow::setIcon(QString szIconPath)
|
||||
{
|
||||
if (QFileInfo(szIconPath).exists())
|
||||
{
|
||||
if (QFileInfo(szIconPath).exists()) {
|
||||
titlebar()->setIcon(QIcon(szIconPath));
|
||||
setWindowIcon(QIcon(szIconPath));
|
||||
m_tray->setIcon(QIcon(szIconPath));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (!m_fixSize->isChecked()) // 固定窗口大小时禁止全屏
|
||||
{
|
||||
if (event->key() == Qt::Key_F11) // 绑定键盘快捷键 F11
|
||||
{
|
||||
m_fullScreen->trigger();
|
||||
m_menu->update();
|
||||
}
|
||||
}
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void MainWindow::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
if (this->isFullScreen()) {
|
||||
m_fullScreen->setChecked(true);
|
||||
} else {
|
||||
m_fullScreen->setChecked(false);
|
||||
if (!mFixSize) {
|
||||
m_fixSize->setEnabled(true); // 命令行参数没有固定窗口大小时,窗口模式下允许手动选择固定窗口大小
|
||||
}
|
||||
}
|
||||
DMainWindow::resizeEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if (!mtray) {
|
||||
m_dialog->close(); // 不启用托盘时,关闭主窗口则关闭关于窗口
|
||||
}
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void MainWindow::fullScreen()
|
||||
{
|
||||
if(m_fullScreen->isChecked())
|
||||
{
|
||||
if (m_fullScreen->isChecked()) {
|
||||
m_fixSize->setChecked(false);
|
||||
m_fixSize->setDisabled(true);
|
||||
m_menu->update();
|
||||
showFullScreen();
|
||||
// DMessageManager::instance()->sendMessage(this, QIcon::fromTheme("dialog-information").pixmap(64, 64), QString(tr("%1Fullscreen Mode")).arg(" "));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!mFixSize)
|
||||
{
|
||||
m_fixSize->setDisabled(false); // 命令行参数没有固定窗口大小时,窗口模式下允许手动选择固定窗口大小
|
||||
} else {
|
||||
if (!mFixSize) {
|
||||
m_fixSize->setDisabled(false); // 命令行参数没有固定窗口大小时,窗口模式下允许手动选择固定窗口大小
|
||||
}
|
||||
m_menu->update();
|
||||
showNormal();
|
||||
@ -216,16 +232,13 @@ void MainWindow::fullScreen()
|
||||
|
||||
void MainWindow::fixSize()
|
||||
{
|
||||
if(m_fixSize->isChecked())
|
||||
{
|
||||
if (m_fixSize->isChecked()) {
|
||||
m_fullScreen->setChecked(false);
|
||||
m_fullScreen->setDisabled(true);
|
||||
m_menu->update();
|
||||
setFixedSize(this->size());
|
||||
/* 存在 BUG: 启用托盘图标后,若手动选择固定窗口大小,并且关闭窗口,再次打开时会丢失最大化按钮,且无法恢复。 */
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
m_fullScreen->setDisabled(false);
|
||||
m_menu->update();
|
||||
setMinimumSize(m_width, m_height);
|
||||
@ -236,14 +249,11 @@ void MainWindow::fixSize()
|
||||
|
||||
void MainWindow::hideButtons()
|
||||
{
|
||||
if(m_hideButtons->isChecked())
|
||||
{
|
||||
if (m_hideButtons->isChecked()) {
|
||||
btnBack->hide();
|
||||
btnForward->hide();
|
||||
btnRefresh->hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
btnBack->show();
|
||||
btnForward->show();
|
||||
btnRefresh->show();
|
||||
@ -253,65 +263,37 @@ void MainWindow::hideButtons()
|
||||
QString MainWindow::saveAs(QString fileName)
|
||||
{
|
||||
QString saveFile = QFileDialog::getSaveFileName(this, tr("Save As"), QDir::homePath() + "/Downloads/" + fileName);
|
||||
if(!saveFile.isEmpty())
|
||||
{
|
||||
if(QFileInfo(QFileInfo(saveFile).absolutePath()).permissions().testFlag(QFile::WriteUser)) // 判断上层目录是否可写入
|
||||
if (!saveFile.isEmpty()) {
|
||||
if (QFileInfo(QFileInfo(saveFile).absolutePath()).permissions().testFlag(QFile::WriteUser)) // 判断上层目录是否可写入
|
||||
{
|
||||
return saveFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return saveAs(fileName);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void MainWindow::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if(!m_fixSize->isChecked()) // 固定窗口大小时禁止全屏
|
||||
{
|
||||
if(event->key() == Qt::Key_F11) // 绑定键盘快捷键 F11
|
||||
{
|
||||
m_fullScreen->trigger();
|
||||
m_menu->update();
|
||||
}
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if(!mtray)
|
||||
{
|
||||
m_dialog->close(); // 不启用托盘时,关闭主窗口则关闭关于窗口
|
||||
}
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void MainWindow::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
|
||||
{
|
||||
switch(reason)
|
||||
{
|
||||
/* 响应托盘点击事件 */
|
||||
case QSystemTrayIcon::Trigger:
|
||||
this->activateWindow();
|
||||
fixSize();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
switch (reason) {
|
||||
/* 响应托盘点击事件 */
|
||||
case QSystemTrayIcon::Trigger:
|
||||
this->activateWindow();
|
||||
fixSize();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_downloadStart(QWebEngineDownloadItem *item)
|
||||
{
|
||||
/* 尝试加锁互斥量,禁止同时下载多个文件 */
|
||||
if(mutex.tryLock())
|
||||
{
|
||||
if (mutex.tryLock()) {
|
||||
QString fileName = QFileInfo(item->path()).fileName();
|
||||
QString filePath = saveAs(fileName);
|
||||
if(filePath.isEmpty())
|
||||
{
|
||||
if (filePath.isEmpty()) {
|
||||
mutex.unlock();
|
||||
return;
|
||||
}
|
||||
@ -319,21 +301,17 @@ void MainWindow::on_downloadStart(QWebEngineDownloadItem *item)
|
||||
filePath = QFileInfo(item->path()).absoluteFilePath();
|
||||
|
||||
connect(item, &QWebEngineDownloadItem::downloadProgress, this, &MainWindow::on_downloadProgress);
|
||||
connect(item, &QWebEngineDownloadItem::finished, this, [=]()
|
||||
{
|
||||
connect(item, &QWebEngineDownloadItem::finished, this, [=]() {
|
||||
on_downloadFinish(filePath);
|
||||
});
|
||||
|
||||
connect(pause, &DPushButton::clicked, this, [=]()
|
||||
{
|
||||
connect(pause, &DPushButton::clicked, this, [=]() {
|
||||
on_downloadPause(item);
|
||||
});
|
||||
connect(resume, &DPushButton::clicked, this, [=]()
|
||||
{
|
||||
connect(resume, &DPushButton::clicked, this, [=]() {
|
||||
on_downloadResume(item);
|
||||
});
|
||||
connect(cancel, &DPushButton::clicked, this, [=]()
|
||||
{
|
||||
connect(cancel, &DPushButton::clicked, this, [=]() {
|
||||
on_downloadCancel(item);
|
||||
});
|
||||
|
||||
@ -348,10 +326,8 @@ void MainWindow::on_downloadStart(QWebEngineDownloadItem *item)
|
||||
isCanceled = false;
|
||||
resume->hide();
|
||||
pause->show();
|
||||
this->message->show(); // 上一次下载完成后隐藏了进度条,这里要重新显示
|
||||
}
|
||||
else
|
||||
{
|
||||
this->message->show(); // 上一次下载完成后隐藏了进度条,这里要重新显示
|
||||
} else {
|
||||
DMessageManager::instance()->sendMessage(this, QIcon::fromTheme("dialog-cancel").pixmap(64, 64), QString(tr("%1Wait for previous download to complete!")).arg(" "));
|
||||
}
|
||||
}
|
||||
@ -372,7 +348,7 @@ void MainWindow::on_downloadFinish(QString filePath)
|
||||
|
||||
message->hide();
|
||||
|
||||
if(!isCanceled) // 下载完成显示提示信息
|
||||
if (!isCanceled) // 下载完成显示提示信息
|
||||
{
|
||||
DPushButton *button = new DPushButton(tr("Open"));
|
||||
|
||||
@ -382,8 +358,7 @@ void MainWindow::on_downloadFinish(QString filePath)
|
||||
message->setWidget(button);
|
||||
DMessageManager::instance()->sendMessage(this, message);
|
||||
|
||||
connect(button, &DPushButton::clicked, this, [=]()
|
||||
{
|
||||
connect(button, &DPushButton::clicked, this, [=]() {
|
||||
DDesktopServices::showFileItem(filePath);
|
||||
message->hide();
|
||||
});
|
||||
@ -410,7 +385,7 @@ void MainWindow::on_downloadResume(QWebEngineDownloadItem *item)
|
||||
|
||||
void MainWindow::on_downloadCancel(QWebEngineDownloadItem *item)
|
||||
{
|
||||
isCanceled = true; // 取消下载
|
||||
isCanceled = true; // 取消下载
|
||||
item->cancel();
|
||||
|
||||
mutex.unlock();
|
||||
|
@ -36,6 +36,11 @@ public:
|
||||
|
||||
void setIcon(QString szIconPath);
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
void closeEvent(QCloseEvent *event);
|
||||
|
||||
private:
|
||||
Widget *m_widget;
|
||||
DAboutDialog *m_dialog;
|
||||
@ -63,8 +68,8 @@ private:
|
||||
QHBoxLayout *progress;
|
||||
DFloatingMessage *message;
|
||||
|
||||
QMutex mutex; // 通过 Mutex 互斥量禁止同时下载多个文件(使用简单的 bool 变量应该也可以实现该功能?)
|
||||
bool isCanceled; // 判断是否为取消下载
|
||||
QMutex mutex; // 通过 Mutex 互斥量禁止同时下载多个文件(使用简单的 bool 变量应该也可以实现该功能?)
|
||||
bool isCanceled; // 判断是否为取消下载
|
||||
|
||||
bool mtray, mFixSize;
|
||||
int m_width, m_height;
|
||||
@ -75,9 +80,6 @@ private:
|
||||
|
||||
QString saveAs(QString fileName);
|
||||
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
void closeEvent(QCloseEvent *event);
|
||||
|
||||
private slots:
|
||||
void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
|
||||
@ -90,7 +92,6 @@ private slots:
|
||||
|
||||
signals:
|
||||
void sigQuit();
|
||||
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -49,47 +49,45 @@
|
||||
<translation>取消</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="198"/>
|
||||
<source>%1Fullscreen Mode</source>
|
||||
<translation>%1全屏模式</translation>
|
||||
<translation type="vanished">%1全屏模式</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="208"/>
|
||||
<source>%1Windowed Mode</source>
|
||||
<translation>%1窗口模式</translation>
|
||||
<translation type="vanished">%1窗口模式</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="250"/>
|
||||
<location filename="../mainwindow.cpp" line="265"/>
|
||||
<source>Save As</source>
|
||||
<translation>另存为</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="336"/>
|
||||
<location filename="../mainwindow.cpp" line="320"/>
|
||||
<source>%1Start downloading %2</source>
|
||||
<translation>%1开始下载 %2</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="349"/>
|
||||
<location filename="../mainwindow.cpp" line="331"/>
|
||||
<source>%1Wait for previous download to complete!</source>
|
||||
<translation>%1请等待上一个下载任务完成!</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="371"/>
|
||||
<location filename="../mainwindow.cpp" line="353"/>
|
||||
<source>Open</source>
|
||||
<translation>打开</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="375"/>
|
||||
<location filename="../mainwindow.cpp" line="357"/>
|
||||
<source>download finished.</source>
|
||||
<translation>下载完成。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="375"/>
|
||||
<location filename="../mainwindow.cpp" line="357"/>
|
||||
<source>Show in file manager?</source>
|
||||
<translation>是否在文件管理器中显示?</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="413"/>
|
||||
<location filename="../mainwindow.cpp" line="394"/>
|
||||
<source>%1Download canceled!</source>
|
||||
<translation>%1下载取消!</translation>
|
||||
</message>
|
||||
@ -117,77 +115,77 @@
|
||||
<translation>描述:%1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="61"/>
|
||||
<location filename="../main.cpp" line="62"/>
|
||||
<source>Enable CommandLineParser. Default is false.</source>
|
||||
<translation>启用参数解析方式。默认顺序解析方式。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="65"/>
|
||||
<location filename="../main.cpp" line="67"/>
|
||||
<source>The Title of Application. Default is %1.</source>
|
||||
<translation>设置程序的运行标题。默认是 %1。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="71"/>
|
||||
<location filename="../main.cpp" line="74"/>
|
||||
<source>The target URL. Default is Blank.</source>
|
||||
<translation>设置要打开的目标 URL。默认是空。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="77"/>
|
||||
<location filename="../main.cpp" line="81"/>
|
||||
<source>The Width of Application. Default is %1.</source>
|
||||
<translation>设置应用的窗口宽度。默认是 %1。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="83"/>
|
||||
<location filename="../main.cpp" line="88"/>
|
||||
<source>The Height of Application. Default is %1.</source>
|
||||
<translation>设置应用的窗口高度。默认是 %1。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="89"/>
|
||||
<location filename="../main.cpp" line="95"/>
|
||||
<source>Enable Tray Icon. Default is false.</source>
|
||||
<translation>启用托盘图标。默认不启用。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="93"/>
|
||||
<location filename="../main.cpp" line="99"/>
|
||||
<source>Run in Fullscreen Mode. Default is false.</source>
|
||||
<translation>以全屏模式运行。默认关闭该功能。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="97"/>
|
||||
<location filename="../main.cpp" line="103"/>
|
||||
<source>Fix Window Size. Default is false.</source>
|
||||
<translation>固定窗口大小。默认关闭该功能。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="101"/>
|
||||
<location filename="../main.cpp" line="107"/>
|
||||
<source>Hide Control Buttons. Default is false.</source>
|
||||
<translation>隐藏控制按钮。默认关闭该此功能。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="105"/>
|
||||
<location filename="../main.cpp" line="112"/>
|
||||
<source>The ICON of Application.</source>
|
||||
<translation>设置应用的图标。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="111"/>
|
||||
<location filename="../main.cpp" line="119"/>
|
||||
<source>The Description of Application.</source>
|
||||
<translation>设置应用的描述信息。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="117"/>
|
||||
<location filename="../main.cpp" line="126"/>
|
||||
<source>The Configuration file of Application.</source>
|
||||
<translation>设置应用的配置文件。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="123"/>
|
||||
<location filename="../main.cpp" line="133"/>
|
||||
<source>The root path of the program web service.</source>
|
||||
<translation>设置内置 WebServer 的根路径。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="130"/>
|
||||
<location filename="../main.cpp" line="140"/>
|
||||
<source>The port number of the program web service.</source>
|
||||
<translation>设置内置 WebServer 的监听端口号。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="137"/>
|
||||
<location filename="../main.cpp" line="148"/>
|
||||
<source>The ssl port number of the program web service.</source>
|
||||
<translation>设置内置 WebServer 的 SSL 协议的监听端口号。</translation>
|
||||
</message>
|
||||
|
@ -14,14 +14,13 @@ Widget::Widget(QString szUrl, QWidget *parent)
|
||||
m_webEngineView->setObjectName(QStringLiteral("webEngineView"));
|
||||
m_webEngineView->setEnabled(true);
|
||||
m_webEngineView->setAutoFillBackground(false);
|
||||
m_webEngineView->setZoomFactor(1);
|
||||
m_webEngineView->setZoomFactor(1.0);
|
||||
|
||||
QWebEnginePage *page = new QWebEnginePage;
|
||||
m_webEngineView->setPage(page);
|
||||
|
||||
m_webEngineView->setUrl(QUrl(nullptr));
|
||||
if (!m_szUrl.isEmpty())
|
||||
{
|
||||
if (!m_szUrl.isEmpty()) {
|
||||
m_webEngineView->setUrl(QUrl(m_szUrl));
|
||||
}
|
||||
|
||||
@ -56,8 +55,7 @@ void Widget::refresh()
|
||||
void Widget::clearLayout(QLayout *layout)
|
||||
{
|
||||
QLayoutItem *item;
|
||||
while ((item = layout->takeAt(0)) != nullptr)
|
||||
{
|
||||
while ((item = layout->takeAt(0)) != nullptr) {
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user