~ubuntu-branches/ubuntu/edgy/koffice/edgy-updates

« back to all changes in this revision

Viewing changes to karbon/dockers/vdocumentdocker.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040509113300-xi5t1z4yxe7n03x7
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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., 59 Temple Place - Suite 330,
 
17
   Boston, MA 02111-1307, USA.
 
18
*/
 
19
 
 
20
#include <qhbuttongroup.h>
 
21
#include <qinputdialog.h>
 
22
#include <qlayout.h>
 
23
#include <qcheckbox.h>
 
24
#include <qlistview.h>
 
25
#include <qptrvector.h>
 
26
#include <qtoolbutton.h>
 
27
#include <qpainter.h>
 
28
#include <qtabwidget.h>
 
29
#include <qlabel.h>
 
30
#include <qcursor.h>
 
31
 
 
32
#include <klocale.h>
 
33
#include <kglobal.h>
 
34
#include <koMainWindow.h>
 
35
#include <kdebug.h>
 
36
#include <kiconloader.h>
 
37
#include <klineeditdlg.h>
 
38
 
 
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"
 
45
#include "vlayer.h"
 
46
#include "vlayercmd.h"
 
47
#include "vdeletecmd.h"
 
48
#include "vzordercmd.h"
 
49
#include "vselection.h"
 
50
#include "vstroke.h"
 
51
#include "vcanvas.h"
 
52
#include "vdocumentdocker.h"
 
53
#include <visitors/vselectiondesc.h>
 
54
 
 
55
static long g_lastKey = 0;
 
56
 
 
57
/*************************************************************************
 
58
 *  Document tab                                                         *
 
59
 *************************************************************************/
 
60
 
 
61
VDocumentPreview::VDocumentPreview( KarbonView* view, QWidget* parent )
 
62
                : QWidget( parent, "DocumentPreview" ), m_document( &view->part()->document() ), m_view( view )
 
63
{
 
64
        update();
 
65
        installEventFilter( this );
 
66
        setBackgroundMode( Qt::NoBackground );
 
67
        setMouseTracking( true );
 
68
        m_dragging = false;
 
69
        m_docpixmap = 0L;
 
70
} // VDocumentPreview::VDocumentPreview
 
71
 
 
72
VDocumentPreview::~VDocumentPreview()
 
73
{
 
74
        delete m_docpixmap;
 
75
} // VDocumentPreview::~VDocumentPreview
 
76
 
 
77
void
 
78
VDocumentPreview::reset()
 
79
{
 
80
        delete m_docpixmap;
 
81
        m_docpixmap = 0L;
 
82
}
 
83
 
 
84
bool
 
85
VDocumentPreview::eventFilter( QObject* object, QEvent* event )
 
86
{
 
87
        double scaleFactor;
 
88
        double xoffset = 0.;
 
89
        double yoffset = 0.;
 
90
        if ( ( height() - 4 ) / m_document->height() > ( width() - 4 ) / m_document->width() )
 
91
        {
 
92
                scaleFactor = ( width() - 4 ) / m_document->width();
 
93
                yoffset = ( ( height() - 4 ) / scaleFactor - m_document->height() ) / 2;
 
94
        }
 
95
        else
 
96
        {
 
97
                scaleFactor = ( height() - 4 ) / m_document->height();
 
98
                xoffset = ( ( width() - 4 ) / scaleFactor - m_document->width() ) / 2;
 
99
        }
 
100
        KoRect rect = m_view->canvasWidget()->boundingBox();
 
101
 
 
102
        QMouseEvent* mouseEvent = static_cast<QMouseEvent*>( event );
 
103
        if( event->type() == QEvent::MouseButtonPress )
 
104
        {
 
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 );
 
111
        }
 
112
        else if( event->type() == QEvent::MouseButtonRelease )
 
113
        {
 
114
                if( m_dragging )
 
115
                {
 
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;
 
123
                        m_dragging = false;
 
124
                        update();
 
125
                }
 
126
        }
 
127
        else if( event->type() == QEvent::MouseMove )
 
128
        {
 
129
                if( m_dragging )
 
130
                {
 
131
                        m_lastPoint.setX( mouseEvent->pos().x() );
 
132
                        m_lastPoint.setY( mouseEvent->pos().y() );
 
133
                        update();
 
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;*/
 
139
                }
 
140
                else
 
141
                {
 
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 ) );
 
145
                }
 
146
        }
 
147
 
 
148
        return QWidget::eventFilter( object, event );
 
149
}
 
150
 
 
151
void
 
152
VDocumentPreview::paintEvent( QPaintEvent* )
 
