[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/krita
From: Boudewijn Rempt <boud () valdyas ! org>
Date: 2007-06-26 11:11:20
Message-ID: 1182856280.632550.28141.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 680490 by rempt:
Some work on mask and shape layers; start writing a unit test for
our shape controller.
M +2 -2 image/kis_image_view_converter.cpp
M +14 -2 image/kis_image_view_converter.h
M +2 -3 ui/kis_layer_shape.cc
M +26 -3 ui/kis_layermap_visitor.cc
M +10 -2 ui/kis_layermap_visitor.h
M +9 -0 ui/kis_mask_shape.h
M +53 -6 ui/kis_shape_controller.cpp
M +8 -1 ui/kis_shape_controller.h
M +0 -5 ui/kis_shape_layer.cc
M +5 -1 ui/kis_shape_layer.h
M +1 -1 ui/kis_shape_layer_canvas.cpp
M +12 -0 ui/tests/CMakeLists.txt
M +2 -2 ui/tests/kis_layer_model_test.cpp
M +1 -1 ui/tests/kis_layer_model_test.h
A ui/tests/kis_shape_controller_test.cpp [License: GPL (v2+)]
A ui/tests/kis_shape_controller_test.h [License: GPL (v2+)]
--- trunk/koffice/krita/image/kis_image_view_converter.cpp #680489:680490
@@ -19,8 +19,8 @@
// #include <kdebug.h>
-KisImageViewConverter::KisImageViewConverter(const KisImage *image)
-: m_image(image)
+KisImageViewConverter::KisImageViewConverter(const KisImageSP image)
+ : m_image(image)
{
Q_ASSERT(image);
}
--- trunk/koffice/krita/image/kis_image_view_converter.h #680489:680490
@@ -22,6 +22,7 @@
#include <krita_export.h>
#include "kis_image.h"
+#include "kis_types.h"
#include <KoViewConverter.h>
/**
@@ -37,32 +38,43 @@
* constructor
* @param image the image this viewConver works for.
*/
- KisImageViewConverter( const KisImage *image );
+ KisImageViewConverter( const KisImageSP image );
+
/// convert from flake to krita units
QPointF documentToView( const QPointF &documentPoint ) const;
+
/// convert from krita to flake units
QPointF viewToDocument( const QPointF &viewPoint ) const;
+
/// convert from flake to krita units
QRectF documentToView( const QRectF &documentRect ) const;
+
/// convert from krita to flake units
QRectF viewToDocument( const QRectF &viewRect ) const;
+
/// convert from krita to flake units
QSizeF documentToView( const QSizeF& documentSize ) const;
+
/// convert from krita to flake units
QSizeF viewToDocument( const QSizeF& viewSize ) const;
+
/// convert from flake to krita units
inline double documentToViewX( double documentX ) const { return documentX * \
m_image->xRes(); } +
/// convert from flake to krita units
inline double documentToViewY( double documentY ) const { return documentY * \
m_image->yRes(); } +
/// convert from krita to flake units
inline double viewToDocumentX( double viewX ) const { return viewX / \
m_image->xRes(); } +
/// convert from krita to flake units
inline double viewToDocumentY( double viewY ) const { return viewY / \
m_image->yRes(); } +
/// reimplemented from superclass
void zoom(double *zoomX, double *zoomY) const;
private:
- const KisImage *m_image;
+ const KisImageSP m_image;
};
#endif
--- trunk/koffice/krita/ui/kis_layer_shape.cc #680489:680490
@@ -18,8 +18,6 @@
#include "kis_layer_shape.h"
-
-
#include <kis_types.h>
#include <kis_layer.h>
#include <kis_image.h>
@@ -121,6 +119,7 @@
// TODO
}
-bool KisLayerShape::loadOdf( const KoXmlElement & element, KoShapeLoadingContext \
&context ) { +bool KisLayerShape::loadOdf( const KoXmlElement & element, \
KoShapeLoadingContext &context ) +{
return false; // TODO
}
--- trunk/koffice/krita/ui/kis_layermap_visitor.cc #680489:680490
@@ -31,10 +31,12 @@
#include <kis_shape_layer.h>
#include <kis_layer_container_shape.h>
#include <kis_group_layer.h>
+#include <kis_mask_shape.h>
#include <kis_adjustment_layer.h>
-KisLayerMapVisitor::KisLayerMapVisitor(QMap<KisLayerSP, KoShape*> & layerMap)
+KisLayerMapVisitor::KisLayerMapVisitor(QMap<KisLayerSP, KoShape*> & layerMap, \
QMap<KisMaskSP, KoShape*> & maskMap) : m_layerMap( layerMap )
+ , m_maskMap( maskMap )
{
}
@@ -43,6 +45,12 @@
return m_layerMap;
}
+QMap<KisMaskSP, KoShape*> & KisLayerMapVisitor::maskMap()
+{
+ return m_maskMap;
+}
+
+
bool KisLayerMapVisitor::visit( KisExternalLayer * layer)
{
// kDebug(41007) << "KisLayerMap visitor adding external layer: " << \
layer->name() << endl; @@ -52,6 +60,7 @@
return false;
}
m_layerMap[layer] = layerShape;
+ fillMaskMap( layer, layerShape );
return true;
}
@@ -66,7 +75,7 @@
KoShapeContainer * parent = static_cast<KoShapeContainer*>( \
m_layerMap[layer->parentLayer()] ); KisLayerShape * layerShape = new KisLayerShape( \
parent, layer ); m_layerMap[layer] = layerShape;
-
+ fillMaskMap( layer, layerShape );
return true;
}
return false;
@@ -90,6 +99,7 @@
child = child->nextSibling();
}
+ fillMaskMap( layer, layerContainer );
return true;
}
@@ -104,10 +114,23 @@
parent = static_cast<KoShapeContainer*>( m_layerMap[layer->parentLayer()] );
KisLayerShape * layerShape = new KisLayerShape( parent, layer );
m_layerMap[layer] = layerShape;
-
+ fillMaskMap( layer, layerShape );
return true;
}
return false;
}
+
+void KisLayerMapVisitor::fillMaskMap( KisLayerSP layer, KoShapeContainer * container \
) +{
+ if ( !layer->hasEffectMasks() ) return;
+
+ QList<KisMaskSP> masks = layer->effectMasks();
+ for ( int i = 0; i < masks.size(); ++i ) {
+ KisMaskSP mask = masks.at( i );
+ KisMaskShape * maskShape = new KisMaskShape( container, mask );
+ container->addChild( maskShape );
+ m_maskMap[mask] = maskShape;
+ }
+}
--- trunk/koffice/krita/ui/kis_layermap_visitor.h #680489:680490
@@ -34,12 +34,14 @@
public:
/**
- * @param layerMap: the map that maps layers to layer shapes
+ * @param layerMap: the map that maps layers to layer shapes and
+ * masks to mask shapes.
*/
- KisLayerMapVisitor(QMap<KisLayerSP, KoShape*> & layerMap);
+ KisLayerMapVisitor(QMap<KisLayerSP, KoShape*> & layerMap, QMap<KisMaskSP, \
KoShape*> & maskMap); virtual ~KisLayerMapVisitor() {}
QMap<KisLayerSP, KoShape*> & layerMap();
+ QMap<KisMaskSP, KoShape*> & maskMap();
public:
@@ -50,9 +52,15 @@
bool visit(KisGroupLayer *layer);
bool visit(KisAdjustmentLayer *layer);
+
private:
+ void fillMaskMap( KisLayerSP layer, KoShapeContainer * container );
+
+private:
+
QMap<KisLayerSP, KoShape*> m_layerMap;
+ QMap<KisMaskSP, KoShape*> m_maskMap;
};
--- trunk/koffice/krita/ui/kis_mask_shape.h #680489:680490
@@ -56,7 +56,16 @@
}
bool isSelectable() const { return false; }
+ bool loadOdf( const KoXmlElement&, KoShapeLoadingContext&)
+ {
+ return false;
+ }
+ void saveOdf( KoShapeSavingContext& ) const
+ {
+ }
+
+
private:
class Private;
--- trunk/koffice/krita/ui/kis_shape_controller.cpp #680489:680490
@@ -44,13 +44,14 @@
#include "kis_view2.h"
typedef QMap<KisLayerSP, KoShape*> KisLayerMap;
+typedef QMap<KisMaskSP, KoShape*> KisMaskMap;
-
class KisShapeController::Private
{
public:
KisImageSP image;
KisLayerMap layerShapes; // maps from krita/image layers to shapes
+ KisMaskMap maskShapes; // maps from krita/image masks to shapes
KisDoc2 * doc;
KisNameServer * nameServer;
};
@@ -68,6 +69,7 @@
KisShapeController::~KisShapeController()
{
kDebug(41007) << "Deleting the KisShapeController. There are " << \
m_d->layerShapes.size() << " shapes" << endl; + kDebug(41007) << "Deleting the \
KisShapeController. There are " << m_d->maskShapes.size() << " masks" << endl; /*
foreach( KoShape* shape, m_d->layerShapes ) {
removeShape( shape);
@@ -91,19 +93,33 @@
}
m_d->layerShapes.clear();
+
+ foreach( KoShape* shape, m_d->maskShapes ) {
+ removeShape( shape );
+ delete shape; // XXX: What happes with stuff on the
+ // clipboard? And how about undo information?
+
+ }
+ m_d->maskShapes.clear();
}
+
+
m_d->image = image;
- KisLayerMapVisitor v( m_d->layerShapes );
+ KisLayerMapVisitor v( m_d->layerShapes, m_d->maskShapes );
m_d->image->rootLayer()->accept( v );
m_d->layerShapes = v.layerMap();
+ m_d->maskShapes = v.maskMap();
foreach( KoView *view, m_d->doc->views() ) {
KisCanvas2 *canvas = ((KisView2*)view)->canvasBase();
foreach( KoShape* shape, m_d->layerShapes ) {
canvas->shapeManager()->add(shape);
}
+ foreach( KoShape* shape, m_d->maskShapes ) {
+ canvas->shapeManager()->add( shape );
+ }
canvas->canvasWidget()->update();
}
@@ -170,15 +186,17 @@
// KisShapeLayer::KoShapeLayer::KoShapeContainer::KoShape.
KisShapeLayer * shapeLayer = dynamic_cast<KisShapeLayer*>( shape->parent() \
); + kDebug() << "shape: " << shape << endl;
+ kDebug() << "shape parent: " << shape->parent() << endl;
+ kDebug() << "shape layer: " << shapeLayer << endl;
-//TODO this needs to be checked
-#if 0
if ( !shapeLayer ) {
// There is no parent layer set, which means that when
// dropping, there was no shape layer active. Create one
// and add it on top of the image stack.
KisLayerContainerShape * container = \
dynamic_cast<KisLayerContainerShape*>( m_d->image->rootLayer().data() ); + \
kDebug() << "container: " << container << endl; shapeLayer = new \
KisShapeLayer(container, m_d->image,
i18n( "Flake shapes %1", \
m_d->nameServer->number() ), @@ -191,12 +209,13 @@
m_d->image->addLayer( shapeLayer, m_d->image->rootLayer());
}
-#endif
+ // XXX: What happens if the shape is added embedded in another
+ // shape?
if ( shapeLayer )
shapeLayer->addChild( shape );
}
else {
- kDebug() << "Eeek -- we tried to add a krita layer shape without going \
through KisImage" << endl; + kWarning() << "Eeek -- we tried to add a krita \
layer shape without going through KisImage" << endl; }
m_d->doc->setModified( true );
@@ -302,4 +321,32 @@
}
}
+
+void KisShapeController::slotMaskAdded( KisMaskSP mask )
+{
+ if ( m_d->maskShapes.contains( mask ) ) {
+ kWarning() << "KisShapeController::slotAddedMask: mask " << mask << " is \
already in the map\n"; + return;
+ }
+
+ KoShapeContainer * parent = dynamic_cast<KoShapeContainer*>( shapeForLayer( \
mask->parentLayer() ) ); + if ( parent ) {
+ KisMaskShape * maskShape = new KisMaskShape( parent, mask );
+ m_d->maskShapes[mask] = maskShape;
+ parent->addChild( maskShape );
+ }
+}
+
+void KisShapeController::slotMaskRemoved( KisMaskSP mask, KisLayerSP wasParent, \
KisMaskSP wasAboveThis ) +{
+}
+
+void KisShapeController::slotMaskMoved( KisMaskSP mask, KisLayerSP previousParent, \
KisMaskSP wasAboveThis ) +{
+}
+
+void KisShapeController::slotMasksChanged( KisLayerSP layer )
+{
+}
+
#include "kis_shape_controller.moc"
--- trunk/koffice/krita/ui/kis_shape_controller.h #680489:680490
@@ -23,18 +23,20 @@
#include <KoShapeControllerBase.h>
#include "kis_types.h"
+#include <krita_export.h>
class KoShape;
class KisView2;
class KisDoc2;
class KisNameServer;
+
/**
* KisShapeController keeps track of new layers, shapes, masks and
* selections -- everything that needs to be wrapped as a shape for
* the tools to work on.
*/
-class KisShapeController : public QObject, public KoShapeControllerBase {
+class KRITAUI_EXPORT KisShapeController : public QObject, public \
KoShapeControllerBase {
Q_OBJECT
@@ -60,6 +62,11 @@
void slotLayerMoved( KisLayerSP layer, KisGroupLayerSP previousParent, \
KisLayerSP wasAboveThis ); void slotLayersChanged( KisGroupLayerSP rootLayer );
+ void slotMaskAdded( KisMaskSP mask );
+ void slotMaskRemoved( KisMaskSP mask, KisLayerSP wasParent, KisMaskSP \
wasAboveThis ); + void slotMaskMoved( KisMaskSP mask, KisLayerSP previousParent, \
KisMaskSP wasAboveThis ); + void slotMasksChanged( KisLayerSP layer );
+
private:
class Private;
--- trunk/koffice/krita/ui/kis_shape_layer.cc #680489:680490
@@ -106,11 +106,6 @@
void KisShapeLayer::updateProjection(const QRect& r)
{
kDebug(41001) << "KisShapeLayer::updateProjection()" << r << endl;
-
- // XXX: Is r in document, widget or pixel coordinates? I hope in
- // document coordinates. Note: see dox for updateCanvas.
-
- setDirty( r ); // Convert to right coordinates
}
KisPaintDeviceSP KisShapeLayer::projection() const
--- trunk/koffice/krita/ui/kis_shape_layer.h #680489:680490
@@ -70,7 +70,11 @@
// KisExternalLayer implementation
QIcon icon() const;
- // Keep the projection up to date
+ /**
+ * Keep the projection up to date.
+ *
+ * @param r the rect that needs to be updated in pixel coordinates
+ */
void updateProjection(const QRect& r);
// Retrieve the projection for
--- trunk/koffice/krita/ui/kis_shape_layer_canvas.cpp #680489:680490
@@ -78,7 +78,7 @@
void KisShapeLayerCanvas::updateCanvas(const QRectF& rc)
{
- kDebug(41001) << "KisShapeLayerCanvas::updateCanvas()" << endl;
+ kDebug(41001) << "KisShapeLayerCanvas::updateCanvas()" << rc << endl;
QRect r = m_viewConverter->documentToView(rc).toRect();
r.adjust(-2, -2, 2, 2); // for antialias
--- trunk/koffice/krita/ui/tests/CMakeLists.txt #680489:680490
@@ -15,6 +15,18 @@
add_test(krita-ui-kis_layer_model_test kis_layer_model_test)
+########### next target ###############
+
+set(kis_shape_controller_test_SRCS kis_shape_controller_test.cpp )
+
+kde4_automoc(${kis_shape_controller_test_SRCS})
+
+kde4_add_executable(kis_shape_controller_test RUN_UNINSTALLED \
${kis_shape_controller_test_SRCS}) +
+target_link_libraries(kis_shape_controller_test ${KDE4_KDEUI_LIBS} koguiutils \
komain kritaimage kritaui ${QT_QTTEST_LIBRARY}) +
+add_test(krita-ui-kis_shape_controller_test kis_shape_controller_test)
+
########### end ###############
endif(KDE4_BUILD_TESTS)
--- trunk/koffice/krita/ui/tests/kis_layer_model_test.cpp #680489:680490
@@ -1,5 +1,5 @@
- /*
- * Copyright (C) Adrian Page <adrian@pagenet.plus.com>, (C) 2007
+/*
+ * Copyright (C) 2007 Boudewijn Rempt <boud@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
--- trunk/koffice/krita/ui/tests/kis_layer_model_test.h #680489:680490
@@ -1,5 +1,5 @@
/*
- * Copyright (C) Adrian Page <adrian@pagenet.plus.com>, (C) 2007
+ * Copyright (C) 2007 Boudewijn Rempt <boud@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic