Skip to content

Commit

Permalink
Merge pull request #3 from namecheap/feature/RND-675-flameshot-make-p…
Browse files Browse the repository at this point in the history
…reviews-in-the-latest-uploads-smaller

Make preview files on the local disk for the 'Latest uploads' smaller
  • Loading branch information
panpuchkov authored Oct 28, 2020
2 parents 2f03c51 + 7e49d4e commit ca7834e
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 27 deletions.
9 changes: 1 addition & 8 deletions src/config/geneneralconf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ void GeneneralConf::updateComponents()
m_copyAndCloseAfterUpload->setChecked(
config.copyAndCloseAfterUploadEnabled());
m_saveAfterCopy->setChecked(config.saveAfterCopyValue());

if (!config.saveAfterCopyPathValue().isEmpty()) {
m_savePath->setText(config.saveAfterCopyPathValue());
} else {
ConfigHandler().setSaveAfterCopyPath(
QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
}
m_copyPathAfterSave->setChecked(config.copyPathAfterSaveEnabled());

#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
Expand Down Expand Up @@ -376,7 +369,7 @@ void GeneneralConf::changeSavePath()
QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
if (!path.isEmpty()) {
m_savePath->setText(path);
ConfigHandler().setSaveAfterCopyPath(path);
ConfigHandler().setSavePath(path);
}
}

Expand Down
10 changes: 0 additions & 10 deletions src/utils/confighandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,16 +485,6 @@ const QString& ConfigHandler::uploadStorage()
return m_strRes;
}

QString ConfigHandler::saveAfterCopyPathValue()
{
return m_settings.value(QStringLiteral("saveAfterCopyPath")).toString();
}

void ConfigHandler::setSaveAfterCopyPath(const QString& path)
{
m_settings.setValue(QStringLiteral("saveAfterCopyPath"), path);
}

void ConfigHandler::setDefaults()
{
m_settings.clear();
Expand Down
3 changes: 0 additions & 3 deletions src/utils/confighandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ class ConfigHandler
bool saveAfterCopyValue();
void setSaveAfterCopy(const bool);

QString saveAfterCopyPathValue();
void setSaveAfterCopyPath(const QString&);

bool copyPathAfterSaveEnabled();
void setCopyPathAfterSaveEnabled(const bool);

Expand Down
13 changes: 12 additions & 1 deletion src/utils/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,20 @@ const QString& History::path()

void History::save(const QPixmap& pixmap, const QString& fileName)
{
// scale preview only in local disk
QPixmap pixmapScaled = QPixmap(pixmap);
if (pixmap.height() / HISTORYPIXMAP_MAX_PREVIEW_HEIGHT >=
pixmap.width() / HISTORYPIXMAP_MAX_PREVIEW_WIDTH) {
pixmapScaled = pixmap.scaledToHeight(HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);
} else {
pixmapScaled = pixmap.scaledToWidth(HISTORYPIXMAP_MAX_PREVIEW_WIDTH);
}

// save preview
QFile file(path() + fileName);
file.open(QIODevice::WriteOnly);
pixmap.save(&file, "PNG");
pixmapScaled.save(&file, "PNG");

history();
}

Expand Down
3 changes: 3 additions & 0 deletions src/utils/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#define HISTORY_MAX_SIZE 25

#define HISTORYPIXMAP_MAX_PREVIEW_WIDTH 160
#define HISTORYPIXMAP_MAX_PREVIEW_HEIGHT 90

#include <QList>
#include <QPixmap>
#include <QString>
Expand Down
4 changes: 2 additions & 2 deletions src/utils/screenshotsaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ void ScreenshotSaver::saveToClipboard(const QPixmap& capture)
// If we are able to properly save the file, save the file and copy to
// clipboard.
if ((ConfigHandler().saveAfterCopyValue()) &&
(!ConfigHandler().saveAfterCopyPathValue().isEmpty())) {
(!ConfigHandler().savePath().isEmpty())) {
saveToFilesystem(capture,
ConfigHandler().saveAfterCopyPathValue(),
ConfigHandler().savePath(),
QObject::tr("Capture saved to clipboard."));
QApplication::clipboard()->setPixmap(capture);
}
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/historywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ void HistoryWidget::addLine(const QString& path, const QString& fileName)
QPixmap pixmap;
pixmap.load(fullFileName, "png");

// TODO - remove much later, it is still required to keep old previews works
// fine
if (pixmap.height() / HISTORYPIXMAP_MAX_PREVIEW_HEIGHT >=
pixmap.width() / HISTORYPIXMAP_MAX_PREVIEW_WIDTH) {
pixmap = pixmap.scaledToHeight(HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);
Expand Down
3 changes: 0 additions & 3 deletions src/widgets/historywidget.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#ifndef HISTORYWIDGET_H
#define HISTORYWIDGET_H

#define HISTORYPIXMAP_MAX_PREVIEW_WIDTH 160
#define HISTORYPIXMAP_MAX_PREVIEW_HEIGHT 90

#include <QDialog>
#include <QObject>
#include <QString>
Expand Down

0 comments on commit ca7834e

Please sign in to comment.