153
{
 
154
        // TODO : use NotROP, otherwise too slow
 
155
        QPixmap pixmap( width(), height() );
 
156
        double xoffset = 0.;
 
157
        double yoffset = 0.;
 
158
        double scaleFactor;
 
159
        if ( ( height() - 4 ) / m_document->height() > ( width() - 4 ) / m_document->width() )
 
160
        {
 
161
                scaleFactor = ( width() - 4 ) / m_document->width();
 
162
                yoffset = ( ( height() - 4 ) / scaleFactor - m_document->height() ) / 2;
 
163
        }
 
164
        else
 
165
        {
 
166
                scaleFactor = ( height() - 4 ) / m_document->height();
 
167
                xoffset = ( ( width() - 4 ) / scaleFactor - m_document->width() ) / 2;
 
168
        }
 
169
        xoffset += 2 / scaleFactor;
 
170
        yoffset += 2 / scaleFactor;
 
171
        if( !m_docpixmap || m_docpixmap->width() != width() || m_docpixmap->height() != height() )
 
172
        {
 
173
                delete m_docpixmap;
 
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 );
 
180
                // draw doc outline
 
181
                VColor c( Qt::black );
 
182
                VStroke stroke( c, 0L, 1.0 / scaleFactor );
 
183
                p.setPen( stroke );
 
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 );
 
187
                p.end();
 
188
        }
 
189
        bitBlt( &pixmap, 0, 0, m_docpixmap, 0, 0, width(), height() );
 
190
 
 
191
        // draw viewport rect
 
192
        {
 
193
                QPainter p( &pixmap );
 
194
                p.setWorldMatrix( QWMatrix( scaleFactor, 0, 0, -scaleFactor, xoffset * scaleFactor, height() - yoffset * scaleFactor ) );
 
195
                p.setPen( Qt::red );
 
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() ) );
 
203
        }
 
204
 
 
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 );
 
216
        pw.end();
 
217
        bitBlt( this, 0, 0, &pixmap, 0, 0, width(), height() );
 
218
} // VDocumentPreview::paintEvent
 
219
 
 
220
VDocumentTab::VDocumentTab( KarbonView* view, QWidget* parent )
 
221
                : QWidget( parent, "DocumentTab" ), m_view( view )
 
222
{
 
223
        QFrame* frame;
 
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 );
 
245
        //layout->addWidget(
 
246
 
 
247
        m_width->setAlignment( AlignRight );
 
248
        m_height->setAlignment( AlignRight );
 
249
        m_layers->setAlignment( AlignRight );
 
250
        m_format->setAlignment( AlignRight );
 
251
 
 
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() ) );
 
256
 
 
257
        updateDocumentInfo();
 
258
} // VDocumentTab::VDocumentTab
 
259
 
 
260
VDocumentTab::~VDocumentTab()
 
261
{
 
262
} // VDocumentTab::~VDocumentTab
 
263
 
 
264
void
 
265
VDocumentTab::updateDocumentInfo()
 
266
{
 
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
 
271
 
 
272
void
 
273
VDocumentTab::slotCommandAdded( VCommand * )
 
274
{
 
275
        m_documentPreview->reset();
 
276
        m_documentPreview->update();
 
277
}
 
278
 
 
279
void
 
280
VDocumentTab::slotZoomChanged( double )
 
281
{
 
282
        m_documentPreview->update();
 
283
}
 
284
 
 
285
void
 
286
VDocumentTab::slotViewportChanged()
 
287
{
 
288
        m_documentPreview->update();
 
289
        updateDocumentInfo();
 
290
}
 
291
 
 
292
void
 
293
VDocumentTab::slotCommandExecuted()
 
294
{
 
295
        m_documentPreview->reset();
 
296
        m_documentPreview->update();
 
297
}
 
298
 
 
299
/*************************************************************************
 
300
 *  Layers tab                                                           *
 
301
 *************************************************************************/
 
302
 
 
303
VObjectListViewItem::VObjectListViewItem( QListViewItem* parent, VObject* object, VDocument *doc, uint key )
 
304
        : QListViewItem( parent, 0L ), m_object( object ), m_document( doc ), m_key( key )
 
305
{
 
306
        update();
 
307
}
 
308
 
 
309
QString
 
310
VObjectListViewItem::key( int, bool ) const
 
311
{
 
312
        return QString( "%1" ).arg( m_key );
 
313
}
 
314
 
 
315
void
 
316
VObjectListViewItem::update()
 
317
{
 
318
        // text description
 
319
        VSelectionDescription selectionDesc;
 
320
        selectionDesc.visit( *m_object );
 
321
        setText( 0, QString( "%1" ).arg( selectionDesc.shortDescription() ) );
 
322
 
 
323
        // draw thumb preview (16x16)
 
324
        QPixmap preview;
 
325
        preview.resize( 16, 16 );
 
326
        VKoPainter p( &preview, 16, 16, false );
 
327
        // Y mirroring
 
328
        QWMatrix mat;
 
329
        mat.scale( 1, -1 );
 
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 );
 
335
 
 
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 ) );
 
