Krita Source Code Documentation
Loading...
Searching...
No Matches
KoDocumentResourceManager Class Reference

#include <KoDocumentResourceManager.h>

+ Inheritance diagram for KoDocumentResourceManager:

Public Types

enum  DocumentResource {
  UndoStack , OdfDocument , GrabSensitivity , MarkerCollection ,
  DocumentResolution , DocumentRectInPixels , KarbonStart = 1000 , KexiStart = 2000 ,
  FlowStart = 3000 , PlanStart = 4000 , StageStart = 5000 , KritaStart = 6000 ,
  SheetsStart = 7000 , WordsStart = 8000 , KoPageAppStart = 9000 , KoTextStart = 10000
}
 

Signals

void resourceChanged (int key, const QVariant &value)
 

Public Member Functions

bool boolResource (int key) const
 
void clearResource (int key)
 
QRectF documentRectInPixels () const
 
qreal documentResolution () const
 
int grabSensitivity () const
 Returns the actual grab sensitivity.
 
bool hasResource (int key) const
 
int intResource (int key) const
 
KoColor koColorResource (int key) const
 
 KoDocumentResourceManager (QObject *parent=0)
 
KoShapekoShapeResource (int key) const
 
QVariant resource (int key) const
 
void setGrabSensitivity (int grabSensitivity)
 
void setResource (int key, const KoColor &color)
 
void setResource (int key, const KoUnit &unit)
 
void setResource (int key, const QVariant &value)
 
void setResource (int key, KoShape *shape)
 
void setUndoStack (KUndo2Stack *undoStack)
 
QSizeF sizeResource (int key) const
 
QString stringResource (int key) const
 
KUndo2StackundoStack () const
 
KoUnit unitResource (int key) const
 
 ~KoDocumentResourceManager () override
 

Public Attributes

KoResourceManager manager
 

Private Member Functions

 KoDocumentResourceManager (const KoDocumentResourceManager &)
 
KoDocumentResourceManageroperator= (const KoDocumentResourceManager &)
 
- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Detailed Description

The KoResourceManager contains a set of per-canvas or per-document properties, like current foreground color, current background color and more. All tools belonging to the current canvas are notified when a Resource changes (is set).

The properties come from the KoDocumentResourceManager::DocumentResource See KoShapeController::resourceManager

The manager can contain all sorts of variable types and there are accessors for the most common ones. All variables are always stored inside a QVariant instance internally and you can always just use the resource() method to get that directly. The way to store arbitrary data objects that are stored as pointers you can use the following code snippets;

QVariant variant;
variant.setValue<void*>(textShapeData->document());
resourceManager->setResource(KoText::CurrentTextDocument, variant);
// and get it out again.
QVariant var = resourceManager->resource(KoText::CurrentTextDocument);
document = static_cast<QTextDocument*>(var.value<void*>());

Definition at line 19 of file KoDocumentResourceManager.cpp.

Member Enumeration Documentation

◆ DocumentResource

This enum holds identifiers to the resources that can be stored in here.

Enumerator
UndoStack 

The document-wide undo stack (KUndo2Stack)

OdfDocument 

OBSOLETE The document this canvas shows.

GrabSensitivity 

The grab sensitivity used for grabbing handles of any kind.

MarkerCollection 

The collection holding all markers.

DocumentResolution 

Pixels-per-inch resolution of the document.

DocumentRectInPixels 

Bounds of the document in pixels.

KarbonStart 

Base number for Karbon specific values.

KexiStart 

Base number for Kexi specific values.

FlowStart 

Base number for Flow specific values.

PlanStart 

Base number for Plan specific values.

StageStart 

Base number for Stage specific values.

KritaStart 

Base number for Krita specific values.

SheetsStart 

Base number for Sheets specific values.

WordsStart 

Base number for Words specific values.

KoPageAppStart 

Base number for KoPageApp specific values.

KoTextStart 

Base number for KoText specific values.

Definition at line 57 of file KoDocumentResourceManager.h.

57 {
58 UndoStack,
64
65 KarbonStart = 1000,
66 KexiStart = 2000,
67 FlowStart = 3000,
68 PlanStart = 4000,
69 StageStart = 5000,
70 KritaStart = 6000,
71 SheetsStart = 7000,
72 WordsStart = 8000,
73 KoPageAppStart = 9000,
74 KoTextStart = 10000
75};
@ KritaStart
Base number for Krita specific values.
@ KexiStart
Base number for Kexi specific values.
@ OdfDocument
OBSOLETE The document this canvas shows.
@ KarbonStart
Base number for Karbon specific values.
@ UndoStack
The document-wide undo stack (KUndo2Stack)
@ WordsStart
Base number for Words specific values.
@ DocumentRectInPixels
Bounds of the document in pixels.
@ KoTextStart
Base number for KoText specific values.
@ DocumentResolution
Pixels-per-inch resolution of the document.
@ GrabSensitivity
The grab sensitivity used for grabbing handles of any kind.
@ KoPageAppStart
Base number for KoPageApp specific values.
@ FlowStart
Base number for Flow specific values.
@ MarkerCollection
The collection holding all markers.
@ StageStart
Base number for Stage specific values.
@ PlanStart
Base number for Plan specific values.
@ SheetsStart
Base number for Sheets specific values.

