chalk

kis_layerlist.cpp
1/*
2 Copyright (c) 2005 Gábor Lehel <illissius@gmail.com>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library 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 GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include <tdeaboutdata.h>
21#include <tdeglobal.h>
22#include <kiconloader.h>
23#include <tdelocale.h>
24#include <tdepopupmenu.h>
25#include <KoPartSelectAction.h>
26#include <tqimage.h>
27
28#include "kis_layer.h"
29#include "kis_paint_layer.h"
30#include "kis_part_layer.h"
31#include "kis_adjustment_layer.h"
32#include "kis_filter.h"
33#include "kis_filter_configuration.h"
34#include "kis_filter_registry.h"
35#include "kis_layerlist.h"
36
37
38KisLayerList::KisLayerList( TQWidget *parent, const char *name )
39 : super( parent, name )
40{
41 m_partLayerAction = new KoPartSelectAction( i18n( "New &Object Layer" ), "gear", this );
42}
43
44static const int ADJUSTMENT_LAYER = 5384; //hack?
45
46void KisLayerList::constructMenu( LayerItem *layer )
47{
48 super::constructMenu( layer );
49
50 contextMenu()->removeItem( MenuItems::NewLayer );
51 contextMenu()->removeItem( MenuItems::NewFolder );
52 contextMenu()->changeItem( MenuItems::RemoveLayer, i18n( "&Remove Layer" ) );
53
54 if( layer )
55 {
56 static TDEPopupMenu submenu;
57 submenu.clear();
58 submenu.insertItem( SmallIconSet( "file" ), i18n( "&Layer..." ), MenuItems::NewLayer );
59 submenu.insertItem( SmallIconSet( "folder" ), i18n( "&Group Layer..." ), MenuItems::NewFolder );
60 submenu.insertItem( SmallIconSet( "tool_filter" ), i18n( "&Adjustment Layer..." ), ADJUSTMENT_LAYER );
61 m_partLayerAction->setText( i18n( "&Object Layer" ) );
62 m_partLayerAction->plug( &submenu );
63
64 contextMenu()->insertItem( SmallIconSet( "document-new" ), i18n( "&New" ), &submenu );
65 }
66 else
67 {
68 contextMenu()->insertItem( SmallIconSet( "document-new" ), i18n( "&New Layer..." ), MenuItems::NewLayer );
69 contextMenu()->insertItem( SmallIconSet( "folder" ), i18n( "New &Group Layer..." ), MenuItems::NewFolder );
70 contextMenu()->insertItem( SmallIconSet( "tool_filter" ), i18n( "New &Adjustment Layer..." ), ADJUSTMENT_LAYER );
71 m_partLayerAction->setText( i18n( "New &Object Layer" ) );
72 m_partLayerAction->plug( contextMenu() );
73 }
74}
75
76void KisLayerList::menuActivated( int id, LayerItem *layer )
77{
78 const TQValueList<LayerItem*> selected = selectedLayers();
79 LayerItem *parent = ( layer && layer->isFolder() ) ? layer : 0;
80 LayerItem *after = 0;
81 if( layer && !parent )
82 {
83 parent = layer->parent();
84 after = layer->prevSibling();
85 }
86 switch( id )
87 {
88 case MenuItems::NewLayer:
89 emit requestNewLayer( parent, after );
90 emit requestNewLayer( parent ? parent->id() : -1, after ? after->id() : -1 );
91 break;
92 case MenuItems::NewFolder:
93 emit requestNewFolder( parent, after );
94 emit requestNewFolder( parent ? parent->id() : -1, after ? after->id() : -1 );
95 break;
96 case ADJUSTMENT_LAYER:
97 emit requestNewAdjustmentLayer( parent, after );
98 emit requestNewAdjustmentLayer( parent ? parent->id() : -1, after ? after->id() : -1 );
99 break;
100 case MenuItems::RemoveLayer:
101 {
102 TQValueList<int> ids;
103 for( int i = 0, n = selected.count(); i < n; ++i )
104 {
105 ids.append( selected[i]->id() );
106 emit requestRemoveLayer( selected[i]->id() );
107 }
108 emit requestRemoveLayers( ids );
109 }
110 for( int i = 0, n = selected.count(); i < n; ++i )
111 emit requestRemoveLayer( selected[i] );
112 emit requestRemoveLayers( selected );
113 break;
114 case MenuItems::LayerProperties:
115 if( layer )
116 {
117 emit requestLayerProperties( layer );
118 emit requestLayerProperties( layer->id() );
119 }
120 break;
121 default:
122 if( id >= MenuItems::COUNT && layer )
123 super::menuActivated( id, layer );
124 else if( id != -1 ) //object layer was selected
125 {
126 emit requestNewObjectLayer( parent, after, m_partLayerAction->documentEntry() );
127 emit requestNewObjectLayer( parent ? parent->id() : -1, after ? after->id() : -1, m_partLayerAction->documentEntry() );
128 }
129 }
130}
131
132KisLayerItem::KisLayerItem( LayerList* parent, KisLayer* layer )
133 : super( layer->name(),
134 parent,
135 layer->prevSibling() ? parent->layer( layer->prevSibling()->id() ) : 0,
136 layer->id() )
137 , m_layer( layer )
138{
139 init();
140}
141
142KisLayerItem::KisLayerItem( LayerItem* parent, KisLayer* layer )
143 : super( layer->name(),
144 parent,
145 layer->prevSibling() ? parent->listView()->layer( layer->prevSibling()->id() ) : 0,
146 layer->id() )
147 , m_layer( layer )
148{
149 init();
150}
151
152void KisLayerItem::init()
153{
154 setPreviewImage( &m_preview );
155 sync();
156}
157
158KisLayer* KisLayerItem::layer() const
159{
160 return m_layer;
161}
162
163void KisLayerItem::sync()
164{
165 setProperty( "visible", layer()->visible() );
166 setProperty( "locked", layer()->locked() );
167 setDisplayName( layer()->name() );
168 update();
169}
170
171bool KisLayerItem::updatePreview()
172{
173 m_preview = m_layer->createThumbnail( height()*2, height()*2 );
174 m_preview.setAlphaBuffer( true );
175 previewChanged();
176 return !m_preview.isNull();
177}
178
179TQString KisLayerItem::tooltip() const
180{
181 TQString text = super::tooltip();
182 text = text.left( text.length() - 8 ); //HACK -- strip the </table>
183 TQString row = "<tr><td>%1</td><td>%2</td></tr>";
184 text += row.arg( i18n( "Opacity:" ) ).arg( "%1%" ).arg( int( float( m_layer->opacity() * 100 ) / 255 + 0.5 ) );
185 text += row.arg( i18n( "Composite mode:" ) ).arg( m_layer->compositeOp().id().name() );
186 if( KisPaintLayer *player = dynamic_cast<KisPaintLayer*>( m_layer ) )
187 {
188 text += row.arg( i18n( "Colorspace:" ) ).arg( player->paintDevice()->colorSpace()->id().name() );
189 if( KisProfile *profile = player->paintDevice()->colorSpace()->getProfile() )
190 text += row.arg( i18n( "Profile:" ) ).arg( profile->productName() );
191 }
192 if( KisAdjustmentLayer *alayer = dynamic_cast<KisAdjustmentLayer*>( m_layer ) )
193 text += row.arg( i18n( "Filter: " ) ).arg( KisFilterRegistry::instance()->get( alayer->filter()->name() )->id().name() );
194 if( KisPartLayerImpl *player = dynamic_cast<KisPartLayerImpl*>( m_layer ) ) {
195 TQString type = player->docType();
196
197 if( type.isEmpty() ) {
198 type = player->childDoc()->document()->instance()->aboutData()->programName();
199 }
200
201 text += row.arg( i18n( "Document type: " ) ).arg( type );
202 }
203 text += "</table>";
204
205 return text;
206}
207
208TQImage KisLayerItem::tooltipPreview() const
209{
210 TQImage img = m_layer->createThumbnail( 400, 400 );
211 if( img.isNull() )
212 return img; //so TQt doesn't complain
213 img.setAlphaBuffer( true );
214 const int size = kMin( 200, kMax( img.width(), img.height() ) );
215 return img.smoothScale( size, size, TQImage::ScaleMin );
216}
217
218//void KisLayerItem::paintCell( TQPainter *p, const TQColorGroup &cg, int column, int width, int align );
219
220#include "kis_layerlist.moc"
Class that contains a KisFilter and optionally a KisSelection.
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.
A PartLayer is a layer that contains a KOffice Part like a KWord document or a KSpread spreadsheet.