Salome HOME
Copyright update 2021
[modules/gui.git] / src / Style / Style_Model.cxx
1 // Copyright (C) 2007-2021  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.cxx
21 // Author : Vadim SANDLER, Open CASCADE S.A.S (vadim.sandler@opencascade.com)
22 //
23 #include "Style_Model.h"
24 #include "Style_Salome.h"
25
26 #include <QtxResourceMgr.h>
27
28 #include <QApplication>
29 #include <QColor>
30 #include <QFont>
31 #include <QPalette>
32
33 /*!
34   \brief Mix two colors to get color with averaged red, green, blue and alpha-channel values
35   \internal
36   \param c1 first color
37   \param c2 second color
38   \return averaged color
39 */
40 static QColor mixColors( const QColor& c1, const QColor& c2 )
41 {
42   return QColor( (c1.red()   + c2.red() )   / 2,
43                  (c1.green() + c2.green() ) / 2,
44                  (c1.blue()  + c2.blue() )  / 2,
45                  (c1.alpha() + c2.alpha() ) / 2 );
46 }
47
48 /*!
49   \class Style_Model
50   \brief SALOME style model
51
52   Style model class stores properties of the SALOME style, like palette colors,
53   widget roundings etc. It allows reading these properties from the resource file
54   and write them back to resource file.
55
56   SALOME_Style class provides an access to the global style model (which is applied
57   to the application). To get access to the global SALOME style model, use static
58   Style_Model::model() function.
59
60   \sa Style_Salome class
61 */
62
63 /*!
64   \brief Application style data
65   \internal
66 */
67 Style_Model::AppData* Style_Model::myAppData = 0;
68
69 /*!
70   \brief Constructor
71
72   Create new SALOME style model with default properties.
73 */
74 Style_Model::Style_Model()
75   : myResourceMgr( 0 )
76 {
77   initDefaults(); // init from default values
78 }
79
80 /*!
81   \brief Destructor
82 */
83 Style_Model::~Style_Model()
84 {
85 }
86
87 /*!
88   \brief Initialize model from the current application style
89   
90   This function is useful when it is necessary to set/remove SALOME style
91   dynamically. Function fromApplication() saves current application properties
92   (style, palette, font) which can be later restored with the restore() function.
93
94   The simplest way it can be done is using static functions of Style_Salome class:
95   Style_Salome::apply(), Style_Salome::restore()
96
97   \param reset if \c true model is also initializes preoperties from the application
98   \sa restore(), fromResources()
99   \sa Style_Salome class
100 */
101 void Style_Model::fromApplication( bool reset )
102 {
103   initDefaults();
104
105   if ( !QApplication::instance() )  // application object is not created yet
106     return;
107
108   if ( !myAppData ) // if not yes initialized from the application init myAppData
109     myAppData = new AppData;
110
111   // store original application's style, palette, etc
112   if ( !Style_Salome::isActive() ) {
113     myAppData->myStyle   = QApplication::style();
114     myAppData->myPalette = QApplication::palette();
115     myAppData->myFont    = QApplication::font();
116   }
117
118   // initialize style properties from the application
119
120   if ( !reset ) return;
121
122   // font
123   myFont = myAppData->myFont;
124   // colors
125   for ( int i = (int)QPalette::Active; i <= (int)QPalette::Inactive; i++ ) {
126     for ( int j = (int)Style_Model::WindowText; j < (int)Style_Model::NColorRoles; j++ ) {
127       myColors[ (QPalette::ColorGroup)i ][ (Style_Model::ColorRole)j ] =
128         myAppData->myPalette.color( (QPalette::ColorGroup)i, (QPalette::ColorRole)j );
129     }
130   }
131
132   QColor dark = myAppData->myPalette.color( QPalette::Dark );
133   setColor( BorderTop,       dark.lighter() );
134   setColor( BorderBottom,    dark.darker() );
135   setColor( TabBorderTop,    dark.lighter().lighter() );
136   setColor( TabBorderBottom, dark.darker().darker() );
137   setColor( FieldLight,      myAppData->myPalette.color( QPalette::Light ) );
138   setColor( FieldDark,       myAppData->myPalette.color( QPalette::Mid ).light( 125 ) );
139   setColor( ProgressBar,     myAppData->myPalette.color( QPalette::Highlight ) );
140   setColor( Pointer,         myAppData->myPalette.color( QPalette::WindowText ) );
141   setColor( Checked,         myAppData->myPalette.color( QPalette::Base ) );
142   setColor( GridLine,        myAppData->myPalette.color( QPalette::Mid ) );
143   setColor( Header,          myAppData->myPalette.color( QPalette::Button ) );
144   setColor( Slider,          myAppData->myPalette.color( QPalette::Button ) );
145   setColor( HighlightWidget, myAppData->myPalette.color( QPalette::Button ) );
146   setColor( HighlightBorder, myAppData->myPalette.color( QPalette::Button ) );
147   setColor( Lines,           myAppData->myPalette.color( QPalette::Mid ) );
148 }
149
150 /*!
151   \brief Initialize model from the resources
152
153   This function can be used to retrieve SALOME style properties from the resource file(s).
154   Note, that paremeters \a resMgr and \a resSection are stored by the model to be used
155   later with save() method.
156
157   \param resMgr resources manager
158   \param resSection resources section name; if empty (default), "Theme" section is used instead
159   \sa fromApplication(), save(), update()
160 */
161 void Style_Model::fromResources( QtxResourceMgr* resMgr, const QString& resSection )
162 {
163   // init from application
164   fromApplication( false );
165
166   myResourceMgr     = resMgr;
167   myResourceSection = resSection;
168
169   // init from resource manager
170   if ( !resourceMgr() )
171     return;
172
173   QString section = resourceSection();
174
175   // colors
176   // Button
177   readColorValue( Button, "button" );
178   // Window text
179   readColorValue( WindowText, "window-text" );
180   // Light
181   readColorValue( Light, "light" );
182   // Dark
183   readColorValue( Dark, "dark" );
184   // Mid
185   readColorValue( Mid, "mid" );
186   // Text
187   readColorValue( Text, "text" );
188   // BrightText
189   readColorValue( BrightText, "bright-text" );
190   // ButtonText
191   readColorValue( ButtonText, "button-text" );
192   // Base
193   readColorValue( Base, "base" );
194   // Window
195   readColorValue( Window, "window" );
196   // AlternateBase
197   readColorValue( AlternateBase, "alternate-base" );
198   // Midlight
199   readColorValue( Midlight, "midlight" );
200   // Shadow
201   readColorValue( Shadow, "shadow" );
202   // Highlight
203   readColorValue( Highlight, "highlight" );
204   // HighlightedText
205   readColorValue( HighlightedText, "highlight-text" );
206   // Link
207   readColorValue( Link, "link" );
208   // LinkVisited
209   readColorValue( LinkVisited, "link-visited" );
210   // ToolTipBase
211   readColorValue( ToolTipBase, "tooltip-base" );
212   // ToolTipText
213   readColorValue( ToolTipText, "tooltip-text" );
214   // BorderTop
215   readColorValue( BorderTop, "border-top" );
216   // BorderBottom
217   readColorValue( BorderBottom, "border-bottom" );
218   // TabBorderTop
219   readColorValue( TabBorderTop, "tab-border-top" );
220   // TabBorderBottom
221   readColorValue( TabBorderBottom, "tab-border-bottom" );
222   // FieldLight
223   readColorValue( FieldLight, "field-light" );
224   // FieldDark
225   readColorValue( FieldDark, "field-dark" );
226   // ProgressBar
227   readColorValue( ProgressBar, "progress-bar" );
228   // Pointer
229   readColorValue( Pointer, "pointer" );
230   // Checked
231   readColorValue( Checked, "checked" );
232   // GridLine
233   readColorValue( GridLine, "grid-line" );
234   // Header
235   readColorValue( Header, "header" );
236   // Slider
237   readColorValue( Slider, "slider" );
238   // HighlightWidget
239   readColorValue( HighlightWidget, "highlight-widget" );
240   // HighlightBorder
241   readColorValue( HighlightBorder, "highlight-border" );
242   // Lines
243   readColorValue( Lines, "lines" );
244   // auto-palette flag (internal)
245   if ( resourceMgr()->hasValue( section, "auto-palette" ) ) {
246     setAutoPalette( resourceMgr()->booleanValue( section, "auto-palette" ) );
247   }
248   // lines type
249   if ( resourceMgr()->hasValue( section, "lines-type" ) ) {
250     int ltype = resourceMgr()->integerValue( section, "lines-type" );
251     if ( ltype >= NoLines && ltype <= Inclined )
252       setLinesType( (LineType)ltype );
253   }
254   // lines transparency
255   if ( resourceMgr()->hasValue( section, "lines-transparency" ) ) {
256     int ltransp = resourceMgr()->integerValue( section, "lines-transparency" );
257     if ( ltransp >= 0 && ltransp <= 100 )
258       setLinesTransparency( ltransp );
259   }
260   // application font
261   if ( resourceMgr()->hasValue( section, "application-font" ) ) {
262     setApplicationFont( resourceMgr()->fontValue( section, "application-font" ) );
263   }
264   // widgets rounding
265   if ( resourceMgr()->hasValue( section, "button-rad" ) ) {
266     setWidgetRounding( ButtonRadius, resourceMgr()->doubleValue( section, "button-rad" ) );
267   }
268   if ( resourceMgr()->hasValue( section, "edit-rad" ) ) {
269     setWidgetRounding( EditRadius, resourceMgr()->doubleValue( section, "edit-rad" ) );
270   }
271   if ( resourceMgr()->hasValue( section, "frame-rad" ) ) {
272     setWidgetRounding( FrameRadius, resourceMgr()->doubleValue( section, "frame-rad" ) );
273   }
274   if ( resourceMgr()->hasValue( section, "slider-rad" ) ) {
275     setWidgetRounding( SliderRadius, resourceMgr()->doubleValue( section, "slider-rad" ) );
276   }
277   // widget effect
278   if ( resourceMgr()->hasValue( section, "widget-effect" ) ) {
279     int effect = resourceMgr()->integerValue( section, "widget-effect" );
280     if ( effect >= NoEffect && effect <= AutoRaiseEffect )
281       setWidgetEffect( (WidgetEffect)effect );
282   }
283   else if ( resourceMgr()->hasValue( section, "is-highlight-widget" ) ||
284             resourceMgr()->hasValue( section, "is-raising-widget" ) ) {
285     bool highlight = resourceMgr()->booleanValue( section, "is-highlight-widget", false );
286     bool autoraise = resourceMgr()->booleanValue( section, "is-highlight-widget", false );
287     if ( highlight )
288       setWidgetEffect( HighlightEffect );
289     else if ( autoraise )
290       setWidgetEffect( AutoRaiseEffect );
291   }
292   if ( resourceMgr()->hasValue( section, "all-antialized" ) ) {
293     setAntialiasing( resourceMgr()->booleanValue( section, "all-antialized" ) );
294   }
295   // handles
296   if ( resourceMgr()->hasValue( section, "hor-hadle-delta" ) ) {
297     setHandleDelta( Qt::Horizontal, resourceMgr()->integerValue( section, "hor-hadle-delta" ) );
298   }
299   if ( resourceMgr()->hasValue( section, "ver-hadle-delta" ) ) {
300     setHandleDelta( Qt::Vertical, resourceMgr()->integerValue( section, "vsr-hadle-delta" ) );
301   }
302   if ( resourceMgr()->hasValue( section, "slider-size" ) ) {
303     setSliderSize( resourceMgr()->integerValue( section, "slider-size" ) );
304   }
305   else if ( resourceMgr()->hasValue( section, "slider-increase" ) ) {
306     setSliderSize( resourceMgr()->integerValue( section, "slider-increase" ) );
307   }
308   if ( resourceMgr()->hasValue( section, "split-handle-len" ) ) {
309     setSplitHandleLength( resourceMgr()->integerValue( section, "split-handle-len" ) );
310   }
311 }
312
313 /*!
314   \brief Save SALOME stype properties to the resource file.
315   
316   If paremeters \a resMgr and \a resSection are not specified, default ones
317   (those passed to the fromResources() function) are used instead.
318
319   \param resMgr resources manager
320   \param resSection resources section name
321   \sa fromResources(), update()
322 */
323 void Style_Model::save( QtxResourceMgr* resMgr, const QString& resSection )
324 {
325   if ( !resMgr )
326     resMgr = resourceMgr();
327   if ( !resMgr )
328     return;
329
330   QString section = resSection.isEmpty() ? resourceSection() : resSection;
331
332   // colors
333   // Button
334   writeColorValue( Button, "button", resMgr, section );
335   // Window text
336   writeColorValue( WindowText, "window-text", resMgr, section );
337   // Light
338   writeColorValue( Light, "light", resMgr, section );
339   // Dark
340   writeColorValue( Dark, "dark", resMgr, section );
341   // Mid
342   writeColorValue( Mid, "mid", resMgr, section );
343   // Text
344   writeColorValue( Text, "text", resMgr, section );
345   // BrightText
346   writeColorValue( BrightText, "bright-text", resMgr, section );
347   // ButtonText
348   writeColorValue( ButtonText, "button-text", resMgr, section );
349   // Base
350   writeColorValue( Base, "base", resMgr, section );
351   // Window
352   writeColorValue( Window, "window", resMgr, section );
353   // AlternateBase
354   writeColorValue( AlternateBase, "alternate-base", resMgr, section );
355   // Midlight
356   writeColorValue( Midlight, "midlight", resMgr, section );
357   // Shadow
358   writeColorValue( Shadow, "shadow", resMgr, section );
359   // Highlight
360   writeColorValue( Highlight, "highlight", resMgr, section );
361   // HighlightedText
362   writeColorValue( HighlightedText, "highlight-text", resMgr, section );
363   // Link
364   writeColorValue( Link, "link", resMgr, section );
365   // LinkVisited
366   writeColorValue( LinkVisited, "link-visited", resMgr, section );
367   // ToolTipBase
368   writeColorValue( ToolTipBase, "tooltip-base", resMgr, section );
369   // ToolTipText
370   writeColorValue( ToolTipText, "tooltip-text", resMgr, section );
371   // BorderTop
372   writeColorValue( BorderTop, "border-top", resMgr, section );
373   // BorderBottom
374   writeColorValue( BorderBottom, "border-bottom", resMgr, section );
375   // TabBorderTop
376   writeColorValue( TabBorderTop, "tab-border-top", resMgr, section );
377   // TabBorderBottom
378   writeColorValue( TabBorderBottom, "tab-border-bottom", resMgr, section );
379   // FieldLight
380   writeColorValue( FieldLight, "field-light", resMgr, section );
381   // FieldDark
382   writeColorValue( FieldDark, "field-dark", resMgr, section );
383   // ProgressBar
384   writeColorValue( ProgressBar, "progress-bar", resMgr, section );
385   // Pointer
386   writeColorValue( Pointer, "pointer", resMgr, section );
387   // Checked
388   writeColorValue( Checked, "checked", resMgr, section );
389   // GridLine
390   writeColorValue( GridLine, "grid-line", resMgr, section );
391   // Header
392   writeColorValue( Header, "header", resMgr, section );
393   // Slider
394   writeColorValue( Slider, "slider", resMgr, section );
395   // HighlightWidget
396   writeColorValue( HighlightWidget, "highlight-widget", resMgr, section );
397   // HighlightBorder
398   writeColorValue( HighlightBorder, "highlight-border", resMgr, section );
399   // Lines
400   writeColorValue( Lines, "lines", resMgr, section );
401   // auto-palette flag (internal)
402   resMgr->setValue( section, "auto-palette", isAutoPalette() );
403
404   // lines type
405   resMgr->setValue( section, "lines-type", (int)linesType() );
406   // lines transparency
407   resMgr->setValue( section, "lines-transparency", linesTransparency() );
408   // application font
409   resMgr->setValue( section, "application-font", applicationFont() );
410   // widgets rounding
411   resMgr->setValue( section, "button-rad", widgetRounding( ButtonRadius ) );
412   resMgr->setValue( section, "edit-rad",   widgetRounding( EditRadius ) );
413   resMgr->setValue( section, "frame-rad",  widgetRounding( FrameRadius ) );
414   resMgr->setValue( section, "slider-rad", widgetRounding( SliderRadius ) );
415   resMgr->setValue( section, "all-antialized", antialiasing() );
416   // widget effect
417   resMgr->setValue( section, "widget-effect", (int)widgetEffect() );
418   // handles
419   resMgr->setValue( section, "hor-hadle-delta", handleDelta( Qt::Horizontal ) );
420   resMgr->setValue( section, "vsr-hadle-delta", handleDelta( Qt::Vertical ) );
421   resMgr->setValue( section, "slider-size", sliderSize() );
422   resMgr->setValue( section, "split-handle-len", splitHandleLength() );
423 }
424
425 /*!
426   \brief Reload SALOME style properties from the resources file(s).
427   \sa fromResources(), save()
428 */
429 void Style_Model::update()
430 {
431   fromResources( resourceMgr(), resourceSection() );
432 }
433
434 /*!
435   \brief Restore original style, palette and font to the application
436
437   This function should be used in conjunction with fromApplication() method.
438   Sets initial style, color palette and font to the application.
439   If SALOME style model has not been initialized from the application,
440   this function does nothing.
441
442   \sa fromApplication()
443 */
444 void Style_Model::restore()
445 {
446   if ( !QApplication::instance() ) // application object is not created yet
447     return;
448   if ( !myAppData ) // not initialized from the application yet
449     return;
450
451   QApplication::setStyle( myAppData->myStyle );
452   QApplication::setPalette( myAppData->myPalette );
453   QApplication::setFont( myAppData->myFont );
454 }
455
456 /*!
457   \brief Get resource manager used by this SALOME style model.
458
459   \return pointer to the resource manager passed previously to the fromResources() method
460   \sa initFromResources(), resourceSection()
461 */
462 QtxResourceMgr* Style_Model::resourceMgr() const
463 {
464   return myResourceMgr;
465 }
466
467 /*!
468   \brief Get resources section name
469
470   If section name is empty, default "Theme" is returned
471
472   \return resource section name passed previously to the fromResources() method
473   \sa initFromResources(), resourceMgr()
474 */
475 QString Style_Model::resourceSection() const
476 {
477   return !myResourceSection.isEmpty() ? myResourceSection : "Theme";
478 }
479
480 /*!
481   \brief Get palette color value
482   \param role color role
483   \param cg color group
484   \return a color which should be used to draw the corresponding part of the application
485   \sa setColor()
486 */
487 QColor Style_Model::color( ColorRole role, QPalette::ColorGroup cg ) const
488 {
489   QColor c = myColors[ cg ][ role ];
490   if ( !c.isValid() ) c = myColors[ QPalette::Active ][ role ];
491   return c;
492 }
493
494 /*!
495   \brief Set palette color value
496
497   If \a inactive and/or \a disabled colors are not specified, they are automatically
498   calculated from \a active color.
499
500   \param role color role
501   \param active a color to be used with active color group (QPalette::Active)
502   \param inactive a color to be used with inactive color group (QPalette::Inactive)
503   \param disabled a color to be used with disabled color group (QPalette::Disabled)
504   \sa color()
505 */
506 void Style_Model::setColor( Style_Model::ColorRole role, const QColor& active,
507                             const QColor& inactive, const QColor& disabled )
508 {
509   QColor ac = active, ic = inactive, dc = disabled;
510
511   if ( !ic.isValid() ) {
512     ic = ac;
513   }
514   if ( !dc.isValid() ) {
515     switch ( role ) {
516     case WindowText:
517     case Text:
518     case ButtonText:
519       dc = color( Button ).darker();
520       break;
521     case Base:
522       dc = color( Button );
523       break;
524     case AlternateBase:
525       dc = mixColors( color( Base,  QPalette::Inactive ), color( Button, QPalette::Inactive ) );
526       break;
527     case Midlight:
528       dc = mixColors( color( Light, QPalette::Inactive ), color( Button, QPalette::Inactive ) );
529       break;
530     default:
531       dc = ac;
532       break;
533     }
534   }
535
536   setColor( role, QPalette::Active,   ac );
537   setColor( role, QPalette::Inactive, ic );
538   setColor( role, QPalette::Disabled, dc );
539 }
540
541 /*!
542   \brief Set palette color value
543
544   If \a inactive and/or \a disabled colors are not specified, they are automatically
545   calculated from \a active color.
546
547   \param role color role
548   \param cg color group
549   \param c color which should be used to draw the corresponding part of the application
550   \sa color()
551 */
552 void Style_Model::setColor( Style_Model::ColorRole role, QPalette::ColorGroup cg, const QColor& c )
553 {
554   myColors[ cg ][ role ] = c;
555 }
556
557 /*!
558   \brief Returns 'auto-calculating color values' flag
559   \return 'auto-calculating color values' flag
560   \internal
561   \sa setAutoPalette()
562 */
563 bool Style_Model::isAutoPalette() const
564 {
565   return myAutoPalette;
566 }
567
568 /*!
569   \brief Set/clear 'auto-calculating color values' flag
570   \param on new value of 'auto-calculating color values' flag
571   \internal
572   \sa isAutoPalette()
573 */
574 void Style_Model::setAutoPalette( bool on )
575 {
576   myAutoPalette = on;
577 }
578
579 /*!
580   \brief Get lines type
581   \return current lines type
582   \sa setLinesType(), linesTransparency()
583 */
584 Style_Model::LineType Style_Model::linesType() const
585 {
586   return myLinesType;
587 }
588
589 /*!
590   \brief Set lines type
591   \param lt new lines type
592   \sa linesType(), linesTransparency()
593 */
594 void Style_Model::setLinesType( LineType lt )
595 {
596   myLinesType = lt;
597 }
598
599 /*!
600   \brief Get lines transparency value
601   \return current lines transparency
602   \sa setLinesTransparency(), linesType()
603 */
604 int Style_Model::linesTransparency() const
605 {
606   return myLinesTransparency;
607 }
608
609 /*!
610   \brief Set lines transparency value
611   \param transparency new lines transparency
612   \sa linesTransparency(), linesType()
613 */
614 void Style_Model::setLinesTransparency( int transparency )
615 {
616   myLinesTransparency = transparency;
617 }
618
619 /*!
620   \brief Get application font
621   \return current application font
622   \sa setApplicationFont()
623 */
624 QFont Style_Model::applicationFont() const
625 {
626   return myFont;
627 }
628
629 /*!
630   \brief Set application font
631   \param font new application font
632   \sa applicationFont()
633 */
634 void Style_Model::setApplicationFont( const QFont& font )
635 {
636   myFont = font;
637 }
638
639 /*!
640   \brief Get widget corners rounding radius value
641   \param wr widget type
642   \return current widget corners rounding
643   \sa setWidgetRounding(), antialiasing()
644 */
645 double Style_Model::widgetRounding( Style_Model::WidgetRounding wr ) const
646 {
647   return myWidgetRounding[ wr ];
648 }
649
650 /*!
651   \brief Set widget corners rounding radius value
652   \param wr widget type
653   \param value new widget corners rounding
654   \sa widgetRounding(), antialiasing()
655 */
656 void Style_Model::setWidgetRounding( WidgetRounding wr, double value )
657 {
658   myWidgetRounding[ wr ] = value;
659 }
660
661 /*!
662   \brief Get anti-aliasing flag value
663   \return \c true if widgets borders should be antialiased
664   \sa setAntialiasing(), widgetRounding()
665 */
666 bool Style_Model::antialiasing() const
667 {
668   return myAntiAliasing;
669 }
670
671 /*!
672   \brief Set anti-aliasing flag value
673   \param value if \c true, widgets borders should be antialiased
674   \sa antialiasing(), widgetRounding()
675 */
676 void Style_Model::setAntialiasing( bool value )
677 {
678   myAntiAliasing = value;
679 }
680
681 /*!
682   \brief Get widget effect
683   \return current widget effect
684   \sa setWidgetEffect()
685 */
686 Style_Model::WidgetEffect Style_Model::widgetEffect() const
687 {
688   return myWidgetEffect;
689 }
690
691 /*!
692   \brief Set widget effect
693   \param we new widget effect
694   \sa widgetEffect()
695 */
696 void Style_Model::setWidgetEffect( WidgetEffect we )
697 {
698   myWidgetEffect = we;
699 }
700
701 /*!
702   \brief Get handle spacing value
703   \param o handle spacing direction
704   \return current handle spacing value
705   \sa setHandleDelta()
706 */
707 int Style_Model::handleDelta( Qt::Orientation o ) const
708 {
709   return myHandleDelta[ o ];
710 }
711
712 /*!
713   \brief Set handle spacing value
714   \param o handle spacing direction
715   \param value new handle spacing value
716   \sa handleDelta()
717 */
718 void Style_Model::setHandleDelta( Qt::Orientation o, int value )
719 {
720   myHandleDelta[ o ] = value;
721 }
722
723 /*!
724   \brief Get splitter handle length
725   \return current splitter handle length
726   \sa setSplitHandleLength()
727 */
728 int Style_Model::splitHandleLength() const
729 {
730   return mySplitHandleLength;
731 }
732
733 /*!
734   \brief Set splitted handle length
735   \param value new splitter handle length
736   \sa splitHandleLength()
737 */
738 void Style_Model::setSplitHandleLength( int value )
739 {
740   mySplitHandleLength = value; 
741 }
742
743 /*!
744   \brief Get slider handle extra size
745   \return current slider handle extra size
746   \sa setSliderSize()
747 */
748 int Style_Model::sliderSize() const
749 {
750   return mySliderSize;
751 }
752
753 /*!
754   \brief Set slider handle extra size
755   \param value new slider handle extra size
756   \sa sliderSize()
757 */
758 void Style_Model::setSliderSize( int value )
759 {
760   mySliderSize = value;
761 }
762
763 /*!
764   \brief Initialize model with the default values
765 */
766 void Style_Model::initDefaults()
767 {
768   // default application font
769   myFont.fromString( "Sans Serif,9,-1,5,50,0,0,0,0,0" );
770
771   // default palette colors
772   myAutoPalette = false;
773   QColor btn = QColor( "#e6e7e6" );
774   QColor fg  = QColor( "#000000" );
775   QColor bg  = QColor( "#ffffff" );
776   setColor( Button,          btn );                  // = (230, 231, 230)
777   setColor( WindowText,      fg );                   // = (  0,   0,   0)
778   setColor( Light,           bg );                   // = (255, 255, 255)
779   setColor( Dark,            btn.darker() );         // = (115, 115, 115) // btn.darker( 130 ) = (177, 178, 177)
780   setColor( Mid,             btn.darker( 150 ) );    // = (153, 154, 153)
781   setColor( Text,            fg );                   // = (  0,   0,   0)
782   setColor( BrightText,      bg );                   // = (255, 255, 255) // fg = (  0,  0,  0)
783   setColor( ButtonText,      fg );                   // = (  0,   0,   0)
784   setColor( Base,            bg );                   // = (255, 255, 255)
785   setColor( Window,          btn );                  // = (230, 231, 230)
786   setColor( AlternateBase,   mixColors( bg, btn ) ); // = (242, 243, 242)
787   setColor( Midlight,        mixColors( bg, btn ) ); // = (242, 243, 242)
788   setColor( Shadow,          fg );                   // = (  0,   0,   0)
789   setColor( Highlight,       "#000080" );            // = (  0,   0, 128) // (  33,  68, 156 )
790   setColor( HighlightedText, bg );                   // = (255, 255, 255)
791   setColor( Link,            "#0000ff" );            // = (  0,   0, 255)
792   setColor( LinkVisited,     "#ff00ff" );            // = (255,   0, 255)
793   setColor( ToolTipBase,     "#ffffdc" );            // = (255, 255, 220) // ( 230, 231, 230 )
794   setColor( ToolTipText,     fg );                   // = (  0,   0,   0)
795   setColor( BorderTop,       "#adadad" );            // = (173, 173, 173) // ( 255, 255, 255 )
796   setColor( BorderBottom,    "#393939" );            // = ( 57,  57,  57) // (  88,  89,  88 )
797   setColor( TabBorderTop,    "#ffffff" );            // = (255, 255, 255)
798   setColor( TabBorderBottom, "#0e0e0e" );            // = ( 14,  14,  14) // (  44,  44,  44 )
799   setColor( FieldLight,      "#ffffff" );            // = (255, 255, 255)
800   setColor( FieldDark,       "#c0c1c0" );            // = (192, 193, 192) // ( 240, 241, 240 )
801   setColor( ProgressBar,     "#000080" );            // = (  0,   0, 128) // (  33,  68, 156 )
802   setColor( Pointer,         "#000000" );            // = (  0,   0,   0)
803   setColor( Checked,         "#ffffff" );            // = (255, 255, 255)
804   setColor( GridLine,        "#999a99" );            // = (153, 154, 153) // ( 192, 192, 192 )
805   setColor( Header,          "#e6e7e6" );            // = (230, 231, 230)
806   setColor( Slider,          "#e6e7e6" );            // = (230, 231, 230)
807   setColor( HighlightWidget, "#e6e7e6" );            // = (230, 231, 230)
808   setColor( HighlightBorder, "#e6e7e6" );            // = (230, 231, 230)
809   setColor( Lines,           "#999a99" );            // = (153, 154, 153) // ( 192, 193, 192 )
810
811   // default values
812   myLinesType          = NoLines;
813   myWidgetEffect       = NoEffect;
814   myAntiAliasing       = false;
815   myLinesTransparency  = 0;
816   myWidgetRounding[ EditRadius   ] = 0.0;
817   myWidgetRounding[ ButtonRadius ] = 0.0;
818   myWidgetRounding[ FrameRadius  ] = 0.0;
819   myWidgetRounding[ SliderRadius ] = 0.0;
820   myHandleDelta[ Qt::Horizontal ]  = 3;
821   myHandleDelta[ Qt::Vertical ]    = 3;
822   mySplitHandleLength              = 20;
823   mySliderSize                     = 2;
824 }
825
826 /*!
827   \brief Read palette color values from resources manager
828   \param role color role
829   \param prefix palette color value resource name prefix
830   \sa writeColorValue()
831 */
832 void Style_Model::readColorValue( ColorRole role, const QString& prefix )
833 {
834   if ( !resourceMgr() ) return;
835
836   QString section = resourceSection();
837   QString active   = QString( "%1-color" ).arg( prefix );
838   QString inactive = QString( "%1-color-inactive" ).arg( prefix );
839   QString disabled = QString( "%1-color-disabled" ).arg( prefix );
840
841   if ( resourceMgr()->hasValue( section, active ) )
842     setColor( role, resourceMgr()->colorValue( section, active ) );
843   if ( resourceMgr()->hasValue( section, inactive ) )
844     setColor( role, QPalette::Inactive, resourceMgr()->colorValue( section, inactive ) );
845   if ( resourceMgr()->hasValue( section, disabled ) )
846     setColor( role, QPalette::Disabled, resourceMgr()->colorValue( section, disabled ) );
847 }
848
849 /*!
850   \brief Write palette color values to resources manager
851   \param role color role
852   \param prefix palette color value resource name prefix
853   \param resMgr resource manager
854   \param resSection resource section name
855   \sa readColorValue()
856 */
857 void Style_Model::writeColorValue( ColorRole role, const QString& prefix,
858                                    QtxResourceMgr* resMgr, const QString& resSection ) const
859 {
860   QString active   = QString( "%1-color" ).arg( prefix );
861   QString inactive = QString( "%1-color-inactive" ).arg( prefix );
862   QString disabled = QString( "%1-color-disabled" ).arg( prefix );
863
864   resMgr->setValue( resSection, active,   color( role, QPalette::Active ) );
865   resMgr->setValue( resSection, inactive, color( role, QPalette::Inactive ) );
866   resMgr->setValue( resSection, disabled, color( role, QPalette::Disabled ) );
867 }