Salome HOME
43bb896c06c7d72a3117b03ba53dc466c14eab67
[modules/gui.git] / src / Style / Style_Model.cxx
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.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S (vadim.sandler@opencascade.com)
24 //
25 #include "Style_Model.h"
26
27 #include <QtxResourceMgr.h>
28
29 #include <QApplication>
30 #include <QColor>
31 #include <QFont>
32 #include <QPalette>
33
34 /*!
35   \brief Mix two colors to get color with averaged red, green, blue and alpha-channel values
36   \internal
37   \param c1 first color
38   \param c2 second color
39   \return averaged color
40 */
41 static QColor mixColors( const QColor& c1, const QColor& c2 )
42 {
43   return QColor( (c1.red()   + c2.red() )   / 2,
44                  (c1.green() + c2.green() ) / 2,
45                  (c1.blue()  + c2.blue() )  / 2,
46                  (c1.alpha() + c2.alpha() ) / 2 );
47 }
48
49 /*!
50   \class Style_Model
51   \brief SALOME style model
52
53   Style model class stores properties of the SALOME style, like palette colors,
54   widget roundings etc. It allows reading these properties from the resource file
55   and write them back to resource file.
56
57   SALOME_Style class provides an access to the global style model (which is applied
58   to the application). To get access to the global SALOME style model, use static
59   Style_Model::model() function.
60
61   \sa Style_Salome class
62 */
63
64 /*!
65   \brief Application style data
66   \internal
67 */
68 Style_Model::AppData* Style_Model::myAppData = 0;
69
70 /*!
71   \brief Constructor
72
73   Create new SALOME style model with default properties.
74 */
75 Style_Model::Style_Model()
76   : myResourceMgr( 0 )
77 {
78   initDefaults(); // init from default values
79 }
80
81 /*!
82   \brief Destructor
83 */
84 Style_Model::~Style_Model()
85 {
86 }
87
88 /*!
89   \brief Initialize model from the current application style
90   
91   This function is useful when it is necessary to set/remove SALOME style
92   dynamically. Function fromApplication() saves current application properties
93   (style, palette, font) which can be later restored with the restore() function.
94
95   The simplest way it can be done is using static functions of Style_Salome class:
96   Style_Salome::apply(), Style_Salome::restore()
97
98   \param reset if \c true model is also initializes preoperties from the application
99   \sa restore(), fromResources()
100   \sa Style_Salome class
101 */
102 void Style_Model::fromApplication( bool reset )
103 {
104   initDefaults();
105
106   if ( !QApplication::instance() )  // application object is not created yet
107     return;
108
109   if ( !myAppData )  {
110     // if not yes initialized from the application,
111     // store current application's style, palette, etc
112     myAppData = new AppData;
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       dc = color( Button ).darker();
519       break;
520     case Base:
521       dc = color( Button );
522       break;
523     case AlternateBase:
524       dc = mixColors( color( Base,  QPalette::Inactive ), color( Button, QPalette::Inactive ) );
525       break;
526     case Midlight:
527       dc = mixColors( color( Light, QPalette::Inactive ), color( Button, QPalette::Inactive ) );
528       break;
529     default:
530       dc = ac;
531       break;
532     }
533   }
534
535   setColor( role, QPalette::Active,   ac );
536   setColor( role, QPalette::Inactive, ic );
537   setColor( role, QPalette::Disabled, dc );
538 }
539
540 /*!
541   \brief Set palette color value
542
543   If \a inactive and/or \a disabled colors are not specified, they are automatically
544   calculated from \a active color.
545
546   \param role color role
547   \param cg color group
548   \param c color which should be used to draw the corresponding part of the application
549   \sa color()
550 */
551 void Style_Model::setColor( Style_Model::ColorRole role, QPalette::ColorGroup cg, const QColor& c )
552 {
553   myColors[ cg ][ role ] = c;
554 }
555
556 /*!
557   \brief Returns 'auto-calculating color values' flag
558   \return 'auto-calculating color values' flag
559   \internal
560   \sa setAutoPalette()
561 */
562 bool Style_Model::isAutoPalette() const
563 {
564   return myAutoPalette;
565 }
566
567 /*!
568   \brief Set/clear 'auto-calculating color values' flag
569   \param on new value of 'auto-calculating color values' flag
570   \internal
571   \sa isAutoPalette()
572 */
573 void Style_Model::setAutoPalette( bool on )
574 {
575   myAutoPalette = on;
576 }
577
578 /*!
579   \brief Get lines type
580   \return current lines type
581   \sa setLinesType(), linesTransparency()
582 */
583 Style_Model::LineType Style_Model::linesType() const
584 {
585   return myLinesType;
586 }
587
588 /*!
589   \brief Set lines type
590   \param lt new lines type
591   \sa linesType(), linesTransparency()
592 */
593 void Style_Model::setLinesType( LineType lt )
594 {
595   myLinesType = lt;
596 }
597
598 /*!
599   \brief Get lines transparency value
600   \return current lines transparency
601   \sa setLinesTransparency(), linesType()
602 */
603 int Style_Model::linesTransparency() const
604 {
605   return myLinesTransparency;
606 }
607
608 /*!
609   \brief Set lines transparency value
610   \param transparency new lines transparency
611   \sa linesTransparency(), linesType()
612 */
613 void Style_Model::setLinesTransparency( int transparency )
614 {
615   myLinesTransparency = transparency;
616 }
617
618 /*!
619   \brief Get application font
620   \return current application font
621   \sa setApplicationFont()
622 */
623 QFont Style_Model::applicationFont() const
624 {
625   return myFont;
626 }
627
628 /*!
629   \brief Set application font
630   \param font new application font
631   \sa applicationFont()
632 */
633 void Style_Model::setApplicationFont( const QFont& font )
634 {
635   myFont = font;
636 }
637
638 /*!
639   \brief Get widget corners rounding radius value
640   \param wr widget type
641   \return current widget corners rounding
642   \sa setWidgetRounding(), antialiasing()
643 */
644 double Style_Model::widgetRounding( Style_Model::WidgetRounding wr ) const
645 {
646   return myWidgetRounding[ wr ];
647 }
648
649 /*!
650   \brief Set widget corners rounding radius value
651   \param wr widget type
652   \param value new widget corners rounding
653   \sa widgetRounding(), antialiasing()
654 */
655 void Style_Model::setWidgetRounding( WidgetRounding wr, double value )
656 {
657   myWidgetRounding[ wr ] = value;
658 }
659
660 /*!
661   \brief Get anti-aliasing flag value
662   \return \c true if widgets borders should be antialiased
663   \sa setAntialiasing(), widgetRounding()
664 */
665 bool Style_Model::antialiasing() const
666 {
667   return myAntiAliasing;
668 }
669
670 /*!
671   \brief Set anti-aliasing flag value
672   \param value if \c true, widgets borders should be antialiased
673   \sa antialiasing(), widgetRounding()
674 */
675 void Style_Model::setAntialiasing( bool value )
676 {
677   myAntiAliasing = value;
678 }
679
680 /*!
681   \brief Get widget effect
682   \return current widget effect
683   \sa setWidgetEffect()
684 */
685 Style_Model::WidgetEffect Style_Model::widgetEffect() const
686 {
687   return myWidgetEffect;
688 }
689
690 /*!
691   \brief Set widget effect
692   \param we new widget effect
693   \sa widgetEffect()
694 */
695 void Style_Model::setWidgetEffect( WidgetEffect we )
696 {
697   myWidgetEffect = we;
698 }
699
700 /*!
701   \brief Get handle spacing value
702   \param o handle spacing direction
703   \return current handle spacing value
704   \sa setHandleDelta()
705 */
706 int Style_Model::handleDelta( Qt::Orientation o ) const
707 {
708   return myHandleDelta[ o ];
709 }
710
711 /*!
712   \brief Set handle spacing value
713   \param o handle spacing direction
714   \param value new handle spacing value
715   \sa handleDelta()
716 */
717 void Style_Model::setHandleDelta( Qt::Orientation o, int value )
718 {
719   myHandleDelta[ o ] = value;
720 }
721
722 /*!
723   \brief Get splitter handle length
724   \return current splitter handle length
725   \sa setSplitHandleLength()
726 */
727 int Style_Model::splitHandleLength() const
728 {
729   return mySplitHandleLength;
730 }
731
732 /*!
733   \brief Set splitted handle length
734   \param value new splitter handle length
735   \sa splitHandleLength()
736 */
737 void Style_Model::setSplitHandleLength( int value )
738 {
739   mySplitHandleLength = value; 
740 }
741
742 /*!
743   \brief Get slider handle extra size
744   \return current slider handle extra size
745   \sa setSliderSize()
746 */
747 int Style_Model::sliderSize() const
748 {
749   return mySliderSize;
750 }
751
752 /*!
753   \brief Set slider handle extra size
754   \param value new slider handle extra size
755   \sa sliderSize()
756 */
757 void Style_Model::setSliderSize( int value )
758 {
759   mySliderSize = value;
760 }
761
762 /*!
763   \brief Initialize model with the default values
764 */
765 void Style_Model::initDefaults()
766 {
767   // default application font
768   myFont.fromString( "Sans Serif,9,-1,5,50,0,0,0,0,0" );
769
770   // default palette colors
771   myAutoPalette = false;
772   QColor btn = QColor( "#e6e7e6" );
773   QColor fg  = QColor( "#000000" );
774   QColor bg  = QColor( "#ffffff" );
775   setColor( Button,          btn );                  // = (230, 231, 230)
776   setColor( WindowText,      fg );                   // = (  0,   0,   0)
777   setColor( Light,           bg );                   // = (255, 255, 255)
778   setColor( Dark,            btn.darker() );         // = (115, 115, 115) // btn.darker( 130 ) = (177, 178, 177)
779   setColor( Mid,             btn.darker( 150 ) );    // = (153, 154, 153)
780   setColor( Text,            fg );                   // = (  0,   0,   0)
781   setColor( BrightText,      bg );                   // = (255, 255, 255) // fg = (  0,  0,  0)
782   setColor( ButtonText,      fg );                   // = (  0,   0,   0)
783   setColor( Base,            bg );                   // = (255, 255, 255)
784   setColor( Window,          btn );                  // = (230, 231, 230)
785   setColor( AlternateBase,   mixColors( bg, btn ) ); // = (242, 243, 242)
786   setColor( Midlight,        mixColors( bg, btn ) ); // = (242, 243, 242)
787   setColor( Shadow,          fg );                   // = (  0,   0,   0)
788   setColor( Highlight,       "#000080" );            // = (  0,   0, 128) // (  33,  68, 156 )
789   setColor( HighlightedText, bg );                   // = (255, 255, 255)
790   setColor( Link,            "#0000ff" );            // = (  0,   0, 255)
791   setColor( LinkVisited,     "#ff00ff" );            // = (255,   0, 255)
792   setColor( ToolTipBase,     "#ffffdc" );            // = (255, 255, 220) // ( 230, 231, 230 )
793   setColor( ToolTipText,     fg );                   // = (  0,   0,   0)
794   setColor( BorderTop,       "#adadad" );            // = (173, 173, 173) // ( 255, 255, 255 )
795   setColor( BorderBottom,    "#393939" );            // = ( 57,  57,  57) // (  88,  89,  88 )
796   setColor( TabBorderTop,    "#ffffff" );            // = (255, 255, 255)
797   setColor( TabBorderBottom, "#0e0e0e" );            // = ( 14,  14,  14) // (  44,  44,  44 )
798   setColor( FieldLight,      "#ffffff" );            // = (255, 255, 255)
799   setColor( FieldDark,       "#c0c1c0" );            // = (192, 193, 192) // ( 240, 241, 240 )
800   setColor( ProgressBar,     "#000080" );            // = (  0,   0, 128) // (  33,  68, 156 )
801   setColor( Pointer,         "#000000" );            // = (  0,   0,   0)
802   setColor( Checked,         "#ffffff" );            // = (255, 255, 255)
803   setColor( GridLine,        "#999a99" );            // = (153, 154, 153) // ( 192, 192, 192 )
804   setColor( Header,          "#e6e7e6" );            // = (230, 231, 230)
805   setColor( Slider,          "#e6e7e6" );            // = (230, 231, 230)
806   setColor( HighlightWidget, "#e6e7e6" );            // = (230, 231, 230)
807   setColor( HighlightBorder, "#e6e7e6" );            // = (230, 231, 230)
808   setColor( Lines,           "#999a99" );            // = (153, 154, 153) // ( 192, 193, 192 )
809
810   // default values
811   myLinesType          = NoLines;
812   myWidgetEffect       = NoEffect;
813   myAntiAliasing       = false;
814   myLinesTransparency  = 0;
815   myWidgetRounding[ EditRadius   ] = 0.0;
816   myWidgetRounding[ ButtonRadius ] = 0.0;
817   myWidgetRounding[ FrameRadius  ] = 0.0;
818   myWidgetRounding[ SliderRadius ] = 0.0;
819   myHandleDelta[ Qt::Horizontal ]  = 3;
820   myHandleDelta[ Qt::Vertical ]    = 3;
821   mySplitHandleLength              = 20;
822   mySliderSize                     = 2;
823 }
824
825 /*!
826   \brief Read palette color values from resources manager
827   \param role color role
828   \param prefix palette color value resource name prefix
829   \sa writeColorValue()
830 */
831 void Style_Model::readColorValue( ColorRole role, const QString& prefix )
832 {
833   if ( !resourceMgr() ) return;
834
835   QString section = resourceSection();
836   QString active   = QString( "%1-color" ).arg( prefix );
837   QString inactive = QString( "%1-color-inactive" ).arg( prefix );
838   QString disabled = QString( "%1-color-disabled" ).arg( prefix );
839
840   if ( resourceMgr()->hasValue( section, active ) )
841     setColor( role, resourceMgr()->colorValue( section, active ) );
842   if ( resourceMgr()->hasValue( section, inactive ) )
843     setColor( role, QPalette::Inactive, resourceMgr()->colorValue( section, inactive ) );
844   if ( resourceMgr()->hasValue( section, disabled ) )
845     setColor( role, QPalette::Disabled, resourceMgr()->colorValue( section, disabled ) );
846 }
847
848 /*!
849   \brief Write palette color values to resources manager
850   \param role color role
851   \param prefix palette color value resource name prefix
852   \param resMgr resource manager
853   \param resSection resource section name
854   \sa readColorValue()
855 */
856 void Style_Model::writeColorValue( ColorRole role, const QString& prefix,
857                                    QtxResourceMgr* resMgr, const QString& resSection ) const
858 {
859   QString active   = QString( "%1-color" ).arg( prefix );
860   QString inactive = QString( "%1-color-inactive" ).arg( prefix );
861   QString disabled = QString( "%1-color-disabled" ).arg( prefix );
862
863   resMgr->setValue( resSection, active,   color( role, QPalette::Active ) );
864   resMgr->setValue( resSection, inactive, color( role, QPalette::Inactive ) );
865   resMgr->setValue( resSection, disabled, color( role, QPalette::Disabled ) );
866 }