forked from flameshot-org/flameshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuploadhistory.cpp
More file actions
103 lines (85 loc) · 2.76 KB
/
uploadhistory.cpp
File metadata and controls
103 lines (85 loc) · 2.76 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
#include "uploadhistory.h"
#include "./ui_uploadhistory.h"
#include "src/tools/imgupload/imguploadermanager.h"
#include "src/utils/confighandler.h"
#include "src/utils/history.h"
#include "uploadlineitem.h"
#include <QDateTime>
#include <QDesktopWidget>
#include <QFileInfo>
#include <QPixmap>
void scaleThumbnail(QPixmap& pixmap)
{
if (pixmap.height() / HISTORYPIXMAP_MAX_PREVIEW_HEIGHT >=
pixmap.width() / HISTORYPIXMAP_MAX_PREVIEW_WIDTH) {
pixmap = pixmap.scaledToHeight(HISTORYPIXMAP_MAX_PREVIEW_HEIGHT,
Qt::SmoothTransformation);
} else {
pixmap = pixmap.scaledToWidth(HISTORYPIXMAP_MAX_PREVIEW_WIDTH,
Qt::SmoothTransformation);
}
}
void clearHistoryLayout(QLayout* layout)
{
while (layout->count() != 0) {
delete layout->takeAt(0);
}
}
UploadHistory::UploadHistory(QWidget* parent)
: QWidget(parent)
, ui(new Ui::UploadHistory)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
resize(QDesktopWidget().availableGeometry(this).size() * 0.5);
}
void UploadHistory::loadHistory()
{
clearHistoryLayout(ui->historyContainer);
History history = History();
QList<QString> historyFiles = history.history();
if (historyFiles.isEmpty()) {
setEmptyMessage();
} else {
foreach (QString fileName, historyFiles) {
addLine(history.path(), fileName);
}
}
}
void UploadHistory::setEmptyMessage()
{
auto* buttonEmpty = new QPushButton;
buttonEmpty->setText(tr("Screenshots history is empty"));
buttonEmpty->setMinimumSize(1, HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);
connect(buttonEmpty, &QPushButton::clicked, this, [=]() { this->close(); });
ui->historyContainer->addWidget(buttonEmpty);
}
void UploadHistory::addLine(const QString& path, const QString& fileName)
{
QString fullFileName = path + fileName;
History history;
HistoryFileName unpackFileName = history.unpackFileName(fileName);
QString url = ImgUploaderManager(this).url() + unpackFileName.file;
// load pixmap
QPixmap pixmap;
pixmap.load(fullFileName, "png");
scaleThumbnail(pixmap);
// get file info
auto fileInfo = QFileInfo(fullFileName);
QString lastModified =
fileInfo.lastModified().toString("yyyy-MM-dd\nhh:mm:ss");
auto* line = new UploadLineItem(
this, pixmap, lastModified, url, fullFileName, unpackFileName);
connect(line, &UploadLineItem::requestedDeletion, this, [=]() {
if (ui->historyContainer->count() <= 1) {
setEmptyMessage();
}
delete line;
});
ui->historyContainer->addWidget(line);
}
UploadHistory::~UploadHistory()
{
delete ui;
}