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