...
 
Commits (2)
  • Mathias Wein's avatar
    Implement quality setting for WebP export · 5939f131
    Mathias Wein authored
    Since WebP is the only format handled by QImageIO plugin that
    uses the quality option (or any meaningful options really),
    there are no generic QImageWriter capability checks for now.
    
    A quality of 100 makes the WebP plugin bundled with Qt save in the
    lossless format. This is nice because in many cases it compresses
    significantly better than PNG, including alternative implementations
    that put additional effort into compressing PNGs better then libPNG.
    5939f131
  • Kuntal  Majumder's avatar
    Recently used fonts are put to the top automatically · eb187f22
    Kuntal Majumder authored
    REF: T11854
    eb187f22
......@@ -16,7 +16,7 @@ set(kritaqimageioimport_SOURCES
kis_qimageio_import.cpp
)
ki18n_wrap_ui(kritaqimageioimport_SOURCES )
ki18n_wrap_ui(kritaqimageioimport_SOURCES kis_wdg_options_qimageio.ui)
add_library(kritaqimageioimport MODULE ${kritaqimageioimport_SOURCES})
......
......@@ -18,6 +18,7 @@
*/
#include "kis_qimageio_export.h"
#include "ui_kis_wdg_options_qimageio.h"
#include <QCheckBox>
#include <QSlider>
......@@ -32,9 +33,41 @@
#include <KisDocument.h>
#include <kis_image.h>
#include <kis_paint_layer.h>
#include <kis_config_widget.h>
K_PLUGIN_FACTORY_WITH_JSON(KisQImageIOExportFactory, "krita_qimageio_export.json", registerPlugin<KisQImageIOExport>();)
class KisWdgOptionsQImageIO : public KisConfigWidget, public Ui::KisWdgOptionsQImageIO
{
Q_OBJECT
public:
KisWdgOptionsQImageIO(QWidget *parent);
void setConfiguration(const KisPropertiesConfigurationSP cfg) override;
KisPropertiesConfigurationSP configuration() const override;
};
KisWdgOptionsQImageIO::KisWdgOptionsQImageIO(QWidget *parent)
: KisConfigWidget(parent)
{
setupUi(this);
imageQuality->setRange(1, 100, 0);
}
KisPropertiesConfigurationSP KisWdgOptionsQImageIO::configuration() const
{
KisPropertiesConfigurationSP cfg(new KisPropertiesConfiguration());
cfg->setProperty("quality", (int)imageQuality->value());
return cfg;
}
void KisWdgOptionsQImageIO::setConfiguration(const KisPropertiesConfigurationSP cfg)
{
imageQuality->setValue(cfg->getInt("quality", 75));
}
KisQImageIOExport::KisQImageIOExport(QObject *parent, const QVariantList &) : KisImportExportFilter(parent)
{
}
......@@ -43,11 +76,16 @@ KisQImageIOExport::~KisQImageIOExport()
{
}
KisImportExportErrorCode KisQImageIOExport::convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP /*configuration*/)
KisImportExportErrorCode KisQImageIOExport::convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration)
{
QRect rc = document->savingImage()->bounds();
QImage image = document->savingImage()->projection()->convertToQImage(0, 0, 0, rc.width(), rc.height(), KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::internalConversionFlags());
bool result = image.save(io, QFileInfo(filename()).suffix().toLatin1());
int quality = -1;
if (configuration) {
quality = configuration->getInt("quality", -1);
}
bool result = image.save(io, QFileInfo(filename()).suffix().toLatin1(), quality);
if (result) {
return ImportExportCodes::OK;
}
......@@ -65,5 +103,25 @@ void KisQImageIOExport::initializeCapabilities()
addCapability(KisExportCheckRegistry::instance()->get("ColorModelPerLayerCheck/" + RGBAColorModelID.id() + "/" + Integer8BitsColorDepthID.id())->create(KisExportCheckBase::SUPPORTED));
}
KisConfigWidget *KisQImageIOExport::createConfigurationWidget(QWidget *parent, const QByteArray& /*from*/, const QByteArray& /*to*/) const
{
if (mimeType() == "image/webp") {
return new KisWdgOptionsQImageIO(parent);
}
return 0;
}
KisPropertiesConfigurationSP KisQImageIOExport::defaultConfiguration(const QByteArray &, const QByteArray &) const
{
if (mimeType() == "image/webp") {
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
// the Qt webp plugin chooses 75 when passing -1 (default argument) to QImage::save()
cfg->setProperty("quality", 75);
return cfg;
}
return 0;
}
#include "kis_qimageio_export.moc"
......@@ -30,8 +30,10 @@ class KisQImageIOExport : public KisImportExportFilter
public:
KisQImageIOExport(QObject *parent, const QVariantList &);
~KisQImageIOExport() override;
public:
KisImportExportErrorCode convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration = 0) override;
KisConfigWidget *createConfigurationWidget(QWidget *parent, const QByteArray& from, const QByteArray& to) const override;
KisPropertiesConfigurationSP defaultConfiguration(const QByteArray &, const QByteArray &) const override;
void initializeCapabilities() override;
};
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>KisWdgOptionsQImageIO</class>
<widget class="QWidget" name="KisWdgOptionsQImageIO">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>489</width>
<height>70</height>
</rect>
</property>
<property name="windowTitle">
<string>WebP Options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="2">
<widget class="QLabel" name="textLabel3">
<property name="whatsThis">
<string>&lt;p&gt;Adjust the compression time. Better compression takes longer.
&lt;br&gt;Note: the compression level does not change the quality of the result.&lt;/p&gt;</string>
</property>
<property name="text">
<string comment="The compression will take a long time; saving the file will be slow.">Highest quality</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="textLabel2">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="whatsThis">
<string>&lt;p&gt;Adjust the compression time. Better compression takes longer.
&lt;br&gt;Note: the compression level does not change the quality of the result.&lt;/p&gt;</string>
</property>
<property name="text">
<string comment="The file will save fast but will not be compressed a lot">Lowest quality</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="textLabel1">
<property name="toolTip">
<string>Note: 100 uses lossless compression, everything below is lossy.</string>
</property>
<property name="whatsThis">
<string>&lt;p&gt;Adjust image quality. The lower the quality, the more compression artifacts get introduced. &lt;br/&gt;Note: A quality of 100 switches to lossless compression similar to (but often more efficient than) PNG.&lt;/p&gt;</string>
</property>
<property name="text">
<string>Quality:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="KisDoubleSliderSpinBox" name="imageQuality" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Note: 100 uses lossless compression, everything below is lossy.</string>
</property>
<property name="whatsThis">
<string>&lt;p&gt;Adjust image quality. The lower the quality, the more compression artifacts get introduced. &lt;br/&gt;Note: A quality of 100 switches to lossless compression similar to (but often more efficient than) PNG.&lt;/p&gt;</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="spacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>414</width>
<height>16</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KisDoubleSliderSpinBox</class>
<extends>QWidget</extends>
<header>kis_slider_spin_box.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
......@@ -189,7 +189,8 @@ void SvgTextEditor::setShape(KoSvgTextShape *shape)
QMessageBox::warning(this, i18n("Conversion failed"), "Could not get svg text from the shape:\n" + converter.errors().join('\n') + "\n" + converter.warnings().join('\n'));
}
}
KisFontComboBoxes* fontComboBox = qobject_cast<KisFontComboBoxes*>(qobject_cast<QWidgetAction*>(actionCollection()->action("svg_font"))->defaultWidget());
fontComboBox->hasInitialized();
}
void SvgTextEditor::save()
......
......@@ -26,9 +26,11 @@
#include <QScrollBar>
#include <QCompleter>
#include <klocalizedstring.h>
#include <QDebug>
#include <kis_debug.h>
KisFontFamilyComboBox::KisFontFamilyComboBox(QWidget *parent)
:QComboBox(parent)
:QComboBox(parent), m_initilized(false)
{
setEditable(true);
completer()->setCompletionMode(QCompleter::InlineCompletion);
......@@ -98,6 +100,26 @@ void KisFontFamilyComboBox::refillComboBox(QVector<QFontDatabase::WritingSystem>
view()->setMinimumWidth(maxWidth);
}
void KisFontFamilyComboBox::setTopFont(const QString &family){
if(family.isEmpty() || !m_initilized)
return;
if(m_pinnedFonts.contains(family))
return;
if(m_pinnedFonts.count() > 4){
this->removeItem(4);
m_pinnedFonts.pop_back();
}
if(m_pinnedFonts.isEmpty())
this->insertSeparator(0);
m_pinnedFonts.push_front(family);
this->insertItem(0, family);
}
KisFontComboBoxes::KisFontComboBoxes(QWidget *parent)
:QWidget(parent)
......@@ -183,9 +205,13 @@ void KisFontComboBoxes::fontFamilyChanged()
m_styles->clear();
QStringList styles;
KisFontFamilyComboBox *cmb = qobject_cast<KisFontFamilyComboBox*>(m_family);
cmb->setTopFont(family);
if (fonts.styles(family).isEmpty()) {
styles.append("Normal");
}
Q_FOREACH(const QString style, fonts.styles(family)) {
int b = fonts.weight(family, style);
int bindex = 0;
......@@ -213,3 +239,9 @@ void KisFontComboBoxes::fontChange()
{
emit fontChanged(currentFont(10).toString());
}
void KisFontComboBoxes::hasInitialized()
{
KisFontFamilyComboBox *cmb = qobject_cast<KisFontFamilyComboBox*>(m_family);
cmb->hasInitialized();
}
......@@ -61,6 +61,8 @@ public:
QFont currentFont(int pointSize = 10) const;
void refillComboBox(QVector<QFontDatabase::WritingSystem> writingSystems = QVector<QFontDatabase::WritingSystem>());
void hasInitialized();
Q_SIGNALS:
void fontChanged(QString);
private Q_SLOTS:
......@@ -86,11 +88,13 @@ public:
//List of writing systems to use. If empty will default to "all"
void refillComboBox(QVector<QFontDatabase::WritingSystem> writingSystems = QVector<QFontDatabase::WritingSystem>());
void setTopFont(const QString &family);
inline void hasInitialized() { m_initilized = true; };
private:
QStringList m_blacklistedFonts;
private:
QStringList m_pinnedFonts, m_blacklistedFonts;
bool m_initilized;
};
#endif // KIS_FONT_FAMILY_COMBO_BOX_H