kpresenter

KPrBackground.h

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) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00004    Copyright (C) 2004,2006 Thorsten Zachmann <zachmann@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #ifndef kpbackground_h
00023 #define kpbackground_h
00024 
00025 #include <qsize.h>
00026 #include <qdatetime.h>
00027 #include <KoBrush.h>
00028 #include <KoStyleStack.h>
00029 #include <KoOasisStyles.h>
00030 #include <KoOasisContext.h>
00031 
00032 #include <KoPictureCollection.h>
00033 
00034 #include "global.h"
00035 
00036 class KPrDocument;
00037 class QPainter;
00038 class QPixmap;
00039 class KPrGradientCollection;
00040 class QDomDocument;
00041 class QDomElement;
00042 class KoTextZoomHandler;
00043 class KPrPage;
00044 class KoXmlWriter;
00045 class KoGenStyles;
00046 class KoGenStyle;
00047 
00048 
00049 class KPrBackGround
00050 {
00051 public:
00052     struct Settings
00053     {
00054         Settings( const BackType backType, const QColor backColor1, const QColor backColor2,
00055                   const BCType bcType, const bool unbalanced, const int xfactor, const int yfactor,
00056                   const KoPictureKey &key, const BackView backView )
00057         : m_backType( backType )
00058         , m_backColor1( backColor1 )
00059         , m_backColor2( backColor2 )
00060         , m_bcType( bcType )
00061         , m_unbalanced( unbalanced )
00062         , m_xfactor( xfactor )
00063         , m_yfactor( yfactor )
00064         , m_backPictureKey( key )
00065         , m_backView( backView )
00066         {}
00067 
00068         BackType m_backType;
00069         QColor m_backColor1;
00070         QColor m_backColor2;
00071         // Gradient setting
00072         BCType m_bcType;
00073         bool m_unbalanced;
00074         // Gradient factors
00075         int m_xfactor, m_yfactor;
00076 
00077         KoPictureKey m_backPictureKey;
00078         BackView m_backView;
00079     };
00080 
00081     KPrBackGround( KPrPage *_page );
00082     ~KPrBackGround() {}
00083 
00084     void setBackType( BackType _backType )
00085         {
00086             backType = _backType;
00087             if (backType==BT_PICTURE || backType==BT_CLIPART)
00088                 removeGradient();
00089         }
00090     void setBackView( BackView _backView )
00091         { backView = _backView; }
00092     void setBackColor1( const QColor &_color )
00093         { removeGradient(); backColor1 = _color; }
00094     void setBackColor2( const QColor &_color )
00095         { removeGradient(); backColor2 = _color; }
00096     void setBackColorType( BCType _bcType )
00097         { removeGradient(); bcType = _bcType; }
00098     void setBackUnbalanced( bool _unbalanced )
00099         { removeGradient(); unbalanced = _unbalanced; }
00100     void setBackXFactor( int _xfactor )
00101         { removeGradient(); xfactor = _xfactor; }
00102     void setBackYFactor( int _yfactor )
00103         { removeGradient(); yfactor = _yfactor; }
00105     void setBackPicture( const KoPicture& picture );
00106     void setBackPicture ( const KoPictureKey& key );
00107     void setBackGround( const struct Settings &settings );
00108     struct Settings getBackGround() const;
00109 
00110     KoPicture picture() const { return backPicture;}
00111 
00112     BackType getBackType() const
00113         { return backType; }
00114     BackView getBackView() const
00115         { return backView; }
00116     QColor getBackColor1() const
00117         { return backColor1; }
00118     QColor getBackColor2() const
00119         { return backColor2; }
00120     BCType getBackColorType() const
00121         { return bcType; }
00122     KoPictureKey getBackPictureKey() const
00123         { return backPicture.getKey(); }
00124     KoPicture getBackPicture() const
00125         { return backPicture;}
00126 
00127     bool getBackUnbalanced() const
00128         { return unbalanced; }
00129     int getBackXFactor() const
00130         { return xfactor; }
00131     int getBackYFactor() const
00132         { return yfactor; }
00133 
00134     // Draw the background.
00135     // Uses the @p zoomHandler to determine the size of the background
00136     void drawBackground( QPainter *_painter, const KoTextZoomHandler* zoomHandler,
00137                          const QRect& crect, bool _drawBorders );
00138     // Draw the background. The size of the background is passed explicitly
00139     void drawBackground( QPainter *_painter, const QSize& ext,
00140                          const QRect& crect, bool _drawBorders );
00141 
00142     void reload();
00143 
00144     QDomElement save( QDomDocument &doc );
00145     void load( const QDomElement &element );
00146     void loadOasis( KoOasisContext & context );
00147     void saveOasisBackgroundPageStyle( KoGenStyle &stylepageauto, KoGenStyles &mainStyles );
00148 
00149 protected:
00150     void drawBackColor( QPainter *_painter, const QSize& ext, const QRect& crect );
00151     void drawBackPix( QPainter *_painter, const QSize& ext, const QRect& crect );
00152     void drawBorders( QPainter *_painter, const QSize& ext, const QRect& crect );
00153     // The current gradient isn't valid anymore (e.g. size or settings changed) -> discard it
00154     void removeGradient();
00155     // Generate a new gradient pixmap, for the given size
00156     void generateGradient( const QSize& size );
00157 
00158     KoPictureCollection *pictureCollection() const;
00159     KPrGradientCollection *gradientCollection() const;
00160 
00161     QString saveOasisPictureStyle( KoGenStyles& mainStyles );
00162 
00163 private:
00164     BackType backType;
00165     BackView backView;
00166     QColor backColor1;
00167     QColor backColor2;
00168     BCType bcType;
00169 
00170     // Background picture
00171     KoPicture backPicture;
00172 
00173     // Pixmap used to cache the drawing of the gradient, at the current size
00174     const QPixmap *gradientPixmap;
00175 
00176     // The page for which this background exists
00177     KPrPage *m_page;
00178 
00179     //int footerHeight;
00180 
00181     // Gradient factors
00182     int xfactor, yfactor;
00183 
00184     // Gradient setting
00185     bool unbalanced;
00186 };
00187 
00188 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys