Skip to content
This repository has been archived by the owner on Oct 20, 2021. It is now read-only.

Commit

Permalink
测试多语言功能通过
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuzhiqian committed Jul 28, 2017
1 parent 2ef4ffc commit 2361648
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 31 deletions.
37 changes: 37 additions & 0 deletions canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QDateTime>

#include "operateSet.h"
#include <QTranslator>

/*
* Author:qiuzhiqian
Expand All @@ -32,6 +33,14 @@ Canvas::Canvas(QWidget *parent) : QWidget(parent)
clipboard = QApplication::clipboard(); //获取系统剪贴板指针

setMouseTracking(true); //鼠标移动捕捉

// QTranslator translator;
// bool sta=translator.load("zh_cn.qm");
// QApplication::installTranslator(&translator);

// refrashToolBar();

// qDebug()<<sta;
}

void Canvas::mousePressEvent(QMouseEvent *event)
Expand Down Expand Up @@ -411,6 +420,13 @@ void Canvas::hideToolBar() //掩藏工具条
toolbar->setVisible(false);
}

void Canvas::refrashToolBar()
{
btn_cancel->setText(tr("Quit"));
btn_saveClipboard->setText(tr("Copy"));
btn_saveFile->setText(tr("Save"));
}

void Canvas::slt_saveFile()
{
shootScreen(shotArea);
Expand Down Expand Up @@ -483,3 +499,24 @@ QRectF Canvas::getRectF(QPointF p1, QPointF p2)
QRectF rect(ps,pe);
return rect;
}

void Canvas::changeLanguage(QString lan)
{
QTranslator translator;
bool sta=false;

if(lan=="zh_cn") //简体中文
{
sta=translator.load("zh_cn.qm");
}
else if(lan=="en")
{
sta=translator.load("en.qm");
}

if(sta)
{
QApplication::installTranslator(&translator);
refrashToolBar(); //刷新自定义语言翻译
}
}
3 changes: 3 additions & 0 deletions canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ class Canvas : public QWidget
void initToolBar();
void showToolBar();
void hideToolBar();
void refrashToolBar();

QRectF getRectF(QPointF p1,QPointF p2); //通过两个坐标点生成矩形

void changeLanguage(QString lan);

signals:

public slots:
Expand Down
Binary file added doc/1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 15 additions & 12 deletions en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,30 @@
<context>
<name>Canvas</name>
<message>
<location filename="canvas.cpp" line="359"/>
<location filename="canvas.cpp" line="368"/>
<location filename="canvas.cpp" line="425"/>
<source>Quit</source>
<translation>Quit</translation>
</message>
<message>
<location filename="canvas.cpp" line="360"/>
<location filename="canvas.cpp" line="369"/>
<location filename="canvas.cpp" line="426"/>
<source>Copy</source>
<translation>Copy</translation>
</message>
<message>
<location filename="canvas.cpp" line="361"/>
<location filename="canvas.cpp" line="370"/>
<location filename="canvas.cpp" line="427"/>
<source>Save</source>
<translation>Save</translation>
</message>
<message>
<location filename="canvas.cpp" line="424"/>
<location filename="canvas.cpp" line="440"/>
<source>Save File</source>
<translation>Save File</translation>
</message>
<message>
<location filename="canvas.cpp" line="426"/>
<location filename="canvas.cpp" line="442"/>
<source>JPEG File (*.jpg)</source>
<translation>JPEG File (*.jpg)</translation>
</message>
Expand All @@ -49,9 +52,9 @@
<message>
<location filename="screenshottool.ui" line="36"/>
<location filename="screenshottool.cpp" line="59"/>
<location filename="screenshottool.cpp" line="108"/>
<location filename="screenshottool.cpp" line="444"/>
<location filename="screenshottool.cpp" line="445"/>
<location filename="screenshottool.cpp" line="128"/>
<location filename="screenshottool.cpp" line="472"/>
<location filename="screenshottool.cpp" line="473"/>
<source>Setting</source>
<translation>Setting</translation>
</message>
Expand All @@ -74,14 +77,14 @@
<translation type="vanished">中文</translation>
</message>
<message>
<location filename="screenshottool.cpp" line="109"/>
<location filename="screenshottool.cpp" line="446"/>
<location filename="screenshottool.cpp" line="129"/>
<location filename="screenshottool.cpp" line="474"/>
<source>About</source>
<translation>About</translation>
</message>
<message>
<location filename="screenshottool.cpp" line="110"/>
<location filename="screenshottool.cpp" line="447"/>
<location filename="screenshottool.cpp" line="130"/>
<location filename="screenshottool.cpp" line="475"/>
<source>Quit</source>
<translation>Quit</translation>
</message>
Expand Down
4 changes: 0 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,5 @@ int main(int argc, char *argv[])

a.installNativeEventFilter(&w); //注册windows全局事件,用来启用全局热键

QTranslator translator;
bool sta=translator.load("cn.qm");
a.installTranslator(&translator);

return a.exec();
}
23 changes: 20 additions & 3 deletions screenshottool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ ScreenShotTool::ScreenShotTool(QWidget *parent) :

QString language=OperateSet::readSetting("Setting","Language","en").toString();
changeLanguage(language);
if(language=="en")
{
ui->comboBox->setCurrentIndex(0);
}
else
{
ui->comboBox->setCurrentIndex(1);
}

this->setFixedSize(this->size());
}
Expand All @@ -100,6 +108,15 @@ void ScreenShotTool::ss_start() //开始截屏
screenCanvas=new Canvas(0); //创建画布

screenCanvas->setbgPixmap(fullPixmap); //传递全屏背景图片

if(ui->comboBox->currentIndex()==0)
{
screenCanvas->changeLanguage("en");
}
else if(ui->comboBox->currentIndex()==1)
{
screenCanvas->changeLanguage("zh_cn");
}
}

void ScreenShotTool::initTray() //初始化托盘
Expand Down Expand Up @@ -415,14 +432,14 @@ void ScreenShotTool::slt_language_set(int index)

void ScreenShotTool::setAutoRun(bool sta)
{
QSettings *reg=new QSettings("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",QSettings::NativeFormat);
QSettings *reg=new QSettings("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",QSettings::NativeFormat);
if(sta == true)
{
reg->setValue("app",QApplication::applicationFilePath());
reg->setValue("ScreenShotTool",QApplication::applicationFilePath());
}
else
{
reg->setValue("app","");
reg->remove("ScreenShotTool");
}
}

Expand Down
27 changes: 15 additions & 12 deletions zh_cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,30 @@
<context>
<name>Canvas</name>
<message>
<location filename="canvas.cpp" line="359"/>
<location filename="canvas.cpp" line="368"/>
<location filename="canvas.cpp" line="425"/>
<source>Quit</source>
<translation>退出</translation>
</message>
<message>
<location filename="canvas.cpp" line="360"/>
<location filename="canvas.cpp" line="369"/>
<location filename="canvas.cpp" line="426"/>
<source>Copy</source>
<translation>复制</translation>
</message>
<message>
<location filename="canvas.cpp" line="361"/>
<location filename="canvas.cpp" line="370"/>
<location filename="canvas.cpp" line="427"/>
<source>Save</source>
<translation>保存</translation>
</message>
<message>
<location filename="canvas.cpp" line="424"/>
<location filename="canvas.cpp" line="440"/>
<source>Save File</source>
<translation>保存文件</translation>
</message>
<message>
<location filename="canvas.cpp" line="426"/>
<location filename="canvas.cpp" line="442"/>
<source>JPEG File (*.jpg)</source>
<translation>JPEG文件 (*.jpg)</translation>
</message>
Expand All @@ -49,9 +52,9 @@
<message>
<location filename="screenshottool.ui" line="36"/>
<location filename="screenshottool.cpp" line="59"/>
<location filename="screenshottool.cpp" line="108"/>
<location filename="screenshottool.cpp" line="444"/>
<location filename="screenshottool.cpp" line="445"/>
<location filename="screenshottool.cpp" line="128"/>
<location filename="screenshottool.cpp" line="472"/>
<location filename="screenshottool.cpp" line="473"/>
<source>Setting</source>
<translation>设置</translation>
</message>
Expand All @@ -74,14 +77,14 @@
<translation type="vanished">中文</translation>
</message>
<message>
<location filename="screenshottool.cpp" line="109"/>
<location filename="screenshottool.cpp" line="446"/>
<location filename="screenshottool.cpp" line="129"/>
<location filename="screenshottool.cpp" line="474"/>
<source>About</source>
<translation>关于</translation>
</message>
<message>
<location filename="screenshottool.cpp" line="110"/>
<location filename="screenshottool.cpp" line="447"/>
<location filename="screenshottool.cpp" line="130"/>
<location filename="screenshottool.cpp" line="475"/>
<source>Quit</source>
<translation>退出</translation>
</message>
Expand Down

0 comments on commit 2361648

Please sign in to comment.