Commit f2710b95 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Add a krita wrapper around the resource provider for the gui code to simply

set things the tools should know about. Experiment with QMetaType and so on.

svn path=/trunk/koffice/; revision=601310
parent 0c06a287
......@@ -56,14 +56,18 @@ class KRITAIMAGE_EXPORT KisBrush : public KisResource {
Q_OBJECT
public:
/// Construct brush to load filename later as brush
KisBrush(const QString& filename);
/// Load brush from the specified data, at position dataPos, and set the filename
KisBrush(const QString& filename,
const QByteArray & data,
qint32 & dataPos);
/// Load brush from the specified paint device, in the specified region
KisBrush(KisPaintDevice* image, int x, int y, int w, int h);
/// Load brush as a copy from the specified QImage (handy when you need to copy a brush!)
KisBrush(const QImage& image, const QString& name = QString(""));
......
......@@ -20,6 +20,7 @@
#define KIS_LAYER_H_
#include <QRect>
#include <QMetaType>
#include "krita_export.h"
......@@ -301,5 +302,7 @@ public:
virtual KisLayer* layer() = 0;
};
Q_DECLARE_METATYPE( KisLayerSP )
#endif // KIS_LAYER_H_
......@@ -24,6 +24,7 @@
#define KIS_PAINTOP_H_
#include <QString>
#include <QMetaType>
#include <ksharedptr.h>
#include <klocale.h>
......@@ -101,7 +102,9 @@ private:
};
class KisPaintOpSettings {
public:
KisPaintOpSettings() {}
KisPaintOpSettings(QWidget *parent) { Q_UNUSED(parent); }
virtual ~KisPaintOpSettings() {}
......
......@@ -18,10 +18,27 @@
#include "kis_resource_provider.h"
#include <KoCanvasBase.h>
#include <KoID.h>
#include "kis_brush.h"
#include "kis_pattern.h"
#include "kis_gradient.h"
#include "kis_view2.h"
#include <kis_layer.h>
KisResourceProvider::KisResourceProvider(KisView2 * view )
: m_view( view )
, m_resourceProvider( view->canvasBase()->resourceProvider() )
{
QVariant v;
v.setValue( KoColor(Qt::black, view->image()->colorSpace()) );
m_resourceProvider->setResource( FOREGROUND_COLOR, v );
v.setValue( KoColor(Qt::white, view->image()->colorSpace()) );
m_resourceProvider->setResource( BACKGROUND_COLOR, v );
}
KoCanvasBase * KisResourceProvider::canvas() const
{
......@@ -30,120 +47,144 @@ KoCanvasBase * KisResourceProvider::canvas() const
KoColor KisResourceProvider::bgColor() const
{
return m_bgColor;
return m_resourceProvider->resource( FOREGROUND_COLOR ).value<KoColor>();
}
KoColor KisResourceProvider::fgColor() const
{
return m_fgColor;
return m_resourceProvider->resource( BACKGROUND_COLOR ).value<KoColor>();
}
float KisResourceProvider::HDRExposure() const
{
return m_HDRExposure;
return static_cast<float>( m_resourceProvider->resource( HDR_EXPOSURE ).toDouble() );
}
void KisResourceProvider::setHDRExposure(float exposure)
{
m_HDRExposure = exposure;
m_resourceProvider->setResource( HDR_EXPOSURE, static_cast<double>( exposure ) );
}
KisBrush * KisResourceProvider::currentBrush() const
{
return m_brush;
return static_cast<KisBrush *>( m_resourceProvider->resource( CURRENT_KIS_BRUSH ).value<void *>() );
}
KisPattern * KisResourceProvider::currentPattern() const
{
return m_pattern;
return static_cast<KisPattern*>( m_resourceProvider->resource( CURRENT_PATTERN ).value<void *>() );
}
KisGradient * KisResourceProvider::currentGradient() const
{
return m_gradient;
return static_cast<KisGradient*>( m_resourceProvider->resource( CURRENT_GRADIENT ).value<void *>() );
}
KoID KisResourceProvider::currentPaintop() const
{
return m_paintop;
return m_resourceProvider->resource( CURRENT_PAINTOP ).value<KoID>();
}
const KisPaintOpSettings * KisResourceProvider::currentPaintopSettings() const
{
return m_paintopSettings;
return static_cast<KisPaintOpSettings*>( m_resourceProvider->resource( CURRENT_PAINTOP_SETTINGS )
.value<void *>() );
}
void KisResourceProvider::brushActivated(KisResource *brush)
KisLayerSP KisResourceProvider::currentLayer() const
{
return m_resourceProvider->resource( CURRENT_KIS_LAYER ).value<KisLayerSP>();
}
m_brush = dynamic_cast<KisBrush*>(brush);
void KisResourceProvider::slotBrushActivated(KisResource *res)
{
if (m_brush )
KisBrush * brush = dynamic_cast<KisBrush*>(res);
QVariant v = qVariantFromValue( ( void * ) brush );
m_resourceProvider->setResource( CURRENT_KIS_BRUSH, v );
if (brush )
{
emit brushChanged(m_brush);
emit sigBrushChanged(brush);
}
}
void KisResourceProvider::patternActivated(KisResource *pattern)
void KisResourceProvider::slotPatternActivated(KisResource * res)
{
m_pattern = dynamic_cast<KisPattern*>(pattern);
if (m_pattern) {
emit patternChanged(m_pattern);
KisPattern * pattern = dynamic_cast<KisPattern*>(res);
QVariant v = qVariantFromValue( ( void * ) pattern );
m_resourceProvider->setResource( CURRENT_PATTERN, v );
if (pattern) {
emit sigPatternChanged(pattern);
}
}
void KisResourceProvider::gradientActivated(KisResource *gradient)
void KisResourceProvider::slotGradientActivated(KisResource *res)
{
m_gradient = dynamic_cast<KisGradient*>(gradient);
if (m_gradient) {
emit gradientChanged(m_gradient);
KisGradient * gradient = dynamic_cast<KisGradient*>(res);
QVariant v = qVariantFromValue( ( void * ) gradient );
m_resourceProvider->setResource( CURRENT_GRADIENT, v );
if (gradient) {
emit sigGradientChanged(gradient);
}
}
void KisResourceProvider::paintopActivated(const KoID & paintop, const KisPaintOpSettings *paintopSettings)
void KisResourceProvider::slotPaintopActivated(const KoID & paintop,
const KisPaintOpSettings *paintopSettings)
{
if (paintop.id().isNull() || paintop.id().isEmpty()) {
return;
}
m_paintop = paintop;
m_paintopSettings = paintopSettings;
emit paintopChanged(m_paintop, paintopSettings);
QVariant v;
v.setValue( paintop );
m_resourceProvider->setResource( CURRENT_PAINTOP, v );
v = qVariantFromValue( ( void * ) paintopSettings );
m_resourceProvider->setResource( CURRENT_PAINTOP_SETTINGS, v );
emit sigPaintopChanged(paintop, paintopSettings);
}
void KisResourceProvider::setBGColor(const KoColor& c)
{
m_bgColor = c;
QVariant v;
v.setValue( c );
m_resourceProvider->setResource( BACKGROUND_COLOR, v );
emit sigBGColorChanged( c );
}
void KisResourceProvider::setFGColor(const KoColor& c)
{
m_fgColor = c;
QVariant v;
v.setValue( c );
m_resourceProvider->setResource( FOREGROUND_COLOR, v );
emit sigFGColorChanged( c );
}
void KisResourceProvider::slotSetFGColor(const KoColor& c)
{
m_fgColor = c;
emit sigFGColorChanged( c );
setFGColor( c );
}
void KisResourceProvider::slotSetBGColor(const KoColor& c)
{
m_bgColor = c;
emit sigBGColorChanged( c );
setBGColor( c );
}
void KisResourceProvider::slotLayerActivated( const KisLayerSP l )
{
QVariant v;
v.setValue( l );
m_resourceProvider->setResource( CURRENT_PAINTOP, v );
}
#include "kis_resource_provider.moc"
......@@ -23,6 +23,7 @@
#include <KoColor.h>
#include <KoID.h>
#include <KoCanvasResourceProvider.h>
#include "kis_view2.h"
#include "kis_image.h"
......@@ -36,6 +37,12 @@ class KisResource;
/**
KisResourceProvider contains the per-view current settings that
influence painting, like paintop, color, gradients and so on.
XXX: KisBrush, KisGradient, KisPattern and the other pointers
should really be shared pointers. That would be much safer. Also
note: we should have a koffice-wide provider of brushes, patterns
and gradients.
*/
class KisResourceProvider : public QObject {
......@@ -43,17 +50,7 @@ class KisResourceProvider : public QObject {
public:
KisResourceProvider(KisView2 * view)
: m_view( view )
, m_brush( 0 )
, m_pattern( 0 )
, m_gradient( 0 )
, m_paintopSettings( 0 )
, m_HDRExposure( 0 )
{
m_fgColor = KoColor(Qt::black, view->image()->colorSpace());
m_bgColor = KoColor(Qt::white, view->image()->colorSpace());
}
KisResourceProvider(KisView2 * view);
KoCanvasBase * canvas() const;
......@@ -73,35 +70,33 @@ public:
KoID currentPaintop() const;
const KisPaintOpSettings *currentPaintopSettings() const;
KisLayerSP currentLayer() const;
public slots:
void slotSetFGColor(const KoColor& c);
void slotSetBGColor(const KoColor& c);
void brushActivated(KisResource *brush);
void patternActivated(KisResource *pattern);
void gradientActivated(KisResource *gradient);
void paintopActivated(const KoID & paintop, const KisPaintOpSettings *paintopSettings);
void slotBrushActivated(KisResource *brush);
void slotPatternActivated(KisResource *pattern);
void slotGradientActivated(KisResource *gradient);
void slotPaintopActivated(const KoID & paintop, const KisPaintOpSettings *paintopSettings);
void slotLayerActivated( const KisLayerSP layer );
signals:
void sigFGColorChanged(const KoColor &);
void sigBGColorChanged(const KoColor &);
void brushChanged(KisBrush * brush);
void gradientChanged(KisGradient * gradient);
void patternChanged(KisPattern * pattern);
void paintopChanged(KoID paintop, const KisPaintOpSettings *paintopSettings);
void sigBrushChanged(KisBrush * brush);
void sigGradientChanged(KisGradient * gradient);
void sigPatternChanged(KisPattern * pattern);
void sigPaintopChanged(KoID paintop, const KisPaintOpSettings *paintopSettings);
void sigLayerChanged( const KisLayerSP layer );
private:
KisView2 * m_view;
KisBrush * m_brush;
KisPattern * m_pattern;
KisGradient * m_gradient;
KoColor m_fgColor;
KoColor m_bgColor;
KoID m_paintop;
const KisPaintOpSettings *m_paintopSettings;
float m_HDRExposure;
KoCanvasResourceProvider * m_resourceProvider;
};
#endif
......@@ -153,7 +153,7 @@ public:
* @return the value of the vertical scrollbar
*/
virtual qint32 verticalScrollbarValue() const 0;
q
/**
* Sets the horizontal and vertical scrollbars to the specified values
*
......
......@@ -36,6 +36,7 @@ enum enumCanvasResource {
CURRENT_GRADIENT = 1004,
CURRENT_PAINTOP = 1005,
CURRENT_PAINTOP_SETTINGS = 1007,
CURRENT_KIS_LAYER = 1008,
KIVIO_CANVAS_BASE = 2000
};
......
......@@ -23,7 +23,7 @@
#define _KO_ID_H_
#include <QString>
#include <QMetaType>
/**
* A KoID is a combination of a user-visible string and a string that uniquely
......@@ -52,6 +52,8 @@ private:
};
Q_DECLARE_METATYPE( KoID )
inline bool operator==(const KoID &v1, const KoID &v2)
{
return v1.m_id == v2.m_id;
......@@ -74,4 +76,5 @@ inline bool operator>(const KoID &v1, const KoID &v2)
return v1.m_id < v2.m_id;
}
#endif
......@@ -20,6 +20,8 @@
#define KOCOLOR_H
#include <QColor>
#include <QMetaType>
#include <koffice_export.h>
#include "KoColorProfile.h"
......@@ -87,4 +89,6 @@ private:
KoColorSpace * m_colorSpace;
};
Q_DECLARE_METATYPE( KoColor )
#endif
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