diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
commit | 8362bf63dea22bbf6736609b0f49c152f975eb63 (patch) | |
tree | 0eea3928e39e50fae91d4e68b21b1e6cbae25604 /krita/sdk | |
download | koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip |
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'krita/sdk')
-rw-r--r-- | krita/sdk/Makefile.am | 23 | ||||
-rw-r--r-- | krita/sdk/kis_annotation.h | 89 | ||||
-rw-r--r-- | krita/sdk/kis_canvas_controller.h | 200 | ||||
-rw-r--r-- | krita/sdk/kis_canvas_observer.h | 55 | ||||
-rw-r--r-- | krita/sdk/kis_canvas_subject.h | 192 | ||||
-rw-r--r-- | krita/sdk/kis_debug_areas.h | 34 | ||||
-rw-r--r-- | krita/sdk/kis_generic_registry.h | 166 | ||||
-rw-r--r-- | krita/sdk/kis_global.h | 83 | ||||
-rw-r--r-- | krita/sdk/kis_id.h | 108 | ||||
-rw-r--r-- | krita/sdk/kis_integer_maths.h | 111 | ||||
-rw-r--r-- | krita/sdk/kis_progress_display_interface.h | 76 | ||||
-rw-r--r-- | krita/sdk/kis_progress_subject.cc | 29 | ||||
-rw-r--r-- | krita/sdk/kis_progress_subject.h | 44 | ||||
-rw-r--r-- | krita/sdk/kis_shared_ptr_vector.h | 70 | ||||
-rw-r--r-- | krita/sdk/kis_undo_adapter.h | 67 |
15 files changed, 1347 insertions, 0 deletions
diff --git a/krita/sdk/Makefile.am b/krita/sdk/Makefile.am new file mode 100644 index 00000000..e6f4f4a5 --- /dev/null +++ b/krita/sdk/Makefile.am @@ -0,0 +1,23 @@ +KDE_OPTIONS = nofinal + +INCLUDES = $(KOFFICE_INCLUDES) $(KOPAINTER_INCLUDES) \ + $(all_includes) + +noinst_LTLIBRARIES = libkritasdk.la +libkritasdk_la_SOURCES = kis_progress_subject.cc +libkritasdk_la_METASOURCES = AUTO + +include_HEADERS = \ + kis_annotation.h \ + kis_canvas_controller.h \ + kis_canvas_observer.h \ + kis_canvas_subject.h \ + kis_global.h \ + kis_id.h \ + kis_integer_maths.h \ + kis_progress_display_interface.h \ + kis_progress_subject.h \ + kis_shared_ptr_vector.h \ + kis_undo_adapter.h \ + kis_generic_registry.h + diff --git a/krita/sdk/kis_annotation.h b/krita/sdk/kis_annotation.h new file mode 100644 index 00000000..03287004 --- /dev/null +++ b/krita/sdk/kis_annotation.h @@ -0,0 +1,89 @@ +/* + * This file is part of the KDE project + * + * Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.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 + * 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 _KIS_ANNOTATION_H_ +#define _KIS_ANNOTATION_H_ + +#include <ksharedptr.h> +#include "kis_shared_ptr_vector.h" + +#include <qstring.h> +#include <qcstring.h> +#include <qmemarray.h> + +/** + * An data extension mechanism for Krita. + * + * An annotation can be of something like a QByteArray or a QString op a more specific + * datatype that can be attached to an image (or maybe later, if needed, to a layer) + * and contains data that must be associated with an image for purposes of import/export. + * + * Annotations will be saved to krita images and may be exported in filetypes that support + * them. + * + * Examples of annotations are EXIF data and ICC profiles. + */ +class KisAnnotation : public KShared { + + +public: + + /** + * Creates a new annotation object. The annotation object cannot be changed later + * + * @param type a non-localized string identifying the type of the annotation + * @param description a localized string describing the annotation + * @param data a binary blob containing the annotation data + */ + KisAnnotation(const QString & type, const QString & description, const QByteArray & data) + : m_type(type), + m_description(description), + m_annotation(data) {}; + + /** + * @return a non-localized string identifiying the type of the annotation + */ + QString & type() {return m_type;}; + + /** + * @return a localized string describing the type of the annotations + * for user interface purposes. + */ + QString & description() {return m_description;}; + + /** + * @return a binary blob representation of this annotation + */ + QByteArray & annotation() { return m_annotation;}; + +private: + + QString m_type; + QString m_description; + QByteArray m_annotation; + +}; + +typedef KSharedPtr<KisAnnotation> KisAnnotationSP; +typedef KisSharedPtrVector<KisAnnotation> vKisAnnotationSP; +typedef vKisAnnotationSP::iterator vKisAnnotationSP_it; +typedef vKisAnnotationSP::const_iterator vKisAnnotationSP_cit; + +#endif // _KIS_ANNOTATION_H_ diff --git a/krita/sdk/kis_canvas_controller.h b/krita/sdk/kis_canvas_controller.h new file mode 100644 index 00000000..99d43c38 --- /dev/null +++ b/krita/sdk/kis_canvas_controller.h @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2003 Patrick Julien <freak@codepimps.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 + * 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 KIS_CANVAS_CONTROLLER_H_ +#define KIS_CANVAS_CONTROLLER_H_ + +#include <qglobal.h> +#include <qpoint.h> +#include <qrect.h> +#include "kis_types.h" + +class QWidget; +class KisTool; +class KisRect; +class KisPoint; +class KisCanvas; +class KisInputDevice; + +/** + * Interface for classes that implement a canvas; i.e., a widget where KisImages + * are painted onto. This is the "view" part of the model-view-controller paradigm; + * the naming is a confusing historical artefact. + */ +class KisCanvasController { +public: + KisCanvasController() {}; + virtual ~KisCanvasController() {}; + +public: + + /** + * @return the canvas object + */ + virtual KisCanvas *kiscanvas() const = 0; + + + /** + * @return the value of the horizontal scrollbar. + */ + virtual Q_INT32 horzValue() const = 0; + + /** + * @return the value of the vertical scrollbar + */ + virtual Q_INT32 vertValue() const = 0; + + /** + * Sets the horizontal and vertical scrollbars to the specified values + * + * @param x the value the horizontal scrollbar is set to + * @param y the value the vertical scrollbar is set to + */ + virtual void scrollTo(Q_INT32 x, Q_INT32 y) = 0; + + /** + * Tell all of the canvas to repaint itself. + */ + virtual void updateCanvas() = 0; + + + /** + * Tell the canvas to repaint the rectangle defined by x, y, w and h. + * The coordinates are image coordinates. + */ + virtual void updateCanvas(Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h) = 0; + + /** + * Tell the canvas repaint the specified rectangle. The coordinates + * are image coordinates, not view coordinates. + */ + virtual void updateCanvas(const QRect& rc) = 0; + + /** + * Increase the zoomlevel one step + */ + virtual void zoomIn() = 0; + + /** + * Increase the zoomlevel one step and make sure that x,y is the center point of the view. + * + * @param x The x coordinate of the visible point in image coordinates + * @param y the y coordinate of the visible point in image coordinates + */ + virtual void zoomIn(Q_INT32 x, Q_INT32 y) = 0; + + /** + * Decrease the zoomlevel one step + */ + virtual void zoomOut() = 0; + + + /** + * Decrease the zoomlevel one step and make sure that x,y is the center point of the view. + * + * @param x the x coordinate of the visible point in image coordinates + * @param y the y coordinate of the visible point in image coordinates + */ + virtual void zoomOut(Q_INT32 x, Q_INT32 y) = 0; + + /** + * To centre the view on the given point with the given zoom factor. + * + * @param x the x coordinate of the center point in image coordinates + * @param y the y coordinate of the center point in image coordinates + * @param zf the zoomfactor + */ + virtual void zoomAroundPoint(double x, double y, double zf) = 0; + + /** + * Make the rect defined by x, y, w and h visible, zooming in or + * out as necessary. The view will be centered around the center point + * of the specified rect. + */ + virtual void zoomTo(Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h) = 0; + + /** + * Make the rect defined by x, y, w and h visible, zooming in or + * out as necessary. The view will be centered around the center point + * of the specified rect. + */ + virtual void zoomTo(const QRect& r) = 0; + + /** + * Make the rect defined by x, y, w and h visible, zooming in or + * out as necessary. The view will be centered around the center point + * of the specified rect. + */ + virtual void zoomTo(const KisRect& r) = 0; + + /** + * Conversion functions from view coordinates to image coordinates + * + * You can get the rectangle of the image that's visible using the + * viewToWindow() functions (KisCanvasController). E.g. + * viewToWindow(QRect(0, 0, canvasWidth, canvasHeight)). + * + * Here, the view is the canvas widget in the view widget, and the window + * is the window on the image. + */ + virtual QPoint viewToWindow(const QPoint& pt) = 0; + virtual KisPoint viewToWindow(const KisPoint& pt) = 0; + virtual QRect viewToWindow(const QRect& rc) = 0; + virtual KisRect viewToWindow(const KisRect& rc) = 0; + virtual void viewToWindow(Q_INT32 *x, Q_INT32 *y) = 0; + + /** + * Conversion functions from image coordinates to view coordinates + */ + virtual QPoint windowToView(const QPoint& pt) = 0; + virtual KisPoint windowToView(const KisPoint& pt) = 0; + virtual QRect windowToView(const QRect& rc) = 0; + virtual KisRect windowToView(const KisRect& rc) = 0; + virtual void windowToView(Q_INT32 *x, Q_INT32 *y) = 0; + + /** + * Set the cursor shown when the pointer is over the canvas widget to + * the specified cursor. + * + * @param cursor the new cursor + * @return the old cursor + */ + virtual QCursor setCanvasCursor(const QCursor & cursor) = 0; + + /** + * Set the active input device to the specified input device, This + * could be a mouse, a stylus, an eraser or any other pointing input + * device. + * + * @param inputDevice the new input device + */ + virtual void setInputDevice(KisInputDevice inputDevice) = 0; + + /** + * @return the current input device, such as a mouse or a stylus + */ + virtual KisInputDevice currentInputDevice() const = 0; + + +private: + KisCanvasController(const KisCanvasController&); + KisCanvasController& operator=(const KisCanvasController&); +}; + +#endif // KIS_CANVAS_CONTROLLER_H_ + diff --git a/krita/sdk/kis_canvas_observer.h b/krita/sdk/kis_canvas_observer.h new file mode 100644 index 00000000..e62d23f3 --- /dev/null +++ b/krita/sdk/kis_canvas_observer.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2003 Patrick Julien <freak@codepimps.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 + * 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 KIS_CANVAS_OBSERVER_H_ +#define KIS_CANVAS_OBSERVER_H_ + +class KisCanvasSubject; + +/** + * This is the base interface plugins use to implement the Observer + * design pattern. Observer can register themselves with an implementation + * of KisCanvasSubject. The KisCanvasSubject will then call update() + * on all registered observers whenever something interesting has happened. + * + * (This is something my predecessor should have done with signals and slots, + * I think...) + */ +class KisCanvasObserver { +public: + KisCanvasObserver() {}; + virtual ~KisCanvasObserver() {}; + +public: + /** + * Implement this function to query the KisCanvasSubject implementation + * about state that may be interesting, such as current paint color and + * so on. + * + * @param subject the KisCanvasSubject that may know something that's + * interesting for us. + */ + virtual void update(KisCanvasSubject *subject) = 0; + +private: + KisCanvasObserver(const KisCanvasObserver&); + KisCanvasObserver& operator=(const KisCanvasObserver&); +}; + +#endif // KIS_CANVAS_OBSERVER_H_ + diff --git a/krita/sdk/kis_canvas_subject.h b/krita/sdk/kis_canvas_subject.h new file mode 100644 index 00000000..7fcef988 --- /dev/null +++ b/krita/sdk/kis_canvas_subject.h @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2003 Patrick Julien <freak@codepimps.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 + * 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 KIS_CANVAS_SUBJECT_H_ +#define KIS_CANVAS_SUBJECT_H_ + +#include "kis_types.h" +#include "kis_id.h" + +class KisDoc; +class KisBrush; +class KisCanvasController; +class KisCanvasObserver; +class KisGradient; +class KisPattern; +class KisPaintOpFactory; +class KisToolControllerInterface; +class KisUndoAdapter; +class KisProgressDisplayInterface; +class KisSelectionManager; +class QWidget; +class QCursor; +class KisColor; +class KoPaletteManager; +class KisProfile; +class KisPaintOpSettings; +class KisPerspectiveGridManager; + +/** + * KisCanvasSubject is part of the Observer pattern. Classes implementing KisCanvasObserver + * that have attached themselves to a class implementing this interface will be notified + * whenever any of the methods defined in this class will return something different. + * + * Historical notes: This class has grown a bit an now seems to be the abstract definition + * of the View part in the Model-View-Controller pattern. We need to fix this! + */ +class KisCanvasSubject { + +public: + KisCanvasSubject() {}; + virtual ~KisCanvasSubject() {}; + +public: + + /** + * From now on, the observer will be notified of changes in + * brush, foreground color, background color, pattern, gradient + * and paintop + */ + virtual void attach(KisCanvasObserver *observer) = 0; + + /** + * From now on, the specified observer will no longer be informed + * of changes. + */ + virtual void detach(KisCanvasObserver *observer) = 0; + + /** + * Calling this method will notify all observers. Do not call this + * method from the Update method of a KisCanvasObserver! + */ + virtual void notifyObservers() = 0; + + /** + * @return the image that is currently active. + */ + virtual KisImageSP currentImg() const = 0; + + /** + * @return the background color + */ + virtual KisColor bgColor() const = 0; + + /** + * Set the background color. This should cause all observers to be notified. Do not call from KisCanvasObserver::update()! + * + * @param c the new background color + */ + virtual void setBGColor(const KisColor& c) = 0; + + /** + * @return the currently set foreground or painting color + */ + virtual KisColor fgColor() const = 0; + + /** + * Set the foreground or painting color. This should cause all observers to be notified. Do not call from KisCanvasObserver::update()! + * + * @param c the new foreground color + */ + virtual void setFGColor(const KisColor& c) = 0; + + /** + * @return the exposure value. This determines which exposure of multiple exposure or HDR images will be displayed + */ + virtual float HDRExposure() const = 0; + + /** + * Set the exposure value. This determines which exposure of multiple exposure or HDR images will be displayed. All observers should be notified. + * + * @param exposure the new exposure value + */ + virtual void setHDRExposure(float exposure) = 0; + + /** + * @return the current brush object. + */ + virtual KisBrush *currentBrush() const = 0; + + /** + * @return the current pattern object. + */ + virtual KisPattern *currentPattern() const = 0; + + /** + * @return the current gradient object + */ + virtual KisGradient *currentGradient() const = 0; + + /** + * @return the identification of the current paintop object, not the paintop object itself. + */ + virtual KisID currentPaintop() const = 0; + + /** + * @return the settings for the current paintop object, or 0 if there are no options set. + */ + virtual const KisPaintOpSettings *currentPaintopSettings() const = 0; + + /** + * @return the currently applied zoom factor. XXX: Shouldn't this be in the canvas controller? + */ + virtual double zoomFactor() const = 0; + + /** + * retrieve the undo adapater -- there is one undo adapter + * per document, and it collects all transactions + */ + virtual KisUndoAdapter *undoAdapter() const = 0; + + /** + * @return the interface to the canvas widget + */ + virtual KisCanvasController *canvasController() const = 0; + + /// XXX: Remove this method + virtual KisToolControllerInterface *toolController() const = 0; + + /// XXX: Remove this method + virtual KisDoc * document() const = 0; + + /// XXX: Remove this method + virtual KisProgressDisplayInterface *progressDisplay() const = 0; + + /// XXX: Remove this method + virtual KisSelectionManager * selectionManager() = 0; + + /// XXX: Remove this method + virtual KoPaletteManager * paletteManager() = 0; + + /** + * Get the profile that this view uses to display itself on + * he monitor. + */ + virtual KisProfile * monitorProfile() = 0; + + /** + * Get the perspective grid manager. + */ + virtual KisPerspectiveGridManager* perspectiveGridManager() = 0; +private: + KisCanvasSubject(const KisCanvasSubject&); + KisCanvasSubject& operator=(const KisCanvasSubject&); +}; + +#endif // KIS_CANVAS_SUBJECT_H_ + diff --git a/krita/sdk/kis_debug_areas.h b/krita/sdk/kis_debug_areas.h new file mode 100644 index 00000000..67cb3566 --- /dev/null +++ b/krita/sdk/kis_debug_areas.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.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 + * 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 KIS_DEBUG_AREAS_H_ +#define KIS_DEBUG_AREAS_H_ + +#define DBG_AREA_CORE 41001 +#define DBG_AREA_REGISTRY 40002 +#define DBG_AREA_TOOLS 41003 +#define DBG_AREA_CMS 41004 +#define DBG_AREA_FILTERS 41005 +#define DBG_AREA_PLUGINS 41006 +#define DBG_AREA_UI 41007 +#define DBG_AREA_FILE 41008 +#define DBG_AREA_MATH 41009 +#define DBG_AREA_RENDER 41010 +#define DBG_AREA_SCRIPT 41011 + + +#endif diff --git a/krita/sdk/kis_generic_registry.h b/krita/sdk/kis_generic_registry.h new file mode 100644 index 00000000..bb930d90 --- /dev/null +++ b/krita/sdk/kis_generic_registry.h @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2004 Cyrille Berger <cberger@cberger.net> + * + * 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 _KIS_GENERIC_REGISTRY_H_ +#define _KIS_GENERIC_REGISTRY_H_ + +#include <map> + +#include <qstring.h> +#include <kdebug.h> + +#include <kis_id.h> + +/** + * Base class for registry objects in Krita. Krita registries + * contain resources such as filters, tools or colorspaces. + * + * Items are mapped by KisID. A KisID is the combination of + * a non-localized string that can be used in files and a + * user-visible, translated string that can be used in the + * user interface. + */ +template<typename _T> +class KisGenericRegistry { +protected: + typedef std::map<KisID, _T> storageMap; +public: + KisGenericRegistry() { }; + virtual ~KisGenericRegistry() { }; +public: + + /** + * add an object to the registry + * @param item the item to add (NOTE: _T must have an KisID id() function) + */ + void add(_T item) + { + m_storage.insert( typename storageMap::value_type( item->id(), item) ); + } + /** + * add an object to the registry + * @param id the id of the object + * @param item the item + */ + void add(KisID id, _T item) + { + m_storage.insert(typename storageMap::value_type(id, item)); + } + /** + * This function remove an item from the registry + * @return the object which have been remove from the registry and which can be safely delete + */ + _T remove(const KisID& name) + { + _T p = 0; + typename storageMap::iterator it = m_storage.find(name); + if (it != m_storage.end()) { + m_storage.erase(it); + p = it->second; + } + return p; + } + /** + * This function remove an item from the registry + * @param id the identifiant of the object + * @return the object which have been remove from the registry and which can be safely delete + */ + _T remove(const QString& id) + { + return remove(KisID(id,"")); + } + /** + * This function allow to get an object from its KisID + * @param name the KisID of the object + * @return _T the object + */ + _T get(const KisID& name) const + { + _T p = 0; + typename storageMap::const_iterator it = m_storage.find(name); + if (it != m_storage.end()) { + p = it->second; + } + return p; + } + + /** + * Get a single entry based on the identifying part of KisID, not the + * the descriptive part. + */ + _T get(const QString& id) const + { + return get(KisID(id, "")); + } + + /** + * @param id + * @return true if there is an object corresponding to id + */ + bool exists(const KisID& id) const + { + typename storageMap::const_iterator it = m_storage.find(id); + return (it != m_storage.end()); + } + + bool exists(const QString& id) const + { + return exists(KisID(id, "")); + } + /** + * This function allow to search a KisID from the name. + * @param t the name to search + * @param result The result is filled in this variable + * @return true if the search has been successfull, false otherwise + */ + bool search(const QString& t, KisID& result) const + { + for(typename storageMap::const_iterator it = m_storage.begin(); + it != m_storage.end(); ++it) + { + if(it->first.name() == t) + { + result = it->first; + return true; + } + } + return false; + } + + /** This function return a list of all the keys + */ + KisIDList listKeys() const + { + KisIDList list; + typename storageMap::const_iterator it = m_storage.begin(); + typename storageMap::const_iterator endit = m_storage.end(); + while( it != endit ) + { + list.append(it->first); + ++it; + } + return list; + } + +protected: + KisGenericRegistry(const KisGenericRegistry&) { }; + KisGenericRegistry operator=(const KisGenericRegistry&) { }; + storageMap m_storage; +}; + +#endif diff --git a/krita/sdk/kis_global.h b/krita/sdk/kis_global.h new file mode 100644 index 00000000..31a982da --- /dev/null +++ b/krita/sdk/kis_global.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2000 Matthias Elter <elter@kde.org> + * Copyright (c) 2002 Patrick Julien <freak@codepimps.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 + * 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 KISGLOBAL_H_ +#define KISGLOBAL_H_ + +#include <config.h> +#include LCMS_HEADER +#include <limits.h> +#include <qglobal.h> +#include <kglobal.h> + +#define KRITA_VERSION VERSION + +const Q_UINT8 Q_UINT8_MAX = UCHAR_MAX; +const Q_UINT16 Q_UINT16_MAX = 65535; + +const Q_INT32 Q_INT32_MAX = (2147483647); +const Q_INT32 Q_INT32_MIN = (-2147483647-1); + +const Q_UINT8 OPACITY_TRANSPARENT = 0; +const Q_UINT8 OPACITY_OPAQUE = UCHAR_MAX; + +const Q_UINT8 MAX_SELECTED = UCHAR_MAX; +const Q_UINT8 MIN_SELECTED = 0; +const Q_UINT8 SELECTION_THRESHOLD = 1; + +enum enumCursorStyle { + CURSOR_STYLE_TOOLICON = 0, + CURSOR_STYLE_CROSSHAIR = 1, + CURSOR_STYLE_POINTER = 2, + CURSOR_STYLE_OUTLINE = 3 +}; + +enum enumResourceTypes { + RESOURCE_PAINTOP, + RESOURCE_FILTER, + RESOURCE_TOOL, + RESOURCE_COLORSPACE +}; + +/* + * Most wacom pads have 512 levels of pressure; Qt only supports 256, and even + * this is downscaled to 127 levels because the line would be too jittery, and + * the amount of masks take too much memory otherwise. + */ +const Q_INT32 PRESSURE_LEVELS= 127; +const double PRESSURE_MIN = 0.0; +const double PRESSURE_MAX = 1.0; +const double PRESSURE_DEFAULT = (PRESSURE_MAX - PRESSURE_MIN) / 2; +const double PRESSURE_THRESHOLD = 5.0 / 255.0; + +#define CLAMP(x,l,u) ((x)<(l)?(l):((x)>(u)?(u):(x))) + + +namespace krita { + + // String constants for palettes and palette widgets + const QString TOOL_OPTION_WIDGET ("tooloptions"); + + const QString CONTROL_PALETTE ("controlpalette"); + const QString PAINTBOX ("paintbox"); + const QString COLORBOX ("colorbox"); + const QString LAYERBOX ("layerbox"); +} + +#endif // KISGLOBAL_H_ + diff --git a/krita/sdk/kis_id.h b/krita/sdk/kis_id.h new file mode 100644 index 00000000..b5651505 --- /dev/null +++ b/krita/sdk/kis_id.h @@ -0,0 +1,108 @@ +/* + * This file is part of the KDE project + * + * Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.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 + * 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 _KIS_ID_H_ +#define _KIS_ID_H_ + +#include <qvaluelist.h> +#include <qstring.h> + +/** + * Krita has a large number of extensible resources. Think: + * + * - Brushes + * - Palettes + * - Patterns + * - Gradients + * - Color models + * - Filters + * - Composition operations + * - Paint operations + * - Tools + * - Docker tabs + * + * and more... + * + * Many of these resources are stored in KisGenericRegistry-based + * registries. If we store these resources with a descriptive string + * as a key use the same string in our UI, then our UI will not be + * localizable, because the identifications of particular resources + * will be stored in files, and those files need to be exchangeable. + * + * So, instead we use and ID class that couples an identification + * string that will be the same across all languages, an i18n-able + * string that will be used in comboboxes and that has a fast equality + * operator to make it well suited for use as key in a registry map. + * + * That last bit has not been solved yet. + * + */ +class KisID { + + +public: + + KisID() : m_id(QString::null), m_name(QString::null) {} + + KisID(const QString & id, const QString & name = QString::null) + : m_id(id), + m_name(name) {}; + + QString id() const { return m_id; }; + QString name() const { return m_name; }; + + friend inline bool operator==(const KisID &, const KisID &); + friend inline bool operator!=(const KisID &, const KisID &); + friend inline bool operator<(const KisID &, const KisID &); + friend inline bool operator>(const KisID &, const KisID &); + +private: + + QString m_id; + QString m_name; + +}; + +inline bool operator==(const KisID &v1, const KisID &v2) +{ + return v1.m_id == v2.m_id; +} + +inline bool operator!=(const KisID &v1, const KisID &v2) +{ + return v1.m_id != v2.m_id; +} + + +inline bool operator<(const KisID &v1, const KisID &v2) +{ + return v1.m_id < v2.m_id; +} + + +inline bool operator>(const KisID &v1, const KisID &v2) +{ + return v1.m_id < v2.m_id; +} + + +typedef QValueList<KisID> KisIDList; + +#endif // _KIS_ID_H_ diff --git a/krita/sdk/kis_integer_maths.h b/krita/sdk/kis_integer_maths.h new file mode 100644 index 00000000..c8db9aee --- /dev/null +++ b/krita/sdk/kis_integer_maths.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2005 Adrian Page <adrian@pagenet.plus.com> + * + * 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 KIS_INTEGER_MATHS_H +#define KIS_INTEGER_MATHS_H + +#define UINT8_MAX 255u +#define UINT8_MIN 0u + +#define UINT16_MAX 65535u +#define UINT16_MIN 0u + +#define UINT32_MAX (4294967295u) +#define UINT32_MIN 0u + +#define INT16_MAX 32767 +#define INT16_MIN -32768 + +/// take a and scale it up by 256*b/255 +inline uint UINT8_SCALEBY(uint a, uint b) +{ + uint c = a * b + 0x80u; + return (c >> 8) + c; +} + +inline uint UINT8_MULT(uint a, uint b) +{ + uint c = a * b + 0x80u; + return ((c >> 8) + c) >> 8; +} + +inline uint UINT8_DIVIDE(uint a, uint b) +{ + uint c = (a * UINT8_MAX + (b / 2u)) / b; + return c; +} + +inline uint UINT8_BLEND(uint a, uint b, uint alpha) +{ + // Basically we do a*alpha + b*(1-alpha) + // However refactored to (a-b)*alpha + b since that saves a multiplication + // Signed arithmetic is needed since a-b might be negative + int c = ((int(a) - int(b)) * int(alpha)) >> 8; + + return uint(c + b); +} + +inline uint UINT16_MULT(uint a, uint b) +{ + uint c = a * b + 0x8000u; + return ((c >> 16) + c) >> 16; +} + +inline int INT16_MULT(int a, int b) +{ + return (a*b) / INT16_MAX; +} + +inline uint UINT16_DIVIDE(uint a, uint b) +{ + uint c = (a * UINT16_MAX + (b / 2u)) / b; + return c; +} + +inline uint UINT16_BLEND(uint a, uint b, uint alpha) +{ + // Basically we do a*alpha + b*(1-alpha) + // However refactored to (a-b)*alpha + b since that saves a multiplication + // Signed arithmetic is needed since a-b might be negative + int c = ((int(a) - int(b)) * int(alpha)) >> 16; + return uint(c + b); +} + +inline uint UINT8_TO_UINT16(uint c) +{ + return c | (c<<8); +} + +inline uint UINT16_TO_UINT8(uint c) +{ + //return round(c / 257.0); + //For all UINT16 this calculation is the same and a lot faster (off by c/65656 which for every c is 0) + c = c - (c >> 8) + 128; + return c >>8; +} + +inline int INT16_BLEND(int a, int b, uint alpha) +{ + // Basically we do a*alpha + b*(1-alpha) + // However refactored to (a-b)*alpha + b since that saves a multiplication + int c = ((int(a) - int(b)) * int(alpha)) >> 16; + return c + b; +} + +#endif + diff --git a/krita/sdk/kis_progress_display_interface.h b/krita/sdk/kis_progress_display_interface.h new file mode 100644 index 00000000..bf0dede3 --- /dev/null +++ b/krita/sdk/kis_progress_display_interface.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com> + * + * 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 KIS_PROGRESS_DISPLAY_INTERFACE_H_ +#define KIS_PROGRESS_DISPLAY_INTERFACE_H_ + +class KisProgressSubject; + + +namespace KisProgress { + + const int ProgressEventBase = QEvent::User + 42 + 42; + + class UpdateEvent : QCustomEvent { + + public: + + UpdateEvent(int percent) : QCustomEvent(ProgressEventBase + 1), m_percent(percent) {}; + int m_percent; + }; + + class UpdateStageEvent : QCustomEvent { + + public: + + UpdateStageEvent(const QString & stage, int percent) : QCustomEvent(ProgressEventBase + 2 ), m_stage(stage), m_percent(percent) {}; + QString m_stage; + int m_percent; + }; + + class DoneEvent : QCustomEvent { + DoneEvent() : QCustomEvent(ProgressEventBase + 3){}; + }; + + class ErrorEvent : QCustomEvent { + ErrorEvent() : QCustomEvent(ProgressEventBase + 4){}; + }; + + class DestroyedEvent: QCustomEvent { + DestroyedEvent() : QCustomEvent(ProgressEventBase + 5){}; + }; + + +} + + + +class KisProgressDisplayInterface { +public: + KisProgressDisplayInterface() {} + virtual ~KisProgressDisplayInterface() {} + + virtual void setSubject(KisProgressSubject *subject, bool modal, bool canCancel) = 0; + +private: + KisProgressDisplayInterface(const KisProgressDisplayInterface&); + KisProgressDisplayInterface& operator=(const KisProgressDisplayInterface&); +}; + +#endif // KIS_PROGRESS_DISPLAY_INTERFACE_H_ + diff --git a/krita/sdk/kis_progress_subject.cc b/krita/sdk/kis_progress_subject.cc new file mode 100644 index 00000000..fa53086b --- /dev/null +++ b/krita/sdk/kis_progress_subject.cc @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2002 Patrick Julien <freak@codepimps.org> + * 2004 Adrian Page <adrian@pagenet.plus.com> + * + * 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 <kdebug.h> + +#include "kis_progress_subject.h" + +KisProgressSubject::~KisProgressSubject() +{ +} + +#include "kis_progress_subject.moc" + diff --git a/krita/sdk/kis_progress_subject.h b/krita/sdk/kis_progress_subject.h new file mode 100644 index 00000000..d936c7b7 --- /dev/null +++ b/krita/sdk/kis_progress_subject.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2002 Patrick Julien <freak@codepimps.org> + * 2004 Adrian Page <adrian@pagenet.plus.com> + * + * 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 KIS_PROGRESS_SUBJECT_H_ +#define KIS_PROGRESS_SUBJECT_H_ + +#include <qobject.h> +#include <koffice_export.h> + +class KRITAUI_EXPORT KisProgressSubject : public QObject { + Q_OBJECT + +protected: + KisProgressSubject() {}; + KisProgressSubject(QObject * parent, const char * name) : QObject(parent, name) {}; + virtual ~KisProgressSubject(); + +public: + virtual void cancel() = 0; + +signals: + void notifyProgress(int percent); + void notifyProgressStage(const QString& stage, int percent); + void notifyProgressDone(); + void notifyProgressError(); +}; + +#endif // KIS_PROGRESS_SUBJECT_H_ + diff --git a/krita/sdk/kis_shared_ptr_vector.h b/krita/sdk/kis_shared_ptr_vector.h new file mode 100644 index 00000000..0a7695a1 --- /dev/null +++ b/krita/sdk/kis_shared_ptr_vector.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com> + * + * 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 KIS_SHARED_PTR_VECTOR_H +#define KIS_SHARED_PTR_VECTOR_H + +#include <qvaluevector.h> + +#include <ksharedptr.h> + +/** + * QValueVector does not always destroy an element when it is erased. + * If the items it is holding are KSharedPtr, this can result in hidden + * references to objects that cannot be accounted for. This class + * sets the KSharedPtr to 0 on erase, which dereferences the object as + * expected. + */ +template <class T> +class KisSharedPtrVector : public QValueVector< KSharedPtr<T> > +{ + typedef QValueVector< KSharedPtr<T> > super; +public: + KisSharedPtrVector() {} + + void pop_back() + { + if (!super::empty()) { + super::back() = 0; + super::pop_back(); + } + } + + typename super::iterator erase(typename super::iterator it) + { + *it = 0; + return super::erase(it); + } + + typename super::iterator erase(typename super::iterator first, typename super::iterator last) + { + qFill(first, last, 0); + return super::erase(first, last); + } + + bool contains(KSharedPtr<T> ptr) const + { + for (int i = 0, n = super::count(); i < n; ++i) + if (super::at(i) == ptr) + return true; + return false; + } +}; + +#endif // KIS_SHARED_PTR_VECTOR_H + diff --git a/krita/sdk/kis_undo_adapter.h b/krita/sdk/kis_undo_adapter.h new file mode 100644 index 00000000..32cd655a --- /dev/null +++ b/krita/sdk/kis_undo_adapter.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2003 Patrick Julien <freak@codepimps.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 + * 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 KIS_UNDO_ADAPTER_H_ +#define KIS_UNDO_ADAPTER_H_ + +#include <qglobal.h> + +class QString; +class KCommand; + +/** + * Undo listeners want to be notified of undo and redo actions. + * add notification is given _before_ the command is added to the + * stack. + * execute notification is given on undo and redo + */ +class KisCommandHistoryListener { + +public: + + KisCommandHistoryListener(){}; + + virtual void notifyCommandAdded(KCommand * cmd) = 0; + virtual void notifyCommandExecuted(KCommand * cmd) = 0; +}; + +class KisUndoAdapter { +public: + KisUndoAdapter() {}; + virtual ~KisUndoAdapter() {}; + +public: + + virtual void setCommandHistoryListener(const KisCommandHistoryListener *) = 0; + virtual void removeCommandHistoryListener(const KisCommandHistoryListener *) = 0; + + virtual KCommand * presentCommand() = 0; + virtual void addCommand(KCommand *cmd) = 0; + virtual void setUndo(bool undo) = 0; + virtual bool undo() const = 0; + virtual void beginMacro(const QString& macroName) = 0; + virtual void endMacro() = 0; + +private: + KisUndoAdapter(const KisUndoAdapter&); + KisUndoAdapter& operator=(const KisUndoAdapter&); +}; + + +#endif // KIS_UNDO_ADAPTER_H_ + |