344
        p.end();
 
345
 
 
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 ) );
 
352
}
 
353
 
 
354
 
 
355
VLayerListViewItem::VLayerListViewItem( QListView* parent, VLayer* layer, VDocument *doc )
 
356
        : QCheckListItem( parent, 0L, CheckBox ), m_layer( layer ), m_document( doc)
 
357
{
 
358
        update();
 
359
} // VLayerListViewItem::VLayerListViewItem
 
360
 
 
361
void
 
362
VLayerListViewItem::update()
 
363
{
 
364
        // draw thumb preview (16x16)
 
365
        QPixmap preview;
 
366
        preview.resize( 16, 16 );
 
367
        VKoPainter p( &preview, 16, 16, false );
 
368
        // Y mirroring
 
369
        QWMatrix mat;
 
370
        mat.scale( 1, -1 );
 
371
        mat.translate( 0,  -16 );
 
372
        p.setWorldMatrix( mat );
 
373
 
 
374
        // TODO: When the document will support page size, change the following line.
 
375
        p.setZoomFactor( 16. / 800. );
 
376
        m_layer->draw( &p );
 
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 ) );
 
382
        p.end();
 
383
 
 
384
        // text description
 
385
        setOn( m_layer->selected() );
 
386
        setText( 0, m_layer->name() );
 
387
 
 
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
 
395
 
 
396
void
 
397
VLayerListViewItem::stateChange( bool on )
 
398
{
 
399
        m_layer->setSelected( on );
 
400
} // VLayerListViewItem::stateChange
 
401
 
 
402
int
 
403
VLayerListViewItem::pos()
 
404
{
 
405
        VLayerListViewItem* item;
 
406
        if( !( item = (VLayerListViewItem*)itemAbove() ) )
 
407
                return 0;
 
408
        else
 
409
                return 1 + item->pos();
 
410
} // VLayerListViewItem::pos
 
411
 
 
412
VLayersTab::VLayersTab( KarbonView* view, QWidget* parent )
 
413
                : QWidget( parent, "LayersTab" ), m_view( view ), m_document( &view->part()->document() )
 
414
{
 
415
 
 
416
        QToolButton* button;
 
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 );
 
440
 
 
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 );
 
451
 
 
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 ) ) );
 
456
 
 
457
        layout->activate();
 
458
        updateLayers();
 
459
} // VLayersTab::VLayersTab
 
460
 
 
461
VLayersTab::~VLayersTab()
 
462
{
 
463
} // VLayersTab::~VLayersTab
 
464
 
 
465
void
 
466
VLayersTab::slotButtonClicked( int ID )
 
467
{
 
468
        switch( ID )
 
469
        {
 
470
                case 0:
 
471
                        addLayer(); break;
 
472
                case 1:
 
473
                        raiseItem(); break;
 
474
                case 2:
 
475
                        lowerItem(); break;
 
476
                case 3:
 
477
                        deleteItem(); break;
 
478
        }
 
479
} // VLayersTab::slotButtonClicked
 
480
 
 
481
void
 
482
VLayersTab::slotSelectionChanged()
 
483
{
 
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 )
 
489
                {
 
490
                        QListViewItemIterator it( m_layersListView );
 
491
                        bool found = false;
 
492
                        while( !found && dynamic_cast<VObjectListViewItem *>( it.current() ) )
 
493
                        {
 
494
                                if( dynamic_cast<VObjectListViewItem *>( it.current() ) &&
 
495
                                        dynamic_cast<VObjectListViewItem *>( it.current() )->object() == itr.current() )
 
496
                                {
 
497
                                        m_layersListView->setSelected( it.current(), true );
 
498
                                        found = true;
 
499
                                }
 
500
                                ++it;
 
501
                        }
 
502
                        // not found, insert
 
503
                        if( !found )
 
504
                        {
 
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() ) );
 
508
                        }
 
509
 
 
510
                }
 
511
}
 
512
 
 
513
void
 
514
VLayersTab::selectionChanged( QListViewItem* item, const QPoint &, int col )
 
