F:/KPlato/koffice/libs/kofficecore/KoViewChild.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002  *   Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
00003  * 
00004  *   This library is free software; you can redistribute it and/or
00005  *   modify it under the terms of the GNU Library General Public
00006  *   License as published by the Free Software Foundation; either
00007  *   version 2 of the License, or (at your option) any later version.
00008  * 
00009  *   This library is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *   Library General Public License for more details.
00013  * 
00014  *   You should have received a copy of the GNU Library General Public License
00015  *   along with this library; see the file COPYING.LIB.  If not, write to
00016  *   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #include "KoViewChild.h"
00021 
00022 #include <QRect>
00023 
00024 #include <KoView.h>
00025 #include <KoFrame.h>
00026 #include <KoDocumentChild.h>
00027 #include <KoDocument.h>
00028 
00029 class KoViewChild::KoViewChildPrivate
00030 {
00031     public:
00032         KoViewChildPrivate()
00033         {
00034         }
00035         ~KoViewChildPrivate()
00036         {
00037         }
00038 };
00039 
00040 KoViewChild::KoViewChild( KoDocumentChild *child, KoView *_parentView )
00041 {
00042     d = new KoViewChildPrivate;
00043     m_parentView = _parentView;
00044     m_child = child;
00045 
00046     m_frame = new KoFrame( parentView()->canvas() );
00047     KoView *view = child->document()->createView( m_frame );
00048     view->setXMLGUIBuildDocument( child->document()->viewBuildDocument( view ) );
00049 
00050     view->setPartManager( parentView()->partManager() );
00051 
00052     // hack? (Werner)
00053     view->setZoom( parentView()->zoom() * qMax(child->xScaling(), child->yScaling()) );
00054 
00055     m_frame->setView( view );
00056     m_frame->show();
00057     m_frame->raise();
00058 
00059     parentView()->canvasAddChild( this );
00060 
00061 
00062     /*
00063      *   KoViewChild has basically three geometries to keep in sync.
00064      *   - The KoDocumentChild geometry (i.e. the embedded object's geometry, unzoomed)
00065      *   - Its own geometry (used for hit-test etc.)
00066      *   - The KoFrame geometry (the graphical widget for moving the object when active)
00067      * 
00068      *   So we need to subtract the scrollview's offset for the frame geometry, since it's a widget.
00069      * 
00070      *   The rules are
00071      *   (R1) frameGeometry = viewGeometry(childGeometry) "+" m_frame->{left|right|top|bottom}Border() - scrollview offset,
00072      *   (R2) frameGeometry = myGeometry "+" active_frame_border - scrollview offset.
00073      * 
00074      *   So: (R3, unused) myGeometry = viewGeometry(childGeometry) "+" m_frame->{left|right|top|bottom}Border() "-" active_frame_border
00075      * 
00076      *   Notes: active_frame_border is m_frame->border() (0 when inactive, 5 when active).
00077      *          {left|right|top|bottom}Border are the borders used in kspread (0 when inactive, big when active).
00078      *          "+" border means we add a border, so it's a subtraction on x, y and an addition on width, height.
00079      * 
00080      *          viewGeometry() applies the zoom as well as any other translation the app might want to do
00081      */
00082 
00083     // Setting the frameGeometry is done in setInitialFrameGeometry, which is
00084     // also called right after activation.
00085 
00086     connect( view, SIGNAL( activated( bool ) ),
00087              parentView(), SLOT( slotChildActivated( bool ) ) );
00088 }
00089 
00090 KoViewChild::~KoViewChild()
00091 {
00092     if ( m_frame )
00093     {
00094         slotFrameGeometryChanged();
00095         delete static_cast<KoFrame *>( m_frame );
00096     }
00097     delete d;
00098 }
00099 
00100 void KoViewChild::slotFrameGeometryChanged()
00101 {
00102     // Set our geometry from the frame geometry (R2 reversed)
00103     QRect geom = m_frame->geometry();
00104     int b = m_frame->border();
00105     QRect borderRect( geom.x() + b + parentView()->canvasXOffset(),
00106                       geom.y() + b + parentView()->canvasYOffset(),
00107                       geom.width() - b * 2,
00108                       geom.height() - b * 2 );
00109                       setGeometry( borderRect );
00110 
00111     if(m_child)
00112     {
00113         // Set the child geometry from the frame geometry (R1 reversed)
00114         QRect borderLessRect( geom.x() + m_frame->leftBorder() + parentView()->canvasXOffset(),
00115                             geom.y() + m_frame->topBorder() + parentView()->canvasYOffset(),
00116                             geom.width() - m_frame->leftBorder() - m_frame->rightBorder(),
00117                             geom.height() - m_frame->topBorder() - m_frame->bottomBorder() );
00118 
00119         // We don't want to trigger slotDocGeometryChanged again
00120         lock();
00121         QRect childGeom = parentView()->reverseViewTransformations( borderLessRect );
00122         kDebug() << "KoChild::slotFrameGeometryChanged child geometry "
00123         << ( geometry() == childGeom ? "already " : "set to " )
00124         << childGeom << endl;
00125         m_child->setGeometry( childGeom );
00126         unlock();
00127     }
00128 }
00129 
00130 void KoViewChild::slotDocGeometryChanged()
00131 {
00132     if ( locked() )
00133         return;
00134     // Set frame geometry from child geometry (R1)
00135     // The frame's resizeEvent will call slotFrameGeometryChanged.
00136     QRect geom = parentView()->applyViewTransformations( m_child->geometry() );
00137     QRect borderRect( geom.x() - m_frame->leftBorder() - parentView()->canvasXOffset(),
00138                       geom.y() - m_frame->topBorder() - parentView()->canvasYOffset(),
00139                       geom.width() + m_frame->leftBorder() + m_frame->rightBorder(),
00140                       geom.height() + m_frame->topBorder() + m_frame->bottomBorder() );
00141     kDebug() << "KoViewChild::slotDocGeometryChanged frame geometry "
00142     << ( m_frame->geometry() == borderRect ? "already " : "set to " )
00143     << borderRect << endl;
00144 
00145     m_frame->setGeometry( borderRect );
00146 }
00147 
00148 void KoViewChild::setInitialFrameGeometry()
00149 {
00150     kDebug() << k_funcinfo << endl;
00151 
00152     // Connect only now, so that the GUI building doesn't move us around.
00153     connect( m_frame, SIGNAL( geometryChanged() ),
00154              this, SLOT( slotFrameGeometryChanged() ) );
00155     connect( m_child, SIGNAL( changed( KoChild * ) ),
00156             this, SLOT( slotDocGeometryChanged() ) );
00157 
00158     // Set frameGeometry from childGeometry
00159     slotDocGeometryChanged();
00160     // Set myGeometry from frameGeometry
00161     slotFrameGeometryChanged();
00162 }
00163 
00164 #include "KoViewChild.moc"

Généré le Wed Nov 22 23:41:04 2006 pour KPlato par  doxygen 1.5.1-p1