kdecoration_p.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "kdecoration_p.h"
00026
00027 #include <kconfig.h>
00028 #include <kglobalsettings.h>
00029 #include <qpalette.h>
00030 #include <qapplication.h>
00031 #include <assert.h>
00032
00033 KDecorationOptionsPrivate::KDecorationOptionsPrivate()
00034 {
00035 for(int i=0; i < NUM_COLORS*2; ++i)
00036 cg[i] = NULL;
00037 }
00038
00039 KDecorationOptionsPrivate::~KDecorationOptionsPrivate()
00040 {
00041 int i;
00042 for(i=0; i < NUM_COLORS*2; ++i)
00043 {
00044 if(cg[i])
00045 {
00046 delete cg[i];
00047 cg[i] = NULL;
00048 }
00049 }
00050 }
00051
00052 void KDecorationOptionsPrivate::defaultKWinSettings()
00053 {
00054 title_buttons_left = "MS";
00055 title_buttons_right = "HIAX";
00056 custom_button_positions = false;
00057 show_tooltips = true;
00058 border_size = BorderNormal;
00059 cached_border_size = BordersCount;
00060 move_resize_maximized_windows = true;
00061 OpMaxButtonRightClick = MaximizeOp;
00062 OpMaxButtonMiddleClick = VMaximizeOp;
00063 OpMaxButtonLeftClick = HMaximizeOp;
00064 }
00065
00066 unsigned long KDecorationOptionsPrivate::updateKWinSettings( KConfig* config )
00067 {
00068 unsigned long changed = 0;
00069 QString old_group = config->group();
00070 config->setGroup( "WM" );
00071
00072
00073 QColor old_colors[NUM_COLORS*2];
00074 for( int i = 0;
00075 i < NUM_COLORS*2;
00076 ++i )
00077 old_colors[ i ] = colors[ i ];
00078
00079 QPalette pal = QApplication::palette();
00080
00081 colors[ColorFrame] = pal.active().background();
00082 colors[ColorFrame] = config->readColorEntry("frame", &colors[ColorFrame]);
00083 colors[ColorHandle] = colors[ColorFrame];
00084 colors[ColorHandle] = config->readColorEntry("handle", &colors[ColorHandle]);
00085
00086
00087 if(QPixmap::defaultDepth() > 8)
00088 colors[ColorButtonBg] = colors[ColorFrame].light(130);
00089 else
00090 colors[ColorButtonBg] = colors[ColorFrame];
00091 colors[ColorButtonBg] = config->readColorEntry("activeTitleBtnBg",
00092 &colors[ColorFrame]);
00093 colors[ColorTitleBar] = pal.active().highlight();
00094 colors[ColorTitleBar] = config->readColorEntry("activeBackground",
00095 &colors[ColorTitleBar]);
00096 if(QPixmap::defaultDepth() > 8)
00097 colors[ColorTitleBlend] = colors[ ColorTitleBar ].dark(110);
00098 else
00099 colors[ColorTitleBlend] = colors[ ColorTitleBar ];
00100 colors[ColorTitleBlend] = config->readColorEntry("activeBlend",
00101 &colors[ColorTitleBlend]);
00102
00103 colors[ColorFont] = pal.active().highlightedText();
00104 colors[ColorFont] = config->readColorEntry("activeForeground", &colors[ColorFont]);
00105
00106
00107 colors[ColorFrame+NUM_COLORS] = config->readColorEntry("inactiveFrame",
00108 &colors[ColorFrame]);
00109 colors[ColorTitleBar+NUM_COLORS] = colors[ColorFrame];
00110 colors[ColorTitleBar+NUM_COLORS] = config->
00111 readColorEntry("inactiveBackground", &colors[ColorTitleBar+NUM_COLORS]);
00112
00113 if(QPixmap::defaultDepth() > 8)
00114 colors[ColorTitleBlend+NUM_COLORS] = colors[ ColorTitleBar+NUM_COLORS ].dark(110);
00115 else
00116 colors[ColorTitleBlend+NUM_COLORS] = colors[ ColorTitleBar+NUM_COLORS ];
00117 colors[ColorTitleBlend+NUM_COLORS] =
00118 config->readColorEntry("inactiveBlend", &colors[ColorTitleBlend+NUM_COLORS]);
00119
00120
00121 if(QPixmap::defaultDepth() > 8)
00122 colors[ColorButtonBg+NUM_COLORS] = colors[ColorFrame+NUM_COLORS].light(130);
00123 else
00124 colors[ColorButtonBg+NUM_COLORS] = colors[ColorFrame+NUM_COLORS];
00125 colors[ColorButtonBg+NUM_COLORS] =
00126 config->readColorEntry("inactiveTitleBtnBg",
00127 &colors[ColorButtonBg]);
00128
00129 colors[ColorHandle+NUM_COLORS] =
00130 config->readColorEntry("inactiveHandle", &colors[ColorHandle]);
00131
00132 colors[ColorFont+NUM_COLORS] = colors[ColorFrame].dark();
00133 colors[ColorFont+NUM_COLORS] = config->readColorEntry("inactiveForeground",
00134 &colors[ColorFont+NUM_COLORS]);
00135
00136 for( int i = 0;
00137 i < NUM_COLORS*2;
00138 ++i )
00139 if( old_colors[ i ] != colors[ i ] )
00140 changed |= SettingColors;
00141
00142
00143 QFont old_activeFont = activeFont;
00144 QFont old_inactiveFont = inactiveFont;
00145 QFont old_activeFontSmall = activeFontSmall;
00146 QFont old_inactiveFontSmall = inactiveFontSmall;
00147
00148 QFont activeFontGuess = KGlobalSettings::windowTitleFont();
00149
00150 activeFont = config->readFontEntry("activeFont", &activeFontGuess);
00151 inactiveFont = config->readFontEntry("inactiveFont", &activeFont);
00152
00153 activeFontSmall = activeFont;
00154 activeFontSmall.setPointSize(activeFont.pointSize() - 2);
00155 activeFontSmall = config->readFontEntry("activeFontSmall", &activeFontSmall);
00156 inactiveFontSmall = config->readFontEntry("inactiveFontSmall", &activeFontSmall);
00157
00158 if( old_activeFont != activeFont
00159 || old_inactiveFont != inactiveFont
00160 || old_activeFontSmall != activeFontSmall
00161 || old_inactiveFontSmall != inactiveFontSmall )
00162 changed |= SettingFont;
00163
00164 config->setGroup( "Style" );
00165
00166 QString old_title_buttons_left = title_buttons_left;
00167 QString old_title_buttons_right = title_buttons_right;
00168 bool old_custom_button_positions = custom_button_positions;
00169 custom_button_positions = config->readBoolEntry("CustomButtonPositions", false);
00170 if (custom_button_positions)
00171 {
00172 title_buttons_left = config->readEntry("ButtonsOnLeft", "MS");
00173 title_buttons_right = config->readEntry("ButtonsOnRight", "HIAX");
00174 }
00175 else
00176 {
00177 title_buttons_left = "MS";
00178 title_buttons_right = "HIAX";
00179 }
00180 if( old_custom_button_positions != custom_button_positions
00181 || ( custom_button_positions &&
00182 ( old_title_buttons_left != title_buttons_left
00183 || old_title_buttons_right != title_buttons_right )))
00184 changed |= SettingButtons;
00185
00186
00187 bool old_show_tooltips = show_tooltips;
00188 show_tooltips = config->readBoolEntry("ShowToolTips", true);
00189 if( old_show_tooltips != show_tooltips )
00190 changed |= SettingTooltips;
00191
00192
00193
00194 BorderSize old_border_size = border_size;
00195 int border_size_num = config->readNumEntry( "BorderSize", BorderNormal );
00196 if( border_size_num >= 0 && border_size_num < BordersCount )
00197 border_size = static_cast< BorderSize >( border_size_num );
00198 else
00199 border_size = BorderNormal;
00200 if( old_border_size != border_size )
00201 changed |= SettingBorder;
00202 cached_border_size = BordersCount;
00203
00204 config->setGroup( "Windows" );
00205 bool old_move_resize_maximized_windows = move_resize_maximized_windows;
00206 move_resize_maximized_windows = config->readBoolEntry( "MoveResizeMaximizedWindows", false );
00207 if( old_move_resize_maximized_windows != move_resize_maximized_windows )
00208 changed |= SettingBorder;
00209
00210
00211 int i;
00212 for(i=0; i < NUM_COLORS*2; ++i)
00213 {
00214 if(cg[i])
00215 {
00216 delete cg[i];
00217 cg[i] = NULL;
00218 }
00219 }
00220
00221 config->setGroup( old_group );
00222
00223 return changed;
00224 }
00225
00226 KDecorationDefines::BorderSize KDecorationOptionsPrivate::findPreferredBorderSize( BorderSize size,
00227 QValueList< BorderSize > sizes ) const
00228 {
00229 for( QValueList< BorderSize >::ConstIterator it = sizes.begin();
00230 it != sizes.end();
00231 ++it )
00232 if( size <= *it )
00233 return *it;
00234 return sizes.last();
00235 }
|