Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit ff066882 authored by Casper Boemann's avatar Casper Boemann

change TransformVisitor into using the

KisPaintDeviceVisitor as base class


svn path=/trunk/koffice/; revision=444356
parent 15baa998
......@@ -570,12 +570,6 @@ void KisPaintDevice::accept(KisRotateVisitor& visitor)
visitor.visitKisPaintDevice(this);
}
void KisPaintDevice::accept(KisTransformVisitor& visitor)
{
visitor.visitKisPaintDevice(this);
}
void KisPaintDevice::scale(double xscale, double yscale, KisProgressDisplayInterface * progress, KisFilterStrategy *filterStrategy)
{
KisScaleVisitor visitor;
......@@ -597,15 +591,6 @@ void KisPaintDevice::shear(double angleX, double angleY, KisProgressDisplayInter
visitor.shear(angleX, angleY, progress);
}
void KisPaintDevice::transform(double xscale, double yscale,
double xshear, double yshear, double rotation,
Q_INT32 xtranslate, Q_INT32 ytranslate, KisProgressDisplayInterface *progress, KisFilterStrategy *filterStrategy)
{
KisTransformVisitor visitor;
accept(visitor);
visitor.transform(xscale, yscale, xshear, yshear, rotation, xtranslate, ytranslate, progress, filterStrategy);
}
void KisPaintDevice::mirrorX()
{
QRect r;
......
......@@ -50,7 +50,6 @@ class KisHLineIteratorPixel;
class KNamedCommand;
class KisRotateVisitor;
class KisScaleVisitor;
class KisTransformVisitor;
class KisFilterStrategy;
/**
......@@ -301,9 +300,6 @@ public:
void scale(double sx, double sy, KisProgressDisplayInterface *m_progress, KisFilterStrategy *filterStrategy);
void rotate(double angle, bool rotateAboutImageCentre, KisProgressDisplayInterface *m_progress);
void shear(double angleX, double angleY, KisProgressDisplayInterface *m_progress);
void transform(double xscale, double yscale,
double xshear, double yshear, double rotation,
Q_INT32 xtranslate, Q_INT32 ytranslate, KisProgressDisplayInterface *m_progress, KisFilterStrategy *filterStrategy);
/**
* Mirror the device along the X axis
......@@ -401,7 +397,6 @@ private:
void accept(KisScaleVisitor &);
void accept(KisRotateVisitor &);
void accept(KisTransformVisitor &);
// Whether the selection is active
bool m_hasSelection;
......
......@@ -27,6 +27,22 @@
#include "kis_iterators_pixel.h"
#include "kis_filter_strategy.h"
KisTransformVisitor::KisTransformVisitor(double xscale, double yscale,
double xshear, double yshear, double rotation,
Q_INT32 xtranslate, Q_INT32 ytranslate,
KisProgressDisplayInterface *progress, KisFilterStrategy *filter)
{
m_xscale = xscale;
m_yscale = yscale;
m_xshear = xshear;
m_yshear = yshear;
m_rotation = rotation,
m_xtranslate = xtranslate;
m_ytranslate = ytranslate;
m_progress = progress;
m_filter = filter;
}
void KisTransformVisitor::rotateRight90(KisPaintDeviceSP src, KisPaintDeviceSP dst)
{
KisSelectionSP dstSelection;
......@@ -341,26 +357,31 @@ printf(" )=%d\n",sum);
delete [] weight;
}
void KisTransformVisitor::transform(double xscale, double yscale,
double xshear, double yshear, double rotation,
Q_INT32 xtranslate, Q_INT32 ytranslate,
KisProgressDisplayInterface *progress, KisFilterStrategy *filterStrategy)
bool KisTransformVisitor::visit(KisPainter &gc, KisPaintDevice *dev)
{
//progress info
m_cancelRequested = false;
progress -> setSubject(this, true, true);
m_progress -> setSubject(this, true, true);
m_progressTotalSteps = 0;
m_progressStep = 0;
QRect r;
if(m_dev->hasSelection())
r = m_dev->selection()->selectedExactRect();
if(dev->hasSelection())
r = dev->selection()->selectedExactRect();
else
r = m_dev->exactBounds();
r = dev->exactBounds();
KisPaintDeviceSP tmpdev1 = new KisPaintDevice(m_dev->colorStrategy(),"temporary");;
KisPaintDeviceSP tmpdev2 = new KisPaintDevice(m_dev->colorStrategy(),"temporary");;
KisPaintDeviceSP srcdev = m_dev;
KisPaintDeviceSP tmpdev1 = new KisPaintDevice(dev->colorStrategy(),"temporary");;
KisPaintDeviceSP tmpdev2 = new KisPaintDevice(dev->colorStrategy(),"temporary");;
KisPaintDeviceSP srcdev = dev;
double xscale = m_xscale;
double yscale = m_yscale;
double xshear = m_xshear;
double yshear = m_yshear;
double rotation = m_rotation;
Q_INT32 xtranslate = m_xtranslate;
Q_INT32 ytranslate = m_ytranslate;
int rotQuadrant = int(rotation /(M_PI/2) + 0.5);
double tmp;
switch(rotQuadrant)
......@@ -400,12 +421,23 @@ void KisTransformVisitor::transform(double xscale, double yscale,
QTime time;
time.start();
transformPass <KisVLineIteratorPixel>(srcdev, tmpdev2, yscale, yshear, ytranslate, filterStrategy);
if ( m_cancelRequested) {
emit notifyProgressDone(this);
return false;
}
transformPass <KisVLineIteratorPixel>(srcdev, tmpdev2, yscale, yshear, ytranslate, m_filter);
printf("time taken first pass %d\n",time.restart());
if(m_dev->hasSelection())
m_dev->selection()->clear();
if(dev->hasSelection())
dev->selection()->clear();
printf("time taken to clear selection %d\n",time.restart());
transformPass <KisHLineIteratorPixel>(tmpdev2, m_dev, xscale, xshear, xtranslate, filterStrategy);
if ( m_cancelRequested) {
emit notifyProgressDone(this);
return false;
}
transformPass <KisHLineIteratorPixel>(tmpdev2, dev, xscale, xshear, xtranslate, m_filter);
printf("time taken second pass %d\n",time.elapsed());
printf("%d %d\n",xtranslate, ytranslate);
......@@ -415,5 +447,5 @@ printf("%f\n",rotation);
//progress info
emit notifyProgressDone(this);
return;
return m_cancelRequested;
}
......@@ -22,6 +22,7 @@
#include "kis_types.h"
#include "kis_progress_subject.h"
#include "kis_paint_device_visitor.h"
class KisPaintDevice;
class KisProgressDisplayInterface;
......@@ -29,21 +30,58 @@ class KisHLineIteratorPixel;
class KisVLineIteratorPixel;
class KisFilterStrategy;
class KisTransformVisitor : public KisProgressSubject {
class KisTransformVisitor : public KisProgressSubject, KisPaintDeviceVisitor {
typedef KisProgressSubject super;
public:
KisTransformVisitor();
~KisTransformVisitor();
void visitKisPaintDevice(KisPaintDevice* dev);
void transform(double xscale, double yscale,
KisTransformVisitor(double xscale, double yscale,
double xshear, double yshear, double rotation,
Q_INT32 xtranslate, Q_INT32 ytranslate,
KisProgressDisplayInterface *progress, KisFilterStrategy *filter);
~KisTransformVisitor();
public:
virtual bool visit(KisPainter& gc, KisPaintDeviceSP dev)
{
visit(gc, dev);
return true;
}
virtual bool visit(KisPainter& gc, vKisPaintDeviceSP& devs)
{
for (Q_INT32 i = devs.size() - 1; i >= 0; i--)
visit(gc, devs[i]);
return true;
}
virtual bool visit(KisPainter& gc, vKisLayerSP& layers)
{
for (Q_INT32 i = layers.size() - 1; i >= 0; i--) {
KisLayerSP& layer = layers[i];
visit(gc, layer.data());
}
return true;
}
virtual bool visit(KisPainter& gc, KisLayerSP layer)
{
visit(gc, layer.data());
return true;
}
virtual bool visit(KisPainter& gc, KisSelectionSP selection)
{
visit(gc, selection.data());
return true;
}
private:
bool visit(KisPainter& gc, KisPaintDevice *dev);
// XXX (BSAR): Why didn't we use the shared-pointer versions of the paint device classes?
template <class T> void transformPass(KisPaintDevice *src, KisPaintDevice *dst, double xscale, double shear, Q_INT32 dx, KisFilterStrategy *filterStrategy);
......@@ -52,7 +90,11 @@ private:
void rotate180(KisPaintDeviceSP src, KisPaintDeviceSP dst);
private:
KisPaintDevice* m_dev;
double m_xscale, m_yscale;
double m_xshear, m_yshear, m_rotation;
Q_INT32 m_xtranslate, m_ytranslate;
KisProgressDisplayInterface *m_progress;
KisFilterStrategy *m_filter;
// Implement KisProgressSubject
bool m_cancelRequested;
virtual void cancel() { m_cancelRequested = true; }
......@@ -60,16 +102,9 @@ private:
Q_INT32 m_progressStep;
};
inline KisTransformVisitor::KisTransformVisitor()
{
}
inline KisTransformVisitor::~KisTransformVisitor()
{
}
inline void KisTransformVisitor::visitKisPaintDevice(KisPaintDevice* dev)
{
m_dev = dev;
}
#endif // KIS_TRANSFORM_VISITOR_H_
......@@ -49,6 +49,7 @@
#include <kis_cmb_idlist.h>
#include <kis_id.h>
#include <kis_tool_controller.h>
#include <kis_transform_visitor.h>
#include "kis_tool_transform.h"
#include "wdg_tool_transform.h"
......@@ -649,8 +650,10 @@ printf("%f %f\n",tx,ty);
}
m_transaction = new TransformCmd(img->activeLayer().data());
Q_CHECK_PTR(m_transaction);
img->activeLayer()->transform(m_scaleX, m_scaleY, 0, 0, m_a, int(tx), int(ty), progress, m_filter);
KisTransformVisitor t(m_scaleX, m_scaleY, 0, 0, m_a, int(tx), int(ty), progress, m_filter);
KisPainter gc(img->activeLayer());
t.visit(gc, img->activeLayer());
QRect rc = img->activeLayer()->extent();
rc = rc.normalize();
......
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