Skip to content

Commit

Permalink
改用tr
Browse files Browse the repository at this point in the history
  • Loading branch information
GengGode committed Aug 7, 2021
1 parent 73ed050 commit d9d1a0a
Show file tree
Hide file tree
Showing 12 changed files with 389 additions and 84 deletions.
21 changes: 11 additions & 10 deletions GenshinImpactNaturalLaw/GenshinImpactNaturalLaw.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "GenshinImpactNaturalLaw.h"
#include "GenshinImpactNaturalLaw.h"

GenshinImpactNaturalLaw::GenshinImpactNaturalLaw(QWidget *parent)
: QMainWindow(parent)
Expand All @@ -10,17 +10,18 @@ GenshinImpactNaturalLaw::GenshinImpactNaturalLaw(QWidget *parent)
uiConnectButtonLabel();
uiShowImage();


Tray = new QSystemTrayIcon(this);
Tray->setIcon(QIcon(QPixmap(":/icon/resource/icon/ICON.png")));
Tray->setToolTip(QString::fromUtf8("\345\244\251\347\220\206"));//天理
QString title = "天理";
QString text = "原神天理系统";
Tray->setToolTip(tr("Str_TianLi"));//天理
QString title = "天理";
QString text = "原神天理系统";
Tray->show();
connect(Tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(TrayMenuClickEvent(QSystemTrayIcon::ActivationReason)));

ShowMainAction = new QAction(QString::fromUtf8("\346\230\276\347\244\272\344\270\273\347\225\214\351\235\242"), this);//显示主界面
ShowMainAction = new QAction(tr("Str_ShowMainWidget"), this);//显示主界面
connect(ShowMainAction, SIGNAL(triggered()), this, SLOT(show()));
ExitAction = new QAction(QString::fromUtf8("\351\200\200\345\207\272"), this);//退出
ExitAction = new QAction(tr("Str_Exit"), this);//退出
connect(ExitAction, SIGNAL(triggered()), this, SLOT(close()));

TrayMenu = new QMenu(this);
Expand All @@ -34,7 +35,7 @@ GenshinImpactNaturalLaw::GenshinImpactNaturalLaw(QWidget *parent)
Shadow_LabelPage->setOffset(0.0);
ui.label_Page_Rect->setGraphicsEffect(Shadow_LabelPage);

setAttribute(Qt::WA_TranslucentBackground, true); // 背景透明
setAttribute(Qt::WA_TranslucentBackground, true); // 背景透明
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect;
shadow->setOffset(0, 0);
shadow->setColor(QColor(15, 15, 15, 50));
Expand Down Expand Up @@ -270,9 +271,9 @@ void GenshinImpactNaturalLaw::TrayMenuClickEvent(QSystemTrayIcon::ActivationReas
{
switch (reason)
{
case QSystemTrayIcon::Trigger://单击托盘图标
case QSystemTrayIcon::Trigger://单击托盘图标
break;
case QSystemTrayIcon::DoubleClick://双击托盘图标
case QSystemTrayIcon::DoubleClick://双击托盘图标
this->showNormal();
break;
default:
Expand Down Expand Up @@ -304,7 +305,7 @@ void GenshinImpactNaturalLaw::ShowTopMainWidget()

void GenshinImpactNaturalLaw::ReceiveUniqueKeyMsg()
{
//还原显示窗口
//还原显示窗口

this->show();

Expand Down
1 change: 1 addition & 0 deletions GenshinImpactNaturalLaw/GenshinImpactNaturalLaw.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QGraphicsDropShadowEffect>
#include <QDesktopServices>
#include <QTextCodec>
#include <QTranslator>
#include <QSystemTrayIcon>
#include <QDesktopServices>
#include <QAction>
Expand Down
7 changes: 4 additions & 3 deletions GenshinImpactNaturalLaw/GenshinImpactNaturalLaw.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@
<Link>
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
</Link>
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<ClCompile />
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration">
<ClCompile>
Expand Down Expand Up @@ -147,6 +145,9 @@
<ItemGroup>
<None Include="GenshinImpactNaturalLaw.pro" />
</ItemGroup>
<ItemGroup>
<QtTranslation Include="genshinimpactnaturallaw_zh.ts" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
<Import Project="$(QtMsBuild)\qt.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,9 @@
<ItemGroup>
<None Include="GenshinImpactNaturalLaw.pro" />
</ItemGroup>
<ItemGroup>
<QtTranslation Include="genshinimpactnaturallaw_zh.ts">
<Filter>Translation Files</Filter>
</QtTranslation>
</ItemGroup>
</Project>
16 changes: 8 additions & 8 deletions GenshinImpactNaturalLaw/QtWidgetsSetting.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "QtWidgetsSetting.h"
#include "QtWidgetsSetting.h"
//#pragma execution_character_set("utf-8")

QtWidgetsSetting::QtWidgetsSetting(QWidget *parent)
Expand Down Expand Up @@ -398,22 +398,22 @@ void QtWidgetsSetting::CheckOptions_CheckGameLauncher()
{
FileDialogPath = setting->launcher_install_path;
}
QString GameLauncherPath = QFileDialog::getExistingDirectory(this, "选择原神启动器所在目录", FileDialogPath, QFileDialog::ShowDirsOnly);
QString GameLauncherPath = QFileDialog::getExistingDirectory(this, "选择原神启动器所在目录", FileDialogPath, QFileDialog::ShowDirsOnly);

if (!GameLauncherPath.isEmpty())
{
QFileInfo file(GameLauncherPath+"/launcher.exe");
if (file.exists() == false)
{
emit ShowMessageBox();//未能找到游戏本体,请重新选择游戏本体路径
emit ShowMessageBox();//未能找到游戏本体,请重新选择游戏本体路径
return;
}
else
{
setting->launcher_install_path = GameLauncherPath;
if (!setting->tryGetGamePath())
{
emit ShowMessageBox();//未能找到游戏本体,请手动选择游戏本体路径
emit ShowMessageBox();//未能找到游戏本体,请手动选择游戏本体路径
return;
}
}
Expand All @@ -432,7 +432,7 @@ void QtWidgetsSetting::CheckOptions_CheckGame()
{
FileDialogPath = setting->game_install_path;
}
QString GamePath = QFileDialog::getOpenFileName(this, "选择原神所在目录", FileDialogPath, "应用程序 (*.exe);;");
QString GamePath = QFileDialog::getOpenFileName(this, "选择原神所在目录", FileDialogPath, "应用程序 (*.exe);;");
if (!GamePath.isEmpty())
{
setting->game_start_name = GamePath.section('/', -1);
Expand All @@ -453,22 +453,22 @@ void QtWidgetsSetting::CheckOptions_CheckModule()
{
FileDialogPath = setting->launcher_install_path;
}
QString GameLauncherPath = QFileDialog::getExistingDirectory(this, "选择原神启动器所在目录", FileDialogPath, QFileDialog::ShowDirsOnly);
QString GameLauncherPath = QFileDialog::getExistingDirectory(this, "选择原神启动器所在目录", FileDialogPath, QFileDialog::ShowDirsOnly);

if (!GameLauncherPath.isEmpty())
{
QFileInfo file(GameLauncherPath + "/launcher.exe");
if (file.exists() == false)
{
emit ShowMessageBox();//未能找到游戏本体,请重新选择游戏本体路径
emit ShowMessageBox();//未能找到游戏本体,请重新选择游戏本体路径
return;
}
else
{
setting->launcher_install_path = GameLauncherPath;
if (!setting->tryGetGamePath())
{
emit ShowMessageBox();//未能找到游戏本体,请手动选择游戏本体路径
emit ShowMessageBox();//未能找到游戏本体,请手动选择游戏本体路径
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion GenshinImpactNaturalLaw/QtWidgetsSetting.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class QtWidgetsSetting : public QWidget
QPoint m_Move;
bool leftBtnClk = false;

QString KeyString1 = "当前版本:";//QString::QStringLiteral("当前版本:");
QString KeyString1 = tr("Str_NowVer:");//QString::QStringLiteral("当前版本:");

QtWidgetsMessageBox *WidgetsMessageBox = nullptr;
QLabel *MainMaskLabel = nullptr;
Expand Down
56 changes: 29 additions & 27 deletions GenshinImpactNaturalLaw/QtWidgetsSetting.qrc
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
<RCC>
<qresource prefix="QtWidgetsSetting"/>
<qresource prefix="RadioButton">
<file>resource/QtWidgetsSetting/RadioButton/radiobutton_checked.png</file>
<file>resource/QtWidgetsSetting/RadioButton/radiobutton_checked_hover.png</file>
<file>resource/QtWidgetsSetting/RadioButton/radiobutton_checked_pressed.png</file>
<file>resource/QtWidgetsSetting/RadioButton/radiobutton_unchecked.png</file>
<file>resource/QtWidgetsSetting/RadioButton/radiobutton_unchecked_hover.png</file>
<file>resource/QtWidgetsSetting/RadioButton/radiobutton_unchecked_pressed.png</file>
</qresource>
<qresource prefix="CheckBox">
<file>resource/QtWidgetsSetting/CheckBox/checkbox_checked.png</file>
<file>resource/QtWidgetsSetting/CheckBox/checkbox_checked_hover.png</file>
<file>resource/QtWidgetsSetting/CheckBox/checkbox_checked_pressed.png</file>
<file>resource/QtWidgetsSetting/CheckBox/checkbox_unchecked.png</file>
<file>resource/QtWidgetsSetting/CheckBox/checkbox_unchecked_hover.png</file>
<file>resource/QtWidgetsSetting/CheckBox/checkbox_unchecked_pressed.png</file>
</qresource>
<qresource prefix="Exit">
<file>resource/QtWidgetsSetting/Exit/exit0.png</file>
<file>resource/QtWidgetsSetting/Exit/exit1.png</file>
</qresource>
<qresource prefix="UI">
<file>resource/QtWidgetsSetting/UI/title.png</file>
</qresource>
<qresource prefix="BackgroundImage">
<file>resource/QtWidgetsSetting/bg.png</file>
</qresource>
<qresource prefix="/QtWidgetsSetting">
<file>genshinimpactnaturallaw_zh.qm</file>
</qresource>
<qresource prefix="/RadioButton">
<file>resource/QtWidgetsSetting/RadioButton/radiobutton_checked.png</file>
<file>resource/QtWidgetsSetting/RadioButton/radiobutton_checked_hover.png</file>
<file>resource/QtWidgetsSetting/RadioButton/radiobutton_checked_pressed.png</file>
<file>resource/QtWidgetsSetting/RadioButton/radiobutton_unchecked.png</file>
<file>resource/QtWidgetsSetting/RadioButton/radiobutton_unchecked_hover.png</file>
<file>resource/QtWidgetsSetting/RadioButton/radiobutton_unchecked_pressed.png</file>
</qresource>
<qresource prefix="/CheckBox">
<file>resource/QtWidgetsSetting/CheckBox/checkbox_checked.png</file>
<file>resource/QtWidgetsSetting/CheckBox/checkbox_checked_hover.png</file>
<file>resource/QtWidgetsSetting/CheckBox/checkbox_checked_pressed.png</file>
<file>resource/QtWidgetsSetting/CheckBox/checkbox_unchecked.png</file>
<file>resource/QtWidgetsSetting/CheckBox/checkbox_unchecked_hover.png</file>
<file>resource/QtWidgetsSetting/CheckBox/checkbox_unchecked_pressed.png</file>
</qresource>
<qresource prefix="/Exit">
<file>resource/QtWidgetsSetting/Exit/exit0.png</file>
<file>resource/QtWidgetsSetting/Exit/exit1.png</file>
</qresource>
<qresource prefix="/UI">
<file>resource/QtWidgetsSetting/UI/title.png</file>
</qresource>
<qresource prefix="/BackgroundImage">
<file>resource/QtWidgetsSetting/bg.png</file>
</qresource>
</RCC>
10 changes: 5 additions & 5 deletions GenshinImpactNaturalLaw/UpdataModule.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "UpdataModule.h"
#include "UpdataModule.h"

UpdataModule::UpdataModule()
{
Expand Down Expand Up @@ -51,9 +51,9 @@ void UpdataModule::getFile()
allBits = downloadFile->size();

httpRequestAborted = false;
//尝试获取文件
//尝试获取文件
startRequest(downloadUrl);
//事件循环,防止在下载没完成前结束对象
//事件循环,防止在下载没完成前结束对象
}

void UpdataModule::startRequest(QUrl url)
Expand All @@ -67,7 +67,7 @@ void UpdataModule::startRequest(QUrl url)
req.setRawHeader("RANGE", tr("bytes=%1-").arg(allBits).toUtf8());//
}
downloadReply = downloadmanager.get(req);
//连接信号与槽
//连接信号与槽
if (downloadReply)
{
connect(downloadReply, SIGNAL(readyRead()), this, SLOT(downloadReadyRead()));
Expand Down Expand Up @@ -98,7 +98,7 @@ void UpdataModule::cancel()
}
void UpdataModule::downloadReadyRead()
{
//如果文件可以访问,下载
//如果文件可以访问,下载
if (downloadFile)
downloadFile->write(downloadReply->readAll());
FileBuff = FileBuff + QString(downloadReply->readAll());
Expand Down
60 changes: 30 additions & 30 deletions GenshinImpactNaturalLaw/UpdataModule.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <QDir>
#include <QFileInfo>
#include <QApplication>
Expand All @@ -20,65 +20,65 @@ class UpdataModule :public QObject
~UpdataModule();


// 设置要下载的url和文件名
// 设置要下载的url和文件名
void setData(QUrl url);
//开始下载
//开始下载
void getFile();
void startRequest(QUrl url);
//发生的错误代码
//发生的错误代码
//int lastError();
//返回是否有错误发生
//返回是否有错误发生
//bool errorValid();
//返回是否下载中
//返回是否下载中
//bool isRunning();
//返回是否下载完成
//返回是否下载完成
//bool isFinished();
//返回所下载文件的版本号
//返回所下载文件的版本号
QString getDownloadVersionCode();
//返回所下载文件的名字(带扩展名)
//返回所下载文件的名字(带扩展名)
//QString getFileName();
void cancel();
private:

//=====状态变量=====
bool bisFinished; //下载是否完成
bool bisRunning; //下载是否进行中
bool bisError; //是否有错误发生
int errorCode; //错误代码
int allBits = 0; //文件大小
//=====状态变量=====
bool bisFinished; //下载是否完成
bool bisRunning; //下载是否进行中
bool bisError; //是否有错误发生
int errorCode; //错误代码
int allBits = 0; //文件大小
bool httpRequestAborted;

//=====对象声明=====
//=====对象声明=====
VersionNumber version;

QString FileBuff;
QFile *downloadFile; //保存目标文件指针
QUrl downloadUrl; //下载地址Url
QString savePath; //文件存放路径
QString versionCode = ""; //所下载的文件版本号
QString fileName = ""; //所下载文件名
QNetworkReply *downloadReply; //网络应答指针
QNetworkAccessManager downloadmanager; //网络连接主类指针
QFile *downloadFile; //保存目标文件指针
QUrl downloadUrl; //下载地址Url
QString savePath; //文件存放路径
QString versionCode = ""; //所下载的文件版本号
QString fileName = ""; //所下载文件名
QNetworkReply *downloadReply; //网络应答指针
QNetworkAccessManager downloadmanager; //网络连接主类指针
signals:

//当错误发生时向外抛出错误信息
//当错误发生时向外抛出错误信息
void error(QNetworkReply::NetworkError);
//抛出下载进度(更新进度条)
//抛出下载进度(更新进度条)
void updateProgress(qint64 bytesSent, qint64 bytesTotal);
//下载结果 0成功 其他失败
//下载结果 0成功 其他失败
void downloadResult(int retCode);

void finish();

private slots:

//准备下载,读取数据
//准备下载,读取数据
void downloadReadyRead();
//下载完成
//下载完成
void downloadFinished();
//下载过程中发生错误
//下载过程中发生错误
void downloadError(QNetworkReply::NetworkError errorCode);
//下载过程进度条
//下载过程进度条
void downloadProgress(qint64 bytesSent, qint64 bytesTotal);
};

Binary file not shown.
Loading

0 comments on commit d9d1a0a

Please sign in to comment.