-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathwidget.cpp
133 lines (117 loc) · 3.49 KB
/
widget.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "widget.h"
#include "ui_widget.h"
#include <QMouseEvent>
#include <qdebug.h>
#include <QFileDialog>
#include <QMessageBox>
#include <qcryptographichash.h>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint);
this->setWindowTitle(ui->label_title->text());
this->setWindowIcon(QIcon(":/new/prefix1/image/Safe.ico"));
ui->widget_title->installEventFilter(this);
m_pointStart = QPoint(0, 0);
m_fileEncryption = new FileEncryption();
m_thread = new QThread();
m_fileEncryption->moveToThread(m_thread);
m_thread->start();
ui->comboBox_Padding->setCurrentIndex(2);
connect(m_fileEncryption, &FileEncryption::showLog, this, &Widget::on_showLog);
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_but_min_clicked()
{
this->showMinimized();
}
void Widget::on_but_close_clicked()
{
this->close();
}
/**
* @brief 鼠标移动窗口
* @param watched
* @param event
* @return
*/
bool Widget::eventFilter(QObject *watched, QEvent *event)
{
if(watched == ui->widget_title)
{
QMouseEvent* e = static_cast<QMouseEvent*>(event);
switch (e->type())
{
case QEvent::MouseButtonPress:
{
if(e->button() == Qt::LeftButton)
{
m_pointStart = e->globalPos() - this->geometry().topLeft();
break;
}
}
case QEvent::MouseMove:
{
if(m_pointStart != QPoint(0, 0))
{
this->move(e->globalPos() - m_pointStart);
}
break;
}
case QEvent::MouseButtonRelease:
{
m_pointStart = QPoint(0, 0);
break;
}
default:
break;
}
}
return QWidget::eventFilter(watched, event);
}
void Widget::on_but_in_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this, "选择输入文件", "./", "输入文件(*)");
if(!fileName.isEmpty())
{
ui->lineEdit_in->setText(fileName);
QFileInfo info(fileName);
QString name = info.fileName();
QString path = info.canonicalPath();
ui->lineEdit_out->setText(path + "/out_" + name);
}
}
void Widget::on_but_out_clicked()
{
QString fileName = QFileDialog::getSaveFileName(this, "选择输出文件路径", ui->lineEdit_out->text(), "输出文件(*)");
if(!fileName.isEmpty())
{
ui->lineEdit_out->setText(fileName);
}
}
void Widget::on_but_start_clicked()
{
m_fileEncryption->setFile(ui->lineEdit_in->text(), ui->lineEdit_out->text());
m_fileEncryption->setEncryption(!ui->radio_de->isChecked());
QByteArray arrkey(ui->lineEdit_key->text().trimmed().toUtf8());
if(arrkey.isEmpty())
{
QMessageBox::about(this, "注意!", "未输入密钥。");
return;
}
arrkey = QCryptographicHash::hash(arrkey, QCryptographicHash::Md5).toHex(); // 使用md5适配所有长度的密码,否则如果密码过短会导致解密失败
m_fileEncryption->setKey(arrkey);
m_fileEncryption->setAESParameter((QAESEncryption::Aes)ui->comboBox_len->currentIndex(),
(QAESEncryption::Mode)ui->comboBox_mode->currentIndex(),
(QAESEncryption::Padding)ui->comboBox_Padding->currentIndex());
emit m_fileEncryption->start();
}
void Widget::on_showLog(QString log)
{
ui->textEdit_log->append(log);
}