2003-08-29 22:49:03 +00:00
|
|
|
/* Plastik KWin window decoration
|
|
|
|
Copyright (C) 2003 Sandro Giessl <ceebx@users.sourceforge.net>
|
|
|
|
|
|
|
|
based on the window decoration "Web":
|
|
|
|
Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; see the file COPYING. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <kconfig.h>
|
|
|
|
|
|
|
|
#include "misc.h"
|
|
|
|
#include "plastik.h"
|
|
|
|
#include "plastik.moc"
|
|
|
|
#include "plastikclient.h"
|
|
|
|
|
2003-09-17 18:43:17 +00:00
|
|
|
namespace KWinPlastik
|
|
|
|
{
|
2003-08-29 22:49:03 +00:00
|
|
|
|
|
|
|
// static bool pixmaps_created = false;
|
|
|
|
|
|
|
|
bool PlastikHandler::m_initialized = false;
|
|
|
|
bool PlastikHandler::m_animateButtons = true;
|
|
|
|
bool PlastikHandler::m_titleShadow = true;
|
|
|
|
bool PlastikHandler::m_shrinkBorders = true;
|
2003-09-23 20:39:13 +00:00
|
|
|
bool PlastikHandler::m_menuClose = false;
|
|
|
|
bool PlastikHandler::m_reverse = false;
|
2003-08-29 22:49:03 +00:00
|
|
|
int PlastikHandler::m_borderSize = 4;
|
|
|
|
int PlastikHandler::m_titleHeight = 19;
|
|
|
|
int PlastikHandler::m_titleHeightTool= 12;
|
|
|
|
QFont PlastikHandler::m_titleFont = QFont();
|
|
|
|
QFont PlastikHandler::m_titleFontTool = QFont();
|
|
|
|
Qt::AlignmentFlags PlastikHandler::m_titleAlign = Qt::AlignHCenter;
|
|
|
|
|
|
|
|
PlastikHandler::PlastikHandler()
|
|
|
|
{
|
2003-09-17 18:43:17 +00:00
|
|
|
reset(0);
|
2003-08-29 22:49:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PlastikHandler::~PlastikHandler()
|
|
|
|
{
|
|
|
|
m_initialized = false;
|
|
|
|
}
|
|
|
|
|
2003-09-17 18:43:17 +00:00
|
|
|
bool PlastikHandler::reset(unsigned long changed)
|
2003-08-29 22:49:03 +00:00
|
|
|
{
|
2003-09-17 18:43:17 +00:00
|
|
|
// we assume the active font to be the same as the inactive font since the control
|
|
|
|
// center doesn't offer different settings anyways.
|
|
|
|
m_titleFont = KDecoration::options()->font(true, false); // not small
|
|
|
|
m_titleFontTool = KDecoration::options()->font(true, true); // small
|
|
|
|
|
2003-09-24 18:59:07 +00:00
|
|
|
switch(KDecoration::options()->preferredBorderSize( this )) {
|
2003-09-17 18:43:17 +00:00
|
|
|
case BorderTiny:
|
|
|
|
m_borderSize = 2;
|
|
|
|
break;
|
|
|
|
case BorderLarge:
|
|
|
|
m_borderSize = 8;
|
|
|
|
break;
|
|
|
|
case BorderVeryLarge:
|
|
|
|
m_borderSize = 12;
|
|
|
|
break;
|
|
|
|
case BorderHuge:
|
2003-09-23 14:45:56 +00:00
|
|
|
m_borderSize = 18;
|
|
|
|
break;
|
|
|
|
case BorderVeryHuge:
|
|
|
|
m_borderSize = 27;
|
|
|
|
break;
|
|
|
|
case BorderOversized:
|
|
|
|
m_borderSize = 40;
|
2003-09-17 18:43:17 +00:00
|
|
|
break;
|
|
|
|
case BorderNormal:
|
|
|
|
default:
|
|
|
|
m_borderSize = 4;
|
|
|
|
}
|
2003-08-29 22:49:03 +00:00
|
|
|
|
2003-09-23 20:39:13 +00:00
|
|
|
// check if we are in reverse layout mode
|
|
|
|
m_reverse = QApplication::reverseLayout();
|
|
|
|
|
2003-08-29 22:49:03 +00:00
|
|
|
// read in the configuration
|
|
|
|
readConfig();
|
|
|
|
|
|
|
|
m_initialized = true;
|
2003-09-17 18:43:17 +00:00
|
|
|
|
|
|
|
// Do we need to "hit the wooden hammer" ?
|
|
|
|
bool needHardReset = true;
|
|
|
|
// TODO: besides the Color and Font settings I can maybe handle more changes
|
|
|
|
// without a hard reset. I will do this later...
|
|
|
|
if (changed & SettingColors || changed & SettingFont)
|
|
|
|
{
|
|
|
|
needHardReset = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needHardReset) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
resetDecorations(changed);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KDecoration* PlastikHandler::createDecoration( KDecorationBridge* bridge )
|
|
|
|
{
|
|
|
|
return new PlastikClient( bridge, this );
|
2003-08-29 22:49:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlastikHandler::readConfig()
|
|
|
|
{
|
|
|
|
// create a config object
|
|
|
|
KConfig config("kwinplastikrc");
|
|
|
|
config.setGroup("General");
|
|
|
|
|
|
|
|
// grab settings
|
|
|
|
m_titleShadow = config.readBoolEntry("TitleShadow", true);
|
|
|
|
|
|
|
|
QFontMetrics fm(m_titleFont); // active font = inactive font
|
|
|
|
int titleHeightMin = config.readNumEntry("TitleHeightMin", 19);
|
|
|
|
// The title should strech with bigger font sizes!
|
|
|
|
m_titleHeight = QMAX(titleHeightMin, fm.height() + 4); // 4 px for the shadow etc.
|
|
|
|
|
|
|
|
fm = QFontMetrics(m_titleFontTool); // active font = inactive font
|
|
|
|
int titleHeightToolMin = config.readNumEntry("TitleHeightToolMin", 13);
|
|
|
|
// The title should strech with bigger font sizes!
|
|
|
|
m_titleHeightTool = QMAX(titleHeightToolMin, fm.height() ); // don't care about the shadow etc.
|
|
|
|
|
|
|
|
QString value = config.readEntry("TitleAlignment", "AlignHCenter");
|
|
|
|
if (value == "AlignLeft") m_titleAlign = Qt::AlignLeft;
|
|
|
|
else if (value == "AlignHCenter") m_titleAlign = Qt::AlignHCenter;
|
|
|
|
else if (value == "AlignRight") m_titleAlign = Qt::AlignRight;
|
|
|
|
|
|
|
|
m_animateButtons = config.readBoolEntry("AnimateButtons", true);
|
2003-09-23 20:39:13 +00:00
|
|
|
m_menuClose = config.readBoolEntry("CloseOnMenuDoubleClick", true);
|
2003-08-29 22:49:03 +00:00
|
|
|
}
|
|
|
|
|
2003-09-17 18:43:17 +00:00
|
|
|
QColor PlastikHandler::getColor(KWinPlastik::ColorType type, const bool active)
|
2003-08-29 22:49:03 +00:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case WindowContour:
|
2003-09-17 18:43:17 +00:00
|
|
|
return KDecoration::options()->color(ColorTitleBar, active).dark(190);
|
2003-08-29 22:49:03 +00:00
|
|
|
case TitleGradientFrom:
|
2003-09-17 18:43:17 +00:00
|
|
|
return KDecoration::options()->color(ColorTitleBar, active);
|
2003-08-29 22:49:03 +00:00
|
|
|
break;
|
|
|
|
case TitleGradientTo:
|
2003-09-17 18:43:17 +00:00
|
|
|
return alphaBlendColors(KDecoration::options()->color(ColorTitleBar, active),
|
2003-08-29 22:49:03 +00:00
|
|
|
Qt::white, active?210:220);
|
|
|
|
break;
|
|
|
|
case TitleGradientToTop:
|
2003-09-17 18:43:17 +00:00
|
|
|
return alphaBlendColors(KDecoration::options()->color(ColorTitleBar, active),
|
2003-08-29 22:49:03 +00:00
|
|
|
Qt::white, active?180:190);
|
|
|
|
break;
|
|
|
|
case TitleHighlightTop:
|
|
|
|
case SideHighlightLeft:
|
2003-09-17 18:43:17 +00:00
|
|
|
return alphaBlendColors(KDecoration::options()->color(ColorTitleBar, active),
|
2003-08-29 22:49:03 +00:00
|
|
|
Qt::white, active?150:160);
|
|
|
|
break;
|
|
|
|
case SideHighlightRight:
|
|
|
|
case SideHighlightBottom:
|
2003-09-17 18:43:17 +00:00
|
|
|
return alphaBlendColors(KDecoration::options()->color(ColorTitleBar, active),
|
2003-08-29 22:49:03 +00:00
|
|
|
Qt::black, active?150:160);
|
|
|
|
break;
|
|
|
|
case Border:
|
2003-09-17 18:43:17 +00:00
|
|
|
return KDecoration::options()->color(ColorFrame, active);
|
2003-08-29 22:49:03 +00:00
|
|
|
case TitleFont:
|
2003-09-17 18:43:17 +00:00
|
|
|
return KDecoration::options()->color(ColorFont, active);
|
2003-08-29 22:49:03 +00:00
|
|
|
default:
|
|
|
|
return Qt::black;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-24 20:02:35 +00:00
|
|
|
QValueList< PlastikHandler::BorderSize >
|
|
|
|
PlastikHandler::borderSizes() const
|
|
|
|
{
|
|
|
|
// the list must be sorted
|
|
|
|
return QValueList< BorderSize >() << BorderTiny << BorderNormal <<
|
|
|
|
BorderLarge << BorderVeryLarge << BorderHuge <<
|
|
|
|
BorderVeryHuge << BorderOversized;
|
|
|
|
}
|
|
|
|
|
2003-09-17 18:43:17 +00:00
|
|
|
} // KWinPlastik
|
|
|
|
|
2003-08-29 22:49:03 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Plugin Stuff //
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2003-09-17 18:43:17 +00:00
|
|
|
static KWinPlastik::PlastikHandler *handler = 0;
|
2003-08-29 22:49:03 +00:00
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
2003-09-17 18:43:17 +00:00
|
|
|
KDecorationFactory *create_factory()
|
2003-08-29 22:49:03 +00:00
|
|
|
{
|
2003-09-17 18:43:17 +00:00
|
|
|
handler = new KWinPlastik::PlastikHandler();
|
|
|
|
return handler;
|
2003-08-29 22:49:03 +00:00
|
|
|
}
|
|
|
|
}
|