1
/* This file is part of the KDE project
2
Copyright (C) 2001, 2002, 2003 The Karbon Developers
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.
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.
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., 59 Temple Place - Suite 330,
17
Boston, MA 02111-1307, USA.
20
#include <qhbuttongroup.h>
21
#include <qinputdialog.h>
23
#include <qcheckbox.h>
24
#include <qlistview.h>
25
#include <qptrvector.h>
26
#include <qtoolbutton.h>
28
#include <qtabwidget.h>
34
#include <koMainWindow.h>
36
#include <kiconloader.h>
37
#include <klineeditdlg.h>
39
#include "karbon_part.h"
40
#include "karbon_view.h"
41
#include "karbon_factory.h"
42
#include "karbon_resourceserver.h"
43
#include "vdocument.h"
44
#include "vkopainter.h"
46
#include "vlayercmd.h"
47
#include "vdeletecmd.h"
48
#include "vzordercmd.h"
49
#include "vselection.h"
52
#include "vdocumentdocker.h"
53
#include <visitors/vselectiondesc.h>
55
static long g_lastKey = 0;
57
/*************************************************************************
59
*************************************************************************/
61
VDocumentPreview::VDocumentPreview( KarbonView* view, QWidget* parent )
62
: QWidget( parent, "DocumentPreview" ), m_document( &view->part()->document() ), m_view( view )
65
installEventFilter( this );
66
setBackgroundMode( Qt::NoBackground );
67
setMouseTracking( true );
70
} // VDocumentPreview::VDocumentPreview
72
VDocumentPreview::~VDocumentPreview()
75
} // VDocumentPreview::~VDocumentPreview
78
VDocumentPreview::reset()
85
VDocumentPreview::eventFilter( QObject* object, QEvent* event )
90
if ( ( height() - 4 ) / m_document->height() > ( width() - 4 ) / m_document->width() )
92
scaleFactor = ( width() - 4 ) / m_document->width();
93
yoffset = ( ( height() - 4 ) / scaleFactor - m_document->height() ) / 2;
97
scaleFactor = ( height() - 4 ) / m_document->height();
98
xoffset = ( ( width() - 4 ) / scaleFactor - m_document->width() ) / 2;
100
KoRect rect = m_view->canvasWidget()->boundingBox();
102
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>( event );
103
if( event->type() == QEvent::MouseButtonPress )
105
m_firstPoint.setX( mouseEvent->pos().x() );
106
m_firstPoint.setY( mouseEvent->pos().y() );
107
m_lastPoint = m_firstPoint;
108
KoPoint p3( m_firstPoint.x() / scaleFactor - xoffset,
109
( height() - m_firstPoint.y() ) / scaleFactor - yoffset );
110
m_dragging = rect.contains( p3 );
112
else if( event->type() == QEvent::MouseButtonRelease )
116
m_lastPoint.setX( mouseEvent->pos().x() );
117
m_lastPoint.setY( mouseEvent->pos().y() );
118
double dx = m_lastPoint.x() - m_firstPoint.x();
119
double dy = m_lastPoint.y() - m_firstPoint.y();
120
scaleFactor /= m_view->zoom();
121
m_view->canvasWidget()->scrollBy( int( dx / scaleFactor ), int( dy / scaleFactor ) );
122
m_firstPoint = m_lastPoint;
127
else if( event->type() == QEvent::MouseMove )
131
m_lastPoint.setX( mouseEvent->pos().x() );
132
m_lastPoint.setY( mouseEvent->pos().y() );
134
/*double dx = m_lastPoint.x() - m_firstPoint.x();
135
double dy = m_lastPoint.y() - m_firstPoint.y();
136
scaleFactor /= m_view->zoom();
137
m_view->canvasWidget()->scrollBy( int( dx / scaleFactor ), int( dy / scaleFactor ) );
138
m_firstPoint = m_lastPoint;*/
142
KoPoint p3( mouseEvent->pos().x() / scaleFactor - xoffset,
143
( height() - mouseEvent->pos().y() ) / scaleFactor - yoffset );
144
setCursor( rect.contains( p3 ) ? QCursor::SizeAllCursor : QCursor( Qt::arrowCursor ) );
148
return QWidget::eventFilter( object, event );
152
VDocumentPreview::paintEvent( QPaintEvent* )
154
// TODO : use NotROP, otherwise too slow
155
QPixmap pixmap( width(), height() );
159
if ( ( height() - 4 ) / m_document->height() > ( width() - 4 ) / m_document->width() )
161
scaleFactor = ( width() - 4 ) / m_document->width();
162
yoffset = ( ( height() - 4 ) / scaleFactor - m_document->height() ) / 2;
166
scaleFactor = ( height() - 4 ) / m_document->height();
167
xoffset = ( ( width() - 4 ) / scaleFactor - m_document->width() ) / 2;
169
xoffset += 2 / scaleFactor;
170
yoffset += 2 / scaleFactor;
171
if( !m_docpixmap || m_docpixmap->width() != width() || m_docpixmap->height() != height() )
174
m_docpixmap = new QPixmap( width(), height() );
175
VKoPainter p( m_docpixmap, width(), height() );
176
p.clear( QColor( 195, 194, 193 ) );
177
p.setWorldMatrix( QWMatrix( 1, 0, 0, -1, xoffset * scaleFactor, height() - yoffset * scaleFactor ) );
178
p.setZoomFactor( scaleFactor );
179
KoRect rect( -xoffset, -yoffset, m_document->width() + xoffset, m_document->height() + yoffset );
181
VColor c( Qt::black );
182
VStroke stroke( c, 0L, 1.0 / scaleFactor );
184
p.setBrush( Qt::white );
185
p.drawRect( KoRect( 2, 2, m_document->width() - 2, m_document->height() - 2 ) );
186
m_document->draw( &p, &rect );
189
bitBlt( &pixmap, 0, 0, m_docpixmap, 0, 0, width(), height() );
191
// draw viewport rect
193
QPainter p( &pixmap );
194
p.setWorldMatrix( QWMatrix( scaleFactor, 0, 0, -scaleFactor, xoffset * scaleFactor, height() - yoffset * scaleFactor ) );
196
double dx = ( m_lastPoint.x() - m_firstPoint.x() ) * m_view->zoom();
197
double dy = ( m_lastPoint.y() - m_firstPoint.y() ) * m_view->zoom();
198
KoPoint p1( dx / scaleFactor, dy / scaleFactor );
199
p1 = m_view->canvasWidget()->toContents( p1 );
200
KoPoint p2( dx / scaleFactor + m_view->canvasWidget()->width(), dy / scaleFactor + m_view->canvasWidget()->height() );
201
p2 = m_view->canvasWidget()->toContents( p2 );
202
p.drawRect( int( p1.x() ), int( p1.y() ), int( p2.x() - p1.x() ), int( p2.y() - p1.y() ) );
205
QPainter pw( &pixmap );
206
pw.setPen( colorGroup().light() );
207
pw.drawLine( 1, 1, 1, height() - 2 );
208
pw.drawLine( 1, 1, width() - 2, 1 );
209
pw.drawLine( width() - 1, height() - 1, 0, height() - 1 );
210
pw.drawLine( width() - 1, height() - 1, width() - 1, 0 );
211
pw.setPen( colorGroup().dark() );
212
pw.drawLine( 0, 0, width() - 1, 0 );
213
pw.drawLine( 0, 0, 0, height() - 1 );
214
pw.drawLine( width() - 2, height() - 2, width() - 2, 1 );
215
pw.drawLine( width() - 2, height() - 2, 1, height() - 2 );
217
bitBlt( this, 0, 0, &pixmap, 0, 0, width(), height() );
218
} // VDocumentPreview::paintEvent
220
VDocumentTab::VDocumentTab( KarbonView* view, QWidget* parent )
221
: QWidget( parent, "DocumentTab" ), m_view( view )
224
QGridLayout* layout = new QGridLayout( this );
225
layout->setMargin( 3 );
226
layout->setSpacing( 2 );
227
layout->addMultiCellWidget( m_documentPreview = new VDocumentPreview( m_view, this ), 0, 7, 2, 2 );
228
layout->addWidget( new QLabel( i18n( "Width:" ), this ), 0, 0 );
229
layout->addWidget( new QLabel( i18n( "Height:" ), this ), 1, 0 );
230
layout->addMultiCellWidget( frame = new QFrame( this ), 2, 2, 0, 1 );
231
frame->setFrameShape( QFrame::HLine );
232
layout->addWidget( new QLabel( i18n( "Layers:" ), this ), 3, 0 );
233
layout->addWidget( new QLabel( i18n( "Format:" ), this ), 4, 0 );
234
layout->addMultiCellWidget( frame = new QFrame( this ), 5, 5, 0, 1 );
235
frame->setFrameShape( QFrame::HLine );
236
//layout->addMultiCellWidget( new QLabel( i18n( "Zoom factor:" ), this ), 6, 6, 0, 1 );
237
layout->addWidget( m_width = new QLabel( this ), 0, 1 );
238
layout->addWidget( m_height = new QLabel( this ), 1, 1 );
239
layout->addWidget( m_layers = new QLabel( this ), 3, 1 );
240
layout->addWidget( m_format = new QLabel( this ), 4, 1 );
241
layout->setRowStretch( 7, 1 );
242
layout->setColStretch( 0, 0 );
243
layout->setColStretch( 1, 0 );
244
layout->setColStretch( 2, 2 );
247
m_width->setAlignment( AlignRight );
248
m_height->setAlignment( AlignRight );
249
m_layers->setAlignment( AlignRight );
250
m_format->setAlignment( AlignRight );
252
connect( view->part()->commandHistory(), SIGNAL( commandAdded( VCommand* ) ), this, SLOT( slotCommandAdded( VCommand* ) ) );
253
connect( view->part()->commandHistory(), SIGNAL( commandExecuted() ), this, SLOT( slotCommandExecuted() ) );
254
connect( view, SIGNAL( pageLayoutChanged() ), this, SLOT( slotCommandExecuted() ) );
255
connect( view->canvasWidget(), SIGNAL( viewportChanged() ), this, SLOT( slotViewportChanged() ) );
257
updateDocumentInfo();
258
} // VDocumentTab::VDocumentTab
260
VDocumentTab::~VDocumentTab()
262
} // VDocumentTab::~VDocumentTab
265
VDocumentTab::updateDocumentInfo()
267
m_width->setText( KoUnit::userValue( m_view->part()->document().width(), m_view->part()->unit() ) + m_view->part()->unitName() );
268
m_height->setText( KoUnit::userValue( m_view->part()->document().height(), m_view->part()->unit() ) + m_view->part()->unitName() );
269
m_layers->setText( QString::number( m_view->part()->document().layers().count() ) );
270
} // VDocumentTab::updateDocumentInfo
273
VDocumentTab::slotCommandAdded( VCommand * )
275
m_documentPreview->reset();
276
m_documentPreview->update();
280
VDocumentTab::slotZoomChanged( double )
282
m_documentPreview->update();
286
VDocumentTab::slotViewportChanged()
288
m_documentPreview->update();
289
updateDocumentInfo();
293
VDocumentTab::slotCommandExecuted()
295
m_documentPreview->reset();
296
m_documentPreview->update();
299
/*************************************************************************
301
*************************************************************************/
303
VObjectListViewItem::VObjectListViewItem( QListViewItem* parent, VObject* object, VDocument *doc, uint key )
304
: QListViewItem( parent, 0L ), m_object( object ), m_document( doc ), m_key( key )
310
VObjectListViewItem::key( int, bool ) const
312
return QString( "%1" ).arg( m_key );
316
VObjectListViewItem::update()
319
VSelectionDescription selectionDesc;
320
selectionDesc.visit( *m_object );
321
setText( 0, QString( "%1" ).arg( selectionDesc.shortDescription() ) );
323
// draw thumb preview (16x16)
325
preview.resize( 16, 16 );
326
VKoPainter p( &preview, 16, 16, false );
330
KoRect bbox = m_object->boundingBox();
331
mat.translate( 0, -16 );
332
double factor = 16. / kMax( bbox.width(), bbox.height() );
333
mat.translate( -bbox.x() * factor, -bbox.y() * factor );
334
p.setWorldMatrix( mat );
336
// TODO: When the document will support page size, change the following line.
337
p.setZoomFactor( factor );
338
m_object->draw( &p );
339
p.setZoomFactor( 1 );
340
p.setWorldMatrix( QWMatrix() );
341
p.setPen( Qt::black );
342
p.setBrush( Qt::NoBrush );
343
p.drawRect( KoRect( 0, 0, 16, 16 ) );
346
// set thumb preview, lock and visible pixmaps
347
setPixmap( 0, preview );
348
QString s = ( m_object->state() == VObject::normal_locked || m_object->state() == VObject::hidden_locked ) ? "locked.png" : "unlocked.png";
349
setPixmap( 1, *KarbonFactory::rServer()->cachePixmap( s, KIcon::Small ) );
350
s = ( m_object->state() == VObject::hidden || m_object->state() == VObject::hidden_locked ) ? "14_layer_novisible.png" : "14_layer_visible.png";
351
setPixmap( 2, *KarbonFactory::rServer()->cachePixmap( s, KIcon::Small ) );
355
VLayerListViewItem::VLayerListViewItem( QListView* parent, VLayer* layer, VDocument *doc )
356
: QCheckListItem( parent, 0L, CheckBox ), m_layer( layer ), m_document( doc)
359
} // VLayerListViewItem::VLayerListViewItem
362
VLayerListViewItem::update()
364
// draw thumb preview (16x16)
366
preview.resize( 16, 16 );
367
VKoPainter p( &preview, 16, 16, false );
371
mat.translate( 0, -16 );
372
p.setWorldMatrix( mat );
374
// TODO: When the document will support page size, change the following line.
375
p.setZoomFactor( 16. / 800. );
377
p.setZoomFactor( 1 );
378
p.setWorldMatrix( QWMatrix() );
379
p.setPen( Qt::black );
380
p.setBrush( Qt::NoBrush );
381
p.drawRect( KoRect( 0, 0, 16, 16 ) );
385
setOn( m_layer->selected() );
386
setText( 0, m_layer->name() );
388
// set thumb preview, lock and visible pixmaps
389
setPixmap( 0, preview );
390
QString s = ( m_layer->state() == VObject::normal_locked || m_layer->state() == VObject::hidden_locked ) ? "locked.png" : "unlocked.png";
391
setPixmap( 1, *KarbonFactory::rServer()->cachePixmap( s, KIcon::Small ) );
392
s = ( m_layer->state() == VObject::normal || m_layer->state() == VObject::normal_locked ) ? "14_layer_visible.png" : "14_layer_novisible.png";
393
setPixmap( 2, *KarbonFactory::rServer()->cachePixmap( s, KIcon::Small ) );
394
} // VLayerListViewItem::update
397
VLayerListViewItem::stateChange( bool on )
399
m_layer->setSelected( on );
400
} // VLayerListViewItem::stateChange
403
VLayerListViewItem::pos()
405
VLayerListViewItem* item;
406
if( !( item = (VLayerListViewItem*)itemAbove() ) )
409
return 1 + item->pos();
410
} // VLayerListViewItem::pos
412
VLayersTab::VLayersTab( KarbonView* view, QWidget* parent )
413
: QWidget( parent, "LayersTab" ), m_view( view ), m_document( &view->part()->document() )
417
QVBoxLayout* layout = new QVBoxLayout( this, 1 );
418
layout->addWidget( m_layersListView = new QListView( this ), 0 );
419
m_buttonGroup = new QHButtonGroup( this );
420
m_buttonGroup->setInsideMargin( 3 );
421
button = new QToolButton( m_buttonGroup );
422
button->setIconSet( SmallIcon( "14_layer_newlayer.png" ) );
423
button->setTextLabel( i18n( "New" ) );
424
m_buttonGroup->insert( button );
425
button = new QToolButton( m_buttonGroup );
426
button->setIconSet( SmallIcon( "14_layer_raiselayer.png" ) );
427
button->setTextLabel( i18n( "Raise" ) );
428
m_buttonGroup->insert( button );
429
button = new QToolButton( m_buttonGroup );
430
button->setIconSet( SmallIcon( "14_layer_lowerlayer.png" ) );
431
button->setTextLabel( i18n( "Lower" ) );
432
m_buttonGroup->insert( button );
433
button = new QToolButton( m_buttonGroup );
434
button->setIconSet( SmallIcon( "14_layer_deletelayer.png" ) );
435
button->setTextLabel( i18n( "Delete" ) );
436
m_buttonGroup->insert( button );
437
layout->addWidget( m_buttonGroup, 1);
438
layout->setSpacing( 0 );
439
layout->setMargin( 3 );
441
m_layersListView->setAllColumnsShowFocus( true );
442
m_layersListView->addColumn( i18n( "Item" ), 120 );
443
m_layersListView->addColumn( i18n( "L" ), 20 );
444
m_layersListView->addColumn( i18n( "V" ), 20 );
445
m_layersListView->setColumnWidthMode( 0, QListView::Maximum );
446
m_layersListView->setColumnAlignment( 1, Qt::AlignCenter );
447
m_layersListView->setColumnAlignment( 2, Qt::AlignCenter );
448
m_layersListView->setResizeMode( QListView::NoColumn );
449
//m_layersListView->setSorting( 0, false );
450
m_layersListView->setRootIsDecorated( true );
452
connect( m_layersListView, SIGNAL( clicked( QListViewItem*, const QPoint&, int ) ), this, SLOT( selectionChanged( QListViewItem*, const QPoint&, int ) ) );
453
connect( m_layersListView, SIGNAL( rightButtonClicked( QListViewItem*, const QPoint&, int ) ), this, SLOT( renameItem( QListViewItem*, const QPoint&, int ) ) );
454
connect( m_view, SIGNAL( selectionChange() ), this, SLOT( slotSelectionChanged() ) );
455
connect( m_buttonGroup, SIGNAL( clicked( int ) ), this, SLOT( slotButtonClicked( int ) ) );
459
} // VLayersTab::VLayersTab
461
VLayersTab::~VLayersTab()
463
} // VLayersTab::~VLayersTab
466
VLayersTab::slotButtonClicked( int ID )
479
} // VLayersTab::slotButtonClicked
482
VLayersTab::slotSelectionChanged()
484
// TODO : use some kind of mapping...
485
m_layersListView->clearSelection();
486
VObjectListIterator itr = m_document->selection()->objects();
487
for( ; itr.current();++itr )
488
if( itr.current()->state() != VObject::deleted )
490
QListViewItemIterator it( m_layersListView );
492
while( !found && dynamic_cast<VObjectListViewItem *>( it.current() ) )
494
if( dynamic_cast<VObjectListViewItem *>( it.current() ) &&
495
dynamic_cast<VObjectListViewItem *>( it.current() )->object() == itr.current() )
497
m_layersListView->setSelected( it.current(), true );
505
VLayerListViewItem *layerItem = dynamic_cast<VLayerListViewItem *>( m_layers[ m_document->activeLayer() ] );
506
if( layerItem && !m_objects[ itr.current() ] )
507
m_objects.insert( itr.current(), new VObjectListViewItem( layerItem, itr.current(), m_document, layerItem->childCount() ) );
514
VLayersTab::selectionChanged( QListViewItem* item, const QPoint &, int col )
518
VLayerListViewItem *layerItem = dynamic_cast<VLayerListViewItem *>( item );
521
VLayer *obj = layerItem->layer();
522
m_document->setActiveLayer( layerItem->layer() );
523
m_document->selection()->clear();
528
obj->setState( obj->state() == VObject::normal || obj->state() == VObject::normal_locked ? VObject::hidden : VObject::normal );
530
if( obj->state() == VObject::hidden_locked )
531
obj->setState( VObject::hidden );
532
else if( obj->state() == VObject::normal_locked )
533
obj->setState( VObject::normal );
534
else if( obj->state() == VObject::normal )
535
obj->setState( VObject::normal_locked );
536
else if( obj->state() == VObject::hidden )
537
obj->setState( VObject::hidden_locked );
539
m_view->part()->repaintAllViews();
544
VObjectListViewItem *objectItem = dynamic_cast< VObjectListViewItem *>( m_layersListView->selectedItem() );
545
VObject *obj = objectItem->object();
547
if( col > 0 ) // set visibility
550
obj->setState( obj->state() == VObject::hidden ? VObject::normal : VObject::hidden );
552
if( obj->state() == VObject::hidden_locked )
553
obj->setState( VObject::hidden );
554
else if( obj->state() == VObject::normal_locked )
555
obj->setState( VObject::normal );
556
else if( obj->state() == VObject::normal || obj->state() >= VObject::selected )
557
obj->setState( VObject::normal_locked );
558
else if( obj->state() == VObject::hidden )
559
obj->setState( VObject::hidden_locked );
560
objectItem->update();
561
m_document->selection()->take( *obj );
562
m_view->part()->repaintAllViews();
564
else if( obj->state() == VObject::normal ||
565
obj->state() >= VObject::selected ) // select only visible and unlocked objects
567
m_document->selection()->clear();
568
m_document->selection()->append( obj );
569
m_view->part()->repaintAllViews();
573
} // VLayersTab::selectionChanged
576
VLayersTab::renameItem( QListViewItem* item, const QPoint&, int col )
578
if ( ( item ) && col == 0 )
581
VLayerListViewItem* layerItem = dynamic_cast<VLayerListViewItem *>( m_layersListView->selectedItem() );
584
VObjectListViewItem *objectItem = dynamic_cast< VObjectListViewItem *>( m_layersListView->selectedItem() );
585
VObject *obj = objectItem->object();
586
QString name = KLineEditDlg::getText( i18n( "Current Object" ), i18n( "Change the name of the object:" ),
587
obj->name(), &ok, this );
590
m_document->setObjectName( obj, name );
591
objectItem->update();
596
QString name = KLineEditDlg::getText( i18n( "Rename Layer" ), i18n( "Change the name of the current layer:" ),
597
layerItem->layer()->name(), &ok, this );
600
layerItem->layer()->setName( name );
605
} // VLayersTab::renameItem
608
VLayersTab::addLayer()
611
QString name = KLineEditDlg::getText( i18n( "New Layer" ), i18n( "Enter the name of the new layer:" ),
612
i18n( "New layer" ), &ok, this );
615
VLayer* layer = new VLayer( m_document );
616
layer->setName( name );
617
VLayerCmd* cmd = new VLayerCmd( m_document, i18n( "Add Layer" ),
618
layer, VLayerCmd::addLayer );
619
m_view->part()->addCommand( cmd, true );
622
} // VLayersTab::addLayer
625
VLayersTab::raiseItem()
628
//QListViewItem *newselection = 0L;
629
VLayerListViewItem* layerItem = dynamic_cast<VLayerListViewItem *>( m_layersListView->selectedItem() );
632
VLayer *layer = layerItem->layer();
633
if( layer && m_document->canRaiseLayer( layer ) )
635
cmd = new VLayerCmd( m_document, i18n( "Raise Layer" ),
636
layerItem->layer(), VLayerCmd::raiseLayer );
637
//newselection = layerItem;
642
VObjectListViewItem* item = dynamic_cast< VObjectListViewItem *>( m_layersListView->selectedItem() );
645
cmd = new VZOrderCmd( m_document, item->object(), VZOrderCmd::up );
646
//newselection = item;
651
m_view->part()->addCommand( cmd, true );
654
// m_layersListView->setSelected( newselection, true );
656
} // VLayersTab::raiseItem
659
VLayersTab::lowerItem()
662
VLayerListViewItem* layerItem = dynamic_cast<VLayerListViewItem *>( m_layersListView->selectedItem() );
665
VLayer *layer = layerItem->layer();
666
if( layer && m_document->canLowerLayer( layer ) )
667
cmd = new VLayerCmd( m_document, i18n( "Lower Layer" ), layer, VLayerCmd::lowerLayer );
671
VObjectListViewItem* item = dynamic_cast< VObjectListViewItem *>( m_layersListView->selectedItem() );
673
cmd = new VZOrderCmd( m_document, item->object(), VZOrderCmd::down );
677
m_view->part()->addCommand( cmd, true );
680
} // VLayersTab::lowerItem
683
VLayersTab::deleteItem()
686
VLayerListViewItem* layerItem = dynamic_cast< VLayerListViewItem *>( m_layersListView->selectedItem() );
689
VLayer *layer = layerItem->layer();
692
cmd = new VLayerCmd( m_document, i18n( "Delete Layer" ), layer, VLayerCmd::deleteLayer );
693
m_view->part()->addCommand( cmd, true );
699
VObjectListViewItem* item = dynamic_cast< VObjectListViewItem *>( m_layersListView->selectedItem() );
702
cmd = new VDeleteCmd( m_document, item->object() );
703
m_view->part()->addCommand( cmd, true );
707
} // VLayersTab::deleteItem
710
VLayersTab::updatePreviews()
712
// TODO: Optimization: call update() on each view item...
714
} // VLayersTab::updatePreviews
717
VLayersTab::updateLayers()
719
QPtrVector<VLayer> vector;
720
m_document->layers().toVector( &vector );
721
VLayerListViewItem* item;
722
for( int i = vector.count() - 1; i >= 0; i-- )
724
if ( vector[i]->state() != VObject::deleted )
726
if( !m_layers[ vector[i] ] )
727
m_layers.insert( vector[i], new VLayerListViewItem( m_layersListView, vector[i], m_document ) );
728
item = m_layers[ vector[i] ];
730
item->setOpen( true );
731
VObjectListIterator itr = vector[i]->objects();
733
for( ; itr.current();++itr, objcount++ )
734
if( itr.current()->state() != VObject::deleted )
736
if( !m_objects[ itr.current() ] )
737
m_objects.insert( itr.current(), new VObjectListViewItem( item, itr.current(), m_document, objcount ) );
739
m_objects[ itr.current() ]->setKey( objcount );
741
//kdDebug(38000) << "obj : " << itr.current() << ", key : " << m_objects[ itr.current() ]->key( 0, true ).latin1() << endl;
743
if( dynamic_cast<VGroup *>( itr.current() ) )
744
updateObjects( itr.current(), m_objects[ itr.current() ] );
750
m_layersListView->sort();
751
} // VLayersTab::updateLayers
754
VLayersTab::updateObjects( VObject *object, QListViewItem *item )
757
VObjectListIterator itr = dynamic_cast<VGroup *>( object )->objects();
758
for( ; itr.current();++itr, objcount++ )
759
if( itr.current()->state() != VObject::deleted )
761
if( !m_objects[ itr.current() ] )
762
m_objects.insert( itr.current(), new VObjectListViewItem( item, itr.current(), m_document, objcount ) );
765
delete m_objects[ itr.current() ];
766
m_objects.insert( itr.current(), new VObjectListViewItem( item, itr.current(), m_document, objcount ) );
767
m_objects[ itr.current() ]->setKey( objcount );
770
if( dynamic_cast<VGroup *>( itr.current() ) )
771
updateObjects( itr.current(), m_objects[ itr.current() ] );
777
/*************************************************************************
779
*************************************************************************/
781
VHistoryGroupItem::VHistoryGroupItem( VHistoryItem* item, QListView* parent, QListViewItem* after )
782
: QListViewItem( parent, after )
784
setPixmap( 0, *item->pixmap( 0 ) );
785
setText( 0, item->text( 0 ) );
786
parent->takeItem( item );
788
m_key = item->key( 0, true );
789
} // VHistoryItem::VHistoryItem
791
VHistoryGroupItem::~VHistoryGroupItem()
793
} // VHistoryGroupItem::~VHistoryGroupItem
796
VHistoryGroupItem::paintCell( QPainter* p, const QColorGroup& cg, int column, int width, int align )
800
VHistoryItem* item = (VHistoryItem*)firstChild();
803
if ( item->command()->success() )
807
item = (VHistoryItem*)item->nextSibling();
811
p->fillRect( 0, 0, width, height(), cg.base() );
813
p->fillRect( 0, 0, width, height(), QBrush( cg.base().dark( 140 ), QBrush::BDiagPattern ) );
816
p->fillRect( 0, 0, width, height(), cg.base().dark( 140 ) );
818
const QPixmap* pixmap = this->pixmap( column );
822
int pw = pixmap->width();
823
int ph = pixmap->height();
824
p->drawPixmap( ( height() - pw ) / 2, ( height() - ph ) / 2, *pixmap );
829
p->setPen( cg.text() );
830
p->drawText( xstart, 0, width - xstart, height(), align | Qt::AlignVCenter, text( column ) );
831
} // VHistoryGroupItem::paintCell
833
VHistoryItem::VHistoryItem( VCommand* command, QListView* parent, QListViewItem* after )
834
: QListViewItem( parent, after ), m_command( command )
837
} // VHistoryItem::VHistoryItem
839
VHistoryItem::VHistoryItem( VCommand* command, VHistoryGroupItem* parent, QListViewItem* after )
840
: QListViewItem( parent, after ), m_command( command )
843
} // VHistoryItem::VHistoryItem
848
kdDebug(38000) << "In VHistoryItem::init() : " << m_command->name() << endl;
850
sprintf( buffer, "%064ld", ++g_lastKey );
852
setPixmap( 0, QPixmap( KGlobal::iconLoader()->iconPath( m_command->icon(), KIcon::Small ) ) );
853
setText( 0, m_command->name() );
854
} // VHistoryITem::init
856
VHistoryItem::~VHistoryItem()
858
} // VHistoryItem::~VHistoryItem
861
VHistoryItem::paintCell( QPainter* p, const QColorGroup& cg, int column, int width, int align )
863
p->fillRect( 0, 0, width - 1, height() - 1, ( m_command->success() ? cg.base() : cg.base().dark( 140 ) ) );
865
const QPixmap* pixmap = this->pixmap( column );
869
int pw = pixmap->width();
870
int ph = pixmap->height();
871
p->drawPixmap( ( height() - pw ) / 2, ( height() - ph ) / 2, *pixmap );
876
p->setPen( cg.text() );
877
p->drawText( xstart, 0, width - xstart, height(), align | Qt::AlignVCenter, text( column ) );
878
} // VHistoryItem::paintCell
880
VHistoryTab::VHistoryTab( KarbonPart* part, QWidget* parent )
881
: QWidget( parent ), m_part( part )
883
QVBoxLayout* layout = new QVBoxLayout( this );
884
layout->setMargin( 3 );
885
layout->setSpacing( 2 );
886
layout->add( m_history = new QListView( this ) );
887
m_history->setVScrollBarMode( QListView::AlwaysOn );
888
m_history->setSelectionMode( QListView::NoSelection );
889
m_history->addColumn( i18n( "Commands" ) );
890
m_history->setResizeMode( QListView::AllColumns );
891
m_history->setRootIsDecorated( true );
892
layout->add( m_groupCommands = new QCheckBox( i18n( "Group commands" ), this ) );
894
m_history->setSorting( 0, true );
895
VHistoryGroupItem* group = 0;
896
VHistoryItem* last = 0;
897
QPtrVector<VCommand> cmds;
898
part->commandHistory()->commands()->toVector( &cmds );
899
int c = cmds.count();
900
for ( int i = 0; i < c; i++ )
902
if ( ( i > 0 ) && ( cmds[ i ]->name() == cmds[ i - 1 ]->name() ) )
905
QListViewItem* prev = group->firstChild();
906
while ( prev && prev->nextSibling() )
907
prev = prev->nextSibling();
908
new VHistoryItem( cmds[ i ], group, prev );
912
group = new VHistoryGroupItem( last, m_history, last );
913
new VHistoryItem( cmds[ i ], group, last );
917
last = new VHistoryItem( cmds[ i ], m_history, last );
923
connect( m_history, SIGNAL( mouseButtonClicked( int, QListViewItem*, const QPoint&, int ) ), this, SLOT( commandClicked( int, QListViewItem*, const QPoint&, int ) ) );
924
connect( m_groupCommands, SIGNAL( stateChanged( int ) ), this, SLOT( groupingChanged( int ) ) );
925
connect( part->commandHistory(), SIGNAL( historyCleared() ), this, SLOT( historyCleared() ) );
926
connect( part->commandHistory(), SIGNAL( commandAdded( VCommand* ) ), this, SLOT( slotCommandAdded( VCommand* ) ) );
927
connect( part->commandHistory(), SIGNAL( commandExecuted( VCommand* ) ), this, SLOT( commandExecuted( VCommand* ) ) );
928
connect( part->commandHistory(), SIGNAL( firstCommandRemoved() ), this, SLOT( removeFirstCommand() ) );
929
connect( part->commandHistory(), SIGNAL( lastCommandRemoved() ), this, SLOT( removeLastCommand() ) );
930
connect( this, SIGNAL( undoCommand( VCommand* ) ), part->commandHistory(), SLOT( undo( VCommand* ) ) );
931
connect( this, SIGNAL( redoCommand( VCommand* ) ), part->commandHistory(), SLOT( redo( VCommand* ) ) );
932
connect( this, SIGNAL( undoCommandsTo( VCommand* ) ), part->commandHistory(), SLOT( undoAllTo( VCommand* ) ) );
933
connect( this, SIGNAL( redoCommandsTo( VCommand* ) ), part->commandHistory(), SLOT( redoAllTo( VCommand* ) ) );
934
} // VHistoryTab::VHistoryTab
936
VHistoryTab::~VHistoryTab()
938
} // VHistoryTab::~VHistoryTab
941
VHistoryTab::groupingEnabled()
943
return m_groupCommands->isChecked();
944
} // VHistoryTab::groupingEnabled
947
VHistoryTab::historyCleared()
950
} // VHistoryTab::historyCleared
953
VHistoryTab::commandExecuted( VCommand* command )
955
QListViewItem* item = m_history->firstChild();
957
while ( !found && item )
959
if ( item->rtti() == 1001 )
961
QListViewItem* child = item->firstChild();
962
while ( !found && child )
964
found = ( ( (VHistoryItem*)child )->command() == command );
966
child = child->nextSibling();
971
found = ( item && ( (VHistoryItem*)item )->command() == command );
973
item = item->nextSibling();
977
m_history->repaintItem( item );
978
if ( item->parent() )
979
m_history->repaintItem( item->parent() );
980
m_history->ensureItemVisible( item );
982
} // VHistoryTab::commandExecuted
985
VHistoryTab::slotCommandAdded( VCommand* command )
990
QListViewItem* last = m_history->firstChild();
991
while ( last && last->nextSibling() )
992
last = last->nextSibling();
994
if( groupingEnabled() )
996
if( ( last ) && last->text( 0 ) == command->name() )
998
if( last->rtti() == 1002 )
1000
QListViewItem* prevSibling;
1001
if( m_history->childCount() > 1 )
1003
prevSibling = m_history->firstChild();
1004
while ( prevSibling->nextSibling() != last )
1005
prevSibling = prevSibling->nextSibling();
1008
prevSibling = m_history->firstChild();
1009
last = new VHistoryGroupItem( (VHistoryItem*)last, m_history, prevSibling );
1011
QListViewItem* prev = last->firstChild();
1012
while ( prev && prev->nextSibling() )
1013
prev = prev->nextSibling();
1014
m_history->setCurrentItem( new VHistoryItem( command, (VHistoryGroupItem*)last, prev ) );
1017
m_history->setCurrentItem( new VHistoryItem( command, m_history, last ) );
1020
m_history->setCurrentItem( new VHistoryItem( command, m_history, last ) );
1023
m_history->ensureItemVisible( m_history->currentItem() );
1024
m_history->update();
1025
} // VHistoryTab::slotCommandAdded
1028
VHistoryTab::removeFirstCommand()
1030
if ( m_history->childCount() > 0 )
1031
if ( m_history->firstChild()->rtti() == 1002 )
1032
delete m_history->firstChild();
1035
VHistoryGroupItem* group = (VHistoryGroupItem*)m_history->firstChild();
1036
delete group->firstChild();
1037
if ( group->childCount() == 1 )
1039
new VHistoryItem( ( (VHistoryItem*)group->firstChild() )->command(), m_history, 0 );
1043
} // VHistoryTab::removeFirstCommand
1046
VHistoryTab::removeLastCommand()
1048
if ( m_history->childCount() > 0 )
1050
QListViewItem* last = m_history->firstChild();
1051
while ( last && last->nextSibling() )
1052
last = last->nextSibling();
1053
if ( last->rtti() == 1002 )
1057
VHistoryGroupItem* group = (VHistoryGroupItem*)last;
1058
last = group->firstChild();
1059
while ( last && last->nextSibling() )
1060
last = last->nextSibling();
1062
if ( group->childCount() == 1 )
1064
new VHistoryItem( ( (VHistoryItem*)group->firstChild() )->command(), m_history, group );
1069
} // VHistoryTab::removeLastCommand
1072
VHistoryTab::commandClicked( int button, QListViewItem* item, const QPoint&, int )
1074
if ( !item || item->rtti() == 1001 )
1077
VCommand* cmd = ( (VHistoryItem*)item )->command();
1078
if ( cmd->success() )
1080
emit undoCommandsTo( ( (VHistoryItem*)item )->command() );
1082
emit undoCommand( ( (VHistoryItem*)item )->command() );
1085
emit redoCommandsTo( ( (VHistoryItem*)item )->command() );
1087
emit redoCommand( ( (VHistoryItem*)item )->command() );
1088
} // VHistoryTab::commandClicked
1091
VHistoryTab::groupingChanged( int )
1093
if ( m_groupCommands->isChecked() && m_history->childCount() > 1 )
1095
QListViewItem* s2last = 0;
1096
QListViewItem* last = m_history->firstChild();
1097
QListViewItem* item = last->nextSibling();
1099
if ( last->text( 0 ) == item->text( 0 ) )
1101
if ( last->rtti() == 1002 )
1102
last = new VHistoryGroupItem( (VHistoryItem*)last, m_history, s2last );
1103
m_history->takeItem( item );
1104
last->insertItem( item );
1105
item = last->nextSibling();
1111
item = last->nextSibling();
1116
QListViewItem* item = m_history->firstChild();
1118
if ( item->rtti() == 1001 )
1120
QListViewItem* child;
1121
while ( ( child = item->firstChild() ) )
1123
item->takeItem( child );
1124
m_history->insertItem( child );
1127
item = item->nextSibling();
1131
item = item->nextSibling();
1134
m_history->update();
1135
} // VHistoryTab::groupingChanged
1137
/*************************************************************************
1139
*************************************************************************/
1141
VDocumentDocker::VDocumentDocker( KarbonView* view )
1144
setCaption( i18n( "Overview" ) );
1146
QTabWidget* tabWidget;
1147
setWidget( tabWidget = new QTabWidget( this ) );
1148
tabWidget->setFont( font() );
1149
tabWidget->addTab( m_documentTab = new VDocumentTab( view, this ), i18n( "Document" ) );
1150
tabWidget->addTab( m_layersTab = new VLayersTab( view, this ), i18n( "Layers" ) );
1151
tabWidget->addTab( m_historyTab = new VHistoryTab( view->part(), this ), i18n( "History" ) );
1153
setFixedSize( 200, 200 );
1154
} // VDocumentDocker::VDocumentDocker
1156
VDocumentDocker::~VDocumentDocker()
1158
} // VDocumentDocker::~VDocumentDocker
1160
#include "vdocumentdocker.moc"