-
Notifications
You must be signed in to change notification settings - Fork 14
/
translate_page.cpp
73 lines (59 loc) · 1.89 KB
/
translate_page.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "translate_page.h"
#include <QLabel>
#include <QPushButton>
TranslatePage::TranslatePage(QWidget *parent)
: QWidget(parent),
api(new YoudaoAPI(this))
{
layout = new QVBoxLayout(this);
hLayout = new QHBoxLayout;
original = new QPlainTextEdit;
translator = new QPlainTextEdit;
QLabel *tips1 = new QLabel("原文");
QLabel *tips2 = new QLabel("译文");
tips1->setObjectName("TrLabel");
tips2->setObjectName("TrLabel");
original->setObjectName("TranslateEdit1");
translator->setObjectName("TranslateEdit2");
QPushButton *clearBtn = new QPushButton("清空");
QPushButton *trBtn = new QPushButton("翻译");
hLayout->addWidget(clearBtn);
hLayout->addWidget(trBtn);
trBtn->setFixedHeight(35);
trBtn->setObjectName("Button");
translator->setReadOnly(true);
layout->setMargin(25);
layout->addWidget(tips1);
layout->addWidget(original);
layout->addSpacing(10);
layout->addLayout(hLayout);
layout->addSpacing(10);
layout->addWidget(tips2);
layout->addWidget(translator);
connect(trBtn, SIGNAL(clicked()), this, SLOT(translateButtonClicked()));
connect(clearBtn, SIGNAL(clicked()), this, SLOT(clearButtonClicked()));
connect(api, SIGNAL(translatorFinished(QString)), this, SLOT(processingData(QString)));
}
void TranslatePage::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Return && (event->modifiers() & Qt::ControlModifier))
translateButtonClicked();
}
void TranslatePage::translateButtonClicked()
{
original->setFocus();
if (!original->toPlainText().isEmpty()) {
api->translator(original->toPlainText());
}else {
}
}
void TranslatePage::clearButtonClicked()
{
original->setFocus();
original->setPlainText("");
translator->setPlainText("");
}
void TranslatePage::processingData(QString text)
{
translator->setPlainText(text);
}