Add JPEG Quality Option (#3285)

* fixes #3188 (#3254)

Add JPEG quality option

Signed-off-by: Mike Phillips <mdphillips375@gmail.com>

Revert "Add JPEG quality option"

This reverts commit 046497d8273a69ea1cc0f134a996a5ada818ed8c.

* Add JPEG Quality Option

* Fix local variable name

* JPEG Quality: Add .ini example and minor fixes.

* JPEG Quality: Add .ini example and minor fixes.

* Fix Formatting

---------

Co-authored-by: Mehrad Mahmoudian <m.mahmoudian@gmail.com>
This commit is contained in:
Mike Phillips
2023-09-16 06:48:59 -05:00
committed by GitHub
parent 1d276a2cd3
commit c97c3aa546
6 changed files with 55 additions and 3 deletions

View File

@@ -87,6 +87,9 @@
;; Use larger color palette as the default one
; predefinedColorPaletteLarge=false
;
;; Set JPEG Quality (int in range 0-100)
; jpegQuality=75
;
;; Shortcut Settings for all tools
;[Shortcuts]
;TYPE_ARROW=A

View File

@@ -64,6 +64,7 @@ GeneralConf::GeneralConf(QWidget* parent)
initShowMagnifier();
initSquareMagnifier();
initJpegQuality();
// this has to be at the end
initConfigButtons();
updateComponents();
@@ -777,11 +778,36 @@ void GeneralConf::initShowSelectionGeometry()
vboxLayout->addStretch();
}
void GeneralConf::initJpegQuality()
{
auto* tobox = new QHBoxLayout();
int quality = ConfigHandler().value("jpegQuality").toInt();
m_jpegQuality = new QSpinBox();
m_jpegQuality->setRange(0, 100);
m_jpegQuality->setToolTip(tr("Quality range of 0-100; Higher number is "
"better quality and larger file size"));
m_jpegQuality->setValue(quality);
tobox->addWidget(m_jpegQuality);
tobox->addWidget(new QLabel(tr("JPEG Quality")));
m_scrollAreaLayout->addLayout(tobox);
connect(m_jpegQuality,
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
this,
&GeneralConf::setJpegQuality);
}
void GeneralConf::setSelGeoHideTime(int v)
{
ConfigHandler().setValue("showSelectionGeometryHideTime", v);
}
void GeneralConf::setJpegQuality(int v)
{
ConfigHandler().setJpegQuality(v);
}
void GeneralConf::setGeometryLocation(int index)
{
ConfigHandler().setValue("showSelectionGeometry",

View File

@@ -57,6 +57,7 @@ private slots:
void setSaveAsFileExtension(const QString& extension);
void setGeometryLocation(int index);
void setSelGeoHideTime(int v);
void setJpegQuality(int v);
private:
const QString chooseFolder(const QString& currentPath = "");
@@ -90,6 +91,7 @@ private:
void initUploadClientSecret();
void initSaveLastRegion();
void initShowSelectionGeometry();
void initJpegQuality();
void _updateComponents(bool allowEmptySavePath);
@@ -133,4 +135,5 @@ private:
QCheckBox* m_showSelectionGeometry;
QComboBox* m_selectGeometryLocation;
QSpinBox* m_xywhTimeout;
QSpinBox* m_jpegQuality;
};

View File

@@ -124,7 +124,8 @@ static QMap<class QString, QSharedPointer<ValueHandler>>
OPTION("copyOnDoubleClick" ,Bool ( false )),
OPTION("uploadClientSecret" ,String ( "313baf0c7b4d3ff" )),
OPTION("showSelectionGeometry" , BoundedInt (0,5,4)),
OPTION("showSelectionGeometryHideTime", LowerBoundedInt (0, 3000))
OPTION("showSelectionGeometryHideTime", LowerBoundedInt (0, 3000)),
OPTION("jpegQuality", BoundedInt (0,100,75))
};
static QMap<QString, QSharedPointer<KeySequence>> recognizedShortcuts = {

View File

@@ -126,6 +126,7 @@ public:
CONFIG_GETTER_SETTER(uploadClientSecret, setUploadClientSecret, QString)
CONFIG_GETTER_SETTER(saveLastRegion, setSaveLastRegion, bool)
CONFIG_GETTER_SETTER(showSelectionGeometry, setShowSelectionGeometry, int)
CONFIG_GETTER_SETTER(jpegQuality, setJpegQuality, int)
CONFIG_GETTER_SETTER(showSelectionGeometryHideTime,
showSelectionGeometryHideTime,
int)

View File

@@ -35,7 +35,16 @@ bool saveToFilesystem(const QPixmap& capture,
path, ConfigHandler().saveAsFileExtension());
QFile file{ completePath };
file.open(QIODevice::WriteOnly);
bool okay = capture.save(&file);
bool okay;
QString saveExtension;
saveExtension = QFileInfo(completePath).suffix().toLower();
if (saveExtension == "jpg" || saveExtension == "jpeg") {
okay = capture.save(&file, nullptr, ConfigHandler().jpegQuality());
} else {
okay = capture.save(&file);
}
QString saveMessage = messagePrefix;
QString notificationPath = completePath;
if (!saveMessage.isEmpty()) {
@@ -97,6 +106,9 @@ void saveToClipboardMime(const QPixmap& capture, const QString& imageType)
QByteArray array;
QBuffer buffer{ &array };
QImageWriter imageWriter{ &buffer, imageType.toUpper().toUtf8() };
if (imageType == "jpeg") {
imageWriter.setQuality(ConfigHandler().jpegQuality());
}
imageWriter.write(capture.toImage());
QPixmap formattedPixmap;
@@ -189,7 +201,13 @@ bool saveToFilesystemGUI(const QPixmap& capture)
QFile file{ savePath };
file.open(QIODevice::WriteOnly);
QString saveExtension;
saveExtension = QFileInfo(savePath).suffix().toLower();
if (saveExtension == "jpg" || saveExtension == "jpeg") {
okay = capture.save(&file, nullptr, ConfigHandler().jpegQuality());
} else {
okay = capture.save(&file);
}
if (okay) {
QString pathNoFile =