]> SALOME platform Git repositories - modules/gui.git/blob - src/Style/Style_Model.h
Salome HOME
7d94ba7c16762c0e0248f2bc7a6fca936392d8f2
[modules/gui.git] / src / Style / Style_Model.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : Style_Model.h
23 // Author : Vadim SANDLER, Open CASCADE S.A.S (vadim.sandler@opencascade.com)
24 //
25 #ifndef STYLE_MODEL_H
26 #define STYLE_MODEL_H
27
28 #include "Style.h"
29
30 #include <QMap>
31 #include <QString>
32 #include <QPalette>
33 #include <QFont>
34
35 class QStyle;
36 class QtxResourceMgr;
37
38 //
39 // This class is private for Style package.
40 // Normally it should not be exported.
41 //
42 class STYLE_SALOME_EXPORT Style_Model
43 {
44 public:
45   //! Color palette instance enumeration
46   typedef enum {
47     WindowText      = QPalette::WindowText,      //!< A general foreground color
48     Button          = QPalette::Button,          //!< The general button background color
49     Light           = QPalette::Light,           //!< Usually lighter than Button color
50     Midlight        = QPalette::Midlight,        //!< Usually between Button and Light
51     Dark            = QPalette::Dark,            //!< Usually darker than Button
52     Mid             = QPalette::Mid,             //!< Usualliy between Button and Dark
53     Text            = QPalette::Text,            //!< The foreground color used with Base
54     BrightText      = QPalette::BrightText,      //!< A text color that is very different from WindowText, and contrasts well with e.g. Dark
55     ButtonText      = QPalette::ButtonText,      //!< A foreground color used with the Button color
56     Base            = QPalette::Base,            //!< Used mostly as the background color for text entry widgets
57     Window          = QPalette::Window,          //!< A general background color
58     Shadow          = QPalette::Shadow,          //!< Usually a very dark palette color
59     Highlight       = QPalette::Highlight,       //!< A color to indicate a selected item or the current item
60     HighlightedText = QPalette::HighlightedText, //!< A text color that contrasts with Highlight
61     Link            = QPalette::Link,            //!< A text color used for unvisited hyperlinks
62     LinkVisited     = QPalette::LinkVisited,     //!< A text color used for already visited hyperlinks
63     AlternateBase   = QPalette::AlternateBase,   //!< Used as the alternate background color in views with alternating row colors
64     NoRole          = QPalette::NoRole,          //!< No role; this special role is often used to indicate that a role has not been assigned
65     ToolTipBase     = QPalette::ToolTipBase,     //!< Used as the background color for QToolTip and QWhatsThis
66     ToolTipText     = QPalette::ToolTipText,     //!< Used as the foreground color for QToolTip and QWhatsThis
67     NColorRoles     = QPalette::NColorRoles,     //!< Used to indicate last standard palette color
68     BorderTop       = NColorRoles,               //!< Used to draw top-left borders of the widgets
69     BorderBottom,                                //!< Used to draw bottom-right borders of the widgets
70     TabBorderTop,                                //!< Used to draw top-left borders of the tab panels
71     TabBorderBottom,                             //!< Used to draw bottom-right borders of the tab panels
72     FieldLight,                                  //!< Light component of the text entry widgets
73     FieldDark,                                   //!< Dark component of the text entry widgets
74     Slider,                                      //!< Used to draw sliders
75     Lines,                                       //!< Used to draw lines throughout all the widgets
76     HighlightWidget,                             //!< Used to draw widget background when widget is hovered
77     HighlightBorder,                             //!< Used to draw widget borders when widget is hovered
78     Header,                                      //!< Used to draw header of tab panels
79     ProgressBar,                                 //!< Main progress bar color
80     Pointer,                                     //!< Used to draw different widgets indicators like spin box arrows etc
81     Checked,                                     //!< Check box indicator color
82     GridLine,                                    //!< Used to draw table widgets grid
83     LastColor                                    //!< Points to the last color; no specific meaning
84   } ColorRole;
85
86   //! Lines type
87   typedef enum {
88     NoLines,                     //!< Do not draw lines
89     Horizontal,                  //!< Draw horozontal lines
90     Inclined,                    //!< Draw inclined lines
91   } LineType;
92
93   //!< Widget roundings
94   typedef enum {
95     ButtonRadius,               //!< Buttons rounding
96     EditRadius,                 //!< Text entry widgets rounding
97     FrameRadius,                //!< Frames rounding
98     SliderRadius,               //!< Sliders rounding
99   } WidgetRounding;
100
101   //! Widget effect
102   typedef enum {
103     NoEffect,                   //!< Do not use widget effects
104     HighlightEffect,            //!< Highlight widget when it is hovered
105     AutoRaiseEffect             //!< Raise widget when it is hovered
106   } WidgetEffect;
107
108   Style_Model();
109   virtual ~Style_Model();
110
111   void                fromApplication( bool = false );
112   void                fromResources( QtxResourceMgr*, const QString& = QString() );
113
114   void                save( QtxResourceMgr* = 0, const QString& = QString() );
115   void                update();
116   void                restore();
117
118   QtxResourceMgr*     resourceMgr() const;
119   QString             resourceSection() const;
120
121
122   QColor              color( ColorRole, QPalette::ColorGroup = QPalette::Active ) const;
123   void                setColor( ColorRole, const QColor&, const QColor& = QColor(), const QColor& = QColor() );
124   void                setColor( ColorRole, QPalette::ColorGroup, const QColor& );
125
126   bool                isAutoPalette() const;
127   void                setAutoPalette( bool );
128
129   LineType            linesType() const;
130   void                setLinesType( LineType );
131
132   int                 linesTransparency() const;
133   void                setLinesTransparency( int );
134
135   QFont               applicationFont() const;
136   void                setApplicationFont( const QFont& );
137
138   double              widgetRounding( WidgetRounding ) const;
139   void                setWidgetRounding( WidgetRounding, double );
140
141   bool                antialiasing() const;
142   void                setAntialiasing( bool );
143   
144   WidgetEffect        widgetEffect() const;
145   void                setWidgetEffect( WidgetEffect );
146
147   int                 handleDelta( Qt::Orientation ) const;
148   void                setHandleDelta( Qt::Orientation, int );
149
150   int                 splitHandleLength() const;
151   void                setSplitHandleLength( int );
152
153   int                 sliderSize() const;
154   void                setSliderSize( int );
155
156 private:
157   void                initDefaults();
158   void                readColorValue( ColorRole, const QString& );
159   void                writeColorValue( ColorRole, const QString&, QtxResourceMgr*, const QString& ) const;
160
161 private:
162   typedef QMap<ColorRole, QColor>              ColorMap;
163   typedef QMap<QPalette::ColorGroup, ColorMap> ColorGroupMap;
164   typedef QMap<WidgetRounding, double>         RoundMap;
165   typedef QMap<Qt::Orientation, int>           DeltaMap;
166
167   QtxResourceMgr*     myResourceMgr;
168   QString             myResourceSection;
169
170   ColorGroupMap       myColors;
171   bool                myAutoPalette;
172   RoundMap            myWidgetRounding;
173   DeltaMap            myHandleDelta;
174   QFont               myFont;
175   LineType            myLinesType;
176   WidgetEffect        myWidgetEffect;
177   bool                myAntiAliasing;
178   int                 myLinesTransparency;
179   int                 mySplitHandleLength;
180   int                 mySliderSize;
181
182   struct AppData {
183     QStyle*  myStyle;
184     QPalette myPalette;
185     QFont    myFont;
186   };
187   
188   static AppData*     myAppData;
189 };
190
191 #endif // STYLE_MODEL_H