karbon

karbon_view.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001, 2002, 2003 The Karbon Developers
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "karbon_view.h"
21
22#include <tqdragobject.h>
23#include <tqiconset.h>
24#include <tqapplication.h>
25#include <tqclipboard.h>
26#include <tqpopupmenu.h>
27#include <tqpaintdevicemetrics.h>
28#include <tqpainter.h>
29
30#include <tdeaction.h>
31#include <kcolordrag.h>
32#include <tdelocale.h>
33#include <kiconloader.h>
34#include <tdemessagebox.h>
35#include <kprinter.h>
36
37#include <KoMainWindow.h>
38#include <KoFilterManager.h>
39#include <kstatusbar.h>
40#include <tdefiledialog.h>
41#include <kstdaction.h>
42#include <KoContextCelp.h>
43#include <KoUnitWidgets.h>
44#include <KoPageLayoutDia.h>
45#include <vruler.h>
46#include <Kolinestyleaction.h>
47
48// Commands.
49#include "valigncmd.h"
50#include "vcleanupcmd.h"
51#include "vclipartcmd.h"
52#include "vclosepathcmd.h"
53#include "vdeletecmd.h"
54#include "vdistributecmd.h"
55#include "vfillcmd.h"
56#include "vgroupcmd.h"
57#include "vstrokecmd.h"
58#include "vtransformcmd.h"
59#include "vinsertcmd.h"
60#include "vungroupcmd.h"
61#include "vzordercmd.h"
62
63// Dialogs.
64#include "vconfiguredlg.h"
65
66// Dockers.
67#include <kopalettemanager.h>
68#include "vcolordocker.h"
69#include "vdocumentdocker.h"
70#include "vstrokedocker.h"
71#include "vstyledocker.h"
72#include "vtransformdocker.h"
73
74// ToolBars
75//#include "vselecttoolbar.h"
76
77// Statusbar
78#include "vsmallpreview.h"
79
80// The rest.
81#include "karbon_factory.h"
82#include "karbon_part.h"
83#include "karbon_view_iface.h"
84#include "vglobal.h"
85#include "vselection.h"
86#include "vtool.h"
87#include "vtoolcontroller.h"
88#include "vcomposite.h"
89#include "vgroup.h"
90#include "vpainterfactory.h"
91#include "vqpainter.h"
92#include "vkopainter.h"
93#include "vstrokefillpreview.h"
94#include "vtypebuttonbox.h"
95#include "vstatebutton.h"
96#include "vcanvas.h"
97#include "vtoolbox.h"
98#include "karbon_drag.h"
99// #include "vselectnodestool.h"
100
101#include <unistd.h>
102
103// Only for debugging.
104#include <kdebug.h>
105
106const int rulerWidth = 20; // vertical ruler width
107const int rulerHeight = 20; // horizontal ruler height
108
109KarbonView::KarbonView( KarbonPart* p, TQWidget* parent, const char* name )
110 : KoView( p, parent, name ), KXMLGUIBuilder( shell() ), m_part( p )
111{
112 m_toolbox = 0L;
113 m_toolController = new VToolController( this );
114 m_toolController->init();
115
116 setInstance( KarbonFactory::instance(), true );
117
118 setClientBuilder( this );
119
120 if( !p->isReadWrite() )
121 setXMLFile( TQString::fromLatin1( "karbon_readonly.rc" ) );
122 else
123 setXMLFile( TQString::fromLatin1( "karbon.rc" ) );
124
125 m_dcop = 0L;
126 dcopObject(); // build it
127
128 // set up status bar message
129 m_status = new KStatusBarLabel( TQString(), 0, statusBar() );
130 m_status->setAlignment( AlignLeft | AlignVCenter );
131 m_status->setMinimumWidth( 300 );
132 addStatusBarItem( m_status, 1 );
133 m_cursorCoords = new KStatusBarLabel( TQString(), 0, statusBar() );
134 m_cursorCoords->setAlignment( AlignLeft | AlignVCenter );
135 m_cursorCoords->setMinimumWidth( 50 );
136 addStatusBarItem( m_cursorCoords, 0 );
137 m_smallPreview = new VSmallPreview( this, name );
138 addStatusBarItem( m_smallPreview );
139
140 initActions();
141
142 m_DocumentTab = 0L;
143 m_LayersTab = 0L;
144 m_HistoryTab = 0L;
145 m_strokeFillPreview = 0L;
146 m_ColorManager = 0L;
147 m_strokeDocker = 0L;
148 m_styleDocker = 0L;
149 m_TransformDocker = 0L;
150
151 // set selectTool by default
152 //m_toolbox->slotPressButton( 0 );
153
154 m_pPaletteManager = new KoPaletteManager(this, actionCollection(), "karbon palette manager");
155
156 unsigned int max = part()->maxRecentFiles();
157 setNumberOfRecentFiles( max );
158
159 reorganizeGUI();
160
161 connect( p, TQ_SIGNAL( unitChanged( KoUnit::Unit ) ), this, TQ_SLOT( setUnit( KoUnit::Unit ) ) );
162
163 // widgets:
164 m_horizRuler = new VRuler( TQt::Horizontal, this );
165 m_horizRuler->setUnit(p->unit());
166 connect( p, TQ_SIGNAL( unitChanged( KoUnit::Unit ) ), m_horizRuler, TQ_SLOT( setUnit( KoUnit::Unit ) ) );
167
168 m_vertRuler = new VRuler( TQt::Vertical, this );
169 m_vertRuler->setUnit(p->unit());
170 connect( p, TQ_SIGNAL( unitChanged( KoUnit::Unit ) ), m_vertRuler, TQ_SLOT( setUnit( KoUnit::Unit ) ) );
171
172 m_canvas = new VCanvas( this, this, p );
173 connect( m_canvas, TQ_SIGNAL( contentsMoving( int, int ) ), this, TQ_SLOT( canvasContentsMoving( int, int ) ) );
174
175 m_canvas->show();
176
177 // set up factory
178 m_painterFactory = new VPainterFactory;
179 m_painterFactory->setPainter( canvasWidget()->pixmap(), width(), height() );
180 m_painterFactory->setEditPainter( canvasWidget()->viewport(), width(), height() );
181
182 if( shell() )
183 {
184 //Create Dockers
185 createColorDock();
186 createStrokeDock();
187 createTransformDock();
188 createDocumentTabDock();
189 createLayersTabDock();
190 createHistoryTabDock();
191 createResourceDock();
192
193 if( m_showRulerAction->isChecked() )
194 {
195 m_horizRuler->show();
196 m_vertRuler->show();
197 }
198 else
199 {
200 m_horizRuler->hide();
201 m_vertRuler->hide();
202 }
203
204 m_horizRuler->installEventFilter(m_canvas);
205 m_vertRuler->installEventFilter(m_canvas);
206 }
207
208 zoomChanged();
209}
210
211KarbonView::~KarbonView()
212{
213 kdDebug(38000) << "Handling KarbonView dtor" << endl;
214
215 // widgets:
216 delete m_smallPreview;
217 delete m_status;
218 delete m_cursorCoords;
219
220 delete m_painterFactory;
221
222 delete m_canvas;
223
224 delete m_dcop;
225
226 delete m_toolController;
227}
228
229static TQt::Dock stringToDock( const TQString& attrPosition )
230{
231 TDEToolBar::Dock dock = TDEToolBar::DockTop;
232 if ( !attrPosition.isEmpty() ) {
233 if ( attrPosition == "top" )
234 dock = TQt::DockTop;
235 else if ( attrPosition == "left" )
236 dock = TQt::DockLeft;
237 else if ( attrPosition == "right" )
238 dock = TQt::DockRight;
239 else if ( attrPosition == "bottom" )
240 dock = TQt::DockBottom;
241 else if ( attrPosition == "floating" )
242 dock = TQt::DockTornOff;
243 else if ( attrPosition == "flat" )
244 dock = TQt::DockMinimized;
245 }
246
247 return dock;
248}
249
250TQWidget *
251KarbonView::createContainer( TQWidget *parent, int index, const TQDomElement &element, int &id )
252{
253 if( element.attribute( "name" ) == "Tools" )
254 {
255 m_toolbox = new VToolBox( mainWindow(), "Tools", KarbonFactory::instance() );
256 toolController()->setUp( actionCollection(), m_toolbox );
257
258 kdDebug() << "Toolbox position: " << element.attribute( "position" ) << "\n";
259 Dock dock = stringToDock( element.attribute( "position" ).lower() );
260
261 mainWindow()->addDockWindow( m_toolbox, dock, false);
262 mainWindow()->moveDockWindow( m_toolbox, dock, false, 0, 0 );
263
264 //connect( m_toolbox, TQ_SIGNAL( activeToolChanged( VTool * ) ), this, TQ_SLOT( slotActiveToolChanged( VTool * ) ) );
265
266 if( shell() )
267 {
268 m_strokeFillPreview = new VStrokeFillPreview( part(), m_toolbox );
269 m_typeButtonBox = new VTypeButtonBox( part(), m_toolbox );
270
271 connect( m_strokeFillPreview, TQ_SIGNAL( fillSelected() ), m_typeButtonBox, TQ_SLOT( setFill() ) );
272 connect( m_strokeFillPreview, TQ_SIGNAL( strokeSelected() ), m_typeButtonBox, TQ_SLOT( setStroke() ) );
273
274 connect( m_strokeFillPreview, TQ_SIGNAL( strokeChanged( const VStroke & ) ), this, TQ_SLOT( slotStrokeChanged( const VStroke & ) ) );
275 connect( m_strokeFillPreview, TQ_SIGNAL( fillChanged( const VFill & ) ), this, TQ_SLOT( slotFillChanged( const VFill & ) ) );
276
277 connect( m_strokeFillPreview, TQ_SIGNAL( strokeSelected() ), m_ColorManager, TQ_SLOT( setStrokeDocker() ) );
278 connect( m_strokeFillPreview, TQ_SIGNAL( fillSelected( ) ), m_ColorManager, TQ_SLOT( setFillDocker() ) );
279
280 connect( m_part->commandHistory(), TQ_SIGNAL( commandExecuted( VCommand* ) ), this, TQ_SLOT( commandExecuted( VCommand* ) ) );
281
282 connect( m_ColorManager, TQ_SIGNAL(modeChanged( KDualColorButton::DualColor)), this, TQ_SLOT( strokeFillSelectionChanged(KDualColorButton::DualColor) ) );
283 connect( m_ColorManager, TQ_SIGNAL(bgColorChanged( const TQColor & )), this, TQ_SLOT(colorChanged( const TQColor & )) );
284 connect( m_ColorManager, TQ_SIGNAL(fgColorChanged( const TQColor & )), this, TQ_SLOT(colorChanged( const TQColor & )) );
285 selectionChanged();
286
287 //create toolbars
288// m_selectToolBar = new VSelectToolBar( this, "selecttoolbar" );
289// mainWindow()->addToolBar( m_selectToolBar );
290 }
291 }
292
293 return KXMLGUIBuilder::createContainer( parent, index, element, id );
294}
295
296void
297KarbonView::removeContainer( TQWidget *container, TQWidget *parent,
298 TQDomElement &element, int id )
299{
300 if( container )
301 kdDebug(38000) << container << endl;
302
303 if( shell() && container == m_toolbox )
304 {
305 disconnect( m_part->commandHistory(), TQ_SIGNAL( commandExecuted( VCommand* ) ), this, TQ_SLOT( commandExecuted( VCommand* ) ) );
306 disconnect( m_ColorManager, TQ_SIGNAL(modeChanged( KDualColorButton::DualColor)), this, TQ_SLOT( strokeFillSelectionChanged(KDualColorButton::DualColor) ) );
307 disconnect( m_ColorManager, TQ_SIGNAL(bgColorChanged( const TQColor & )), this, TQ_SLOT(colorChanged( const TQColor & )) );
308 disconnect( m_ColorManager, TQ_SIGNAL(fgColorChanged( const TQColor & )), this, TQ_SLOT(colorChanged( const TQColor & )) );
309 delete m_toolbox;
310 m_toolbox = 0L;
311 m_toolController->youAintGotNoToolBox();
312// delete m_strokeFillPreview;
313 m_strokeFillPreview = 0;
314// delete m_typeButtonBox;
315 m_typeButtonBox = 0;
316// delete m_selectToolBar;
317// m_selectToolBar = 0L;
318 }
319 else
320 KXMLGUIBuilder::removeContainer( container, parent, element, id );
321}
322
323
324DCOPObject *
325KarbonView::dcopObject()
326{
327 if( !m_dcop )
328 m_dcop = new KarbonViewIface( this );
329
330 return m_dcop;
331}
332
333TQWidget*
334KarbonView::canvas() const
335{
336 return m_canvas;
337}
338
339void
340KarbonView::resizeEvent( TQResizeEvent* /*event*/ )
341{
342 if( shell() && m_showRulerAction->isChecked())
343 {
344 m_canvas->setGeometry( rulerWidth, rulerHeight, width() - rulerWidth, height() - rulerHeight );
345 updateRuler();
346 }
347 else
348 {
349 m_horizRuler->hide();
350 m_vertRuler->hide();
351 m_canvas->setGeometry( 0, 0, width(), height() );
352 }
353
354 zoomChanged();
355 reorganizeGUI();
356}
357
358void
359KarbonView::dropEvent( TQDropEvent *e )
360{
361 //Accepts TQColor - from Color Manager's KColorPatch
362 TQColor color;
363 VColor realcolor;
364 VObjectList selection;
365
366 if( KColorDrag::decode( e, color ) )
367 {
368 float r = color.red() / 255.0;
369 float g = color.green() / 255.0;
370 float b = color.blue() / 255.0;
371
372 realcolor.set( r, g, b );
373
374 if( part() )
375 if( m_strokeFillPreview->strokeIsSelected() )
376 part()->addCommand( new VStrokeCmd( &part()->document(), realcolor ), true );
377 else
378 part()->addCommand( new VFillCmd( &part()->document(), realcolor ), true );
379 }
380 else if( KarbonDrag::decode( e, selection, m_part->document() ) )
381 {
382 VObject *clipart = selection.first();
383 KoPoint p( e->pos() );
384 p = m_canvas->toContents( p );
385 TQWMatrix mat( 1, 0, 0, 1, p.x(), p.y() );
386
387 VTransformCmd trafo( 0L, mat );
388 trafo.visit( *clipart );
389 VClipartCmd* cmd = new VClipartCmd( &m_part->document(), i18n( "Insert Clipart" ), clipart );
390
391 m_part->addCommand( cmd, true );
392 }
393}
394
395void
396KarbonView::print( KPrinter &printer )
397{
398 // TODO : ultimately use plain TQPainter here as that is better suited to print system
399 kdDebug(38000) << "KarbonView::print" << endl;
400
401 TQPaintDeviceMetrics metrics( ( TQPaintDevice * ) & printer );
402 printer.setFullPage( true );
403
404 KoPageLayout pageLayout = part()->pageLayout();
405 printer.setOrientation( pageLayout.orientation == PG_PORTRAIT ? KPrinter::Portrait : KPrinter::Landscape );
406 printer.setPageSize( (KPrinter::PageSize)KoPageFormat::printerPageSize( pageLayout.format ) );
407
408 // we are using 72 dpi internally
409 double zoom = metrics.logicalDpiX() / 72.0;
410
411 TQWMatrix mat;
412 mat.scale( 1, -1 );
413 mat.translate( 0, -part()->document().height()*zoom );
414
415 double w = zoom*part()->document().width();
416 double h = zoom*part()->document().height();
417
418 KoRect rect( 0, 0, w, h );
419
420 TQPixmap img( static_cast<int>( w ), static_cast<int>( h ) );
421
422 // first use the libarts painter to draw into the pixmap
423 VKoPainter kop( ( TQPaintDevice * )&img, static_cast<int>( w ), static_cast<int>( h ) );
424
425 kop.setZoomFactor( zoom );
426 kop.setWorldMatrix( mat );
427
428 kop.begin();
429
430 part()->document().draw( &kop, &rect );
431
432 kop.end();
433
434 TQPainter p;
435
436 // us kopainter to draw the pixmap
437 // note that it is looking unsmooth when previewing,
438 // but the print is actually ok as we are printing at 100% zoom anyway
439 p.begin( &printer );
440 p.drawPixmap( 0, 0, img );
441 p.end();
442}
443
444void
445KarbonView::fileImportGraphic()
446{
447 TQStringList filter;
448 filter << "application/x-karbon" << "image/svg+xml" << "image/x-wmf" << "image/x-eps" << "application/postscript";
449 KFileDialog *dialog = new KFileDialog( "foo", TQString(), 0L, "Choose Graphic to Add", true);
450 dialog->setMimeFilter( filter, "application/x-karbon" );
451 if(dialog->exec()!=TQDialog::Accepted) {
452 delete dialog;
453 return;
454 }
455 TQString fname = dialog->selectedFile();
456 //kdDebug(38000) << "in : " << fname.latin1() << endl;
457 //kdDebug(38000) << "part()->document()->nativeFormatMimeType().latin1() : " << part()->nativeFormatMimeType() << endl;
458 //kdDebug(38000) << "dialog->currentMimeFilter().latin1() : " << dialog->currentMimeFilter().latin1() << endl;
459 if( part()->nativeFormatMimeType() == dialog->currentMimeFilter().latin1() )
460 part()->mergeNativeFormat( fname );
461 else
462 {
463 KoFilterManager man( part() );
464 KoFilter::ConversionStatus status;
465 TQString importedFile = man.import( fname, status );
466 part()->mergeNativeFormat( importedFile );
467 if( !importedFile.isEmpty() )
468 unlink( TQFile::encodeName( importedFile ) );
469 }
470 delete dialog;
471 part()->repaintAllViews();
472}
473
474void
475KarbonView::editCut()
476{
477 addSelectionToClipboard();
478 // remove selection
479 editDeleteSelection();
480}
481
482void
483KarbonView::editCopy()
484{
485 addSelectionToClipboard();
486}
487
488void
489KarbonView::addSelectionToClipboard() const
490{
491 if( part()->document().selection()->objects().count() <= 0 )
492 return;
493
494 KarbonDrag* kd = new KarbonDrag();
495 kd->setObjectList( part()->document().selection()->objects() );
496 TQApplication::clipboard()->setData( kd );
497}
498
499void
500KarbonView::editPaste()
501{
502 KarbonDrag kd;
503 VObjectList objects;
504
505 if( !kd.decode( TQApplication::clipboard()->data(), objects, part()->document() ) )
506 return;
507
508 // Paste with a small offset.
509 double copyOffset = part()->instance()->config()->readNumEntry( "CopyOffset", 10 );
510 part()->addCommand( new VInsertCmd( &part()->document(),
511 objects.count() == 1
512 ? i18n( "Paste Object" )
513 : i18n( "Paste Objects" ),
514 &objects, copyOffset ),
515 true );
516
517 part()->repaintAllViews();
518 selectionChanged();
519}
520
521void
522KarbonView::editSelectAll()
523{
524 part()->document().selection()->append();
525
526 if( part()->document().selection()->objects().count() > 0 )
527 part()->repaintAllViews();
528
529 selectionChanged();
530}
531
532void
533KarbonView::editDeselectAll()
534{
535 if( part()->document().selection()->objects().count() > 0 )
536 {
537 part()->document().selection()->clear();
538 part()->repaintAllViews();
539 }
540
541 selectionChanged();
542}
543
544void
545KarbonView::editDeleteSelection()
546{
547 kdDebug(38000) << "*********" << endl;
548
549 if( part()->document().selection()->objects().count() > 0 )
550 {
551 part()->addCommand(
552 new VDeleteCmd( &part()->document() ),
553 true );
554 }
555}
556
557void
558KarbonView::editPurgeHistory()
559{
560 // TODO: check for history size != 0
561
562 if( KMessageBox::warningContinueCancel( this,
563 i18n( "This action cannot be undone later. Do you really want to continue?" ),
564 i18n( "Purge History" ),
565 KStdGuiItem::del(),
566 "edit_purge_history" ) )
567 {
568 // Use the VCleanUp command to remove "deleted"
569 // objects from all layers.
570 VCleanUpCmd cmd( &part()->document() );
571 cmd.execute();
572
573 part()->clearHistory();
574 }
575}
576
577void
578KarbonView::selectionAlignHorizontalLeft()
579{
580 part()->addCommand(
581 new VAlignCmd( &part()->document(), VAlignCmd::ALIGN_HORIZONTAL_LEFT ), true );
582}
583void
584KarbonView::selectionAlignHorizontalCenter()
585{
586 part()->addCommand(
587 new VAlignCmd( &part()->document(), VAlignCmd::ALIGN_HORIZONTAL_CENTER ), true );
588}
589
590void
591KarbonView::selectionAlignHorizontalRight()
592{
593 part()->addCommand(
594 new VAlignCmd( &part()->document(), VAlignCmd::ALIGN_HORIZONTAL_RIGHT ), true );
595}
596
597void
598KarbonView::selectionAlignVerticalTop()
599{
600 part()->addCommand(
601 new VAlignCmd( &part()->document(), VAlignCmd::ALIGN_VERTICAL_TOP ), true );
602}
603
604void
605KarbonView::selectionAlignVerticalCenter()
606{
607 part()->addCommand(
608 new VAlignCmd( &part()->document(), VAlignCmd::ALIGN_VERTICAL_CENTER ), true );
609}
610
611void
612KarbonView::selectionAlignVerticalBottom()
613{
614 part()->addCommand(
615 new VAlignCmd( &part()->document(), VAlignCmd::ALIGN_VERTICAL_BOTTOM ), true );
616}
617
618void
619KarbonView::selectionDistributeHorizontalCenter()
620{
621 part()->addCommand(
622 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_HORIZONTAL_CENTER ), true );
623}
624
625void
626KarbonView::selectionDistributeHorizontalGap()
627{
628 part()->addCommand(
629 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_HORIZONTAL_GAP ), true );
630}
631
632void
633KarbonView::selectionDistributeHorizontalLeft()
634{
635 part()->addCommand(
636 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_HORIZONTAL_LEFT ), true );
637}
638
639void
640KarbonView::selectionDistributeHorizontalRight()
641{
642 part()->addCommand(
643 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_HORIZONTAL_RIGHT ), true );
644}
645
646void
647KarbonView::selectionDistributeVerticalCenter()
648{
649 part()->addCommand(
650 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_VERTICAL_CENTER ), true );
651}
652
653void
654KarbonView::selectionDistributeVerticalGap()
655{
656 part()->addCommand(
657 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_VERTICAL_GAP ), true );
658}
659
660void
661KarbonView::selectionDistributeVerticalBottom()
662{
663 part()->addCommand(
664 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_VERTICAL_BOTTOM ), true );
665}
666
667void
668KarbonView::selectionDistributeVerticalTop()
669{
670 part()->addCommand(
671 new VDistributeCmd( &part()->document(), VDistributeCmd::DISTRIBUTE_VERTICAL_TOP ), true );
672}
673
674void
675KarbonView::selectionDuplicate()
676{
677 if ( !part()->document().selection()->objects().count() )
678 return;
679
680 VObjectList objects;
681
682 // Create copies of all the objects and not just the list.
683 VObjectListIterator itr( part()->document().selection()->objects() );
684 for ( ; itr.current() ; ++itr ) {
685 objects.append( itr.current()->clone() );
686 }
687
688 // Paste with a small offset.
689 double copyOffset = part()->instance()->config()->readNumEntry( "CopyOffset", 10 );
690 part()->addCommand( new VInsertCmd( &part()->document(),
691 objects.count() == 1
692 ? i18n( "Duplicate Object" )
693 : i18n( "Duplicate Objects" ),
694 &objects, copyOffset ),
695 true );
696
697 part()->repaintAllViews();
698 selectionChanged();
699}
700
701void
702KarbonView::selectionBringToFront()
703{
704 part()->addCommand(
705 new VZOrderCmd( &part()->document(), VZOrderCmd::bringToFront ), true );
706}
707
708void
709KarbonView::selectionMoveUp()
710{
711 part()->addCommand(
712 new VZOrderCmd( &part()->document(), VZOrderCmd::up ), true );
713}
714
715void
716KarbonView::selectionMoveDown()
717{
718 part()->addCommand(
719 new VZOrderCmd( &part()->document(), VZOrderCmd::down ), true );
720}
721
722void
723KarbonView::selectionSendToBack()
724{
725 part()->addCommand(
726 new VZOrderCmd( &part()->document(), VZOrderCmd::sendToBack ), true );
727}
728
729void
730KarbonView::groupSelection()
731{
732 part()->addCommand( new VGroupCmd( &part()->document() ), true );
733}
734
735void
736KarbonView::ungroupSelection()
737{
738 part()->addCommand( new VUnGroupCmd( &part()->document() ), true );
739}
740
741void
742KarbonView::closePath()
743{
744 part()->addCommand( new VClosePathCmd( &part()->document() ), true );
745}
746
747void
748KarbonView::slotActiveToolChanged( VTool *tool )
749{
750 toolController()->setCurrentTool( tool );
751
752 m_canvas->repaintAll();
753}
754
755void
756KarbonView::viewModeChanged()
757{
758 canvasWidget()->pixmap()->fill();
759
760 if( m_viewAction->currentItem() == 1 )
761 m_painterFactory->setWireframePainter( canvasWidget()->pixmap(), width(), height() );
762 else
763 m_painterFactory->setPainter( canvasWidget()->pixmap(), width(), height() );
764
765 m_canvas->repaintAll();
766}
767
768void
769KarbonView::setZoomAt( double zoom, const KoPoint &p )
770{
771 TQString zoomText = TQString( "%1%" ).arg( zoom * 100.0, 0, 'f', 2 );
772 TQStringList stl = m_zoomAction->items();
773 if( stl.first() == "25%" )
774 {
775 stl.prepend( zoomText.latin1() );
776 m_zoomAction->setItems( stl );
777 m_zoomAction->setCurrentItem( 0 );
778 }
779 else
780 {
781 m_zoomAction->setCurrentItem( 0 );
782 m_zoomAction->changeItem( m_zoomAction->currentItem(), zoomText.latin1() );
783 }
784 zoomChanged( p );
785}
786
787void
788KarbonView::viewZoomIn()
789{
790 setZoomAt( zoom() * 1.50 );
791}
792
793void
794KarbonView::viewZoomOut()
795{
796 setZoomAt( zoom() * 0.75 );
797}
798
799void
800KarbonView::zoomChanged( const KoPoint &p )
801{
802 double centerX;
803 double centerY;
804 double zoomFactor;
805
806 if( !p.isNull() )
807 {
808 centerX = ( ( p.x() ) * zoom() + m_canvas->pageOffsetX() ) / double( m_canvas->contentsWidth() );
809 centerY = 1 - ( ( p.y() ) * zoom() + m_canvas->pageOffsetY() ) / double( m_canvas->contentsHeight() );
810 zoomFactor = m_zoomAction->currentText().remove( '%' ).toDouble() / 100.0;
811 }
812 else if( m_zoomAction->currentText() == i18n("Zoom Width") )
813 {
814 centerX = 0.5;
815 centerY = double( m_canvas->contentsY() + 0.5 * m_canvas->visibleHeight() ) / double( m_canvas->contentsHeight() );
816 zoomFactor = double( m_canvas->visibleWidth() ) / double( part()->document().width() );
817 }
818 else if( m_zoomAction->currentText() == i18n("Whole Page") )
819 {
820 centerX = 0.5;
821 centerY = 0.5;
822 double zoomFactorX = double( m_canvas->visibleWidth() ) / double( part()->document().width() );
823 double zoomFactorY = double( m_canvas->visibleHeight() ) / double( part()->document().height() );
824
825 if(zoomFactorX < 0 && zoomFactorY > 0)
826 zoomFactor = zoomFactorY;
827 else if(zoomFactorX > 0 && zoomFactorY < 0)
828 zoomFactor = zoomFactorX;
829 else if(zoomFactorX < 0 && zoomFactorY < 0)
830 zoomFactor = 0.0001;
831 else
832 zoomFactor = kMin( zoomFactorX, zoomFactorY );
833 }
834 else
835 {
836 if( m_canvas->contentsWidth() > m_canvas->visibleWidth() )
837 centerX = double( m_canvas->contentsX() + 0.5 * m_canvas->visibleWidth() ) / double( m_canvas->contentsWidth() );
838 else
839 centerX = 0.5;
840 if( m_canvas->contentsHeight() > m_canvas->visibleHeight() )
841 centerY = double( m_canvas->contentsY() + 0.5 * m_canvas->visibleHeight() ) / double( m_canvas->contentsHeight() );
842 else
843 centerY = 0.5;
844 zoomFactor = m_zoomAction->currentText().remove( '%' ).toDouble() / 100.0;
845 }
846 kdDebug(38000) << "centerX : " << centerX << endl;
847 kdDebug(38000) << "centerY : " << centerY << endl;
848 kdDebug(38000) << "zoomFactor : " << zoomFactor << endl;
849 if( zoomFactor == 0.0 ) return;
850
851 // above 2000% probably doesn't make sense... (Rob)
852 if( zoomFactor > 20 )
853 {
854 zoomFactor = 20;
855 m_zoomAction->changeItem( m_zoomAction->currentItem(), " 2000%" );
856 }
857
858 KoView::setZoom( zoomFactor );
859
860 m_canvas->viewport()->setUpdatesEnabled( false );
861
862 m_canvas->resizeContents( int( ( part()->pageLayout().ptWidth + 300 ) * zoomFactor ),
863 int( ( part()->pageLayout().ptHeight + 460 ) * zoomFactor ) );
864
865
866 VPainter *painter = painterFactory()->editpainter();
867 painter->setZoomFactor( zoomFactor );
868
869 m_canvas->setViewport( centerX, centerY );
870 m_canvas->repaintAll();
871 m_canvas->viewport()->setUpdatesEnabled( true );
872
873
874 if( shell() && m_showRulerAction->isChecked() )
875 {
876 m_horizRuler->setZoom( zoomFactor );
877 m_vertRuler->setZoom( zoomFactor );
878 m_canvas->setGeometry( rulerWidth, rulerHeight, width() - rulerWidth, height() - rulerHeight );
879 updateRuler();
880 }
881 else
882 {
883 m_horizRuler->hide();
884 m_vertRuler->hide();
885 }
886 m_canvas->viewport()->setFocus();
887
888 emit zoomChanged( zoomFactor );
889}
890
891void
892KarbonView::setLineStyle( int style )
893{
894 TQValueList<float> dashes;
895 if( style == TQt::NoPen )
896 part()->addCommand( new VStrokeCmd( &part()->document(), dashes << 0 << 20 ), true );
897 else if( style == TQt::SolidLine )
898 part()->addCommand( new VStrokeCmd( &part()->document(), dashes ), true );
899 else if( style == TQt::DashLine )
900 part()->addCommand( new VStrokeCmd( &part()->document(), dashes << 12 << 6 ), true );
901 else if( style == TQt::DotLine )
902 part()->addCommand( new VStrokeCmd( &part()->document(), dashes << 2 << 2 ), true );
903 else if( style == TQt::DashDotLine )
904 part()->addCommand( new VStrokeCmd( &part()->document(), dashes << 12 << 2 << 2 << 2 ), true );
905 else if( style == TQt::DashDotDotLine )
906 part()->addCommand( new VStrokeCmd( &part()->document(), dashes << 12 << 2 << 2 << 2 << 2 << 2 ), true );
907}
908
909void
910KarbonView::slotStrokeChanged( const VStroke &c )
911{
912 part()->document().selection()->setStroke( c );
913 selectionChanged();
914}
915
916void
917KarbonView::slotFillChanged( const VFill &f )
918{
919 part()->document().selection()->setFill( f );
920 selectionChanged();
921}
922
923void
924KarbonView::setLineWidth()
925{
926 setLineWidth( m_setLineWidth->value() );
927 selectionChanged();
928}
929
930//necessary for dcop call !
931void
932KarbonView::setLineWidth( double val )
933{
934 part()->addCommand( new VStrokeCmd( &part()->document(), val ), true );
935}
936
937void
938KarbonView::initActions()
939{
940 // view ----->
941 m_viewAction = new TDESelectAction(
942 i18n( "View &Mode" ), 0, this,
943 TQ_SLOT( viewModeChanged() ), actionCollection(), "view_mode" );
944
945 m_zoomAction = new TDESelectAction(
946 i18n( "&Zoom" ), "viewmag", 0, this,
947 TQ_SLOT( zoomChanged() ), actionCollection(), "view_zoom" );
948
949 TQStringList mstl;
950 mstl << i18n( "Normal" ) << i18n( "Wireframe" );
951 m_viewAction->setItems( mstl );
952 m_viewAction->setCurrentItem( 0 );
953 m_viewAction->setEditable( false );
954
955 TQStringList stl;
956 // xgettext:no-c-format
957 stl << i18n( "25%" );
958 // xgettext:no-c-format
959 stl << i18n( "50%" );
960 // xgettext:no-c-format
961 stl << i18n( "100%" );
962 // xgettext:no-c-format
963 stl << i18n( "200%" );
964 // xgettext:no-c-format
965 stl << i18n( "300%" );
966 // xgettext:no-c-format
967 stl << i18n( "400%" );
968 // xgettext:no-c-format
969 stl << i18n( "800%" );
970 stl << i18n( "Whole Page" )
971 << i18n( "Zoom Width" );
972
973 m_zoomAction->setItems( stl );
974 m_zoomAction->setEditable( true );
975 m_zoomAction->setCurrentItem( 7 );
976
977 KStdAction::zoomIn( this, TQ_SLOT( viewZoomIn() ), actionCollection(), "view_zoom_in" );
978 KStdAction::zoomOut( this, TQ_SLOT( viewZoomOut() ), actionCollection(), "view_zoom_out" );
979
980 m_showPageMargins = new TDEToggleAction( i18n("Show Page Margins"), "view_margins", 0, actionCollection(), "view_show_margins" );
981 connect( m_showPageMargins, TQ_SIGNAL(toggled(bool)), TQ_SLOT(togglePageMargins(bool)));
982 m_showPageMargins->setCheckedState(i18n("Hide Page Margins"));
983
984 // No need for the other actions in read-only (embedded) mode
985 if( !shell() )
986 return;
987
988 // edit ----->
989 KStdAction::cut( this,
990 TQ_SLOT( editCut() ), actionCollection(), "edit_cut" );
991 KStdAction::copy( this,
992 TQ_SLOT( editCopy() ), actionCollection(), "edit_copy" );
993 KStdAction::paste( this,
994 TQ_SLOT( editPaste() ), actionCollection(), "edit_paste" );
995 KStdAction::selectAll( this, TQ_SLOT( editSelectAll() ), actionCollection(), "edit_select_all" );
996 KStdAction::deselect( this, TQ_SLOT( editDeselectAll() ), actionCollection(), "edit_deselect_all" );
997
998 new TDEAction(
999 i18n( "&Import Graphic..." ), 0, 0, this,
1000 TQ_SLOT( fileImportGraphic() ), actionCollection(), "file_import" );
1001 m_deleteSelectionAction = new TDEAction(
1002 i18n( "D&elete" ), "edit-delete", TQKeySequence( "Del" ), this,
1003 TQ_SLOT( editDeleteSelection() ), actionCollection(), "edit_delete" );
1004 new TDEAction(
1005 i18n( "&History" ), 0, 0, this,
1006 TQ_SLOT( editPurgeHistory() ), actionCollection(), "edit_purge_history" );
1007 // edit <-----
1008
1009 // object ----->
1010 new TDEAction(
1011 i18n( "&Duplicate" ), "duplicate", TQKeySequence( "Ctrl+D" ), this,
1012 TQ_SLOT( selectionDuplicate() ), actionCollection(), "object_duplicate" );
1013 new TDEAction(
1014 i18n( "Bring to &Front" ), "bring_forward", TQKeySequence( "Ctrl+Shift+]" ), this,
1015 TQ_SLOT( selectionBringToFront() ), actionCollection(), "object_move_totop" );
1016 new TDEAction(
1017 i18n( "&Raise" ), "raise", TQKeySequence( "Ctrl+]" ), this,
1018 TQ_SLOT( selectionMoveUp() ), actionCollection(), "object_move_up" );
1019 new TDEAction(
1020 i18n( "&Lower" ), "lower", TQKeySequence( "Ctrl+[" ), this,
1021 TQ_SLOT( selectionMoveDown() ), actionCollection(), "object_move_down" );
1022 new TDEAction(
1023 i18n( "Send to &Back" ), "send_backward", TQKeySequence( "Ctrl+Shift+[" ), this,
1024 TQ_SLOT( selectionSendToBack() ), actionCollection(), "object_move_tobottom" );
1025
1026 new TDEAction(
1027 i18n( "Align Left" ), "aoleft", 0, this,
1028 TQ_SLOT( selectionAlignHorizontalLeft() ),
1029 actionCollection(), "object_align_horizontal_left" );
1030 new TDEAction(
1031 i18n( "Align Center (Horizontal)" ), "aocenterh", 0, this,
1032 TQ_SLOT( selectionAlignHorizontalCenter() ),
1033 actionCollection(), "object_align_horizontal_center" );
1034 new TDEAction(
1035 i18n( "Align Right" ), "aoright", 0, this,
1036 TQ_SLOT( selectionAlignHorizontalRight() ),
1037 actionCollection(), "object_align_horizontal_right" );
1038 new TDEAction(
1039 i18n( "Align Top" ), "aotop", 0, this,
1040 TQ_SLOT( selectionAlignVerticalTop() ),
1041 actionCollection(), "object_align_vertical_top" );
1042 new TDEAction(
1043 i18n( "Align Middle (Vertical)" ), "aocenterv", 0, this,
1044 TQ_SLOT( selectionAlignVerticalCenter() ),
1045 actionCollection(), "object_align_vertical_center" );
1046 new TDEAction(
1047 i18n( "Align Bottom" ), "aobottom", 0, this,
1048 TQ_SLOT( selectionAlignVerticalBottom() ),
1049 actionCollection(), "object_align_vertical_bottom" );
1050
1051 new TDEAction(
1052 i18n( "Distribute Center (Horizontal)" ), "", 0, this,
1053 TQ_SLOT( selectionDistributeHorizontalCenter() ),
1054 actionCollection(), "object_distribute_horizontal_center" );
1055 new TDEAction(
1056 i18n( "Distribute Gaps (Horizontal)" ), "", 0, this,
1057 TQ_SLOT( selectionDistributeHorizontalGap() ),
1058 actionCollection(), "object_distribute_horizontal_gap" );
1059 new TDEAction(
1060 i18n( "Distribute Left Borders" ), "", 0, this,
1061 TQ_SLOT( selectionDistributeHorizontalLeft() ),
1062 actionCollection(), "object_distribute_horizontal_left" );
1063 new TDEAction(
1064 i18n( "Distribute Right Borders" ), "", 0, this,
1065 TQ_SLOT( selectionDistributeHorizontalRight() ),
1066 actionCollection(), "object_distribute_horizontal_right" );
1067 new TDEAction(
1068 i18n( "Distribute Center (Vertical)" ), "", 0, this,
1069 TQ_SLOT( selectionDistributeVerticalCenter() ),
1070 actionCollection(), "object_distribute_vertical_center" );
1071 new TDEAction(
1072 i18n( "Distribute Gaps (Vertical)" ), "", 0, this,
1073 TQ_SLOT( selectionDistributeVerticalGap() ),
1074 actionCollection(), "object_distribute_vertical_gap" );
1075 new TDEAction(
1076 i18n( "Distribute Bottom Borders" ), "", 0, this,
1077 TQ_SLOT( selectionDistributeVerticalBottom() ),
1078 actionCollection(), "object_distribute_vertical_bottom" );
1079 new TDEAction(
1080 i18n( "Distribute Top Borders" ), "", 0, this,
1081 TQ_SLOT( selectionDistributeVerticalTop() ),
1082 actionCollection(), "object_distribute_vertical_top" );
1083
1084 m_showRulerAction = new TDEToggleAction( i18n( "Show Rulers" ), 0, this, TQ_SLOT( showRuler() ), actionCollection(), "view_show_ruler" );
1085 m_showRulerAction->setCheckedState(i18n("Hide Rulers"));
1086 m_showRulerAction->setToolTip( i18n( "Shows or hides rulers." ) );
1087 m_showRulerAction->setChecked( false );
1088 m_showGridAction = new TDEToggleAction( i18n( "Show Grid" ), "view_grid", this, TQ_SLOT( showGrid() ), actionCollection(), "view_show_grid" );
1089 m_showGridAction->setCheckedState(i18n("Hide Grid"));
1090 m_showGridAction->setToolTip( i18n( "Shows or hides grid." ) );
1091 //m_showGridAction->setChecked( true );
1092 m_snapGridAction = new TDEToggleAction( i18n( "Snap to Grid" ), 0, this, TQ_SLOT( snapToGrid() ), actionCollection(), "view_snap_to_grid" );
1093 m_snapGridAction->setToolTip( i18n( "Snaps to grid." ) );
1094 //m_snapGridAction->setChecked( true );
1095 m_groupObjects = new TDEAction(
1096 i18n( "&Group Objects" ), "group", TQKeySequence( "Ctrl+G" ), this,
1097 TQ_SLOT( groupSelection() ), actionCollection(), "selection_group" );
1098 m_ungroupObjects = new TDEAction(
1099 i18n( "&Ungroup Objects" ), "ungroup", TQKeySequence( "Ctrl+Shift+G" ), this,
1100 TQ_SLOT( ungroupSelection() ), actionCollection(), "selection_ungroup" );
1101 m_closePath = new TDEAction(
1102 i18n( "&Close Path" ), TQKeySequence( "Ctrl+U" ), this,
1103 TQ_SLOT( closePath() ), actionCollection(), "close_path" );
1104 // object <-----
1105
1106 // line style (dashes)
1107 m_lineStyleAction = new KoLineStyleAction( i18n( "Line Style" ), "linestyle", this, TQ_SLOT( setLineStyle( int ) ), actionCollection(), "setLineStyle" );
1108
1109 // line width
1110 m_setLineWidth = new KoUnitDoubleSpinComboBox( this, 0.0, 1000.0, 0.5, 1.0, KoUnit::U_PT, 1 );
1111 new KWidgetAction( m_setLineWidth, i18n( "Set Line Width" ), 0, this, TQ_SLOT( setLineWidth() ), actionCollection(), "setLineWidth" );
1112 m_setLineWidth->insertItem( 0.25 );
1113 m_setLineWidth->insertItem( 0.5 );
1114 m_setLineWidth->insertItem( 0.75 );
1115 m_setLineWidth->insertItem( 1.0 );
1116 m_setLineWidth->insertItem( 2.0 );
1117 m_setLineWidth->insertItem( 3.0 );
1118 m_setLineWidth->insertItem( 4.0 );
1119 m_setLineWidth->insertItem( 5.0 );
1120 m_setLineWidth->insertItem( 10.0 );
1121 m_setLineWidth->insertItem( 20.0 );
1122 connect( m_setLineWidth, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( setLineWidth() ) );
1123
1124 m_configureAction = new TDEAction(
1125 i18n( "Configure Karbon..." ), "configure", 0, this,
1126 TQ_SLOT( configure() ), actionCollection(), "configure" );
1127
1128 new TDEAction( i18n( "Page &Layout..." ), 0, this,
1129 TQ_SLOT( pageLayout() ), actionCollection(), "page_layout" );
1130 m_contextHelpAction = new KoContextHelpAction( actionCollection(), this );
1131}
1132
1133void
1134KarbonView::paintEverything( TQPainter& /*p*/, const TQRect& /*rect*/, bool /*transparent*/ )
1135{
1136 kdDebug(38000) << "view->paintEverything()" << endl;
1137}
1138
1139bool
1140KarbonView::mouseEvent( TQMouseEvent* event, const KoPoint &p )
1141{
1142 int mx = event->pos().x();
1143 int my = event->pos().y();
1144
1145 int px;
1146 int py;
1147 if( m_canvas->horizontalScrollBar()->isVisible() && ((m_canvas->horizontalScrollBar()->value() - m_canvas->pageOffsetX()) > 0))
1148 px = mx;
1149 else
1150 px = (mx + canvasWidget()->contentsX() - canvasWidget()->pageOffsetX());
1151
1152 if( m_canvas->verticalScrollBar()->isVisible() && ((m_canvas->verticalScrollBar()->value() - m_canvas->pageOffsetY()) > 0))
1153 py = my;
1154 else
1155 py = (my + canvasWidget()->contentsY() - canvasWidget()->pageOffsetY());
1156
1157 m_horizRuler->updatePointer(px, py);
1158 m_vertRuler->updatePointer(px, py);
1159
1160 KoPoint xy;
1161 xy.setX((mx + canvasWidget()->contentsX() - canvasWidget()->pageOffsetX())/zoom());
1162 xy.setY( tqRound(m_part->document().height()) - (my + canvasWidget()->contentsY() - canvasWidget()->pageOffsetY())/zoom());
1163
1164 xy.setX(KoUnit::toUserValue(xy.x(), part()->unit()));
1165 xy.setY(KoUnit::toUserValue(xy.y(), part()->unit()));
1166
1167 m_cursorCoords->setText( TQString( "%1, %2" ).arg(TDEGlobal::_locale->formatNumber(xy.x(), 2)).arg(TDEGlobal::_locale->formatNumber(xy.y(), 2)) );
1168
1169 if( toolController() )
1170 return toolController()->mouseEvent( event, p );
1171 else
1172 return false;
1173}
1174
1175bool
1176KarbonView::keyEvent( TQEvent* event )
1177{
1178 if( toolController() )
1179 return toolController()->keyEvent( event );
1180 else
1181 return false;
1182}
1183
1184void
1185KarbonView::reorganizeGUI()
1186{
1187 if( statusBar() )
1188 {
1189 if( part()->showStatusBar() )
1190 statusBar()->show();
1191 else
1192 statusBar()->hide();
1193 }
1194}
1195
1196void
1197KarbonView::setNumberOfRecentFiles( unsigned int number )
1198{
1199 if( shell() ) // 0L when embedded into konq !
1200 shell()->setMaxRecentItems( number );
1201}
1202
1203void
1204KarbonView::showRuler()
1205{
1206 if( shell() && m_showRulerAction->isChecked() )
1207 {
1208 m_horizRuler->show();
1209 m_vertRuler->show();
1210 m_canvas->setGeometry( rulerWidth, rulerHeight, width() - rulerWidth, height() - rulerHeight );
1211 updateRuler();
1212 }
1213 else
1214 {
1215 m_horizRuler->hide();
1216 m_vertRuler->hide();
1217 m_canvas->setGeometry( 0, 0, width(), height() );
1218 }
1219
1220 zoomChanged();
1221}
1222
1223bool
1224KarbonView::showPageMargins()
1225{
1226 return ((TDEToggleAction*)actionCollection()->action("view_show_margins"))->isChecked();
1227}
1228
1229void
1230KarbonView::togglePageMargins(bool b)
1231{
1232 ((TDEToggleAction*)actionCollection()->action("view_show_margins"))->setChecked(b);
1233 m_canvas->repaintAll();
1234}
1235
1236void
1237KarbonView::updateRuler()
1238{
1239 if(!m_canvas->horizontalScrollBar()->isVisible())
1240 {
1241 if( (1 + m_canvas->pageOffsetX() - m_canvas->contentsX()) >= 0 )
1242 {
1243 m_horizRuler->setGeometry( 1 + rulerWidth + m_canvas->pageOffsetX() - m_canvas->contentsX(), 0, tqRound( 1 + part()->document().width() * zoom() ), rulerHeight );
1244 m_horizRuler->updateVisibleArea(0,0);
1245 }
1246 else
1247 {
1248 m_horizRuler->setGeometry( rulerWidth, 0, tqRound( 1 + part()->document().width() * zoom() ) - m_canvas->contentsX() + m_canvas->pageOffsetX(), rulerHeight );
1249 m_horizRuler->updateVisibleArea((m_canvas->contentsX() - m_canvas->pageOffsetX()),0);
1250 }
1251 }
1252
1253 if(!m_canvas->verticalScrollBar()->isVisible())
1254 {
1255 if( (1 + m_canvas->pageOffsetY() - m_canvas->contentsY()) >= 0 )
1256 {
1257 m_vertRuler->setGeometry( 0, 1 + rulerHeight + m_canvas->pageOffsetY() - m_canvas->contentsY(), rulerWidth, 1 + tqRound( part()->document().height() * zoom() ));
1258 m_vertRuler->updateVisibleArea(0,0);
1259 }
1260 else
1261 {
1262 m_vertRuler->setGeometry( 0, 1 + rulerHeight, rulerWidth, 1 + tqRound( part()->document().height() * zoom() ) + m_canvas->contentsY() - m_canvas->pageOffsetY() );
1263 m_vertRuler->updateVisibleArea(0, (m_canvas->contentsY() - m_canvas->pageOffsetY()));
1264 }
1265 }
1266}
1267
1268void
1269KarbonView::showGrid()
1270{
1271 m_part->document().grid().isShow = m_showGridAction->isChecked();
1272}
1273
1274void
1275KarbonView::snapToGrid()
1276{
1277 m_part->document().grid().isSnap = m_snapGridAction->isChecked();
1278}
1279
1280void
1281KarbonView::showSelectionPopupMenu( const TQPoint &pos )
1282{
1283 TQPtrList<TDEAction> actionList;
1284 if( m_groupObjects->isEnabled() )
1285 actionList.append( m_groupObjects );
1286 else if( m_ungroupObjects->isEnabled() )
1287 actionList.append( m_ungroupObjects );
1288 if( m_closePath->isEnabled() )
1289 actionList.append( m_closePath );
1290 plugActionList( "selection_type_action", actionList );
1291 ((TQPopupMenu *)factory()->container( "selection_popup", this ) )->exec( pos );
1292 unplugActionList( "selection_type_action" );
1293}
1294
1295void
1296KarbonView::configure()
1297{
1298 VConfigureDlg dialog( this );
1299 dialog.exec();
1300}
1301
1302void
1303KarbonView::pageLayout()
1304{
1305 KoHeadFoot hf;
1306 KoPageLayout layout = part()->pageLayout();
1307 KoUnit::Unit unit = part()->unit();
1308 if( KoPageLayoutDia::pageLayout( layout, hf, FORMAT_AND_BORDERS | DISABLE_UNIT, unit ) )
1309 {
1310 part()->setPageLayout( layout, unit );
1311 m_horizRuler->setUnit( unit );
1312 m_vertRuler->setUnit( unit );
1313 m_canvas->resizeContents( int( ( part()->pageLayout().ptWidth + 300 ) * zoom() ),
1314 int( ( part()->pageLayout().ptHeight + 460 ) * zoom() ) );
1315 part()->repaintAllViews();
1316
1317 emit pageLayoutChanged();
1318 }
1319}
1320
1321void
1322KarbonView::canvasContentsMoving( int x, int y )
1323{
1324 if( m_canvas->horizontalScrollBar()->isVisible() )
1325 {
1326 if( shell() && m_showRulerAction->isChecked() )
1327 {
1328 if( (1 + m_canvas->pageOffsetX() - x) >= 0)
1329 {
1330 m_horizRuler->setGeometry( 1 + rulerWidth + m_canvas->pageOffsetX() - x, 0, tqRound( 1 + part()->document().width() * zoom() ), rulerHeight );
1331 m_horizRuler->updateVisibleArea(0,0);
1332 }
1333 else
1334 {
1335 m_horizRuler->setGeometry( rulerWidth, 0, tqRound( 1 + part()->document().width() * zoom() ) - x + m_canvas->pageOffsetX(), rulerHeight );
1336 m_horizRuler->updateVisibleArea((x - m_canvas->pageOffsetX()),0);
1337 }
1338 }
1339 }
1340
1341 if( m_canvas->verticalScrollBar()->isVisible() )
1342 {
1343 if( shell() && m_showRulerAction->isChecked() )
1344 {
1345 if( (1 + m_canvas->pageOffsetY() - y) >= 0)
1346 {
1347 m_vertRuler->setGeometry( 0, 1 + rulerHeight + m_canvas->pageOffsetY() - y , rulerWidth, 1 + tqRound( part()->document().height() * zoom() ));
1348 m_vertRuler->updateVisibleArea(0,0);
1349 }
1350 else
1351 {
1352 m_vertRuler->setGeometry( 0, 1 + rulerHeight, rulerWidth, 1 + tqRound( part()->document().height() * zoom() ) - y + m_canvas->pageOffsetY() );
1353 m_vertRuler->updateVisibleArea(0, (y - m_canvas->pageOffsetY()));
1354 }
1355 }
1356 }
1357}
1358
1359void
1360KarbonView::selectionChanged()
1361{
1362 VSelection *selection = part()->document().selection();
1363 int count = selection->objects().count();
1364 m_groupObjects->setEnabled( false );
1365 m_closePath->setEnabled( false );
1366 m_ungroupObjects->setEnabled( false );
1367
1368 if( count > 0 )
1369 {
1370 VObject *obj = selection->objects().getFirst();
1371 VFill fill = obj->fill() ? *obj->fill() : VFill();
1372 VStroke stroke = obj->stroke() ? *obj->stroke() : VStroke();
1373
1374 if ( shell() ) {
1375 //if ( this == shell()->rootView() || koDocument()->isEmbedded() ) {
1376 m_strokeFillPreview->update( stroke, fill );
1377 m_smallPreview->update( stroke, fill );
1378 //}
1379 }
1380 m_strokeDocker->setStroke( stroke );
1381
1382 if( count == 1 )
1383 {
1384 VGroup *group = dynamic_cast<VGroup *>( selection->objects().getFirst() );
1385 m_ungroupObjects->setEnabled( group );
1386 VPath *path = dynamic_cast<VPath *>( selection->objects().getFirst() );
1387 m_closePath->setEnabled( path && !path->isClosed() );
1388 }
1389 else
1390 m_groupObjects->setEnabled( true );
1391
1392 selection->setStroke( stroke );
1393 selection->setFill( fill );
1394 m_setLineWidth->setEnabled( true );
1395 m_setLineWidth->updateValue( stroke.lineWidth() );
1396 // dashes
1397 m_lineStyleAction->setEnabled( true );
1398 if( stroke.dashPattern().array().isEmpty() )
1399 m_lineStyleAction->setCurrentSelection( TQt::SolidLine );
1400 else if( stroke.dashPattern().array()[ 0 ] == 0. )
1401 m_lineStyleAction->setCurrentSelection( TQt::NoPen );
1402 else if( stroke.dashPattern().array()[ 0 ] == 2. )
1403 m_lineStyleAction->setCurrentSelection( TQt::DotLine );
1404 else if( stroke.dashPattern().array().count() == 2 )
1405 m_lineStyleAction->setCurrentSelection( TQt::DashLine );
1406 else if( stroke.dashPattern().array().count() == 4 )
1407 m_lineStyleAction->setCurrentSelection( TQt::DashDotLine );
1408 else if( stroke.dashPattern().array().count() == 6 )
1409 m_lineStyleAction->setCurrentSelection( TQt::DashDotDotLine );
1410
1411 m_deleteSelectionAction->setEnabled( true );
1412 }
1413 else
1414 {
1415 if ( shell() )
1416 {
1417 VFill fill = selection->fill() ? *selection->fill() : VFill();
1418 VStroke stroke = selection->stroke() ? *selection->stroke() : VStroke();
1419 //if ( this == shell()->rootView() || koDocument()->isEmbedded() && m_strokeFillPreview )
1420 m_strokeFillPreview->update( stroke, fill );
1421 }
1422 m_lineStyleAction->setEnabled( false );
1423 m_deleteSelectionAction->setEnabled( false );
1424 }
1425 emit selectionChange();
1426}
1427void
1428KarbonView::setCursor( const TQCursor &c )
1429{
1430 m_canvas->setCursor( c );
1431}
1432
1433void
1434KarbonView::repaintAll( const KoRect &r )
1435{
1436 m_canvas->repaintAll( r );
1437}
1438
1439void
1440KarbonView::repaintAll( bool repaint )
1441{
1442 m_canvas->repaintAll( repaint );
1443}
1444void
1445KarbonView::setPos( const KoPoint& p )
1446{
1447 m_canvas->setPos( p );
1448}
1449
1450void
1451KarbonView::setViewportRect( const KoRect &rect )
1452{
1453 m_canvas->setViewportRect( rect );
1454}
1455
1456void
1457KarbonView::setUnit( KoUnit::Unit /*_unit*/ )
1458{
1459}
1460
1461void KarbonView::createDocumentTabDock()
1462{
1463 m_DocumentTab = new VDocumentTab(this, this);
1464 m_DocumentTab->setCaption(i18n("Document"));
1465 paletteManager()->addWidget(m_DocumentTab, "DocumentTabDock", "DocumentPanel");
1466 connect( m_part, TQ_SIGNAL( unitChanged( KoUnit::Unit ) ), m_DocumentTab, TQ_SLOT( updateDocumentInfo() ) );
1467}
1468
1469void KarbonView::createLayersTabDock()
1470{
1471 m_LayersTab = new VLayersTab(this, this);
1472 m_LayersTab->setCaption(i18n("Layers"));
1473 paletteManager()->addWidget(m_LayersTab, "LayersTabDock", "DocumentPanel");
1474}
1475
1476void KarbonView::createHistoryTabDock()
1477{
1478 m_HistoryTab = new VHistoryTab(part(), this);
1479 m_HistoryTab->setCaption(i18n("History"));
1480 paletteManager()->addWidget(m_HistoryTab, "HistoryTabDock", "DocumentPanel");
1481}
1482
1483void KarbonView::createStrokeDock()
1484{
1485 m_strokeDocker = new VStrokeDocker(part(), this);
1486 m_strokeDocker->setCaption(i18n("Stroke Properties"));
1487 paletteManager()->addWidget(m_strokeDocker, "StrokeTabDock", "StrokePanel");
1488
1489 connect( part(), TQ_SIGNAL( unitChanged( KoUnit::Unit ) ), m_strokeDocker, TQ_SLOT( setUnit( KoUnit::Unit ) ) );
1490}
1491
1492void KarbonView::createColorDock()
1493{
1494 m_ColorManager = new VColorDocker(part(),this);
1495 //m_ColorManager->setCaption(i18n("Stroke Properties"));
1496 paletteManager()->addWidget(m_ColorManager, "ColorTabDock", "ColorPanel");
1497
1498 connect( this, TQ_SIGNAL( selectionChange() ), m_ColorManager, TQ_SLOT( update() ) );
1499}
1500
1501void KarbonView::createTransformDock()
1502{
1503 m_TransformDocker = new VTransformDocker(part(), this);
1504 m_TransformDocker->setCaption(i18n("Transform"));
1505 paletteManager()->addWidget(m_TransformDocker, "TransformTabDock", "TransformPanel");
1506
1507 connect( this, TQ_SIGNAL( selectionChange() ), m_TransformDocker, TQ_SLOT( update() ) );
1508 connect( part(), TQ_SIGNAL( unitChanged( KoUnit::Unit ) ), m_TransformDocker, TQ_SLOT( setUnit( KoUnit::Unit ) ) );
1509}
1510
1511void KarbonView::createResourceDock()
1512{
1513 m_styleDocker = new VStyleDocker( part(), this );
1514 m_styleDocker->setCaption(i18n("Resources"));
1515 paletteManager()->addWidget(m_styleDocker, "ResourceTabDock", "ResourcePanel");
1516}
1517
1518VToolController *
1519KarbonView::toolController()
1520{
1521 return m_toolController;
1522}
1523
1524void KarbonView::commandExecuted( VCommand *command )
1525{
1526 if( command && command->changesSelection() )
1527 selectionChanged();
1528}
1529
1530void KarbonView::strokeFillSelectionChanged( KDualColorButton::DualColor s )
1531{
1532 if( s == KDualColorButton::Foreground )
1533 m_strokeFillPreview->setStrokeSelected();
1534 else
1535 m_strokeFillPreview->setFillSelected();
1536 selectionChanged();
1537}
1538
1539void KarbonView::colorChanged( const TQColor &c )
1540{
1541 selectionChanged();
1542}
1543
1544#include "karbon_view.moc"
1545
Keeps track of visual per document properties.
Definition karbon_part.h:46
void set(float v1)
Sets the first color component.
Definition vcolor.h:91
The base class for all karbon commands.
Definition vcommand.h:42
virtual bool changesSelection() const
Returns if the command changes the actual document selection.
Definition vcommand.h:84
Manages the fill of shapes.
Definition vfill.h:45
virtual void setStroke(const VStroke &stroke)
Sets the stroke to a given new stroke.
Definition vobject.cpp:84
virtual VFill * fill() const
Gets the object's actual fill.
Definition vobject.h:177
virtual VStroke * stroke() const
Gets the object's actual stroke.
Definition vobject.h:170
virtual void setFill(const VFill &fill)
Sets the fill to a given new fill.
Definition vobject.cpp:93
const VObjectList & objects() const
Read only access to the selected objects.
Definition vselection.h:136
Manages stroke properties.
Definition vstroke.h:49
The base class for all karbon tools.
Definition vtool.h:52