Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 2df8deb

Browse files
author
15dd
committed
ver1.1 第一版
1 parent 031483f commit 2df8deb

File tree

7 files changed

+118
-40
lines changed

7 files changed

+118
-40
lines changed

about.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
</font>
9797
</property>
9898
<property name="text">
99-
<string>Version 1.0</string>
99+
<string>Version 1.1</string>
100100
</property>
101101
</widget>
102102
</item>

aria2Launcher.cpp

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@ aria2Launcher::aria2Launcher(QWidget *parent)
77
ui->setupUi(this);
88

99
checkFile();//检测所需文件是否存在
10+
checkAria2Status();//检测是否已经有aria2c运行,可选择新建进程或kill已存在的进程再新建进程
1011
uiInitialize();//ui初始化
12+
showWindow();
1113
showHide();//根据设置决定是显示窗口还是启动到托盘
12-
checkAria2Status();//检测是否已经有aria2c运行,可选择新建进程或kill已存在的进程再新建进程
1314

14-
this->resize((this->width())+1,(this->height())+1);//界面刷新
15+
//this->resize((this->width())+1,(this->height())+1);//界面刷新
1516

1617
connect(ui->aboutqt, &QAction::triggered, [this]() {QMessageBox::aboutQt(this, tr("About Qt")); });//弹出qt版本
1718
connect(ui->aboutthis, &QAction::triggered, [this]() {aboutWin->exec(); });//弹出关于窗口
1819
connect(ui->set, &QAction::triggered, [this]() {settingWin->exec(); });//弹出设置窗口
1920
connect(ui->close, &QAction::triggered, [this]() {qApp->quit(); });
21+
22+
connect(settingWin->ui->radioButton_7, &QRadioButton::clicked, [this]() {ui->webui->setEnabled(true); });
23+
connect(settingWin->ui->radioButton_8, &QRadioButton::clicked, [this]() {ui->webui->setEnabled(false); showCmd(); ui->cmd->setChecked(true); });
24+
connect(ui->cmd, &QAction::triggered, this, &aria2Launcher::showCmd);
25+
connect(ui->webui, &QAction::triggered, this, &aria2Launcher::showWebui);
2026
}
2127

2228
aria2Launcher::~aria2Launcher()
@@ -28,6 +34,37 @@ aria2Launcher::~aria2Launcher()
2834
delete ui;
2935
}
3036

