Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds WebP Quality Config #3672

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions flameshot.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
;; Set JPEG Quality (int in range 0-100)
; jpegQuality=75
;
;; Set WebP Quality (int in range 0-100)
; webpQuality=90
;
;; Shortcut Settings for all tools
;[Shortcuts]
;TYPE_ARROW=A
Expand Down
26 changes: 26 additions & 0 deletions src/config/generalconf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ GeneralConf::GeneralConf(QWidget* parent)
initShowMagnifier();
initSquareMagnifier();
initJpegQuality();
initWebPQuality();
// this has to be at the end
initConfigButtons();
updateComponents();
Expand Down Expand Up @@ -799,6 +800,26 @@ void GeneralConf::initJpegQuality()
&GeneralConf::setJpegQuality);
}

void GeneralConf::initWebPQuality()
{
auto* tobox = new QHBoxLayout();

int quality = ConfigHandler().value("webpQuality").toInt();
m_webpQuality = new QSpinBox();
m_webpQuality->setRange(0, 100);
m_webpQuality->setToolTip(tr("Quality range of 0-100; Higher number is "
"better quality and larger file size"));
m_webpQuality->setValue(quality);
tobox->addWidget(m_webpQuality);
tobox->addWidget(new QLabel(tr("WebP Quality")));

m_scrollAreaLayout->addLayout(tobox);
connect(m_webpQuality,
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
this,
&GeneralConf::setWebPQuality);
}

void GeneralConf::setSelGeoHideTime(int v)
{
ConfigHandler().setValue("showSelectionGeometryHideTime", v);
Expand All @@ -809,6 +830,11 @@ void GeneralConf::setJpegQuality(int v)
ConfigHandler().setJpegQuality(v);
}

void GeneralConf::setWebPQuality(int v)
{
ConfigHandler().setWebPQuality(v);
}

void GeneralConf::setGeometryLocation(int index)
{
ConfigHandler().setValue("showSelectionGeometry",
Expand Down
3 changes: 3 additions & 0 deletions src/config/generalconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ private slots:
void setGeometryLocation(int index);
void setSelGeoHideTime(int v);
void setJpegQuality(int v);
void setWebPQuality(int v);

private:
const QString chooseFolder(const QString& currentPath = "");
Expand Down Expand Up @@ -92,6 +93,7 @@ private slots:
void initSaveLastRegion();
void initShowSelectionGeometry();
void initJpegQuality();
void initWebPQuality();

void _updateComponents(bool allowEmptySavePath);

Expand Down Expand Up @@ -136,4 +138,5 @@ private slots:
QComboBox* m_selectGeometryLocation;
QSpinBox* m_xywhTimeout;
QSpinBox* m_jpegQuality;
QSpinBox* m_webpQuality;
};
3 changes: 2 additions & 1 deletion src/utils/confighandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ static QMap<class QString, QSharedPointer<ValueHandler>>
OPTION("uploadClientSecret" ,String ( "313baf0c7b4d3ff" )),
OPTION("showSelectionGeometry" , BoundedInt (0,5,4)),
OPTION("showSelectionGeometryHideTime", LowerBoundedInt (0, 3000)),
OPTION("jpegQuality", BoundedInt (0,100,75))
OPTION("jpegQuality", BoundedInt (0,100,75)),
OPTION("webpQuality", BoundedInt (0,100,90))
};

static QMap<QString, QSharedPointer<KeySequence>> recognizedShortcuts = {
Expand Down
1 change: 1 addition & 0 deletions src/utils/confighandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class ConfigHandler : public QObject
CONFIG_GETTER_SETTER(saveLastRegion, setSaveLastRegion, bool)
CONFIG_GETTER_SETTER(showSelectionGeometry, setShowSelectionGeometry, int)
CONFIG_GETTER_SETTER(jpegQuality, setJpegQuality, int)
CONFIG_GETTER_SETTER(webpQuality, setWebPQuality, int)
CONFIG_GETTER_SETTER(showSelectionGeometryHideTime,
showSelectionGeometryHideTime,
int)
Expand Down
7 changes: 7 additions & 0 deletions src/utils/screenshotsaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ bool saveToFilesystem(const QPixmap& capture,
saveExtension = QFileInfo(completePath).suffix().toLower();
if (saveExtension == "jpg" || saveExtension == "jpeg") {
okay = capture.save(&file, nullptr, ConfigHandler().jpegQuality());
} else if (saveExtension == "webp") {
okay = capture.save(&file, nullptr, ConfigHandler().webpQuality());
} else {
okay = capture.save(&file);
}
Expand Down Expand Up @@ -108,6 +110,9 @@ void saveToClipboardMime(const QPixmap& capture, const QString& imageType)
QImageWriter imageWriter{ &buffer, imageType.toUpper().toUtf8() };
if (imageType == "jpeg") {
imageWriter.setQuality(ConfigHandler().jpegQuality());
} else if (imageType == "webp") {
imageWriter.setQuality(ConfigHandler().webpQuality());
imageWriter.setOptimizedWrite(true);
}
imageWriter.write(capture.toImage());

Expand Down Expand Up @@ -206,6 +211,8 @@ bool saveToFilesystemGUI(const QPixmap& capture)
saveExtension = QFileInfo(savePath).suffix().toLower();
if (saveExtension == "jpg" || saveExtension == "jpeg") {
okay = capture.save(&file, nullptr, ConfigHandler().jpegQuality());
} else if (saveExtension == "webp") {
okay = capture.save(&file, nullptr, ConfigHandler().webpQuality());
} else {
okay = capture.save(&file);
}
Expand Down