-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileinfowidget.cpp
74 lines (66 loc) · 2.06 KB
/
fileinfowidget.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 "fileinfowidget.h"
#include "ui_fileinfowidget.h"
#include <qdebug.h>
#include <QFileInfo>
FileInfoWidget::FileInfoWidget(QFile *file, QWidget *parent):
QWidget(parent),
ui(new Ui::FileInfoWidget)
{
ui->setupUi(this);
this->file = file;
file->open(QIODevice::ReadOnly);
QFileInfo fileInfo(*file);
absolutePath = fileInfo.absoluteFilePath();
QString fileName = file->fileName();
qDebug() << fileName.lastIndexOf('/');
//获取文件名,去除路径
fileName = fileName.right(fileName.size() - fileName.lastIndexOf('/') - 1);
// const unsigned int maxSize = (1 << 16) * 512;
this->ui->lineEdit->setText(fileName);
double size_mb = file->size() * 1.0 / 1024 / 1024;
if(size_mb < 1.0){
this->ui->label->setText(tr("文件大小(KB)"));
this->ui->lineEdit_2->setText(QString::number(size_mb * 1024, 'f', 1));
}
else{
this->ui->lineEdit_2->setText(QString::number(file->size() * 1.0 / 1024 / 1024, 'f', 1));
}
this->ui->lineEdit->setReadOnly(true);
this->ui->lineEdit_2->setReadOnly(true);
file->close();
}
FileInfoWidget::FileInfoWidget(QString fileName, QString fileDes, QWidget *parent):
QWidget(parent),
ui(new Ui::FileInfoWidget)
{
ui->setupUi(this);
this->ui->label->setText(tr("文件类型"));
this->ui->lineEdit->setText(fileName);
this->ui->lineEdit_2->setText(fileDes);
this->ui->lineEdit->setReadOnly(true);
this->ui->lineEdit_2->setReadOnly(true);
}
FileInfoWidget::~FileInfoWidget()
{
delete ui;
delete file;
}
void FileInfoWidget::setSelectRadio(bool checked){
if(ui->radioButton->isChecked() != checked){
ui->radioButton->setChecked(checked);
}
}
bool FileInfoWidget::getChecked()const{
return ui->radioButton->isChecked();
}
QString FileInfoWidget::getFileName()const
{
return this->ui->lineEdit->text();
}
QString FileInfoWidget::getFileAbsolutePath()const{
return this->absolutePath;
}
void FileInfoWidget::on_radioButton_toggled(bool checked)
{
emit(selectRadioChecked(checked, absolutePath));
}