515
{
 
516
        if( item )
 
517
        {
 
518
                VLayerListViewItem *layerItem = dynamic_cast<VLayerListViewItem *>( item );
 
519
                if( layerItem )
 
520
                {
 
521
                        VLayer *obj = layerItem->layer();
 
522
                        m_document->setActiveLayer( layerItem->layer() );
 
523
                        m_document->selection()->clear();
 
524
 
 
525
                        if( col > 0 )
 
526
                        {
 
527
                                if( col == 2 )
 
528
                                        obj->setState( obj->state() == VObject::normal || obj->state() == VObject::normal_locked ? VObject::hidden : VObject::normal );
 
529
                                else
 
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 );
 
538
                                layerItem->update();
 
539
                                m_view->part()->repaintAllViews();
 
540
                        }
 
541
                }
 
542
                else
 
543
                {
 
544
                        VObjectListViewItem *objectItem = dynamic_cast< VObjectListViewItem *>( m_layersListView->selectedItem() );
 
545
                        VObject *obj = objectItem->object();
 
546
 
 
547
                        if( col > 0 ) // set visibility
 
548
                        {
 
549
                                if( col == 2 )
 
550
                                        obj->setState( obj->state() == VObject::hidden ? VObject::normal : VObject::hidden );
 
551
                                else
 
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();
 
563
                        }
 
564
                        else if( obj->state() == VObject::normal ||
 
565
                                         obj->state() >= VObject::selected ) // select only visible and unlocked objects
 
566
                        {
 
567
                                m_document->selection()->clear();
 
568
                                m_document->selection()->append( obj );
 
569
                                m_view->part()->repaintAllViews();
 
570
                        }
 
571
                }
 
572
        }
 
573
} // VLayersTab::selectionChanged
 
574
 
 
575
void
 
576
VLayersTab::renameItem( QListViewItem* item, const QPoint&, int col )
 
577
{
 
578
        if ( ( item ) && col == 0 )
 
579
        {
 
580
                bool ok = true;
 
581
                VLayerListViewItem* layerItem = dynamic_cast<VLayerListViewItem *>( m_layersListView->selectedItem() );
 
582
                if( !layerItem )
 
583
                {
 
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 );
 
588
                        if( ok )
 
589
                        {
 
590
                                m_document->setObjectName( obj, name );
 
591
                                objectItem->update();
 
592
                        }
 
593
                }
 
594
                else
 
595
                {
 
596
                        QString name = KLineEditDlg::getText( i18n( "Rename Layer" ), i18n( "Change the name of the current layer:" ),
 
597
                                                                                                                                        layerItem->layer()->name(), &ok, this );
 
598
                        if( ok )
 
599
                        {
 
600
                                layerItem->layer()->setName( name );
 
601
                                layerItem->update();
 
602
                        }
 
603
                }
 
604
        }
 
605
} // VLayersTab::renameItem
 
606
 
 
607
void
 
608
VLayersTab::addLayer()
 
609
{
 
610
        bool ok = true;
 
611
        QString name = KLineEditDlg::getText( i18n( "New Layer" ), i18n( "Enter the name of the new layer:" ),
 
612
                                     i18n( "New layer" ), &ok, this );
 
613
        if( ok )
 
614
        {
 
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 );
 
620
                updateLayers();
 
621
        }
 
622
} // VLayersTab::addLayer
 
623
 
 
624
void
 
625
VLayersTab::raiseItem()
 
626
{
 
627
        VCommand *cmd = 0L;
 
628
        //QListViewItem *newselection = 0L;
 
629
        VLayerListViewItem* layerItem = dynamic_cast<VLayerListViewItem *>( m_layersListView->selectedItem() );
 
630
        if( layerItem )
 
631
        {
 
632
                VLayer *layer = layerItem->layer();
 
633
                if( layer && m_document->canRaiseLayer( layer ) )
 
634
                {
 
635
                        cmd = new VLayerCmd( m_document, i18n( "Raise Layer" ),
 
636
                                                        layerItem->layer(), VLayerCmd::raiseLayer );
 
637
                        //newselection = layerItem;
 
638
                }
 
639
        }
 
640
        else
 
641
        {
 
642
                VObjectListViewItem* item = dynamic_cast< VObjectListViewItem *>( m_layersListView->selectedItem() );
 
643
                if( item )
 
644
                {
 
645
                        cmd = new VZOrderCmd( m_document, item->object(), VZOrderCmd::up );
 
646
                        //newselection = item;
 
647
                }
 
648
        }
 
649
        if( cmd )
 
650
        {
 
651
                m_view->part()->addCommand( cmd, true );
 
652
                updatePreviews();
 
653
                //if( newselection )
 
654
                //      m_layersListView->setSelected( newselection, true );
 
655
        }
 
656
} // VLayersTab::raiseItem
 
657
 
 
658
void
 
659
VLayersTab::lowerItem()
 
660
{
 
661
        VCommand *cmd = 0L;
 
662
        VLayerListViewItem* layerItem = dynamic_cast<VLayerListViewItem *>( m_layersListView->selectedItem() );
 
663
        if( layerItem )
 
664
        {
 
665
                VLayer *layer = layerItem->layer();
 
666
                if( layer && m_document->canLowerLayer( layer ) )
 
667
                        cmd = new VLayerCmd( m_document, i18n( "Lower Layer" ), layer, VLayerCmd::lowerLayer );
 
668
        }
 
669
        else
 
670
        {
 
671
                VObjectListViewItem* item = dynamic_cast< VObjectListViewItem *>( m_layersListView->selectedItem() );
 
672
                if( item )
 
673
                        cmd = new VZOrderCmd( m_document, item->object(), VZOrderCmd::down );
 
674
        }
 
675
        if( cmd )
 
676
        {
 
677
                m_view->part()->addCommand( cmd, true );
 
678
                updatePreviews();
 
679
        }
 
680
} // VLayersTab::lowerItem
 
