kwin 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     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::generalFont();
00149     activeFontGuess.setBold(true);
00150     activeFontGuess.setPixelSize(12);
00151 
00152     activeFont = config->readFontEntry("activeFont", &activeFontGuess);
00153     inactiveFont = config->readFontEntry("inactiveFont", &activeFont);
00154 
00155     activeFontSmall = activeFont;
00156     activeFontSmall.setPointSize(activeFont.pointSize() - 2);
00157     activeFontSmall = config->readFontEntry("activeFontSmall", &activeFontSmall);
00158     inactiveFontSmall = config->readFontEntry("inactiveFontSmall", &activeFontSmall);
00159 
00160     if( old_activeFont != activeFont
00161         || old_inactiveFont != inactiveFont
00162         || old_activeFontSmall != activeFontSmall
00163         || old_inactiveFontSmall != inactiveFontSmall )
00164         changed |= SettingFont;
00165 
00166     config->setGroup( "Style" );
00167 // SettingsButtons        
00168     QString old_title_buttons_left = title_buttons_left;
00169     QString old_title_buttons_right = title_buttons_right;
00170     bool old_custom_button_positions = custom_button_positions;
00171     custom_button_positions = config->readBoolEntry("CustomButtonPositions", false);
00172     if (custom_button_positions)
00173         {
00174         title_buttons_left  = config->readEntry("ButtonsOnLeft", "MS");
00175         title_buttons_right = config->readEntry("ButtonsOnRight", "HIAX");
00176         }
00177     else
00178         {
00179         title_buttons_left  = "MS";
00180         title_buttons_right = "HIAX";
00181         }
00182     if( old_custom_button_positions != custom_button_positions
00183         || ( custom_button_positions &&
00184                 ( old_title_buttons_left != title_buttons_left
00185                 || old_title_buttons_right != title_buttons_right )))
00186         changed |= SettingButtons;
00187 
00188 // SettingTooltips
00189     bool old_show_tooltips = show_tooltips;
00190     show_tooltips = config->readBoolEntry("ShowToolTips", true);
00191     if( old_show_tooltips != show_tooltips )
00192         changed |= SettingTooltips;
00193 
00194 // SettingBorder
00195 
00196     BorderSize old_border_size = border_size;
00197     int border_size_num = config->readNumEntry( "BorderSize", BorderNormal );
00198     if( border_size_num >= 0 && border_size_num < BordersCount )
00199         border_size = static_cast< BorderSize >( border_size_num );
00200     else
00201         border_size = BorderNormal;
00202     if( old_border_size != border_size )
00203         changed |= SettingBorder;
00204     cached_border_size = BordersCount; // invalid
00205 
00206     config->setGroup( "Windows" );
00207     bool old_move_resize_maximized_windows = move_resize_maximized_windows;
00208     move_resize_maximized_windows = config->readBoolEntry( "MoveResizeMaximizedWindows", true );
00209     if( old_move_resize_maximized_windows != move_resize_maximized_windows )
00210         changed |= SettingBorder;
00211 
00212 // destroy cached values
00213     int i;
00214     for(i=0; i < NUM_COLORS*2; ++i)
00215         {
00216         if(cg[i])
00217             {
00218             delete cg[i];
00219             cg[i] = NULL;
00220             }
00221         }
00222 
00223     config->setGroup( old_group );
00224 
00225     return changed;
00226     }
00227 
00228 KDecorationDefines::BorderSize KDecorationOptionsPrivate::findPreferredBorderSize( BorderSize size,
00229     QValueList< BorderSize > sizes ) const
00230     {
00231     for( QValueList< BorderSize >::ConstIterator it = sizes.begin();
00232          it != sizes.end();
00233          ++it )
00234         if( size <= *it ) // size is either a supported size, or *it is the closest larger supported
00235             return *it;
00236     return sizes.last(); // size is larger than all supported ones, return largest
00237     }
KDE Logo
This file is part of the documentation for kwin Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Sep 30 18:40:42 2005 by doxygen 1.4.3 written by Dimitri van Heesch, © 1997-2003