Commit e01a0e6b authored by Boudewijn Rempt's avatar Boudewijn Rempt

Big commit of a big refactor, and painting with any paintop but sumi-e is broken for now.

* move all brush stuff into new lib, libpaintop
* move all action recording to krita/image
* make a library with options for paintops to use and re-use.
* use paintop presets everywhere instead of paintop id + paintop settings (which was
giving bugs all over the place)


svn path=/trunk/koffice/; revision=849399
parent c03f57db
......@@ -58,14 +58,10 @@ set(kritaimage_LIB_SRCS
filter/kis_filter_config_widget.cc
filter/kis_filter_job.cpp
filter/kis_filter_registry.cc
kis_filter_strategy.cc
filter/kis_recorded_filter_action.cc
generator/kis_generator.cpp
generator/kis_generator_registry.cpp
generator/kis_generator_layer.cpp
kis_action_recorder.cc
generator/kis_generator_registry.cpp
kis_adjustment_layer.cc
kis_auto_brush.cpp
kis_autogradient_resource.cc
kis_base_node.cpp
kis_base_processor.cpp
......@@ -73,22 +69,19 @@ set(kritaimage_LIB_SRCS
kis_bookmarked_configuration_manager.cc
kis_bottom_up_update_strategy.cpp
kis_boundary.cc
kis_brush.cc
kis_brush_p.cc
kis_brush_registry.cpp
kis_clone_layer.cpp
kis_convolution_kernel.cc
kis_convolution_painter.cc
kis_effect_mask.cc
kis_fill_painter.cc
kis_filter_mask.cpp
kis_filter_strategy.cc
kis_gradient_painter.cc
kis_group_layer.cc
kis_histogram.cc
kis_image.cc
kis_iterator.cc
kis_layer.cc
kis_macro.cc
kis_mask.cc
kis_mask_generator.cc
kis_math_toolbox.cpp
......@@ -103,9 +96,9 @@ set(kritaimage_LIB_SRCS
kis_paint_information.cc
kis_paint_layer.cc
kis_paintop.cc
kis_paintop_preset.cpp
kis_paintop_registry.cc
kis_paintop_settings.cpp
kis_paintop_preset.cpp
kis_pattern.cc
kis_perspective_grid.cpp
kis_perspective_math.cpp
......@@ -116,21 +109,19 @@ set(kritaimage_LIB_SRCS
kis_random_accessor.cpp
kis_random_generator.cc
kis_random_sub_accessor.cpp
kis_recorded_action.cc
kis_recorded_action_factory_registry.cc
kis_rotate_visitor.cc
kis_selected_transaction.cc
kis_selection_transaction.cc
kis_selection.cc
kis_selection_mask.cpp
kis_selection_transaction.cc
kis_serializable_configuration.cc
kis_shared.cc
kis_threaded_applicator.cpp
kis_top_down_update_strategy.cpp
kis_transaction.cc
kis_transformation_mask.cpp
kis_transform_worker.cc
kis_transparency_mask.cc
kis_top_down_update_strategy.cpp
kis_undo_adapter.cc
kis_vec.cc
metadata/kis_meta_data_entry.cc
......@@ -145,6 +136,14 @@ set(kritaimage_LIB_SRCS
metadata/kis_meta_data_schema.cc
metadata/kis_meta_data_store.cc
metadata/kis_meta_data_value.cc
recorder/kis_action_recorder.cc
recorder/kis_macro.cc
recorder/kis_recorded_action.cc
recorder/kis_recorded_action_factory_registry.cc
recorder/kis_recorded_bezier_curve_paint_action.cpp
recorder/kis_recorded_filter_action.cpp
recorder/kis_recorded_paint_action.cpp
recorder/kis_recorded_polyline_paint_action.cpp
)
......@@ -161,12 +160,11 @@ install(TARGETS kritaimage DESTINATION ${LIB_INSTALL_DIR})
#install( FILES kis_debug.h kis_global.h kis_annotation.h
#kis_shared_ptr_vector.h kis_undo_adapter.h kis_progress_subject.h
#kis_progress_display_interface.h kis_adjustment_layer.h
# kis_autobrush_resource.h
#kis_autogradient_resource.h kis_boundary.h kis_brush.h
#kis_autogradient_resource.h kis_boundary.h
#kis_command.h kis_convolution_painter.h kis_fill_painter.h
#kis_filter.h kis_filter_registry.h kis_gradient.h
#kis_gradient_painter.h kis_histogram.h kis_image.h
#kis_imagepipe_brush.h kis_iterator.h kis_iterators_pixel.h
# kis_iterator.h kis_iterators_pixel.h
#kis_iteratorpixeltrait.h kis_layer.h kis_meta_registry.h
#kis_nameserver.h kis_paint_device.h kis_painter.h kis_paintop.h
#kis_paintop_registry.h kis_palette.h kis_pattern.h
......
......@@ -42,7 +42,8 @@ const KoID KisFilter::CategoryOther = KoID("other_filters", i18n("Other"));
KisFilter::KisFilter(const KoID& id, const KoID & category, const QString & entry)
: KisBaseProcessor(id, category, entry)
{
setBookmarkManager(new KisBookmarkedConfigurationManager(configEntryGroup(), new KisFilterConfigurationFactory(id.id(), 1) ));
setBookmarkManager(new KisBookmarkedConfigurationManager(configEntryGroup(),
new KisFilterConfigurationFactory(id.id(), 1) ));
}
KisFilter::~KisFilter()
......
......@@ -78,7 +78,7 @@ KisFilterConfiguration * KisBaseProcessor::defaultConfiguration(const KisPaintDe
return fc;
}
KisFilterConfigWidget * KisBaseProcessor::createConfigurationWidget(QWidget *, const KisPaintDeviceSP, const KisImageSP image ) const
KisFilterConfigWidget * KisBaseProcessor::createConfigurationWidget(QWidget *, const KisPaintDeviceSP, const KisImageSP ) const
{
return 0;
}
......
......@@ -26,9 +26,11 @@
/**
* Generates an 'outline' for a paint device. It should look a bit like the outline of a
* marching ants selection. You can use it to paint the outline of a KisBrush while painting.
* marching ants selection.
*
* It's not really optimized, so it's not recommended to do big things with it and expect
* it to be fast.
*
* Usage: construct a KisBoundary, and then run a generateBoundary(w, h) on it. After that,
* you can use the KisBoundaryPainter::paint method to let it paint the outline, or get a pixmap.
**/
......
/* This file is part of the KDE project
* Copyright (C) Boudewijn Rempt <boud@valdyas.org>, (C) 2008
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <KoPluginLoader.h>
#include "kis_brush_registry.h"
KisBrushRegistry * KisBrushRegistry::m_singleton = 0;
KisBrushRegistry::KisBrushRegistry()
{
Q_ASSERT(KisBrushRegistry::m_singleton == 0);
}
KisBrushRegistry::~KisBrushRegistry()
{
}
KisBrushRegistry* KisBrushRegistry::instance()
{
if(KisBrushRegistry::m_singleton == 0)
{
KisBrushRegistry::m_singleton = new KisBrushRegistry();
KoPluginLoader::instance()->load("Krita/Brush", "(Type == 'Service') and ([X-Krita-Version] == 3)");
Q_CHECK_PTR(KisBrushRegistry::m_singleton);
}
return KisBrushRegistry::m_singleton;
}
KisBrushFactorySP KisBrushRegistry::factory(const QString & extension) const
{
if (m_fileBrushes.contains(extension)) {
return m_fileBrushes[extension];
}
else {
return 0;
}
}
void KisBrushRegistry::registerFactory(KisBrushFactorySP factory, const QString & extension)
{
m_fileBrushes[extension] = factory;
}
QList<KisBrushFactorySP> KisBrushRegistry::dynamicBrushFactories() const
{
return m_dynamicBrushes.values();
}
KisBrushFactorySP KisBrushRegistry::dynamicBrushFactory( const QString & id) const
{
if (m_dynamicBrushes.contains(id)) {
return m_dynamicBrushes[id];
}
else {
return 0;
}
}
void KisBrushRegistry::registerDynamicFactory(KisBrushFactorySP factory, const QString & id)
{
m_dynamicBrushes[id] = factory;
}
/* This file is part of the KDE project
* Copyright (C) Boudewijn Rempt <boud@valdyas.org>, (C) 2008
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KIS_BRUSH_REGISTRY_H
#define KIS_BRUSH_REGISTRY_H
#include <QObject>
#include "kis_brush.h"
#include "kis_types.h"
#include "krita_export.h"
/**
* KisBrushRegistry keeps track of all the various types of brushes.
* Brushes are organized on file type, if loadable from a file. We
* don't do mimetypes for brush files (yet).
*
* There are also dynamic brushes (text and custom spring to mind).
* Those can be retrieved by ID or it is possible to get a list of
* factories for those types.
*/
class KisBrushRegistry {
public:
~KisBrushRegistry();
public:
static KisBrushRegistry* instance();
/**
* Get the factory for the specified file extension
*/
KisBrushFactorySP factory(const QString & extension) const;
/**
* register the factory for the specified file extension.
*/
void registerFactory(KisBrushFactorySP factory, const QString & extension);
/**
* Get a list of factories that create dynamic brushes.
*/
QList<KisBrushFactorySP> dynamicBrushFactories() const;
/**
* Get a dynamic brush factory for the give ID
*/
KisBrushFactorySP dynamicBrushFactory( const QString & id) const;
/**
* Register a dynamic brush factory
*/
void registerDynamicFactory(KisBrushFactorySP factory, const QString & id);
private:
KisBrushRegistry();
KisBrushRegistry(const KisBrushRegistry&);
KisBrushRegistry operator=(const KisBrushRegistry&);
private:
static KisBrushRegistry *m_singleton;
QHash<QString, KisBrushFactorySP> m_fileBrushes;
QHash<QString, KisBrushFactorySP> m_dynamicBrushes;
};
#endif
......@@ -94,9 +94,11 @@ KisConvolutionKernelSP KisConvolutionKernel::fromQImage(const QImage& img)
KisConvolutionKernelSP KisConvolutionKernel::kernelFromMaskGenerator(KisMaskGenerator* kmg, double angle)
{
Q_UNUSED(angle);
qint32 width = (int)( kmg->width() + 0.5 );
qint32 height = (int)( kmg->height() + 0.5 );
KisConvolutionKernelSP k = new KisConvolutionKernel( width, height, 0, 0);
double cosa = 1.0;//cos(angle);
double sina = 0.0;//sin(angle);
......@@ -179,4 +181,4 @@ QDebug operator<<(QDebug dbg, const KisConvolutionKernel &c)
}
dbg.nospace() << c.factor()<< " " << c.offset() << " }";
return dbg.space();
}
}
......@@ -44,7 +44,7 @@
#include <KoProgressUpdater.h>
#include "kis_brush.h"
#include "kis_convolution_kernel.h"
#include "kis_convolution_kernel.h"
#include "kis_global.h"
#include "kis_image.h"
......
......@@ -43,8 +43,6 @@
#include <KoAbstractGradient.h>
#include <KoProgressUpdater.h>
#include "kis_brush.h"
#include "kis_debug.h"
#include "kis_image.h"
#include "kis_iterators_pixel.h"
#include "kis_layer.h"
......
......@@ -43,7 +43,7 @@
#include "KoColorConversionTransformation.h"
#include "colorprofiles/KoIccColorProfile.h"
#include "kis_action_recorder.h"
#include "recorder/kis_action_recorder.h"
#include "kis_adjustment_layer.h"
#include "kis_annotation.h"
#include "kis_change_profile_visitor.h"
......
......@@ -253,6 +253,7 @@ public:
* @return the action recorder associated with this image
*/
KisActionRecorder* actionRecorder() const;
/**
* Returns true if this image wants undo information, false otherwise
*/
......
......@@ -46,7 +46,6 @@
#include <KoColor.h>
#include <KoCompositeOp.h>
#include "kis_brush.h"
#include "kis_image.h"
#include "filter/kis_filter.h"
#include "kis_layer.h"
......@@ -61,6 +60,8 @@
#include "kis_fill_painter.h"
#include "filter/kis_filter_configuration.h"
#include "kis_pixel_selection.h"
#include "kis_paint_information.h"
#include "kis_paintop_registry.h"
// Maximum distance from a Bezier control point to the line through the start
// and end points for the curve to be considered flat.
......@@ -74,7 +75,7 @@ struct KisPainter::Private {
QRegion dirtyRegion;
QRect dirtyRect;
KisPaintOp * paintOp;
QRect bounds;
KoColor paintColor;
KoColor backgroundColor;
......@@ -84,11 +85,9 @@ struct KisPainter::Private {
FillStyle fillStyle;
StrokeStyle strokeStyle;
bool antiAliasPolygonFill;
KisBrush *brush;
KisPattern *pattern;
QPointF duplicateOffset;
quint8 opacity;
KisPaintOp * paintOp;
qint32 pixelSize;
const KoColorSpace * colorSpace;
KoColorProfile * profile;
......@@ -96,6 +95,7 @@ struct KisPainter::Private {
QBitArray channelFlags;
bool useBoundingDirtyRect;
KoAbstractGradient* gradient;
KisPaintOpPresetSP paintOpPreset;
};
KisPainter::KisPainter()
......@@ -126,7 +126,6 @@ void KisPainter::init()
d->selection = 0 ;
d->transaction = 0;
d->paintOp = 0;
d->brush = 0;
d->pattern= 0;
d->opacity = OPACITY_OPAQUE;
d->sourceLayer = 0;
......@@ -144,7 +143,6 @@ void KisPainter::init()
KisPainter::~KisPainter()
{
end();
d->brush = 0;
delete d->paintOp;
delete d;
}
......@@ -236,12 +234,6 @@ QRegion KisPainter::addDirtyRect(const QRect & r)
}
void KisPainter::setPaintOp(KisPaintOp * paintOp)
{
delete d->paintOp;
d->paintOp = paintOp;
}
void KisPainter::bitBlt(qint32 dx, qint32 dy,
const KoCompositeOp* op,
const KisPaintDeviceSP src,
......@@ -1627,19 +1619,20 @@ QBitArray KisPainter::channelFlags()
return d->channelFlags;
}
void KisPainter::setBrush(KisBrush* brush) { d->brush = brush; }
KisBrush * KisPainter::brush() const { return d->brush; }
void KisPainter::setPattern(KisPattern * pattern) { d->pattern = pattern; }
KisPattern * KisPainter::pattern() const { return d->pattern; }
void KisPainter::setPaintColor(const KoColor& color) { d->paintColor = color;}
KoColor KisPainter::paintColor() const { return d->paintColor; }
void KisPainter::setBackgroundColor(const KoColor& color) {d->backgroundColor = color; }
KoColor KisPainter::backgroundColor() const { return d->backgroundColor; }
void KisPainter::setFillColor(const KoColor& color) { d->fillColor = color; }
KoColor KisPainter::fillColor() const { return d->fillColor; }
void KisPainter::setGenerator(KisFilterConfiguration * generator)
......@@ -1652,7 +1645,6 @@ KisFilterConfiguration * KisPainter::generator() const
return d->generator;
}
void KisPainter::setFillStyle(FillStyle fillStyle) { d->fillStyle = fillStyle; }
KisPainter::FillStyle KisPainter::fillStyle() const
......@@ -1674,14 +1666,15 @@ KisPainter::StrokeStyle KisPainter::strokeStyle() const
}
void KisPainter::setOpacity(quint8 opacity) { d->opacity = opacity; }
quint8 KisPainter::opacity() const { return d->opacity; }
void KisPainter::setBounds( const QRect & bounds ) { d->bounds = bounds; }
QRect KisPainter::bounds() { return d->bounds; }
KisPaintOp * KisPainter::paintOp() const { return d->paintOp; }
QRect KisPainter::bounds() { return d->bounds; }
void KisPainter::setCompositeOp(const KoCompositeOp * op) { d->compositeOp = op; }
const KoCompositeOp * KisPainter::compositeOp() { return d->compositeOp; }
void KisPainter::setSelection(KisSelectionSP selection) { d->selection = selection; }
......@@ -1698,3 +1691,22 @@ KoAbstractGradient* KisPainter::gradient()
{
return d->gradient;
}
void KisPainter::setPaintOpPreset( KisPaintOpPresetSP preset, KisImageSP image )
{
kDebug() << "setting the paintop " << preset;
d->paintOpPreset = preset;
delete d->paintOp;
d->paintOp = KisPaintOpRegistry::instance()->paintOp(preset, this, image);
kDebug() << " paintop: " << d->paintOp;
}
KisPaintOpPresetSP KisPainter::preset() const
{
return d->paintOpPreset;
}
KisPaintOp* KisPainter::paintOp() const
{
return d->paintOp;
}
......@@ -44,12 +44,10 @@ class KoColor;
class KoCompositeOp;
class KisTransaction;
class KisBrush;
class KisPattern;
class KisFilterConfiguration;
class KisPaintOp;
class KisPaintInformation;
class KisPaintOp;
/**
* KisPainter contains the graphics primitives necessary to draw on a
* KisPaintDevice. This is the same kind of abstraction as used in Qt
......@@ -451,17 +449,23 @@ public:
QBitArray channelFlags();
/// Set the current brush
void KDE_DEPRECATED setBrush(KisBrush* brush);
/// Returns the currently set brush
KisBrush* KDE_DEPRECATED brush() const;
/**
* Set the paintop preset to use. If @param image is given,
* the paintop will be created using this image as parameter.
* Some paintops really want to know about the image they work
* for, e.g. the duplicate paintop.
*/
void setPaintOpPreset( KisPaintOpPresetSP preset, KisImageSP image = 0 );
/// Set the paintop preset to use
void setPaintOpPreset( KisPaintOpPresetSP preset );
/// Return the paintop preset
KisPaintOpPresetSP preset() const;
/**
* Return the active paintop (which is created based on the specified preset and
* will be deleted as soon as the KisPainter instance dies).
*/
KisPaintOp* paintOp() const;
/// Set the current pattern
void setPattern(KisPattern * pattern);
......@@ -539,15 +543,6 @@ public:
void setBounds( const QRect & bounds );
QRect bounds();
/**
* Set the current paint operation. This is used for all drawing functions.
* The painter will DELETE the paint op itself!!
* That means no that you should not delete it yourself (or put it on the stack)
*/
void setPaintOp(KisPaintOp * paintOp);
/// Returns the current paint operation
KisPaintOp * paintOp() const;
/// Set the composite op for this painter
void setCompositeOp(const KoCompositeOp * op);
const KoCompositeOp * compositeOp();
......
......@@ -31,7 +31,6 @@
#include "kis_painter.h"
#include "kis_layer.h"
#include "kis_brush.h"
#include "kis_types.h"