Repository navigation
Expand file tree
/
Copy pathCopyMoveToDialog.cpp
More file actions
168 lines (141 loc) · 6.24 KB
/
Copy pathCopyMoveToDialog.cpp
File metadata and controls
168 lines (141 loc) · 6.24 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
166
167
168
/*
* Copyright (C) 2013-2014 Ofer Kashayov - oferkv@live.com
* This file is part of Phototonic Image Viewer.
*
* Phototonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phototonic is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Phototonic. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QApplication>
#include <QBoxLayout>
#include <QFileDialog>
#include <QHeaderView>
#include <QLabel>
#include <QPushButton>
#include <QStandardItemModel>
#include <QTableView>
#include "CopyMoveToDialog.h"
#include "Settings.h"
#if __cplusplus >= 202002L
#define _LCD_ =,this
#else
#define _LCD_ =
#endif
static QStringList gs_tmpPaths;
void CopyMoveToDialog::savePaths() {
Settings::bookmarkPaths.clear();
for (int i = 0; i < pathsTableModel->rowCount(); ++i) {
if (QStandardItem *bookmark = pathsTableModel->item(i))
Settings::bookmarkPaths.insert(bookmark->text());
}
}
static QIcon &folderIcon() {
static QIcon icon = QIcon::fromTheme("folder");
return icon;
}
void CopyMoveToDialog::add() {
QString dirName = QFileDialog::getExistingDirectory(this, tr("Choose Directory"), currentPath,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (dirName.isEmpty()) {
return;
}
if (!gs_tmpPaths.contains(dirName))
gs_tmpPaths << dirName;
QStandardItem *item = new QStandardItem(folderIcon(), dirName);
pathsTableModel->insertRow(pathsTableModel->rowCount(), item);
pathsTable->selectionModel()->clearSelection();
pathsTable->selectionModel()->select(pathsTableModel->index(pathsTableModel->rowCount() - 1, 0),
QItemSelectionModel::Select);
}
void CopyMoveToDialog::closeEvent(QCloseEvent *event) {
savePaths();
QDialog::closeEvent(event);
}
CopyMoveToDialog::CopyMoveToDialog(QWidget *parent, QString thumbsPath, bool copyOp) : QDialog(parent) {
if (copyOp) {
setWindowTitle(tr("Copy to..."));
setWindowIcon(QIcon::fromTheme("edit-copy"));
} else {
setWindowTitle(tr("Move to..."));
setWindowIcon(QIcon::fromTheme("go-next"));
}
const int w = QFontMetrics(font()).averageCharWidth()*60;
resize(w, 10*w/16);
currentPath = thumbsPath;
pathsTable = new QTableView(this);
pathsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
pathsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
pathsTable->setSelectionMode(QAbstractItemView::SingleSelection);
pathsTableModel = new QStandardItemModel(this);
pathsTable->setModel(pathsTableModel);
pathsTable->verticalHeader()->setVisible(false);
pathsTable->horizontalHeader()->setVisible(false);
pathsTable->verticalHeader()->setDefaultSectionSize(pathsTable->verticalHeader()->minimumSectionSize());
pathsTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
pathsTable->horizontalHeader()->setStretchLastSection(true);
pathsTable->setShowGrid(false);
connect(pathsTable->selectionModel(), &QItemSelectionModel::selectionChanged, [this](){
m_destination = QString();
QModelIndexList indexesList;
QStandardItem *item;
if ((indexesList = pathsTable->selectionModel()->selectedIndexes()).size() &&
(item = pathsTableModel->itemFromIndex(indexesList.first())))
m_destination = item->text();
destinationLabel->setText(m_destination);
});
connect(pathsTable, &QTableView::doubleClicked, this, [this](){ m_destination.isEmpty() ? reject() : accept(); });
QVBoxLayout *addRemoveBox = new QVBoxLayout;
QPushButton *addButton = new QPushButton(tr("Browse..."));
connect(addButton, SIGNAL(clicked()), this, SLOT(add()));
addRemoveBox->addWidget(addButton, 0);
QPushButton *removeButton = new QPushButton(tr("Delete Bookmark"));
connect(removeButton, &QPushButton::clicked, this, [_LCD_]() {
QModelIndexList indexesList;
if ((indexesList = pathsTable->selectionModel()->selectedIndexes()).size())
pathsTableModel->removeRow(indexesList.first().row());
});
addRemoveBox->addWidget(removeButton, 0);
addRemoveBox->addStretch(1);
QHBoxLayout *buttonsHbox = new QHBoxLayout;
QPushButton *cancelButton = new QPushButton(tr("Cancel"));
connect(cancelButton, &QPushButton::clicked, this, [this](){ reject(); });
QPushButton *okButton = new QPushButton(copyOp ? tr("Copy") : tr("Move"));
okButton->setDefault(true);
connect(addButton, SIGNAL(clicked()), okButton, SLOT(setFocus()));
connect(okButton, &QPushButton::clicked, this, [this](){ m_destination.isEmpty() ? reject() : accept(); });
buttonsHbox->addStretch(1);
buttonsHbox->addWidget(cancelButton, 0);
buttonsHbox->addWidget(okButton, 0);
destinationLabel = new QLabel(this);
destinationLabel->setAlignment(Qt::AlignCenter);
QFont fnt = destinationLabel->font();
if (fnt.pointSize() > 0)
fnt.setPointSize(8*fnt.pointSize()/5);
else
fnt.setPixelSize(8*fnt.pixelSize()/5);
destinationLabel->setFont(fnt);
QHBoxLayout *pathsBox = new QHBoxLayout;
pathsBox->addWidget(pathsTable);
pathsBox->addLayout(addRemoveBox);
QVBoxLayout *mainVbox = new QVBoxLayout;
mainVbox->addLayout(pathsBox);
mainVbox->addWidget(new QLabel(tr("Destination:")));
mainVbox->addWidget(destinationLabel);
mainVbox->addLayout(buttonsHbox);
setLayout(mainVbox);
// Load paths list
for (const QString &s : Settings::bookmarkPaths)
pathsTableModel->insertRow(pathsTableModel->rowCount(), new QStandardItem(QIcon(":/images/bookmarks.png"), s));
for (const QString &s : gs_tmpPaths)
pathsTableModel->insertRow(pathsTableModel->rowCount(), new QStandardItem(folderIcon(), s));
pathsTableModel->sort(0);
}