-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFilesAndBmap.h
135 lines (122 loc) · 4 KB
/
FilesAndBmap.h
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
#ifndef FILESANDBMAP_H
#define FILESANDBMAP_H
#include "BmapOutput.h"
#include "ButtonStack.h"
#include <QHeaderView>
#include <QScroller>
#include <QTreeView>
#include <QFileSystemModel>
#include <QDebug>
class FilesAndBmap : public QWidget {
QStackedLayout* layout;
BmapOutput* bmapOutput;
QFileSystemModel *model;
QTreeView *tree;
QString path;
QString blockDevice;
ButtonStack* bStack;
QStringList* filters;
public:
FilesAndBmap(const QString& _path, ButtonStack* _bStack) : QWidget(){
path = _path;
bStack = _bStack;
bmapOutput = new BmapOutput();
model = new QFileSystemModel();
model->setRootPath(path);
model->setFilter(QDir::NoDotAndDotDot | QDir::Files | QDir::AllDirs);
filters = new QStringList({"*"});
model->setNameFilters(*filters);
model->setNameFilterDisables(false);
tree = new QTreeView();
tree->setModel(model);
tree->setRootIndex(model->index(path));
tree->setColumnHidden(1,1);
tree->setColumnHidden(2,1);
tree->setColumnHidden(3,1);
tree->setStyleSheet("font-size: 40px;");
tree->setFixedHeight(280);
tree->resizeColumnToContents(0);
tree->setHeaderHidden(1);
//tree->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
tree->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
tree->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
tree->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
tree->header()->setStretchLastSection(false);
//tree->setAutoScroll(true);
tree->setExpandsOnDoubleClick(true);
QScroller::grabGesture(tree, QScroller::LeftMouseButtonGesture);
tree->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
tree->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
layout = new QStackedLayout();
layout->addWidget(tree);
layout->addWidget(bmapOutput);
setLayout(layout);
}
~FilesAndBmap(){
delete layout;
delete bmapOutput;
delete model;
delete filters;
}
void clearFilter(){
delete filters;
filters = new QStringList({"*.img", "*.wic.*"});
model->setNameFilters(*filters);
model->setNameFilterDisables(false);
}
public slots:
void flash(){
qInfo(blockDevice.toStdString().c_str());
if (blockDevice.isNull()) {
return;
}
layout->setCurrentWidget(bmapOutput);
bmapOutput->flash(model->filePath(tree->selectionModel()->selection().at(0).indexes().at(0)), blockDevice, bStack);
bStack->displayBack();
}
void back(){
layout->setCurrentWidget(tree);
bStack->displayFlash();
}
void setBlockDevice(const QString &path) {
blockDevice = path;
qInfo(blockDevice.toStdString().c_str());
}
void filterWic(bool checked){
if(checked){
filters->removeIf([](QString x){
return x == QString("*");
});
filters->append(QString("*.wic.*"));
}else{
filters->removeIf([](QString x){
return x == QString("*.wic.*");
});
}
if(!filters->length()){
delete filters;
filters = new QStringList({"*"});
}
model->setNameFilters(*filters);
model->setNameFilterDisables(false);
}
void filterImg(bool checked){
if(checked){
filters->removeIf([](QString x){
return x == QString("*");
});
filters->append(QString("*.img"));
}else{
filters->removeIf([](QString x){
return x == QString("*.img");
});
}
if(!filters->length()){
delete filters;
filters = new QStringList({"*"});
}
model->setNameFilters(*filters);
model->setNameFilterDisables(false);
}
};
#endif // FILESANDBMAP_H