Commit 596c2c22 authored by Halla Rempt's avatar Halla Rempt
Browse files

Port the file layer fixes to master

CCBUG:328906

This contains:

commit 8d1a936d
Author: Boudewijn Rempt <boud@valdyas.org>
Date:   Wed Dec 18 14:03:46 2013 +0100

    BUG:328906 Fix scaling of file layer

commit 0ff91ca0
Author: Boudewijn Rempt <boud@valdyas.org>
Date:   Wed Dec 18 13:48:30 2013 +0100

    Fix crash on loading a file layer

    CCBUG:328906

commit de1b6ccc
Author: Boudewijn Rempt <boud@valdyas.org>
Date:   Wed Dec 18 12:45:54 2013 +0100

    BUG:328906 Fix scaling method labels for file layer dialog
parent fea27275
......@@ -79,6 +79,7 @@ void SpecificColorSelectorDock::unsetCanvas()
void SpecificColorSelectorDock::layerChanged(const KisNodeSP node)
{
if (!node) return;
if (!node->paintDevice()) return;
if (!m_colorSelector) return;
if (!m_colorSelector->customColorSpaceUsed()) {
const KoColorSpace *cs = node->paintDevice() ?
......
......@@ -37,6 +37,7 @@
#include <kis_paint_device.h>
#include <kis_transaction.h>
#include <kis_node.h>
#include <kis_file_layer.h>
KisDlgFileLayer::KisDlgFileLayer(const QString &basePath, const QString & name, QWidget * parent)
: KDialog(parent)
......@@ -70,9 +71,17 @@ QString KisDlgFileLayer::layerName() const
return dlgWidget.txtLayerName->text();
}
bool KisDlgFileLayer::scaleToImageResolution() const
KisFileLayer::ScalingMethod KisDlgFileLayer::scaleToImageResolution() const
{
return dlgWidget.chkScaleToImageResolution->isChecked();
if (dlgWidget.radioDontScale->isChecked()) {
return KisFileLayer::None;
}
else if (dlgWidget.radioScaleToImageSize->isChecked()) {
return KisFileLayer::ToImageSize;
}
else {
return KisFileLayer::ToImagePPI;
}
}
QString KisDlgFileLayer::fileName() const
......
......@@ -27,6 +27,8 @@ class QGroupBox;
class KisConfigWidget;
class KLineEdit;
#include <kis_file_layer.h>
#include "ui_wdgdlgfilelayer.h"
/**
......@@ -48,7 +50,7 @@ public:
KisDlgFileLayer(const QString &basePath, const QString &name, QWidget *parent = 0);
QString fileName() const;
QString layerName() const;
bool scaleToImageResolution() const;
KisFileLayer::ScalingMethod scaleToImageResolution() const;
protected slots:
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>440</width>
<height>120</height>
<width>400</width>
<height>196</height>
</rect>
</property>
<property name="minimumSize">
......@@ -16,10 +16,7 @@
<height>0</height>
</size>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
......@@ -64,13 +61,36 @@
</layout>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="chkScaleToImageResolution">
<property name="text">
<string>Scale To Image Resolution</string>
</property>
<property name="checked">
<bool>true</bool>
<widget class="QGroupBox" name="grpScalingOptions">
<property name="title">
<string>Scaling Options</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QRadioButton" name="radioDontScale">
<property name="text">
<string>No Scaling</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="radioScaleToImageSize">
<property name="text">
<string>Scale to Image SIze</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="radioScalePPI">
<property name="text">
<string>Adapt to Image Resolution (ppi)</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
......
......@@ -23,15 +23,16 @@
#include "kis_filter_strategy.h"
#include "kis_node_progress_proxy.h"
#include "kis_node_visitor.h"
#include "kis_image.h"
#include <KoProgressUpdater.h>
#include <KoProgressProxy.h>
KisFileLayer::KisFileLayer(KisImageWSP image, const QString &basePath, const QString &filename, bool scaleToImageResolution, const QString &name, quint8 opacity)
KisFileLayer::KisFileLayer(KisImageWSP image, const QString &basePath, const QString &filename, ScalingMethod scaleToImageResolution, const QString &name, quint8 opacity)
: KisExternalLayer(image, name, opacity)
, m_basePath(basePath)
, m_filename(filename)
, m_scaleToImageResolution(scaleToImageResolution)
, m_scalingMethod(scaleToImageResolution)
{
connect(&m_loader, SIGNAL(loadingFinished()), SLOT(slotLoadingFinished()));
m_loader.setPath(path());
......@@ -49,7 +50,7 @@ KisFileLayer::KisFileLayer(const KisFileLayer &rhs)
m_filename = rhs.m_filename;
Q_ASSERT(QFile::exists(rhs.path()));
m_scaleToImageResolution = rhs.m_scaleToImageResolution;
m_scalingMethod = rhs.m_scalingMethod;
connect(&m_loader, SIGNAL(loadingFinished()), SLOT(slotLoadingFinished()));
m_loader.setPath(path());
......@@ -107,27 +108,28 @@ QString KisFileLayer::path() const
}
}
void KisFileLayer::setScaleToImageResolution(bool scale)
KisFileLayer::ScalingMethod KisFileLayer::scalingMethod() const
{
m_scaleToImageResolution = scale;
m_loader.reloadImage();
}
bool KisFileLayer::scaleToImageResolution() const
{
return m_scaleToImageResolution;
return m_scalingMethod;
}
void KisFileLayer::slotLoadingFinished()
{
KisImageWSP importedImage = m_loader.image();
m_image = importedImage->projection();
if (m_scaleToImageResolution && (image()->xRes() != importedImage->xRes()
|| image()->yRes() != importedImage->yRes()))
{
if (m_scalingMethod == ToImagePPI && (image()->xRes() != importedImage->xRes()
|| image()->yRes() != importedImage->yRes())) {
qreal xscale = image()->xRes() / importedImage->xRes();
qreal yscale = image()->yRes() / importedImage->yRes();
KisTransformWorker worker(m_image, xscale, yscale, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, KisFilterStrategyRegistry::instance()->get("Bicubic"));
worker.run();
}
else if (m_scalingMethod == ToImageSize) {
QSize sz = importedImage->size();
sz.scale(image()->size(), Qt::KeepAspectRatio);
qreal xscale = sz.width() / importedImage->width();
qreal yscale = sz.height() / importedImage->height();
KisTransformWorker worker(m_image, xscale, yscale, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, KisFilterStrategyRegistry::instance()->get("Bicubic"));
worker.run();
}
......
......@@ -23,6 +23,7 @@
class KisPart2;
/**
* @brief The KisFileLayer class loads a particular file as a layer into the layer stack.
*/
......@@ -30,7 +31,14 @@ class KisFileLayer : public KisExternalLayer
{
Q_OBJECT
public:
explicit KisFileLayer(KisImageWSP image, const QString& basePath, const QString &filename, bool scaleToImageResolution, const QString &name, quint8 opacity);
enum ScalingMethod {
None,
ToImageSize,
ToImagePPI
};
explicit KisFileLayer(KisImageWSP image, const QString& basePath, const QString &filename, ScalingMethod scalingMethod, const QString &name, quint8 opacity);
~KisFileLayer();
KisFileLayer(const KisFileLayer& rhs);
......@@ -45,8 +53,8 @@ public:
void setFileName(const QString &basePath, const QString &filename);
QString fileName() const;
QString path() const;
void setScaleToImageResolution(bool scale);
bool scaleToImageResolution() const;
ScalingMethod scalingMethod() const;
KisNodeSP clone() const;
bool allowAsChild(KisNodeSP) const;
......@@ -60,7 +68,7 @@ public slots:
private:
QString m_basePath;
QString m_filename;
bool m_scaleToImageResolution;
ScalingMethod m_scalingMethod;
KisPaintDeviceSP m_image;
KisSafeDocumentLoader m_loader;
......
......@@ -874,10 +874,10 @@ void KisLayerManager::addFileLayer(KisNodeSP activeNode)
return;
}
bool scaleToImageResolution = dlg.scaleToImageResolution();
KisFileLayer::ScalingMethod scalingMethod = dlg.scaleToImageResolution();
addLayerCommon(activeNode,
new KisFileLayer(image, basePath, fileName, scaleToImageResolution, name, OPACITY_OPAQUE_U8));
new KisFileLayer(image, basePath, fileName, scalingMethod, name, OPACITY_OPAQUE_U8));
}
}
......
......@@ -528,10 +528,19 @@ KisNodeSP KisKraLoader::loadFileLayer(const KoXmlElement& element, KisImageWSP i
QString filename = element.attribute("source", QString());
if (filename.isNull()) return 0;
bool scale = (element.attribute("scale", "true") == "true");
int scalingMethod = element.attribute("scalingmethod", "-1").toInt();
if (scalingMethod < 0) {
if (scale) {
scalingMethod = KisFileLayer::ToImagePPI;
}
else {
scalingMethod = KisFileLayer::None;
}
}
QString documentPath = m_d->document->url().toLocalFile();
QFileInfo info(documentPath);
KisLayer *layer = new KisFileLayer(image, info.absolutePath(), filename, scale, name, opacity);
KisLayer *layer = new KisFileLayer(image, info.absolutePath(), filename, (KisFileLayer::ScalingMethod)scalingMethod, name, opacity);
Q_CHECK_PTR(layer);
return layer;
......
......@@ -74,12 +74,21 @@ bool KisSaveXmlVisitor::visit(KisExternalLayer * layer)
QDomElement layerElement = m_doc.createElement(LAYER);
saveLayer(layerElement, FILE_LAYER, layer);
QString path = dynamic_cast<KisFileLayer*>(layer)->path();
KisFileLayer *fileLayer = dynamic_cast<KisFileLayer*>(layer);
QString path = fileLayer->path();
QDir d(QFileInfo(m_url).absolutePath());
layerElement.setAttribute("source", d.relativeFilePath(path));
layerElement.setAttribute("scale", dynamic_cast<KisFileLayer*>(layer)->scaleToImageResolution() ? "true" : "false");
if (fileLayer->scalingMethod() == KisFileLayer::ToImagePPI) {
layerElement.setAttribute("scale", "true");
}
else {
layerElement.setAttribute("scale", "false");
}
layerElement.setAttribute("scalingmethod", (int)fileLayer->scalingMethod());
layerElement.setAttribute(COLORSPACE_NAME, layer->original()->colorSpace()->id());
m_elem.appendChild(layerElement);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment