kwin Library API Documentation

plastik.cpp

00001 /* Plastik KWin window decoration
00002   Copyright (C) 2003 Sandro Giessl <ceebx@users.sourceforge.net>
00003 
00004   based on the window decoration "Web":
00005   Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
00006 
00007   This program is free software; you can redistribute it and/or
00008   modify it under the terms of the GNU General Public
00009   License as published by the Free Software Foundation; either
00010   version 2 of the License, or (at your option) any later version.
00011 
00012   This program is distributed in the hope that it will be useful,
00013   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015   General Public License for more details.
00016 
00017   You should have received a copy of the GNU General Public License
00018   along with this program; see the file COPYING.  If not, write to
00019   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020   Boston, MA 02111-1307, USA.
00021  */
00022 
00023 #include <kconfig.h>
00024 
00025 #include "misc.h"
00026 #include "plastik.h"
00027 #include "plastik.moc"
00028 #include "plastikclient.h"
00029 
00030 namespace KWinPlastik
00031 {
00032 
00033 // static bool pixmaps_created = false;
00034 
00035 bool PlastikHandler::m_initialized    = false;
00036 bool PlastikHandler::m_animateButtons = true;
00037 bool PlastikHandler::m_titleShadow    = true;
00038 bool PlastikHandler::m_shrinkBorders  = true;
00039 bool PlastikHandler::m_menuClose      = false;
00040 bool PlastikHandler::m_reverse        = false;
00041 int  PlastikHandler::m_borderSize     = 4;
00042 int  PlastikHandler::m_titleHeight    = 19;
00043 int  PlastikHandler::m_titleHeightTool= 12;
00044 QFont PlastikHandler::m_titleFont = QFont();
00045 QFont PlastikHandler::m_titleFontTool = QFont();
00046 Qt::AlignmentFlags PlastikHandler::m_titleAlign = Qt::AlignHCenter;
00047 
00048 PlastikHandler::PlastikHandler()
00049 {
00050     reset(0);
00051 }
00052 
00053 PlastikHandler::~PlastikHandler()
00054 {
00055     m_initialized = false;
00056 }
00057 
00058 bool PlastikHandler::reset(unsigned long changed)
00059 {
00060     // we assume the active font to be the same as the inactive font since the control
00061     // center doesn't offer different settings anyways.
00062     m_titleFont = KDecoration::options()->font(true, false); // not small
00063     m_titleFontTool = KDecoration::options()->font(true, true); // small
00064 
00065     switch(KDecoration::options()->preferredBorderSize( this )) {
00066         case BorderTiny:
00067             m_borderSize = 2;
00068             break;
00069         case BorderLarge:
00070             m_borderSize = 8;
00071             break;
00072         case BorderVeryLarge:
00073             m_borderSize = 12;
00074             break;
00075         case BorderHuge:
00076             m_borderSize = 18;
00077             break;
00078         case BorderVeryHuge:
00079             m_borderSize = 27;
00080             break;
00081         case BorderOversized:
00082             m_borderSize = 40;
00083             break;
00084         case BorderNormal:
00085         default:
00086             m_borderSize = 4;
00087     }
00088 
00089     // check if we are in reverse layout mode
00090     m_reverse = QApplication::reverseLayout();
00091 
00092     // read in the configuration
00093     readConfig();
00094 
00095     m_initialized = true;
00096 
00097     // Do we need to "hit the wooden hammer" ?
00098     bool needHardReset = true;
00099     // TODO: besides the Color and Font settings I can maybe handle more changes
00100     //       without a hard reset. I will do this later...
00101     if (changed & SettingColors || changed & SettingFont)
00102     {
00103         needHardReset = false;
00104     }
00105 
00106     if (needHardReset) {
00107         return true;
00108     } else {
00109         resetDecorations(changed);
00110         return false;
00111     }
00112 }
00113 
00114 KDecoration* PlastikHandler::createDecoration( KDecorationBridge* bridge )
00115 {
00116         return new PlastikClient( bridge, this );
00117 }
00118 
00119 bool PlastikHandler::supports( Ability ability )
00120 {
00121     switch( ability )
00122     {
00123         case AbilityAnnounceButtons:
00124         case AbilityButtonMenu:
00125         case AbilityButtonOnAllDesktops:
00126         case AbilityButtonSpacer:
00127         case AbilityButtonHelp:
00128         case AbilityButtonMinimize:
00129         case AbilityButtonMaximize:
00130         case AbilityButtonClose:
00131         case AbilityButtonAboveOthers:
00132         case AbilityButtonBelowOthers:
00133         case AbilityButtonShade:
00134             return true;
00135         default:
00136             return false;
00137     };
00138 }
00139 
00140 void PlastikHandler::readConfig()
00141 {
00142     // create a config object
00143     KConfig config("kwinplastikrc");
00144     config.setGroup("General");
00145 
00146     // grab settings
00147     m_titleShadow    = config.readBoolEntry("TitleShadow", true);
00148 
00149     QFontMetrics fm(m_titleFont);  // active font = inactive font
00150     int titleHeightMin = config.readNumEntry("MinTitleHeight", 16);
00151     // The title should strech with bigger font sizes!
00152     m_titleHeight = QMAX(titleHeightMin, fm.height() + 4); // 4 px for the shadow etc.
00153 
00154     fm = QFontMetrics(m_titleFontTool);  // active font = inactive font
00155     int titleHeightToolMin = config.readNumEntry("MinTitleHeightTool", 13);
00156     // The title should strech with bigger font sizes!
00157     m_titleHeightTool = QMAX(titleHeightToolMin, fm.height() ); // don't care about the shadow etc.
00158 
00159     QString value = config.readEntry("TitleAlignment", "AlignHCenter");
00160     if (value == "AlignLeft")         m_titleAlign = Qt::AlignLeft;
00161     else if (value == "AlignHCenter") m_titleAlign = Qt::AlignHCenter;
00162     else if (value == "AlignRight")   m_titleAlign = Qt::AlignRight;
00163 
00164     m_animateButtons = config.readBoolEntry("AnimateButtons", true);
00165     m_menuClose = config.readBoolEntry("CloseOnMenuDoubleClick", true);
00166 }
00167 
00168 QColor PlastikHandler::getColor(KWinPlastik::ColorType type, const bool active)
00169 {
00170     switch (type) {
00171         case WindowContour:
00172             return KDecoration::options()->color(ColorTitleBar, active).dark(190);
00173         case TitleGradientFrom:
00174             return KDecoration::options()->color(ColorTitleBar, active);
00175             break;
00176         case TitleGradientTo:
00177             return alphaBlendColors(KDecoration::options()->color(ColorTitleBar, active),
00178                     Qt::white, active?210:220);
00179             break;
00180         case TitleGradientToTop:
00181             return alphaBlendColors(KDecoration::options()->color(ColorTitleBar, active),
00182                     Qt::white, active?180:190);
00183             break;
00184         case TitleHighlightTop:
00185         case SideHighlightLeft:
00186             return alphaBlendColors(KDecoration::options()->color(ColorTitleBar, active),
00187                     Qt::white, active?150:160);
00188             break;
00189         case SideHighlightRight:
00190         case SideHighlightBottom:
00191             return alphaBlendColors(KDecoration::options()->color(ColorTitleBar, active),
00192                     Qt::black, active?150:160);
00193             break;
00194         case Border:
00195             return KDecoration::options()->color(ColorFrame, active);
00196         case TitleFont:
00197             return KDecoration::options()->color(ColorFont, active);
00198         default:
00199             return Qt::black;
00200     }
00201 }
00202 
00203 QValueList< PlastikHandler::BorderSize >
00204 PlastikHandler::borderSizes() const
00205 {
00206     // the list must be sorted
00207     return QValueList< BorderSize >() << BorderTiny << BorderNormal <<
00208     BorderLarge << BorderVeryLarge <<  BorderHuge <<
00209     BorderVeryHuge << BorderOversized;
00210 }
00211 
00212 } // KWinPlastik
00213 
00215 // Plugin Stuff                                                             //
00217 
00218 static KWinPlastik::PlastikHandler *handler = 0;
00219 
00220 extern "C"
00221 {
00222     KDE_EXPORT KDecorationFactory *create_factory()
00223     {
00224         handler = new KWinPlastik::PlastikHandler();
00225         return handler;
00226     }
00227 }
KDE Logo
This file is part of the documentation for kwin Library Version 3.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jun 14 19:06:09 2006 by doxygen 1.4.4 written by Dimitri van Heesch, © 1997-2003