kwin/lib Library API Documentation

kdecoration_p.cpp

00001 /***************************************************************** 00002 This file is part of the KDE project. 00003 00004 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org> 00005 00006 Permission is hereby granted, free of charge, to any person obtaining a 00007 copy of this software and associated documentation files (the "Software"), 00008 to deal in the Software without restriction, including without limitation 00009 the rights to use, copy, modify, merge, publish, distribute, sublicense, 00010 and/or sell copies of the Software, and to permit persons to whom the 00011 Software is furnished to do so, subject to the following conditions: 00012 00013 The above copyright notice and this permission notice shall be included in 00014 all copies or substantial portions of the Software. 00015 00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00019 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00020 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00021 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00022 DEALINGS IN THE SOFTWARE. 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; // invalid 00060 move_resize_maximized_windows = true; 00061 } 00062 00063 unsigned long KDecorationOptionsPrivate::updateKWinSettings( KConfig* config ) 00064 { 00065 unsigned long changed = 0; 00066 QString old_group = config->group(); 00067 config->setGroup( "WM" ); 00068 00069 // SettingColors 00070 QColor old_colors[NUM_COLORS*2]; 00071 for( int i = 0; 00072 i < NUM_COLORS*2; 00073 ++i ) 00074 old_colors[ i ] = colors[ i ]; 00075 00076 QPalette pal = QApplication::palette(); 00077 // normal colors 00078 colors[ColorFrame] = pal.active().background(); 00079 colors[ColorFrame] = config->readColorEntry("frame", &colors[ColorFrame]); 00080 colors[ColorHandle] = colors[ColorFrame]; 00081 colors[ColorHandle] = config->readColorEntry("handle", &colors[ColorHandle]); 00082 00083 // full button configuration (background, blend, and foreground 00084 if(QPixmap::defaultDepth() > 8) 00085 colors[ColorButtonBg] = colors[ColorFrame].light(130); 00086 else 00087 colors[ColorButtonBg] = colors[ColorFrame]; 00088 colors[ColorButtonBg] = config->readColorEntry("activeTitleBtnBg", 00089 &colors[ColorFrame]); 00090 colors[ColorTitleBar] = pal.active().highlight(); 00091 colors[ColorTitleBar] = config->readColorEntry("activeBackground", 00092 &colors[ColorTitleBar]); 00093 if(QPixmap::defaultDepth() > 8) 00094 colors[ColorTitleBlend] = colors[ ColorTitleBar ].dark(110); 00095 else 00096 colors[ColorTitleBlend] = colors[ ColorTitleBar ]; 00097 colors[ColorTitleBlend] = config->readColorEntry("activeBlend", 00098 &colors[ColorTitleBlend]); 00099 00100 colors[ColorFont] = pal.active().highlightedText(); 00101 colors[ColorFont] = config->readColorEntry("activeForeground", &colors[ColorFont]); 00102 00103 // inactive 00104 colors[ColorFrame+NUM_COLORS] = config->readColorEntry("inactiveFrame", 00105 &colors[ColorFrame]); 00106 colors[ColorTitleBar+NUM_COLORS] = colors[ColorFrame]; 00107 colors[ColorTitleBar+NUM_COLORS] = config-> 00108 readColorEntry("inactiveBackground", &colors[ColorTitleBar+NUM_COLORS]); 00109 00110 if(QPixmap::defaultDepth() > 8) 00111 colors[ColorTitleBlend+NUM_COLORS] = colors[ ColorTitleBar+NUM_COLORS ].dark(110); 00112 else 00113 colors[ColorTitleBlend+NUM_COLORS] = colors[ ColorTitleBar+NUM_COLORS ]; 00114 colors[ColorTitleBlend+NUM_COLORS] = 00115 config->readColorEntry("inactiveBlend", &colors[ColorTitleBlend+NUM_COLORS]); 00116 00117 // full button configuration 00118 if(QPixmap::defaultDepth() > 8) 00119 colors[ColorButtonBg+NUM_COLORS] = colors[ColorFrame+NUM_COLORS].light(130); 00120 else 00121 colors[ColorButtonBg+NUM_COLORS] = colors[ColorFrame+NUM_COLORS]; 00122 colors[ColorButtonBg+NUM_COLORS] = 00123 config->readColorEntry("inactiveTitleBtnBg", 00124 &colors[ColorButtonBg]); 00125 00126 colors[ColorHandle+NUM_COLORS] = 00127 config->readColorEntry("inactiveHandle", &colors[ColorHandle]); 00128 00129 colors[ColorFont+NUM_COLORS] = colors[ColorFrame].dark(); 00130 colors[ColorFont+NUM_COLORS] = config->readColorEntry("inactiveForeground", 00131 &colors[ColorFont+NUM_COLORS]); 00132 00133 for( int i = 0; 00134 i < NUM_COLORS*2; 00135 ++i ) 00136 if( old_colors[ i ] != colors[ i ] ) 00137 changed |= SettingColors; 00138 00139 // SettingFont 00140 QFont old_activeFont = activeFont; 00141 QFont old_inactiveFont = inactiveFont; 00142 QFont old_activeFontSmall = activeFontSmall; 00143 QFont old_inactiveFontSmall = inactiveFontSmall; 00144 00145 QFont activeFontGuess = KGlobalSettings::generalFont(); 00146 activeFontGuess.setBold(true); 00147 activeFontGuess.setPixelSize(12); 00148 00149 activeFont = config->readFontEntry("activeFont", &activeFontGuess); 00150 inactiveFont = config->readFontEntry("inactiveFont", &activeFont); 00151 00152 activeFontSmall = activeFont; 00153 activeFontSmall.setPointSize(activeFont.pointSize() - 2); 00154 activeFontSmall = config->readFontEntry("activeFontSmall", &activeFontSmall); 00155 inactiveFontSmall = config->readFontEntry("inactiveFontSmall", &activeFontSmall); 00156 00157 if( old_activeFont != activeFont 00158 || old_inactiveFont != inactiveFont 00159 || old_activeFontSmall != activeFontSmall 00160 || old_inactiveFontSmall != inactiveFontSmall ) 00161 changed |= SettingFont; 00162 00163 config->setGroup( "Style" ); 00164 // SettingsButtons 00165 QString old_title_buttons_left = title_buttons_left; 00166 QString old_title_buttons_right = title_buttons_right; 00167 bool old_custom_button_positions = custom_button_positions; 00168 custom_button_positions = config->readBoolEntry("CustomButtonPositions", false); 00169 if (custom_button_positions) 00170 { 00171 title_buttons_left = config->readEntry("ButtonsOnLeft", "MS"); 00172 title_buttons_right = config->readEntry("ButtonsOnRight", "HIAX"); 00173 } 00174 else 00175 { 00176 title_buttons_left = "MS"; 00177 title_buttons_right = "HIAX"; 00178 } 00179 if( old_custom_button_positions != custom_button_positions 00180 || ( custom_button_positions && 00181 ( old_title_buttons_left != title_buttons_left 00182 || old_title_buttons_right != title_buttons_right ))) 00183 changed |= SettingButtons; 00184 00185 // SettingTooltips 00186 bool old_show_tooltips = show_tooltips; 00187 show_tooltips = config->readBoolEntry("ShowToolTips", true); 00188 if( old_show_tooltips != show_tooltips ) 00189 changed |= SettingTooltips; 00190 00191 // SettingBorder 00192 00193 BorderSize old_border_size = border_size; 00194 int border_size_num = config->readNumEntry( "BorderSize", BorderNormal ); 00195 if( border_size_num >= 0 && border_size_num < BordersCount ) 00196 border_size = static_cast< BorderSize >( border_size_num ); 00197 else 00198 border_size = BorderNormal; 00199 if( old_border_size != border_size ) 00200 changed |= SettingBorder; 00201 cached_border_size = BordersCount; // invalid 00202 00203 config->setGroup( "Windows" ); 00204 bool old_move_resize_maximized_windows = move_resize_maximized_windows; 00205 move_resize_maximized_windows = config->readBoolEntry( "MoveResizeMaximizedWindows", true ); 00206 if( old_move_resize_maximized_windows != move_resize_maximized_windows ) 00207 changed |= SettingBorder; 00208 00209 // destroy cached values 00210 int i; 00211 for(i=0; i < NUM_COLORS*2; ++i) 00212 { 00213 if(cg[i]) 00214 { 00215 delete cg[i]; 00216 cg[i] = NULL; 00217 } 00218 } 00219 00220 config->setGroup( old_group ); 00221 00222 return changed; 00223 } 00224 00225 KDecorationDefines::BorderSize KDecorationOptionsPrivate::findPreferredBorderSize( BorderSize size, 00226 QValueList< BorderSize > sizes ) const 00227 { 00228 for( QValueList< BorderSize >::ConstIterator it = sizes.begin(); 00229 it != sizes.end(); 00230 ++it ) 00231 if( size <= *it ) // size is either a supported size, or *it is the closest larger supported 00232 return *it; 00233 return sizes.last(); // size is larger than all supported ones, return largest 00234 }
KDE Logo
This file is part of the documentation for kwin/lib Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Aug 31 00:02:16 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003