Pin antialiasing option (#1997)

* adds a config option to toggle antialiasing for the pin zoom

* fix C++ scope error thanks for @veracioux

* set the default value of antialiasing of pin tool to be true

* fix the clang-format
This commit is contained in:
Mehrad Mahmoudian
2021-10-22 20:36:21 +03:00
committed by GitHub
parent 988dcab9de
commit 08e532f787
6 changed files with 34 additions and 2 deletions

View File

@@ -66,6 +66,9 @@
;; Copy path to image after save (bool)
;copyPathAfterSave=false
;
;; Anti-aliasing image when zoom the pinned image (bool)
;antialiasingPinZoom=true
;
;; Use JPG format instead of PNG (bool)
;useJpgForClipboard=false
;

View File

@@ -40,6 +40,7 @@ GeneralConf::GeneralConf(QWidget* parent)
initShowStartupLaunchMessage();
initCopyAndCloseAfterUpload();
initCopyPathAfterSave();
initAntialiasingPinZoom();
initUseJpgForClipboard();
initSaveAfterCopy();
inituploadHistoryMax();
@@ -62,6 +63,7 @@ void GeneralConf::_updateComponents(bool allowEmptySavePath)
m_copyAndCloseAfterUpload->setChecked(config.copyAndCloseAfterUpload());
m_saveAfterCopy->setChecked(config.saveAfterCopy());
m_copyPathAfterSave->setChecked(config.copyPathAfterSave());
m_antialiasingPinZoom->setChecked(config.antialiasingPinZoom());
m_useJpgForClipboard->setChecked(config.useJpgForClipboard());
m_historyConfirmationToDelete->setChecked(
config.historyConfirmationToDelete());
@@ -488,6 +490,19 @@ void GeneralConf::initCopyPathAfterSave()
});
}
void GeneralConf::initAntialiasingPinZoom()
{
m_antialiasingPinZoom =
new QCheckBox(tr("Anti-aliasing image when zoom the pinned image"), this);
m_antialiasingPinZoom->setToolTip(
tr("After zooming the pinned image, should the image get smoothened or "
"stay pixelated"));
m_scrollAreaLayout->addWidget(m_antialiasingPinZoom);
connect(m_antialiasingPinZoom, &QCheckBox::clicked, [](bool checked) {
ConfigHandler().setAntialiasingPinZoom(checked);
});
}
const QString GeneralConf::chooseFolder(const QString pathDefault)
{
QString path;

View File

@@ -58,6 +58,7 @@ private:
void initCopyAndCloseAfterUpload();
void initSaveAfterCopy();
void initCopyPathAfterSave();
void initAntialiasingPinZoom();
void initUseJpgForClipboard();
void _updateComponents(bool allowEmptySavePath);
@@ -75,6 +76,7 @@ private:
QCheckBox* m_showStartupLaunchMessage;
QCheckBox* m_copyAndCloseAfterUpload;
QCheckBox* m_copyPathAfterSave;
QCheckBox* m_antialiasingPinZoom;
QPushButton* m_importButton;
QPushButton* m_exportButton;
QPushButton* m_resetButton;

View File

@@ -121,9 +121,19 @@ void PinWidget::mouseMoveEvent(QMouseEvent* e)
void PinWidget::setScaledPixmap(const QSize& size)
{
ConfigHandler config;
QPixmap scaledPixmap;
const qreal scale = qApp->devicePixelRatio();
QPixmap scaledPixmap = m_pixmap.scaled(
size * scale, Qt::KeepAspectRatio, Qt::SmoothTransformation);
if (config.antialiasingPinZoom()) {
scaledPixmap = m_pixmap.scaled(
size * scale, Qt::KeepAspectRatio, Qt::SmoothTransformation);
} else {
scaledPixmap = m_pixmap.scaled(
size * scale, Qt::KeepAspectRatio, Qt::FastTransformation);
}
scaledPixmap.setDevicePixelRatio(scale);
m_label->setPixmap(scaledPixmap);
}

View File

@@ -87,6 +87,7 @@ static QMap<class QString, QSharedPointer<ValueHandler>>
OPTION("showStartupLaunchMessage" ,Bool ( true )),
OPTION("copyAndCloseAfterUpload" ,Bool ( true )),
OPTION("copyPathAfterSave" ,Bool ( false )),
OPTION("antialiasingPinZoom" ,Bool ( true )),
#if !defined(Q_OS_MACOS)
OPTION("useJpgForClipboard" ,Bool ( false )),
#endif

View File

@@ -88,6 +88,7 @@ public:
CONFIG_GETTER_SETTER(uploadHistoryMax, setUploadHistoryMax, int)
CONFIG_GETTER_SETTER(saveAfterCopy, setSaveAfterCopy, bool)
CONFIG_GETTER_SETTER(copyPathAfterSave, setCopyPathAfterSave, bool)
CONFIG_GETTER_SETTER(antialiasingPinZoom, setAntialiasingPinZoom, bool)
CONFIG_GETTER_SETTER(useJpgForClipboard, setUseJpgForClipboard, bool)
CONFIG_GETTER_SETTER(ignoreUpdateToVersion,
setIgnoreUpdateToVersion,