20#include <tqhbuttongroup.h>
21#include <tqinputdialog.h>
23#include <tqcheckbox.h>
24#include <tqlistview.h>
25#include <tqptrvector.h>
26#include <tqtoolbutton.h>
28#include <tqtabwidget.h>
34#include <KoMainWindow.h>
36#include <kiconloader.h>
37#include <klineeditdlg.h>
38#include <kinputdialog.h>
40#include "karbon_part.h"
41#include "karbon_view.h"
42#include "karbon_factory.h"
43#include "karbon_resourceserver.h"
45#include "vkopainter.h"
48#include "vdeletecmd.h"
49#include "vzordercmd.h"
51#include "vungroupcmd.h"
52#include "vselection.h"
55#include "vdocumentdocker.h"
56#include <visitors/vselectiondesc.h>
58static long g_lastKey = 0;
64VDocumentPreview::VDocumentPreview( KarbonView* view, TQWidget* parent )
65 : TQWidget( parent,
"DocumentPreview" ), m_document( &view->part()->document() ), m_view( view )
68 installEventFilter(
this );
69 setBackgroundMode( TQt::NoBackground );
70 setMouseTracking(
true );
75VDocumentPreview::~VDocumentPreview()
81VDocumentPreview::reset()
88VDocumentPreview::eventFilter( TQObject*
object, TQEvent* event )
93 if ( ( height() - 4 ) / m_document->height() > ( width() - 4 ) / m_document->width() )
95 scaleFactor = ( width() - 4 ) / m_document->width();
96 yoffset = ( ( height() - 4 ) / scaleFactor - m_document->height() ) / 2;
100 scaleFactor = ( height() - 4 ) / m_document->height();
101 xoffset = ( ( width() - 4 ) / scaleFactor - m_document->width() ) / 2;
103 KoRect rect = m_view->canvasWidget()->boundingBox();
105 TQMouseEvent* mouseEvent =
static_cast<TQMouseEvent*
>( event );
106 if( event->type() == TQEvent::MouseButtonPress )
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 );
115 else if( event->type() == TQEvent::MouseButtonRelease )
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;
130 else if( event->type() == TQEvent::MouseMove )
134 m_lastPoint.setX( mouseEvent->pos().x() );
135 m_lastPoint.setY( mouseEvent->pos().y() );
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 ) );
151 return TQWidget::eventFilter(
object, event );
155VDocumentPreview::paintEvent( TQPaintEvent* )
158 TQPixmap pixmap( width(), height() );
162 if ( ( height() - 4 ) / m_document->height() > ( width() - 4 ) / m_document->width() )
164 scaleFactor = ( width() - 4 ) / m_document->width();
165 yoffset = ( ( height() - 4 ) / scaleFactor - m_document->height() ) / 2;
169 scaleFactor = ( height() - 4 ) / m_document->height();
170 xoffset = ( ( width() - 4 ) / scaleFactor - m_document->width() ) / 2;
172 xoffset += 2 / scaleFactor;
173 yoffset += 2 / scaleFactor;
174 if( !m_docpixmap || m_docpixmap->width() != width() || m_docpixmap->height() != height() )
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 );
185 VStroke stroke( c, 0L, 1.0 / scaleFactor );
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 );
192 bitBlt( &pixmap, 0, 0, m_docpixmap, 0, 0, width(), height() );
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() ) );
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 );
220 bitBlt(
this, 0, 0, &pixmap, 0, 0, width(), height() );
223VDocumentTab::VDocumentTab( KarbonView* view, TQWidget* parent )
224 : TQWidget( parent,
"DocumentTab" ), m_view( view )
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 );
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 );
250 m_width->setAlignment( AlignRight );
251 m_height->setAlignment( AlignRight );
252 m_layers->setAlignment( AlignRight );
253 m_format->setAlignment( AlignRight );
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() ) );
260 updateDocumentInfo();
263VDocumentTab::~VDocumentTab()
268VDocumentTab::updateDocumentInfo()
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() ) );
276VDocumentTab::slotCommandAdded(
VCommand * )
278 m_documentPreview->reset();
279 m_documentPreview->update();
283VDocumentTab::slotZoomChanged(
double )
285 m_documentPreview->update();
289VDocumentTab::slotViewportChanged()
291 m_documentPreview->update();
292 updateDocumentInfo();
296VDocumentTab::slotCommandExecuted()
298 m_documentPreview->reset();
299 m_documentPreview->update();
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 )
311 m_map->insert(
object,
this );
314VObjectListViewItem::~VObjectListViewItem()
317 m_map->take( m_object );
321VObjectListViewItem::key(
int,
bool )
const
323 return TQString(
"%1" ).arg( m_key );
327VObjectListViewItem::update()
331 selectionDesc.
visit( *m_object );
332 setText( 0, TQString(
"%1" ).arg( selectionDesc.shortDescription() ) );
336 preview.resize( 16, 16 );
337 VKoPainter p( &preview, 16, 16,
false );
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 );
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 ) );
358 setPixmap( 0, preview );
360 setPixmap( 1, *KarbonFactory::rServer()->cachePixmap( s, TDEIcon::Small ) );
362 setPixmap( 2, *KarbonFactory::rServer()->cachePixmap( s, TDEIcon::Small ) );
366VObjectListViewItem::compare( TQListViewItem *i,
int ,
bool )
const
368 VObjectListViewItem *objectItem =
dynamic_cast<VObjectListViewItem*
>(i);
369 if( ! objectItem )
return 0;
370 return m_key < objectItem->m_key ? -1 : 1;
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 )
378 m_map->insert( layer,
this );
381VLayerListViewItem::~VLayerListViewItem()
384 m_map->take( m_layer );
388VLayerListViewItem::update()
392 preview.resize( 16, 16 );
393 VKoPainter p( &preview, 16, 16,
false );
397 mat.translate( 0, -16 );
398 p.setWorldMatrix( mat );
401 p.setZoomFactor( 16. / 800. );
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 ) );
411 setOn( m_layer->selected() );
412 setText( 0, m_layer->name() );
415 setPixmap( 0, preview );
417 setPixmap( 1, *KarbonFactory::rServer()->cachePixmap( s, TDEIcon::Small ) );
419 setPixmap( 2, *KarbonFactory::rServer()->cachePixmap( s, TDEIcon::Small ) );
423VLayerListViewItem::stateChange(
bool on )
425 m_layer->setSelected( on );
429VLayerListViewItem::pos()
431 VLayerListViewItem* item;
432 if( !( item = (VLayerListViewItem*)itemAbove() ) )
435 return 1 + item->pos();
439VLayerListViewItem::key(
int,
bool )
const
441 return TQString(
"%1" ).arg( m_key );
445VLayerListViewItem::compare( TQListViewItem *i,
int ,
bool )
const
447 VLayerListViewItem *layerItem =
dynamic_cast<VLayerListViewItem*
>(i);
448 if( ! layerItem )
return 0;
449 return m_key < layerItem->m_key ? -1 : 1;
452VLayersTab::VLayersTab( KarbonView* view, TQWidget* parent )
453 : TQWidget( parent,
"LayersTab" ), m_view( view ), m_document( &view->part()->document() )
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 );
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 );
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* ) ) );
504VLayersTab::~VLayersTab()
509VLayersTab::slotButtonClicked(
int ID )
525VLayersTab::resetSelection()
527 TQListViewItemIterator it( m_layersListView );
531 for(; it.current(); ++it )
533 it.current()->setSelected(
false );
534 it.current()->repaint();
539VLayersTab::selectActiveLayer()
541 if( ! m_layers[ m_document->activeLayer() ] )
543 TQPtrVector<VLayer> vector;
544 m_document->layers().toVector( &vector );
546 for(
int i = vector.count() - 1; i >= 0; i-- )
549 m_document->setActiveLayer( vector[i] );
555 TQPtrDictIterator<VLayerListViewItem> it( m_layers );
556 for(; it.current(); ++it )
558 it.current()->setSelected(
false );
559 it.current()->repaint();
562 VLayerListViewItem *layerItem = m_layers[ m_document->activeLayer() ];
565 layerItem->setSelected(
true );
566 layerItem->repaint();
567 kdDebug(38000) <<
"selecting active layer: " << layerItem->text() << endl;
572VLayersTab::selectionChangedFromTool()
575 removeDeletedObjectsFromList();
578 VObjectListIterator itr = m_document->selection()->objects();
579 for( ; itr.current(); ++itr )
584 VObjectListViewItem *item = m_objects[ obj ];
587 VLayerListViewItem *layerItem = m_layers[ obj->
parent() ];
589 updateObjects( layerItem->layer(), layerItem );
592 VObjectListViewItem *objectItem = m_objects[ obj->
parent() ];
594 updateObjects( objectItem->object(), objectItem );
598 item = m_objects[ obj ];
600 if( ! item )
continue;
602 item->setSelected(
true );
609VLayersTab::updateChildItems( TQListViewItem *item )
611 TQListViewItemIterator it( item );
614 for( ++it; it.current(); ++it )
616 VObjectListViewItem *objectItem =
dynamic_cast<VObjectListViewItem *
>( it.current() );
617 if( ! objectItem )
continue;
619 if(
dynamic_cast<VGroup*
>( objectItem->object() ) )
620 updateChildItems( objectItem );
622 objectItem->update();
623 objectItem->repaint();
628VLayersTab::toggleState(
VObject *obj,
int col )
656 m_document->selection()->take( *obj );
658 m_document->selection()->append( obj );
662VLayersTab::itemClicked( TQListViewItem* item,
const TQPoint &,
int col )
666 VLayerListViewItem *layerItem =
dynamic_cast<VLayerListViewItem *
>( item );
671 m_document->setActiveLayer( layerItem->layer() );
676 toggleState( layerItem->layer(), col );
679 layerItem->repaint();
681 updateChildItems( layerItem );
683 m_view->part()->repaintAllViews();
688 VObjectListViewItem *objectItem =
dynamic_cast< VObjectListViewItem *
>( item );
692 VObject *obj = objectItem->object();
698 toggleState( objectItem->object(), col );
701 objectItem->setSelected(
true );
703 objectItem->setSelected(
false );
705 objectItem->update();
706 objectItem->repaint();
708 if(
dynamic_cast<VGroup*
>( objectItem->object() ) )
709 updateChildItems( objectItem );
711 m_view->part()->repaintAllViews();
718VLayersTab::selectionChangedFromList()
720 m_document->selection()->clear();
722 TQListViewItemIterator it( m_layersListView );
726 for(; it.current(); ++it )
728 VObjectListViewItem *objectItem =
dynamic_cast<VObjectListViewItem *
>( it.current() );
729 if( ! objectItem )
continue;
742 m_document->selection()->append( objectItem->object() );
743 objectItem->repaint();
747 m_view->selectionChanged();
748 m_view->part()->repaintAllViews();
752VLayersTab::renameItem( TQListViewItem* item,
const TQPoint&,
int col )
754 if ( ( item ) && col == 0 )
757 VLayerListViewItem* layerItem =
dynamic_cast<VLayerListViewItem *
>( item );
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 );
766 m_document->setObjectName( obj, name );
767 objectItem->update();
772 TQString name = KInputDialog::getText( i18n(
"Rename Layer" ), i18n(
"Change the name of the current layer:" ),
773 layerItem->layer()->name(), &ok,
this );
776 layerItem->layer()->setName( name );
784VLayersTab::addLayer()
787 TQString name = KInputDialog::getText( i18n(
"New Layer" ), i18n(
"Enter the name of the new layer:" ),
788 i18n(
"New layer" ), &ok,
this );
793 VLayerCmd* cmd =
new VLayerCmd( m_document, i18n(
"Add Layer" ),
794 layer, VLayerCmd::addLayer );
795 m_view->part()->addCommand( cmd,
true );
801VLayersTab::raiseItem()
805 TQListViewItemIterator it( m_layersListView );
807 if( m_document->selection()->objects().count() )
809 cmd =
new VZOrderCmd( m_document, VZOrderCmd::up );
810 m_view->part()->addCommand( cmd,
true );
814 for(; it.current(); ++it )
816 if( ! it.current()->isSelected() )
continue;
818 VLayerListViewItem* layerItem =
dynamic_cast<VLayerListViewItem *
>( it.current() );
821 VLayer *layer = layerItem->layer();
822 if( layer && m_document->canRaiseLayer( layer ) )
824 cmd =
new VLayerCmd( m_document, i18n(
"Raise Layer" ),
825 layerItem->layer(), VLayerCmd::raiseLayer );
826 m_view->part()->addCommand( cmd,
true );
832 if( cmd ) updatePreviews();
836VLayersTab::lowerItem()
839 TQListViewItemIterator it( m_layersListView );
841 if( m_document->selection()->objects().count() )
843 cmd =
new VZOrderCmd( m_document, VZOrderCmd::down );
844 m_view->part()->addCommand( cmd,
true );
848 for(; it.current(); ++it )
850 if( ! it.current()->isSelected() )
continue;
852 VLayerListViewItem* layerItem =
dynamic_cast<VLayerListViewItem *
>( it.current() );
855 VLayer *layer = layerItem->layer();
856 if( layer && m_document->canLowerLayer( layer ) )
858 cmd =
new VLayerCmd( m_document, i18n(
"Lower Layer" ), layer, VLayerCmd::lowerLayer );
859 m_view->part()->addCommand( cmd,
true );
865 if( cmd ) updatePreviews();
869VLayersTab::deleteItem()
872 TQListViewItemIterator it( m_layersListView );
874 TQPtrList<TQListViewItem> deleteItems;
875 deleteItems.setAutoDelete(
false );
879 for(; it.current(); ++it )
881 if( ! it.current()->isSelected() )
continue;
882 deleteItems.append( it.current() );
885 for( ;deleteItems.first(); )
887 VLayerListViewItem* layerItem =
dynamic_cast< VLayerListViewItem *
>( deleteItems.current() );
890 VLayer *layer = layerItem->layer();
891 if( layer && m_layers.count() > 1 )
893 cmd =
new VLayerCmd( m_document, i18n(
"Delete Layer" ), layer, VLayerCmd::deleteLayer );
895 VObjectListIterator itr = layer->
objects();
898 for( ; itr.current(); ++itr )
900 VObjectListViewItem *objectItem = m_objects.take( itr.current() );
901 deleteItems.remove( objectItem );
906 m_view->part()->addCommand( cmd );
913 VObjectListViewItem* item =
dynamic_cast< VObjectListViewItem *
>( deleteItems.current() );
916 cmd =
new VDeleteCmd( m_document, item->object() );
920 m_view->part()->addCommand( cmd );
924 deleteItems.removeFirst();
929 m_view->part()->repaintAllViews();
934VLayersTab::updatePreviews()
941VLayersTab::updateLayers()
943 removeDeletedObjectsFromList();
945 TQPtrVector<VLayer> vector;
946 m_document->layers().toVector( &vector );
947 VLayerListViewItem* item = 0L;
948 for(
int i = vector.count() - 1; i >= 0; i-- )
952 if( !m_layers[ vector[i] ] )
954 item =
new VLayerListViewItem( m_layersListView, vector[i], m_document, &m_layers );
955 item->setOpen(
true );
958 item = m_layers[ vector[i] ];
962 updateObjects( vector[i], item );
967 m_layersListView->sort();
971VLayersTab::updateObjects(
VObject *
object, TQListViewItem *item )
973 VObjectListIterator itr =
dynamic_cast<VGroup *
>( object )->objects();
975 for( uint objcount = 1; itr.current(); ++itr, objcount++ )
978 VObjectListViewItem *objectItem = m_objects[ itr.current() ];
982 objectItem =
new VObjectListViewItem( item, itr.current(), m_document, objcount, &m_objects );
983 objectItem->update();
985 else if( objectItem->parent() != item )
988 objectItem->parent()->takeItem( objectItem );
989 item->insertItem( objectItem );
992 objectItem->setKey( objcount );
994 if(
dynamic_cast<VGroup *
>( itr.current() ) )
995 updateObjects( itr.current(), objectItem );
1002VLayersTab::removeDeletedObjectsFromList()
1004 TQPtrDictIterator<VObjectListViewItem> it( m_objects );
1010 for(; it.current(); )
1012 VLayerListViewItem *layerItem =
dynamic_cast<VLayerListViewItem*
>( it.current()->parent() );
1015 VGroup *group =
dynamic_cast<VGroup*
>( layerItem->layer() );
1017 if( group && ! group->
objects().contains( it.current()->object() ) )
1019 layerItem->takeItem( it.current() );
1020 delete it.current();
1026 VObjectListViewItem *objectItem =
dynamic_cast<VObjectListViewItem*
>( it.current()->parent() );
1029 VGroup *group =
dynamic_cast<VGroup*
>( objectItem->object() );
1031 if( group && ! group->
objects().contains( it.current()->object() ) )
1033 objectItem->takeItem( it.current() );
1034 delete it.current();
1040 delete it.current();
1047 delete it.current();
1054 TQPtrDictIterator<VLayerListViewItem> itr( m_layers );
1059 for(; itr.current(); )
1063 m_layersListView->takeItem( itr.current() );
1064 delete itr.current();
1073VLayersTab::slotCommandExecuted(
VCommand* command )
1076 if(
dynamic_cast<VLayerCmd*
>( command )
1078 ||
dynamic_cast<VGroupCmd*
>( command )
1079 ||
dynamic_cast<VUnGroupCmd*
>( command )
1088VHistoryGroupItem::VHistoryGroupItem( VHistoryItem* item, TQListView* parent, TQListViewItem* after )
1089 : TQListViewItem( parent, after )
1091 setPixmap( 0, *item->pixmap( 0 ) );
1092 setText( 0, item->text( 0 ) );
1093 parent->takeItem( item );
1095 m_key = item->key( 0,
true );
1098VHistoryGroupItem::~VHistoryGroupItem()
1103VHistoryGroupItem::paintCell( TQPainter* p,
const TQColorGroup& cg,
int column,
int width,
int align )
1107 VHistoryItem* item = (VHistoryItem*)firstChild();
1110 if ( item->command()->success() )
1114 item = (VHistoryItem*)item->nextSibling();
1118 p->fillRect( 0, 0, width, height(), cg.base() );
1120 p->fillRect( 0, 0, width, height(), TQBrush( cg.base().dark( 140 ), TQBrush::BDiagPattern ) );
1123 p->fillRect( 0, 0, width, height(), cg.base().dark( 140 ) );
1125 const TQPixmap* pixmap = this->pixmap( column );
1129 int pw = pixmap->width();
1130 int ph = pixmap->height();
1131 p->drawPixmap( ( height() - pw ) / 2, ( height() - ph ) / 2, *pixmap );
1136 p->setPen( cg.text() );
1137 p->drawText( xstart, 0, width - xstart, height(), align | TQt::AlignVCenter, text( column ) );
1141VHistoryGroupItem::paintFocus( TQPainter*,
const TQColorGroup&,
const TQRect& )
1148VHistoryItem::VHistoryItem(
VCommand* command, TQListView* parent, TQListViewItem* after )
1149 : TQListViewItem( parent, after ), m_command( command )
1154VHistoryItem::VHistoryItem(
VCommand* command, VHistoryGroupItem* parent, TQListViewItem* after )
1155 : TQListViewItem( parent, after ), m_command( command )
1163 kdDebug(38000) <<
"In VHistoryItem::init() : " << m_command->name() << endl;
1165 sprintf( buffer,
"%064ld", ++g_lastKey );
1167 setPixmap( 0, TQPixmap( TDEGlobal::iconLoader()->iconPath( m_command->icon(), TDEIcon::Small ) ) );
1168 setText( 0, m_command->name() );
1171VHistoryItem::~VHistoryItem()
1176VHistoryItem::paintCell( TQPainter* p,
const TQColorGroup& cg,
int column,
int width,
int align )
1178 p->fillRect( 0, 0, width, height(), ( m_command->success() ? cg.base() : TQColor(cg.base().dark( 140 )) ) );
1180 const TQPixmap* pixmap = this->pixmap( column );
1184 int pw = pixmap->width();
1185 int ph = pixmap->height();
1186 p->drawPixmap( ( height() - pw ) / 2, ( height() - ph ) / 2, *pixmap );
1191 p->setPen( cg.text() );
1192 p->drawText( xstart, 0, width - xstart, height(), align | TQt::AlignVCenter, text( column ) );
1196VHistoryItem::paintFocus( TQPainter*,
const TQColorGroup&,
const TQRect& )
1203VHistoryTab::VHistoryTab(
KarbonPart* part, TQWidget* parent )
1204 : TQWidget( parent ), m_part( part )
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 ) );
1217 m_history->setSorting( 0,
true );
1218 VHistoryGroupItem* group = 0;
1219 VHistoryItem* last = 0;
1220 TQPtrVector<VCommand> cmds;
1222 int c = cmds.count();
1223 for (
int i = 0; i < c; i++ )
1225 if ( ( i > 0 ) && ( cmds[ i ]->name() == cmds[ i - 1 ]->name() ) )
1228 TQListViewItem* prev = group->firstChild();
1229 while ( prev && prev->nextSibling() )
1230 prev = prev->nextSibling();
1231 new VHistoryItem( cmds[ i ], group, prev );
1235 group =
new VHistoryGroupItem( last, m_history, last );
1236 new VHistoryItem( cmds[ i ], group, last );
1240 last =
new VHistoryItem( cmds[ i ], m_history, last );
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() ) );
1251 connect( part->
commandHistory(), TQ_SIGNAL( firstCommandRemoved() ),
this, TQ_SLOT( removeFirstCommand() ) );
1252 connect( part->
commandHistory(), TQ_SIGNAL( lastCommandRemoved() ),
this, TQ_SLOT( removeLastCommand() ) );
1259VHistoryTab::~VHistoryTab()
1264VHistoryTab::groupingEnabled()
1266 return m_groupCommands->isChecked();
1270VHistoryTab::historyCleared()
1276VHistoryTab::commandExecuted(
VCommand* command )
1278 TQListViewItem* item = m_history->firstChild();
1280 while ( !found && item )
1282 if ( item->rtti() == 1001 )
1284 TQListViewItem* child = item->firstChild();
1285 while ( !found && child )
1287 found = ( ( (VHistoryItem*)child )->command() == command );
1289 child = child->nextSibling();
1294 found = ( item && ( (VHistoryItem*)item )->command() == command );
1296 item = item->nextSibling();
1300 m_history->repaintItem( item );
1301 if ( item->parent() )
1302 m_history->repaintItem( item->parent() );
1303 m_history->ensureItemVisible( item );
1308VHistoryTab::slotCommandAdded(
VCommand* command )
1313 TQListViewItem* last = m_history->firstChild();
1314 while ( last && last->nextSibling() )
1315 last = last->nextSibling();
1317 if( groupingEnabled() )
1319 if( ( last ) && last->text( 0 ) == command->
name() )
1321 if( last->rtti() == 1002 )
1323 TQListViewItem* prevSibling;
1324 if( m_history->childCount() > 1 )
1326 prevSibling = m_history->firstChild();
1327 while ( prevSibling->nextSibling() != last )
1328 prevSibling = prevSibling->nextSibling();
1331 prevSibling = m_history->firstChild();
1332 last =
new VHistoryGroupItem( (VHistoryItem*)last, m_history, prevSibling );
1334 TQListViewItem* prev = last->firstChild();
1335 while ( prev && prev->nextSibling() )
1336 prev = prev->nextSibling();
1337 m_history->setCurrentItem(
new VHistoryItem( command, (VHistoryGroupItem*)last, prev ) );
1340 m_history->setCurrentItem(
new VHistoryItem( command, m_history, last ) );
1343 m_history->setCurrentItem(
new VHistoryItem( command, m_history, last ) );
1346 m_history->ensureItemVisible( m_history->currentItem() );
1347 m_history->update();
1351VHistoryTab::removeFirstCommand()
1353 if ( m_history->childCount() > 0 )
1354 if ( m_history->firstChild()->rtti() == 1002 )
1355 delete m_history->firstChild();
1358 VHistoryGroupItem* group = (VHistoryGroupItem*)m_history->firstChild();
1359 delete group->firstChild();
1360 if ( group->childCount() == 1 )
1362 new VHistoryItem( ( (VHistoryItem*)group->firstChild() )->command(), m_history, 0 );
1369VHistoryTab::removeLastCommand()
1371 if ( m_history->childCount() > 0 )
1373 TQListViewItem* last = m_history->firstChild();
1374 while ( last && last->nextSibling() )
1375 last = last->nextSibling();
1376 if ( last->rtti() == 1002 )
1380 VHistoryGroupItem* group = (VHistoryGroupItem*)last;
1381 last = group->firstChild();
1382 while ( last && last->nextSibling() )
1383 last = last->nextSibling();
1385 if ( group->childCount() == 1 )
1387 new VHistoryItem( ( (VHistoryItem*)group->firstChild() )->command(), m_history, group );
1395VHistoryTab::commandClicked(
int button, TQListViewItem* item,
const TQPoint&,
int )
1397 if ( !item || item->rtti() == 1001 )
1400 VCommand* cmd = ( (VHistoryItem*)item )->command();
1403 emit undoCommandsTo( ( (VHistoryItem*)item )->command() );
1405 emit undoCommand( ( (VHistoryItem*)item )->command() );
1408 emit redoCommandsTo( ( (VHistoryItem*)item )->command() );
1410 emit redoCommand( ( (VHistoryItem*)item )->command() );
1414VHistoryTab::groupingChanged(
int )
1416 if ( m_groupCommands->isChecked() && m_history->childCount() > 1 )
1418 TQListViewItem* s2last = 0;
1419 TQListViewItem* last = m_history->firstChild();
1420 TQListViewItem* item = last->nextSibling();
1422 if ( last->text( 0 ) == item->text( 0 ) )
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();
1434 item = last->nextSibling();
1439 TQListViewItem* item = m_history->firstChild();
1441 if ( item->rtti() == 1001 )
1443 TQListViewItem* child;
1444 while ( ( child = item->firstChild() ) )
1446 item->takeItem( child );
1447 m_history->insertItem( child );
1450 item = item->nextSibling();
1454 item = item->nextSibling();
1457 m_history->update();
1460#include "vdocumentdocker.moc"
Keeps track of visual per document properties.
VCommandHistory * commandHistory()
access the command history:
This class keeps track of color properties.
const TQPtrList< VCommand > * commands() const
Read only access to the command history list.
The base class for all karbon commands.
TQString name() const
Returns the name of the command.
A class to provide undo/redoable deletion of VObjects.
All non-visual, static doc info is in here.
Base class for all sort of VObject conglomerats.
const VObjectList & objects() const
Read only access to the grouped objects.
VLayer manages a set of vobjects.
The base class for all karbon objects.
virtual void setState(const VState state)
Sets the state to a specified new state.
VObject * parent() const
Returns pointer to current parent object.
@ normal_locked
visible, but locked (r/o)
@ hidden_locked
hidden and locked (r/o)
@ selected
visible, active and can be manipulated by tools
@ deleted
deleted, nearly dead
@ normal
visible, not active
virtual TQString name() const
Returns the name of the object.
void setName(const TQString &s)
Sets the object's name to a given new name.
VState state() const
Get the state the object is in.
This visitors visits structures and tries to capture relevant object type info as text.
Manages stroke properties.
bool success() const
Return if the operation was a success or not.
virtual bool visit(VObject &object)
General visit method.
Command that changes the z-order of the selection within a layer to front, back, one step up,...