37+
void aria2Launcher::showWindow() {
38+
if (settingWin->ui->radioButton_7->isChecked()) {
39+
showWebui();
40+
}
41+
else {
42+
this->ui->webui->setEnabled(false);
43+
this->ui->cmd->setChecked(true);
44+
showCmd();
45+
}
46+
}
47+
48+
void aria2Launcher::showWebui() {
49+
centralWidget()->setParent(NULL); //在切换窗口时,centralwidget一定要先置空(即在函数的最前面)不然会有问题
50+
if (view != NULL) {
51+
delete view;
52+
view = NULL;
53+
}
54+
view = new QWebEngineView(this);
55+
view->setUrl(QUrl(QApplication::applicationDirPath() + "/yaaw/index.html"));
56+
setCentralWidget(view);
57+
}
58+
59+
void aria2Launcher::showCmd() {
60+
centralWidget()->setParent(NULL); //在切换窗口时,centralwidget一定要先置空(即在函数的最前面)不然会有问题
61+
if (view != NULL) {
62+
delete view;
63+
view = NULL;
64+
}
65+
setCentralWidget(aria2CmdWidget);
66+
}
67+
3168
void aria2Launcher::checkFile() { //检测所需文件是否存在
3269
//QFileInfo file1(QApplication::applicationDirPath() + "/aria2c.exe");
3370
QFileInfo file1("aria2c.exe");
@@ -78,8 +115,9 @@ void aria2Launcher::checkAria2Status() { //检测是否已经有aria2c运行,可
78115
}
79116

80117
void aria2Launcher::showHide() { //根据设置决定是显示窗口还是启动到托盘
81-
if (settingWin->sh == false) {
118+
if (settingWin->ui->radioButton_6->isChecked()) {
82119
this->show();
120+
this->resize((this->width()) + 1, (this->height()) + 1);//界面刷新
83121
}
84122
else {
85123
showWindowsMessage();
@@ -110,15 +148,9 @@ void aria2Launcher::uiInitialize() { //ui初始化
110148
connect(Close, &QAction::triggered, this, &aria2Launcher::quitApp);
111149
connect(trayIcon, &QSystemTrayIcon::activated, this, &aria2Launcher::on_activatedSysTrayIcon);
112150

113-
//设置打开webui按钮
114-
QPushButton* openWeb = new QPushButton(this);
115-
openWeb->setText("打开控制界面(Webui)");
116-
statusBar()->addPermanentWidget(openWeb);
117-
118-
connect(openWeb, &QPushButton::clicked, [this]() {
119-
QString path = "file:///" + QApplication::applicationDirPath() + "/yaaw/index.html";
120-
QDesktopServices::openUrl(QUrl(path,QUrl::TolerantMode));
121-
});
151+
QActionGroup* group = new QActionGroup(this);
152+
group->addAction(ui->cmd);
153+
group->addAction(ui->webui);
122154
}
123155

124156
void aria2Launcher::closeEvent(QCloseEvent* event) { //关闭事件
@@ -148,14 +180,15 @@ bool aria2Launcher::quitApp() { //退出询问
148180
}
149181

150182
void aria2Launcher::showWindowsMessage() {//提示程序已进入托盘
151-
if (settingWin->tn == true) {
183+
if (settingWin->ui->radioButton_3->isChecked()) {
152184
trayIcon->showMessage("Aria2 Launcher已最小化到托盘", "如果您希望不再看到这个提示,请前往设置关闭");
153185
}
154186
}
155187

156-
void aria2Launcher::showOrHide() {//显示主窗口或隐藏主窗口
188+
void aria2Launcher::showOrHide() {//显示主窗口或隐藏主窗口,托盘事件
157189
if (this->isHidden()) {
158-
this->showNormal();
190+
this->show();
191+
this->resize((this->width()) + 1, (this->height()) + 1);//界面刷新
159192
}
160193
else {
161194
showWindowsMessage();
@@ -185,8 +218,6 @@ void aria2Launcher::Start() { //启动aria2c.exe,并嵌入窗口中
185218
QWindow* aria2Cmd = QWindow::fromWinId(getProcessWId(pid)); //根据pid,将aria2c.exe的窗口嵌入至主窗口中
186219
aria2Cmd->setFlags(aria2Cmd->flags() | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
187220
aria2CmdWidget = QWidget::createWindowContainer(aria2Cmd);
188-
aria2CmdWidget->setParent(this);
189-
this->setCentralWidget(aria2CmdWidget);
190221
}
191222

192223
//寻找是否有已存在的aria2c.exe========================================================================

aria2Launcher.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <QSystemTrayIcon>
1515
#include <QCloseEvent>
1616
#include <QFileInfo>
17+
#include <QWebEngineView>
1718

1819
class aria2Launcher : public QMainWindow
1920
{
@@ -39,6 +40,7 @@ class aria2Launcher : public QMainWindow
3940
QWidget* aria2CmdWidget; //截获的aria2c.exe窗口
4041
QCloseEvent* event; //关闭事件
4142
QSystemTrayIcon* trayIcon; //托盘
43+
QWebEngineView* view = NULL;
4244
private:
4345
Ui::aria2LauncherClass* ui;
4446
about* aboutWin = new about(this); //关于窗口
@@ -48,6 +50,9 @@ private slots:
4850
void showOrHide(); //显示主窗口或隐藏主窗口
4951
void showWindowsMessage(); //通知横幅,提示程序已进入托盘
5052
void showHide(); //根据设置决定是显示窗口还是启动到托盘
53+
void showCmd();
54+
void showWebui();
55+
void showWindow();
5156
};
5257

5358

aria2Launcher.ui

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141
<addaction name="separator"/>
4242
<addaction name="close"/>
4343
</widget>
44+
<widget class="QMenu" name="menu">
45+
<property name="title">
46+
<string>窗口切换</string>
47+
</property>
48+
<addaction name="cmd"/>
49+
<addaction name="webui"/>
50+
</widget>
51+
<addaction name="menu"/>
4452
<addaction name="more"/>
4553
</widget>
4654
<widget class="QStatusBar" name="statusBar"/>
@@ -80,23 +88,23 @@
8088
<string>退出程序</string>
8189
</property>
8290
</action>
83-
<action name="CMD">
91+
<action name="cmd">
8492
<property name="checkable">
8593
<bool>true</bool>
8694
</property>
87-
<property name="checked">
88-
<bool>true</bool>
89-
</property>
9095
<property name="text">
91-
<string>CMD</string>
96+
<string>cmd</string>
9297
</property>
9398
</action>
94-
<action name="WebUI">
99+
<action name="webui">
95100
<property name="checkable">
96101
<bool>true</bool>
97102
</property>
103+
<property name="checked">
104+
<bool>true</bool>
105+
</property>
98106
<property name="text">
99-
<string>WebUI</string>
107+
<string>webui</string>
100108
</property>
101109
</action>
102110
</widget>

settingWindow.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ setting::setting(QWidget* parent) :
1818
settingInitialize();
1919
}
2020
else { //如果没有ini,即第一次打开程序,配置默认选项
21-
this->sh = false;
22-
this->tn = true;
2321
startWithWindowsDisabled();
2422
startHideDisabled();
2523
trayNoticeEnabled();
24+
showWebuiEnabled();
2625
}
2726

2827
connect(ui->radioButton, &QRadioButton::clicked, this, &setting::startWithWindowsEnabled);
@@ -31,6 +30,8 @@ setting::setting(QWidget* parent) :
3130
connect(ui->radioButton_6, &QRadioButton::clicked, this, &setting::startHideDisabled);
3231
connect(ui->radioButton_3, &QRadioButton::clicked, this, &setting::trayNoticeEnabled);
3332
connect(ui->radioButton_4, &QRadioButton::clicked, this, &setting::trayNoticeDisabled);
33+
connect(ui->radioButton_7, &QRadioButton::clicked, this, &setting::showWebuiEnabled);
34+
connect(ui->radioButton_8, &QRadioButton::clicked, this, &setting::showWebuiDisabled);
3435
}
3536
setting::~setting() {
3637
delete ui;
@@ -48,21 +49,25 @@ void setting::settingInitialize() { //读取数据,初始化单选项
4849
QVariant sh = iniSetting->value("setting/startHide").toString();
4950
if (sh.toBool() == true) {
5051
ui->radioButton_5->setChecked(true);
51-
this->sh = true;
5252
}
5353
else {
5454
ui->radioButton_6->setChecked(true);
55-
this->sh = false;
5655
}
5756

5857
QVariant tn = iniSetting->value("setting/trayNotice").toString();
5958
if (tn.toBool() == true) {
6059
ui->radioButton_3->setChecked(true);
61-
this->tn = true;
6260
}
6361
else {
6462
ui->radioButton_4->setChecked(true);
65-
this->tn = false;
63+
}
64+
65+
QVariant sw = iniSetting->value("setting/showWebui").toString();
66+
if (sw.toBool() == true) {
67+
ui->radioButton_7->setChecked(true);
68+
}
69+
else {
70+
ui->radioButton_8->setChecked(true);
6671
}
6772
}
6873

@@ -78,22 +83,26 @@ void setting::startWithWindowsDisabled() {
7883

7984
void setting::startHideEnabled() {
8085
iniSetting->setValue("setting/startHide","true");
81-
sh = true;
8286
}
8387

8488
void setting::startHideDisabled() {
8589
iniSetting->setValue("setting/startHide", "false");
86-
sh = false;
8790
}
8891

8992
void setting::trayNoticeEnabled() {
9093
iniSetting->setValue("setting/trayNotice", "true");
91-
tn = true;
9294
}
9395

9496
void setting::trayNoticeDisabled() {
9597
iniSetting->setValue("setting/trayNotice", "false");
96-
tn = false;
98+
}
99+
100+
void setting::showWebuiEnabled() {
101+
iniSetting->setValue("setting/showWebui", "true");
102+
}
103+
104+
void setting::showWebuiDisabled() {
105+
iniSetting->setValue("setting/showWebui", "false");
97106
}
98107

99108
//开机启动=============================================================================================

settingWindow.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ public slots:
2020
void startHideDisabled();
2121
void trayNoticeEnabled();
2222
void trayNoticeDisabled();
23+
void showWebuiEnabled();
24+
void showWebuiDisabled();
2325
public:
2426
QSettings* iniSetting;
25-
bool tn;
26-
bool sh;
27-
private:
2827
Ui::setting* ui;
2928
};

settingWindow.ui

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>305</width>
10-
<height>195</height>
9+
<width>337</width>
10+
<height>256</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -114,6 +114,32 @@
114114
</layout>
115115
</widget>
116116
</item>
117+
<item row="3" column="0">
118+
<widget class="QGroupBox" name="groupBox_4">
119+
<property name="title">
120+
<string>启用webui</string>
121+
</property>
122+
<layout class="QGridLayout" name="gridLayout_5">
123+
<item row="0" column="0">
124+
<widget class="QRadioButton" name="radioButton_7">
125+
<property name="text">
126+
<string>启用</string>
127+
</property>
128+
<property name="checked">
129+
<bool>true</bool>
130+
</property>
131+
</widget>
132+
</item>
133+
<item row="0" column="1">
134+
<widget class="QRadioButton" name="radioButton_8">
135+
<property name="text">
136+
<string>禁用</string>
137+
</property>
138+
</widget>
139+
</item>
140+
</layout>
141+
</widget>
142+
</item>
117143
</layout>
118144
</widget>
119145
<resources>

0 commit comments

Comments
 (0)