[plasma/spectacle] src/Gui/SettingsDialog: Disable image quality controls for formats without adjustable quality

Noah Davis <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit e7cd33e2136f35fa2af5644732f98fb326d91ce0 by Noah Davis, on behalf of Zhora Zmeykin.
Committed on 29/07/2026 at 16:29.
Pushed by ndavis into branch 'master'.

Disable image quality controls for formats without adjustable quality

The quality setting does not affect the output for all formats, while the enabled slider gave the false impression that it was being applied.

M  +40   -0    src/Gui/SettingsDialog/ImageSaveOptionsPage.cpp
M  +1    -0    src/Gui/SettingsDialog/ImageSaveOptionsPage.h

https://invent.kde.org/plasma/spectacle/-/commit/e7cd33e2136f35fa2af5644732f98fb326d91ce0

diff --git a/src/Gui/SettingsDialog/ImageSaveOptionsPage.cpp b/src/Gui/SettingsDialog/ImageSaveOptionsPage.cpp
index f00676121..e5f78f260 100644
--- a/src/Gui/SettingsDialog/ImageSaveOptionsPage.cpp
+++ b/src/Gui/SettingsDialog/ImageSaveOptionsPage.cpp
@@ -13,15 +13,42 @@
 
 #include <KLocalizedString>
 
+#include <QBuffer>
 #include <QCheckBox>
 #include <QComboBox>
 #include <QFontDatabase>
+#include <QImageIOHandler>
 #include <QImageWriter>
 #include <QLabel>
 #include <QLineEdit>
 
 using namespace Qt::StringLiterals;
 
+static QStringList getFormatsWithoutQuality()
+{
+    static QStringList formatsWithoutQuality;
+    if (!formatsWithoutQuality.empty()) {
+        return formatsWithoutQuality;
+    }
+
+    formatsWithoutQuality.push_back(u"PNG"_s);
+    formatsWithoutQuality.push_back(u"EXR"_s);
+
+    const auto formats = QImageWriter::supportedImageFormats();
+    QBuffer buffer;
+    buffer.open(QBuffer::ReadWrite);
+    QImageWriter writer(&buffer, "");
+    for (const auto &format : formats) {
+        writer.setDevice(&buffer);
+        writer.setFormat(format);
+        if (!writer.supportsOption(QImageIOHandler::Quality)) {
+            formatsWithoutQuality.push_back(QString::fromLatin1(format));
+        }
+    }
+
+    return formatsWithoutQuality;
+}
+
 ImageSaveOptionsPage::ImageSaveOptionsPage(QWidget *parent)
     : QWidget(parent)
     , m_ui(new Ui_ImageSaveOptions)
@@ -66,6 +93,8 @@ ImageSaveOptionsPage::ImageSaveOptionsPage(QWidget *parent)
         return items;
     }());
     connect(m_ui->kcfg_preferredImageFormat, &QComboBox::currentTextChanged, this, &ImageSaveOptionsPage::updateFilenamePreview);
+    connect(m_ui->kcfg_preferredImageFormat, &QComboBox::currentTextChanged, this, &ImageSaveOptionsPage::updateImageCompressionQualityEnabled);
+    updateImageCompressionQualityEnabled();
 
     m_ui->captureInstructionLabel->setText(CaptureInstructions::text(false));
     connect(m_ui->captureInstructionLabel, &QLabel::linkActivated, this, [this](const QString &link) {
@@ -88,4 +117,15 @@ void ImageSaveOptionsPage::updateFilenamePreview()
     ::updateFilenamePreview(m_ui->preview, templateBasename + u'.' + extension, Settings::imageSaveLocation());
 }
 
+void ImageSaveOptionsPage::updateImageCompressionQualityEnabled()
+{
+    const auto formatsWithoutQuality = getFormatsWithoutQuality();
+    const bool enabled = !formatsWithoutQuality.contains(m_ui->kcfg_preferredImageFormat->currentText(), Qt::CaseInsensitive);
+
+    m_ui->qualityLabel->setEnabled(enabled);
+    m_ui->kcfg_imageCompressionQuality->setEnabled(enabled);
+    m_ui->qualitySpinner->setEnabled(enabled);
+    m_ui->imageCompressionQualityHelpLable->setEnabled(enabled);
+}
+
 #include "moc_ImageSaveOptionsPage.cpp"
diff --git a/src/Gui/SettingsDialog/ImageSaveOptionsPage.h b/src/Gui/SettingsDialog/ImageSaveOptionsPage.h
index 0886d68b8..4c088ffa8 100644
--- a/src/Gui/SettingsDialog/ImageSaveOptionsPage.h
+++ b/src/Gui/SettingsDialog/ImageSaveOptionsPage.h
@@ -24,6 +24,7 @@ private:
     QScopedPointer<Ui_ImageSaveOptions> m_ui;
 
     void updateFilenamePreview();
+    void updateImageCompressionQualityEnabled();
 };
 
 #endif // SAVEOPTIONSPAGE_H
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.