-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrecentfilesdialog.cpp
More file actions
84 lines (71 loc) · 2.3 KB
/
recentfilesdialog.cpp
File metadata and controls
84 lines (71 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
#include "recentfilesdialog.h"
RecentFilesDialog::RecentFilesDialog(QWidget*parent, QListWidget * listWidget):QDialog(parent)
{
listWidget->setParent(this);
layout = new QVBoxLayout(this);
this->setWindowFlags(Qt::FramelessWindowHint |Qt::ToolTip);
this->listWidget = listWidget;
layout->addWidget(listWidget);
listWidget->setSelectionMode(QAbstractItemView::SingleSelection);
}
void RecentFilesDialog::keyPressEvent(QKeyEvent *event)
{
if(event->key() == Qt::Key_Tab){
QListWidgetItem *item;
int row = listWidget->currentRow();
if(++row < listWidget->count()){
item = listWidget->item(row);
}else{
item = listWidget->item(0);
}
listWidget->setCurrentItem(item);
currentPath = item->text();
}
QDialog::keyPressEvent(event);
}
void RecentFilesDialog::show()
{
QDialog::show();
listWidget->clearSelection();
listWidget->setFocusPolicy(Qt::StrongFocus);
if(listWidget->count() ==0){
}else if(listWidget->count()==1){
listWidget->setCurrentRow(0,QItemSelectionModel::Select);
}else{
listWidget->setCurrentRow(1,QItemSelectionModel::Select);
}
listWidget->activateWindow();
listWidget->setFocus();
}
const QString RecentFilesDialog::getCurrentRelativeFile() const
{
if(listWidget->count() ==0){
return "";
}
return listWidget->currentItem()->text();
}
void RecentFilesDialog::updateRecentFileHandle(const QString &relativePath)
{
QListWidgetItem *newItem = new QListWidgetItem;
QFileIconProvider iconProvider;
newItem->setIcon(iconProvider.icon(QFileIconProvider::File));
newItem->setText(relativePath);
for(int i = 0; i < listWidget->count(); ++i) {
QListWidgetItem *item = listWidget->item(i);
if(item->text() == relativePath){
delete listWidget->takeItem(i);
}
}
listWidget->clearSelection();
listWidget->insertItem(0,newItem);
listWidget->setCurrentRow(0,QItemSelectionModel::Select);
}
void RecentFilesDialog::removeRecentDeletedFileHandle(const QString &relativePath)
{
for(int i = 0; i < listWidget->count(); ++i) {
QListWidgetItem *item = listWidget->item(i);
if(item->text() == relativePath){
delete listWidget->takeItem(i);
}
}
}