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
00281 connect( m_part->commandHistory(), SIGNAL( commandExecuted( VCommand* ) ), this, SLOT( commandExecuted( VCommand* ) ) );
00282
00283 connect( m_ColorManager, SIGNAL(modeChanged( KDualColorButton::DualColor)), this, SLOT( strokeFillSelectionChanged(KDualColorButton::DualColor) ) );
00284 connect( m_ColorManager, SIGNAL(bgColorChanged( const QColor & )), this, SLOT(colorChanged( const QColor & )) );
00285 connect( m_ColorManager, SIGNAL(fgColorChanged( const QColor & )), this, SLOT(colorChanged( const QColor & )) );
00286 selectionChanged();
00287
00288
00289
00290
00291 }
00292 }
00293
00294 return KXMLGUIBuilder::createContainer( parent, index, element, id );
00295 }
00296
00297 void
00298 KarbonView::removeContainer( QWidget *container, QWidget *parent,
00299 QDomElement &element, int id )
00300 {
00301 if( container )
00302 kdDebug(38000) << container << endl;
00303
00304 if( shell() && container == m_toolbox )
00305 {
00306 disconnect( m_part->commandHistory(), SIGNAL( commandExecuted( VCommand* ) ), this, SLOT( commandExecuted( VCommand* ) ) );
00307 disconnect( m_ColorManager, SIGNAL(modeChanged( KDualColorButton::DualColor)), this, SLOT( strokeFillSelectionChanged(KDualColorButton::DualColor) ) );
00308 disconnect( m_ColorManager, SIGNAL(bgColorChanged( const QColor & )), this, SLOT(colorChanged( const QColor & )) );
00309 disconnect( m_ColorManager, SIGNAL(fgColorChanged( const QColor & )), this, SLOT(colorChanged( const QColor & )) );
00310 delete m_toolbox;
00311 m_toolbox = 0L;
00312 m_toolController->youAintGotNoToolBox();
00313
00314 m_strokeFillPreview = 0;
00315
00316 m_typeButtonBox = 0;
00317
00318
00319 }
00320 else
00321 KXMLGUIBuilder::removeContainer( container, parent, element, id );
00322 }
00323
00324
00325 DCOPObject *
00326 KarbonView::dcopObject()
00327 {
00328 if( !m_dcop )
00329 m_dcop = new KarbonViewIface( this );
00330
00331 return m_dcop;
00332 }
00333
00334 QWidget*
00335 KarbonView::canvas() const
00336 {
00337 return m_canvas;
00338 }
00339
00340 void
00341 KarbonView::resizeEvent( QResizeEvent* )
00342 {
00343 if( shell() && m_showRulerAction->isChecked())
00344 {
00345 m_canvas->setGeometry( rulerWidth, rulerHeight, width() - rulerWidth, height() - rulerHeight );
00346 updateRuler();
00347 }
00348 else
00349 {
00350 m_horizRuler->hide();
00351 m_vertRuler->hide();
00352 m_canvas->setGeometry( 0, 0, width(), height() );
00353 }
00354
00355 zoomChanged();
00356 reorganizeGUI();
00357 }
00358
00359 void
00360 KarbonView::dropEvent( QDropEvent *e )
00361 {
00362
00363 QColor color;
00364 VColor realcolor;
00365 VObjectList selection;
00366
00367 if( KColorDrag::decode( e, color ) )
00368 {
00369 float r = color.red() / 255.0;
00370 float g = color.green() / 255.0;
00371 float b = color.blue() / 255.0;
00372
00373 realcolor.set( r, g, b );
00374
00375 if( part() )
00376 if( m_strokeFillPreview->strokeIsSelected() )
00377 part()->addCommand( new VStrokeCmd( &part()->document(), realcolor ), true );
00378 else
00379 part()->addCommand( new VFillCmd( &part()->document(), realcolor ), true );
00380 }
00381 else if( KarbonDrag::decode( e, selection, m_part->document() ) )
00382 {
00383 VObject *clipart = selection.first();
00384 KoPoint p( e->pos() );
00385 p = m_canvas->toContents( p );
00386 QWMatrix mat( 1, 0, 0, 1, p.x(), p.y() );
00387
00388 VTransformCmd trafo( 0L, mat );
00389 trafo.visit( *clipart );
00390 VClipartCmd* cmd = new VClipartCmd( &m_part->document(), i18n( "Insert Clipart" ), clipart );
00391
00392 m_part->addCommand( cmd, true );
00393 }
00394 }
00395
00396 void
00397 KarbonView::print( KPrinter &printer )
00398 {
00399
00400 kdDebug(38000) << "KarbonView::print" << endl;
00401
00402 QPaintDeviceMetrics metrics( ( QPaintDevice * ) & printer );
00403 printer.setFullPage( true );
00404
00405 KoPageLayout pageLayout = part()->pageLayout();
00406 printer.setOrientation( pageLayout.orientation == PG_PORTRAIT ? KPrinter::Portrait : KPrinter::Landscape );
00407 printer.setPageSize( (KPrinter::PageSize)KoPageFormat::printerPageSize( pageLayout.format ) );
00408
00409
00410 double zoom = metrics.logicalDpiX() / 72.0;
00411
00412 QWMatrix mat;
00413 mat.scale( 1, -1 );
00414 mat.translate( 0, -part()->document().height()*zoom );
00415
00416 double w = zoom*part()->document().width();
00417 double h = zoom*part()->document().height();
00418
00419 KoRect rect( 0, 0, w, h );
00420
00421 QPixmap img( static_cast<int>( w ), static_cast<int>( h ) );
00422
00423
00424 VKoPainter kop( ( QPaintDevice * )&img, static_cast<int>( w ), static_cast<int>( h ) );
00425
00426 kop.setZoomFactor( zoom );
00427 kop.setWorldMatrix( mat );
00428
00429 kop.begin();
00430
00431 part()->document().draw( &kop, &rect );
00432
00433 kop.end();
00434
00435 QPainter p;
00436
00437
00438
00439
00440 p.begin( &printer );
00441 p.drawPixmap( 0, 0, img );
00442 p.end();
00443 }
00444
00445 void
00446 KarbonView::fileImportGraphic()
00447 {
00448 QStringList filter;
00449 filter << "application/x-karbon" << "image/svg+xml" << "image/x-wmf" << "image/x-eps" << "application/postscript";
00450 KFileDialog *dialog = new KFileDialog( "foo", QString::null, 0L, "Choose Graphic to Add", true);
00451 dialog->setMimeFilter( filter, "application/x-karbon" );
00452 if(dialog->exec()!=QDialog::Accepted) {
00453 delete dialog;
00454 return;
00455 }
00456 QString fname = dialog->selectedFile();
00457
00458
00459
00460 if( part()->nativeFormatMimeType() == dialog->currentMimeFilter().latin1() )
00461 part()->mergeNativeFormat( fname );
00462 else
00463 {
00464 KoFilterManager man( part() );
00465 KoFilter::ConversionStatus status;
00466 QString importedFile = man.import( fname, status );
00467 part()->mergeNativeFormat( importedFile );
00468 if( !importedFile.isEmpty() )
00469 unlink( QFile::encodeName( importedFile ) );
00470 }
00471 delete dialog;
00472 part()->repaintAllViews();
00473 }
00474
00475 void
00476 KarbonView::editCut()
00477 {
00478 addSelectionToClipboard();
00479
00480 editDeleteSelection();
00481 }
00482
00483 void
00484 KarbonView::editCopy()
00485 {
00486 addSelectionToClipboard();
00487 }
00488
00489 void
00490 KarbonView::addSelectionToClipboard() const
00491 {
00492 if( part()->document().selection()->objects().count() <= 0 )
00493 return;
00494
00495 KarbonDrag* kd = new KarbonDrag();
00496 kd->setObjectList( part()->document().selection()->objects() );
00497 QApplication::clipboard()->setData( kd );
00498 }
00499
00500 void
00501 KarbonView::editPaste()
00502 {
00503 KarbonDrag kd;
00504 VObjectList objects;
00505
00506 if( !kd.decode( QApplication::clipboard()->data(), objects, part()->document() ) )
00507 return;
00508
00509
00510 double copyOffset = part()->instance()->config()->readNumEntry( "CopyOffset", 10 );
00511 part()->addCommand( new VInsertCmd( &part()->document(),
00512 objects.count() == 1
00513 ? i18n( "Paste Object" )
00514 : i18n( "Paste Objects" ),
00515 &objects, copyOffset ),
00516 true );
00517
00518 part()->repaintAllViews();
00519 selectionChanged();
00520 }
00521
00522 void
00523 KarbonView::editSelectAll()
00524 {
00525 part()->document().selection()->append();
00526
00527 if( part()->document().selection()->objects().count() > 0 )
00528 part()->repaintAllViews();
00529
00530 selectionChanged();
00531 }
00532
00533 void
00534 KarbonView::editDeselectAll()
00535 {
00536 if( part()->document().selection()->objects().count() > 0 )
00537 {
00538 part()->document().selection()->clear();
00539 part()->repaintAllViews();
00540 }
00541
00542 selectionChanged();
00543 }
00544
00545 void
00546 KarbonView::editDeleteSelection()
00547 {
00548 kdDebug(38000) << "*********" << endl;
00549
00550 if( part()->document().selection()->objects().count() > 0 )
00551 {
00552 part()->addCommand(
00553 new VDeleteCmd( &part()->document() ),
00554 true );
00555 }
00556 }
00557
00558 void
00559 KarbonView::editPurgeHistory()
00560 {
00561
00562
00563 if( KMessageBox::warningContinueCancel( this,
00564 i18n( "This action cannot be undone later. Do you really want to continue?" ),
00565 i18n( "Purge History" ),
00566 KStdGuiItem::del(),
00567 "edit_purge_history" ) )
00568 {
00569
00570
00571 VCleanUpCmd cmd( &part()->document() );
00572 cmd.execute();
00573
00574 part()->clearHistory();
00575 }
00576 }
00577
00578 void
00579 KarbonView::selectionAlignHorizontalLeft()
00580 {
00581 part()->addCommand(
00582 new VAlignCmd( &part()->document(), VAlignCmd::ALIGN_HORIZONTAL_LEFT ), true );
00583 }
00584 void
00585 KarbonView::selectionAlignHorizontalCenter()
00586 {
00587 part()->addCommand(
00588 new VAlignCmd( &part()->document(), VAlignCmd::ALIGN_HORIZONTAL_CENTER ), true );
00589 }
00590
00591 void
00592 KarbonView::selectionAlignHorizontalRight()
00593 {
00594 part()->addCommand(
00595 new VAlignCmd( &part()->document(), VAlignCmd::ALIGN_HORIZONTAL_RIGHT ), true );
00596 }
00597
00598 void
00599 KarbonView::selectionAlignVerticalTop()
00600 {
00601 part()->addCommand(
00602 new VAlignCmd( &part()->document(), VAlignCmd::ALIGN_VERTICAL_TOP ), true );
00603 }
00604
00605 void
00606 KarbonView::selectionAlignVerticalCenter()
00607 {
00608 part()->addCommand(
00609 new VAlignCmd( &part()->document(), VAlignCmd::ALIGN_VERTICAL_CENTER ), true );
00610 }
00611
00612 void
00613 KarbonView::selectionAlignVerticalBottom()
00614 {
00615 part()->addCommand(
00616 new VAlignCmd( &part()->document(), VAlignCmd::ALIGN_VERTICAL_BOTTOM ), true );
00617 }
00618
00619 void
00620 KarbonView::selectionDistributeHorizontalCenter()
00621 {
00622 part()->addCommand(
00623 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_HORIZONTAL_CENTER ), true );
00624 }
00625
00626 void
00627 KarbonView::selectionDistributeHorizontalGap()
00628 {
00629 part()->addCommand(
00630 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_HORIZONTAL_GAP ), true );
00631 }
00632
00633 void
00634 KarbonView::selectionDistributeHorizontalLeft()
00635 {
00636 part()->addCommand(
00637 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_HORIZONTAL_LEFT ), true );
00638 }
00639
00640 void
00641 KarbonView::selectionDistributeHorizontalRight()
00642 {
00643 part()->addCommand(
00644 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_HORIZONTAL_RIGHT ), true );
00645 }
00646
00647 void
00648 KarbonView::selectionDistributeVerticalCenter()
00649 {
00650 part()->addCommand(
00651 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_VERTICAL_CENTER ), true );
00652 }
00653
00654 void
00655 KarbonView::selectionDistributeVerticalGap()
00656 {
00657 part()->addCommand(
00658 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_VERTICAL_GAP ), true );
00659 }
00660
00661 void
00662 KarbonView::selectionDistributeVerticalBottom()
00663 {
00664 part()->addCommand(
00665 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_VERTICAL_BOTTOM ), true );
00666 }
00667
00668 void
00669 KarbonView::selectionDistributeVerticalTop()
00670 {
00671 part()->addCommand(
00672 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_VERTICAL_TOP ), true );
00673 }
00674
00675 void
00676 KarbonView::selectionDuplicate()
00677 {
00678 if ( !part()->document().selection()->objects().count() )
00679 return;
00680
00681 VObjectList objects;
00682
00683
00684 VObjectListIterator itr( part()->document().selection()->objects() );
00685 for ( ; itr.current() ; ++itr ) {
00686 objects.append( itr.current()->clone() );
00687 }
00688
00689
00690 double copyOffset = part()->instance()->config()->readNumEntry( "CopyOffset", 10 );
00691 part()->addCommand( new VInsertCmd( &part()->document(),
00692 objects.count() == 1
00693 ? i18n( "Duplicate Object" )
00694 : i18n( "Duplicate Objects" ),
00695 &objects, copyOffset ),
00696 true );
00697
00698 part()->repaintAllViews();
00699 selectionChanged();
00700 }
00701
00702 void
00703 KarbonView::selectionBringToFront()
00704 {
00705 part()->addCommand(
00706 new VZOrderCmd( &part()->document(), VZOrderCmd::bringToFront ), true );
00707 }
00708
00709 void
00710 KarbonView::selectionMoveUp()
00711 {
00712 part()->addCommand(
00713 new VZOrderCmd( &part()->document(), VZOrderCmd::up ), true );
00714 }
00715
00716 void
00717 KarbonView::selectionMoveDown()
00718 {
00719 part()->addCommand(
00720 new VZOrderCmd( &part()->document(), VZOrderCmd::down ), true );
00721 }
00722
00723 void
00724 KarbonView::selectionSendToBack()
00725 {
00726 part()->addCommand(
00727 new VZOrderCmd( &part()->document(), VZOrderCmd::sendToBack ), true );
00728 }
00729
00730 void
00731 KarbonView::groupSelection()
00732 {
00733 part()->addCommand( new VGroupCmd( &part()->document() ), true );
00734 }
00735
00736 void
00737 KarbonView::ungroupSelection()
00738 {
00739 part()->addCommand( new VUnGroupCmd( &part()->document() ), true );
00740 }
00741
00742 void
00743 KarbonView::closePath()
00744 {
00745 part()->addCommand( new VClosePathCmd( &part()->document() ), true );
00746 }
00747
00748 void
00749 KarbonView::slotActiveToolChanged( VTool *tool )
00750 {
00751 toolController()->setCurrentTool( tool );
00752
00753 m_canvas->repaintAll();
00754 }
00755
00756 void
00757 KarbonView::viewModeChanged()
00758 {
00759 canvasWidget()->pixmap()->fill();
00760
00761 if( m_viewAction->currentItem() == 1 )
00762 m_painterFactory->setWireframePainter( canvasWidget()->pixmap(), width(), height() );
00763 else
00764 m_painterFactory->setPainter( canvasWidget()->pixmap(), width(), height() );
00765
00766 m_canvas->repaintAll();
00767 }
00768
00769 void
00770 KarbonView::setZoomAt( double zoom, const KoPoint &p )
00771 {
00772 QString zoomText = QString( "%1%" ).arg( zoom * 100.0, 0, 'f', 2 );
00773 QStringList stl = m_zoomAction->items();
00774 if( stl.first() == "25%" )
00775 {
00776 stl.prepend( zoomText.latin1() );
00777 m_zoomAction->setItems( stl );
00778 m_zoomAction->setCurrentItem( 0 );
00779 }
00780 else
00781 {
00782 m_zoomAction->setCurrentItem( 0 );
00783 m_zoomAction->changeItem( m_zoomAction->currentItem(), zoomText.latin1() );
00784 }
00785 zoomChanged( p );
00786 }
00787
00788 void
00789 KarbonView::viewZoomIn()
00790 {
00791 setZoomAt( zoom() * 1.50 );
00792 }
00793
00794 void
00795 KarbonView::viewZoomOut()
00796 {
00797 setZoomAt( zoom() * 0.75 );
00798 }
00799
00800 void
00801 KarbonView::zoomChanged( const KoPoint &p )
00802 {
00803 double centerX;
00804 double centerY;
00805 double zoomFactor;
00806
00807 if( !p.isNull() )
00808 {
00809 centerX = ( ( p.x() ) * zoom() + m_canvas->pageOffsetX() ) / double( m_canvas->contentsWidth() );
00810 centerY = 1 - ( ( p.y() ) * zoom() + m_canvas->pageOffsetY() ) / double( m_canvas->contentsHeight() );
00811 zoomFactor = m_zoomAction->currentText().remove( '%' ).toDouble() / 100.0;
00812 }
00813 else if( m_zoomAction->currentText() == i18n("Zoom Width") )
00814 {
00815 centerX = 0.5;
00816 centerY = double( m_canvas->contentsY() + 0.5 * m_canvas->visibleHeight() ) / double( m_canvas->contentsHeight() );
00817 zoomFactor = double( m_canvas->visibleWidth() ) / double( part()->document().width() );
00818 }
00819 else if( m_zoomAction->currentText() == i18n("Whole Page") )
00820 {
00821 centerX = 0.5;
00822 centerY = 0.5;
00823 double zoomFactorX = double( m_canvas->visibleWidth() ) / double( part()->document().width() );
00824 double zoomFactorY = double( m_canvas->visibleHeight() ) / double( part()->document().height() );
00825
00826 if(zoomFactorX < 0 && zoomFactorY > 0)
00827 zoomFactor = zoomFactorY;
00828 else if(zoomFactorX > 0 && zoomFactorY < 0)
00829 zoomFactor = zoomFactorX;
00830 else if(zoomFactorX < 0 && zoomFactorY < 0)
00831 zoomFactor = 0.0001;
00832 else
00833 zoomFactor = kMin( zoomFactorX, zoomFactorY );
00834 }
00835 else
00836 {
00837 if( m_canvas->contentsWidth() > m_canvas->visibleWidth() )
00838 centerX = double( m_canvas->contentsX() + 0.5 * m_canvas->visibleWidth() ) / double( m_canvas->contentsWidth() );
00839 else
00840 centerX = 0.5;
00841 if( m_canvas->contentsHeight() > m_canvas->visibleHeight() )
00842 centerY = double( m_canvas->contentsY() + 0.5 * m_canvas->visibleHeight() ) / double( m_canvas->contentsHeight() );
00843 else
00844 centerY = 0.5;
00845 zoomFactor = m_zoomAction->currentText().remove( '%' ).toDouble() / 100.0;
00846 }
00847 kdDebug(38000) << "centerX : " << centerX << endl;
00848 kdDebug(38000) << "centerY : " << centerY << endl;
00849 kdDebug(38000) << "zoomFactor : " << zoomFactor << endl;
00850 if( zoomFactor == 0.0 ) return;
00851
00852
00853 if( zoomFactor > 20 )
00854 {
00855 zoomFactor = 20;
00856 m_zoomAction->changeItem( m_zoomAction->currentItem(), " 2000%" );
00857 }
00858
00859 KoView::setZoom( zoomFactor );
00860
00861 m_canvas->viewport()->setUpdatesEnabled( false );
00862
00863 m_canvas->resizeContents( int( ( part()->pageLayout().ptWidth + 300 ) * zoomFactor ),
00864 int( ( part()->pageLayout().ptHeight + 460 ) * zoomFactor ) );
00865
00866
00867 VPainter *painter = painterFactory()->editpainter();
00868 painter->setZoomFactor( zoomFactor );
00869
00870 m_canvas->setViewport( centerX, centerY );
00871 m_canvas->repaintAll();
00872 m_canvas->viewport()->setUpdatesEnabled( true );
00873
00874
00875 if( shell() && m_showRulerAction->isChecked() )
00876 {
00877 m_horizRuler->setZoom( zoomFactor );
00878 m_vertRuler->setZoom( zoomFactor );
00879 m_canvas->setGeometry( rulerWidth, rulerHeight, width() - rulerWidth, height() - rulerHeight );
00880 updateRuler();
00881 }
00882 else
00883 {
00884 m_horizRuler->hide();
00885 m_vertRuler->hide();
00886 }
00887 m_canvas->viewport()->setFocus();
00888
00889 emit zoomChanged( zoomFactor );
00890 }
00891
00892 void
00893 KarbonView::setLineStyle( int style )
00894 {
00895 QValueList<float> dashes;
00896 if( style == Qt::NoPen )
00897 part()->addCommand( new VStrokeCmd( &part()->document(), dashes << 0 << 20 ), true );
00898 else if( style == Qt::SolidLine )
00899 part()->addCommand( new VStrokeCmd( &part()->document(), dashes ), true );
00900 else if( style == Qt::DashLine )
00901 part()->addCommand( new VStrokeCmd( &part()->document(), dashes << 12 << 6 ), true );
00902 else if( style == Qt::DotLine )
00903 part()->addCommand( new VStrokeCmd( &part()->document(), dashes << 2 << 2 ), true );
00904 else if( style == Qt::DashDotLine )
00905 part()->addCommand( new VStrokeCmd( &part()->document(), dashes << 12 << 2 << 2 << 2 ), true );
00906 else if( style == Qt::DashDotDotLine )
00907 part()->addCommand( new VStrokeCmd( &part()->document(), dashes << 12 << 2 << 2 << 2 << 2 << 2 ), true );
00908 }
00909
00910 void
00911 KarbonView::slotStrokeChanged( const VStroke &c )
00912 {
00913 part()->document().selection()->setStroke( c );
00914 selectionChanged();
00915 }
00916
00917 void
00918 KarbonView::slotFillChanged( const VFill &f )
00919 {
00920 part()->document().selection()->setFill( f );
00921 selectionChanged();
00922 }
00923
00924 void
00925 KarbonView::setLineWidth()
00926 {
00927 setLineWidth( m_setLineWidth->value() );
00928 selectionChanged();
00929 }
00930
00931
00932 void
00933 KarbonView::setLineWidth( double val )
00934 {
00935 part()->addCommand( new VStrokeCmd( &part()->document(), val ), true );
00936 }
00937
00938 void
00939 KarbonView::initActions()
00940 {
00941
00942 m_viewAction = new KSelectAction(
00943 i18n( "View &Mode" ), 0, this,
00944 SLOT( viewModeChanged() ), actionCollection(), "view_mode" );
00945
00946 m_zoomAction = new KSelectAction(
00947 i18n( "&Zoom" ), "viewmag", 0, this,
00948 SLOT( zoomChanged() ), actionCollection(), "view_zoom" );
00949
00950 QStringList mstl;
00951 mstl << i18n( "Normal" ) << i18n( "Wireframe" );
00952 m_viewAction->setItems( mstl );
00953 m_viewAction->setCurrentItem( 0 );
00954 m_viewAction->setEditable( false );
00955
00956 QStringList stl;
00957
00958 stl << i18n( "25%" );
00959
00960 stl << i18n( "50%" );
00961
00962 stl << i18n( "100%" );
00963
00964 stl << i18n( "200%" );
00965
00966 stl << i18n( "300%" );
00967
00968 stl << i18n( "400%" );
00969
00970 stl << i18n( "800%" );
00971 stl << i18n( "Whole Page" )
00972 << i18n( "Zoom Width" );
00973
00974 m_zoomAction->setItems( stl );
00975 m_zoomAction->setEditable( true );
00976 m_zoomAction->setCurrentItem( 7 );
00977
00978 KStdAction::zoomIn( this, SLOT( viewZoomIn() ), actionCollection(), "view_zoom_in" );
00979 KStdAction::zoomOut( this, SLOT( viewZoomOut() ), actionCollection(), "view_zoom_out" );
00980
00981 m_showPageMargins = new KToggleAction( i18n("Show Page Margins"), "view_margins", 0, actionCollection(), "view_show_margins" );
00982 connect( m_showPageMargins, SIGNAL(toggled(bool)), SLOT(togglePageMargins(bool)));
00983 #if KDE_IS_VERSION(3,2,90)
00984 m_showPageMargins->setCheckedState(i18n("Hide Page Margins"));
00985 #endif
00986
00987
00988 if( !shell() )
00989 return;
00990
00991
00992 KStdAction::cut( this,
00993 SLOT( editCut() ), actionCollection(), "edit_cut" );
00994 KStdAction::copy( this,
00995 SLOT( editCopy() ), actionCollection(), "edit_copy" );
00996 KStdAction::paste( this,
00997 SLOT( editPaste() ), actionCollection(), "edit_paste" );
00998 KStdAction::selectAll( this, SLOT( editSelectAll() ), actionCollection(), "edit_select_all" );
00999 KStdAction::deselect( this, SLOT( editDeselectAll() ), actionCollection(), "edit_deselect_all" );
01000
01001 new KAction(
01002 i18n( "&Import Graphic..." ), 0, 0, this,
01003 SLOT( fileImportGraphic() ), actionCollection(), "file_import" );
01004 m_deleteSelectionAction = new KAction(
01005 i18n( "D&elete" ), "editdelete", QKeySequence( "Del" ), this,
01006 SLOT( editDeleteSelection() ), actionCollection(), "edit_delete" );
01007 new KAction(
01008 i18n( "&History" ), 0, 0, this,
01009 SLOT( editPurgeHistory() ), actionCollection(), "edit_purge_history" );
01010
01011
01012
01013 new KAction(
01014 i18n( "&Duplicate" ), "duplicate", QKeySequence( "Ctrl+D" ), this,
01015 SLOT( selectionDuplicate() ), actionCollection(), "object_duplicate" );
01016 new KAction(
01017 i18n( "Bring to &Front" ), "bring_forward", QKeySequence( "Ctrl+Shift+]" ), this,
01018 SLOT( selectionBringToFront() ), actionCollection(), "object_move_totop" );
01019 new KAction(
01020 i18n( "&Raise" ), "raise", QKeySequence( "Ctrl+]" ), this,
01021 SLOT( selectionMoveUp() ), actionCollection(), "object_move_up" );
01022 new KAction(
01023 i18n( "&Lower" ), "lower", QKeySequence( "Ctrl+[" ), this,
01024 SLOT( selectionMoveDown() ), actionCollection(), "object_move_down" );
01025 new KAction(
01026 i18n( "Send to &Back" ), "send_backward", QKeySequence( "Ctrl+Shift+[" ), this,
01027 SLOT( selectionSendToBack() ), actionCollection(), "object_move_tobottom" );
01028
01029 new KAction(
01030 i18n( "Align Left" ), "aoleft", 0, this,
01031 SLOT( selectionAlignHorizontalLeft() ),
01032 actionCollection(), "object_align_horizontal_left" );
01033 new KAction(
01034 i18n( "Align Center (Horizontal)" ), "aocenterh", 0, this,
01035 SLOT( selectionAlignHorizontalCenter() ),
01036 actionCollection(), "object_align_horizontal_center" );
01037 new KAction(
01038 i18n( "Align Right" ), "aoright", 0, this,
01039 SLOT( selectionAlignHorizontalRight() ),
01040 actionCollection(), "object_align_horizontal_right" );
01041 new KAction(
01042 i18n( "Align Top" ), "aotop", 0, this,
01043 SLOT( selectionAlignVerticalTop() ),
01044 actionCollection(), "object_align_vertical_top" );
01045 new KAction(
01046 i18n( "Align Middle (Vertical)" ), "aocenterv", 0, this,
01047 SLOT( selectionAlignVerticalCenter() ),
01048 actionCollection(), "object_align_vertical_center" );
01049 new KAction(
01050 i18n( "Align Bottom" ), "aobottom", 0, this,
01051 SLOT( selectionAlignVerticalBottom() ),
01052 actionCollection(), "object_align_vertical_bottom" );
01053
01054 new KAction(
01055 i18n( "Distribute Center (Horizontal)" ), "", 0, this,
01056 SLOT( selectionDistributeHorizontalCenter() ),
01057 actionCollection(), "object_distribute_horizontal_center" );
01058 new KAction(
01059 i18n( "Distribute Gaps (Horizontal)" ), "", 0, this,
01060 SLOT( selectionDistributeHorizontalGap() ),
01061 actionCollection(), "object_distribute_horizontal_gap" );
01062 new KAction(
01063 i18n( "Distribute Left Borders" ), "", 0, this,
01064 SLOT( selectionDistributeHorizontalLeft() ),
01065 actionCollection(), "object_distribute_horizontal_left" );
01066 new KAction(
01067 i18n( "Distribute Right Borders" ), "", 0, this,
01068 SLOT( selectionDistributeHorizontalRight() ),
01069 actionCollection(), "object_distribute_horizontal_right" );
01070 new KAction(
01071 i18n( "Distribute Center (Vertical)" ), "", 0, this,
01072 SLOT( selectionDistributeVerticalCenter() ),
01073 actionCollection(), "object_distribute_vertical_center" );
01074 new KAction(
01075 i18n( "Distribute Gaps (Vertical)" ), "", 0, this,
01076 SLOT( selectionDistributeVerticalGap() ),
01077 actionCollection(), "object_distribute_vertical_gap" );
01078 new KAction(
01079 i18n( "Distribute Bottom Borders" ), "", 0, this,
01080 SLOT( selectionDistributeVerticalBottom() ),
01081 actionCollection(), "object_distribute_vertical_bottom" );
01082 new KAction(
01083 i18n( "Distribute Top Borders" ), "", 0, this,
01084 SLOT( selectionDistributeVerticalTop() ),
01085 actionCollection(), "object_distribute_vertical_top" );
01086
01087 m_showRulerAction = new KToggleAction( i18n( "Show Rulers" ), 0, this, SLOT( showRuler() ), actionCollection(), "view_show_ruler" );
01088 #if KDE_IS_VERSION(3,2,90)
01089 m_showRulerAction->setCheckedState(i18n("Hide Rulers"));
01090 #endif
01091 m_showRulerAction->setToolTip( i18n( "Shows or hides rulers." ) );
01092 m_showRulerAction->setChecked( false );
01093 m_showGridAction = new KToggleAction( i18n( "Show Grid" ), "view_grid", this, SLOT( showGrid() ), actionCollection(), "view_show_grid" );
01094 #if KDE_IS_VERSION(3,2,90)
01095 m_showGridAction->setCheckedState(i18n("Hide Grid"));
01096 #endif
01097 m_showGridAction->setToolTip( i18n( "Shows or hides grid." ) );
01098
01099 m_snapGridAction = new KToggleAction( i18n( "Snap to Grid" ), 0, this, SLOT( snapToGrid() ), actionCollection(), "view_snap_to_grid" );
01100 m_snapGridAction->setToolTip( i18n( "Snaps to grid." ) );
01101
01102 m_groupObjects = new KAction(
01103 i18n( "&Group Objects" ), "group", QKeySequence( "Ctrl+G" ), this,
01104 SLOT( groupSelection() ), actionCollection(), "selection_group" );
01105 m_ungroupObjects = new KAction(
01106 i18n( "&Ungroup Objects" ), "ungroup", QKeySequence( "Ctrl+Shift+G" ), this,
01107 SLOT( ungroupSelection() ), actionCollection(), "selection_ungroup" );
01108 m_closePath = new KAction(
01109 i18n( "&Close Path" ), QKeySequence( "Ctrl+U" ), this,
01110 SLOT( closePath() ), actionCollection(), "close_path" );
01111
01112
01113
01114 m_lineStyleAction = new KoLineStyleAction( i18n( "Line Style" ), "linestyle", this, SLOT( setLineStyle( int ) ), actionCollection(), "setLineStyle" );
01115
01116
01117 m_setLineWidth = new KoUnitDoubleSpinComboBox( this, 0.0, 1000.0, 0.5, 1.0, KoUnit::U_PT, 1 );
01118 new KWidgetAction( m_setLineWidth, i18n( "Set Line Width" ), 0, this, SLOT( setLineWidth() ), actionCollection(), "setLineWidth" );
01119 m_setLineWidth->insertItem( 0.25 );
01120 m_setLineWidth->insertItem( 0.5 );
01121 m_setLineWidth->insertItem( 0.75 );
01122 m_setLineWidth->insertItem( 1.0 );
01123 m_setLineWidth->insertItem( 2.0 );
01124 m_setLineWidth->insertItem( 3.0 );
01125 m_setLineWidth->insertItem( 4.0 );
01126 m_setLineWidth->insertItem( 5.0 );
01127 m_setLineWidth->insertItem( 10.0 );
01128 m_setLineWidth->insertItem( 20.0 );
01129 connect( m_setLineWidth, SIGNAL( valueChanged( double ) ), this, SLOT( setLineWidth() ) );
01130
01131 m_configureAction = new KAction(
01132 i18n( "Configure Karbon..." ), "configure", 0, this,
01133 SLOT( configure() ), actionCollection(), "configure" );
01134
01135 new KAction( i18n( "Page &Layout..." ), 0, this,
01136 SLOT( pageLayout() ), actionCollection(), "page_layout" );
01137 m_contextHelpAction = new KoContextHelpAction( actionCollection(), this );
01138 }
01139
01140 void
01141 KarbonView::paintEverything( QPainter& , const QRect& , bool )
01142 {
01143 kdDebug(38000) << "view->paintEverything()" << endl;
01144 }
01145
01146 bool
01147 KarbonView::mouseEvent( QMouseEvent* event, const KoPoint &p )
01148 {
01149 int mx = event->pos().x();
01150 int my = event->pos().y();
01151
01152 int px;
01153 int py;
01154 if( m_canvas->horizontalScrollBar()->isVisible() && ((m_canvas->horizontalScrollBar()->value() - m_canvas->pageOffsetX()) > 0))
01155 px = mx;
01156 else
01157 px = (mx + canvasWidget()->contentsX() - canvasWidget()->pageOffsetX());
01158
01159 if( m_canvas->verticalScrollBar()->isVisible() && ((m_canvas->verticalScrollBar()->value() - m_canvas->pageOffsetY()) > 0))
01160 py = my;
01161 else
01162 py = (my + canvasWidget()->contentsY() - canvasWidget()->pageOffsetY());
01163
01164 m_horizRuler->updatePointer(px, py);
01165 m_vertRuler->updatePointer(px, py);
01166
01167 KoPoint xy;
01168 xy.setX((mx + canvasWidget()->contentsX() - canvasWidget()->pageOffsetX())/zoom());
01169 xy.setY( qRound(m_part->document().height()) - (my + canvasWidget()->contentsY() - canvasWidget()->pageOffsetY())/zoom());
01170
01171 xy.setX(KoUnit::toUserValue(xy.x(), part()->unit()));
01172 xy.setY(KoUnit::toUserValue(xy.y(), part()->unit()));
01173
01174 m_cursorCoords->setText( QString( "%1, %2" ).arg(KGlobal::_locale->formatNumber(xy.x(), 2)).arg(KGlobal::_locale->formatNumber(xy.y(), 2)) );
01175
01176 if( toolController() )
01177 return toolController()->mouseEvent( event, p );
01178 else
01179 return false;
01180 }
01181
01182 bool
01183 KarbonView::keyEvent( QEvent* event )
01184 {
01185 if( toolController() )
01186 return toolController()->keyEvent( event );
01187 else
01188 return false;
01189 }
01190
01191 void
01192 KarbonView::reorganizeGUI()
01193 {
01194 if( statusBar() )
01195 {
01196 if( part()->showStatusBar() )
01197 statusBar()->show();
01198 else
01199 statusBar()->hide();
01200 }
01201 }
01202
01203 void
01204 KarbonView::setNumberOfRecentFiles( unsigned int number )
01205 {
01206 if( shell() )
01207 shell()->setMaxRecentItems( number );
01208 }
01209
01210 void
01211 KarbonView::showRuler()
01212 {
01213 if( shell() && m_showRulerAction->isChecked() )
01214 {
01215 m_horizRuler->show();
01216 m_vertRuler->show();
01217 m_canvas->setGeometry( rulerWidth, rulerHeight, width() - rulerWidth, height() - rulerHeight );
01218 updateRuler();
01219 }
01220 else
01221 {
01222 m_horizRuler->hide();
01223 m_vertRuler->hide();
01224 m_canvas->setGeometry( 0, 0, width(), height() );
01225 }
01226
01227 zoomChanged();
01228 }
01229
01230 bool
01231 KarbonView::showPageMargins()
01232 {
01233 return ((KToggleAction*)actionCollection()->action("view_show_margins"))->isChecked();
01234 }
01235
01236 void
01237 KarbonView::togglePageMargins(bool b)
01238 {
01239 ((KToggleAction*)actionCollection()->action("view_show_margins"))->setChecked(b);
01240 m_canvas->repaintAll();
01241 }
01242
01243 void
01244 KarbonView::updateRuler()
01245 {
01246 if(!m_canvas->horizontalScrollBar()->isVisible())
01247 {
01248 if( (1 + m_canvas->pageOffsetX() - m_canvas->contentsX()) >= 0 )
01249 {
01250 m_horizRuler->setGeometry( 1 + rulerWidth + m_canvas->pageOffsetX() - m_canvas->contentsX(), 0, qRound( 1 + part()->document().width() * zoom() ), rulerHeight );
01251 m_horizRuler->updateVisibleArea(0,0);
01252 }
01253 else
01254 {
01255 m_horizRuler->setGeometry( rulerWidth, 0, qRound( 1 + part()->document().width() * zoom() ) - m_canvas->contentsX() + m_canvas->pageOffsetX(), rulerHeight );
01256 m_horizRuler->updateVisibleArea((m_canvas->contentsX() - m_canvas->pageOffsetX()),0);
01257 }
01258 }
01259
01260 if(!m_canvas->verticalScrollBar()->isVisible())
01261 {
01262 if( (1 + m_canvas->pageOffsetY() - m_canvas->contentsY()) >= 0 )
01263 {
01264 m_vertRuler->setGeometry( 0, 1 + rulerHeight + m_canvas->pageOffsetY() - m_canvas->contentsY(), rulerWidth, 1 + qRound( part()->document().height() * zoom() ));
01265 m_vertRuler->updateVisibleArea(0,0);
01266 }
01267 else
01268 {
01269 m_vertRuler->setGeometry( 0, 1 + rulerHeight, rulerWidth, 1 + qRound( part()->document().height() * zoom() ) + m_canvas->contentsY() - m_canvas->pageOffsetY() );
01270 m_vertRuler->updateVisibleArea(0, (m_canvas->contentsY() - m_canvas->pageOffsetY()));
01271 }
01272 }
01273 }
01274
01275 void
01276 KarbonView::showGrid()
01277 {
01278 m_part->document().grid().isShow = m_showGridAction->isChecked();
01279 }
01280
01281 void
01282 KarbonView::snapToGrid()
01283 {
01284 m_part->document().grid().isSnap = m_snapGridAction->isChecked();
01285 }
01286
01287 void
01288 KarbonView::showSelectionPopupMenu( const QPoint &pos )
01289 {
01290 QPtrList<KAction> actionList;
01291 if( m_groupObjects->isEnabled() )
01292 actionList.append( m_groupObjects );
01293 else if( m_ungroupObjects->isEnabled() )
01294 actionList.append( m_ungroupObjects );
01295 if( m_closePath->isEnabled() )
01296 actionList.append( m_closePath );
01297 plugActionList( "selection_type_action", actionList );
01298 ((QPopupMenu *)factory()->container( "selection_popup", this ) )->exec( pos );
01299 unplugActionList( "selection_type_action" );
01300 }
01301
01302 void
01303 KarbonView::configure()
01304 {
01305 VConfigureDlg dialog( this );
01306 dialog.exec();
01307 }
01308
01309 void
01310 KarbonView::pageLayout()
01311 {
01312 KoHeadFoot hf;
01313 KoPageLayout layout = part()->pageLayout();
01314 KoUnit::Unit unit = part()->unit();
01315 if( KoPageLayoutDia::pageLayout( layout, hf, FORMAT_AND_BORDERS | DISABLE_UNIT, unit ) )
01316 {
01317 part()->setPageLayout( layout, unit );
01318 m_horizRuler->setUnit( unit );
01319 m_vertRuler->setUnit( unit );
01320 m_canvas->resizeContents( int( ( part()->pageLayout().ptWidth + 300 ) * zoom() ),
01321 int( ( part()->pageLayout().ptHeight + 460 ) * zoom() ) );
01322 part()->repaintAllViews();
01323
01324 emit pageLayoutChanged();
01325 }
01326 }
01327
01328 void
01329 KarbonView::canvasContentsMoving( int x, int y )
01330 {
01331 if( m_canvas->horizontalScrollBar()->isVisible() )
01332 {
01333 if( shell() && m_showRulerAction->isChecked() )
01334 {
01335 if( (1 + m_canvas->pageOffsetX() - x) >= 0)
01336 {
01337 m_horizRuler->setGeometry( 1 + rulerWidth + m_canvas->pageOffsetX() - x, 0, qRound( 1 + part()->document().width() * zoom() ), rulerHeight );
01338 m_horizRuler->updateVisibleArea(0,0);
01339 }
01340 else
01341 {
01342 m_horizRuler->setGeometry( rulerWidth, 0, qRound( 1 + part()->document().width() * zoom() ) - x + m_canvas->pageOffsetX(), rulerHeight );
01343 m_horizRuler->updateVisibleArea((x - m_canvas->pageOffsetX()),0);
01344 }
01345 }
01346 }
01347
01348 if( m_canvas->verticalScrollBar()->isVisible() )
01349 {
01350 if( shell() && m_showRulerAction->isChecked() )
01351 {
01352 if( (1 + m_canvas->pageOffsetY() - y) >= 0)
01353 {
01354 m_vertRuler->setGeometry( 0, 1 + rulerHeight + m_canvas->pageOffsetY() - y , rulerWidth, 1 + qRound( part()->document().height() * zoom() ));
01355 m_vertRuler->updateVisibleArea(0,0);
01356 }
01357 else
01358 {
01359 m_vertRuler->setGeometry( 0, 1 + rulerHeight, rulerWidth, 1 + qRound( part()->document().height() * zoom() ) - y + m_canvas->pageOffsetY() );
01360 m_vertRuler->updateVisibleArea(0, (y - m_canvas->pageOffsetY()));
01361 }
01362 }
01363 }
01364 }
01365
01366 void
01367 KarbonView::selectionChanged()
01368 {
01369 VSelection *selection = part()->document().selection();
01370 int count = selection->objects().count();
01371 m_groupObjects->setEnabled( false );
01372 m_closePath->setEnabled( false );
01373 m_ungroupObjects->setEnabled( false );
01374
01375 if( count > 0 )
01376 {
01377 VObject *obj = selection->objects().getFirst();
01378 VFill fill = obj->fill() ? *obj->fill() : VFill();
01379 VStroke stroke = obj->stroke() ? *obj->stroke() : VStroke();
01380
01381 if ( shell() ) {
01382
01383 m_strokeFillPreview->update( stroke, fill );
01384 m_smallPreview->update( stroke, fill );
01385
01386 }
01387 m_strokeDocker->setStroke( stroke );
01388
01389 if( count == 1 )
01390 {
01391 VGroup *group = dynamic_cast<VGroup *>( selection->objects().getFirst() );
01392 m_ungroupObjects->setEnabled( group );
01393 VPath *path = dynamic_cast<VPath *>( selection->objects().getFirst() );
01394 m_closePath->setEnabled( path && !path->isClosed() );
01395 }
01396 else
01397 m_groupObjects->setEnabled( true );
01398
01399 selection->setStroke( stroke );
01400 selection->setFill( fill );
01401 m_setLineWidth->setEnabled( true );
01402 m_setLineWidth->updateValue( stroke.lineWidth() );
01403
01404 m_lineStyleAction->setEnabled( true );
01405 if( stroke.dashPattern().array().isEmpty() )
01406 m_lineStyleAction->setCurrentSelection( Qt::SolidLine );
01407 else if( stroke.dashPattern().array()[ 0 ] == 0. )
01408 m_lineStyleAction->setCurrentSelection( Qt::NoPen );
01409 else if( stroke.dashPattern().array()[ 0 ] == 2. )
01410 m_lineStyleAction->setCurrentSelection( Qt::DotLine );
01411 else if( stroke.dashPattern().array().count() == 2 )
01412 m_lineStyleAction->setCurrentSelection( Qt::DashLine );
01413 else if( stroke.dashPattern().array().count() == 4 )
01414 m_lineStyleAction->setCurrentSelection( Qt::DashDotLine );
01415 else if( stroke.dashPattern().array().count() == 6 )
01416 m_lineStyleAction->setCurrentSelection( Qt::DashDotDotLine );
01417
01418 m_deleteSelectionAction->setEnabled( true );
01419 }
01420 else
01421 {
01422 if ( shell() )
01423 {
01424 VFill fill = selection->fill() ? *selection->fill() : VFill();
01425 VStroke stroke = selection->stroke() ? *selection->stroke() : VStroke();
01426
01427 m_strokeFillPreview->update( stroke, fill );
01428 }
01429 m_lineStyleAction->setEnabled( false );
01430 m_deleteSelectionAction->setEnabled( false );
01431 }
01432 emit selectionChange();
01433 }
01434 void
01435 KarbonView::setCursor( const QCursor &c )
01436 {
01437 m_canvas->setCursor( c );
01438 }
01439
01440 void
01441 KarbonView::repaintAll( const KoRect &r )
01442 {
01443 m_canvas->repaintAll( r );
01444 }
01445
01446 void
01447 KarbonView::repaintAll( bool repaint )
01448 {
01449 m_canvas->repaintAll( repaint );
01450 }
01451 void
01452 KarbonView::setPos( const KoPoint& p )
01453 {
01454 m_canvas->setPos( p );
01455 }
01456
01457 void
01458 KarbonView::setViewportRect( const KoRect &rect )
01459 {
01460 m_canvas->setViewportRect( rect );
01461 }
01462
01463 void
01464 KarbonView::setUnit( KoUnit::Unit )
01465 {
01466 }
01467
01468 void KarbonView::createDocumentTabDock()
01469 {
01470 m_DocumentTab = new VDocumentTab(this, this);
01471 m_DocumentTab->setCaption(i18n("Document"));
01472 paletteManager()->addWidget(m_DocumentTab, "DocumentTabDock", "DocumentPanel");
01473 connect( m_part, SIGNAL( unitChanged( KoUnit::Unit ) ), m_DocumentTab, SLOT( updateDocumentInfo() ) );
01474 }
01475
01476 void KarbonView::createLayersTabDock()
01477 {
01478 m_LayersTab = new VLayersTab(this, this);
01479 m_LayersTab->setCaption(i18n("Layers"));
01480 paletteManager()->addWidget(m_LayersTab, "LayersTabDock", "DocumentPanel");
01481 }
01482
01483 void KarbonView::createHistoryTabDock()
01484 {
01485 m_HistoryTab = new VHistoryTab(part(), this);
01486 m_HistoryTab->setCaption(i18n("History"));
01487 paletteManager()->addWidget(m_HistoryTab, "HistoryTabDock", "DocumentPanel");
01488 }
01489
01490 void KarbonView::createStrokeDock()
01491 {
01492 m_strokeDocker = new VStrokeDocker(part(), this);
01493 m_strokeDocker->setCaption(i18n("Stroke Properties"));
01494 paletteManager()->addWidget(m_strokeDocker, "StrokeTabDock", "StrokePanel");
01495
01496 connect( part(), SIGNAL( unitChanged( KoUnit::Unit ) ), m_strokeDocker, SLOT( setUnit( KoUnit::Unit ) ) );
01497 }
01498
01499 void KarbonView::createColorDock()
01500 {
01501 m_ColorManager = new VColorDocker(part(),this);
01502
01503 paletteManager()->addWidget(m_ColorManager, "ColorTabDock", "ColorPanel");
01504
01505 connect( this, SIGNAL( selectionChange() ), m_ColorManager, SLOT( update() ) );
01506 }
01507
01508 void KarbonView::createTransformDock()
01509 {
01510 m_TransformDocker = new VTransformDocker(part(), this);
01511 m_TransformDocker->setCaption(i18n("Transform"));
01512 paletteManager()->addWidget(m_TransformDocker, "TransformTabDock", "TransformPanel");
01513
01514 connect( this, SIGNAL( selectionChange() ), m_TransformDocker, SLOT( update() ) );
01515 connect( part(), SIGNAL( unitChanged( KoUnit::Unit ) ), m_TransformDocker, SLOT( setUnit( KoUnit::Unit ) ) );
01516 }
01517
01518 void KarbonView::createResourceDock()
01519 {
01520 m_styleDocker = new VStyleDocker( part(), this );
01521 m_styleDocker->setCaption(i18n("Resources"));
01522 paletteManager()->addWidget(m_styleDocker, "ResourceTabDock", "ResourcePanel");
01523 }
01524
01525 VToolController *
01526 KarbonView::toolController()
01527 {
01528 return m_toolController;
01529 }
01530
01531 void KarbonView::commandExecuted( VCommand *command )
01532 {
01533 if( command && command->changesSelection() )
01534 selectionChanged();
01535 }
01536
01537 void KarbonView::strokeFillSelectionChanged( KDualColorButton::DualColor s )
01538 {
01539 if( s == KDualColorButton::Foreground )
01540 m_strokeFillPreview->setStrokeSelected();
01541 else
01542 m_strokeFillPreview->setFillSelected();
01543 selectionChanged();
01544 }
01545
01546 void KarbonView::colorChanged( const QColor &c )
01547 {
01548 selectionChanged();
01549 }
01550
01551 #include "karbon_view.moc"
01552