KoView.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
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 <KoView.h>
21#include <KoDocument.h>
22#include <KoMainWindow.h>
23#include <KoFrame.h>
24#include <KoViewIface.h>
25#include <KoDocumentChild.h>
26
27#include <tdelocale.h>
28#include <tdeglobal.h>
29#include <kdebug.h>
30#include <tdeparts/partmanager.h>
31#include <tdeparts/event.h>
32#include <kcursor.h>
33#include <assert.h>
34#include <kstatusbar.h>
35#include <tdeapplication.h>
36#include <tqtimer.h>
37
38class KoViewPrivate
39{
40public:
41 KoViewPrivate()
42 {
43 m_inOperation = false;
44 m_zoom = 1.0;
45 m_children.setAutoDelete( true );
46 m_manager = 0L;
47 m_tempActiveWidget = 0L;
48 m_dcopObject = 0;
49 m_registered=false;
50 m_documentDeleted=false;
51 }
52 ~KoViewPrivate()
53 {
54 }
55
56 TQGuardedPtr<KoDocument> m_doc; // our KoDocument
57 TQGuardedPtr<KParts::PartManager> m_manager;
58 double m_zoom;
59 TQPtrList<KoViewChild> m_children;
60 TQWidget *m_tempActiveWidget;
61 KoViewIface *m_dcopObject;
62 bool m_registered; // are we registered at the part manager?
63 bool m_documentDeleted; // true when m_doc gets deleted [can't use m_doc==0
64 // since this only happens in ~TQObject, and views
65 // get deleted by ~KoDocument].
66 TQTimer *m_scrollTimer;
67
68 // Hmm sorry for polluting the private class with such a big inner class.
69 // At the beginning it was a little struct :)
70 class StatusBarItem {
71 public:
72 StatusBarItem() // for TQValueList
73 : m_widget(0), m_visible(false)
74 {}
75 StatusBarItem( TQWidget * widget, int stretch, bool permanent )
76 : m_widget(widget), m_stretch(stretch), m_permanent(permanent), m_visible(false)
77 {}
78
79 TQWidget * widget() const { return m_widget; }
80
81 void ensureItemShown( KStatusBar * sb )
82 {
83 if ( !m_visible )
84 {
85 sb->addWidget( m_widget, m_stretch, m_permanent );
86 m_visible = true;
87 m_widget->show();
88 }
89 }
90 void ensureItemHidden( KStatusBar * sb )
91 {
92 if ( m_visible )
93 {
94 sb->removeWidget( m_widget );
95 m_visible = false;
96 m_widget->hide();
97 }
98 }
99 private:
100 TQWidget * m_widget;
101 int m_stretch;
102 bool m_permanent;
103 bool m_visible; // true when the item has been added to the statusbar
104 };
105 TQValueList<StatusBarItem> m_statusBarItems; // Our statusbar items
106 bool m_inOperation; //in the middle of an operation (no screen refreshing)?
107};
108
109KoView::KoView( KoDocument *document, TQWidget *parent, const char *name )
110 : TQWidget( parent, name )
111{
112 Q_ASSERT( document );
113
114 //kdDebug(30003) << "KoView::KoView " << this << endl;
115 d = new KoViewPrivate;
116 d->m_doc = document;
118
119 setFocusPolicy( TQWidget::StrongFocus );
120
121 setMouseTracking( true );
122
123 connect( d->m_doc, TQ_SIGNAL( childChanged( KoDocumentChild * ) ),
124 this, TQ_SLOT( slotChildChanged( KoDocumentChild * ) ) );
125
126 connect( d->m_doc, TQ_SIGNAL( sigBeginOperation() ),
127 this, TQ_SLOT( beginOperation() ) );
128
129 connect( d->m_doc, TQ_SIGNAL( sigEndOperation() ),
130 this, TQ_SLOT( endOperation() ) );
131
132
133 actionCollection()->setWidget( this );
134 setupGlobalActions();
136 /**** not needed anymore, according to David (Werner)
137 TQValueList<TDEAction*> docActions = document->actionCollection()->actions();
138 TQValueList<TDEAction*>::ConstIterator it = docActions.begin();
139 TQValueList<TDEAction*>::ConstIterator end = docActions.end();
140 for (; it != end; ++it )
141 coll->insert( *it );
142 */
143
144 KStatusBar * sb = statusBar();
145 if ( sb ) // No statusbar in e.g. konqueror
146 {
147 coll->setHighlightingEnabled( true );
148 connect( coll, TQ_SIGNAL( actionStatusText( const TQString & ) ),
149 this, TQ_SLOT( slotActionStatusText( const TQString & ) ) );
150 connect( coll, TQ_SIGNAL( clearStatusText() ),
151 this, TQ_SLOT( slotClearStatusText() ) );
152
153 connect( d->m_doc, TQ_SIGNAL( sigStatusBarMessage( const TQString& ) ),
154 this, TQ_SLOT( slotActionStatusText( const TQString& ) ) );
155 connect( d->m_doc, TQ_SIGNAL( sigClearStatusBarMessage() ),
156 this, TQ_SLOT( slotClearStatusText() ) );
157 }
158 d->m_doc->setCurrent();
159
160 d->m_scrollTimer = new TQTimer( this );
161 connect (d->m_scrollTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( slotAutoScroll() ) );
162}
163
165{
166 kdDebug(30003) << "KoView::~KoView " << this << endl;
167 delete d->m_scrollTimer;
168 delete d->m_dcopObject;
169 if (!d->m_documentDeleted)
170 {
171 if ( koDocument() && !koDocument()->isSingleViewMode() )
172 {
173 if ( d->m_manager && d->m_registered ) // if we aren't registered we mustn't unregister :)
174 d->m_manager->removePart( koDocument() );
175 d->m_doc->removeView(this);
176 d->m_doc->setCurrent( false );
177 }
178 }
179 delete d;
180}
181
183{
184 return d->m_doc;
185}
186
188{
189 d->m_documentDeleted = true;
190}
191
193{
194 return d->m_documentDeleted;
195}
196
198{
199 return child( doc ) != 0L;
200}
201
202void KoView::setPartManager( KParts::PartManager *manager )
203{
204 d->m_manager = manager;
205 if ( !koDocument()->isSingleViewMode() &&
206 manager->parts()->containsRef( koDocument() ) == 0 ) // is there another view registered?
207 {
208 d->m_registered = true; // no, so we have to register now and ungregister again in the DTOR
209 manager->addPart( koDocument(), false );
210 }
211 else
212 d->m_registered = false; // There is already another view registered for that part...
213}
214
215KParts::PartManager *KoView::partManager() const
216{
217 return d->m_manager;
218}
219
220TDEAction *KoView::action( const TQDomElement &element ) const
221{
222 static const TQString &attrName = TDEGlobal::staticQString( "name" );
223 TQString name = element.attribute( attrName );
224
225 TDEAction *act = KXMLGUIClient::action( name.utf8() );
226
227 if ( !act )
228 act = d->m_doc->KXMLGUIClient::action( name.utf8() );
229
230 return act;
231}
232
233KoDocument *KoView::hitTest( const TQPoint &viewPos )
234{
235 KoViewChild *viewChild;
236
237 TQPoint pos = reverseViewTransformations( viewPos );
238
239 KoDocumentChild *docChild = selectedChild();
240 if ( docChild )
241 {
242 if ( ( viewChild = child( docChild->document() ) ) )
243 {
244 if ( viewChild->frameRegion().contains( pos ) )
245 return 0;
246 }
247 else
248 if ( docChild->frameRegion().contains( pos ) )
249 return 0;
250 }
251
252 docChild = activeChild();
253 if ( docChild )
254 {
255 if ( ( viewChild = child( docChild->document() ) ) )
256 {
257 if ( viewChild->frameRegion().contains( pos ) )
258 return 0;
259 }
260 else
261 if ( docChild->frameRegion().contains( pos ) )
262 return 0;
263 }
264
265 return koDocument()->hitTest( pos );
266}
267
269{
270 return 0;
271}
272
274{
275 return 0;
276}
277
279{
280 return 0;
281}
282
284{
285 return 0;
286}
287
288void KoView::setZoom( double zoom )
289{
290 d->m_zoom = zoom;
291 update();
292}
293
294double KoView::zoom() const
295{
296 return d->m_zoom;
297}
298
299TQWidget *KoView::canvas() const
300{
301 //dfaure: since the view plays two roles in this method (the const means "you can modify the canvas
302 // but not the view", it's just coincidence that the view is the canvas by default ;)
303 return const_cast<KoView *>(this);
304}
305
307{
308 return 0;
309}
310
312{
313 return 0;
314}
315
319
320void KoView::customEvent( TQCustomEvent *ev )
321{
322 if ( KParts::PartActivateEvent::test( ev ) )
324 else if ( KParts::PartSelectEvent::test( ev ) )
326 else if( KParts::GUIActivateEvent::test( ev ) )
328}
329
331{
332 if ( event->part() != (KParts::Part *)koDocument() )
333 {
334 assert( event->part()->inherits( "KoDocument" ) );
335
336 KoDocumentChild *child = koDocument()->child( (KoDocument *)event->part() );
337 if ( child && event->activated() )
338 {
339 if ( child->isRectangle() && !child->isTransparent() )
340 {
341 KoViewChild *viewChild = new KoViewChild( child, this );
342 d->m_children.append( viewChild );
343
344 TQApplication::setOverrideCursor(waitCursor);
345 // This is the long operation (due to toolbar layout stuff)
346 d->m_manager->setActivePart( child->document(), viewChild->frame()->view() );
347 TQApplication::restoreOverrideCursor();
348
349 // Now we can move the frame to the right place
350 viewChild->setInitialFrameGeometry();
351 }
352 else
353 {
354 emit regionInvalidated( child->frameRegion( matrix() ), true );
355 }
356 emit childActivated( child );
357 }
358 else if ( child )
359 {
360 emit regionInvalidated( child->frameRegion( matrix() ), true );
361 emit childDeactivated( child );
362 }
363 else
364 emit invalidated();
365 }
366 else
367 emit activated( event->activated() );
368}
369
371{
372 if ( event->part() != (KParts::Part *)koDocument() )
373 {
374 assert( event->part()->inherits( "KoDocument" ) );
375
376 KoDocumentChild *child = koDocument()->child( (KoDocument *)event->part() );
377
378 if ( child && event->selected() )
379 {
380 TQRegion r = child->frameRegion( matrix() );
381 r.translate( - canvasXOffset(), - canvasYOffset() );
382 emit regionInvalidated( r, true );
383 emit childSelected( child );
384 }
385 else if ( child )
386 {
387 TQRegion r = child->frameRegion( matrix() );
388 r.translate( - canvasXOffset(), - canvasYOffset() );
389 emit regionInvalidated( r, true );
390 emit childUnselected( child );
391 }
392 else
393 emit invalidated();
394 }
395 else
396 emit selected( event->selected() );
397}
398
400{
401 showAllStatusBarItems( ev->activated() );
402}
403
405{
406 KStatusBar * sb = statusBar();
407 if ( !sb )
408 return;
409 TQValueListIterator<KoViewPrivate::StatusBarItem> it = d->m_statusBarItems.begin();
410 for ( ; it != d->m_statusBarItems.end() ; ++it )
411 if ( show )
412 (*it).ensureItemShown( sb );
413 else
414 (*it).ensureItemHidden( sb );
415}
416
417void KoView::addStatusBarItem( TQWidget * widget, int stretch, bool permanent )
418{
419 KoViewPrivate::StatusBarItem item( widget, stretch, permanent );
420 d->m_statusBarItems.append(item);
421 TQValueListIterator<KoViewPrivate::StatusBarItem> it = d->m_statusBarItems.fromLast();
422 KStatusBar * sb = statusBar();
423 Q_ASSERT(sb);
424 if (sb)
425 (*it).ensureItemShown( sb );
426}
427
428void KoView::removeStatusBarItem( TQWidget * widget )
429{
430 KStatusBar * sb = statusBar();
431 TQValueListIterator<KoViewPrivate::StatusBarItem> it = d->m_statusBarItems.begin();
432 for ( ; it != d->m_statusBarItems.end() ; ++it )
433 if ( (*it).widget() == widget )
434 {
435 if ( sb )
436 (*it).ensureItemHidden( sb );
437 d->m_statusBarItems.remove( it );
438 break;
439 }
440 if ( it == d->m_statusBarItems.end() )
441 kdWarning() << "KoView::removeStatusBarItem. Widget not found : " << widget << endl;
442}
443
445{
446 if ( !d->m_manager )
447 return 0L;
448
449 KParts::Part *selectedPart = d->m_manager->selectedPart();
450
451 if ( !selectedPart || !selectedPart->inherits( "KoDocument" ) )
452 return 0L;
453
454 return koDocument()->child( (KoDocument *)selectedPart );
455}
456
458{
459 if ( !d->m_manager )
460 return 0L;
461
462 KParts::Part *activePart = d->m_manager->activePart();
463
464 if ( !activePart || !activePart->inherits( "KoDocument" ) )
465 return 0L;
466
467 return koDocument()->child( (KoDocument *)activePart );
468}
469
471{
472 d->m_scrollTimer->start( 50 );
473}
474
476{
477 d->m_scrollTimer->stop();
478}
479
480void KoView::paintEverything( TQPainter &painter, const TQRect &rect, bool transparent )
481{
482 koDocument()->paintEverything( painter, rect, transparent, this );
483}
484
486{
487 TQPtrListIterator<KoViewChild> it( d->m_children );
488 for (; it.current(); ++it )
489 if ( it.current()->frame()->view() == view )
490 return it.current();
491
492 return 0L;
493}
494
496{
497 TQPtrListIterator<KoViewChild> it( d->m_children );
498 for (; it.current(); ++it )
499 if ( it.current()->documentChild()->document() == doc )
500 return it.current();
501
502 return 0L;
503}
504
505TQWMatrix KoView::matrix() const
506{
507 TQWMatrix m;
508 m.scale( zoom(), zoom() );
509 //m.translate( canvasXOffset() , canvasYOffset() );
510 return m;
511}
512
513void KoView::slotChildActivated( bool a )
514{
515 // Only interested in deactivate events
516 if ( a )
517 return;
518
519 KoViewChild* ch = child( (KoView*)sender() );
520 if ( !ch )
521 return;
522
523 KoView* view = ch->frame()->view();
524
525 TQWidget *activeWidget = view->d->m_tempActiveWidget;
526
527 if ( d->m_manager->activeWidget() )
528 activeWidget = d->m_manager->activeWidget();
529
530 if ( !activeWidget || !activeWidget->inherits( "KoView" ) )
531 return;
532
533 // Is the new active view a child of this one ?
534 // In this case we may not delete!
535 // TQObject *n = d->m_manager->activeWidget();
536 TQObject *n = activeWidget;
537 while( n )
538 if ( n == (TQObject *)view )
539 return;
540 else
541 n = n->parent();
542
543
544 d->m_tempActiveWidget = activeWidget;
545 TQApplication::setOverrideCursor(waitCursor);
546 d->m_manager->setActivePart( 0L );
547
548 TQGuardedPtr<KoDocumentChild> docChild = ch->documentChild();
549 TQGuardedPtr<KoFrame> chFrame = ch->frame();
550 if ( docChild && chFrame && chFrame->view() )
551 {
552 docChild->setContentsPos( chFrame->view()->canvasXOffset(),
553 chFrame->view()->canvasYOffset() );
554 docChild->document()->setViewBuildDocument( chFrame->view(), chFrame->view()->xmlguiBuildDocument() );
555 }
556
557 d->m_children.remove( ch );
558
559 d->m_manager->addPart( docChild->document(), false ); // the destruction of the view removed the part from the partmanager. re-add it :)
560
561 TQApplication::restoreOverrideCursor();
562
563 // #### HACK
564 // We want to delete as many views as possible and this
565 // trick is used to go upwards in the view-tree.
566 emit activated( false );
567}
568
569void KoView::slotChildChanged( KoDocumentChild *child )
570{
571 TQRegion region( child->oldPointArray( matrix() ) );
572 emit regionInvalidated( child->frameRegion( matrix(), true ).unite( region ), true );
573}
574
575int KoView::autoScrollAcceleration( int offset ) const
576{
577 if(offset < 40)
578 return offset;
579 else
580 return offset*offset/40;
581}
582
583void KoView::slotAutoScroll( )
584{
585 TQPoint scrollDistance;
586 bool actuallyDoScroll = false;
587 TQPoint pos( mapFromGlobal( TQCursor::pos() ) );
588
589 //Provide progressive scrolling depending on the mouse position
590 if ( pos.y() < topBorder() )
591 {
592 scrollDistance.setY ((int) - autoScrollAcceleration( - pos.y() + topBorder() ));
593 actuallyDoScroll = true;
594 }
595 else if ( pos.y() > height() - bottomBorder() )
596 {
597 scrollDistance.setY ((int) autoScrollAcceleration(pos.y() - height() + bottomBorder() ));
598 actuallyDoScroll = true;
599 }
600
601 if ( pos.x() < leftBorder() )
602 {
603 scrollDistance.setX ((int) - autoScrollAcceleration( - pos.x() + leftBorder() ));
604 actuallyDoScroll = true;
605 }
606 else if ( pos.x() > width() - rightBorder() )
607 {
608 scrollDistance.setX ((int) autoScrollAcceleration( pos.x() - width() + rightBorder() ));
609 actuallyDoScroll = true;
610 }
611
612 if ( actuallyDoScroll )
613 {
614 int state=0;
615#if KDE_IS_VERSION(3,4,0)
616 state = kapp->keyboardMouseState();
617#endif
618
619 pos = canvas()->mapFrom(this, pos);
620 TQMouseEvent * event = new TQMouseEvent(TQEvent::MouseMove, pos, 0, state);
621
622 TQApplication::postEvent( canvas(), event );
623 emit autoScroll( scrollDistance );
624 }
625}
626
627
628void KoView::setupGlobalActions() {
629 actionNewView = new TDEAction( i18n( "&New View" ), "window-new", 0,
630 this, TQ_SLOT( newView() ),
631 actionCollection(), "view_newview" );
632}
633
634void KoView::setupPrinter( KPrinter & )
635{
636 kdDebug() << "KoView::setupPrinter not implemented by the application!" << endl;
637}
638
639void KoView::print( KPrinter & )
640{
641 kdDebug() << "KoView::print not implemented by the application!" << endl;
642}
643
645 assert( ( d!=0L && d->m_doc ) );
646
647 KoDocument *thisDocument = d->m_doc;
648 KoMainWindow *shell = new KoMainWindow( thisDocument->instance() );
649 shell->setRootDocument(thisDocument);
650 shell->show();
651}
652
654{
655 return d->m_inOperation;
656}
657
659{
660 d->m_inOperation = true;
661 canvas()->setUpdatesEnabled(false);
662}
663
665{
666 canvas()->setUpdatesEnabled(true);
667 d->m_inOperation = false;
668
669// canvas()->update();
670}
671
673{
674 return dynamic_cast<KoMainWindow *>( topLevelWidget() );
675}
676
678{
679 return dynamic_cast<TDEMainWindow *>( topLevelWidget() );
680}
681
683{
684 KoMainWindow *mw = shell();
685 return mw ? mw->statusBar() : 0L;
686}
687
688void KoView::slotActionStatusText( const TQString &text )
689{
690 KStatusBar *sb = statusBar();
691 if ( sb )
692 sb->message( text );
693}
694
696{
697 KStatusBar *sb = statusBar();
698 if ( sb )
699 sb->clear();
700}
701
703{
704 if ( !d->m_dcopObject )
705 d->m_dcopObject = new KoViewIface( this );
706 return d->m_dcopObject;
707}
708
709class KoViewChild::KoViewChildPrivate
710{
711public:
712 KoViewChildPrivate()
713 {
714 }
715 ~KoViewChildPrivate()
716 {
717 }
718};
719
720KoViewChild::KoViewChild( KoDocumentChild *child, KoView *_parentView )
721{
722 d = new KoViewChildPrivate;
723 m_parentView = _parentView;
724 m_child = child;
725
726 m_frame = new KoFrame( parentView()->canvas() );
727 KoView *view = child->document()->createView( m_frame );
728 view->setXMLGUIBuildDocument( child->document()->viewBuildDocument( view ) );
729
730 view->setPartManager( parentView()->partManager() );
731
732 // hack? (Werner)
733 view->setZoom( parentView()->zoom() * TQMAX(child->xScaling(), child->yScaling()) );
734
735 m_frame->setView( view );
736 m_frame->show();
737 m_frame->raise();
738
739 parentView()->canvasAddChild( this );
740
741
742 /*
743 KoViewChild has basically three geometries to keep in sync.
744 - The KoDocumentChild geometry (i.e. the embedded object's geometry, unzoomed)
745 - Its own geometry (used for hit-test etc.)
746 - The KoFrame geometry (the graphical widget for moving the object when active)
747
748 So we need to subtract the scrollview's offset for the frame geometry, since it's a widget.
749
750 The rules are
751 (R1) frameGeometry = viewGeometry(childGeometry) "+" m_frame->{left|right|top|bottom}Border() - scrollview offset,
752 (R2) frameGeometry = myGeometry "+" active_frame_border - scrollview offset.
753
754 So: (R3, unused) myGeometry = viewGeometry(childGeometry) "+" m_frame->{left|right|top|bottom}Border() "-" active_frame_border
755
756 Notes: active_frame_border is m_frame->border() (0 when inactive, 5 when active).
757 {left|right|top|bottom}Border are the borders used in kspread (0 when inactive, big when active).
758 "+" border means we add a border, so it's a subtraction on x, y and an addition on width, height.
759
760 viewGeometry() applies the zoom as well as any other translation the app might want to do
761 */
762
763 // Setting the frameGeometry is done in setInitialFrameGeometry, which is
764 // also called right after activation.
765
766 connect( view, TQ_SIGNAL( activated( bool ) ),
767 parentView(), TQ_SLOT( slotChildActivated( bool ) ) );
768}
769
770KoViewChild::~KoViewChild()
771{
772 if ( m_frame )
773 {
774 slotFrameGeometryChanged();
775 delete static_cast<KoFrame *>( m_frame );
776 }
777 delete d;
778}
779
780void KoViewChild::slotFrameGeometryChanged()
781{
782 // Set our geometry from the frame geometry (R2 reversed)
783 TQRect geom = m_frame->geometry();
784 int b = m_frame->border();
785 TQRect borderRect( geom.x() + b + parentView()->canvasXOffset(),
786 geom.y() + b + parentView()->canvasYOffset(),
787 geom.width() - b * 2,
788 geom.height() - b * 2 );
789 setGeometry( borderRect );
790
791 if(m_child)
792 {
793 // Set the child geometry from the frame geometry (R1 reversed)
794 TQRect borderLessRect( geom.x() + m_frame->leftBorder() + parentView()->canvasXOffset(),
795 geom.y() + m_frame->topBorder() + parentView()->canvasYOffset(),
796 geom.width() - m_frame->leftBorder() - m_frame->rightBorder(),
797 geom.height() - m_frame->topBorder() - m_frame->bottomBorder() );
798
799 // We don't want to trigger slotDocGeometryChanged again
800 lock();
801 TQRect childGeom = parentView()->reverseViewTransformations( borderLessRect );
802 kdDebug() << "KoChild::slotFrameGeometryChanged child geometry "
803 << ( geometry() == childGeom ? "already " : "set to " )
804 << childGeom << endl;
805 m_child->setGeometry( childGeom );
806 unlock();
807 }
808}
809
810void KoViewChild::slotDocGeometryChanged()
811{
812 if ( locked() )
813 return;
814 // Set frame geometry from child geometry (R1)
815 // The frame's resizeEvent will call slotFrameGeometryChanged.
816 TQRect geom = parentView()->applyViewTransformations( m_child->geometry() );
817 TQRect borderRect( geom.x() - m_frame->leftBorder() - parentView()->canvasXOffset(),
818 geom.y() - m_frame->topBorder() - parentView()->canvasYOffset(),
819 geom.width() + m_frame->leftBorder() + m_frame->rightBorder(),
820 geom.height() + m_frame->topBorder() + m_frame->bottomBorder() );
821 kdDebug() << "KoViewChild::slotDocGeometryChanged frame geometry "
822 << ( m_frame->geometry() == borderRect ? "already " : "set to " )
823 << borderRect << endl;
824
825 m_frame->setGeometry( borderRect );
826}
827
828TQPoint KoView::applyViewTransformations( const TQPoint& p ) const
829{
830 return TQPoint( tqRound( p.x() * zoom() ), tqRound( p.y() * zoom() ) );
831}
832
833TQPoint KoView::reverseViewTransformations( const TQPoint& v ) const
834{
835 return TQPoint( tqRound( v.x() / zoom() ), tqRound( v.y() / zoom() ) );
836}
837
838TQRect KoView::applyViewTransformations( const TQRect& r ) const
839{
840 return TQRect( applyViewTransformations( r.topLeft() ),
841 applyViewTransformations( r.bottomRight() ) );
842}
843
844TQRect KoView::reverseViewTransformations( const TQRect& r ) const
845{
846 return TQRect( reverseViewTransformations( r.topLeft() ),
847 reverseViewTransformations( r.bottomRight() ) );
848}
849
850void KoViewChild::setInitialFrameGeometry()
851{
852 kdDebug() << k_funcinfo << endl;
853
854 // Connect only now, so that the GUI building doesn't move us around.
855 connect( m_frame, TQ_SIGNAL( geometryChanged() ),
856 this, TQ_SLOT( slotFrameGeometryChanged() ) );
857 connect( m_child, TQ_SIGNAL( changed( KoChild * ) ),
858 this, TQ_SLOT( slotDocGeometryChanged() ) );
859
860 // Set frameGeometry from childGeometry
861 slotDocGeometryChanged();
862 // Set myGeometry from frameGeometry
863 slotFrameGeometryChanged();
864
865}
866
867#include "KoView.moc"
868
void setPartObject(TQObject *object)
const TQPtrList< Part > * parts() const
virtual void addPart(Part *part, bool setActive=true)
virtual TDEInstance * instance() const
void setXMLGUIBuildDocument(const TQDomDocument &doc)
TDEAction * action(const char *name) const
virtual TDEActionCollection * actionCollection() const
KoChild is an abstract base class that represents the geometry associated with an embedded document.
Definition KoChild.h:42
virtual bool isTransparent() const
It might be interesting for view updates and repainting in general whether a child is transparent or ...
Definition KoChild.cpp:334
void setGeometry(const TQRect &rect, bool noEmit=false)
Sets a new geometry for this child document.
Definition KoChild.cpp:72
void changed(KoChild *thisChild)
Emitted every time this child changes, but only if this child is not locked.
bool isRectangle() const
Definition KoChild.cpp:117
void lock()
Locks this child and stores the current transformation.
Definition KoChild.cpp:296
void unlock()
Unlocks this child and emits a changed signal.
Definition KoChild.cpp:305
TQRect geometry() const
Definition KoChild.cpp:92
virtual double xScaling() const
Definition KoChild.cpp:149
virtual double yScaling() const
Definition KoChild.cpp:154
virtual TQRegion frameRegion(const TQWMatrix &matrix=TQWMatrix(), bool solid=false) const
Definition KoChild.cpp:244
virtual TQPointArray oldPointArray(const TQWMatrix &matrix)
Definition KoChild.cpp:319
bool locked() const
If the child is locked, geometry changes (including scaling, rotation, ...) are not backed up.
Definition KoChild.cpp:314
Holds an embedded object.
KoDocument * document() const
The KOffice document class.
Definition KoDocument.h:61
virtual KParts::Part * hitTest(TQWidget *widget, const TQPoint &globalPos)
Reimplemented from KParts::Part.
KoDocumentChild * child(KoDocument *doc)
KoView * createView(TQWidget *parent=0, const char *name=0)
Create a new view for the document.
virtual void paintEverything(TQPainter &painter, const TQRect &rect, bool transparent=false, KoView *view=0L, double zoomX=1.0, double zoomY=1.0)
Paints the whole document into the given painter object.
Main window for a KOffice application.
virtual void setRootDocument(KoDocument *doc)
Called when a document is assigned to this mainwindow.
This class represents an active embedded document.
Definition KoView.h:474
This class is used to display a KoDocument.
Definition KoView.h:58
virtual void guiActivateEvent(KParts::GUIActivateEvent *)
Handles the event KParts::GUIActivateEvent.
Definition KoView.cpp:399
void removeStatusBarItem(TQWidget *widget)
Remove a widget from the statusbar for this view.
Definition KoView.cpp:428
TDEMainWindow * mainWindow() const
Definition KoView.cpp:677
virtual int leftBorder() const
Retrieves the left border width that is displayed around the content if the view is active.
Definition KoView.cpp:268
virtual TDEAction * action(const TQDomElement &element) const
Returns the action described action object.
Definition KoView.cpp:220
virtual double zoom() const
Definition KoView.cpp:294
virtual DCOPObject * dcopObject()
Return a DCOP interface for this view KOffice Applications are strongly recommended to reimplement th...
Definition KoView.cpp:702
KoDocument * koDocument() const
Retrieves the document object of this view.
Definition KoView.cpp:182
virtual void endOperation()
Slot to allow code to signal the end of an operation where the screen should not have been updating.
Definition KoView.cpp:664
bool hasDocumentInWindow(KoDocument *doc)
Definition KoView.cpp:197
virtual int bottomBorder() const
Definition KoView.cpp:283
virtual TQWidget * canvas() const
Overload this function if the content will be displayed on some child widget instead of the view dire...
Definition KoView.cpp:299
virtual int topBorder() const
Definition KoView.cpp:278
virtual void partActivateEvent(KParts::PartActivateEvent *event)
Handles the event KParts::PartActivateEvent.
Definition KoView.cpp:330
virtual TQPoint reverseViewTransformations(const TQPoint &) const
Reverse the transformations that the view makes to its contents, i.e.
Definition KoView.cpp:833
virtual int canvasYOffset() const
Overload this function if the content will be displayed with an offset relative to the upper left cor...
Definition KoView.cpp:311
KoViewChild * child(KoView *view)
Definition KoView.cpp:485
void setDocumentDeleted()
Tells this view that its document has got deleted (called internally)
Definition KoView.cpp:187
virtual int canvasXOffset() const
Overload this function if the content will be displayed with an offset relative to the upper left cor...
Definition KoView.cpp:306
virtual void setZoom(double zoom)
Scales the view on the content.
Definition KoView.cpp:288
virtual void customEvent(TQCustomEvent *ev)
This method handles three events: KParts::PartActivateEvent, KParts::PartSelectEvent and KParts::GUIA...
Definition KoView.cpp:320
void addStatusBarItem(TQWidget *widget, int stretch=0, bool permanent=false)
This adds a widget to the statusbar for this view.
Definition KoView.cpp:417
virtual KoDocumentChild * activeChild()
Definition KoView.cpp:457
virtual void partSelectEvent(KParts::PartSelectEvent *event)
Handles the event KParts::PartSelectEvent.
Definition KoView.cpp:370
void enableAutoScroll()
Sets up so that autoScroll signals are emitted when the mouse pointer is outside the view.
Definition KoView.cpp:470
void slotActionStatusText(const TQString &text)
Display a message in the status bar (calls TQStatusBar::message())
Definition KoView.cpp:688
virtual KoDocumentChild * selectedChild()
Definition KoView.cpp:444
virtual void canvasAddChild(KoViewChild *child)
Overload this function if you need to perform some actions after KoView (the part widget) is inserted...
Definition KoView.cpp:316
virtual TQWMatrix matrix() const TDE_DEPRECATED
Returns the matrix which is used by the view to transform the content.
Definition KoView.cpp:505
virtual void print(KPrinter &printer)
Overload this method with your own printing code.
Definition KoView.cpp:639
virtual int rightBorder() const
Definition KoView.cpp:273
virtual ~KoView()
Destroys the view and unregisters at the document.
Definition KoView.cpp:164
virtual TQPoint applyViewTransformations(const TQPoint &) const
Apply the transformations that the view makes to its contents.
Definition KoView.cpp:828
virtual void newView()
Slot to create a new view around the contained koDocument.
Definition KoView.cpp:644
bool isInOperation() const
Check to see if the view is currently in the middle of an operation which means that there will be no...
Definition KoView.cpp:653
KStatusBar * statusBar() const
Definition KoView.cpp:682
void disableAutoScroll()
Stops the emitting of autoScroll signals.
Definition KoView.cpp:475
virtual void beginOperation()
Slot to allow code to signal the beginning of an operation where the screen should not update until i...
Definition KoView.cpp:658
KoMainWindow * shell() const
Definition KoView.cpp:672
virtual void paintEverything(TQPainter &painter, const TQRect &rect, bool transparent=false)
calls KoDocument::paintEverything()
Definition KoView.cpp:480
void showAllStatusBarItems(bool show)
Show or hide all statusbar items.
Definition KoView.cpp:404
virtual KoDocument * hitTest(const TQPoint &pos)
Retrieves the document that is hit.
Definition KoView.cpp:233
virtual void setupPrinter(KPrinter &printer)
Overload this method to setup KPrinter before the actual printing.
Definition KoView.cpp:634
KoView(KoDocument *document, TQWidget *parent=0, const char *name=0)
Creates a new view for the document.
Definition KoView.cpp:109
void slotClearStatusText()
End of the message in the status bar (calls TQStatusBar::clear())
Definition KoView.cpp:695
bool documentDeleted() const
Definition KoView.cpp:192
void setHighlightingEnabled(bool enable)
virtual void setWidget(TQWidget *widget)
KStatusBar * statusBar()
virtual void show()
TDEAction * zoom(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)