-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtfilesystemmodel.cpp
More file actions
90 lines (79 loc) · 2.3 KB
/
Copy pathtfilesystemmodel.cpp
File metadata and controls
90 lines (79 loc) · 2.3 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
#include "tfilesystemmodel.h"
#include "fileutil.h"
#include <QFileIconProvider>
TFileSystemModel::TFileSystemModel(QObject *parent)
: QFileSystemModel{parent}
{}
enum ColumnIndex{
ColName,
ColSize,
ColType,
ColModifiedTime,
ColCount
};
QVariant TFileSystemModel::data(const QModelIndex &index, int role) const
{
QFileInfo fileInfo(filePath(index));
if(role == Qt::ToolTipRole){
return QVariant(fileInfo.fileName());
}
if(role == Qt::DecorationRole && index.column() == 0){
if(!m_previewImage)
return m_iconProvider.icon(fileInfo);
if(FileUtil::isImage(fileInfo.absoluteFilePath())){
auto image = QImage(fileInfo.absoluteFilePath());
if(image.size().width()> image.size().height())
{
image = image.scaledToWidth(m_iconSize);
}else{
image = image.scaledToHeight(m_iconSize);
}
return image;
}
else{
return m_iconProvider.icon(fileInfo);
}
}
if(role == Qt::DisplayRole){
switch(index.column()){
case ColName:
return fileInfo.fileName();
break;
case ColSize:
return FileUtil::sizeFormat(fileInfo.size());
break;
case ColType:
return QFileSystemModel::data(index,role);
break;
case ColModifiedTime:
return FileUtil::timeStr(fileInfo.lastModified());
break;
}
}
return QFileSystemModel::data(index,role);
}
void TFileSystemModel::setPreviewable(bool bPreView, int iconSize)
{
m_previewImage = bPreView;
m_iconSize = iconSize;
}
QVariant TFileSystemModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(role == Qt::DisplayRole && orientation == Qt::Horizontal){
switch(section){
case ColName:
return tr("文件名");
break;
case ColModifiedTime:
return tr("修改时间");
break;
case ColSize:
return tr("大小");
break;
case ColType:
return tr("文件类型");
break;
}
}
return QFileSystemModel::headerData(section,orientation,role);
}