F:/KPlato/koffice/libs/kformula/contextstyle.h

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
00003                       Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
00004    Copyright (C) 2006 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com>                  
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 CONTEXTSTYLE_H
00023 #define CONTEXTSTYLE_H
00024 
00025 #include <QColor>
00026 #include <QFont>
00027 #include <QString>
00028 #include <QStringList>
00029 #include <QValueStack>
00030 #include <kconfig.h>
00031 #include <KoZoomHandler.h>
00032 
00033 #include "kformuladefs.h"
00034 
00035 
00036 KFORMULA_NAMESPACE_BEGIN
00037 
00038 class FontStyle;
00039 class SymbolTable;
00040 
00041 
00050 class ContextStyle : public KoZoomHandler
00051 {
00052 public:
00053 
00054     enum Alignment { left, center, right };
00055 
00068     enum TextStyle {
00069         displayStyle = 0,
00070         textStyle = 1,
00071         scriptStyle = 2,
00072         scriptScriptStyle = 3
00073     };
00074 
00075     enum IndexStyle {normal, cramped};
00076 
00080     ContextStyle();
00081     ~ContextStyle();
00082 
00086     void init( bool init = true );
00087 
00093     void readConfig( KConfig* config, bool init = true );
00094 
00095     bool edit() const { return m_edit; }
00096     void setEdit( bool e ) { m_edit = e; }
00097 
00101     const SymbolTable& symbolTable() const;
00102 
00103     const FontStyle& fontStyle() const { return *m_fontStyle; }
00104 
00105     //copied from KoTextZoomHandler.h
00106     double pixelToLayoutUnitX( double x ) const;
00107     double pixelToLayoutUnitY( double y ) const;
00108     double ptToPixelX( double pt ) const
00109          { return pt * m_resolutionX; }
00110     double ptToPixelY( double pt ) const
00111          { return pt * m_resolutionY; }
00112     double ptToLayoutUnitPt( double pt ) const
00113     {
00114             // taken from KoTextZoomHandler
00115             double m_layoutUnitFactor = 20.0;
00116             return pt *  m_layoutUnitFactor; }
00117     double ptToLayoutUnitPixX( double x_pt ) const
00118         { return ptToPixelX( ptToLayoutUnitPt( x_pt ) ); }
00119     double ptToLayoutUnitPixY( double y_pt ) const
00120             { return ptToPixelY( ptToLayoutUnitPt( y_pt ) ); }
00121     double pixelYToPt( double y ) const
00122             { return y / m_resolutionY; }
00123     double layoutUnitPtToPt( double lupt ) const
00124             { return lupt / 20.0; }
00125     double layoutUnitToPixelX( double lupix ) const;
00126     double layoutUnitToPixelY( double lupix ) const;
00127     double pixelXToPt( double x ) const
00128             { return x / m_resolutionX; }
00129     QPointF pixelToLayoutUnit( const QPointF &p ) const
00130         { return QPointF( pixelToLayoutUnitX( p.x() ),
00131                           pixelToLayoutUnitY( p.y() ) ); }
00132     QRectF pixelToLayoutUnit( const QRectF &r ) const
00133         {
00134           double x = pixelToLayoutUnitX( r.x() );
00135           double y = pixelToLayoutUnitY( r.y() );
00136           double width = pixelToLayoutUnitX( r.x() + r.width() ) - x;
00137           double height = pixelToLayoutUnitY( r.y() + r.height() ) - y;
00138         return QRectF( x,y,width,height ); }
00139     double layoutUnitToFontSize( double luSize, bool /*forPrint*/ ) const;
00140     double layoutUnitPtToPt( double lupt )
00141             { return lupt / 20.0; }
00142     QPoint layoutUnitToPixel( const QPoint &p ) const
00143     { return QPoint( layoutUnitToPixelX( p.x() ),
00144                                  layoutUnitToPixelY( p.y() ) ); }           
00145 
00146     
00147     void setZoomAndResolution( int zoom, int dpiX, int dpiY );
00148 
00153     bool setZoomAndResolution( int zoom, double zoomX, double zoomY, bool updateViews, bool forPrint );
00154 
00155     bool syntaxHighlighting() const { return m_syntaxHighlighting; }
00156     void setSyntaxHighlighting( bool highlight ) { m_syntaxHighlighting = highlight; }
00157 
00158     QColor getDefaultColor()  const { return defaultColor; }
00159     QColor getNumberColorPlain()   const { return numberColor; }
00160     QColor getOperatorColorPlain() const { return operatorColor; }
00161     QColor getErrorColorPlain()    const { return errorColor; }
00162     QColor getEmptyColorPlain()    const { return emptyColor; }
00163     QColor getHelpColorPlain()     const { return helpColor; }
00164     QColor getNumberColor()   const;
00165     QColor getOperatorColor() const;
00166     QColor getErrorColor()    const;
00167     QColor getEmptyColor()    const;
00168     QColor getHelpColor()     const;
00169 
00170     void setDefaultColor( const QColor& );
00171     void setNumberColor( const QColor& );
00172     void setOperatorColor( const QColor& );
00173     void setErrorColor( const QColor& );
00174     void setEmptyColor( const QColor& );
00175     void setHelpColor( const QColor& );
00176 
00177     QString getFontStyle() const { return m_fontStyleName; }
00178     void setFontStyle( const QString& fontStyle, bool init = true );
00179 
00180     QFont getMathFont()       const { return mathFont; }
00181     QFont getBracketFont()    const { return bracketFont; }
00182     QFont getDefaultFont()    const { return defaultFont; }
00183     QFont getNameFont()       const { return nameFont; }
00184     QFont getNumberFont()     const { return numberFont; }
00185     QFont getOperatorFont()   const { return operatorFont; }
00186     QFont getSymbolFont()     const { return symbolFont; }
00187 
00188     void setMathFont( QFont f )     { defaultFont = f; }
00189     void setBracketFont( QFont f )  { bracketFont = f; }
00190     void setDefaultFont( QFont f )  { defaultFont = f; }
00191     void setNameFont( QFont f )     { nameFont = f; }
00192     void setNumberFont( QFont f )   { numberFont = f; }
00193     void setOperatorFont( QFont f ) { operatorFont = f; }
00194 
00195     //const QStringList& requestedFonts() const;
00196     //void setRequestedFonts( const QStringList& list );
00197 
00198     double getReductionFactor( TextStyle tstyle ) const;
00199 
00200     luPt getBaseSize() const;
00201     int baseSize() const { return m_baseSize; }
00202     void setBaseSize( int pointSize );
00203     void setSizeFactor( double factor );
00204 
00205     TextStyle getBaseTextStyle() const { return m_baseTextStyle; }
00206     bool isScript( TextStyle tstyle ) const { return ( tstyle == scriptStyle ) ||
00207                                                      ( tstyle == scriptScriptStyle ); }
00208 
00212     luPixel getSpace( TextStyle tstyle, SpaceWidth space, double factor ) const;
00213     luPixel getThinSpace( TextStyle tstyle, double factor ) const;
00214     luPixel getMediumSpace( TextStyle tstyle, double factor ) const;
00215     luPixel getThickSpace( TextStyle tstyle, double factor ) const;
00216     luPixel getQuadSpace( TextStyle tstyle, double factor ) const;
00217 
00218     luPixel axisHeight( TextStyle tstyle, double factor ) const;
00219 
00223     luPt getAdjustedSize( TextStyle tstyle, double factor ) const;
00224 
00228     luPixel getLineWidth( double factor ) const;
00229 
00230     luPixel getEmptyRectWidth( double factor ) const;
00231     luPixel getEmptyRectHeight( double factor ) const;
00232 
00233     Alignment getMatrixAlignment() const { return center; }
00234 
00235     bool getCenterSymbol() const { return centerSymbol; }
00236 
00243     TextStyle convertTextStyleFraction( TextStyle tstyle ) const;
00244 
00251     TextStyle convertTextStyleIndex( TextStyle tstyle ) const;
00252 
00262     IndexStyle convertIndexStyleUpper( IndexStyle istyle ) const {
00263         return istyle; }
00264 
00265 
00275     IndexStyle convertIndexStyleLower( IndexStyle /*istyle*/ ) const {
00276         return cramped; }
00277 
00278 private:
00279 
00280     void setup();
00281 
00282     struct TextStyleValues {
00283 
00284         void setup( double reduction ) { reductionFactor = reduction; }
00285 
00286         luPt thinSpace( luPt quad ) const   { return static_cast<luPt>( reductionFactor*static_cast<double>( quad )/6. ); }
00287         luPt mediumSpace( luPt quad ) const { return static_cast<luPt>( reductionFactor*static_cast<double>( quad )*2./9. ); }
00288         luPt thickSpace( luPt quad ) const  { return static_cast<luPt>( reductionFactor*static_cast<double>( quad )*5./18. ); }
00289         luPt quadSpace( luPt quad ) const   { return quad; }
00290 
00291         luPixel axisHeight( luPixel height ) const { return static_cast<luPixel>( reductionFactor*height ); }
00292         double reductionFactor;
00293     };
00294 
00295     TextStyleValues textStyleValues[ 4 ];
00296 
00297     QFont mathFont;
00298     QFont bracketFont;
00299     QFont defaultFont;
00300     QFont nameFont;
00301     QFont numberFont;
00302     QFont operatorFont;
00303     QFont symbolFont;
00304 
00305     //QStringList m_requestedFonts;
00306 
00307     QColor defaultColor;
00308     QColor numberColor;
00309     QColor operatorColor;
00310     QColor errorColor;
00311     QColor emptyColor;
00312     QColor helpColor;
00313 
00318     bool linearMovement;
00319 
00323     int m_baseSize;
00324 
00329     double m_sizeFactor;
00330 
00334     TextStyle m_baseTextStyle;
00335 
00339     pt lineWidth;
00340 
00344     luPt quad;
00345 
00349     luPixel m_axisHeight;
00350 
00355     bool centerSymbol;
00356 
00360     bool m_syntaxHighlighting;
00361 
00365     bool m_edit;
00366 
00370     //SymbolTable table;
00371 
00372     FontStyle* m_fontStyle;
00373     QString m_fontStyleName;
00374 };
00375 
00376 // Section 3.3.4.2, default values
00377 const double scriptsizemultiplier   = 0.71;
00378 const double scriptminsize          = 8;
00379 const double veryverythinmathspace  = 0.0555556;
00380 const double verythinmathspace      = 0.111111;
00381 const double thinmathspace          = 0.166667;
00382 const double mediummathspace        = 0.222222;
00383 const double thickmathspace         = 0.277778;
00384 const double verythickmathspace     = 0.333333;
00385 const double veryverythickmathspace = 0.388889;
00386 
00387 class StyleAttributes {
00388  public:
00389     double sizeFactor() const ;
00390     bool customMathVariant() const ;
00391     CharStyle charStyle() const ;
00392     CharFamily charFamily() const ;
00393     QColor color() const ;
00394     QColor background() const ;
00395     QFont font() const ;
00396     bool fontWeight() const ;
00397     bool customFontWeight() const ;
00398     bool fontStyle() const ;
00399     bool customFontStyle() const ;
00400     bool customFont() const ;
00401 
00402     int scriptLevel() const ;
00403     double scriptSizeMultiplier() const ;
00404     double scriptMinSize() const ;
00405     double veryVeryThinMathSpace() const ;
00406     double veryThinMathSpace() const ;
00407     double thinMathSpace() const ;
00408     double mediumMathSpace() const ;
00409     double thickMathSpace() const ;
00410     double veryThickMathSpace() const ;
00411     double veryVeryThickMathSpace() const ;
00412     bool displayStyle() const ;
00413     bool customDisplayStyle() const ;
00414 
00415     double getSpace( SizeType type, double length ) const ;
00416 
00417     void setSizeFactor( double s ) { m_size.push( s ); }
00418     void setCustomMathVariant( bool cmv ) { m_customMathVariant.push( cmv ); }
00419     void setCharStyle( CharStyle cs ) { m_charStyle.push( cs ); }
00420     void setCharFamily( CharFamily cf ) { m_charFamily.push( cf ); }
00421     void setColor( const QColor& c ) { m_color.push( c ); }
00422     void setBackground( const QColor& bg ) { m_background.push( bg ); }
00423     void setFont( const QFont& f ) { m_font.push( f ); }
00424     void setCustomFont( bool cf ) { m_customFontFamily.push ( cf ); }
00425     void setCustomFontWeight( bool cfw ) { m_customFontWeight.push( cfw ); }
00426     void setFontWeight( bool fw ) { m_fontWeight.push( fw ); }
00427     void setCustomFontStyle( bool cfs ) { m_customFontStyle.push( cfs ); }
00428     void setFontStyle( bool fs ) { m_fontStyle.push( fs ); }
00429 
00430     void setScriptLevel( int s ) { m_scriptLevel.push( s ); }
00431     void setScriptSizeMultiplier( double s ) { m_scriptSizeMultiplier.push( s ); }
00432     void setScriptMinSize( double s ) { m_scriptMinSize.push( s ); }
00433     void setVeryVeryThinMathSpace( double s ) { m_veryVeryThinMathSpace.push( s ); }
00434     void setVeryThinMathSpace( double s ) { m_veryThinMathSpace.push( s ); }
00435     void setThinMathSpace( double s ) { m_thinMathSpace.push( s ); }
00436     void setMediumMathSpace( double s ) { m_mediumMathSpace.push( s ); }
00437     void setThickMathSpace( double s ) { m_thickMathSpace.push( s ); }
00438     void setVeryThickMathSpace( double s ) { m_veryThickMathSpace.push( s ); }
00439     void setVeryVeryThickMathSpace( double s ) { m_veryVeryThickMathSpace.push( s ); }
00440     void setDisplayStyle( bool ds ) { m_displayStyle.push( ds ); }
00441     void setCustomDisplayStyle( bool cds ) { m_customDisplayStyle.push( cds ); }
00442 
00443     void reset();
00444     void resetSize();
00445     void resetCharStyle();
00446     void resetCharFamily();
00447     void resetColor();
00448     void resetBackground();
00449     void resetFontFamily();
00450     void resetFontWeight();
00451     void resetFontStyle();
00452 
00453     void resetScriptLevel();
00454     void resetScriptSizeMultiplier();
00455     void resetScriptMinSize();
00456     void resetVeryVeryThinMathSpace();
00457     void resetVeryThinMathSpace();
00458     void resetThinMathSpace();
00459     void resetMediumMathSpace();
00460     void resetThickMathSpace();
00461     void resetVeryThickMathSpace();
00462     void resetVeryVeryThickMathSpace();
00463     void resetDisplayStyle();
00464 
00465  private:
00466     // Size of the font in points (mathsize / fontsize)
00467     QValueStack<double> m_size;
00468 
00469     // Whether a custom mathvariant attribute is in use
00470     QValueStack<bool> m_customMathVariant;
00471 
00472     // Font style (mathvariant, fontweight, fontstyle)
00473     QValueStack<CharStyle> m_charStyle;
00474 
00475     // Font family (mathvariant)
00476     QValueStack<CharFamily> m_charFamily;
00477 
00478     // Foreground color (mathcolor, color)
00479     QValueStack<QColor> m_color;
00480 
00481     // Background color (mathbackground)
00482     QValueStack<QColor> m_background;
00483 
00484     // Font family (fontfamily)
00485     QValueStack<QFont> m_font;
00486 
00487     // Whether a custom fontfamily attribute is in use (instead of CharFamily)
00488     QValueStack<bool> m_customFontFamily;
00489 
00490     // Font Weight (fontweight)
00491     QValueStack<bool> m_fontWeight;
00492 
00493     // Whether a custom fontweight attribute is in use
00494     QValueStack<bool> m_customFontWeight;
00495 
00496     // Font Style (fontstyle)
00497     QValueStack<bool> m_fontStyle;
00498 
00499     // Whether a custom fontstyle attribute is in use
00500     QValueStack<bool> m_customFontStyle;
00501 
00502     QValueStack<int> m_scriptLevel;
00503     QValueStack<double> m_scriptSizeMultiplier;
00504     QValueStack<double> m_scriptMinSize;
00505     QValueStack<double> m_veryVeryThinMathSpace;
00506     QValueStack<double> m_veryThinMathSpace;
00507     QValueStack<double> m_thinMathSpace;
00508     QValueStack<double> m_mediumMathSpace;
00509     QValueStack<double> m_thickMathSpace;
00510     QValueStack<double> m_veryThickMathSpace;
00511     QValueStack<double> m_veryVeryThickMathSpace;
00512     QValueStack<bool> m_displayStyle;
00513     QValueStack<bool> m_customDisplayStyle;
00514 };
00515 
00516 
00517 KFORMULA_NAMESPACE_END
00518 
00519 #endif // CONTEXTSTYLE_H

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