-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
73 lines (63 loc) · 1.98 KB
/
MainWindow.cpp
File metadata and controls
73 lines (63 loc) · 1.98 KB
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 "MainWindow.h"
#include "ui_MainWindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_action_open_triggered()
{
this->filePath = QFileDialog::getOpenFileName(this,"图片","","打开图片(*.jpg;*.png)");
QPixmap qp(this->filePath);
ui->imglabel->setPixmap(qp.scaled(ui->imglabel->width(), ui->imglabel->height()));//显示图片
this->on_checkButton_clicked();
}
void MainWindow::dragEnterEvent(QDragEnterEvent* event)
{
QString ext = event->mimeData()->urls()[0].fileName().right(3).toLower();
if(!ext.compare("jpg") || !ext.compare("jpeg") || !ext.compare("png"))
{
event->acceptProposedAction();
}
else
{
event->ignore();
}
}
void MainWindow::dropEvent(QDropEvent* event)
{
this->filePath = event->mimeData()->urls()[0].toLocalFile();
QPixmap qp(this->filePath);
ui->imglabel->setPixmap(qp.scaled(ui->imglabel->width(), ui->imglabel->height()));//显示图片
this->on_checkButton_clicked();
}
void MainWindow::on_checkButton_clicked()
{
QMovie* movie = new QMovie("processing.gif");
ui->anslabel->setMovie(movie);
movie->start();
DetectThread *thread = new DetectThread();
thread->file = this->filePath;
connect(thread, SIGNAL(resultReady(QString,QString)), this, SLOT(slot_updatelabel(QString,QString)));
thread->start();
}
void MainWindow::slot_updatelabel(QString msg, QString file)
{
QPixmap qp(file);
ui->reslabel->setPixmap(qp.scaled(ui->reslabel->width(), ui->reslabel->height()));//显示图片
ui->anslabel->setText(msg);
}
void MainWindow::on_action_clear_triggered()
{
ui->anslabel->clear();
ui->anslabel->setText(QString("检测结果"));
ui->imglabel->clear();
ui->imglabel->setText(QString("拖拽至此"));
ui->reslabel->clear();
ui->reslabel->setText(QString("处理后效果"));
}