-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
executable file
·166 lines (131 loc) · 4.43 KB
/
mainwindow.cpp
File metadata and controls
executable file
·166 lines (131 loc) · 4.43 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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QFileInfo>
#include <QDir>
#include <QProcess>
#include <QMessageBox>
#include <QDesktopWidget>
#include <QPixmap>
#include <QUrl>
#include <QDesktopServices>
#include "extractthread.h"
#include "framedialog.h"
MainWindow::MainWindow(QWidget *parent, QString filename) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->frameList->setIconSize(QSize(256,256));
video = new QVideoFile();
fd = new FrameDialog();
fth = new FramesThread();
eth = new ExtractThread();
connect(eth, SIGNAL(getOnePreviewImage(QImage,int)), this, SLOT(addPreviewImageToList(QImage,int)));
connect(eth, SIGNAL(finished()),this,SLOT(extractFinished()));
connect(ui->frameList,SIGNAL(itemActivated(QListWidgetItem*)),this,SLOT(showFrameDialog(QListWidgetItem*)));
connect(fth,SIGNAL(getAllFrames(QList<QImage>)),fd,SLOT(addAllFramesToList(QList<QImage>)));
//connect(fth,SIGNAL(finished()),fd,SLOT(gotframe()));
ui->filepath->setText(filename);
QFileInfo *fi = new QFileInfo(filename);
ui->savepath->setText(fi->filePath().remove("."+fi->suffix()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_loadBtn_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Video"), QDir::homePath(),"");
ui->filepath->setText(fileName);
QFileInfo *fi = new QFileInfo(fileName);
ui->savepath->setText(fi->filePath().remove("."+fi->suffix()));
}
void MainWindow::on_saveBtn_clicked()
{
QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
QDir::homePath(),
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
ui->savepath->setText(dir);
}
void MainWindow::on_startBtn_clicked()
{
ui->frameList->clear();
QString filepath = ui->filepath->text();
QString savepath = ui->savepath->text();
int step = ui->timestep->value();
video->openFile(filepath);
video->setSavePath(savepath);
video->setTimeStep(step);
if(filepath == "" || savepath == "") {
QMessageBox::warning(this,"Please choose video file","Please choose video file!",QMessageBox::Ok);
return;
}
ui->progressBar->setMaximum(video->getLength()/step+1);
QDir d;
d.mkdir(savepath);
enableUi(false);
QUrl url(QDir(savepath).absolutePath());
//QDesktopServices::openUrl(QUrl("file:///"+url.toString()));
QDesktopServices::openUrl(url);
/*#ifdef Q_WS_WIN
QProcess::startDetached("explorer.exe",QStringList(savepath.replace("/","\\")));
#else
QProcess::startDetached("pcmanfm",QStringList(savepath));
#endif*/
eth->setVideo(this->video);
eth->start();
}
void MainWindow::addPreviewImageToList(QImage img, int sec)
{
//update progress bar
int val = ui->progressBar->value()+1;
ui->progressBar->setValue(val);
if(img.isNull())
return;
QIcon icon = QIcon(QPixmap::fromImage(img));
QListWidgetItem *item = new QListWidgetItem(ui->frameList);
item->setIcon(icon);
item->setText(QString("%1").arg(sec));
ui->frameList->addItem(item);
}
void MainWindow::extractFinished()
{
video->close();
enableUi(true);
}
void MainWindow::enableUi(bool isenable)
{
ui->filepath->setEnabled(isenable);
ui->savepath->setEnabled(isenable);
ui->loadBtn->setEnabled(isenable);
ui->saveBtn->setEnabled(isenable);
ui->startBtn->setEnabled(isenable);
ui->timestep->setEnabled(isenable);
if(isenable){
ui->progressBar->setValue(0);
ui->progressBar->setMaximum(100);
}
}
void MainWindow::showFrameDialog(QListWidgetItem * item)
{
QVideoFile *video = new QVideoFile();
QString filepath = ui->filepath->text();
QString savepath = ui->savepath->text();
int step = ui->timestep->value();
video->openFile(filepath);
video->setSavePath(savepath);
video->setTimeStep(step);
fth->setVideo(video);
fth->setStartTime(item->text().toInt());
fth->start();
fd->setVideo(video);
fd->setWindowTitle(
" All frames of Seconds " + item->text()+
" to " + QString("%1").arg(item->text().toInt()+video->getTimeStep()));
fd->setModal(true);
fd->startAnimation();
fd->showMaximized();
}