chalk

kis_populate_visitor.h
1/*
2 * Copyright (c) 2005 Gábor Lehel <illissius@gmail.com>
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_POPULATE_VISITOR_H
20#define KIS_POPULATE_VISITOR_H
21
22#include <kiconloader.h>
23#include "kis_types.h"
24#include "kis_layer.h"
25#include "kis_group_layer.h"
26#include "kis_paint_layer.h"
27#include "kis_part_layer.h"
28#include "kis_adjustment_layer.h"
29#include "kis_layerlist.h"
30
31
36class KisPopulateVisitor: public KisLayerVisitor
37{
38 public:
39 KisPopulateVisitor(KisLayerList* widget)
40 : m_widget(widget)
41 , m_parent(0)
42 { }
43
44 KisPopulateVisitor(KisLayerItem* parent)
45 : m_widget(parent->listView())
46 , m_parent(parent)
47 { }
48
49 virtual bool visit(KisPaintLayer* layer)
50 {
51 if (!layer->temporary())
52 add(layer);
53 return true;
54 }
55
56 virtual bool visit(KisPartLayer* layer)
57 {
58 add(layer)->setPixmap(0, SmallIcon("gear", 16));
59 return true;
60 }
61
62 virtual bool visit(KisAdjustmentLayer* layer)
63 {
64 add(layer)->setPixmap(0, SmallIcon("tool_filter", 16));
65 return true;
66 }
67
68 virtual bool visit(KisGroupLayer* layer)
69 {
70 KisLayerItem* item = add(layer);
71 item->makeFolder();
72 KisPopulateVisitor visitor(item);
73 for (KisLayerSP l = layer->firstChild(); l; l = l->nextSibling())
74 l->accept(visitor);
75
76 vKisLayerSP childLayersAdded = visitor.layersAdded();
77
78 for (vKisLayerSP::iterator it = childLayersAdded.begin(); it != childLayersAdded.end(); ++it) {
79 m_layersAdded.append(*it);
80 }
81
82 return true;
83 }
84
85 vKisLayerSP layersAdded() const
86 {
87 return m_layersAdded;
88 }
89
90 private:
91 LayerList* m_widget;
92 KisLayerItem* m_parent;
93 vKisLayerSP m_layersAdded;
94
95 KisLayerItem* add(KisLayer* layer)
96 {
97 if (!layer) return 0;
98
99 KisImageSP img = layer->image();
100 if (!img) return 0;
101
102 KisLayerItem *item;
103 if (m_parent) {
104 item = new KisLayerItem(m_parent, layer);
105 }
106 else {
107 item = new KisLayerItem(m_widget, layer);
108 }
109 if (layer == img->activeLayer()) {
110 item->setActive();
111 }
112 m_layersAdded.append(layer);
113 return item;
114 }
115};
116
117#endif
Class that contains a KisFilter and optionally a KisSelection.
A KisLayer that bundles child layers into a single layer.
virtual KisLayerSP firstChild() const
Returns the first child layer of this layer (if it supports that).
Abstract class that represents the concept of a Layer in Chalk.
Definition kis_layer.h:42
This layer is of a type that can be painted on.
An interface for the Part Layer so that we can use it in core/, but can implement it in ui/.
This visitor walks over the layer tree to fill the layer box.