Commit 0c06a287 authored by Halla Rempt's avatar Halla Rempt
Browse files

Add the first-cut implementation of KoCanvasResourceProvider and make

it by default a property of KoCanvasBase; also automatically connect the
sigResourceChagned signal to a new slot in KoTool. 

svn path=/trunk/koffice/; revision=601286
parent 6b9e2fa9
......@@ -3,6 +3,7 @@ include_directories( ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ${KOFFICECORE_INCLUDES})
add_subdirectory(tests)
set(flake_SRCS
KoCanvasResourceProvider.cpp
KoCommand.cpp
KoInteractionStrategy.cpp
KoInteractionTool.cpp
......
......@@ -16,7 +16,7 @@
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.
Boston, MA 02110-1301, USA.
*/
#ifndef KOCANVASBASE_H
......@@ -30,6 +30,8 @@
#include <QRect>
#include <QWidget>
#include <KoCanvasResourceProvider.h>
class KoSelection;
class KCommand;
class KoShapeManager;
......@@ -42,7 +44,9 @@ class KoViewConverter;
* do things like scroll, redraw, set a cursor etc.
*/
class KoCanvasBase {
public:
KoCanvasBase() {};
virtual ~KoCanvasBase() {};
......@@ -120,6 +124,16 @@ public:
*/
virtual QPoint documentOrigin() { return QPoint(0,0); };
/**
* Return a pointer to the resource provider associated with this
* canvas. The resource provider contains per-canvas settings such
* as current foreground and background color.
*/
virtual KoCanvasResourceProvider * resourceProvider()
{
return m_resourceProvider;
}
#if 0
/* The next list of methods are naming taken from Krita, which means they have already been
toughened by time. So, if you ever need a method in this interface; please uncomment the
......@@ -267,6 +281,12 @@ public:
*/
virtual KoInputDevice currentInputDevice() const 0;
#endif
private:
KoCanvasResourceProvider * m_resourceProvider;
};
#endif
#endif // KOCANVASBASE_H
/*
* Copyright (c) 2006 Boudewijn Rempt
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "KoCanvasResourceProvider.h"
KoCanvasResourceProvider::KoCanvasResourceProvider(QObject * parent)
: QObject( parent )
{
}
void KoCanvasResourceProvider::setResource( enumCanvasResource key, const QVariant & value )
{
KoCanvasResource r ( key, value );
setResource( r );
}
void KoCanvasResourceProvider::setResource( KoCanvasResource & res)
{
if ( m_resources.contains( res.key ) ) {
m_resources[res.key] = res;
}
else {
m_resources.insert( res.key, res );
}
emit sigResourceChanged( res );
}
QVariant KoCanvasResourceProvider::resource(enumCanvasResource key)
{
if ( !m_resources.contains( key ) )
return m_empty;
else
return m_resources.value( key ).value;
}
#include "KoCanvasResourceProvider.moc"
/*
* Copyright (c) 2006 Boudewijn Rempt
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KO_CANVAS_RESOURCE_PROVIDER_
#define KO_CANVAS_RESOURCE_PROVIDER_
#include <QObject>
#include <QHash>
#include <QVariant>
enum enumCanvasResource {
FOREGROUND_COLOR = 0,
BACKGROUND_COLOR = 1,
COMPOSITE_OPERARION = 2,
COMPOSITE_OPACITY = 4,
// XXX: Extend with necessary items, or make base numbers per canvas type as with QEvent::type?
// like:
KRITA_CANVAS_BASE = 1000,
HDR_EXPOSURE = 1001,
CURRENT_KIS_BRUSH = 1002,
CURRENT_PATTERN = 1003,
CURRENT_GRADIENT = 1004,
CURRENT_PAINTOP = 1005,
CURRENT_PAINTOP_SETTINGS = 1007,
KIVIO_CANVAS_BASE = 2000
};
/**
* A single resource, lika a color.
*
* XXX: This is a copy of libs/kotext/styles/Styles_p.h -- should
* we generalize this, or does Qt already have something
* suitable?
*/
class KoCanvasResource {
public:
KoCanvasResource() {}
KoCanvasResource(enumCanvasResource key, const QVariant &value)
{
this->key = key;
this->value = value;
}
inline bool operator==(const KoCanvasResource &res) const
{
return res.key == key && res.value == value;
}
inline bool operator!=(const KoCanvasResource &res) const
{
return res.key != key || res.value != value;
}
enumCanvasResource key;
QVariant value;
};
/**
* The KoCanvasResourceProvider contains a set of per-canvas
* &reserties, like current foreground color, current background
* color and more. All tools belonging to the current canvas are
* notified when a Resource changes (is set).
*/
class KoCanvasResourceProvider : public QObject {
Q_OBJECT
public:
KoCanvasResourceProvider(QObject * parent);
// XXX: Who is going to delete the resource objects? This class?
// The QHash hashmap? The creator?
void setResource( KoCanvasResource & res);
void setResource( enumCanvasResource key, const QVariant & value );
/// @return a pointer to the specified resource or 0 if the
/// specified resource does not exist.
QVariant resource(enumCanvasResource key);
signals:
void sigResourceChanged(const KoCanvasResource & res);
private:
~KoCanvasResourceProvider() {};
KoCanvasResourceProvider(const KoCanvasResourceProvider&);
KoCanvasResourceProvider& operator=(const KoCanvasResourceProvider&);
private:
QVariant m_empty;
QHash<int, KoCanvasResource> m_resources;
};
#endif // KO_CANVAS_RESOURCE_PROVIDER_
......@@ -29,9 +29,14 @@
KoTool::KoTool(KoCanvasBase *canvas )
: m_canvas(canvas)
, m_previousCursor(Qt::ArrowCursor)
, m_optionWidget( 0 )
, m_previousCursor(Qt::ArrowCursor)
{
connect( m_canvas->resourceProvider(),
SIGNAL( sigResourceChanged(const KoCanvasResource & res) ),
this,
SLOT( resourceChanged( const KoCanvasResource & res ) ) );
}
void KoTool::activate(bool temporary) {
......@@ -41,6 +46,11 @@ void KoTool::activate(bool temporary) {
void KoTool::deactivate() {
}
void KoTool::resourceChanged( const KoCanvasResource & res )
{
Q_UNUSED( res );
}
bool KoTool::wantsAutoScroll() {
return true;
}
......
......@@ -25,6 +25,8 @@
#include <koffice_export.h>
#include <KoCanvasResourceProvider.h>
class KoCanvasBase;
class KoPointerEvent;
class KoViewConverter;
......@@ -39,7 +41,7 @@ class QPainter;
/**
* Abstract base class for all tools. Tools can create or manipulate
* flake shapes, canvas state or any other thing that a user may wish
* to do to his document or his view on a document with a pointing
* to do to his document or his view on a document with a pointing
* device.
*
* There exists an instance of every tool for every pointer device.
......@@ -90,6 +92,13 @@ public slots:
*/
virtual void deactivate();
/**
* This method is called whenever a property in the resource
* provider associated with the canvas this tool belongs to
* changes. An example is currently selected foreground color.
*/
virtual void resourceChanged( const KoCanvasResource & res );
public:
/**
......@@ -220,9 +229,13 @@ protected:
* Reimplement this if your tool actually has an option widget.
* Sets the option widget to 0 by default.
*/
virtual void createOptionWidget(QWidget * parent) { m_optionWidget = 0; }
virtual void createOptionWidget(QWidget * parent)
{
Q_UNUSED( parent );
m_optionWidget = 0;
}
protected:
protected:
KoCanvasBase *m_canvas; ///< the canvas interface this tool will work for.
QWidget * m_optionWidget; ///< the optionwidget this tool will show in the option widget palette
......@@ -231,6 +244,7 @@ private:
KoTool();
KoTool(const KoTool&);
KoTool& operator=(const KoTool&);
QCursor m_previousCursor;
};
......
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