00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "karbon_view.h"
00021
00022 #include <qdragobject.h>
00023 #include <qiconset.h>
00024 #include <qapplication.h>
00025 #include <qclipboard.h>
00026 #include <qpopupmenu.h>
00027 #include <qpaintdevicemetrics.h>
00028 #include <qpainter.h>
00029
00030 #include <kaction.h>
00031 #include <kcolordrag.h>
00032 #include <klocale.h>
00033 #include <kiconloader.h>
00034 #include <kmessagebox.h>
00035 #include <kdeversion.h>
00036 #include <kprinter.h>
00037
00038 #include <KoMainWindow.h>
00039 #include <KoFilterManager.h>
00040 #include <kstatusbar.h>
00041 #include <kfiledialog.h>
00042 #include <kstdaction.h>
00043 #include <KoContextCelp.h>
00044 #include <KoUnitWidgets.h>
00045 #include <KoPageLayoutDia.h>
00046 #include <vruler.h>
00047 #include <Kolinestyleaction.h>
00048
00049
00050 #include "valigncmd.h"
00051 #include "vcleanupcmd.h"
00052 #include "vclipartcmd.h"
00053 #include "vclosepathcmd.h"
00054 #include "vdeletecmd.h"
00055 #include "vdistributecmd.h"
00056 #include "vfillcmd.h"
00057 #include "vgroupcmd.h"
00058 #include "vstrokecmd.h"
00059 #include "vtransformcmd.h"
00060 #include "vinsertcmd.h"
00061 #include "vungroupcmd.h"
00062 #include "vzordercmd.h"
00063
00064
00065 #include "vconfiguredlg.h"
00066
00067
00068 #include <kopalettemanager.h>
00069 #include "vcolordocker.h"
00070 #include "vdocumentdocker.h"
00071 #include "vstrokedocker.h"
00072 #include "vstyledocker.h"
00073 #include "vtransformdocker.h"
00074
00075
00076
00077
00078
00079 #include "vsmallpreview.h"
00080
00081
00082 #include "karbon_factory.h"
00083 #include "karbon_part.h"
00084 #include "karbon_view_iface.h"
00085 #include "vglobal.h"
00086 #include "vselection.h"
00087 #include "vtool.h"
00088 #include "vtoolcontroller.h"
00089 #include "vcomposite.h"
00090 #include "vgroup.h"
00091 #include "vpainterfactory.h"
00092 #include "vqpainter.h"
00093 #include "vkopainter.h"
00094 #include "vstrokefillpreview.h"
00095 #include "vtypebuttonbox.h"
00096 #include "vstatebutton.h"
00097 #include "vcanvas.h"
00098 #include "vtoolbox.h"
00099 #include "karbon_drag.h"
00100
00101
00102 #include <unistd.h>
00103
00104
00105 #include <kdebug.h>
00106
00107 const int rulerWidth = 20;
00108 const int rulerHeight = 20;
00109
00110 KarbonView::KarbonView( KarbonPart* p, QWidget* parent, const char* name )
00111 : KoView( p, parent, name ), KXMLGUIBuilder( shell() ), m_part( p )
00112 {
00113 m_toolbox = 0L;
00114 m_toolController = new VToolController( this );
00115 m_toolController->init();
00116
00117 setInstance( KarbonFactory::instance(), true );
00118
00119 setClientBuilder( this );
00120
00121 if( !p->isReadWrite() )
00122 setXMLFile( QString::fromLatin1( "karbon_readonly.rc" ) );
00123 else
00124 setXMLFile( QString::fromLatin1( "karbon.rc" ) );
00125
00126 m_dcop = 0L;
00127 dcopObject();
00128
00129
00130 m_status = new KStatusBarLabel( QString::null, 0, statusBar() );
00131 m_status->setAlignment( AlignLeft | AlignVCenter );
00132 m_status->setMinimumWidth( 300 );
00133 addStatusBarItem( m_status, 1 );
00134 m_cursorCoords = new KStatusBarLabel( QString::null, 0, statusBar() );
00135 m_cursorCoords->setAlignment( AlignLeft | AlignVCenter );
00136 m_cursorCoords->setMinimumWidth( 50 );
00137 addStatusBarItem( m_cursorCoords, 0 );
00138 m_smallPreview = new VSmallPreview( this, name );
00139 addStatusBarItem( m_smallPreview );
00140
00141 initActions();
00142
00143 m_DocumentTab = 0L;
00144 m_LayersTab = 0L;
00145 m_HistoryTab = 0L;
00146 m_strokeFillPreview = 0L;
00147 m_ColorManager = 0L;
00148 m_strokeDocker = 0L;
00149 m_styleDocker = 0L;
00150 m_TransformDocker = 0L;
00151
00152
00153
00154
00155 m_pPaletteManager = new KoPaletteManager(this, actionCollection(), "karbon palette manager");
00156
00157 unsigned int max = part()->maxRecentFiles();
00158 setNumberOfRecentFiles( max );
00159
00160 reorganizeGUI();
00161
00162 connect( p, SIGNAL( unitChanged( KoUnit::Unit ) ), this, SLOT( setUnit( KoUnit::Unit ) ) );
00163
00164
00165 m_horizRuler = new VRuler( Qt::Horizontal, this );
00166 m_horizRuler->setUnit(p->unit());
00167 connect( p, SIGNAL( unitChanged( KoUnit::Unit ) ), m_horizRuler, SLOT( setUnit( KoUnit::Unit ) ) );
00168
00169 m_vertRuler = new VRuler( Qt::Vertical, this );
00170 m_vertRuler->setUnit(p->unit());
00171 connect( p, SIGNAL( unitChanged( KoUnit::Unit ) ), m_vertRuler, SLOT( setUnit( KoUnit::Unit ) ) );
00172
00173 m_canvas = new VCanvas( this, this, p );
00174 connect( m_canvas, SIGNAL( contentsMoving( int, int ) ), this, SLOT( canvasContentsMoving( int, int ) ) );
00175
00176 m_canvas->show();
00177
00178
00179 m_painterFactory = new VPainterFactory;
00180 m_painterFactory->setPainter( canvasWidget()->pixmap(), width(), height() );
00181 m_painterFactory->setEditPainter( canvasWidget()->viewport(), width(), height() );
00182
00183 if( shell() )
00184 {
00185
00186 createColorDock();
00187 createStrokeDock();
00188 createTransformDock();
00189 createDocumentTabDock();
00190 createLayersTabDock();
00191 createHistoryTabDock();
00192 createResourceDock();
00193
00194 if( m_showRulerAction->isChecked() )
00195 {
00196 m_horizRuler->show();
00197 m_vertRuler->show();
00198 }
00199 else
00200 {
00201 m_horizRuler->hide();
00202 m_vertRuler->hide();
00203 }
00204
00205 m_horizRuler->installEventFilter(m_canvas);
00206 m_vertRuler->installEventFilter(m_canvas);
00207 }
00208
00209 zoomChanged();
00210 }
00211
00212 KarbonView::~KarbonView()
00213 {
00214 kdDebug(38000) << "Handling KarbonView dtor" << endl;
00215
00216
00217 delete m_smallPreview;
00218 delete m_status;
00219 delete m_cursorCoords;
00220
00221 delete m_painterFactory;
00222
00223 delete m_canvas;
00224
00225 delete m_dcop;
00226
00227 delete m_toolController;
00228 }
00229
00230 static Qt::Dock stringToDock( const QString& attrPosition )
00231 {
00232 KToolBar::Dock dock = KToolBar::DockTop;
00233 if ( !attrPosition.isEmpty() ) {
00234 if ( attrPosition == "top" )
00235 dock = Qt::DockTop;
00236 else if ( attrPosition == "left" )
00237 dock = Qt::DockLeft;
00238 else if ( attrPosition == "right" )
00239 dock = Qt::DockRight;
00240 else if ( attrPosition == "bottom" )
00241 dock = Qt::DockBottom;
00242 else if ( attrPosition == "floating" )
00243 dock = Qt::DockTornOff;
00244 else if ( attrPosition == "flat" )
00245 dock = Qt::DockMinimized;
00246 }
00247
00248 return dock;
00249 }
00250
00251 QWidget *
00252 KarbonView::createContainer( QWidget *parent, int index, const QDomElement &element, int &id )
00253 {
00254 if( element.attribute( "name" ) == "Tools" )
00255 {
00256 m_toolbox = new VToolBox( mainWindow(), "Tools", KarbonFactory::instance() );
00257 toolController()->setUp( actionCollection(), m_toolbox );
00258
00259 kdDebug() << "Toolbox position: " << element.attribute( "position" ) << "\n";
00260 Dock dock = stringToDock( element.attribute( "position" ).lower() );
00261
00262 mainWindow()->addDockWindow( m_toolbox, dock, false);
00263 mainWindow()->moveDockWindow( m_toolbox, dock, false, 0, 0 );
00264
00265
00266
00267 if( shell() )
00268 {
00269 m_strokeFillPreview = new VStrokeFillPreview( part(), m_toolbox );
00270 m_typeButtonBox = new VTypeButtonBox( part(), m_toolbox );
00271
00272 connect( m_strokeFillPreview, SIGNAL( fillSelected() ), m_typeButtonBox, SLOT( setFill() ) );
00273 connect( m_strokeFillPreview, SIGNAL( strokeSelected() ), m_typeButtonBox, SLOT( setStroke() ) );
00274
00275 connect( m_strokeFillPreview, SIGNAL( strokeChanged( const VStroke & ) ), this, SLOT( slotStrokeChanged( const VStroke & ) ) );
00276 connect( m_strokeFillPreview, SIGNAL( fillChanged( const VFill & ) ), this, SLOT( slotFillChanged( const VFill & ) ) );
00277
00278 connect( m_strokeFillPreview, SIGNAL( strokeSelected() ), m_ColorManager, SLOT( setStrokeDocker() ) );
00279 connect( m_strokeFillPreview, SIGNAL( fillSelected( ) ), m_ColorManager, SLOT( setFillDocker() ) );
00280 selectionChanged();
00281
00282
00283
00284
00285 }
00286 }
00287
00288 return KXMLGUIBuilder::createContainer( parent, index, element, id );
00289 }
00290
00291 void
00292 KarbonView::removeContainer( QWidget *container, QWidget *parent,
00293 QDomElement &element, int id )
00294 {
00295 if( container )
00296 kdDebug(38000) << container << endl;
00297
00298 if( shell() && container == m_toolbox )
00299 {
00300 delete m_toolbox;
00301 m_toolbox = 0L;
00302 m_toolController->youAintGotNoToolBox();
00303
00304 m_strokeFillPreview = 0;
00305
00306 m_typeButtonBox = 0;
00307
00308
00309 }
00310 else
00311 KXMLGUIBuilder::removeContainer( container, parent, element, id );
00312 }
00313
00314
00315 DCOPObject *
00316 KarbonView::dcopObject()
00317 {
00318 if( !m_dcop )
00319 m_dcop = new KarbonViewIface( this );
00320
00321 return m_dcop;
00322 }
00323
00324 QWidget*
00325 KarbonView::canvas() const
00326 {
00327 return m_canvas;
00328 }
00329
00330 void
00331 KarbonView::resizeEvent( QResizeEvent* )
00332 {
00333 if( shell() && m_showRulerAction->isChecked())
00334 {
00335 m_canvas->setGeometry( rulerWidth, rulerHeight, width() - rulerWidth, height() - rulerHeight );
00336 updateRuler();
00337 }
00338 else
00339 {
00340 m_horizRuler->hide();
00341 m_vertRuler->hide();
00342 m_canvas->setGeometry( 0, 0, width(), height() );
00343 }
00344
00345 zoomChanged();
00346 reorganizeGUI();
00347 }
00348
00349 void
00350 KarbonView::dropEvent( QDropEvent *e )
00351 {
00352
00353 QColor color;
00354 VColor realcolor;
00355 VObjectList selection;
00356
00357 if( KColorDrag::decode( e, color ) )
00358 {
00359 float r = color.red() / 255.0;
00360 float g = color.green() / 255.0;
00361 float b = color.blue() / 255.0;
00362
00363 realcolor.set( r, g, b );
00364
00365 if( part() )
00366 if( m_strokeFillPreview->strokeIsSelected() )
00367 part()->addCommand( new VStrokeCmd( &part()->document(), realcolor ), true );
00368 else
00369 part()->addCommand( new VFillCmd( &part()->document(), realcolor ), true );
00370 }
00371 else if( KarbonDrag::decode( e, selection, m_part->document() ) )
00372 {
00373 VObject *clipart = selection.first();
00374 KoPoint p( e->pos() );
00375 p = m_canvas->toContents( p );
00376 QWMatrix mat( 1, 0, 0, 1, p.x(), p.y() );
00377
00378 VTransformCmd trafo( 0L, mat );
00379 trafo.visit( *clipart );
00380 VClipartCmd* cmd = new VClipartCmd( &m_part->document(), i18n( "Insert Clipart" ), clipart );
00381
00382 m_part->addCommand( cmd, true );
00383 }
00384 }
00385
00386 void
00387 KarbonView::print( KPrinter &printer )
00388 {
00389
00390 kdDebug(38000) << "KarbonView::print" << endl;
00391
00392 QPaintDeviceMetrics metrics( ( QPaintDevice * ) & printer );
00393 printer.setFullPage( true );
00394
00395
00396 double zoom = metrics.logicalDpiX() / 72.0;
00397
00398 QWMatrix mat;
00399 mat.scale( 1, -1 );
00400 mat.translate( 0, -part()->document().height()*zoom );
00401
00402 double w = zoom*part()->document().width();
00403 double h = zoom*part()->document().height();
00404
00405 KoRect rect( 0, 0, w, h );
00406
00407 QPixmap img( static_cast<int>( w ), static_cast<int>( h ) );
00408
00409
00410 VKoPainter kop( ( QPaintDevice * )&img, static_cast<int>( w ), static_cast<int>( h ) );
00411
00412 kop.setZoomFactor( zoom );
00413 kop.setWorldMatrix( mat );
00414
00415 kop.begin();
00416
00417 part()->document().draw( &kop, &rect );
00418
00419 kop.end();
00420
00421 QPainter p;
00422
00423
00424
00425
00426 p.begin( &printer );
00427 p.drawPixmap( 0, 0, img );
00428 p.end();
00429 }
00430
00431 void
00432 KarbonView::fileImportGraphic()
00433 {
00434 QStringList filter;
00435 filter << "application/x-karbon" << "image/svg+xml" << "image/x-wmf" << "image/x-eps" << "application/postscript";
00436 KFileDialog *dialog = new KFileDialog( "foo", QString::null, 0L, "Choose Graphic to Add", true);
00437 dialog->setMimeFilter( filter, "application/x-karbon" );
00438 if(dialog->exec()!=QDialog::Accepted) {
00439 delete dialog;
00440 return;
00441 }
00442 QString fname = dialog->selectedFile();
00443
00444
00445
00446 if( part()->nativeFormatMimeType() == dialog->currentMimeFilter().latin1() )
00447 part()->mergeNativeFormat( fname );
00448 else
00449 {
00450 KoFilterManager man( part() );
00451 KoFilter::ConversionStatus status;
00452 QString importedFile = man.import( fname, status );
00453 part()->mergeNativeFormat( importedFile );
00454 if( !importedFile.isEmpty() )
00455 unlink( QFile::encodeName( importedFile ) );
00456 }
00457 delete dialog;
00458 part()->repaintAllViews();
00459 }
00460
00461 void
00462 KarbonView::editCut()
00463 {
00464 addSelectionToClipboard();
00465
00466 editDeleteSelection();
00467 }
00468
00469 void
00470 KarbonView::editCopy()
00471 {
00472 addSelectionToClipboard();
00473 }
00474
00475 void
00476 KarbonView::addSelectionToClipboard() const
00477 {
00478 if( part()->document().selection()->objects().count() <= 0 )
00479 return;
00480
00481 KarbonDrag* kd = new KarbonDrag();
00482 kd->setObjectList( part()->document().selection()->objects() );
00483 QApplication::clipboard()->setData( kd );
00484 }
00485
00486 void
00487 KarbonView::editPaste()
00488 {
00489 KarbonDrag kd;
00490 VObjectList objects;
00491
00492 if( !kd.decode( QApplication::clipboard()->data(), objects, part()->document() ) )
00493 return;
00494
00495
00496 double copyOffset = part()->instance()->config()->readNumEntry( "CopyOffset", 10 );
00497 part()->addCommand( new VInsertCmd( &part()->document(),
00498 objects.count() == 1
00499 ? i18n( "Paste Object" )
00500 : i18n( "Paste Objects" ),
00501 &objects, copyOffset ),
00502 true );
00503
00504 part()->repaintAllViews();
00505 selectionChanged();
00506 }
00507
00508 void
00509 KarbonView::editSelectAll()
00510 {
00511 part()->document().selection()->append();
00512
00513 if( part()->document().selection()->objects().count() > 0 )
00514 part()->repaintAllViews();
00515
00516 selectionChanged();
00517 }
00518
00519 void
00520 KarbonView::editDeselectAll()
00521 {
00522 if( part()->document().selection()->objects().count() > 0 )
00523 {
00524 part()->document().selection()->clear();
00525 part()->repaintAllViews();
00526 }
00527
00528 selectionChanged();
00529 }
00530
00531 void
00532 KarbonView::editDeleteSelection()
00533 {
00534 kdDebug(38000) << "*********" << endl;
00535
00536 if( part()->document().selection()->objects().count() > 0 )
00537 {
00538 part()->addCommand(
00539 new VDeleteCmd( &part()->document() ),
00540 true );
00541 }
00542 }
00543
00544 void
00545 KarbonView::editPurgeHistory()
00546 {
00547
00548
00549 if( KMessageBox::warningContinueCancel( this,
00550 i18n( "This action cannot be undone later. Do you really want to continue?" ),
00551 i18n( "Purge History" ),
00552 KStdGuiItem::del(),
00553 "edit_purge_history" ) )
00554 {
00555
00556
00557 VCleanUpCmd cmd( &part()->document() );
00558 cmd.execute();
00559
00560 part()->clearHistory();
00561 }
00562 }
00563
00564 void
00565 KarbonView::selectionAlignHorizontalLeft()
00566 {
00567 part()->addCommand(
00568 new VAlignCmd( &part()->document(), VAlignCmd::ALIGN_HORIZONTAL_LEFT ), true );
00569 }
00570 void
00571 KarbonView::selectionAlignHorizontalCenter()
00572 {
00573 part()->addCommand(
00574 new VAlignCmd( &part()->document(), VAlignCmd::ALIGN_HORIZONTAL_CENTER ), true );
00575 }
00576
00577 void
00578 KarbonView::selectionAlignHorizontalRight()
00579 {
00580 part()->addCommand(
00581 new VAlignCmd( &part()->document(), VAlignCmd::ALIGN_HORIZONTAL_RIGHT ), true );
00582 }
00583
00584 void
00585 KarbonView::selectionAlignVerticalTop()
00586 {
00587 part()->addCommand(
00588 new VAlignCmd( &part()->document(), VAlignCmd::ALIGN_VERTICAL_TOP ), true );
00589 }
00590
00591 void
00592 KarbonView::selectionAlignVerticalCenter()
00593 {
00594 part()->addCommand(
00595 new VAlignCmd( &part()->document(), VAlignCmd::ALIGN_VERTICAL_CENTER ), true );
00596 }
00597
00598 void
00599 KarbonView::selectionAlignVerticalBottom()
00600 {
00601 part()->addCommand(
00602 new VAlignCmd( &part()->document(), VAlignCmd::ALIGN_VERTICAL_BOTTOM ), true );
00603 }
00604
00605 void
00606 KarbonView::selectionDistributeHorizontalCenter()
00607 {
00608 part()->addCommand(
00609 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_HORIZONTAL_CENTER ), true );
00610 }
00611
00612 void
00613 KarbonView::selectionDistributeHorizontalGap()
00614 {
00615 part()->addCommand(
00616 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_HORIZONTAL_GAP ), true );
00617 }
00618
00619 void
00620 KarbonView::selectionDistributeHorizontalLeft()
00621 {
00622 part()->addCommand(
00623 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_HORIZONTAL_LEFT ), true );
00624 }
00625
00626 void
00627 KarbonView::selectionDistributeHorizontalRight()
00628 {
00629 part()->addCommand(
00630 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_HORIZONTAL_RIGHT ), true );
00631 }
00632
00633 void
00634 KarbonView::selectionDistributeVerticalCenter()
00635 {
00636 part()->addCommand(
00637 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_VERTICAL_CENTER ), true );
00638 }
00639
00640 void
00641 KarbonView::selectionDistributeVerticalGap()
00642 {
00643 part()->addCommand(
00644 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_VERTICAL_GAP ), true );
00645 }
00646
00647 void
00648 KarbonView::selectionDistributeVerticalBottom()
00649 {
00650 part()->addCommand(
00651 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_VERTICAL_BOTTOM ), true );
00652 }
00653
00654 void
00655 KarbonView::selectionDistributeVerticalTop()
00656 {
00657 part()->addCommand(
00658 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_VERTICAL_TOP ), true );
00659 }
00660
00661 void
00662 KarbonView::selectionDuplicate()
00663 {
00664 if ( !part()->document().selection()->objects().count() )
00665 return;
00666
00667 VObjectList objects;
00668
00669
00670 VObjectListIterator itr( part()->document().selection()->objects() );
00671 for ( ; itr.current() ; ++itr ) {
00672 objects.append( itr.current()->clone() );
00673 }
00674
00675
00676 double copyOffset = part()->instance()->config()->readNumEntry( "CopyOffset", 10 );
00677 part()->addCommand( new VInsertCmd( &part()->document(),
00678 objects.count() == 1
00679 ? i18n( "Duplicate Object" )
00680 : i18n( "Duplicate Objects" ),
00681 &objects, copyOffset ),
00682 true );
00683
00684 part()->repaintAllViews();
00685 selectionChanged();
00686 }
00687
00688 void
00689 KarbonView::selectionBringToFront()
00690 {
00691 part()->addCommand(
00692 new VZOrderCmd( &part()->document(), VZOrderCmd::bringToFront ), true );
00693 }
00694
00695 void
00696 KarbonView::selectionMoveUp()
00697 {
00698 part()->addCommand(
00699 new VZOrderCmd( &part()->document(), VZOrderCmd::up ), true );
00700 }
00701
00702 void
00703 KarbonView::selectionMoveDown()
00704 {
00705 part()->addCommand(
00706 new VZOrderCmd( &part()->document(), VZOrderCmd::down ), true );
00707 }
00708
00709 void
00710 KarbonView::selectionSendToBack()
00711 {
00712 part()->addCommand(
00713 new VZOrderCmd( &part()->document(), VZOrderCmd::sendToBack ), true );
00714 }
00715
00716 void
00717 KarbonView::groupSelection()
00718 {
00719 part()->addCommand( new VGroupCmd( &part()->document() ), true );
00720 }
00721
00722 void
00723 KarbonView::ungroupSelection()
00724 {
00725 part()->addCommand( new VUnGroupCmd( &part()->document() ), true );
00726 }
00727
00728 void
00729 KarbonView::closePath()
00730 {
00731 part()->addCommand( new VClosePathCmd( &part()->document() ), true );
00732 }
00733
00734 void
00735 KarbonView::slotActiveToolChanged( VTool *tool )
00736 {
00737 toolController()->setCurrentTool( tool );
00738
00739 m_canvas->repaintAll();
00740 }
00741
00742 void
00743 KarbonView::viewModeChanged()
00744 {
00745 canvasWidget()->pixmap()->fill();
00746
00747 if( m_viewAction->currentItem() == 1 )
00748 m_painterFactory->setWireframePainter( canvasWidget()->pixmap(), width(), height() );
00749 else
00750 m_painterFactory->setPainter( canvasWidget()->pixmap(), width(), height() );
00751
00752 m_canvas->repaintAll();
00753 }
00754
00755 void
00756 KarbonView::setZoomAt( double zoom, const KoPoint &p )
00757 {
00758 QString zoomText = QString( "%1%" ).arg( zoom * 100.0, 0, 'f', 2 );
00759 QStringList stl = m_zoomAction->items();
00760 if( stl.first() == "25%" )
00761 {
00762 stl.prepend( zoomText.latin1() );
00763 m_zoomAction->setItems( stl );
00764 m_zoomAction->setCurrentItem( 0 );
00765 }
00766 else
00767 {
00768 m_zoomAction->setCurrentItem( 0 );
00769 m_zoomAction->changeItem( m_zoomAction->currentItem(), zoomText.latin1() );
00770 }
00771 zoomChanged( p );
00772 }
00773
00774 void
00775 KarbonView::viewZoomIn()
00776 {
00777 setZoomAt( zoom() * 1.50 );
00778 }
00779
00780 void
00781 KarbonView::viewZoomOut()
00782 {
00783 setZoomAt( zoom() * 0.75 );
00784 }
00785
00786 void
00787 KarbonView::zoomChanged( const KoPoint &p )
00788 {
00789 double centerX;
00790 double centerY;
00791 double zoomFactor;
00792
00793 if( !p.isNull() )
00794 {
00795 centerX = ( ( p.x() ) * zoom() + m_canvas->pageOffsetX() ) / double( m_canvas->contentsWidth() );
00796 centerY = 1 - ( ( p.y() ) * zoom() + m_canvas->pageOffsetY() ) / double( m_canvas->contentsHeight() );
00797 zoomFactor = m_zoomAction->currentText().remove( '%' ).toDouble() / 100.0;
00798 }
00799 else if( m_zoomAction->currentText() == i18n("Zoom Width") )
00800 {
00801 centerX = 0.5;
00802 centerY = double( m_canvas->contentsY() + 0.5 * m_canvas->visibleHeight() ) / double( m_canvas->contentsHeight() );
00803 zoomFactor = double( m_canvas->visibleWidth() ) / double( part()->document().width() );
00804 }
00805 else if( m_zoomAction->currentText() == i18n("Whole Page") )
00806 {
00807 centerX = 0.5;
00808 centerY = 0.5;
00809 double zoomFactorX = double( m_canvas->visibleWidth() ) / double( part()->document().width() );
00810 double zoomFactorY = double( m_canvas->visibleHeight() ) / double( part()->document().height() );
00811
00812 if(zoomFactorX < 0 && zoomFactorY > 0)
00813 zoomFactor = zoomFactorY;
00814 else if(zoomFactorX > 0 && zoomFactorY < 0)
00815 zoomFactor = zoomFactorX;
00816 else if(zoomFactorX < 0 && zoomFactorY < 0)
00817 zoomFactor = 0.0001;
00818 else
00819 zoomFactor = kMin( zoomFactorX, zoomFactorY );
00820 }
00821 else
00822 {
00823 if( m_canvas->contentsWidth() > m_canvas->visibleWidth() )
00824 centerX = double( m_canvas->contentsX() + 0.5 * m_canvas->visibleWidth() ) / double( m_canvas->contentsWidth() );
00825 else
00826 centerX = 0.5;
00827 if( m_canvas->contentsHeight() > m_canvas->visibleHeight() )
00828 centerY = double( m_canvas->contentsY() + 0.5 * m_canvas->visibleHeight() ) / double( m_canvas->contentsHeight() );
00829 else
00830 centerY = 0.5;
00831 zoomFactor = m_zoomAction->currentText().remove( '%' ).toDouble() / 100.0;
00832 }
00833 kdDebug(38000) << "centerX : " << centerX << endl;
00834 kdDebug(38000) << "centerY : " << centerY << endl;
00835 kdDebug(38000) << "zoomFactor : " << zoomFactor << endl;
00836 if( zoomFactor == 0.0 ) return;
00837
00838
00839 if( zoomFactor > 20 )
00840 {
00841 zoomFactor = 20;
00842 m_zoomAction->changeItem( m_zoomAction->currentItem(), " 2000%" );
00843 }
00844
00845 KoView::setZoom( zoomFactor );
00846
00847 m_canvas->viewport()->setUpdatesEnabled( false );
00848
00849 m_canvas->resizeContents( int( ( part()->pageLayout().ptWidth + 300 ) * zoomFactor ),
00850 int( ( part()->pageLayout().ptHeight + 460 ) * zoomFactor ) );
00851
00852
00853 VPainter *painter = painterFactory()->editpainter();
00854 painter->setZoomFactor( zoomFactor );
00855
00856 m_canvas->setViewport( centerX, centerY );
00857 m_canvas->repaintAll();
00858 m_canvas->viewport()->setUpdatesEnabled( true );
00859
00860
00861 if( shell() && m_showRulerAction->isChecked() )
00862 {
00863 m_horizRuler->setZoom( zoomFactor );
00864 m_vertRuler->setZoom( zoomFactor );
00865 m_canvas->setGeometry( rulerWidth, rulerHeight, width() - rulerWidth, height() - rulerHeight );
00866 updateRuler();
00867 }
00868 else
00869 {
00870 m_horizRuler->hide();
00871 m_vertRuler->hide();
00872 }
00873 m_canvas->viewport()->setFocus();
00874
00875 emit zoomChanged( zoomFactor );
00876 }
00877
00878 void
00879 KarbonView::setLineStyle( int style )
00880 {
00881 QValueList<float> dashes;
00882 if( style == Qt::NoPen )
00883 part()->addCommand( new VStrokeCmd( &part()->document(), dashes << 0 << 20 ), true );
00884 else if( style == Qt::SolidLine )
00885 part()->addCommand( new VStrokeCmd( &part()->document(), dashes ), true );
00886 else if( style == Qt::DashLine )
00887 part()->addCommand( new VStrokeCmd( &part()->document(), dashes << 12 << 6 ), true );
00888 else if( style == Qt::DotLine )
00889 part()->addCommand( new VStrokeCmd( &part()->document(), dashes << 2 << 2 ), true );
00890 else if( style == Qt::DashDotLine )
00891 part()->addCommand( new VStrokeCmd( &part()->document(), dashes << 12 << 2 << 2 << 2 ), true );
00892 else if( style == Qt::DashDotDotLine )
00893 part()->addCommand( new VStrokeCmd( &part()->document(), dashes << 12 << 2 << 2 << 2 << 2 << 2 ), true );
00894 }
00895
00896 void
00897 KarbonView::slotStrokeChanged( const VStroke &c )
00898 {
00899 part()->document().selection()->setStroke( c );
00900 selectionChanged();
00901 }
00902
00903 void
00904 KarbonView::slotFillChanged( const VFill &f )
00905 {
00906 part()->document().selection()->setFill( f );
00907 selectionChanged();
00908 }
00909
00910 void
00911 KarbonView::setLineWidth()
00912 {
00913 setLineWidth( m_setLineWidth->value() );
00914 selectionChanged();
00915 }
00916
00917
00918 void
00919 KarbonView::setLineWidth( double val )
00920 {
00921 part()->addCommand( new VStrokeCmd( &part()->document(), val ), true );
00922 }
00923
00924 void
00925 KarbonView::initActions()
00926 {
00927
00928 m_viewAction = new KSelectAction(
00929 i18n( "View &Mode" ), 0, this,
00930 SLOT( viewModeChanged() ), actionCollection(), "view_mode" );
00931
00932 m_zoomAction = new KSelectAction(
00933 i18n( "&Zoom" ), "viewmag", 0, this,
00934 SLOT( zoomChanged() ), actionCollection(), "view_zoom" );
00935
00936 QStringList mstl;
00937 mstl << i18n( "Normal" ) << i18n( "Wireframe" );
00938 m_viewAction->setItems( mstl );
00939 m_viewAction->setCurrentItem( 0 );
00940 m_viewAction->setEditable( false );
00941
00942 QStringList stl;
00943
00944 stl << i18n( "25%" );
00945
00946 stl << i18n( "50%" );
00947
00948 stl << i18n( "100%" );
00949
00950 stl << i18n( "200%" );
00951
00952 stl << i18n( "300%" );
00953
00954 stl << i18n( "400%" );
00955
00956 stl << i18n( "800%" );
00957 stl << i18n( "Whole Page" )
00958 << i18n( "Zoom Width" );
00959
00960 m_zoomAction->setItems( stl );
00961 m_zoomAction->setEditable( true );
00962 m_zoomAction->setCurrentItem( 7 );
00963
00964 KStdAction::zoomIn( this, SLOT( viewZoomIn() ), actionCollection(), "view_zoom_in" );
00965 KStdAction::zoomOut( this, SLOT( viewZoomOut() ), actionCollection(), "view_zoom_out" );
00966
00967 m_showPageMargins = new KToggleAction( i18n("Show Page Margins"), "view_margins", 0, actionCollection(), "view_show_margins" );
00968 connect( m_showPageMargins, SIGNAL(toggled(bool)), SLOT(togglePageMargins(bool)));
00969 #if KDE_IS_VERSION(3,2,90)
00970 m_showPageMargins->setCheckedState(i18n("Hide Page Margins"));
00971 #endif
00972
00973
00974 if( !shell() )
00975 return;
00976
00977
00978 KStdAction::cut( this,
00979 SLOT( editCut() ), actionCollection(), "edit_cut" );
00980 KStdAction::copy( this,
00981 SLOT( editCopy() ), actionCollection(), "edit_copy" );
00982 KStdAction::paste( this,
00983 SLOT( editPaste() ), actionCollection(), "edit_paste" );
00984 KStdAction::selectAll( this, SLOT( editSelectAll() ), actionCollection(), "edit_select_all" );
00985 KStdAction::deselect( this, SLOT( editDeselectAll() ), actionCollection(), "edit_deselect_all" );
00986
00987 new KAction(
00988 i18n( "&Import Graphic..." ), 0, 0, this,
00989 SLOT( fileImportGraphic() ), actionCollection(), "file_import" );
00990 m_deleteSelectionAction = new KAction(
00991 i18n( "D&elete" ), "editdelete", QKeySequence( "Del" ), this,
00992 SLOT( editDeleteSelection() ), actionCollection(), "edit_delete" );
00993 new KAction(
00994 i18n( "&History" ), 0, 0, this,
00995 SLOT( editPurgeHistory() ), actionCollection(), "edit_purge_history" );
00996
00997
00998
00999 new KAction(
01000 i18n( "&Duplicate" ), "duplicate", QKeySequence( "Ctrl+D" ), this,
01001 SLOT( selectionDuplicate() ), actionCollection(), "object_duplicate" );
01002 new KAction(
01003 i18n( "Bring to &Front" ), "bring_forward", QKeySequence( "Ctrl+Shift+]" ), this,
01004 SLOT( selectionBringToFront() ), actionCollection(), "object_move_totop" );
01005 new KAction(
01006 i18n( "&Raise" ), "raise", QKeySequence( "Ctrl+]" ), this,
01007 SLOT( selectionMoveUp() ), actionCollection(), "object_move_up" );
01008 new KAction(
01009 i18n( "&Lower" ), "lower", QKeySequence( "Ctrl+[" ), this,
01010 SLOT( selectionMoveDown() ), actionCollection(), "object_move_down" );
01011 new KAction(
01012 i18n( "Send to &Back" ), "send_backward", QKeySequence( "Ctrl+Shift+[" ), this,
01013 SLOT( selectionSendToBack() ), actionCollection(), "object_move_tobottom" );
01014
01015 new KAction(
01016 i18n( "Align Left" ), "aoleft", 0, this,
01017 SLOT( selectionAlignHorizontalLeft() ),
01018 actionCollection(), "object_align_horizontal_left" );
01019 new KAction(
01020 i18n( "Align Center (Horizontal)" ), "aocenterh", 0, this,
01021 SLOT( selectionAlignHorizontalCenter() ),
01022 actionCollection(), "object_align_horizontal_center" );
01023 new KAction(
01024 i18n( "Align Right" ), "aoright", 0, this,
01025 SLOT( selectionAlignHorizontalRight() ),
01026 actionCollection(), "object_align_horizontal_right" );
01027 new KAction(
01028 i18n( "Align Top" ), "aotop", 0, this,
01029 SLOT( selectionAlignVerticalTop() ),
01030 actionCollection(), "object_align_vertical_top" );
01031 new KAction(
01032 i18n( "Align Middle (Vertical)" ), "aocenterv", 0, this,
01033 SLOT( selectionAlignVerticalCenter() ),
01034 actionCollection(), "object_align_vertical_center" );
01035 new KAction(
01036 i18n( "Align Bottom" ), "aobottom", 0, this,
01037 SLOT( selectionAlignVerticalBottom() ),
01038 actionCollection(), "object_align_vertical_bottom" );
01039
01040 new KAction(
01041 i18n( "Distribute Center (Horizontal)" ), "", 0, this,
01042 SLOT( selectionDistributeHorizontalCenter() ),
01043 actionCollection(), "object_distribute_horizontal_center" );
01044 new KAction(
01045 i18n( "Distribute Gaps (Horizontal)" ), "", 0, this,
01046 SLOT( selectionDistributeHorizontalGap() ),
01047 actionCollection(), "object_distribute_horizontal_gap" );
01048 new KAction(
01049 i18n( "Distribute Left Borders" ), "", 0, this,
01050 SLOT( selectionDistributeHorizontalLeft() ),
01051 actionCollection(), "object_distribute_horizontal_left" );
01052 new KAction(
01053 i18n( "Distribute Right Borders" ), "", 0, this,
01054 SLOT( selectionDistributeHorizontalRight() ),
01055 actionCollection(), "object_distribute_horizontal_right" );
01056 new KAction(
01057 i18n( "Distribute Center (Vertical)" ), "", 0, this,
01058 SLOT( selectionDistributeVerticalCenter() ),
01059 actionCollection(), "object_distribute_vertical_center" );
01060 new KAction(
01061 i18n( "Distribute Gaps (Vertical)" ), "", 0, this,
01062 SLOT( selectionDistributeVerticalGap() ),
01063 actionCollection(), "object_distribute_vertical_gap" );
01064 new KAction(
01065 i18n( "Distribute Bottom Borders" ), "", 0, this,
01066 SLOT( selectionDistributeVerticalBottom() ),
01067 actionCollection(), "object_distribute_vertical_bottom" );
01068 new KAction(
01069 i18n( "Distribute Top Borders" ), "", 0, this,
01070 SLOT( selectionDistributeVerticalTop() ),
01071 actionCollection(), "object_distribute_vertical_top" );
01072
01073 m_showRulerAction = new KToggleAction( i18n( "Show Rulers" ), 0, this, SLOT( showRuler() ), actionCollection(), "view_show_ruler" );
01074 #if KDE_IS_VERSION(3,2,90)
01075 m_showRulerAction->setCheckedState(i18n("Hide Rulers"));
01076 #endif
01077 m_showRulerAction->setToolTip( i18n( "Shows or hides rulers." ) );
01078 m_showRulerAction->setChecked( false );
01079 m_showGridAction = new KToggleAction( i18n( "Show Grid" ), "view_grid", this, SLOT( showGrid() ), actionCollection(), "view_show_grid" );
01080 #if KDE_IS_VERSION(3,2,90)
01081 m_showGridAction->setCheckedState(i18n("Hide Grid"));
01082 #endif
01083 m_showGridAction->setToolTip( i18n( "Shows or hides grid." ) );
01084
01085 m_snapGridAction = new KToggleAction( i18n( "Snap to Grid" ), 0, this, SLOT( snapToGrid() ), actionCollection(), "view_snap_to_grid" );
01086 m_snapGridAction->setToolTip( i18n( "Snaps to grid." ) );
01087
01088 m_groupObjects = new KAction(
01089 i18n( "&Group Objects" ), "group", QKeySequence( "Ctrl+G" ), this,
01090 SLOT( groupSelection() ), actionCollection(), "selection_group" );
01091 m_ungroupObjects = new KAction(
01092 i18n( "&Ungroup Objects" ), "ungroup", QKeySequence( "Ctrl+Shift+G" ), this,
01093 SLOT( ungroupSelection() ), actionCollection(), "selection_ungroup" );
01094 m_closePath = new KAction(
01095 i18n( "&Close Path" ), QKeySequence( "Ctrl+U" ), this,
01096 SLOT( closePath() ), actionCollection(), "close_path" );
01097
01098
01099
01100 m_lineStyleAction = new KoLineStyleAction( i18n( "Line Style" ), "linestyle", this, SLOT( setLineStyle( int ) ), actionCollection(), "setLineStyle" );
01101
01102
01103 m_setLineWidth = new KoUnitDoubleSpinComboBox( this, 0.0, 1000.0, 0.5, 1.0, KoUnit::U_PT, 1 );
01104 new KWidgetAction( m_setLineWidth, i18n( "Set Line Width" ), 0, this, SLOT( setLineWidth() ), actionCollection(), "setLineWidth" );
01105 m_setLineWidth->insertItem( 0.25 );
01106 m_setLineWidth->insertItem( 0.5 );
01107 m_setLineWidth->insertItem( 0.75 );
01108 m_setLineWidth->insertItem( 1.0 );
01109 m_setLineWidth->insertItem( 2.0 );
01110 m_setLineWidth->insertItem( 3.0 );
01111 m_setLineWidth->insertItem( 4.0 );
01112 m_setLineWidth->insertItem( 5.0 );
01113 m_setLineWidth->insertItem( 10.0 );
01114 m_setLineWidth->insertItem( 20.0 );
01115 connect( m_setLineWidth, SIGNAL( valueChanged( double ) ), this, SLOT( setLineWidth() ) );
01116
01117 m_configureAction = new KAction(
01118 i18n( "Configure Karbon..." ), "configure", 0, this,
01119 SLOT( configure() ), actionCollection(), "configure" );
01120
01121 new KAction( i18n( "Page &Layout..." ), 0, this,
01122 SLOT( pageLayout() ), actionCollection(), "page_layout" );
01123 m_contextHelpAction = new KoContextHelpAction( actionCollection(), this );
01124 }
01125
01126 void
01127 KarbonView::paintEverything( QPainter& , const QRect& , bool )
01128 {
01129 kdDebug(38000) << "view->paintEverything()" << endl;
01130 }
01131
01132 bool
01133 KarbonView::mouseEvent( QMouseEvent* event, const KoPoint &p )
01134 {
01135 int mx = event->pos().x();
01136 int my = event->pos().y();
01137
01138 int px;
01139 int py;
01140 if( m_canvas->horizontalScrollBar()->isVisible() && ((m_canvas->horizontalScrollBar()->value() - m_canvas->pageOffsetX()) > 0))
01141 px = mx;
01142 else
01143 px = (mx + canvasWidget()->contentsX() - canvasWidget()->pageOffsetX());
01144
01145 if( m_canvas->verticalScrollBar()->isVisible() && ((m_canvas->verticalScrollBar()->value() - m_canvas->pageOffsetY()) > 0))
01146 py = my;
01147 else
01148 py = (my + canvasWidget()->contentsY() - canvasWidget()->pageOffsetY());
01149
01150 m_horizRuler->updatePointer(px, py);
01151 m_vertRuler->updatePointer(px, py);
01152
01153 KoPoint xy;
01154 xy.setX((mx + canvasWidget()->contentsX() - canvasWidget()->pageOffsetX())/zoom());
01155 xy.setY( qRound(m_part->document().height()) - (my + canvasWidget()->contentsY() - canvasWidget()->pageOffsetY())/zoom());
01156
01157 xy.setX(KoUnit::toUserValue(xy.x(), part()->unit()));
01158 xy.setY(KoUnit::toUserValue(xy.y(), part()->unit()));
01159
01160 m_cursorCoords->setText( QString( "%1, %2" ).arg(KGlobal::_locale->formatNumber(xy.x(), 2)).arg(KGlobal::_locale->formatNumber(xy.y(), 2)) );
01161
01162 if( toolController() )
01163 return toolController()->mouseEvent( event, p );
01164 else
01165 return false;
01166 }
01167
01168 bool
01169 KarbonView::keyEvent( QEvent* event )
01170 {
01171 if( toolController() )
01172 return toolController()->keyEvent( event );
01173 else
01174 return false;
01175 }
01176
01177 void
01178 KarbonView::reorganizeGUI()
01179 {
01180 if( statusBar() )
01181 {
01182 if( part()->showStatusBar() )
01183 statusBar()->show();
01184 else
01185 statusBar()->hide();
01186 }
01187 }
01188
01189 void
01190 KarbonView::setNumberOfRecentFiles( unsigned int number )
01191 {
01192 if( shell() )
01193 shell()->setMaxRecentItems( number );
01194 }
01195
01196 void
01197 KarbonView::showRuler()
01198 {
01199 if( shell() && m_showRulerAction->isChecked() )
01200 {
01201 m_horizRuler->show();
01202 m_vertRuler->show();
01203 m_canvas->setGeometry( rulerWidth, rulerHeight, width() - rulerWidth, height() - rulerHeight );
01204 updateRuler();
01205 }
01206 else
01207 {
01208 m_horizRuler->hide();
01209 m_vertRuler->hide();
01210 m_canvas->setGeometry( 0, 0, width(), height() );
01211 }
01212
01213 zoomChanged();
01214 }
01215
01216 bool
01217 KarbonView::showPageMargins()
01218 {
01219 return ((KToggleAction*)actionCollection()->action("view_show_margins"))->isChecked();
01220 }
01221
01222 void
01223 KarbonView::togglePageMargins(bool b)
01224 {
01225 ((KToggleAction*)actionCollection()->action("view_show_margins"))->setChecked(b);
01226 m_canvas->repaintAll();
01227 }
01228
01229 void
01230 KarbonView::updateRuler()
01231 {
01232 if(!m_canvas->horizontalScrollBar()->isVisible())
01233 {
01234 if( (1 + m_canvas->pageOffsetX() - m_canvas->contentsX()) >= 0 )
01235 {
01236 m_horizRuler->setGeometry( 1 + rulerWidth + m_canvas->pageOffsetX() - m_canvas->contentsX(), 0, qRound( 1 + part()->document().width() * zoom() ), rulerHeight );
01237 m_horizRuler->updateVisibleArea(0,0);
01238 }
01239 else
01240 {
01241 m_horizRuler->setGeometry( rulerWidth, 0, qRound( 1 + part()->document().width() * zoom() ) - m_canvas->contentsX() + m_canvas->pageOffsetX(), rulerHeight );
01242 m_horizRuler->updateVisibleArea((m_canvas->contentsX() - m_canvas->pageOffsetX()),0);
01243 }
01244 }
01245
01246 if(!m_canvas->verticalScrollBar()->isVisible())
01247 {
01248 if( (1 + m_canvas->pageOffsetY() - m_canvas->contentsY()) >= 0 )
01249 {
01250 m_vertRuler->setGeometry( 0, 1 + rulerHeight + m_canvas->pageOffsetY() - m_canvas->contentsY(), rulerWidth, 1 + qRound( part()->document().height() * zoom() ));
01251 m_vertRuler->updateVisibleArea(0,0);
01252 }
01253 else
01254 {
01255 m_vertRuler->setGeometry( 0, 1 + rulerHeight, rulerWidth, 1 + qRound( part()->document().height() * zoom() ) + m_canvas->contentsY() - m_canvas->pageOffsetY() );
01256 m_vertRuler->updateVisibleArea(0, (m_canvas->contentsY() - m_canvas->pageOffsetY()));
01257 }
01258 }
01259 }
01260
01261 void
01262 KarbonView::showGrid()
01263 {
01264 m_part->document().grid().isShow = m_showGridAction->isChecked();
01265 }
01266
01267 void
01268 KarbonView::snapToGrid()
01269 {
01270 m_part->document().grid().isSnap = m_snapGridAction->isChecked();
01271 }
01272
01273 void
01274 KarbonView::showSelectionPopupMenu( const QPoint &pos )
01275 {
01276 QPtrList<KAction> actionList;
01277 if( m_groupObjects->isEnabled() )
01278 actionList.append( m_groupObjects );
01279 else if( m_ungroupObjects->isEnabled() )
01280 actionList.append( m_ungroupObjects );
01281 if( m_closePath->isEnabled() )
01282 actionList.append( m_closePath );
01283 plugActionList( "selection_type_action", actionList );
01284 ((QPopupMenu *)factory()->container( "selection_popup", this ) )->exec( pos );
01285 unplugActionList( "selection_type_action" );
01286 }
01287
01288 void
01289 KarbonView::configure()
01290 {
01291 VConfigureDlg dialog( this );
01292 dialog.exec();
01293 }
01294
01295 void
01296 KarbonView::pageLayout()
01297 {
01298 KoHeadFoot hf;
01299 KoPageLayout layout = part()->pageLayout();
01300 KoUnit::Unit unit = part()->unit();
01301 if( KoPageLayoutDia::pageLayout( layout, hf, FORMAT_AND_BORDERS | DISABLE_UNIT, unit ) )
01302 {
01303 part()->setPageLayout( layout, unit );
01304 m_horizRuler->setUnit( unit );
01305 m_vertRuler->setUnit( unit );
01306 m_canvas->resizeContents( int( ( part()->pageLayout().ptWidth + 300 ) * zoom() ),
01307 int( ( part()->pageLayout().ptHeight + 460 ) * zoom() ) );
01308 part()->repaintAllViews();
01309
01310 emit pageLayoutChanged();
01311 }
01312 }
01313
01314 void
01315 KarbonView::canvasContentsMoving( int x, int y )
01316 {
01317 if( m_canvas->horizontalScrollBar()->isVisible() )
01318 {
01319 if( shell() && m_showRulerAction->isChecked() )
01320 {
01321 if( (1 + m_canvas->pageOffsetX() - x) >= 0)
01322 {
01323 m_horizRuler->setGeometry( 1 + rulerWidth + m_canvas->pageOffsetX() - x, 0, qRound( 1 + part()->document().width() * zoom() ), rulerHeight );
01324 m_horizRuler->updateVisibleArea(0,0);
01325 }
01326 else
01327 {
01328 m_horizRuler->setGeometry( rulerWidth, 0, qRound( 1 + part()->document().width() * zoom() ) - x + m_canvas->pageOffsetX(), rulerHeight );
01329 m_horizRuler->updateVisibleArea((x - m_canvas->pageOffsetX()),0);
01330 }
01331 }
01332 }
01333
01334 if( m_canvas->verticalScrollBar()->isVisible() )
01335 {
01336 if( shell() && m_showRulerAction->isChecked() )
01337 {
01338 if( (1 + m_canvas->pageOffsetY() - y) >= 0)
01339 {
01340 m_vertRuler->setGeometry( 0, 1 + rulerHeight + m_canvas->pageOffsetY() - y , rulerWidth, 1 + qRound( part()->document().height() * zoom() ));
01341 m_vertRuler->updateVisibleArea(0,0);
01342 }
01343 else
01344 {
01345 m_vertRuler->setGeometry( 0, 1 + rulerHeight, rulerWidth, 1 + qRound( part()->document().height() * zoom() ) - y + m_canvas->pageOffsetY() );
01346 m_vertRuler->updateVisibleArea(0, (y - m_canvas->pageOffsetY()));
01347 }
01348 }
01349 }
01350 }
01351
01352 void
01353 KarbonView::selectionChanged()
01354 {
01355 int count = part()->document().selection()->objects().count();
01356 m_groupObjects->setEnabled( false );
01357 m_closePath->setEnabled( false );
01358 m_ungroupObjects->setEnabled( false );
01359
01360 if( count > 0 )
01361 {
01362 VObject *obj = part()->document().selection()->objects().getFirst();
01363
01364 if ( shell() ) {
01365
01366 m_strokeFillPreview->update( *obj->stroke(), *obj->fill() );
01367 m_smallPreview->update( *obj->stroke(), *obj->fill() );
01368
01369 }
01370 m_strokeDocker->setStroke( *( obj->stroke() ) );
01371
01372 if( count == 1 )
01373 {
01374 VGroup *group = dynamic_cast<VGroup *>( part()->document().selection()->objects().getFirst() );
01375 m_ungroupObjects->setEnabled( group );
01376 VPath *path = dynamic_cast<VPath *>( part()->document().selection()->objects().getFirst() );
01377 m_closePath->setEnabled( path && !path->isClosed() );
01378 }
01379 else
01380 m_groupObjects->setEnabled( true );
01381
01382 part()->document().selection()->setStroke( *obj->stroke() );
01383 part()->document().selection()->setFill( *obj->fill() );
01384 m_setLineWidth->setEnabled( true );
01385 m_setLineWidth->updateValue( obj->stroke()->lineWidth() );
01386
01387 m_lineStyleAction->setEnabled( true );
01388 if( obj->stroke()->dashPattern().array().isEmpty() )
01389 m_lineStyleAction->setCurrentSelection( Qt::SolidLine );
01390 else if( obj->stroke()->dashPattern().array()[ 0 ] == 0. )
01391 m_lineStyleAction->setCurrentSelection( Qt::NoPen );
01392 else if( obj->stroke()->dashPattern().array()[ 0 ] == 2. )
01393 m_lineStyleAction->setCurrentSelection( Qt::DotLine );
01394 else if( obj->stroke()->dashPattern().array().count() == 2 )
01395 m_lineStyleAction->setCurrentSelection( Qt::DashLine );
01396 else if( obj->stroke()->dashPattern().array().count() == 4 )
01397 m_lineStyleAction->setCurrentSelection( Qt::DashDotLine );
01398 else if( obj->stroke()->dashPattern().array().count() == 6 )
01399 m_lineStyleAction->setCurrentSelection( Qt::DashDotDotLine );
01400
01401 m_deleteSelectionAction->setEnabled( true );
01402 }
01403 else
01404 {
01405 if ( shell() )
01406
01407 m_strokeFillPreview->update( *( part()->document().selection()->stroke() ),
01408 *( part()->document().selection()->fill() ) );
01409 m_lineStyleAction->setEnabled( false );
01410 m_deleteSelectionAction->setEnabled( false );
01411 }
01412 emit selectionChange();
01413 }
01414 void
01415 KarbonView::setCursor( const QCursor &c )
01416 {
01417 m_canvas->setCursor( c );
01418 }
01419
01420 void
01421 KarbonView::repaintAll( const KoRect &r )
01422 {
01423 m_canvas->repaintAll( r );
01424 }
01425
01426 void
01427 KarbonView::repaintAll( bool repaint )
01428 {
01429 m_canvas->repaintAll( repaint );
01430 }
01431 void
01432 KarbonView::setPos( const KoPoint& p )
01433 {
01434 m_canvas->setPos( p );
01435 }
01436
01437 void
01438 KarbonView::setViewportRect( const KoRect &rect )
01439 {
01440 m_canvas->setViewportRect( rect );
01441 }
01442
01443 void
01444 KarbonView::setUnit( KoUnit::Unit )
01445 {
01446 }
01447
01448 void KarbonView::createDocumentTabDock()
01449 {
01450 m_DocumentTab = new VDocumentTab(this, this);
01451 m_DocumentTab->setCaption(i18n("Document"));
01452 paletteManager()->addWidget(m_DocumentTab, "DocumentTabDock", "DocumentPanel");
01453 connect( m_part, SIGNAL( unitChanged( KoUnit::Unit ) ), m_DocumentTab, SLOT( updateDocumentInfo() ) );
01454 }
01455
01456 void KarbonView::createLayersTabDock()
01457 {
01458 m_LayersTab = new VLayersTab(this, this);
01459 m_LayersTab->setCaption(i18n("Layers"));
01460 paletteManager()->addWidget(m_LayersTab, "LayersTabDock", "DocumentPanel");
01461 }
01462
01463 void KarbonView::createHistoryTabDock()
01464 {
01465 m_HistoryTab = new VHistoryTab(part(), this);
01466 m_HistoryTab->setCaption(i18n("History"));
01467 paletteManager()->addWidget(m_HistoryTab, "HistoryTabDock", "DocumentPanel");
01468 }
01469
01470 void KarbonView::createStrokeDock()
01471 {
01472 m_strokeDocker = new VStrokeDocker(part(), this);
01473 m_strokeDocker->setCaption(i18n("Stroke Properties"));
01474 paletteManager()->addWidget(m_strokeDocker, "StrokeTabDock", "StrokePanel");
01475
01476 connect( part(), SIGNAL( unitChanged( KoUnit::Unit ) ), m_strokeDocker, SLOT( setUnit( KoUnit::Unit ) ) );
01477 }
01478
01479 void KarbonView::createColorDock()
01480 {
01481 m_ColorManager = new VColorDocker(part(),this);
01482
01483 paletteManager()->addWidget(m_ColorManager, "ColorTabDock", "ColorPanel");
01484
01485 connect( this, SIGNAL( selectionChange() ), m_ColorManager, SLOT( update() ) );
01486 }
01487
01488 void KarbonView::createTransformDock()
01489 {
01490 m_TransformDocker = new VTransformDocker(part(), this);
01491 m_TransformDocker->setCaption(i18n("Transform"));
01492 paletteManager()->addWidget(m_TransformDocker, "TransformTabDock", "TransformPanel");
01493
01494 connect( this, SIGNAL( selectionChange() ), m_TransformDocker, SLOT( update() ) );
01495 connect( part(), SIGNAL( unitChanged( KoUnit::Unit ) ), m_TransformDocker, SLOT( setUnit( KoUnit::Unit ) ) );
01496 }
01497
01498 void KarbonView::createResourceDock()
01499 {
01500 m_styleDocker = new VStyleDocker( part(), this );
01501 m_styleDocker->setCaption(i18n("Resources"));
01502 paletteManager()->addWidget(m_styleDocker, "ResourceTabDock", "ResourcePanel");
01503 }
01504
01505 VToolController *
01506 KarbonView::toolController()
01507 {
01508 return m_toolController;
01509 }
01510
01511 #include "karbon_view.moc"
01512