681
 
 
682
void
 
683
VLayersTab::deleteItem()
 
684
{
 
685
        VCommand *cmd = 0L;
 
686
        VLayerListViewItem* layerItem = dynamic_cast< VLayerListViewItem *>( m_layersListView->selectedItem() );
 
687
        if( layerItem )
 
688
        {
 
689
                VLayer *layer = layerItem->layer();
 
690
                if( layer )
 
691
                {
 
692
                        cmd = new VLayerCmd( m_document, i18n( "Delete Layer" ), layer, VLayerCmd::deleteLayer );
 
693
                        m_view->part()->addCommand( cmd, true );
 
694
                        delete layerItem;
 
695
                }
 
696
        }
 
697
        else
 
698
        {
 
699
                VObjectListViewItem* item = dynamic_cast< VObjectListViewItem *>( m_layersListView->selectedItem() );
 
700
                if( item )
 
701
                {
 
702
                        cmd = new VDeleteCmd( m_document, item->object() );
 
703
                        m_view->part()->addCommand( cmd, true );
 
704
                        delete item;
 
705
                }
 
706
        }
 
707
} // VLayersTab::deleteItem
 
708
 
 
709
void
 
710
VLayersTab::updatePreviews()
 
711
{
 
712
        // TODO: Optimization: call update() on each view item...
 
713
        updateLayers();
 
714
} // VLayersTab::updatePreviews
 
715
 
 
716
void
 
717
VLayersTab::updateLayers()
 
718
{
 
719
        QPtrVector<VLayer> vector;
 
720
        m_document->layers().toVector( &vector );
 
721
        VLayerListViewItem* item;
 
722
        for( int i = vector.count() - 1; i >= 0; i-- )
 
723
        {
 
724
                if ( vector[i]->state() != VObject::deleted )
 
725
                {
 
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] ];
 
729
 
 
730
                        item->setOpen( true );
 
731
                        VObjectListIterator itr = vector[i]->objects();
 
732
                        uint objcount = 1;
 
733
                        for( ; itr.current();++itr, objcount++ )
 
734
                                if( itr.current()->state() != VObject::deleted )
 
735
                                {
 
736
                                        if( !m_objects[ itr.current() ] )
 
737
                                                m_objects.insert( itr.current(), new VObjectListViewItem( item, itr.current(), m_document, objcount ) );
 
738
                                        else
 
739
                                                m_objects[ itr.current() ]->setKey( objcount );
 
740
 
 
741
                                        //kdDebug(38000) << "obj : " << itr.current() << ", key : " << m_objects[ itr.current() ]->key( 0, true ).latin1() << endl;
 
742
 
 
743
                                        if( dynamic_cast<VGroup *>( itr.current() ) )
 
744
                                                updateObjects( itr.current(),  m_objects[ itr.current() ] );
 
745
                                }
 
746
 
 
747
                        item->sort();
 
748
                }
 
749
        }
 
750
        m_layersListView->sort();
 
751
} // VLayersTab::updateLayers
 
752
 
 
753
void
 
754
VLayersTab::updateObjects( VObject *object, QListViewItem *item )
 
755
{
 
756
        uint objcount = 1;
 
757
        VObjectListIterator itr = dynamic_cast<VGroup *>( object )->objects();
 
758
        for( ; itr.current();++itr, objcount++ )
 
759
                if( itr.current()->state() != VObject::deleted )
 
760
                {
 
761
                        if( !m_objects[ itr.current() ] )
 
762
                                m_objects.insert( itr.current(), new VObjectListViewItem( item, itr.current(), m_document, objcount ) );
 
763
                        else
 
764
                        {
 
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 );
 
768
                        }
 
769
 
 
770
                        if( dynamic_cast<VGroup *>( itr.current() ) )
 
771
                                updateObjects( itr.current(), m_objects[ itr.current() ] );
 
772
                }
 
773
 
 
774
        item->sort();
 
775
}
 
776
 
 
777
/*************************************************************************
 
778
 *  History tab                                                          *
 
779
 *************************************************************************/
 
780
 
 
781
VHistoryGroupItem::VHistoryGroupItem( VHistoryItem* item, QListView* parent, QListViewItem* after )
 
782
                : QListViewItem( parent, after )
 
