diff --git a/src/config/geneneralconf.cpp b/src/config/geneneralconf.cpp index c511605f..d7b18b27 100644 --- a/src/config/geneneralconf.cpp +++ b/src/config/geneneralconf.cpp @@ -39,6 +39,7 @@ GeneneralConf::GeneneralConf(QWidget* parent) initShowDesktopNotification(); initShowTrayIcon(); initAutostart(); + initUseJpgInsteadPngWhenCopy(); initSaveAfterCopy(); // this has to be at the end @@ -54,6 +55,7 @@ void GeneneralConf::updateComponents() m_sysNotifications->setChecked(config.desktopNotificationValue()); m_autostart->setChecked(config.startupLaunchValue()); m_saveAfterCopy->setChecked(config.saveAfterCopyValue()); + m_useJpgInsteadPngCheck->setChecked(config.useJpgInsteadPngWhenCopy()); if (!config.saveAfterCopyPathValue().isEmpty()) { m_savePath->setText(config.saveAfterCopyPathValue()); @@ -304,6 +306,23 @@ void GeneneralConf::initSaveAfterCopy() vboxLayout->addWidget(m_screenshotPathFixedCheck); } +void GeneneralConf::initUseJpgInsteadPngWhenCopy() +{ + m_useJpgInsteadPngCheck = + new QCheckBox(tr("Use JPG format instead of PNG when copy"), this); + ConfigHandler config; + bool checked = config.useJpgInsteadPngWhenCopy(); + m_useJpgInsteadPngCheck->setChecked(checked); + m_useJpgInsteadPngCheck->setToolTip( + tr("Use JPG format instead of PNG when copy")); + m_layout->addWidget(m_useJpgInsteadPngCheck); + + connect(m_useJpgInsteadPngCheck, + &QCheckBox::clicked, + this, + &GeneneralConf::useJpgInsteadPngChanged); +} + void GeneneralConf::saveAfterCopyChanged(bool checked) { ConfigHandler().setSaveAfterCopy(checked); @@ -348,3 +367,8 @@ void GeneneralConf::togglePathFixed() { ConfigHandler().setSavePathFixed(m_screenshotPathFixedCheck->isChecked()); } + +void GeneneralConf::useJpgInsteadPngChanged(bool checked) +{ + ConfigHandler().setUseJpgInsteadPngWhenCopy(checked); +} diff --git a/src/config/geneneralconf.h b/src/config/geneneralconf.h index 4dbc4c42..ce6418a7 100644 --- a/src/config/geneneralconf.h +++ b/src/config/geneneralconf.h @@ -46,6 +46,7 @@ private slots: void exportFileConfiguration(); void resetConfiguration(); void togglePathFixed(); + void useJpgInsteadPngChanged(bool checked); private: const QString chooseFolder(const QString currentPath = ""); @@ -57,6 +58,7 @@ private: void initConfingButtons(); void initAutostart(); void initSaveAfterCopy(); + void initUseJpgInsteadPngWhenCopy(); // class members QVBoxLayout* m_layout; @@ -72,4 +74,5 @@ private: QLineEdit* m_savePath; QPushButton* m_changeSaveButton; QCheckBox* m_screenshotPathFixedCheck; + QCheckBox* m_useJpgInsteadPngCheck; }; diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp index faa83f75..61697e81 100644 --- a/src/utils/confighandler.cpp +++ b/src/utils/confighandler.cpp @@ -431,6 +431,20 @@ void ConfigHandler::setCopyPathAfterSaveEnabled(const bool value) m_settings.setValue(QStringLiteral("copyPathAfterSave"), value); } +bool ConfigHandler::useJpgInsteadPngWhenCopy() const +{ + if (m_settings.contains(QStringLiteral("useJpgInsteadPngWhenCopy"))) { + return m_settings.value(QStringLiteral("useJpgInsteadPngWhenCopy")) + .toBool(); + } + return false; +} + +void ConfigHandler::setUseJpgInsteadPngWhenCopy(const bool value) +{ + m_settings.setValue(QStringLiteral("useJpgInsteadPngWhenCopy"), value); +} + QString ConfigHandler::saveAfterCopyPathValue() { return m_settings.value(QStringLiteral("saveAfterCopyPath")).toString(); diff --git a/src/utils/confighandler.h b/src/utils/confighandler.h index 3524c086..66fb9617 100644 --- a/src/utils/confighandler.h +++ b/src/utils/confighandler.h @@ -86,6 +86,9 @@ public: bool copyPathAfterSaveEnabled(); void setCopyPathAfterSaveEnabled(const bool); + bool useJpgInsteadPngWhenCopy() const; + void setUseJpgInsteadPngWhenCopy(const bool); + void setDefaults(); void setAllTheButtons(); diff --git a/src/utils/screenshotsaver.cpp b/src/utils/screenshotsaver.cpp index 35f1edbb..5273da3f 100644 --- a/src/utils/screenshotsaver.cpp +++ b/src/utils/screenshotsaver.cpp @@ -51,22 +51,27 @@ void ScreenshotSaver::saveToClipboard(const QPixmap& capture) } // Otherwise only save to clipboard else { - SystemNotification().sendMessage( - QObject::tr("Capture saved to clipboard")); + if (ConfigHandler().useJpgInsteadPngWhenCopy()) { + QByteArray array; + QBuffer buffer{ &array }; + QImageWriter imageWriter{ &buffer, "JPG" }; + imageWriter.write(capture.toImage()); - QByteArray array; - QBuffer buffer{ &array }; - QImageWriter imageWriter{ &buffer, "JPG" }; - imageWriter.write(capture.toImage()); - - QPixmap jpgPixmap; - bool isLoaded = jpgPixmap.loadFromData( - reinterpret_cast(array.data()), array.size(), "JPG"); - if (isLoaded) { - QApplication::clipboard()->setPixmap(jpgPixmap); + QPixmap jpgPixmap; + bool isLoaded = jpgPixmap.loadFromData( + reinterpret_cast(array.data()), array.size(), "JPG"); + if (isLoaded) { + QApplication::clipboard()->setPixmap(jpgPixmap); + } else { + SystemNotification().sendMessage( + QObject::tr("Error while saving to clipboard")); + return; + } } else { QApplication::clipboard()->setPixmap(capture); } + SystemNotification().sendMessage( + QObject::tr("Capture saved to clipboard")); } }