1 /*****************************************************************
2 This file is part of the KDE project.
4 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 ******************************************************************/
25 #include "kdecoration_p.h"
28 #include <kconfiggroup.h>
29 #include <kglobalsettings.h>
31 #include <QApplication>
34 KDecorationOptionsPrivate::KDecorationOptionsPrivate()
35 : title_buttons_left( KDecorationOptions::defaultTitleButtonsLeft())
36 , title_buttons_right( KDecorationOptions::defaultTitleButtonsRight())
37 , custom_button_positions( false )
38 , show_tooltips( true )
39 , border_size( BorderNormal
)
40 , cached_border_size( BordersCount
) // invalid
41 , move_resize_maximized_windows( true )
42 , opMaxButtonRightClick( MaximizeOp
)
43 , opMaxButtonMiddleClick( VMaximizeOp
)
44 , opMaxButtonLeftClick( HMaximizeOp
)
46 for(int i
=0; i
< NUM_COLORS
*2; ++i
)
50 KDecorationOptionsPrivate::~KDecorationOptionsPrivate()
53 for(i
=0; i
< NUM_COLORS
*2; ++i
)
63 unsigned long KDecorationOptionsPrivate::updateSettings( KConfig
* config
)
65 unsigned long changed
= 0;
66 KConfigGroup
wmConfig(config
, "WM");
69 QColor old_colors
[NUM_COLORS
*2];
73 old_colors
[ i
] = colors
[ i
];
75 QPalette appPal
= QApplication::palette();
77 colors
[ColorFrame
] = appPal
.color( QPalette::Active
, QPalette::Background
);
78 colors
[ColorFrame
] = wmConfig
.readEntry("frame", colors
[ColorFrame
]);
79 colors
[ColorHandle
] = colors
[ColorFrame
];
80 colors
[ColorHandle
] = wmConfig
.readEntry("handle", colors
[ColorHandle
]);
82 // full button configuration (background, blend, and foreground
83 if(QPixmap::defaultDepth() > 8)
84 colors
[ColorButtonBg
] = colors
[ColorFrame
].light(130);
86 colors
[ColorButtonBg
] = colors
[ColorFrame
];
87 colors
[ColorButtonBg
] = wmConfig
.readEntry("activeTitleBtnBg",
89 colors
[ColorTitleBar
] = appPal
.color( QPalette::Active
, QPalette::Highlight
);
90 colors
[ColorTitleBar
] = wmConfig
.readEntry("activeBackground",
91 colors
[ColorTitleBar
]);
92 if(QPixmap::defaultDepth() > 8)
93 colors
[ColorTitleBlend
] = colors
[ ColorTitleBar
].dark(110);
95 colors
[ColorTitleBlend
] = colors
[ ColorTitleBar
];
96 colors
[ColorTitleBlend
] = wmConfig
.readEntry("activeBlend",
97 colors
[ColorTitleBlend
]);
99 colors
[ColorFont
] = appPal
.color( QPalette::Active
, QPalette::HighlightedText
);
100 colors
[ColorFont
] = wmConfig
.readEntry("activeForeground", colors
[ColorFont
]);
103 colors
[ColorFrame
+NUM_COLORS
] = wmConfig
.readEntry("inactiveFrame",
105 colors
[ColorTitleBar
+NUM_COLORS
] = colors
[ColorFrame
];
106 colors
[ColorTitleBar
+NUM_COLORS
] = wmConfig
.
107 readEntry("inactiveBackground", colors
[ColorTitleBar
+NUM_COLORS
]);
109 if(QPixmap::defaultDepth() > 8)
110 colors
[ColorTitleBlend
+NUM_COLORS
] = colors
[ ColorTitleBar
+NUM_COLORS
].dark(110);
112 colors
[ColorTitleBlend
+NUM_COLORS
] = colors
[ ColorTitleBar
+NUM_COLORS
];
113 colors
[ColorTitleBlend
+NUM_COLORS
] =
114 wmConfig
.readEntry("inactiveBlend", colors
[ColorTitleBlend
+NUM_COLORS
]);
116 // full button configuration
117 if(QPixmap::defaultDepth() > 8)
118 colors
[ColorButtonBg
+NUM_COLORS
] = colors
[ColorFrame
+NUM_COLORS
].light(130);
120 colors
[ColorButtonBg
+NUM_COLORS
] = colors
[ColorFrame
+NUM_COLORS
];
121 colors
[ColorButtonBg
+NUM_COLORS
] =
122 wmConfig
.readEntry("inactiveTitleBtnBg",
123 colors
[ColorButtonBg
]);
125 colors
[ColorHandle
+NUM_COLORS
] =
126 wmConfig
.readEntry("inactiveHandle", colors
[ColorHandle
]);
128 colors
[ColorFont
+NUM_COLORS
] = colors
[ColorFrame
].dark();
129 colors
[ColorFont
+NUM_COLORS
] = wmConfig
.readEntry("inactiveForeground",
130 colors
[ColorFont
+NUM_COLORS
]);
135 if( old_colors
[ i
] != colors
[ i
] )
136 changed
|= SettingColors
;
139 QFont old_activeFont
= activeFont
;
140 QFont old_inactiveFont
= inactiveFont
;
141 QFont old_activeFontSmall
= activeFontSmall
;
142 QFont old_inactiveFontSmall
= inactiveFontSmall
;
144 QFont activeFontGuess
= KGlobalSettings::windowTitleFont();
146 activeFont
= wmConfig
.readEntry("activeFont", activeFontGuess
);
147 inactiveFont
= wmConfig
.readEntry("inactiveFont", activeFont
);
149 activeFontSmall
= activeFont
;
151 #warning KDE4 : is it useful ? ( temporary hack )
153 // activeFontSmall.setPointSize(activeFont.pointSize() - 2 > 0 ? activeFont.pointSize() - 2 : activeFont.pointSize()+1 );
154 activeFontSmall
= wmConfig
.readEntry("activeFontSmall", activeFontSmall
);
155 inactiveFontSmall
= wmConfig
.readEntry("inactiveFontSmall", activeFontSmall
);
157 if( old_activeFont
!= activeFont
158 || old_inactiveFont
!= inactiveFont
159 || old_activeFontSmall
!= activeFontSmall
160 || old_inactiveFontSmall
!= inactiveFontSmall
)
161 changed
|= SettingFont
;
163 KConfigGroup
styleConfig(config
, "Style");
165 QString old_title_buttons_left
= title_buttons_left
;
166 QString old_title_buttons_right
= title_buttons_right
;
167 bool old_custom_button_positions
= custom_button_positions
;
168 custom_button_positions
= styleConfig
.readEntry("CustomButtonPositions", false);
169 if (custom_button_positions
)
171 title_buttons_left
= styleConfig
.readEntry("ButtonsOnLeft", KDecorationOptions::defaultTitleButtonsLeft());
172 title_buttons_right
= styleConfig
.readEntry("ButtonsOnRight", KDecorationOptions::defaultTitleButtonsRight());
176 title_buttons_left
= KDecorationOptions::defaultTitleButtonsLeft();
177 title_buttons_right
= KDecorationOptions::defaultTitleButtonsRight();
179 if( old_custom_button_positions
!= custom_button_positions
180 || ( custom_button_positions
&&
181 ( old_title_buttons_left
!= title_buttons_left
182 || old_title_buttons_right
!= title_buttons_right
)))
183 changed
|= SettingButtons
;
186 bool old_show_tooltips
= show_tooltips
;
187 show_tooltips
= styleConfig
.readEntry("ShowToolTips", true);
188 if( old_show_tooltips
!= show_tooltips
)
189 changed
|= SettingTooltips
;
193 BorderSize old_border_size
= border_size
;
194 int border_size_num
= styleConfig
.readEntry( "BorderSize", (int)BorderNormal
);
195 if( border_size_num
>= 0 && border_size_num
< BordersCount
)
196 border_size
= static_cast< BorderSize
>( border_size_num
);
198 border_size
= BorderNormal
;
199 if( old_border_size
!= border_size
)
200 changed
|= SettingBorder
;
201 cached_border_size
= BordersCount
; // invalid
203 KConfigGroup
windowsConfig(config
, "Windows");
204 bool old_move_resize_maximized_windows
= move_resize_maximized_windows
;
205 move_resize_maximized_windows
= windowsConfig
.readEntry( "MoveResizeMaximizedWindows", false);
206 if( old_move_resize_maximized_windows
!= move_resize_maximized_windows
)
207 changed
|= SettingBorder
;
209 // destroy cached values
211 for(i
=0; i
< NUM_COLORS
*2; ++i
)
223 KDecorationDefines::BorderSize
KDecorationOptionsPrivate::findPreferredBorderSize( BorderSize size
,
224 QList
< BorderSize
> sizes
) const
226 for( QList
< BorderSize
>::ConstIterator it
= sizes
.constBegin();
227 it
!= sizes
.constEnd();
229 if( size
<= *it
) // size is either a supported size, or *it is the closest larger supported
231 return sizes
.last(); // size is larger than all supported ones, return largest