kpresenter

KPrObjectProperties.cpp

00001 // -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
00002 /* This file is part of the KDE project
00003    Copyright (C) 2005-2006 Thorsten Zachmann <zachmann@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "KPrObjectProperties.h"
00022 
00023 #include "KPrObject.h"
00024 #include "KPrGroupObject.h"
00025 #include "KPrLineObject.h"
00026 #include "KPrRectObject.h"
00027 #include "KPrPolygonObject.h"
00028 #include "KPrPieObject.h"
00029 #include "KPrPixmapObject.h"
00030 #include "KPrPointObject.h"
00031 #include "KPrBezierCurveObject.h"
00032 #include "KPrTextObject.h"
00033 
00034 KPrObjectProperties::KPrObjectProperties( const QPtrList<KPrObject> &objects )
00035 : m_objects( objects )
00036 , m_flags( 0 )
00037 , m_pen( KoPen( Qt::black, 1.0, Qt::SolidLine ), L_NORMAL, L_NORMAL )
00038 , m_protectContent( STATE_UNDEF )
00039 {
00040     getProperties( m_objects );
00041 }
00042 
00043 
00044 KPrObjectProperties::~KPrObjectProperties()
00045 {
00046 }
00047 
00048 
00049 void KPrObjectProperties::getProperties( const QPtrList<KPrObject> &objects )
00050 {
00051     QPtrListIterator<KPrObject> it( objects );
00052     for ( ; it.current() ; ++it )
00053     {
00054         switch ( it.current()->getType() )
00055         {
00056             case OT_LINE:
00057             case OT_FREEHAND:
00058             case OT_POLYLINE:
00059             case OT_QUADRICBEZIERCURVE:
00060             case OT_CUBICBEZIERCURVE:
00061                 getPenProperties( it.current() );
00062                 getLineEndsProperties( it.current() );
00063                 m_flags |= PtOther;
00064                 break;
00065             case OT_PIE:
00066                 getPieProperties( it.current() );
00067                 break;
00068             case OT_RECT:
00069                 getRectProperties( it.current() );
00070                 break;
00071             case OT_POLYGON:
00072                 getPolygonSettings( it.current() );
00073                 break;
00074             case OT_TEXT:
00075                 getTextProperties( it.current() );
00076                 break;
00077             case OT_PART:
00078             case OT_ELLIPSE:
00079             case OT_CLOSED_LINE:
00080             case OT_AUTOFORM:
00081                 getPenProperties( it.current() );
00082                 getBrushProperties( it.current() );
00083                 m_flags |= PtOther;
00084                 break;
00085             case OT_CLIPART:
00086             case OT_PICTURE:
00087                 getPictureProperties( it.current() );
00088                 break;
00089             case OT_GROUP:
00090                 {
00091                     KPrGroupObject *obj = dynamic_cast<KPrGroupObject*>( it.current() );
00092                     if ( obj )
00093                     {
00094                         getProperties( obj->objectList() );
00095                     }
00096                 }
00097                 break;
00098             default:
00099                 break;
00100         }
00101     }
00102 }
00103 
00104 
00105 void KPrObjectProperties::getPenProperties( KPrObject *object )
00106 {
00107     if ( !( m_flags & PtPen ) )
00108     {
00109         KPrShadowObject *obj = dynamic_cast<KPrShadowObject*>( object );
00110         if ( obj )
00111         {
00112             m_pen.pen = obj->getPen();
00113 
00114             m_flags |= PtPen;
00115         }
00116     }
00117     if ( !( m_flags & PtPenWidth ) )
00118     {
00119         KPrShadowObject *obj = dynamic_cast<KPrShadowObject*>( object );
00120         if ( obj && obj->getPen().style() != Qt::NoPen )
00121         {
00122             m_flags |= PtPenWidth;
00123         }
00124     }
00125 }
00126 
00127 
00128 void KPrObjectProperties::getLineEndsProperties( KPrObject *object )
00129 {
00130     if ( !( m_flags & PtLineEnds ) )
00131     {
00132         switch ( object->getType() )
00133         {
00134             case OT_LINE:
00135                 {
00136                     KPrLineObject *obj = dynamic_cast<KPrLineObject*>( object );
00137                     if ( obj )
00138                     {
00139                         m_pen.lineBegin = obj->getLineBegin();
00140                         m_pen.lineEnd = obj->getLineEnd();
00141 
00142                         m_flags |= PtLineEnds;
00143                     }
00144                     break;
00145                 }
00146             case OT_FREEHAND:
00147             case OT_POLYLINE:
00148             case OT_QUADRICBEZIERCURVE:
00149             case OT_CUBICBEZIERCURVE:
00150                 {
00151                     KPrPointObject *obj = dynamic_cast<KPrPointObject*>( object );
00152                     if ( obj )
00153                     {
00154                         m_pen.lineBegin = obj->getLineBegin();
00155                         m_pen.lineEnd = obj->getLineEnd();
00156 
00157                         m_flags |= PtLineEnds;
00158                     }
00159                     break;
00160                 }
00161             case OT_PIE:
00162                 {
00163                     KPrPieObject *obj = dynamic_cast<KPrPieObject*>( object );
00164                     if ( obj )
00165                     {
00166                         m_pen.lineBegin = obj->getLineBegin();
00167                         m_pen.lineEnd = obj->getLineEnd();
00168 
00169                         m_flags |= PtLineEnds;
00170                     }
00171                     break;
00172                 }
00173             default:
00174                 break;
00175         }
00176     }
00177 }
00178 
00179 
00180 void KPrObjectProperties::getBrushProperties( KPrObject *object )
00181 {
00182     if ( !( m_flags & PtBrush ) )
00183     {
00184         KPr2DObject * obj = dynamic_cast<KPr2DObject*>( object );
00185         if ( obj )
00186         {
00187             m_brush.brush = obj->getBrush();
00188             m_brush.fillType = obj->getFillType();
00189             m_brush.gColor1 = obj->getGColor1();
00190             m_brush.gColor2 = obj->getGColor2();
00191             m_brush.gType = obj->getGType();
00192             m_brush.unbalanced = obj->getGUnbalanced();
00193             m_brush.xfactor = obj->getGXFactor();
00194             m_brush.yfactor = obj->getGYFactor();
00195 
00196             m_flags |= PtBrush;
00197         }
00198     }
00199 }
00200 
00201 
00202 void KPrObjectProperties::getRectProperties( KPrObject *object )
00203 {
00204     if ( !( m_flags & PtRectangle ) )
00205     {
00206         KPrRectObject *obj = dynamic_cast<KPrRectObject*>( object );
00207         if ( obj )
00208         {
00209             obj->getRnds( m_rectValues.xRnd, m_rectValues.yRnd );
00210 
00211             getPenProperties( object );
00212             getBrushProperties( object );
00213             m_flags |= PtRectangle;
00214         }
00215     }
00216 }
00217 
00218 
00219 void KPrObjectProperties::getPolygonSettings( KPrObject *object )
00220 {
00221     if ( !( m_flags & PtPolygon ) )
00222     {
00223         KPrPolygonObject *obj = dynamic_cast<KPrPolygonObject*>( object );
00224         if ( obj )
00225         {
00226             m_polygonSettings.checkConcavePolygon = obj->getCheckConcavePolygon();
00227             m_polygonSettings.cornersValue = obj->getCornersValue();
00228             m_polygonSettings.sharpnessValue = obj->getSharpnessValue();
00229 
00230             getPenProperties( object );
00231             getBrushProperties( object );
00232             m_flags |= PtPolygon;
00233         }
00234     }
00235 }
00236 
00237 
00238 void KPrObjectProperties::getPieProperties( KPrObject *object )
00239 {
00240     if ( !( m_flags & PtPie ) )
00241     {
00242         KPrPieObject *obj = dynamic_cast<KPrPieObject*>( object );
00243         if ( obj )
00244         {
00245             m_pieValues.pieType = obj->getPieType();
00246             m_pieValues.pieAngle = obj->getPieAngle();
00247             m_pieValues.pieLength = obj->getPieLength();
00248 
00249             getPenProperties( object );
00250             if ( obj->getPieType() != PT_ARC )
00251             {
00252                 getBrushProperties( object );
00253             }
00254             else
00255             {
00256                 getLineEndsProperties( object );
00257             }
00258 
00259             m_flags |= PtPie;
00260         }
00261     }
00262 }
00263 
00264 
00265 void KPrObjectProperties::getPictureProperties( KPrObject *object )
00266 {
00267     if ( !( m_flags & PtPicture ) )
00268     {
00269         KPrPixmapObject *obj = dynamic_cast<KPrPixmapObject*>( object );
00270         if ( obj )
00271         {
00272             m_pictureSettings.mirrorType = obj->getPictureMirrorType();
00273             m_pictureSettings.depth = obj->getPictureDepth();
00274             m_pictureSettings.swapRGB = obj->getPictureSwapRGB();
00275             m_pictureSettings.grayscal = obj->getPictureGrayscal();
00276             m_pictureSettings.bright = obj->getPictureBright();
00277             m_pixmap = obj->getOriginalPixmap();
00278 
00279             getPenProperties( object );
00280             getBrushProperties( object );
00281             m_flags |= PtPicture;
00282         }
00283     }
00284 }
00285 
00286 
00287 void KPrObjectProperties::getTextProperties( KPrObject *object )
00288 {
00289     KPrTextObject *obj = dynamic_cast<KPrTextObject*>( object );
00290     if ( obj )
00291     {
00292         if ( !( m_flags & PtText ) )
00293         {
00294             m_marginsStruct = MarginsStruct( obj );
00295             m_protectContent = obj->isProtectContent() ? STATE_ON : STATE_OFF;
00296 
00297             getPenProperties( object );
00298             getBrushProperties( object );
00299             m_flags |= PtText;
00300         }
00301         else
00302         {
00303             PropValue pv = obj->isProtectContent() ? STATE_ON : STATE_OFF;
00304             if ( pv != m_protectContent )
00305             {
00306                 m_protectContent = STATE_UNDEF;
00307             }
00308         }
00309     }
00310 }
KDE Home | KDE Accessibility Home | Description of Access Keys