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     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 // SettingColors
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     // normal colors
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     // full button configuration (background, blend, and foreground
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     // inactive
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     // full button configuration
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 // SettingFont
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 // SettingsButtons        
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 // SettingTooltips
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 // SettingBorder
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; // invalid
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 // destroy cached values
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 ) // size is either a supported size, or *it is the closest larger supported
00233             return *it;
00234     return sizes.last(); // size is larger than all supported ones, return largest
00235     }
KDE Home | KDE Accessibility Home | Description of Access Keys