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 #ifndef KIS_LAYER_MANAGER
19 #define KIS_LAYER_MANAGER
20 
21 #include <QObject>
22 #include <QPointer>
23 #include <QList>
24 
25 #include "kis_adjustment_layer.h"
26 #include "kis_generator_layer.h"
27 #include "kis_types.h"
28 #include "KisView.h"
29 #include <filter/kis_filter_configuration.h>
30 
31 class KisViewManager;
32 class KisNodeCommandsAdapter;
33 class KisAction;
34 class KisActionManager;
35 class KisProcessingApplicator;
36 
37 /**
38  * KisLayerManager takes care of the gui around working with layers:
39  * adding, removing, editing. It also keeps track of the active layer
40  * for this view.
41  */
42 class KisLayerManager : public QObject
43 {
44 
45     Q_OBJECT
46 
47 public:
48 
49     KisLayerManager(KisViewManager * view);
50     ~KisLayerManager() override;
51     void setView(QPointer<KisView>view);
52 
53 Q_SIGNALS:
54 
55 private:
56 
57     friend class KisNodeManager;
58 
59     /**
60      * Activate the specified layer. The layer may be 0.
61      */
62     void activateLayer(KisLayerSP layer);
63 
64     KisLayerSP activeLayer();
65     KisPaintDeviceSP activeDevice();
66 
67 
68     void setup(KisActionManager *actionManager);
69 
70     void updateGUI();
71 
72 private Q_SLOTS:
73 
74     void mergeLayer();
75 
76     void imageResizeToActiveLayer();
77     void trimToImage();
78 
79     void layerProperties();
80 
81     void flattenImage();
82 
83     void flattenLayer();
84     void rasterizeLayer();
85 
86     void layersUpdated();
87 
88     void saveGroupLayers();
89     bool activeLayerHasSelection();
90 
91     void convertNodeToPaintLayer(KisNodeSP source);
92     void convertGroupToAnimated();
93 
94     void convertLayerToFileLayer(KisNodeSP source);
95 
96     KisLayerSP addPaintLayer(KisNodeSP activeNode);
97     KisNodeSP addGroupLayer(KisNodeSP activeNode);
98 
99     KisNodeSP addCloneLayer(KisNodeList nodes);
100 
101     KisNodeSP addShapeLayer(KisNodeSP activeNode);
102 
103     KisNodeSP addAdjustmentLayer(KisNodeSP activeNode);
104     KisAdjustmentLayerSP addAdjustmentLayer(KisNodeSP activeNode, const QString & name, KisFilterConfigurationSP  filter, KisSelectionSP selection, KisProcessingApplicator *applicator);
105 
106     KisNodeSP addGeneratorLayer(KisNodeSP activeNode);
107     KisGeneratorLayerSP addGeneratorLayer(KisNodeSP activeNode, const QString &name, KisFilterConfigurationSP filter, KisSelectionSP selection, KisProcessingApplicator *applicator);
108 
109     KisNodeSP addFileLayer(KisNodeSP activeNode);
110 
111     void layerStyle();
112 
113     void changeCloneSource();
114 
115 private:
116     void adjustLayerPosition(KisNodeSP node, KisNodeSP activeNode, KisNodeSP &parent, KisNodeSP &above);
117     void addLayerCommon(KisNodeSP activeNode, KisNodeSP layer, bool updateImage = true, KisProcessingApplicator *applicator = 0);
118 
119 private:
120 
121     KisViewManager * m_view;
122     QPointer<KisView>m_imageView {0};
123 
124     KisAction *m_imageFlatten {0};
125     KisAction *m_imageMergeLayer {0};
126     KisAction *m_groupLayersSave {0};
127     KisAction *m_convertGroupAnimated {0};
128     KisAction *m_imageResizeToLayer {0};
129     KisAction *m_flattenLayer {0};
130     KisAction *m_rasterizeLayer {0};
131     KisNodeCommandsAdapter* m_commandsAdapter;
132 
133     KisAction *m_layerStyle {0};
134 };
135 
136 #endif
137