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