Remove screenshot feature
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
<qresource prefix="/">
|
||||
<file>img/app/flameshot.svg</file>
|
||||
<file>img/app/flameshot.png</file>
|
||||
<file>img/material/black/delete.svg</file>
|
||||
<file>img/material/black/undo-variant.svg</file>
|
||||
<file>img/material/black/text.svg</file>
|
||||
<file>img/material/black/square.svg</file>
|
||||
|
||||
BIN
img/material/black/delete.png
Normal file
BIN
img/material/black/delete.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.6 KiB |
7
img/material/black/delete.svg
Normal file
7
img/material/black/delete.svg
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Svg Vector Icons : http://www.onlinewebfonts.com/icon -->
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve">
|
||||
<metadata> Svg Vector Icons : http://www.onlinewebfonts.com/icon </metadata>
|
||||
<g><path d="M876.9,311.5c-20.8,0-37.7,16.9-37.7,37.7v490c0,41.6-33.8,75.4-75.4,75.4H236.2c-41.6,0-75.4-33.8-75.4-75.4v-490c0-20.8-16.9-37.7-37.7-37.7c-20.8,0-37.7,16.9-37.7,37.7v490c0,83.3,67.5,150.8,150.8,150.8h527.7c83.3,0,150.8-67.5,150.8-150.8v-490C914.6,328.4,897.8,311.5,876.9,311.5z M349.2,763.8V349.2c0-20.8-16.9-37.7-37.7-37.7c-20.8,0-37.7,16.9-37.7,37.7v414.6c0,20.8,16.9,37.7,37.7,37.7C332.3,801.5,349.2,784.7,349.2,763.8z M952.3,160.8H650.8V47.7c0-20.8-16.8-37.7-37.7-37.7H386.9c-20.8,0-37.7,16.9-37.7,37.7v113.1H47.7c-20.8,0-37.7,16.9-37.7,37.7c0,20.8,16.9,37.7,37.7,37.7h904.6c20.8,0,37.7-16.8,37.7-37.7C990,177.7,973.2,160.8,952.3,160.8z M575.4,160.8H424.6V85.4h150.8V160.8z M726.2,763.8V349.2c0-20.8-16.8-37.7-37.7-37.7c-20.8,0-37.7,16.9-37.7,37.7v414.6c0,20.8,16.8,37.7,37.7,37.7C709.3,801.5,726.2,784.7,726.2,763.8z M537.7,763.8V349.2c0-20.8-16.8-37.7-37.7-37.7c-20.8,0-37.7,16.9-37.7,37.7v414.6c0,20.8,16.9,37.7,37.7,37.7C520.8,801.5,537.7,784.7,537.7,763.8z"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
@@ -1,7 +1,7 @@
|
||||
#ifndef HISTORY_H
|
||||
#define HISTORY_H
|
||||
|
||||
#define HISTORY_MAX_SIZE 10
|
||||
#define HISTORY_MAX_SIZE 20
|
||||
#define HISTORY_THUNB_SCALE 1.5
|
||||
#define HISTORY_THUNB_WIDTH 160*HISTORY_THUNB_SCALE
|
||||
#define HISTORY_THUNB_HEIGH 90*HISTORY_THUNB_SCALE
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <QDesktopServices>
|
||||
#include <QClipboard>
|
||||
#include <QUrl>
|
||||
#include <QLayoutItem>
|
||||
|
||||
|
||||
HistoryWidget::HistoryWidget(QWidget *parent) : QDialog(parent)
|
||||
@@ -43,88 +44,133 @@ HistoryWidget::HistoryWidget(QWidget *parent) : QDialog(parent)
|
||||
}
|
||||
|
||||
void HistoryWidget::loadHistory() {
|
||||
History history = History();
|
||||
QList<QString> historyFiles = history.history();
|
||||
|
||||
// get settings
|
||||
ConfigEnterprise configEnterprise;
|
||||
QSettings *settings = configEnterprise.settings();
|
||||
settings->beginGroup("S3");
|
||||
QString s3BaseUrl = settings->value("S3_URL").toString();
|
||||
settings->endGroup();
|
||||
|
||||
// read history files
|
||||
History history = History();
|
||||
QList<QString> historyFiles = history.history();
|
||||
|
||||
if(historyFiles.isEmpty()) {
|
||||
QPushButton *buttonEmpty = new QPushButton;
|
||||
buttonEmpty->setText(tr("Screenshots history is empty"));
|
||||
buttonEmpty->setMinimumSize(1, HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);
|
||||
connect(buttonEmpty, &QPushButton::clicked, this, [=](){
|
||||
this->close();
|
||||
});
|
||||
m_pVBox->addWidget(buttonEmpty);
|
||||
return;
|
||||
setEmptyMessage();
|
||||
}
|
||||
foreach(QString fileName, historyFiles) {
|
||||
// generate url
|
||||
QString fullFileName = history.path() + fileName;
|
||||
QString url = s3BaseUrl + fileName;
|
||||
|
||||
// load pixmap
|
||||
QPixmap pixmap;
|
||||
pixmap.load( fullFileName, "png" );
|
||||
|
||||
if (pixmap.height() / HISTORYPIXMAP_MAX_PREVIEW_HEIGHT >= pixmap.width() / HISTORYPIXMAP_MAX_PREVIEW_WIDTH) {
|
||||
pixmap = pixmap.scaledToHeight(HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);
|
||||
} else {
|
||||
pixmap = pixmap.scaledToWidth(HISTORYPIXMAP_MAX_PREVIEW_WIDTH);
|
||||
else {
|
||||
// generate history list
|
||||
foreach(QString fileName, historyFiles) {
|
||||
addLine(s3BaseUrl + fileName, history.path() + fileName);
|
||||
}
|
||||
|
||||
// get file info
|
||||
QFileInfo *pFileInfo = new QFileInfo(fullFileName);
|
||||
QString lastModified = pFileInfo->lastModified().toString(" yyyy-MM-dd hh:mm:ss");
|
||||
|
||||
// screenshot preview
|
||||
QLabel *pScreenshot = new QLabel();
|
||||
pScreenshot->setStyleSheet("padding: 5px;");
|
||||
pScreenshot->setMinimumHeight(HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);
|
||||
pScreenshot->setPixmap(pixmap);
|
||||
|
||||
// screenshot datetime
|
||||
QLabel *pScreenshotText = new QLabel();
|
||||
pScreenshotText->setStyleSheet("padding: 5px;");
|
||||
pScreenshotText->setMinimumHeight(HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);
|
||||
pScreenshotText->setText(lastModified);
|
||||
|
||||
// copy url
|
||||
QPushButton *buttonCopyUrl = new QPushButton;
|
||||
buttonCopyUrl->setText(tr("Copy URL"));
|
||||
buttonCopyUrl->setMinimumHeight(HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);
|
||||
connect(buttonCopyUrl, &QPushButton::clicked, this, [=](){
|
||||
QApplication::clipboard()->setText(url);
|
||||
m_notification->showMessage(tr("URL copied to clipboard."));
|
||||
this->close();
|
||||
});
|
||||
|
||||
// open in browser
|
||||
QPushButton *buttonOpen = new QPushButton;
|
||||
buttonOpen->setText(tr("Open in browser"));
|
||||
buttonOpen->setMinimumHeight(HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);
|
||||
connect(buttonOpen, &QPushButton::clicked, this, [=](){
|
||||
QDesktopServices::openUrl(QUrl(url));
|
||||
this->close();
|
||||
});
|
||||
|
||||
// layout
|
||||
QHBoxLayout *phbl = new QHBoxLayout();
|
||||
phbl->addWidget(pScreenshot);
|
||||
phbl->addWidget(pScreenshotText);
|
||||
phbl->addWidget(buttonCopyUrl);
|
||||
phbl->addWidget(buttonOpen);
|
||||
|
||||
phbl->setStretchFactor(pScreenshot, 3);
|
||||
phbl->setStretchFactor(pScreenshotText, 2);
|
||||
phbl->setStretchFactor(buttonCopyUrl, 2);
|
||||
phbl->setStretchFactor(buttonOpen, 2);
|
||||
|
||||
// add to scroll
|
||||
m_pVBox->addLayout(phbl);
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryWidget::setEmptyMessage() {
|
||||
QPushButton *buttonEmpty = new QPushButton;
|
||||
buttonEmpty->setText(tr("Screenshots history is empty"));
|
||||
buttonEmpty->setMinimumSize(1, HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);
|
||||
connect(buttonEmpty, &QPushButton::clicked, this, [=](){
|
||||
this->close();
|
||||
});
|
||||
m_pVBox->addWidget(buttonEmpty);
|
||||
}
|
||||
|
||||
void HistoryWidget::addLine(const QString &url, const QString &fullFileName) {
|
||||
QHBoxLayout *phbl = new QHBoxLayout();
|
||||
|
||||
// load pixmap
|
||||
QPixmap pixmap;
|
||||
pixmap.load( fullFileName, "png" );
|
||||
|
||||
if (pixmap.height() / HISTORYPIXMAP_MAX_PREVIEW_HEIGHT >= pixmap.width() / HISTORYPIXMAP_MAX_PREVIEW_WIDTH) {
|
||||
pixmap = pixmap.scaledToHeight(HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);
|
||||
} else {
|
||||
pixmap = pixmap.scaledToWidth(HISTORYPIXMAP_MAX_PREVIEW_WIDTH);
|
||||
}
|
||||
|
||||
// get file info
|
||||
QFileInfo *pFileInfo = new QFileInfo(fullFileName);
|
||||
QString lastModified = pFileInfo->lastModified().toString(" yyyy-MM-dd\nhh:mm:ss");
|
||||
|
||||
// screenshot preview
|
||||
QLabel *pScreenshot = new QLabel();
|
||||
pScreenshot->setStyleSheet("padding: 5px;");
|
||||
pScreenshot->setMinimumHeight(HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);
|
||||
pScreenshot->setPixmap(pixmap);
|
||||
|
||||
// screenshot datetime
|
||||
QLabel *pScreenshotText = new QLabel();
|
||||
pScreenshotText->setStyleSheet("padding: 5px;");
|
||||
pScreenshotText->setMinimumHeight(HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);
|
||||
pScreenshotText->setAlignment(Qt::AlignCenter);
|
||||
pScreenshotText->setText(lastModified);
|
||||
|
||||
// copy url
|
||||
QPushButton *buttonCopyUrl = new QPushButton;
|
||||
buttonCopyUrl->setText(tr("Copy URL"));
|
||||
buttonCopyUrl->setMinimumHeight(HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);
|
||||
connect(buttonCopyUrl, &QPushButton::clicked, this, [=](){
|
||||
QApplication::clipboard()->setText(url);
|
||||
m_notification->showMessage(tr("URL copied to clipboard."));
|
||||
this->close();
|
||||
});
|
||||
|
||||
// open in browser
|
||||
QPushButton *buttonOpen = new QPushButton;
|
||||
buttonOpen->setText(tr("Open in browser"));
|
||||
buttonOpen->setMinimumHeight(HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);
|
||||
connect(buttonOpen, &QPushButton::clicked, this, [=](){
|
||||
QDesktopServices::openUrl(QUrl(url));
|
||||
this->close();
|
||||
});
|
||||
|
||||
// delete
|
||||
QPushButton *buttonDelete = new QPushButton;
|
||||
buttonDelete->setIcon(QIcon(":/img/material/black/delete.svg"));
|
||||
buttonDelete->setMinimumHeight(HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);
|
||||
connect(buttonDelete, &QPushButton::clicked, this, [=](){
|
||||
removeItem(phbl, fullFileName);
|
||||
});
|
||||
|
||||
// layout
|
||||
phbl->addWidget(pScreenshot);
|
||||
phbl->addWidget(pScreenshotText);
|
||||
phbl->addWidget(buttonCopyUrl);
|
||||
phbl->addWidget(buttonOpen);
|
||||
phbl->addWidget(buttonDelete);
|
||||
|
||||
phbl->setStretchFactor(pScreenshot, 6);
|
||||
phbl->setStretchFactor(pScreenshotText, 4);
|
||||
phbl->setStretchFactor(buttonCopyUrl, 4);
|
||||
phbl->setStretchFactor(buttonOpen, 4);
|
||||
phbl->setStretchFactor(buttonDelete, 1);
|
||||
|
||||
|
||||
// add to scroll
|
||||
m_pVBox->addLayout(phbl);
|
||||
}
|
||||
|
||||
void HistoryWidget::removeItem(QLayout *pl, const QString &fullFileName) {
|
||||
// TODO - send delete request
|
||||
qDebug() << "Delete image on S3";
|
||||
|
||||
// delete cached image on local dist
|
||||
QFile file(fullFileName);
|
||||
file.remove();
|
||||
|
||||
// remove current row or refresh list
|
||||
while(pl->count() > 0)
|
||||
{
|
||||
QLayoutItem *item = pl->takeAt(0);
|
||||
delete item->widget();
|
||||
delete item;
|
||||
}
|
||||
m_pVBox->removeItem(pl);
|
||||
delete pl;
|
||||
|
||||
// set "empty" message if no items left
|
||||
if(m_pVBox->count() == 0) {
|
||||
setEmptyMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QDialog>
|
||||
#include <QString>
|
||||
|
||||
class QLayout;
|
||||
class QVBoxLayout;
|
||||
class NotificationWidget;
|
||||
|
||||
@@ -21,6 +23,9 @@ signals:
|
||||
|
||||
private:
|
||||
void loadHistory();
|
||||
void addLine(const QString &, const QString &);
|
||||
void removeItem(QLayout *, const QString &);
|
||||
void setEmptyMessage();
|
||||
|
||||
private:
|
||||
QVBoxLayout *m_pVBox;
|
||||
|
||||
Reference in New Issue
Block a user