783
{
 
784
        setPixmap( 0, *item->pixmap( 0 ) );
 
785
        setText( 0, item->text( 0 ) );
 
786
        parent->takeItem( item );
 
787
        insertItem( item );
 
788
        m_key = item->key( 0, true );
 
789
} // VHistoryItem::VHistoryItem
 
790
 
 
791
VHistoryGroupItem::~VHistoryGroupItem()
 
792
{
 
793
} // VHistoryGroupItem::~VHistoryGroupItem
 
794
 
 
795
void
 
796
VHistoryGroupItem::paintCell( QPainter* p, const QColorGroup& cg, int column, int width, int align )
 
797
{
 
798
        int e = 0;
 
799
        int n = 0;
 
800
        VHistoryItem* item = (VHistoryItem*)firstChild();
 
801
        while ( item )
 
802
        {
 
803
                if ( item->command()->success() )
 
804
                        e++;
 
805
                else
 
806
                        n++;
 
807
                item = (VHistoryItem*)item->nextSibling();
 
808
        }
 
809
        if ( e > 0 )
 
810
        {
 
811
                p->fillRect( 0, 0, width, height(), cg.base() );
 
812
                if ( n > 0 )
 
813
                        p->fillRect( 0, 0, width, height(), QBrush( cg.base().dark( 140 ), QBrush::BDiagPattern ) );
 
814
        }
 
815
        else
 
816
                p->fillRect( 0, 0, width, height(), cg.base().dark( 140 ) );
 
817
 
 
818
        const QPixmap* pixmap = this->pixmap( column );
 
819
        int xstart;
 
820
        if ( pixmap )
 
821
        {
 
822
                int pw = pixmap->width();
 
823
                int ph = pixmap->height();
 
824
                p->drawPixmap( ( height() - pw ) / 2, ( height() - ph ) / 2, *pixmap );
 
825
                xstart = height();
 
826
        }
 
827
        else
 
828
                xstart = 4;
 
829
        p->setPen( cg.text() );
 
830
        p->drawText( xstart, 0, width - xstart, height(), align | Qt::AlignVCenter, text( column ) );
 
831
} // VHistoryGroupItem::paintCell
 
832
 
 
833
VHistoryItem::VHistoryItem( VCommand* command, QListView* parent, QListViewItem* after )
 
834
                : QListViewItem( parent, after ), m_command( command )
 
835
{
 
836
        init();
 
837
} // VHistoryItem::VHistoryItem
 
838
 
 
839
VHistoryItem::VHistoryItem( VCommand* command, VHistoryGroupItem* parent, QListViewItem* after )
 
840
                : QListViewItem( parent, after ), m_command( command )
 
841
{
 
842
        init();
 
843
} // VHistoryItem::VHistoryItem
 
844
 
 
845
void
 
846
VHistoryItem::init()
 
847
{
 
848
        kdDebug(38000) << "In VHistoryItem::init() : " << m_command->name() << endl;
 
849
        char buffer[64];
 
850
        sprintf( buffer, "%064ld", ++g_lastKey );
 
851
        m_key = buffer;
 
852
        setPixmap( 0, QPixmap( KGlobal::iconLoader()->iconPath( m_command->icon(), KIcon::Small ) ) );
 
853
        setText( 0, m_command->name() );
 
854
} // VHistoryITem::init
 
855
 
 
856
VHistoryItem::~VHistoryItem()
 
857
{
 
858
} // VHistoryItem::~VHistoryItem
 
859
 
 
860
void
 
861
VHistoryItem::paintCell( QPainter* p, const QColorGroup& cg, int column, int width, int align )
 
862
{
 
863
        p->fillRect( 0, 0, width - 1, height() - 1, ( m_command->success() ? cg.base() : cg.base().dark( 140 ) ) );
 
864
 
 
865
        const QPixmap* pixmap = this->pixmap( column );
 
866
        int xstart;
 
867
        if ( pixmap )
 
868
        {
 
869
                int pw = pixmap->width();
 
870
                int ph = pixmap->height();
 
871
                p->drawPixmap( ( height() - pw ) / 2, ( height() - ph ) / 2, *pixmap );
 
872
                xstart = height();
 
873
        }
 
874
        else
 
875
                xstart = 4;
 
876
        p->setPen( cg.text() );
 
877
        p->drawText( xstart, 0, width - xstart, height(), align | Qt::AlignVCenter, text( column ) );
 
878
} // VHistoryItem::paintCell
 
879
 
 
880
VHistoryTab::VHistoryTab( KarbonPart* part, QWidget* parent )
 
881
                : QWidget( parent ), m_part( part )
 
882
{
 
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 ) );
 
893
 
 
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++ )
 
901
        {
 
902
                if ( ( i > 0 ) && ( cmds[ i ]->name() == cmds[ i - 1 ]->name() ) )
 
903
                        if ( group )
 
904
                        {
 
905
                                QListViewItem* prev = group->firstChild();
 
906
                                while ( prev && prev->nextSibling() )
 
907
                                        prev = prev->nextSibling();
 
908
                                new VHistoryItem( cmds[ i ], group, prev );
 
909
                        }
 
910
                        else
 
911
                        {
 
912
                                group = new VHistoryGroupItem( last, m_history, last );
 
913
                                new VHistoryItem( cmds[ i ], group, last );
 
914
                        }
 
915
                else
 
916
                {
 
917
                        last = new VHistoryItem( cmds[ i ], m_history, last );
 
918
                        group = 0;
 
919
                }
 
920
        }
 
921
        m_history->sort();
 
922
 
 
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
 
935
 
 
936
VHistoryTab::~VHistoryTab()
 
937
{
 
938
} // VHistoryTab::~VHistoryTab
 
939
 
 
940
bool
 
941
VHistoryTab::groupingEnabled()
 
942
{
 
943
        return m_groupCommands->isChecked();
 
944
} // VHistoryTab::groupingEnabled
 
945
 
 
946
void
 
947
VHistoryTab::historyCleared()
 
948
{
 
949
        m_history->clear();
 
950
} // VHistoryTab::historyCleared
 
951
 
 
952
void
 
953
VHistoryTab::commandExecuted( VCommand* command )
 
954
{
 
955
        QListViewItem* item = m_history->firstChild();
 
956
        bool found = false;
 
957
        while ( !found && item )
 
958
        {
 
959
                if ( item->rtti() == 1001 )
 
960
                {
 
961
                        QListViewItem* child = item->firstChild();
 
962
                        while ( !found && child )
 
963
                        {
 
964
                                found = ( ( (VHistoryItem*)child )->command() == command );
 
965
                                if ( !found )
 
966
                                        child = child->nextSibling();
 
967
                                else
 
968
                                        item = child;
 
969
                        }
 
970
                }
 
971
                found = ( item && ( (VHistoryItem*)item )->command() == command );
 
972
                if ( !found )
 
973
                        item = item->nextSibling();
 
974
        }
 
975
        if ( found )
 
976
        {
 
977
                m_history->repaintItem( item );
 
978
                if ( item->parent() )
 
979
                        m_history->repaintItem( item->parent() );
 
980
                m_history->ensureItemVisible( item );
 
981
        }
 
982
} // VHistoryTab::commandExecuted
 
983
 
 
984
void
 
985
VHistoryTab::slotCommandAdded( VCommand* command )
 
986
{
 
987
        if ( !command )
 
988
                return;
 
989
 
 
990
        QListViewItem* last = m_history->firstChild();
 
991
        while ( last && last->nextSibling() )
 
992
                last = last->nextSibling();
 
993
 
 
994
        if( groupingEnabled() )
 
995
        {
 
996
                if( ( last ) && last->text( 0 ) == command->name() )
 
997
                {
 
998
                        if( last->rtti() == 1002 )
 
999
                        {
 
1000
                                QListViewItem* prevSibling;
 
1001
                                if( m_history->childCount() > 1 )
 
1002
                                {
 
1003
                                        prevSibling = m_history->firstChild();
 
1004
                                        while ( prevSibling->nextSibling() != last )
 
1005
                                                prevSibling = prevSibling->nextSibling();
 
1006
                                }
 
1007
                                else
 
1008
                                        prevSibling = m_history->firstChild();
 
1009
                                last = new VHistoryGroupItem( (VHistoryItem*)last, m_history, prevSibling );
 
1010
                        }
 
1011
                        QListViewItem* prev = last->firstChild();
 
1012
                        while ( prev && prev->nextSibling() )
 
1013
                                prev = prev->nextSibling();
 
1014
                        m_history->setCurrentItem( new VHistoryItem( command, (VHistoryGroupItem*)last, prev ) );
 
1015
                }
 
1016
                else
 
1017
                        m_history->setCurrentItem( new VHistoryItem( command, m_history, last ) );
 
1018
        }
 
1019
        else
 
1020
                m_history->setCurrentItem( new VHistoryItem( command, m_history, last ) );
 
1021
 
 
1022
        m_history->sort();
 
1023
        m_history->ensureItemVisible( m_history->currentItem() );
 
1024
        m_history->update();
 
1025
} // VHistoryTab::slotCommandAdded
 
1026
 
 
1027
void
 
1028
VHistoryTab::removeFirstCommand()
 
1029
{
 
1030
        if ( m_history->childCount() > 0 )
 
1031
                if ( m_history->firstChild()->rtti() == 1002 )
 
1032
                        delete m_history->firstChild();
 
1033
                else
 
1034
                {
 
1035
                        VHistoryGroupItem* group = (VHistoryGroupItem*)m_history->firstChild();
 
1036
                        delete group->firstChild();
 
1037
                        if ( group->childCount() == 1 )
 
1038
                        {
 
1039
                                new VHistoryItem( ( (VHistoryItem*)group->firstChild() )->command(), m_history, 0 );
 
1040
                                delete group;
 
1041
                        }
 
1042
                }
 
1043
} // VHistoryTab::removeFirstCommand
 
1044
 
 
1045
void
 
1046
VHistoryTab::removeLastCommand()
 
1047
{
 
1048
        if ( m_history->childCount() > 0 )
 
1049
        {
 
1050
                QListViewItem* last = m_history->firstChild();
 
1051
                while ( last && last->nextSibling() )
 
1052
                        last = last->nextSibling();
 
1053
                if ( last->rtti() == 1002 )
 
1054
                        delete last;
 
1055
                else
 
1056
                {
 
1057
                        VHistoryGroupItem* group = (VHistoryGroupItem*)last;
 
1058
                        last = group->firstChild();
 
1059
                        while ( last && last->nextSibling() )
 
1060
                                last = last->nextSibling();
 
1061
                        delete last;
 
1062
                        if ( group->childCount() == 1 )
 
1063
                        {
 
1064
                                new VHistoryItem( ( (VHistoryItem*)group->firstChild() )->command(), m_history, group );
 
1065
                                delete group;
 
1066
                        }
 
1067
                }
 
1068
        }
 
1069
} // VHistoryTab::removeLastCommand
 
1070
 
 
1071
void
 
1072
VHistoryTab::commandClicked( int button, QListViewItem* item, const QPoint&, int )
 
1073
{
 
1074
        if ( !item || item->rtti() == 1001 )
 
1075
                return;
 
1076
 
 
1077
        VCommand* cmd = ( (VHistoryItem*)item )->command();
 
1078
        if ( cmd->success() )
 
1079
                if ( button == 1 )
 
1080
                        emit undoCommandsTo( ( (VHistoryItem*)item )->command() );
 
1081
                else
 
1082
                        emit undoCommand( ( (VHistoryItem*)item )->command() );
 
1083
        else
 
1084
                if ( button == 1 )
 
1085
                        emit redoCommandsTo( ( (VHistoryItem*)item )->command() );
 
1086
                else
 
1087
                        emit redoCommand( ( (VHistoryItem*)item )->command() );
 
1088
} // VHistoryTab::commandClicked
 
1089
 
 
1090
void
 
1091
VHistoryTab::groupingChanged( int )
 
1092
{
 
1093
        if ( m_groupCommands->isChecked() && m_history->childCount() > 1 )
 
1094
        {
 
1095
                QListViewItem* s2last = 0;
 
1096
                QListViewItem* last = m_history->firstChild();
 
1097
                QListViewItem* item = last->nextSibling();
 
1098
                while ( item )
 
1099
                        if ( last->text( 0 ) == item->text( 0 ) )
 
1100
                        {
 
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();
 
1106
                        }
 
1107
                        else
 
1108
                        {
 
1109
                                s2last = last;
 
1110
                                last = item;
 
1111
                                item = last->nextSibling();
 
1112
                        }
 
1113
        }
 
1114
        else
 
1115
        {
 
1116
                QListViewItem* item = m_history->firstChild();
 
1117
                while ( item )
 
1118
                        if ( item->rtti() == 1001 )
 
1119
                        {
 
1120
                                QListViewItem* child;
 
1121
                                while ( ( child = item->firstChild() ) )
 
1122
                                {
 
1123
                                        item->takeItem( child );
 
1124
                                        m_history->insertItem( child );
 
1125
                                }
 
1126
                                child = item;
 
1127
                                item = item->nextSibling();
 
1128
                                delete child;
 
1129
                        }
 
1130
                        else
 
1131
                                item = item->nextSibling();
 
1132
        }
 
1133
        m_history->sort();
 
1134
        m_history->update();
 
1135
} // VHistoryTab::groupingChanged
 
1136
 
 
1137
/*************************************************************************
 
1138
 *  Document docker                                                      *
 
1139
 *************************************************************************/
 
1140
 
 
1141
VDocumentDocker::VDocumentDocker( KarbonView* view )
 
1142
                : VDocker( view )
 
1143
{
 
1144
        setCaption( i18n( "Overview" ) );
 
1145
 
 
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" ) );
 
1152
 
 
1153
        setFixedSize( 200, 200 );
 
1154
} // VDocumentDocker::VDocumentDocker
 
1155
 
 
1156
VDocumentDocker::~VDocumentDocker()
 
1157
{
 
1158
} // VDocumentDocker::~VDocumentDocker
 
1159
 
 
1160
#include "vdocumentdocker.moc"