diff --git a/graphics.qrc b/graphics.qrc index 87a2a790..43919bdc 100644 --- a/graphics.qrc +++ b/graphics.qrc @@ -2,6 +2,7 @@ img/app/flameshot.svg img/app/flameshot.png + img/material/black/delete.svg img/material/black/undo-variant.svg img/material/black/text.svg img/material/black/square.svg diff --git a/img/material/black/delete.png b/img/material/black/delete.png new file mode 100644 index 00000000..024a1100 Binary files /dev/null and b/img/material/black/delete.png differ diff --git a/img/material/black/delete.svg b/img/material/black/delete.svg new file mode 100644 index 00000000..0fcbb634 --- /dev/null +++ b/img/material/black/delete.svg @@ -0,0 +1,7 @@ + + + + + Svg Vector Icons : http://www.onlinewebfonts.com/icon + + \ No newline at end of file diff --git a/src/utils/history.h b/src/utils/history.h index 6a2fc686..4f720336 100644 --- a/src/utils/history.h +++ b/src/utils/history.h @@ -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 diff --git a/src/widgets/historywidget.cpp b/src/widgets/historywidget.cpp index 20b8140f..d13c68f3 100644 --- a/src/widgets/historywidget.cpp +++ b/src/widgets/historywidget.cpp @@ -18,6 +18,7 @@ #include #include #include +#include HistoryWidget::HistoryWidget(QWidget *parent) : QDialog(parent) @@ -43,88 +44,133 @@ HistoryWidget::HistoryWidget(QWidget *parent) : QDialog(parent) } void HistoryWidget::loadHistory() { - History history = History(); - QList 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 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(); } } diff --git a/src/widgets/historywidget.h b/src/widgets/historywidget.h index e0f1bac1..c685a501 100644 --- a/src/widgets/historywidget.h +++ b/src/widgets/historywidget.h @@ -7,7 +7,9 @@ #include #include #include +#include +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;