krita

kis_layerbox.cc

00001 /*
00002  *  kis_layerbox.cc - part of Krita aka Krayon aka KimageShop
00003  *
00004  *  Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
00005  *  Copyright (C) 2006 Gábor Lehel <illissius@gmail.com>
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  */
00021 
00022 #include <qbutton.h>
00023 #include <qtoolbutton.h>
00024 #include <qbrush.h>
00025 #include <qfont.h>
00026 #include <qfontmetrics.h>
00027 #include <qhbox.h>
00028 #include <qlayout.h>
00029 #include <qpainter.h>
00030 #include <qpoint.h>
00031 #include <qrect.h>
00032 #include <qstring.h>
00033 #include <qstyle.h>
00034 #include <qtooltip.h>
00035 #include <qwidget.h>
00036 #include <qcombobox.h>
00037 #include <qcheckbox.h>
00038 
00039 #include <kdebug.h>
00040 #include <kglobal.h>
00041 #include <kpopupmenu.h>
00042 #include <kmessagebox.h>
00043 #include <kpushbutton.h>
00044 #include <kiconloader.h>
00045 #include <kicontheme.h>
00046 #include <klocale.h>
00047 
00048 #include <KoPartSelectAction.h>
00049 
00050 #include "kis_layerlist.h"
00051 #include "kis_cmb_composite.h"
00052 #include "kis_int_spinbox.h"
00053 #include "wdglayerbox.h"
00054 #include "kis_colorspace.h"
00055 #include "kis_paint_device.h"
00056 #include "kis_layer.h"
00057 #include "kis_group_layer.h"
00058 #include "kis_image.h"
00059 
00060 #include "kis_populate_visitor.h"
00061 
00062 #include "kis_layerbox.h"
00063 
00064 KisLayerBox::KisLayerBox(KisCanvasSubject *subject, QWidget *parent, const char *name)
00065     : super(parent, name), m_image(0)
00066 {
00067     QVBoxLayout *vbox = new QVBoxLayout(this);
00068     vbox->setAutoAdd(true);
00069 
00070     m_lst = new WdgLayerBox(this);
00071     setMinimumSize(m_lst->minimumSizeHint());
00072 
00073     QToolTip::add(m_lst->bnAdd, i18n("Create new layer"));
00074 
00075     QToolTip::add(m_lst->bnDelete, i18n("Remove current layer"));
00076 
00077     QToolTip::add(m_lst->bnRaise, i18n("Raise current layer"));
00078     m_lst->bnRaise->setEnabled(false);
00079 
00080     m_lst->bnLower->setEnabled(false);
00081     QToolTip::add(m_lst->bnLower, i18n("Lower current layer"));
00082 
00083     QToolTip::add(m_lst->bnProperties, i18n("Properties for layer"));
00084 
00085     KIconLoader il( "krita" );
00086 
00087     list()->setPreviewsShown(true);
00088 
00089     list()->setFoldersCanBeActive(true);
00090 
00091     list()->addProperty("visible", i18n("Visible"), loadPixmap("visible.png", il, KIcon::SizeSmallMedium),
00092                                                       loadPixmap("novisible.png", il, KIcon::SizeSmallMedium), true);
00093 
00094     list()->addProperty("locked", i18n("Locked"), loadPixmap("locked.png", il, KIcon::SizeSmallMedium),
00095                                                     loadPixmap("unlocked.png", il, KIcon::SizeSmallMedium));
00096 
00097 
00098     connect(list()->contextMenu(), SIGNAL(aboutToShow()), SLOT(slotAboutToShow()));
00099     connect(list(), SIGNAL(activated(LayerItem*)),
00100                     SLOT(slotLayerActivated(LayerItem*)));
00101     connect(list(), SIGNAL(displayNameChanged(LayerItem*, const QString&)),
00102                     SLOT(slotLayerDisplayNameChanged(LayerItem*, const QString&)));
00103     connect(list(), SIGNAL(propertyChanged(LayerItem*, const QString&, bool)),
00104                     SLOT(slotLayerPropertyChanged(LayerItem*, const QString&, bool)));
00105     connect(list(), SIGNAL(layerMoved(LayerItem*, LayerItem*, LayerItem*)),
00106                     SLOT(slotLayerMoved(LayerItem*, LayerItem*, LayerItem*)));
00107     connect(list(), SIGNAL(requestNewLayer(LayerItem*, LayerItem*)),
00108                     SLOT(slotRequestNewLayer(LayerItem*, LayerItem*)));
00109     connect(list(), SIGNAL(requestNewFolder(LayerItem*, LayerItem*)),
00110                     SLOT(slotRequestNewFolder(LayerItem*, LayerItem*)));
00111     connect(list(), SIGNAL(requestNewAdjustmentLayer(LayerItem*, LayerItem*)),
00112                     SLOT(slotRequestNewAdjustmentLayer(LayerItem*, LayerItem*)));
00113     connect(list(), SIGNAL(requestNewObjectLayer(LayerItem*, LayerItem*, const KoDocumentEntry&)),
00114                     SLOT(slotRequestNewObjectLayer(LayerItem*, LayerItem*, const KoDocumentEntry&)));
00115     connect(list(), SIGNAL(requestRemoveLayer(LayerItem*)),
00116                     SLOT(slotRequestRemoveLayer(LayerItem*)));
00117     connect(list(), SIGNAL(requestLayerProperties(LayerItem*)),
00118                     SLOT(slotRequestLayerProperties(LayerItem*)));
00119 
00120     m_newLayerMenu = new KPopupMenu(this);
00121     m_lst->bnAdd->setPopup(m_newLayerMenu);
00122     m_lst->bnAdd->setPopupDelay(1);
00123     m_newLayerMenu->insertItem( SmallIconSet( "filenew" ), i18n( "&New Layer..." ), PAINT_LAYER );
00124     m_newLayerMenu->insertItem( SmallIconSet( "folder" ), i18n( "New &Group Layer..." ), GROUP_LAYER );
00125     m_newLayerMenu->insertItem( SmallIconSet( "tool_filter" ), i18n( "New &Adjustment Layer..." ), ADJUSTMENT_LAYER );
00126     m_partLayerAction = new KoPartSelectAction( i18n( "New &Object Layer" ), "gear", this );
00127     m_partLayerAction->plug( m_newLayerMenu );
00128     connect(m_partLayerAction, SIGNAL(activated()), this, SLOT(slotAddMenuActivated()));
00129     connect(m_newLayerMenu, SIGNAL(activated(int)), this, SLOT(slotAddMenuActivated(int)));
00130 
00131 
00132     connect(m_lst->bnDelete, SIGNAL(clicked()), SLOT(slotRmClicked()));
00133     connect(m_lst->bnRaise, SIGNAL(clicked()), SLOT(slotRaiseClicked()));
00134     connect(m_lst->bnLower, SIGNAL(clicked()), SLOT(slotLowerClicked()));
00135     connect(m_lst->bnProperties, SIGNAL(clicked()), SLOT(slotPropertiesClicked()));
00136     connect(m_lst->intOpacity, SIGNAL(valueChanged(int, bool)), SIGNAL(sigOpacityChanged(int, bool)));
00137     connect(m_lst->intOpacity, SIGNAL(finishedChanging(int, int)), SIGNAL(sigOpacityFinishedChanging(int, int)));
00138     connect(m_lst->cmbComposite, SIGNAL(activated(const KisCompositeOp&)), SIGNAL(sigItemComposite(const KisCompositeOp&)));
00139 
00140     Q_ASSERT(subject->document() != 0);
00141 
00142     if (subject->document()) {
00143         connect(subject->document(), SIGNAL(sigCommandExecuted()), SLOT(updateThumbnails()));
00144     }
00145 }
00146 
00147 KisLayerBox::~KisLayerBox()
00148 {
00149 }
00150 
00151 KisLayerList* KisLayerBox::list() const
00152 {
00153     return m_lst->listLayers;
00154 }
00155 
00156 void KisLayerBox::setImage(KisImageSP img)
00157 {
00158     if (m_image == img)
00159         return;
00160 
00161     if (m_image)
00162         m_image->disconnect(this);
00163 
00164     m_image = img;
00165 
00166     if (img)
00167     {
00168         connect(img, SIGNAL(sigLayerActivated(KisLayerSP)), this, SLOT(slotLayerActivated(KisLayerSP)));
00169         connect(img, SIGNAL(sigLayerAdded(KisLayerSP)), this, SLOT(slotLayerAdded(KisLayerSP)));
00170         connect(img, SIGNAL(sigLayerRemoved(KisLayerSP, KisGroupLayerSP, KisLayerSP)),
00171                 this, SLOT(slotLayerRemoved(KisLayerSP, KisGroupLayerSP, KisLayerSP)));
00172         connect(img, SIGNAL(sigLayerPropertiesChanged(KisLayerSP)),
00173                 this, SLOT(slotLayerPropertiesChanged(KisLayerSP)));
00174         connect(img, SIGNAL(sigLayerMoved(KisLayerSP, KisGroupLayerSP, KisLayerSP)),
00175                 this, SLOT(slotLayerMoved(KisLayerSP, KisGroupLayerSP, KisLayerSP)));
00176         connect(img, SIGNAL(sigLayersChanged(KisGroupLayerSP)), this, SLOT(slotLayersChanged(KisGroupLayerSP)));
00177         connect(img, SIGNAL(sigLayerUpdated(KisLayerSP, QRect)), this, SLOT(slotLayerUpdated(KisLayerSP, QRect)));
00178         slotLayersChanged(img->rootLayer());
00179         updateThumbnails();
00180     }
00181     else
00182     {
00183         clear();
00184     }
00185 }
00186 
00187 void KisLayerBox::slotLayerActivated(KisLayerSP layer)
00188 {
00189     if (layer)
00190         list()->setActiveLayer(layer->id());
00191     else
00192         list()->setActiveLayer(-1);
00193     updateUI();
00194 }
00195 
00196 void KisLayerBox::slotLayerAdded(KisLayerSP layer)
00197 {
00198     if (layer.data() == m_image->rootLayer().data() || list()->layer(layer->id()))
00199         return;
00200 
00201     vKisLayerSP layersAdded;
00202 
00203     if (layer->parent() == m_image->rootLayer())
00204     {
00205         KisPopulateVisitor visitor(list());
00206         layer->accept(visitor);
00207         layersAdded = visitor.layersAdded();
00208     }
00209     else
00210     {
00211         KisPopulateVisitor visitor(static_cast<KisLayerItem*>(list()->layer(layer->parent()->id())));
00212         layer->accept(visitor);
00213         layersAdded = visitor.layersAdded();
00214     }
00215 
00216     for (vKisLayerSP::iterator it = layersAdded.begin(); it != layersAdded.end(); ++it) {
00217         markModified(*it);
00218     }
00219     updateUI();
00220 }
00221 
00222 void KisLayerBox::slotLayerRemoved(KisLayerSP layer, KisGroupLayerSP wasParent, KisLayerSP)
00223 {
00224     list()->removeLayer(layer->id());
00225     m_modified.remove(layer->id());
00226     markModified(wasParent);
00227     updateUI();
00228 }
00229 
00230 void KisLayerBox::slotLayerMoved(KisLayerSP layer, KisGroupLayerSP wasParent, KisLayerSP)
00231 {
00232     int parentID = layer->parent()->id();
00233     if (layer->parent() == m_image->rootLayer())
00234         parentID = -1;
00235 
00236     int siblingID = -1;
00237     if (layer->prevSibling())
00238         siblingID = layer->prevSibling()->id();
00239 
00240     list()->moveLayer(layer->id(), parentID, siblingID);
00241 
00242     markModified(layer->parent());
00243     markModified(wasParent);
00244     updateUI();
00245 }
00246 
00247 void KisLayerBox::slotLayerPropertiesChanged(KisLayerSP layer)
00248 {
00249     if (KisLayerItem* item = dynamic_cast<KisLayerItem*>(list()->layer(layer->id())))
00250     {
00251         Q_ASSERT(item->layer() == layer.data());
00252         item->sync();
00253         updateUI();
00254         markModified(layer);
00255     }
00256 }
00257 
00258 void KisLayerBox::slotLayersChanged(KisGroupLayerSP rootLayer)
00259 {
00260     list()->clear();
00261     KisPopulateVisitor visitor(list());
00262     for (KisLayerSP layer = rootLayer->firstChild(); layer; layer = layer->nextSibling())
00263         layer->accept(visitor);
00264     m_modified.clear();
00265     for (QListViewItemIterator it(list()->lastItem()); *it; --it)
00266         m_modified.append(static_cast<LayerItem*>(*it)->id());
00267     updateUI();
00268 }
00269 
00270 void KisLayerBox::slotLayerUpdated(KisLayerSP layer, QRect)
00271 {
00272     markModified(layer);
00273 }
00274 
00275 void KisLayerBox::slotLayerActivated(LayerItem* item)
00276 {
00277     if (item)
00278         m_image->activate(m_image->findLayer(item->id()));
00279     else
00280         m_image->activate(0);
00281     updateUI();
00282 }
00283 
00284 void KisLayerBox::slotLayerDisplayNameChanged(LayerItem* item, const QString& displayName)
00285 {
00286     if(KisLayerSP layer = m_image->findLayer(item->id()))
00287         layer->setName(displayName);
00288     updateUI();
00289 }
00290 
00291 void KisLayerBox::slotLayerPropertyChanged(LayerItem* item, const QString& name, bool on)
00292 {
00293     if (KisLayerSP layer = m_image->findLayer(item->id()))
00294     {
00295         if (name == "visible")
00296             layer->setVisible(on);
00297         else if (name == "locked")
00298             layer->setLocked(on);
00299     }
00300 }
00301 
00302 void KisLayerBox::slotLayerMoved(LayerItem* item, LayerItem*, LayerItem*)
00303 {
00304     KisLayerSP layer = m_image->findLayer(item->id());
00305     KisGroupLayerSP parent;
00306     if( item->parent() )
00307         parent = dynamic_cast<KisGroupLayer*>(m_image->findLayer(item->parent()->id()).data());
00308     if( !parent )
00309         parent = m_image->rootLayer();
00310     KisLayerSP above = 0;
00311     if (item->nextSibling())
00312         above = m_image->findLayer(item->nextSibling()->id());
00313     if (layer)
00314         m_image->moveLayer(layer, parent.data(), above);
00315     updateUI();
00316 }
00317 
00318 void KisLayerBox::slotRequestNewLayer(LayerItem* p, LayerItem* after)
00319 {
00320     KisLayer* l = m_image->rootLayer().data();
00321     if (p)
00322         l = m_image->findLayer(p->id()).data();
00323     KisGroupLayerSP parent = dynamic_cast<KisGroupLayer*>(l);
00324 
00325     KisLayerSP above = 0;
00326     if (after && after->nextSibling())
00327         above = m_image->findLayer(after->nextSibling()->id());
00328     else if (after)
00329         above = 0;
00330     else if (p && p->firstChild())
00331         above = parent->firstChild();
00332     else if (!p && m_image->rootLayer()->childCount())
00333         above = m_image->rootLayer()->firstChild();
00334     emit sigRequestLayer(parent, above);
00335 }
00336 
00337 void KisLayerBox::slotRequestNewFolder(LayerItem* p, LayerItem* after)
00338 {
00339     KisLayer* l = m_image->rootLayer().data(); //FIXME I hate copy-pasting like this.
00340     if (p)
00341         l = m_image->findLayer(p->id()).data();
00342     KisGroupLayerSP parent = dynamic_cast<KisGroupLayer*>(l);
00343 
00344     KisLayerSP above = 0;
00345     if (after && after->nextSibling())
00346         above = m_image->findLayer(after->nextSibling()->id());
00347     else if (after)
00348         above = 0;
00349     else if (p && p->firstChild())
00350         above = parent->firstChild();
00351     else if (!p && m_image->rootLayer()->childCount())
00352         above = m_image->rootLayer()->firstChild();
00353     emit sigRequestGroupLayer(parent, above);
00354 }
00355 
00356 void KisLayerBox::slotRequestNewAdjustmentLayer(LayerItem* p, LayerItem* after)
00357 {
00358     KisLayer* l = m_image->rootLayer().data(); //FIXME here too.
00359     if (p)
00360         l = m_image->findLayer(p->id()).data();
00361     KisGroupLayerSP parent = dynamic_cast<KisGroupLayer*>(l);
00362 
00363     KisLayerSP above = 0;
00364     if (after && after->nextSibling())
00365         above = m_image->findLayer(after->nextSibling()->id());
00366     else if (after)
00367         above = 0;
00368     else if (p && p->firstChild())
00369         above = parent->firstChild();
00370     else if (!p && m_image->rootLayer()->childCount())
00371         above = m_image->rootLayer()->firstChild();
00372     emit sigRequestAdjustmentLayer(parent, above);
00373 }
00374 
00375 void KisLayerBox::slotRequestNewObjectLayer(LayerItem* p, LayerItem* after, const KoDocumentEntry& entry)
00376 {
00377     KisLayer* l = m_image->rootLayer().data(); //FIXME and here.
00378     if (p)
00379         l = m_image->findLayer(p->id()).data();
00380     KisGroupLayerSP parent = dynamic_cast<KisGroupLayer*>(l);
00381 
00382     KisLayerSP above = 0;
00383     if (after && after->nextSibling())
00384         above = m_image->findLayer(after->nextSibling()->id());
00385     else if (after)
00386         above = 0;
00387     else if (p && p->firstChild())
00388         above = parent->firstChild();
00389     else if (!p && m_image->rootLayer()->childCount())
00390         above = m_image->rootLayer()->firstChild();
00391     emit sigRequestPartLayer(parent, above, entry);
00392 }
00393 
00394 void KisLayerBox::slotRequestRemoveLayer(LayerItem* item)
00395 {
00396     if (KisLayerSP layer = m_image->findLayer(item->id())) {
00397         m_image->removeLayer(layer);
00398     }
00399     updateUI();
00400 }
00401 
00402 void KisLayerBox::slotRequestLayerProperties(LayerItem* item)
00403 {
00404     if (KisLayerSP layer = m_image->findLayer(item->id()))
00405     {
00406         emit sigRequestLayerProperties(layer);
00407     }
00408 }
00409 
00410 void KisLayerBox::updateUI()
00411 {
00412     m_lst->bnDelete->setEnabled(list()->activeLayer());
00413     m_lst->bnRaise->setEnabled(list()->activeLayer() && (list()->activeLayer()->prevSibling() || list()->activeLayer()->parent()));
00414     m_lst->bnLower->setEnabled(list()->activeLayer() && list()->activeLayer()->nextSibling());
00415     m_lst->intOpacity->setEnabled(list()->activeLayer());
00416     m_lst->cmbComposite->setEnabled(list()->activeLayer());
00417     if (m_image)
00418         if (KisLayerSP active = m_image->activeLayer())
00419         {
00420             if (m_image->activeDevice())
00421                 slotSetColorSpace(m_image->activeDevice()->colorSpace());
00422             else
00423                 slotSetColorSpace(m_image->colorSpace());
00424             slotSetOpacity(int(float(active->opacity() * 100) / 255 + 0.5));
00425             slotSetCompositeOp(active->compositeOp());
00426         }
00427 }
00428 
00429 void KisLayerBox::slotAboutToShow()
00430 {
00431 }
00432 
00433 void KisLayerBox::slotSetCompositeOp(const KisCompositeOp& compositeOp)
00434 {
00435     m_lst->cmbComposite->blockSignals(true);
00436     m_lst->cmbComposite->setCurrentItem(compositeOp);
00437     m_lst->cmbComposite->blockSignals(false);
00438 }
00439 
00440 void KisLayerBox::slotSetColorSpace(const KisColorSpace * colorSpace)
00441 {
00442     m_lst->cmbComposite->blockSignals(true);
00443     m_lst->cmbComposite->setCompositeOpList(colorSpace->userVisiblecompositeOps());
00444     m_lst->cmbComposite->blockSignals(false);
00445 }
00446 
00447 // range: 0-100
00448 void KisLayerBox::slotSetOpacity(int opacity)
00449 {
00450     m_lst->intOpacity->blockSignals(true);
00451     m_lst->intOpacity->setValue(opacity);
00452     m_lst->intOpacity->blockSignals(false);
00453 }
00454 
00455 void KisLayerBox::clear()
00456 {
00457     list()->clear();
00458     updateUI();
00459 }
00460 
00461 void KisLayerBox::slotAddMenuActivated(int type)
00462 {
00463     if(type == -1)
00464         return;
00465 
00466     KisGroupLayerSP root = m_image->rootLayer();
00467     KisGroupLayerSP parent;
00468     KisLayerSP above;
00469     if (KisLayerSP active = m_image->activeLayer())
00470     {
00471         parent = root;
00472         above = active;
00473         if (active->parent())
00474             parent = active->parent();
00475     }
00476     else
00477     {
00478         parent = root;
00479         above = m_image->rootLayer()->firstChild();
00480     }
00481 
00482     switch (type)
00483     {
00484         case PAINT_LAYER:
00485             emit sigRequestLayer(parent, above);
00486             break;
00487         case GROUP_LAYER:
00488             emit sigRequestGroupLayer(parent, above);
00489             break;
00490         case ADJUSTMENT_LAYER:
00491             emit sigRequestAdjustmentLayer(parent, above);
00492             break;
00493         case OBJECT_LAYER:
00494         default: //goddamned Qt doesn't emit activated for default-assigned IDs, so this does nothing
00495             emit sigRequestPartLayer(parent, above, m_partLayerAction->documentEntry());
00496     }
00497 }
00498 
00499 void KisLayerBox::slotRmClicked()
00500 {
00501     QValueList<int> l = list()->selectedLayerIDs();
00502     if (l.count() < 2 && list()->activeLayer() && !l.contains(list()->activeLayer()->id()))
00503     {
00504         l.clear();
00505         l.append(list()->activeLayer()->id());
00506     }
00507 
00508     for (int i = 0, n = l.count(); i < n; ++i)
00509     {
00510         m_modified.remove(l[i]);
00511         m_image->removeLayer(m_image->findLayer(l[i]));
00512     }
00513 }
00514 
00515 void KisLayerBox::slotRaiseClicked()
00516 {
00517     QValueList<int> l = list()->selectedLayerIDs();
00518     if (l.count() < 2 && list()->activeLayer() && !l.contains(list()->activeLayer()->id()))
00519     {
00520         l.clear();
00521         l.append(list()->activeLayer()->id());
00522     }
00523 
00524     KisLayerSP layer = m_image->findLayer(l.first());
00525     if( l.count() == 1 && layer == layer->parent()->firstChild() && layer->parent() != m_image->rootLayer())
00526     {
00527         if (KisGroupLayerSP grandparent = layer->parent()->parent())
00528             m_image->moveLayer(layer, grandparent, layer->parent().data());
00529     }
00530     else
00531     {
00532         for (int i = 0, n = l.count(); i < n; ++i)
00533             if (KisLayerSP li = m_image->findLayer(l[i]))
00534                 if (li->prevSibling())
00535                     m_image->moveLayer(li, li->parent(), li->prevSibling());
00536     }
00537 
00538     if( !l.isEmpty() )
00539         list()->ensureItemVisible( list()->layer( l.first() ) );
00540 }
00541 
00542 void KisLayerBox::slotLowerClicked()
00543 {
00544     QValueList<LayerItem*> l = list()->selectedLayers();
00545     if (l.count() < 2 && list()->activeLayer() && !l.contains(list()->activeLayer()))
00546     {
00547         l.clear();
00548         l.append(list()->activeLayer());
00549     }
00550 
00551     for (int i = l.count() - 1; i >= 0; --i)
00552         if (LayerItem *layer = l[i])
00553             if (layer->nextSibling())
00554                 list()->moveLayer(layer, layer->parent(), layer->nextSibling());
00555 
00556     if( !l.isEmpty() )
00557         list()->ensureItemVisible( l.last() );
00558 }
00559 
00560 void KisLayerBox::slotPropertiesClicked()
00561 {
00562     if (KisLayerSP active = m_image->activeLayer())
00563         emit sigRequestLayerProperties(active);
00564 }
00565 
00566 void KisLayerBox::updateThumbnails()
00567 {
00568     bool again = true;
00569     while (m_modified.count() && again)
00570     {
00571         //again = false;
00572         KisLayerItem* item = static_cast<KisLayerItem*>(list()->layer(m_modified.last()));
00573         m_modified.pop_back();
00574         if (!item || !item->updatePreview())
00575             again = true;
00576     }
00577 }
00578 
00579 void KisLayerBox::setUpdatesAndSignalsEnabled(bool enable)
00580 {
00581     setUpdatesEnabled(enable);
00582     m_lst->intOpacity->setUpdatesEnabled(enable);
00583     m_lst->cmbComposite->setUpdatesEnabled(enable);
00584 
00585     list()->blockSignals(!enable);
00586     m_lst->intOpacity->blockSignals(!enable);
00587     m_lst->cmbComposite->blockSignals(!enable);
00588 }
00589 
00590 
00591 QPixmap KisLayerBox::loadPixmap(const QString& filename, const KIconLoader&
00592                                     il, int size)
00593 {
00594     QPixmap pixmap = il.loadIcon(filename, KIcon::NoGroup, size);
00595 
00596     if (pixmap.isNull())
00597         KMessageBox::error(0, i18n("Cannot find %1").arg(filename),
00598                            i18n("Canvas"));
00599 
00600     return pixmap;
00601 }
00602 
00603 void KisLayerBox::markModified(KisLayer* layer)
00604 {
00605     if( !layer )
00606         return;
00607 
00608     QValueList<int> v;
00609     while (layer && layer != m_image->rootLayer().data())
00610     {
00611         v.append(layer->id());
00612         layer = layer->parent();
00613     }
00614     for (int i = v.count() - 1; i >= 0; --i)
00615         if (!m_modified.contains(v[i]))
00616             m_modified.append(v[i]);
00617 }
00618 
00619 void KisLayerBox::printKritaLayers() const
00620 {
00621     static int indent = 0;
00622     static KisLayer *root = 0;
00623     if( !root )
00624         root = m_image->rootLayer();
00625     if( !root )
00626         return;
00627     QString s = root->name();
00628     if( dynamic_cast<KisGroupLayer*>( root ) )
00629         s = QString("[%1]").arg( s );
00630     if( m_image->activeLayer().data() == root )
00631         s.prepend("*");
00632     kdDebug() << (QString().fill(' ', indent) +  s) << endl;
00633     for (KisLayer* layer = root->firstChild(); layer; layer = layer->nextSibling())
00634     {
00635         indent += 2;
00636         root = layer;
00637         printKritaLayers();
00638         indent -= 2;
00639         root = layer->parent();
00640     }
00641 }
00642 
00643 void KisLayerBox::printLayerboxLayers() const
00644 {
00645     static int indent = 0;
00646     static LayerItem *root = 0;
00647     if( !root )
00648     {
00649         for (LayerItem* layer = list()->firstChild(); layer; layer = layer->nextSibling())
00650         {
00651             indent += 2;
00652             root = layer;
00653             printLayerboxLayers();
00654             indent -= 2;
00655             root = layer->parent();
00656         }
00657         return;
00658     }
00659     QString s = root->displayName();
00660     if( root->isFolder() )
00661         s = QString("[%1]").arg( s );
00662     if( list()->activeLayer() == root )
00663         s.prepend("*");
00664     kdDebug() << (QString().fill(' ', indent) +  s) << endl;
00665     for (LayerItem* layer = root->firstChild(); layer; layer = layer->nextSibling())
00666     {
00667         indent += 2;
00668         root = layer;
00669         printLayerboxLayers();
00670         indent -= 2;
00671         root = layer->parent();
00672     }
00673 }
00674 
00675 #include "kis_layerbox.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys