lib

contextstyle.h

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 
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 #ifndef CONTEXTSTYLE_H
00022 #define CONTEXTSTYLE_H
00023 
00024 //Qt Include
00025 #include <qcolor.h>
00026 #include <qfont.h>
00027 #include <qstring.h>
00028 #include <qstringlist.h>
00029 #include <qvaluestack.h>
00030 
00031 //KDE Include
00032 #include <kconfig.h>
00033 #include <KoTextZoomHandler.h>
00034 
00035 //Formula include
00036 #include "kformuladefs.h"
00037 
00038 
00039 KFORMULA_NAMESPACE_BEGIN
00040 
00041 class FontStyle;
00042 class SymbolTable;
00043 
00044 
00053 class ContextStyle : public KoTextZoomHandler
00054 {
00055 public:
00056 
00057     enum Alignment { left, center, right };
00058 
00071     enum TextStyle {
00072         displayStyle = 0,
00073         textStyle = 1,
00074         scriptStyle = 2,
00075         scriptScriptStyle = 3
00076     };
00077 
00078     enum IndexStyle {normal, cramped};
00079 
00083     ContextStyle();
00084     ~ContextStyle();
00085 
00089     void init( bool init = true );
00090 
00096     void readConfig( KConfig* config, bool init = true );
00097 
00098     bool edit() const { return m_edit; }
00099     void setEdit( bool e ) { m_edit = e; }
00100 
00104     const SymbolTable& symbolTable() const;
00105 
00106     const FontStyle& fontStyle() const { return *m_fontStyle; }
00107 
00108 
00109     void setZoomAndResolution( int zoom, int dpiX, int dpiY );
00110 
00115     bool setZoomAndResolution( int zoom, double zoomX, double zoomY, bool updateViews, bool forPrint );
00116 
00117     bool syntaxHighlighting() const { return m_syntaxHighlighting; }
00118     void setSyntaxHighlighting( bool highlight ) { m_syntaxHighlighting = highlight; }
00119 
00120     QColor getDefaultColor()  const { return defaultColor; }
00121     QColor getNumberColorPlain()   const { return numberColor; }
00122     QColor getOperatorColorPlain() const { return operatorColor; }
00123     QColor getErrorColorPlain()    const { return errorColor; }
00124     QColor getEmptyColorPlain()    const { return emptyColor; }
00125     QColor getHelpColorPlain()     const { return helpColor; }
00126     QColor getNumberColor()   const;
00127     QColor getOperatorColor() const;
00128     QColor getErrorColor()    const;
00129     QColor getEmptyColor()    const;
00130     QColor getHelpColor()     const;
00131 
00132     void setDefaultColor( const QColor& );
00133     void setNumberColor( const QColor& );
00134     void setOperatorColor( const QColor& );
00135     void setErrorColor( const QColor& );
00136     void setEmptyColor( const QColor& );
00137     void setHelpColor( const QColor& );
00138 
00139     QString getFontStyle() const { return m_fontStyleName; }
00140     void setFontStyle( const QString& fontStyle, bool init = true );
00141 
00142     QFont getMathFont()       const { return mathFont; }
00143     QFont getBracketFont()    const { return bracketFont; }
00144     QFont getDefaultFont()    const { return defaultFont; }
00145     QFont getNameFont()       const { return nameFont; }
00146     QFont getNumberFont()     const { return numberFont; }
00147     QFont getOperatorFont()   const { return operatorFont; }
00148     QFont getSymbolFont()     const { return symbolFont; }
00149 
00150     void setMathFont( QFont f )     { defaultFont = f; }
00151     void setBracketFont( QFont f )  { bracketFont = f; }
00152     void setDefaultFont( QFont f )  { defaultFont = f; }
00153     void setNameFont( QFont f )     { nameFont = f; }
00154     void setNumberFont( QFont f )   { numberFont = f; }
00155     void setOperatorFont( QFont f ) { operatorFont = f; }
00156 
00157     //const QStringList& requestedFonts() const;
00158     //void setRequestedFonts( const QStringList& list );
00159 
00160     double getReductionFactor( TextStyle tstyle ) const;
00161 
00162     luPt getBaseSize() const;
00163     int baseSize() const { return m_baseSize; }
00164     void setBaseSize( int pointSize );
00165     void setSizeFactor( double factor );
00166 
00167     TextStyle getBaseTextStyle() const { return m_baseTextStyle; }
00168     bool isScript( TextStyle tstyle ) const { return ( tstyle == scriptStyle ) ||
00169                                                      ( tstyle == scriptScriptStyle ); }
00170 
00174     luPixel getSpace( TextStyle tstyle, SpaceWidth space, double factor ) const;
00175     luPixel getThinSpace( TextStyle tstyle, double factor ) const;
00176     luPixel getMediumSpace( TextStyle tstyle, double factor ) const;
00177     luPixel getThickSpace( TextStyle tstyle, double factor ) const;
00178     luPixel getQuadSpace( TextStyle tstyle, double factor ) const;
00179 
00180     luPixel axisHeight( TextStyle tstyle, double factor ) const;
00181 
00185     luPt getAdjustedSize( TextStyle tstyle, double factor ) const;
00186 
00190     luPixel getLineWidth( double factor ) const;
00191 
00192     luPixel getEmptyRectWidth( double factor ) const;
00193     luPixel getEmptyRectHeight( double factor ) const;
00194 
00195     Alignment getMatrixAlignment() const { return center; }
00196 
00197     bool getCenterSymbol() const { return centerSymbol; }
00198 
00205     TextStyle convertTextStyleFraction( TextStyle tstyle ) const;
00206 
00213     TextStyle convertTextStyleIndex( TextStyle tstyle ) const;
00214 
00224     IndexStyle convertIndexStyleUpper( IndexStyle istyle ) const {
00225     return istyle; }
00226 
00227 
00237     IndexStyle convertIndexStyleLower( IndexStyle /*istyle*/ ) const {
00238     return cramped; }
00239 
00240 private:
00241 
00242     void setup();
00243 
00244     struct TextStyleValues {
00245 
00246         void setup( double reduction ) { reductionFactor = reduction; }
00247 
00248         luPt thinSpace( luPt quad ) const   { return static_cast<luPt>( reductionFactor*static_cast<double>( quad )/6. ); }
00249         luPt mediumSpace( luPt quad ) const { return static_cast<luPt>( reductionFactor*static_cast<double>( quad )*2./9. ); }
00250         luPt thickSpace( luPt quad ) const  { return static_cast<luPt>( reductionFactor*static_cast<double>( quad )*5./18. ); }
00251         luPt quadSpace( luPt quad ) const   { return quad; }
00252 
00253         luPixel axisHeight( luPixel height ) const { return static_cast<luPixel>( reductionFactor*height ); }
00254         double reductionFactor;
00255     };
00256 
00257     TextStyleValues textStyleValues[ 4 ];
00258 
00259     QFont mathFont;
00260     QFont bracketFont;
00261     QFont defaultFont;
00262     QFont nameFont;
00263     QFont numberFont;
00264     QFont operatorFont;
00265     QFont symbolFont;
00266 
00267     //QStringList m_requestedFonts;
00268 
00269     QColor defaultColor;
00270     QColor numberColor;
00271     QColor operatorColor;
00272     QColor errorColor;
00273     QColor emptyColor;
00274     QColor helpColor;
00275 
00280     bool linearMovement;
00281 
00285     int m_baseSize;
00286 
00291     double m_sizeFactor;
00292 
00296     TextStyle m_baseTextStyle;
00297 
00301     pt lineWidth;
00302 
00306     luPt quad;
00307 
00311     luPixel m_axisHeight;
00312 
00317     bool centerSymbol;
00318 
00322     bool m_syntaxHighlighting;
00323 
00327     bool m_edit;
00328 
00332     //SymbolTable table;
00333 
00334     FontStyle* m_fontStyle;
00335     QString m_fontStyleName;
00336 };
00337 
00338 // Section 3.3.4.2, default values
00339 const double scriptsizemultiplier   = 0.71;
00340 const double scriptminsize          = 8;
00341 const double veryverythinmathspace  = 0.0555556;
00342 const double verythinmathspace      = 0.111111;
00343 const double thinmathspace          = 0.166667;
00344 const double mediummathspace        = 0.222222;
00345 const double thickmathspace         = 0.277778;
00346 const double verythickmathspace     = 0.333333;
00347 const double veryverythickmathspace = 0.388889;
00348 
00349 class StyleAttributes {
00350  public:
00351     double sizeFactor() const ;
00352     bool customMathVariant() const ;
00353     CharStyle charStyle() const ;
00354     CharFamily charFamily() const ;
00355     QColor color() const ;
00356     QColor background() const ;
00357     QFont font() const ;
00358     bool fontWeight() const ;
00359     bool customFontWeight() const ;
00360     bool fontStyle() const ;
00361     bool customFontStyle() const ;
00362     bool customFont() const ;
00363 
00364     int scriptLevel() const ;
00365     double scriptSizeMultiplier() const ;
00366     double scriptMinSize() const ;
00367     double veryVeryThinMathSpace() const ;
00368     double veryThinMathSpace() const ;
00369     double thinMathSpace() const ;
00370     double mediumMathSpace() const ;
00371     double thickMathSpace() const ;
00372     double veryThickMathSpace() const ;
00373     double veryVeryThickMathSpace() const ;
00374     bool displayStyle() const ;
00375     bool customDisplayStyle() const ;
00376 
00377     double getSpace( SizeType type, double length ) const ;
00378 
00379     void setSizeFactor( double s ) { m_size.push( s ); }
00380     void setCustomMathVariant( bool cmv ) { m_customMathVariant.push( cmv ); }
00381     void setCharStyle( CharStyle cs ) { m_charStyle.push( cs ); }
00382     void setCharFamily( CharFamily cf ) { m_charFamily.push( cf ); }
00383     void setColor( const QColor& c ) { m_color.push( c ); }
00384     void setBackground( const QColor& bg ) { m_background.push( bg ); }
00385     void setFont( const QFont& f ) { m_font.push( f ); }
00386     void setCustomFont( bool cf ) { m_customFontFamily.push ( cf ); }
00387     void setCustomFontWeight( bool cfw ) { m_customFontWeight.push( cfw ); }
00388     void setFontWeight( bool fw ) { m_fontWeight.push( fw ); }
00389     void setCustomFontStyle( bool cfs ) { m_customFontStyle.push( cfs ); }
00390     void setFontStyle( bool fs ) { m_fontStyle.push( fs ); }
00391 
00392     void setScriptLevel( int s ) { m_scriptLevel.push( s ); }
00393     void setScriptSizeMultiplier( double s ) { m_scriptSizeMultiplier.push( s ); }
00394     void setScriptMinSize( double s ) { m_scriptMinSize.push( s ); }
00395     void setVeryVeryThinMathSpace( double s ) { m_veryVeryThinMathSpace.push( s ); }
00396     void setVeryThinMathSpace( double s ) { m_veryThinMathSpace.push( s ); }
00397     void setThinMathSpace( double s ) { m_thinMathSpace.push( s ); }
00398     void setMediumMathSpace( double s ) { m_mediumMathSpace.push( s ); }
00399     void setThickMathSpace( double s ) { m_thickMathSpace.push( s ); }
00400     void setVeryThickMathSpace( double s ) { m_veryThickMathSpace.push( s ); }
00401     void setVeryVeryThickMathSpace( double s ) { m_veryVeryThickMathSpace.push( s ); }
00402     void setDisplayStyle( bool ds ) { m_displayStyle.push( ds ); }
00403     void setCustomDisplayStyle( bool cds ) { m_customDisplayStyle.push( cds ); }
00404 
00405     void reset();
00406     void resetSize();
00407     void resetCharStyle();
00408     void resetCharFamily();
00409     void resetColor();
00410     void resetBackground();
00411     void resetFontFamily();
00412     void resetFontWeight();
00413     void resetFontStyle();
00414 
00415     void resetScriptLevel();
00416     void resetScriptSizeMultiplier();
00417     void resetScriptMinSize();
00418     void resetVeryVeryThinMathSpace();
00419     void resetVeryThinMathSpace();
00420     void resetThinMathSpace();
00421     void resetMediumMathSpace();
00422     void resetThickMathSpace();
00423     void resetVeryThickMathSpace();
00424     void resetVeryVeryThickMathSpace();
00425     void resetDisplayStyle();
00426 
00427  private:
00428     // Size of the font in points (mathsize / fontsize)
00429     QValueStack<double> m_size;
00430 
00431     // Whether a custom mathvariant attribute is in use
00432     QValueStack<bool> m_customMathVariant;
00433 
00434     // Font style (mathvariant, fontweight, fontstyle)
00435     QValueStack<CharStyle> m_charStyle;
00436 
00437     // Font family (mathvariant)
00438     QValueStack<CharFamily> m_charFamily;
00439 
00440     // Foreground color (mathcolor, color)
00441     QValueStack<QColor> m_color;
00442 
00443     // Background color (mathbackground)
00444     QValueStack<QColor> m_background;
00445 
00446     // Font family (fontfamily)
00447     QValueStack<QFont> m_font;
00448 
00449     // Whether a custom fontfamily attribute is in use (instead of CharFamily)
00450     QValueStack<bool> m_customFontFamily;
00451 
00452     // Font Weight (fontweight)
00453     QValueStack<bool> m_fontWeight;
00454 
00455     // Whether a custom fontweight attribute is in use
00456     QValueStack<bool> m_customFontWeight;
00457 
00458     // Font Style (fontstyle)
00459     QValueStack<bool> m_fontStyle;
00460 
00461     // Whether a custom fontstyle attribute is in use
00462     QValueStack<bool> m_customFontStyle;
00463 
00464     QValueStack<int> m_scriptLevel;
00465     QValueStack<double> m_scriptSizeMultiplier;
00466     QValueStack<double> m_scriptMinSize;
00467     QValueStack<double> m_veryVeryThinMathSpace;
00468     QValueStack<double> m_veryThinMathSpace;
00469     QValueStack<double> m_thinMathSpace;
00470     QValueStack<double> m_mediumMathSpace;
00471     QValueStack<double> m_thickMathSpace;
00472     QValueStack<double> m_veryThickMathSpace;
00473     QValueStack<double> m_veryVeryThickMathSpace;
00474     QValueStack<bool> m_displayStyle;
00475     QValueStack<bool> m_customDisplayStyle;
00476 };
00477 
00478 KFORMULA_NAMESPACE_END
00479 
00480 #endif // CONTEXTSTYLE_H
KDE Home | KDE Accessibility Home | Description of Access Keys