Constructor & Destructor Documentation

◆ KoDocumentResourceManager() [1/2]

KoDocumentResourceManager::KoDocumentResourceManager ( QObject * parent = 0)
explicit

Constructor.

Parameters
parentthe parent QObject, used for memory management.

Definition at line 25 of file KoDocumentResourceManager.cpp.

26 : QObject(parent),
27 d(new Private())
28{
31}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void resourceChanged(int key, const QVariant &value)
void resourceChanged(int key, const QVariant &value)

References connect(), d, resourceChanged(), and KoResourceManager::resourceChanged().

◆ ~KoDocumentResourceManager()

KoDocumentResourceManager::~KoDocumentResourceManager ( )
override

Definition at line 33 of file KoDocumentResourceManager.cpp.

34{
35 delete d;
36}

References d.

◆ KoDocumentResourceManager() [2/2]

KoDocumentResourceManager::KoDocumentResourceManager ( const KoDocumentResourceManager & )
private

Member Function Documentation

◆ boolResource()

bool KoDocumentResourceManager::boolResource ( int key) const

Return the resource determined by param key as a boolean.

Parameters
keythe identifying key for the resource
See also
KoDocumentResourceManager::DocumentResource

Definition at line 75 of file KoDocumentResourceManager.cpp.

76{
77 return d->manager.boolResource(key);
78}

References d.

◆ clearResource()

void KoDocumentResourceManager::clearResource ( int key)

Remove the resource with key from the provider.

Parameters
keythe key that will be used to remove the resource There will be a signal emitted with a variable that will return true on QVariable::isNull();
See also
KoDocumentResourceManager::DocumentResource

Definition at line 100 of file KoDocumentResourceManager.cpp.

101{
102 d->manager.clearResource(key);
103}

References d.

◆ documentRectInPixels()

QRectF KoDocumentResourceManager::documentRectInPixels ( ) const

Definition at line 140 of file KoDocumentResourceManager.cpp.

141{
143 return resource(DocumentRectInPixels).toRectF();
144}
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129

