krita

kis_populate_visitor.h

00001 /*
00002  *  Copyright (c) 2005 Gábor Lehel <illissius@gmail.com>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #ifndef KIS_POPULATE_VISITOR_H
00020 #define KIS_POPULATE_VISITOR_H
00021 
00022 #include <kiconloader.h>
00023 #include "kis_types.h"
00024 #include "kis_layer.h"
00025 #include "kis_group_layer.h"
00026 #include "kis_paint_layer.h"
00027 #include "kis_part_layer.h"
00028 #include "kis_adjustment_layer.h"
00029 #include "kis_layerlist.h"
00030 
00031 
00036 class KisPopulateVisitor: public KisLayerVisitor
00037 {
00038     public:
00039         KisPopulateVisitor(KisLayerList* widget)
00040             : m_widget(widget)
00041             , m_parent(0)
00042             { }
00043 
00044         KisPopulateVisitor(KisLayerItem* parent)
00045             : m_widget(parent->listView())
00046             , m_parent(parent)
00047             { }
00048 
00049         virtual bool visit(KisPaintLayer* layer)
00050         {
00051             if (!layer->temporary())
00052                 add(layer);
00053             return true;
00054         }
00055 
00056         virtual bool visit(KisPartLayer* layer)
00057         {
00058             add(layer)->setPixmap(0, SmallIcon("gear", 16));
00059             return true;
00060         }
00061 
00062         virtual bool visit(KisAdjustmentLayer* layer)
00063         {
00064             add(layer)->setPixmap(0, SmallIcon("tool_filter", 16));
00065             return true;
00066         }
00067 
00068         virtual bool visit(KisGroupLayer* layer)
00069         {
00070             KisLayerItem* item = add(layer);
00071             item->makeFolder();
00072             KisPopulateVisitor visitor(item);
00073             for (KisLayerSP l = layer->firstChild(); l; l = l->nextSibling())
00074                 l->accept(visitor);
00075 
00076             vKisLayerSP childLayersAdded = visitor.layersAdded();
00077 
00078             for (vKisLayerSP::iterator it = childLayersAdded.begin(); it != childLayersAdded.end(); ++it) {
00079                 m_layersAdded.append(*it);
00080             }
00081 
00082             return true;
00083         }
00084 
00085         vKisLayerSP layersAdded() const
00086         {
00087             return m_layersAdded;
00088         }
00089 
00090     private:
00091         LayerList* m_widget;
00092         KisLayerItem* m_parent;
00093         vKisLayerSP m_layersAdded;
00094 
00095         KisLayerItem* add(KisLayer* layer)
00096         {
00097             if (!layer) return 0;
00098 
00099             KisImageSP img = layer->image();
00100             if (!img) return 0;
00101                         
00102             KisLayerItem *item;
00103             if (m_parent) {
00104                 item = new KisLayerItem(m_parent, layer);
00105             }
00106             else {
00107                 item = new KisLayerItem(m_widget, layer); 
00108             }
00109             if (layer == img->activeLayer()) {
00110                 item->setActive();
00111             }
00112             m_layersAdded.append(layer);
00113             return item;
00114         }
00115 };
00116 
00117 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys