karbon

vdocumentdocker.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001, 2002, 2003 The Karbon Developers
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 <tqhbuttongroup.h>
21#include <tqinputdialog.h>
22#include <tqlayout.h>
23#include <tqcheckbox.h>
24#include <tqlistview.h>
25#include <tqptrvector.h>
26#include <tqtoolbutton.h>
27#include <tqpainter.h>
28#include <tqtabwidget.h>
29#include <tqlabel.h>
30#include <tqcursor.h>
31
32#include <tdelocale.h>
33#include <tdeglobal.h>
34#include <KoMainWindow.h>
35#include <kdebug.h>
36#include <kiconloader.h>
37#include <klineeditdlg.h>
38#include <kinputdialog.h>
39
40#include "karbon_part.h"
41#include "karbon_view.h"
42#include "karbon_factory.h"
43#include "karbon_resourceserver.h"
44#include "vdocument.h"
45#include "vkopainter.h"
46#include "vlayer.h"
47#include "vlayercmd.h"
48#include "vdeletecmd.h"
49#include "vzordercmd.h"
50#include "vgroupcmd.h"
51#include "vungroupcmd.h"
52#include "vselection.h"
53#include "vstroke.h"
54#include "vcanvas.h"
55#include "vdocumentdocker.h"
56#include <visitors/vselectiondesc.h>
57
58static long g_lastKey = 0;
59
60/*************************************************************************
61 * Document tab *
62 *************************************************************************/
63
64VDocumentPreview::VDocumentPreview( KarbonView* view, TQWidget* parent )
65 : TQWidget( parent, "DocumentPreview" ), m_document( &view->part()->document() ), m_view( view )
66{
67 update();
68 installEventFilter( this );
69 setBackgroundMode( TQt::NoBackground );
70 setMouseTracking( true );
71 m_dragging = false;
72 m_docpixmap = 0L;
73} // VDocumentPreview::VDocumentPreview
74
75VDocumentPreview::~VDocumentPreview()
76{
77 delete m_docpixmap;
78} // VDocumentPreview::~VDocumentPreview
79
80void
81VDocumentPreview::reset()
82{
83 delete m_docpixmap;
84 m_docpixmap = 0L;
85}
86
87bool
88VDocumentPreview::eventFilter( TQObject* object, TQEvent* event )
89{
90 double scaleFactor;
91 double xoffset = 0.;
92 double yoffset = 0.;
93 if ( ( height() - 4 ) / m_document->height() > ( width() - 4 ) / m_document->width() )
94 {
95 scaleFactor = ( width() - 4 ) / m_document->width();
96 yoffset = ( ( height() - 4 ) / scaleFactor - m_document->height() ) / 2;
97 }
98 else
99 {
100 scaleFactor = ( height() - 4 ) / m_document->height();
101 xoffset = ( ( width() - 4 ) / scaleFactor - m_document->width() ) / 2;
102 }
103 KoRect rect = m_view->canvasWidget()->boundingBox();
104
105 TQMouseEvent* mouseEvent = static_cast<TQMouseEvent*>( event );
106 if( event->type() == TQEvent::MouseButtonPress )
107 {
108 m_firstPoint.setX( mouseEvent->pos().x() );
109 m_firstPoint.setY( mouseEvent->pos().y() );
110 m_lastPoint = m_firstPoint;
111 KoPoint p3( m_firstPoint.x() / scaleFactor - xoffset,
112 ( height() - m_firstPoint.y() ) / scaleFactor - yoffset );
113 m_dragging = rect.contains( p3 );
114 }
115 else if( event->type() == TQEvent::MouseButtonRelease )
116 {
117 if( m_dragging )
118 {
119 m_lastPoint.setX( mouseEvent->pos().x() );
120 m_lastPoint.setY( mouseEvent->pos().y() );
121 double dx = m_lastPoint.x() - m_firstPoint.x();
122 double dy = m_lastPoint.y() - m_firstPoint.y();
123 scaleFactor /= m_view->zoom();
124 m_view->canvasWidget()->scrollBy( int( dx / scaleFactor ), int( dy / scaleFactor ) );
125 m_firstPoint = m_lastPoint;
126 m_dragging = false;
127 update();
128 }
129 }
130 else if( event->type() == TQEvent::MouseMove )
131 {
132 if( m_dragging )
133 {
134 m_lastPoint.setX( mouseEvent->pos().x() );
135 m_lastPoint.setY( mouseEvent->pos().y() );
136 update();
137 /*double dx = m_lastPoint.x() - m_firstPoint.x();
138 double dy = m_lastPoint.y() - m_firstPoint.y();
139 scaleFactor /= m_view->zoom();
140 m_view->canvasWidget()->scrollBy( int( dx / scaleFactor ), int( dy / scaleFactor ) );
141 m_firstPoint = m_lastPoint;*/
142 }
143 else
144 {
145 KoPoint p3( mouseEvent->pos().x() / scaleFactor - xoffset,
146 ( height() - mouseEvent->pos().y() ) / scaleFactor - yoffset );
147 setCursor( rect.contains( p3 ) ? TQCursor::SizeAllCursor : TQCursor( TQt::arrowCursor ) );
148 }
149 }
150
151 return TQWidget::eventFilter( object, event );
152}
153
154void
155VDocumentPreview::paintEvent( TQPaintEvent* )
156{
157 // TODO : use NotROP, otherwise too slow
158 TQPixmap pixmap( width(), height() );
159 double xoffset = 0.;
160 double yoffset = 0.;
161 double scaleFactor;
162 if ( ( height() - 4 ) / m_document->height() > ( width() - 4 ) / m_document->width() )
163 {
164 scaleFactor = ( width() - 4 ) / m_document->width();
165 yoffset = ( ( height() - 4 ) / scaleFactor - m_document->height() ) / 2;
166 }
167 else
168 {
169 scaleFactor = ( height() - 4 ) / m_document->height();
170 xoffset = ( ( width() - 4 ) / scaleFactor - m_document->width() ) / 2;
171 }
172 xoffset += 2 / scaleFactor;
173 yoffset += 2 / scaleFactor;
174 if( !m_docpixmap || m_docpixmap->width() != width() || m_docpixmap->height() != height() )
175 {
176 delete m_docpixmap;
177 m_docpixmap = new TQPixmap( width(), height() );
178 VKoPainter p( m_docpixmap, width(), height() );
179 p.clear( TQColor( 195, 194, 193 ) );
180 p.setWorldMatrix( TQWMatrix( 1, 0, 0, -1, xoffset * scaleFactor, height() - yoffset * scaleFactor ) );
181 p.setZoomFactor( scaleFactor );
182 KoRect rect( -xoffset, -yoffset, m_document->width() + xoffset, m_document->height() + yoffset );
183 // draw doc outline
184 VColor c( TQt::black );
185 VStroke stroke( c, 0L, 1.0 / scaleFactor );
186 p.setPen( stroke );
187 p.setBrush( TQt::white );
188 p.drawRect( KoRect( 2, 2, m_document->width() - 2, m_document->height() - 2 ) );
189 m_document->draw( &p, &rect );
190 p.end();
191 }
192 bitBlt( &pixmap, 0, 0, m_docpixmap, 0, 0, width(), height() );
193
194 // draw viewport rect
195 {
196 TQPainter p( &pixmap );
197 p.setWorldMatrix( TQWMatrix( scaleFactor, 0, 0, -scaleFactor, xoffset * scaleFactor, height() - yoffset * scaleFactor ) );
198 p.setPen( TQt::red );
199 double dx = ( m_lastPoint.x() - m_firstPoint.x() ) * m_view->zoom();
200 double dy = ( m_lastPoint.y() - m_firstPoint.y() ) * m_view->zoom();
201 KoPoint p1( dx / scaleFactor, dy / scaleFactor );
202 p1 = m_view->canvasWidget()->toContents( p1 );
203 KoPoint p2( dx / scaleFactor + m_view->canvasWidget()->width(), dy / scaleFactor + m_view->canvasWidget()->height() );
204 p2 = m_view->canvasWidget()->toContents( p2 );
205 p.drawRect( int( p1.x() ), int( p1.y() ), int( p2.x() - p1.x() ), int( p2.y() - p1.y() ) );
206 }
207
208 TQPainter pw( &pixmap );
209 pw.setPen( colorGroup().light() );
210 pw.drawLine( 1, 1, 1, height() - 2 );
211 pw.drawLine( 1, 1, width() - 2, 1 );
212 pw.drawLine( width() - 1, height() - 1, 0, height() - 1 );
213 pw.drawLine( width() - 1, height() - 1, width() - 1, 0 );
214 pw.setPen( colorGroup().dark() );
215 pw.drawLine( 0, 0, width() - 1, 0 );
216 pw.drawLine( 0, 0, 0, height() - 1 );
217 pw.drawLine( width() - 2, height() - 2, width() - 2, 1 );
218 pw.drawLine( width() - 2, height() - 2, 1, height() - 2 );
219 pw.end();
220 bitBlt( this, 0, 0, &pixmap, 0, 0, width(), height() );
221} // VDocumentPreview::paintEvent
222
223VDocumentTab::VDocumentTab( KarbonView* view, TQWidget* parent )
224 : TQWidget( parent, "DocumentTab" ), m_view( view )
225{
226 TQFrame* frame;
227 TQGridLayout* layout = new TQGridLayout( this );
228 layout->setMargin( 3 );
229 layout->setSpacing( 2 );
230 layout->addMultiCellWidget( m_documentPreview = new VDocumentPreview( m_view, this ), 0, 7, 2, 2 );
231 layout->addWidget( new TQLabel( i18n( "document width", "Width:" ), this ), 0, 0 );
232 layout->addWidget( new TQLabel( i18n( "Height:" ), this ), 1, 0 );
233 layout->addMultiCellWidget( frame = new TQFrame( this ), 2, 2, 0, 1 );
234 frame->setFrameShape( TQFrame::HLine );
235 layout->addWidget( new TQLabel( i18n( "Layers:" ), this ), 3, 0 );
236 layout->addWidget( new TQLabel( i18n( "Format:" ), this ), 4, 0 );
237 layout->addMultiCellWidget( frame = new TQFrame( this ), 5, 5, 0, 1 );
238 frame->setFrameShape( TQFrame::HLine );
239 //layout->addMultiCellWidget( new TQLabel( i18n( "Zoom factor:" ), this ), 6, 6, 0, 1 );
240 layout->addWidget( m_width = new TQLabel( this ), 0, 1 );
241 layout->addWidget( m_height = new TQLabel( this ), 1, 1 );
242 layout->addWidget( m_layers = new TQLabel( this ), 3, 1 );
243 layout->addWidget( m_format = new TQLabel( this ), 4, 1 );
244 layout->setRowStretch( 7, 1 );
245 layout->setColStretch( 0, 0 );
246 layout->setColStretch( 1, 0 );
247 layout->setColStretch( 2, 2 );
248 //layout->addWidget(
249
250 m_width->setAlignment( AlignRight );
251 m_height->setAlignment( AlignRight );
252 m_layers->setAlignment( AlignRight );
253 m_format->setAlignment( AlignRight );
254
255 connect( view->part()->commandHistory(), TQ_SIGNAL( commandAdded( VCommand* ) ), this, TQ_SLOT( slotCommandAdded( VCommand* ) ) );
256 connect( view->part()->commandHistory(), TQ_SIGNAL( commandExecuted() ), this, TQ_SLOT( slotCommandExecuted() ) );
257 connect( view, TQ_SIGNAL( pageLayoutChanged() ), this, TQ_SLOT( slotCommandExecuted() ) );
258 connect( view->canvasWidget(), TQ_SIGNAL( viewportChanged() ), this, TQ_SLOT( slotViewportChanged() ) );
259
260 updateDocumentInfo();
261} // VDocumentTab::VDocumentTab
262
263VDocumentTab::~VDocumentTab()
264{
265} // VDocumentTab::~VDocumentTab
266
267void
268VDocumentTab::updateDocumentInfo()
269{
270 m_width->setText( KoUnit::toUserStringValue( m_view->part()->document().width(), m_view->part()->unit() ) + m_view->part()->unitName() );
271 m_height->setText( KoUnit::toUserStringValue( m_view->part()->document().height(), m_view->part()->unit() ) + m_view->part()->unitName() );
272 m_layers->setText( TQString::number( m_view->part()->document().layers().count() ) );
273} // VDocumentTab::updateDocumentInfo
274
275void
276VDocumentTab::slotCommandAdded( VCommand * )
277{
278 m_documentPreview->reset();
279 m_documentPreview->update();
280}
281
282void
283VDocumentTab::slotZoomChanged( double )
284{
285 m_documentPreview->update();
286}
287
288void
289VDocumentTab::slotViewportChanged()
290{
291 m_documentPreview->update();
292 updateDocumentInfo();
293}
294
295void
296VDocumentTab::slotCommandExecuted()
297{
298 m_documentPreview->reset();
299 m_documentPreview->update();
300}
301
302/*************************************************************************
303 * Layers tab *
304 *************************************************************************/
305
306VObjectListViewItem::VObjectListViewItem( TQListViewItem* parent, VObject* object, VDocument *doc, uint key, TQPtrDict<VObjectListViewItem> *map )
307 : TQListViewItem( parent, 0L ), m_object( object ), m_document( doc ), m_key( key ), m_map( map )
308{
309 update();
310 // add itself to object list item map
311 m_map->insert( object, this );
312}
313
314VObjectListViewItem::~VObjectListViewItem()
315{
316 // remove itself from object list item map
317 m_map->take( m_object );
318}
319
320TQString
321VObjectListViewItem::key( int, bool ) const
322{
323 return TQString( "%1" ).arg( m_key );
324}
325
326void
327VObjectListViewItem::update()
328{
329 // text description
330 VSelectionDescription selectionDesc;
331 selectionDesc.visit( *m_object );
332 setText( 0, TQString( "%1" ).arg( selectionDesc.shortDescription() ) );
333
334 // draw thumb preview (16x16)
335 TQPixmap preview;
336 preview.resize( 16, 16 );
337 VKoPainter p( &preview, 16, 16, false );
338 // Y mirroring
339 TQWMatrix mat;
340 mat.scale( 1, -1 );
341 KoRect bbox = m_object->boundingBox();
342 mat.translate( 0, -16 );
343 double factor = 16. / kMax( bbox.width(), bbox.height() );
344 mat.translate( -bbox.x() * factor, -bbox.y() * factor );
345 p.setWorldMatrix( mat );
346
347 // TODO: When the document will support page size, change the following line.
348 p.setZoomFactor( factor );
349 m_object->draw( &p );
350 p.setZoomFactor( 1 );
351 p.setWorldMatrix( TQWMatrix() );
352 p.setPen( TQt::black );
353 p.setBrush( TQt::NoBrush );
354 p.drawRect( KoRect( 0, 0, 16, 16 ) );
355 p.end();
356
357 // set thumb preview, lock and visible pixmaps
358 setPixmap( 0, preview );
359 TQString s = ( m_object->state() == VObject::normal_locked || m_object->state() == VObject::hidden_locked ) ? "locked" : "unlocked";
360 setPixmap( 1, *KarbonFactory::rServer()->cachePixmap( s, TDEIcon::Small ) );
361 s = ( m_object->state() == VObject::hidden || m_object->state() == VObject::hidden_locked ) ? "14_layer_novisible" : "14_layer_visible";
362 setPixmap( 2, *KarbonFactory::rServer()->cachePixmap( s, TDEIcon::Small ) );
363}
364
365int
366VObjectListViewItem::compare( TQListViewItem *i, int /*col*/, bool /*ascending*/ ) const
367{
368 VObjectListViewItem *objectItem = dynamic_cast<VObjectListViewItem*>(i);
369 if( ! objectItem ) return 0;
370 return m_key < objectItem->m_key ? -1 : 1;
371}
372
373VLayerListViewItem::VLayerListViewItem( TQListView* parent, VLayer* layer, VDocument *doc, TQPtrDict<VLayerListViewItem> *map )
374 : TQCheckListItem( parent, 0L, CheckBox ), m_layer( layer ), m_document( doc), m_map( map )
375{
376 update();
377 // add itself to layer list item map
378 m_map->insert( layer, this );
379} // VLayerListViewItem::VLayerListViewItem
380
381VLayerListViewItem::~VLayerListViewItem()
382{
383 // remove itself from layer list item map
384 m_map->take( m_layer );
385}
386
387void
388VLayerListViewItem::update()
389{
390 // draw thumb preview (16x16)
391 TQPixmap preview;
392 preview.resize( 16, 16 );
393 VKoPainter p( &preview, 16, 16, false );
394 // Y mirroring
395 TQWMatrix mat;
396 mat.scale( 1, -1 );
397 mat.translate( 0, -16 );
398 p.setWorldMatrix( mat );
399
400 // TODO: When the document will support page size, change the following line.
401 p.setZoomFactor( 16. / 800. );
402 m_layer->draw( &p );
403 p.setZoomFactor( 1 );
404 p.setWorldMatrix( TQWMatrix() );
405 p.setPen( TQt::black );
406 p.setBrush( TQt::NoBrush );
407 p.drawRect( KoRect( 0, 0, 16, 16 ) );
408 p.end();
409
410 // text description
411 setOn( m_layer->selected() );
412 setText( 0, m_layer->name() );
413
414 // set thumb preview, lock and visible pixmaps
415 setPixmap( 0, preview );
416 TQString s = ( m_layer->state() == VObject::normal_locked || m_layer->state() == VObject::hidden_locked ) ? "locked" : "unlocked";
417 setPixmap( 1, *KarbonFactory::rServer()->cachePixmap( s, TDEIcon::Small ) );
418 s = ( m_layer->state() == VObject::normal || m_layer->state() == VObject::normal_locked ) ? "14_layer_visible" : "14_layer_novisible";
419 setPixmap( 2, *KarbonFactory::rServer()->cachePixmap( s, TDEIcon::Small ) );
420} // VLayerListViewItem::update
421
422void
423VLayerListViewItem::stateChange( bool on )
424{
425 m_layer->setSelected( on );
426} // VLayerListViewItem::stateChange
427
428int
429VLayerListViewItem::pos()
430{
431 VLayerListViewItem* item;
432 if( !( item = (VLayerListViewItem*)itemAbove() ) )
433 return 0;
434 else
435 return 1 + item->pos();
436} // VLayerListViewItem::pos
437
438TQString
439VLayerListViewItem::key( int, bool ) const
440{
441 return TQString( "%1" ).arg( m_key );
442}
443
444int
445VLayerListViewItem::compare( TQListViewItem *i, int /*col*/, bool /*ascending*/ ) const
446{
447 VLayerListViewItem *layerItem = dynamic_cast<VLayerListViewItem*>(i);
448 if( ! layerItem ) return 0;
449 return m_key < layerItem->m_key ? -1 : 1;
450}
451
452VLayersTab::VLayersTab( KarbonView* view, TQWidget* parent )
453 : TQWidget( parent, "LayersTab" ), m_view( view ), m_document( &view->part()->document() )
454{
455
456 TQToolButton* button;
457 TQVBoxLayout* layout = new TQVBoxLayout( this, 1 );
458 layout->addWidget( m_layersListView = new TQListView( this ), 1 );
459 m_buttonGroup = new TQHButtonGroup( this );
460 m_buttonGroup->setInsideMargin( 3 );
461 button = new TQToolButton( m_buttonGroup );
462 button->setIconSet( SmallIcon( "14_layer_newlayer" ) );
463 button->setTextLabel( i18n( "New" ) );
464 m_buttonGroup->insert( button );
465 button = new TQToolButton( m_buttonGroup );
466 button->setIconSet( SmallIcon( "14_layer_raiselayer" ) );
467 button->setTextLabel( i18n( "Raise" ) );
468 m_buttonGroup->insert( button );
469 button = new TQToolButton( m_buttonGroup );
470 button->setIconSet( SmallIcon( "14_layer_lowerlayer" ) );
471 button->setTextLabel( i18n( "Lower" ) );
472 m_buttonGroup->insert( button );
473 button = new TQToolButton( m_buttonGroup );
474 button->setIconSet( SmallIcon( "14_layer_deletelayer" ) );
475 button->setTextLabel( i18n( "Delete" ) );
476 m_buttonGroup->insert( button );
477 layout->addWidget( m_buttonGroup, 0);
478 layout->setSpacing( 0 );
479 layout->setMargin( 3 );
480
481 m_layersListView->setAllColumnsShowFocus( true );
482 m_layersListView->addColumn( i18n( "Item" ), 120 );
483 m_layersListView->addColumn( i18n( "L" ), 20 );
484 m_layersListView->addColumn( i18n( "V" ), 20 );
485 m_layersListView->setColumnWidthMode( 0, TQListView::Maximum );
486 m_layersListView->setColumnAlignment( 1, TQt::AlignCenter );
487 m_layersListView->setColumnAlignment( 2, TQt::AlignCenter );
488 m_layersListView->setResizeMode( TQListView::NoColumn );
489 m_layersListView->setSorting( 0, false );
490 m_layersListView->setRootIsDecorated( true );
491 m_layersListView->setSelectionMode( TQListView::Extended );
492
493 connect( m_layersListView, TQ_SIGNAL( clicked( TQListViewItem*, const TQPoint&, int ) ), this, TQ_SLOT( itemClicked( TQListViewItem*, const TQPoint&, int ) ) );
494 connect( m_layersListView, TQ_SIGNAL( rightButtonClicked( TQListViewItem*, const TQPoint&, int ) ), this, TQ_SLOT( renameItem( TQListViewItem*, const TQPoint&, int ) ) );
495 connect( m_layersListView, TQ_SIGNAL( selectionChanged() ), this, TQ_SLOT( selectionChangedFromList() ) );
496 connect( m_view, TQ_SIGNAL( selectionChange() ), this, TQ_SLOT( selectionChangedFromTool() ) );
497 connect( m_buttonGroup, TQ_SIGNAL( clicked( int ) ), this, TQ_SLOT( slotButtonClicked( int ) ) );
498 connect( view->part()->commandHistory(), TQ_SIGNAL( commandExecuted( VCommand*) ), this, TQ_SLOT( slotCommandExecuted( VCommand* ) ) );
499
500 layout->activate();
501 updateLayers();
502} // VLayersTab::VLayersTab
503
504VLayersTab::~VLayersTab()
505{
506} // VLayersTab::~VLayersTab
507
508void
509VLayersTab::slotButtonClicked( int ID )
510{
511 switch( ID )
512 {
513 case 0:
514 addLayer(); break;
515 case 1:
516 raiseItem(); break;
517 case 2:
518 lowerItem(); break;
519 case 3:
520 deleteItem(); break;
521 }
522} // VLayersTab::slotButtonClicked
523
524void
525VLayersTab::resetSelection()
526{
527 TQListViewItemIterator it( m_layersListView );
528
529 // iterates over all list items and deselects them manually
530 // to avoid the list views selectionChanged signal
531 for(; it.current(); ++it )
532 {
533 it.current()->setSelected( false );
534 it.current()->repaint();
535 }
536}
537
538void
539VLayersTab::selectActiveLayer()
540{
541 if( ! m_layers[ m_document->activeLayer() ] )
542 {
543 TQPtrVector<VLayer> vector;
544 m_document->layers().toVector( &vector );
545 // find another layer to set active
546 for( int i = vector.count() - 1; i >= 0; i-- )
547 if ( vector[i]->state() != VObject::deleted )
548 {
549 m_document->setActiveLayer( vector[i] );
550 break;
551 }
552 }
553
554 // deselect all other layers
555 TQPtrDictIterator<VLayerListViewItem> it( m_layers );
556 for(; it.current(); ++it )
557 {
558 it.current()->setSelected( false );
559 it.current()->repaint();
560 }
561
562 VLayerListViewItem *layerItem = m_layers[ m_document->activeLayer() ];
563 if( layerItem )
564 {
565 layerItem->setSelected( true );
566 layerItem->repaint();
567 kdDebug(38000) << "selecting active layer: " << layerItem->text() << endl;
568 }
569}
570
571void
572VLayersTab::selectionChangedFromTool()
573{
574 resetSelection();
575 removeDeletedObjectsFromList();
576
577 // TODO : use some kind of mapping...
578 VObjectListIterator itr = m_document->selection()->objects();
579 for( ; itr.current(); ++itr )
580 if( itr.current()->state() != VObject::deleted )
581 {
582 VObject *obj = itr.current();
583
584 VObjectListViewItem *item = m_objects[ obj ];
585 if( ! item )
586 {
587 VLayerListViewItem *layerItem = m_layers[ obj->parent() ];
588 if( layerItem )
589 updateObjects( layerItem->layer(), layerItem );
590 else
591 {
592 VObjectListViewItem *objectItem = m_objects[ obj->parent() ];
593 if( objectItem )
594 updateObjects( objectItem->object(), objectItem );
595 else
596 continue;
597 }
598 item = m_objects[ obj ];
599 }
600 if( ! item ) continue;
601
602 item->setSelected( true );
603 item->update();
604 }
605 selectActiveLayer();
606}
607
608void
609VLayersTab::updateChildItems( TQListViewItem *item )
610{
611 TQListViewItemIterator it( item );
612
613 // iterator points to item, so make the next item current first
614 for( ++it; it.current(); ++it )
615 {
616 VObjectListViewItem *objectItem = dynamic_cast<VObjectListViewItem *>( it.current() );
617 if( ! objectItem ) continue;
618
619 if( dynamic_cast<VGroup*>( objectItem->object() ) )
620 updateChildItems( objectItem );
621
622 objectItem->update();
623 objectItem->repaint();
624 }
625}
626
627void
628VLayersTab::toggleState( VObject *obj, int col )
629{
630 switch( col )
631 {
632 case 1: // toggle visibility
633 if( obj->state() == VObject::hidden_locked )
635 else if( obj->state() == VObject::normal_locked )
637 else if( obj->state() == VObject::normal || obj->state() >= VObject::selected )
639 else if( obj->state() == VObject::hidden )
641 break;
642 case 2: // toggle locking
643 if( obj->state() == VObject::hidden_locked )
645 else if( obj->state() == VObject::normal_locked )
647 else if( obj->state() == VObject::normal || obj->state() >= VObject::selected )
649 else if( obj->state() == VObject::hidden )
651 break;
652 default: return;
653 }
654
655 if( obj->state() < VObject::selected )
656 m_document->selection()->take( *obj );
657 else
658 m_document->selection()->append( obj );
659}
660
661void
662VLayersTab::itemClicked( TQListViewItem* item, const TQPoint &, int col )
663{
664 if( item )
665 {
666 VLayerListViewItem *layerItem = dynamic_cast<VLayerListViewItem *>( item );
667 if( layerItem )
668 {
669 if( col == 0 )
670 {
671 m_document->setActiveLayer( layerItem->layer() );
672 selectActiveLayer();
673 }
674 if( col > 0 )
675 {
676 toggleState( layerItem->layer(), col );
677
678 layerItem->update();
679 layerItem->repaint();
680
681 updateChildItems( layerItem );
682
683 m_view->part()->repaintAllViews();
684 }
685 }
686 else
687 {
688 VObjectListViewItem *objectItem = dynamic_cast< VObjectListViewItem *>( item );
689
690 if( col == 0 )
691 {
692 VObject *obj = objectItem->object();
693 if( obj->state() == VObject::normal )
695 }
696 if( col > 0 )
697 {
698 toggleState( objectItem->object(), col );
699
700 if( objectItem->object()->state() == VObject::selected )
701 objectItem->setSelected( true );
702 else
703 objectItem->setSelected( false );
704
705 objectItem->update();
706 objectItem->repaint();
707
708 if( dynamic_cast<VGroup*>( objectItem->object() ) )
709 updateChildItems( objectItem );
710
711 m_view->part()->repaintAllViews();
712 }
713 }
714 }
715} // VLayersTab::itemClicked
716
717void
718VLayersTab::selectionChangedFromList()
719{
720 m_document->selection()->clear();
721
722 TQListViewItemIterator it( m_layersListView );
723
724 // iterate over all list items and add their corresponding object
725 // to the documents selection if the list item is selected and not hidden or locked or both
726 for(; it.current(); ++it )
727 {
728 VObjectListViewItem *objectItem = dynamic_cast<VObjectListViewItem *>( it.current() );
729 if( ! objectItem ) continue;
730
731 VObject::VState state = objectItem->object()->state();
732
733 if( state == VObject::deleted )
734 {
735 delete objectItem;
736 continue;
737 }
738
739 if( objectItem->isSelected() && (state != VObject::hidden) && (state != VObject::normal_locked )
740 && (state != VObject::hidden_locked) )
741 {
742 m_document->selection()->append( objectItem->object() );
743 objectItem->repaint();
744 }
745 }
746
747 m_view->selectionChanged();
748 m_view->part()->repaintAllViews();
749}
750
751void
752VLayersTab::renameItem( TQListViewItem* item, const TQPoint&, int col )
753{
754 if ( ( item ) && col == 0 )
755 {
756 bool ok = true;
757 VLayerListViewItem* layerItem = dynamic_cast<VLayerListViewItem *>( item );
758 if( !layerItem )
759 {
760 VObjectListViewItem *objectItem = dynamic_cast< VObjectListViewItem *>( item );
761 VObject *obj = objectItem->object();
762 TQString name = KInputDialog::getText( i18n( "Current Object" ), i18n( "Change the name of the object:" ),
763 obj->name(), &ok, this );
764 if( ok )
765 {
766 m_document->setObjectName( obj, name );
767 objectItem->update();
768 }
769 }
770 else
771 {
772 TQString name = KInputDialog::getText( i18n( "Rename Layer" ), i18n( "Change the name of the current layer:" ),
773 layerItem->layer()->name(), &ok, this );
774 if( ok )
775 {
776 layerItem->layer()->setName( name );
777 layerItem->update();
778 }
779 }
780 }
781} // VLayersTab::renameItem
782
783void
784VLayersTab::addLayer()
785{
786 bool ok = true;
787 TQString name = KInputDialog::getText( i18n( "New Layer" ), i18n( "Enter the name of the new layer:" ),
788 i18n( "New layer" ), &ok, this );
789 if( ok )
790 {
791 VLayer* layer = new VLayer( m_document );
792 layer->setName( name );
793 VLayerCmd* cmd = new VLayerCmd( m_document, i18n( "Add Layer" ),
794 layer, VLayerCmd::addLayer );
795 m_view->part()->addCommand( cmd, true );
796 updateLayers();
797 }
798} // VLayersTab::addLayer
799
800void
801VLayersTab::raiseItem()
802{
803 VCommand *cmd = 0L;
804 //TQListViewItem *newselection = 0L;
805 TQListViewItemIterator it( m_layersListView );
806
807 if( m_document->selection()->objects().count() )
808 {
809 cmd = new VZOrderCmd( m_document, VZOrderCmd::up );
810 m_view->part()->addCommand( cmd, true );
811 }
812 else
813 {
814 for(; it.current(); ++it )
815 {
816 if( ! it.current()->isSelected() ) continue;
817
818 VLayerListViewItem* layerItem = dynamic_cast<VLayerListViewItem *>( it.current() );
819 if( layerItem )
820 {
821 VLayer *layer = layerItem->layer();
822 if( layer && m_document->canRaiseLayer( layer ) )
823 {
824 cmd = new VLayerCmd( m_document, i18n( "Raise Layer" ),
825 layerItem->layer(), VLayerCmd::raiseLayer );
826 m_view->part()->addCommand( cmd, true );
827 }
828 }
829 }
830 }
831
832 if( cmd ) updatePreviews();
833} // VLayersTab::raiseItem
834
835void
836VLayersTab::lowerItem()
837{
838 VCommand *cmd = 0L;
839 TQListViewItemIterator it( m_layersListView );
840
841 if( m_document->selection()->objects().count() )
842 {
843 cmd = new VZOrderCmd( m_document, VZOrderCmd::down );
844 m_view->part()->addCommand( cmd, true );
845 }
846 else
847 {
848 for(; it.current(); ++it )
849 {
850 if( ! it.current()->isSelected() ) continue;
851
852 VLayerListViewItem* layerItem = dynamic_cast<VLayerListViewItem *>( it.current() );
853 if( layerItem )
854 {
855 VLayer *layer = layerItem->layer();
856 if( layer && m_document->canLowerLayer( layer ) )
857 {
858 cmd = new VLayerCmd( m_document, i18n( "Lower Layer" ), layer, VLayerCmd::lowerLayer );
859 m_view->part()->addCommand( cmd, true );
860 }
861 }
862 }
863 }
864
865 if( cmd ) updatePreviews();
866} // VLayersTab::lowerItem
867
868void
869VLayersTab::deleteItem()
870{
871 VCommand *cmd = 0L;
872 TQListViewItemIterator it( m_layersListView );
873
874 TQPtrList<TQListViewItem> deleteItems;
875 deleteItems.setAutoDelete( false );
876
877 // collect all selected items because they get deselected
878 // when the first item is removed
879 for(; it.current(); ++it )
880 {
881 if( ! it.current()->isSelected() ) continue;
882 deleteItems.append( it.current() );
883 }
884
885 for( ;deleteItems.first(); )
886 {
887 VLayerListViewItem* layerItem = dynamic_cast< VLayerListViewItem *>( deleteItems.current() );
888 if( layerItem )
889 {
890 VLayer *layer = layerItem->layer();
891 if( layer && m_layers.count() > 1 )
892 {
893 cmd = new VLayerCmd( m_document, i18n( "Delete Layer" ), layer, VLayerCmd::deleteLayer );
894
895 VObjectListIterator itr = layer->objects();
896 // iterate over this layers child objects and remove them from the internal
897 // object list and the list of the to be deleted items
898 for( ; itr.current(); ++itr )
899 {
900 VObjectListViewItem *objectItem = m_objects.take( itr.current() );
901 deleteItems.remove( objectItem );
902 }
903
904 delete layerItem;
905
906 m_view->part()->addCommand( cmd );
907
908 selectActiveLayer();
909 }
910 }
911 else
912 {
913 VObjectListViewItem* item = dynamic_cast< VObjectListViewItem *>( deleteItems.current() );
914 if( item )
915 {
916 cmd = new VDeleteCmd( m_document, item->object() );
917
918 delete item;
919
920 m_view->part()->addCommand( cmd );
921 }
922 }
923 // remove first item, next item becomes current
924 deleteItems.removeFirst();
925 }
926 if( cmd )
927 {
928 updatePreviews();
929 m_view->part()->repaintAllViews();
930 }
931} // VLayersTab::deleteItem
932
933void
934VLayersTab::updatePreviews()
935{
936 // TODO: Optimization: call update() on each view item...
937 updateLayers();
938} // VLayersTab::updatePreviews
939
940void
941VLayersTab::updateLayers()
942{
943 removeDeletedObjectsFromList();
944
945 TQPtrVector<VLayer> vector;
946 m_document->layers().toVector( &vector );
947 VLayerListViewItem* item = 0L;
948 for( int i = vector.count() - 1; i >= 0; i-- )
949 {
950 if ( vector[i]->state() != VObject::deleted )
951 {
952 if( !m_layers[ vector[i] ] )
953 {
954 item = new VLayerListViewItem( m_layersListView, vector[i], m_document, &m_layers );
955 item->setOpen( true );
956 }
957 else
958 item = m_layers[ vector[i] ];
959
960 item->setKey(i);
961
962 updateObjects( vector[i], item );
963 }
964 }
965
966 selectActiveLayer();
967 m_layersListView->sort();
968} // VLayersTab::updateLayers
969
970void
971VLayersTab::updateObjects( VObject *object, TQListViewItem *item )
972{
973 VObjectListIterator itr = dynamic_cast<VGroup *>( object )->objects();
974
975 for( uint objcount = 1; itr.current(); ++itr, objcount++ )
976 if( itr.current()->state() != VObject::deleted )
977 {
978 VObjectListViewItem *objectItem = m_objects[ itr.current() ];
979 if( ! objectItem )
980 {
981 // object not found -> insert
982 objectItem = new VObjectListViewItem( item, itr.current(), m_document, objcount, &m_objects );
983 objectItem->update();
984 }
985 else if( objectItem->parent() != item )
986 {
987 // object found, but has false parent -> reparent
988 objectItem->parent()->takeItem( objectItem );
989 item->insertItem( objectItem );
990 }
991
992 objectItem->setKey( objcount );
993
994 if( dynamic_cast<VGroup *>( itr.current() ) )
995 updateObjects( itr.current(), objectItem );
996 }
997
998 item->sort();
999}
1000
1001void
1002VLayersTab::removeDeletedObjectsFromList()
1003{
1004 TQPtrDictIterator<VObjectListViewItem> it( m_objects );
1005
1006 // iterate over all object items and delete the following items:
1007 // - items representing deleted objects
1008 // - items with objects objects that changed parents
1009 // BEWARE: when deleting an item, the iterator is automatically incremented
1010 for(; it.current(); )
1011 {
1012 VLayerListViewItem *layerItem = dynamic_cast<VLayerListViewItem*>( it.current()->parent() );
1013 if( layerItem )
1014 {
1015 VGroup *group = dynamic_cast<VGroup*>( layerItem->layer() );
1016 // check if object of item is still child of object of parent item
1017 if( group && ! group->objects().contains( it.current()->object() ) )
1018 {
1019 layerItem->takeItem( it.current() );
1020 delete it.current();
1021 continue;
1022 }
1023 }
1024 else
1025 {
1026 VObjectListViewItem *objectItem = dynamic_cast<VObjectListViewItem*>( it.current()->parent() );
1027 if( objectItem )
1028 {
1029 VGroup *group = dynamic_cast<VGroup*>( objectItem->object() );
1030 // check if object of item is still child of object of parent item
1031 if( group && ! group->objects().contains( it.current()->object() ) )
1032 {
1033 objectItem->takeItem( it.current() );
1034 delete it.current();
1035 continue;
1036 }
1037 }
1038 else
1039 {
1040 delete it.current();
1041 continue;
1042 }
1043 }
1044
1045 if( it.current()->object()->state() == VObject::deleted )
1046 {
1047 delete it.current();
1048 continue;
1049 }
1050
1051 ++it;
1052 }
1053
1054 TQPtrDictIterator<VLayerListViewItem> itr( m_layers );
1055
1056 // iterate over all layer items and delete the following items:
1057 // - items representing deleted layers
1058 // BEWARE: when deleting an item, the iterator is automatically incremented
1059 for(; itr.current(); )
1060 {
1061 if( itr.current()->layer()->state() == VObject::deleted )
1062 {
1063 m_layersListView->takeItem( itr.current() );
1064 delete itr.current();
1065 continue;
1066 }
1067 ++itr;
1068 }
1069}
1070
1071
1072void
1073VLayersTab::slotCommandExecuted( VCommand* command )
1074{
1075 // sync listview on changing layers or deleting/undeleting or grouping/ungrouping objects
1076 if( dynamic_cast<VLayerCmd*>( command )
1077 || dynamic_cast<VDeleteCmd*>( command )
1078 || dynamic_cast<VGroupCmd*>( command )
1079 || dynamic_cast<VUnGroupCmd*>( command )
1080 || dynamic_cast<VZOrderCmd*>( command ) )
1081 updateLayers();
1082}
1083
1084/*************************************************************************
1085 * History tab *
1086 *************************************************************************/
1087
1088VHistoryGroupItem::VHistoryGroupItem( VHistoryItem* item, TQListView* parent, TQListViewItem* after )
1089 : TQListViewItem( parent, after )
1090{
1091 setPixmap( 0, *item->pixmap( 0 ) );
1092 setText( 0, item->text( 0 ) );
1093 parent->takeItem( item );
1094 insertItem( item );
1095 m_key = item->key( 0, true );
1096} // VHistoryItem::VHistoryItem
1097
1098VHistoryGroupItem::~VHistoryGroupItem()
1099{
1100} // VHistoryGroupItem::~VHistoryGroupItem
1101
1102void
1103VHistoryGroupItem::paintCell( TQPainter* p, const TQColorGroup& cg, int column, int width, int align )
1104{
1105 int e = 0;
1106 int n = 0;
1107 VHistoryItem* item = (VHistoryItem*)firstChild();
1108 while ( item )
1109 {
1110 if ( item->command()->success() )
1111 e++;
1112 else
1113 n++;
1114 item = (VHistoryItem*)item->nextSibling();
1115 }
1116 if ( e > 0 )
1117 {
1118 p->fillRect( 0, 0, width, height(), cg.base() );
1119 if ( n > 0 )
1120 p->fillRect( 0, 0, width, height(), TQBrush( cg.base().dark( 140 ), TQBrush::BDiagPattern ) );
1121 }
1122 else
1123 p->fillRect( 0, 0, width, height(), cg.base().dark( 140 ) );
1124
1125 const TQPixmap* pixmap = this->pixmap( column );
1126 int xstart;
1127 if ( pixmap )
1128 {
1129 int pw = pixmap->width();
1130 int ph = pixmap->height();
1131 p->drawPixmap( ( height() - pw ) / 2, ( height() - ph ) / 2, *pixmap );
1132 xstart = height();
1133 }
1134 else
1135 xstart = 4;
1136 p->setPen( cg.text() );
1137 p->drawText( xstart, 0, width - xstart, height(), align | TQt::AlignVCenter, text( column ) );
1138} // VHistoryGroupItem::paintCell
1139
1140void
1141VHistoryGroupItem::paintFocus( TQPainter*, const TQColorGroup&, const TQRect& )
1142{
1143 // Do not paint any focus rectangle
1144 // It makes the list and the selected item look messy
1145
1146} // VHistoryGroupItem::paintFocus
1147
1148VHistoryItem::VHistoryItem( VCommand* command, TQListView* parent, TQListViewItem* after )
1149 : TQListViewItem( parent, after ), m_command( command )
1150{
1151 init();
1152} // VHistoryItem::VHistoryItem
1153
1154VHistoryItem::VHistoryItem( VCommand* command, VHistoryGroupItem* parent, TQListViewItem* after )
1155 : TQListViewItem( parent, after ), m_command( command )
1156{
1157 init();
1158} // VHistoryItem::VHistoryItem
1159
1160void
1161VHistoryItem::init()
1162{
1163 kdDebug(38000) << "In VHistoryItem::init() : " << m_command->name() << endl;
1164 char buffer[70];
1165 sprintf( buffer, "%064ld", ++g_lastKey );
1166 m_key = buffer;
1167 setPixmap( 0, TQPixmap( TDEGlobal::iconLoader()->iconPath( m_command->icon(), TDEIcon::Small ) ) );
1168 setText( 0, m_command->name() );
1169} // VHistoryITem::init
1170
1171VHistoryItem::~VHistoryItem()
1172{
1173} // VHistoryItem::~VHistoryItem
1174
1175void
1176VHistoryItem::paintCell( TQPainter* p, const TQColorGroup& cg, int column, int width, int align )
1177{
1178 p->fillRect( 0, 0, width, height(), ( m_command->success() ? cg.base() : TQColor(cg.base().dark( 140 )) ) );
1179
1180 const TQPixmap* pixmap = this->pixmap( column );
1181 int xstart;
1182 if ( pixmap )
1183 {
1184 int pw = pixmap->width();
1185 int ph = pixmap->height();
1186 p->drawPixmap( ( height() - pw ) / 2, ( height() - ph ) / 2, *pixmap );
1187 xstart = height();
1188 }
1189 else
1190 xstart = 4;
1191 p->setPen( cg.text() );
1192 p->drawText( xstart, 0, width - xstart, height(), align | TQt::AlignVCenter, text( column ) );
1193} // VHistoryItem::paintCell
1194
1195void
1196VHistoryItem::paintFocus( TQPainter*, const TQColorGroup&, const TQRect& )
1197{
1198 // Do not paint any focus rectangle
1199 // It makes the list and the selected item look messy
1200
1201} // VHistoryItem::paintFocus
1202
1203VHistoryTab::VHistoryTab( KarbonPart* part, TQWidget* parent )
1204 : TQWidget( parent ), m_part( part )
1205{
1206 TQVBoxLayout* layout = new TQVBoxLayout( this );
1207 layout->setMargin( 3 );
1208 layout->setSpacing( 2 );
1209 layout->add( m_history = new TQListView( this ) );
1210 m_history->setVScrollBarMode( TQListView::AlwaysOn );
1211 m_history->setSelectionMode( TQListView::NoSelection );
1212 m_history->addColumn( i18n( "Commands" ) );
1213 m_history->setResizeMode( TQListView::AllColumns );
1214 m_history->setRootIsDecorated( true );
1215 layout->add( m_groupCommands = new TQCheckBox( i18n( "Group commands" ), this ) );
1216
1217 m_history->setSorting( 0, true );
1218 VHistoryGroupItem* group = 0;
1219 VHistoryItem* last = 0;
1220 TQPtrVector<VCommand> cmds;
1221 part->commandHistory()->commands()->toVector( &cmds );
1222 int c = cmds.count();
1223 for ( int i = 0; i < c; i++ )
1224 {
1225 if ( ( i > 0 ) && ( cmds[ i ]->name() == cmds[ i - 1 ]->name() ) )
1226 if ( group )
1227 {
1228 TQListViewItem* prev = group->firstChild();
1229 while ( prev && prev->nextSibling() )
1230 prev = prev->nextSibling();
1231 new VHistoryItem( cmds[ i ], group, prev );
1232 }
1233 else
1234 {
1235 group = new VHistoryGroupItem( last, m_history, last );
1236 new VHistoryItem( cmds[ i ], group, last );
1237 }
1238 else
1239 {
1240 last = new VHistoryItem( cmds[ i ], m_history, last );
1241 group = 0;
1242 }
1243 }
1244 m_history->sort();
1245
1246 connect( m_history, TQ_SIGNAL( mouseButtonClicked( int, TQListViewItem*, const TQPoint&, int ) ), this, TQ_SLOT( commandClicked( int, TQListViewItem*, const TQPoint&, int ) ) );
1247 connect( m_groupCommands, TQ_SIGNAL( stateChanged( int ) ), this, TQ_SLOT( groupingChanged( int ) ) );
1248 connect( part->commandHistory(), TQ_SIGNAL( historyCleared() ), this, TQ_SLOT( historyCleared() ) );
1249 connect( part->commandHistory(), TQ_SIGNAL( commandAdded( VCommand* ) ), this, TQ_SLOT( slotCommandAdded( VCommand* ) ) );
1250 connect( part->commandHistory(), TQ_SIGNAL( commandExecuted( VCommand* ) ), this, TQ_SLOT( commandExecuted( VCommand* ) ) );
1251 connect( part->commandHistory(), TQ_SIGNAL( firstCommandRemoved() ), this, TQ_SLOT( removeFirstCommand() ) );
1252 connect( part->commandHistory(), TQ_SIGNAL( lastCommandRemoved() ), this, TQ_SLOT( removeLastCommand() ) );
1253 connect( this, TQ_SIGNAL( undoCommand( VCommand* ) ), part->commandHistory(), TQ_SLOT( undo( VCommand* ) ) );
1254 connect( this, TQ_SIGNAL( redoCommand( VCommand* ) ), part->commandHistory(), TQ_SLOT( redo( VCommand* ) ) );
1255 connect( this, TQ_SIGNAL( undoCommandsTo( VCommand* ) ), part->commandHistory(), TQ_SLOT( undoAllTo( VCommand* ) ) );
1256 connect( this, TQ_SIGNAL( redoCommandsTo( VCommand* ) ), part->commandHistory(), TQ_SLOT( redoAllTo( VCommand* ) ) );
1257} // VHistoryTab::VHistoryTab
1258
1259VHistoryTab::~VHistoryTab()
1260{
1261} // VHistoryTab::~VHistoryTab
1262
1263bool
1264VHistoryTab::groupingEnabled()
1265{
1266 return m_groupCommands->isChecked();
1267} // VHistoryTab::groupingEnabled
1268
1269void
1270VHistoryTab::historyCleared()
1271{
1272 m_history->clear();
1273} // VHistoryTab::historyCleared
1274
1275void
1276VHistoryTab::commandExecuted( VCommand* command )
1277{
1278 TQListViewItem* item = m_history->firstChild();
1279 bool found = false;
1280 while ( !found && item )
1281 {
1282 if ( item->rtti() == 1001 )
1283 {
1284 TQListViewItem* child = item->firstChild();
1285 while ( !found && child )
1286 {
1287 found = ( ( (VHistoryItem*)child )->command() == command );
1288 if ( !found )
1289 child = child->nextSibling();
1290 else
1291 item = child;
1292 }
1293 }
1294 found = ( item && ( (VHistoryItem*)item )->command() == command );
1295 if ( !found )
1296 item = item->nextSibling();
1297 }
1298 if ( found )
1299 {
1300 m_history->repaintItem( item );
1301 if ( item->parent() )
1302 m_history->repaintItem( item->parent() );
1303 m_history->ensureItemVisible( item );
1304 }
1305} // VHistoryTab::commandExecuted
1306
1307void
1308VHistoryTab::slotCommandAdded( VCommand* command )
1309{
1310 if ( !command )
1311 return;
1312
1313 TQListViewItem* last = m_history->firstChild();
1314 while ( last && last->nextSibling() )
1315 last = last->nextSibling();
1316
1317 if( groupingEnabled() )
1318 {
1319 if( ( last ) && last->text( 0 ) == command->name() )
1320 {
1321 if( last->rtti() == 1002 )
1322 {
1323 TQListViewItem* prevSibling;
1324 if( m_history->childCount() > 1 )
1325 {
1326 prevSibling = m_history->firstChild();
1327 while ( prevSibling->nextSibling() != last )
1328 prevSibling = prevSibling->nextSibling();
1329 }
1330 else
1331 prevSibling = m_history->firstChild();
1332 last = new VHistoryGroupItem( (VHistoryItem*)last, m_history, prevSibling );
1333 }
1334 TQListViewItem* prev = last->firstChild();
1335 while ( prev && prev->nextSibling() )
1336 prev = prev->nextSibling();
1337 m_history->setCurrentItem( new VHistoryItem( command, (VHistoryGroupItem*)last, prev ) );
1338 }
1339 else
1340 m_history->setCurrentItem( new VHistoryItem( command, m_history, last ) );
1341 }
1342 else
1343 m_history->setCurrentItem( new VHistoryItem( command, m_history, last ) );
1344
1345 m_history->sort();
1346 m_history->ensureItemVisible( m_history->currentItem() );
1347 m_history->update();
1348} // VHistoryTab::slotCommandAdded
1349
1350void
1351VHistoryTab::removeFirstCommand()
1352{
1353 if ( m_history->childCount() > 0 )
1354 if ( m_history->firstChild()->rtti() == 1002 )
1355 delete m_history->firstChild();
1356 else
1357 {
1358 VHistoryGroupItem* group = (VHistoryGroupItem*)m_history->firstChild();
1359 delete group->firstChild();
1360 if ( group->childCount() == 1 )
1361 {
1362 new VHistoryItem( ( (VHistoryItem*)group->firstChild() )->command(), m_history, 0 );
1363 delete group;
1364 }
1365 }
1366} // VHistoryTab::removeFirstCommand
1367
1368void
1369VHistoryTab::removeLastCommand()
1370{
1371 if ( m_history->childCount() > 0 )
1372 {
1373 TQListViewItem* last = m_history->firstChild();
1374 while ( last && last->nextSibling() )
1375 last = last->nextSibling();
1376 if ( last->rtti() == 1002 )
1377 delete last;
1378 else
1379 {
1380 VHistoryGroupItem* group = (VHistoryGroupItem*)last;
1381 last = group->firstChild();
1382 while ( last && last->nextSibling() )
1383 last = last->nextSibling();
1384 delete last;
1385 if ( group->childCount() == 1 )
1386 {
1387 new VHistoryItem( ( (VHistoryItem*)group->firstChild() )->command(), m_history, group );
1388 delete group;
1389 }
1390 }
1391 }
1392} // VHistoryTab::removeLastCommand
1393
1394void
1395VHistoryTab::commandClicked( int button, TQListViewItem* item, const TQPoint&, int )
1396{
1397 if ( !item || item->rtti() == 1001 )
1398 return;
1399
1400 VCommand* cmd = ( (VHistoryItem*)item )->command();
1401 if ( cmd->success() )
1402 if ( button == 1 )
1403 emit undoCommandsTo( ( (VHistoryItem*)item )->command() );
1404 else
1405 emit undoCommand( ( (VHistoryItem*)item )->command() );
1406 else
1407 if ( button == 1 )
1408 emit redoCommandsTo( ( (VHistoryItem*)item )->command() );
1409 else
1410 emit redoCommand( ( (VHistoryItem*)item )->command() );
1411} // VHistoryTab::commandClicked
1412
1413void
1414VHistoryTab::groupingChanged( int )
1415{
1416 if ( m_groupCommands->isChecked() && m_history->childCount() > 1 )
1417 {
1418 TQListViewItem* s2last = 0;
1419 TQListViewItem* last = m_history->firstChild();
1420 TQListViewItem* item = last->nextSibling();
1421 while ( item )
1422 if ( last->text( 0 ) == item->text( 0 ) )
1423 {
1424 if ( last->rtti() == 1002 )
1425 last = new VHistoryGroupItem( (VHistoryItem*)last, m_history, s2last );
1426 m_history->takeItem( item );
1427 last->insertItem( item );
1428 item = last->nextSibling();
1429 }
1430 else
1431 {
1432 s2last = last;
1433 last = item;
1434 item = last->nextSibling();
1435 }
1436 }
1437 else
1438 {
1439 TQListViewItem* item = m_history->firstChild();
1440 while ( item )
1441 if ( item->rtti() == 1001 )
1442 {
1443 TQListViewItem* child;
1444 while ( ( child = item->firstChild() ) )
1445 {
1446 item->takeItem( child );
1447 m_history->insertItem( child );
1448 }
1449 child = item;
1450 item = item->nextSibling();
1451 delete child;
1452 }
1453 else
1454 item = item->nextSibling();
1455 }
1456 m_history->sort();
1457 m_history->update();
1458} // VHistoryTab::groupingChanged
1459
1460#include "vdocumentdocker.moc"
Keeps track of visual per document properties.
Definition karbon_part.h:46
VCommandHistory * commandHistory()
access the command history:
Definition karbon_part.h:85
This class keeps track of color properties.
Definition vcolor.h:41
const TQPtrList< VCommand > * commands() const
Read only access to the command history list.
Definition vcommand.h:223
The base class for all karbon commands.
Definition vcommand.h:42
TQString name() const
Returns the name of the command.
Definition vcommand.h:91
A class to provide undo/redoable deletion of VObjects.
Definition vdeletecmd.h:32
All non-visual, static doc info is in here.
Definition vdocument.h:53
Base class for all sort of VObject conglomerats.
Definition vgroup.h:35
const VObjectList & objects() const
Read only access to the grouped objects.
Definition vgroup.h:110
VLayer manages a set of vobjects.
Definition vlayer.h:37
The base class for all karbon objects.
Definition vobject.h:50
virtual void setState(const VState state)
Sets the state to a specified new state.
Definition vobject.h:163
VObject * parent() const
Returns pointer to current parent object.
Definition vobject.h:147
@ normal_locked
visible, but locked (r/o)
Definition vobject.h:55
@ hidden_locked
hidden and locked (r/o)
Definition vobject.h:57
@ selected
visible, active and can be manipulated by tools
Definition vobject.h:61
@ deleted
deleted, nearly dead
Definition vobject.h:58
@ normal
visible, not active
Definition vobject.h:54
@ hidden
hidden
Definition vobject.h:56
virtual TQString name() const
Returns the name of the object.
Definition vobject.cpp:225
void setName(const TQString &s)
Sets the object's name to a given new name.
Definition vobject.cpp:231
VState state() const
Get the state the object is in.
Definition vobject.h:154
This visitors visits structures and tries to capture relevant object type info as text.
Manages stroke properties.
Definition vstroke.h:49
bool success() const
Return if the operation was a success or not.
Definition vvisitor.h:125
virtual bool visit(VObject &object)
General visit method.
Definition vvisitor.cpp:31
Command that changes the z-order of the selection within a layer to front, back, one step up,...
Definition vzordercmd.h:32