References DocumentRectInPixels, hasResource(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, and resource().

◆ documentResolution()

qreal KoDocumentResourceManager::documentResolution ( ) const

◆ grabSensitivity()

int KoDocumentResourceManager::grabSensitivity ( ) const

Returns the actual grab sensitivity.

Definition at line 120 of file KoDocumentResourceManager.cpp.

121{
124 return 5; // default value (and is used just about everywhere)
125}

References GrabSensitivity, hasResource(), and intResource().

◆ hasResource()

bool KoDocumentResourceManager::hasResource ( int key) const

Returns true if there is a resource set with the requested key.

Parameters
keythe identifying key for the resource
See also
KoDocumentResourceManager::DocumentResource

Definition at line 95 of file KoDocumentResourceManager.cpp.

96{
97 return d->manager.hasResource(key);
98}

References d.

◆ intResource()

int KoDocumentResourceManager::intResource ( int key) const

Return the resource determined by param key as an integer.

Parameters
keythe identifying key for the resource
See also
KoDocumentResourceManager::DocumentResource

Definition at line 80 of file KoDocumentResourceManager.cpp.

81{
82 return d->manager.intResource(key);
83}

References d.

◆ koColorResource()

KoColor KoDocumentResourceManager::koColorResource ( int key) const

Return the resource determined by param key as a KoColor.

Parameters
keythe identifying key for the resource
See also
KoDocumentResourceManager::DocumentResource

Definition at line 69 of file KoDocumentResourceManager.cpp.

70{
71 return d->manager.koColorResource(key);
72}

References d.

◆ koShapeResource()

KoShape * KoDocumentResourceManager::koShapeResource ( int key) const

Return the resource determined by param key as a pointer to a KoShape.

Parameters
keythe identifying key for the resource
See also
KoDocumentResourceManager::DocumentResource

◆ operator=()

KoDocumentResourceManager & KoDocumentResourceManager::operator= ( const KoDocumentResourceManager & )
private

◆ resource()

QVariant KoDocumentResourceManager::resource ( int key) const

Returns a qvariant containing the specified resource or a standard one if the specified resource does not exist.

Parameters
keythe key
See also
KoDocumentResourceManager::DocumentResource

Definition at line 43 of file KoDocumentResourceManager.cpp.

44{
45 return d->manager.resource(key);
46}

References d.

◆ resourceChanged

void KoDocumentResourceManager::resourceChanged ( int key,
const QVariant & value )
signal

This signal is emitted every time a resource is set that is either new or different from the previous set value.

Parameters
keythe identifying key for the resource
valuethe variants new value.
See also
KoDocumentResourceManager::DocumentResource

◆ setGrabSensitivity()

void KoDocumentResourceManager::setGrabSensitivity ( int grabSensitivity)

Tools that are used to grab handles or similar with the mouse should use this value to determine if the mouse is near enough

Parameters
grabSensitivitythe grab sensitivity in pixels

Definition at line 112 of file KoDocumentResourceManager.cpp.

113{
114 // do not allow arbitrary small grab sensitivity
115 if (grabSensitivity < 5)
116 grabSensitivity = 5;
118}
int grabSensitivity() const
Returns the actual grab sensitivity.
void setResource(int key, const QVariant &value)

References GrabSensitivity, grabSensitivity(), and setResource().

◆ setResource() [1/4]

void KoDocumentResourceManager::setResource ( int key,
const KoColor & color )

Set a resource of type KoColor.

Parameters
keythe integer key
colorthe new value for the key.
See also
KoDocumentResourceManager::DocumentResource

Definition at line 48 of file KoDocumentResourceManager.cpp.

49{
50 QVariant v;
51 v.setValue(color);
52 setResource(key, v);
53}
qreal v

References setResource(), and v.

◆ setResource() [2/4]

void KoDocumentResourceManager::setResource ( int key,
const KoUnit & unit )

Set a resource of type KoUnit

Parameters
keythe integer key
idthe new value for the key.
See also
KoDocumentResourceManager::DocumentResource

Definition at line 62 of file KoDocumentResourceManager.cpp.

63{
64 QVariant v;
65 v.setValue(unit);
66 setResource(key, v);
67}

References setResource(), and v.

◆ setResource() [3/4]

void KoDocumentResourceManager::setResource ( int key,
const QVariant & value )

Set a resource of any type.

Parameters
keythe integer key
valuethe new value for the key.
See also
KoDocumentResourceManager::DocumentResource

Definition at line 38 of file KoDocumentResourceManager.cpp.

39{
40 d->manager.setResource(key, value);
41}
float value(const T *src, size_t ch)

References d, and value().

◆ setResource() [4/4]

void KoDocumentResourceManager::setResource ( int key,
KoShape * shape )

Set a resource of type KoShape*.

Parameters
keythe integer key
idthe new value for the key.
See also
KoDocumentResourceManager::DocumentResource

Definition at line 55 of file KoDocumentResourceManager.cpp.

56{
57 QVariant v;
58 v.setValue(shape);
59 setResource(key, v);
60}

References setResource(), and v.

◆ setUndoStack()

void KoDocumentResourceManager::setUndoStack ( KUndo2Stack * undoStack)

Definition at line 127 of file KoDocumentResourceManager.cpp.

128{
129 QVariant variant;
130 variant.setValue<void*>(undoStack);
131 setResource(UndoStack, variant);
132}

References setResource(), and undoStack().

◆ sizeResource()

QSizeF KoDocumentResourceManager::sizeResource ( int key) const

Return the resource determined by param key as a QSizeF.

Parameters
keythe identifying key for the resource
See also
KoDocumentResourceManager::DocumentResource

Definition at line 90 of file KoDocumentResourceManager.cpp.

91{
92 return d->manager.sizeResource(key);
93}

References d.

◆ stringResource()

QString KoDocumentResourceManager::stringResource ( int key) const

Return the resource determined by param key as a QString .

Parameters
keythe identifying key for the resource
See also
KoDocumentResourceManager::DocumentResource

Definition at line 85 of file KoDocumentResourceManager.cpp.

86{
87 return d->manager.stringResource(key);
88}

References d.

◆ undoStack()

KUndo2Stack * KoDocumentResourceManager::undoStack ( ) const

Definition at line 105 of file KoDocumentResourceManager.cpp.

106{
108 return 0;
109 return static_cast<KUndo2Stack*>(resource(UndoStack).value<void*>());
110}

References hasResource(), and resource().

◆ unitResource()

KoUnit KoDocumentResourceManager::unitResource ( int key) const

Return the resource determined by param key as a KoUnit.

Parameters
keythe identifying key for the resource
See also
KoDocumentResourceManager::DocumentResource

Member Data Documentation

◆ d

Private* const KoDocumentResourceManager::d
private

Definition at line 221 of file KoDocumentResourceManager.h.

◆ manager

KoResourceManager KoDocumentResourceManager::manager

Definition at line 22 of file KoDocumentResourceManager.cpp.


The documentation for this class was generated from the following files: