1 /*
2  *  Copyright (c) 2006 Boudewijn Rempt  <boud@valdyas.org>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef KIS_CANVAS_RESOURCE_PROVIDER_H_
20 #define KIS_CANVAS_RESOURCE_PROVIDER_H_
21 
22 #include <QObject>
23 
24 #include <KoColor.h>
25 #include <KoID.h>
26 #include <KoCanvasResourceProvider.h>
27 
28 #include "kis_types.h"
29 #include "kritaui_export.h"
30 
31 class KisWorkspaceResource;
32 class KoColorProfile;
33 class KoAbstractGradient;
34 class KoResource;
35 
36 class KoCanvasBase;
37 class KisViewManager;
38 class KoPattern;
39 class KoGamutMask;
40 class KisFilterConfiguration;
41 
42 #include <kis_abstract_perspective_grid.h>
43 
44 /**
45  * KisCanvasResourceProvider contains the per-window current settings that
46  * influence painting, like paintop, color, gradients and so on.
47  */
48 class KRITAUI_EXPORT KisCanvasResourceProvider : public QObject
49 {
50     Q_OBJECT
51 
52 public:
53 
54     enum Resources {
55         HdrExposure = KoCanvasResourceProvider::KritaStart + 1,
56         CurrentPattern,
57         CurrentGamutMask,
58         GamutMaskActive,
59         CurrentGradient,
60         CurrentDisplayProfile,
61         CurrentKritaNode,
62         CurrentPaintOpPreset,
63         CurrentGeneratorConfiguration,
64         CurrentCompositeOp,
65         CurrentEffectiveCompositeOp,
66         LodAvailability, ///<-user choice
67         LodSizeThreshold, ///<-user choice
68         LodSizeThresholdSupported, ///<-paintop property
69         EffectiveLodAvailablility, ///<- a superposition of user choice, threshold and paintop traits
70         EraserMode,
71         MirrorHorizontal,
72         MirrorVertical,
73         MirrorHorizontalLock,
74         MirrorVerticalLock,
75         MirrorVerticalHideDecorations,
76         MirrorHorizontalHideDecorations,
77         Opacity,
78         Flow,
79         Size,
80         HdrGamma,
81         GlobalAlphaLock,
82         DisablePressure,
83         PreviousPaintOpPreset,
84         EffectiveZoom, ///<-Used only by painting tools for non-displaying purposes
85         PatternSize
86     };
87 
88 
89     KisCanvasResourceProvider(KisViewManager * view);
90     ~KisCanvasResourceProvider() override;
91 
92     void setResourceManager(KoCanvasResourceProvider *resourceManager);
93     KoCanvasResourceProvider* resourceManager();
94 
95     KoCanvasBase * canvas() const;
96 
97     KoColor bgColor() const;
98     void setBGColor(const KoColor& c);
99 
100     KoColor fgColor() const;
101     void setFGColor(const KoColor& c);
102 
103     float HDRExposure() const;
104     void setHDRExposure(float exposure);
105 
106     float HDRGamma() const;
107     void setHDRGamma(float gamma);
108 
109     bool eraserMode() const;
110     void setEraserMode(bool value);
111 
112     KoPattern *currentPattern() const;
113 
114     KoAbstractGradient *currentGradient() const;
115 
116     KisImageWSP currentImage() const;
117 
118     KisNodeSP currentNode() const;
119 
120     KoGamutMask* currentGamutMask() const;
121     bool gamutMaskActive() const;
122 
123     KisPaintOpPresetSP currentPreset() const;
124     void setPaintOpPreset(const KisPaintOpPresetSP preset);
125 
126     KisPaintOpPresetSP previousPreset() const;
127     void setPreviousPaintOpPreset(const KisPaintOpPresetSP preset);
128 
129     void setCurrentCompositeOp(const QString& compositeOp);
130     QString currentCompositeOp() const;
131 
132     QList<QPointer<KisAbstractPerspectiveGrid> > perspectiveGrids() const;
133     void addPerspectiveGrid(KisAbstractPerspectiveGrid*);
134     void removePerspectiveGrid(KisAbstractPerspectiveGrid*);
135     void clearPerspectiveGrids();
136 
137     void setMirrorHorizontal(bool mirrorHorizontal);
138     bool mirrorHorizontal() const;
139 
140     void setMirrorVertical(bool mirrorVertical);
141     bool mirrorVertical() const;
142 
143     // options for horizontal and vertical mirror toolbar
144     void setMirrorHorizontalLock(bool isLocked);
145     bool mirrorHorizontalLock();
146     void setMirrorVerticalLock(bool isLocked);
147     bool mirrorVerticalLock();
148 
149     void setMirrorVerticalHideDecorations(bool hide);
150     bool mirrorVerticalHideDecorations();
151 
152     void setMirrorHorizontalHideDecorations(bool hide);
153     bool mirrorHorizontalHideDecorations();
154 
155     void mirrorVerticalMoveCanvasToCenter();
156     void mirrorHorizontalMoveCanvasToCenter();
157 
158     void setOpacity(qreal opacity);
159     qreal opacity() const;
160 
161     void setFlow(qreal opacity);
162     qreal flow() const;
163 
164     void setSize(qreal size);
165     qreal size() const;
166 
167     void setPatternSize(qreal size);
168     qreal patternSize() const;
169 
170     void setGlobalAlphaLock(bool lock);
171     bool globalAlphaLock() const;
172 
173     void setDisablePressure(bool value);
174     bool disablePressure() const;
175 
176     ///Notify that the workspace is saved and settings should be saved to it
177     void notifySavingWorkspace(KisWorkspaceResource* workspace);
178 
179     ///Notify that the workspace is loaded and settings can be read
180     void notifyLoadingWorkspace(KisWorkspaceResource* workspace);
181 
182 public Q_SLOTS:
183 
184     void slotSetFGColor(const KoColor& c);
185     void slotSetBGColor(const KoColor& c);
186     void slotPatternActivated(KoResource *pattern);
187     void slotGradientActivated(KoResource *gradient);
188     void slotNodeActivated(const KisNodeSP node);
189     void slotPainting();
190 
191     void slotGamutMaskActivated(KoGamutMask* mask);
192     void slotGamutMaskUnset();
193     void slotGamutMaskPreviewUpdate();
194     void slotGamutMaskDeactivate();
195 
196     /**
197      * Set the image size in pixels. The resource provider will store
198      * the image size in postscript points.
199      */
200     // FIXME: this slot doesn't catch the case when image resolution is changed
201     void slotImageSizeChanged();
202     void slotOnScreenResolutionChanged();
203 
204 private Q_SLOTS:
205 
206     void slotCanvasResourceChanged(int key, const QVariant & res);
207 
208 Q_SIGNALS:
209 
210     void sigFGColorChanged(const KoColor &);
211     void sigBGColorChanged(const KoColor &);
212     void sigGradientChanged(KoAbstractGradient *);
213     void sigPatternChanged(KoPattern *);
214     void sigNodeChanged(const KisNodeSP);
215     void sigDisplayProfileChanged(const KoColorProfile *);
216     void sigFGColorUsed(const KoColor&);
217     void sigOnScreenResolutionChanged(qreal scaleX, qreal scaleY);
218     void sigOpacityChanged(qreal);
219     void sigSavingWorkspace(KisWorkspaceResource* workspace);
220     void sigLoadingWorkspace(KisWorkspaceResource* workspace);
221 
222     void mirrorModeChanged();
223     void moveMirrorVerticalCenter();
224     void moveMirrorHorizontalCenter();
225 
226     void sigGamutMaskChanged(KoGamutMask* mask);
227     void sigGamutMaskUnset();
228     void sigGamutMaskPreviewUpdate();
229     void sigGamutMaskDeactivated();
230 
231 private:
232 
233     KisViewManager * m_view;
234     KoCanvasResourceProvider *m_resourceManager;
235     bool m_fGChanged;
236     QList<QPointer<KisAbstractPerspectiveGrid> > m_perspectiveGrids;
237 };
238 
239 #endif
240