2007-04-29 17:35:43 +00:00
|
|
|
/*****************************************************************
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
copy of this software and associated documentation files (the "Software"),
|
|
|
|
to deal in the Software without restriction, including without limitation
|
|
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
DEALINGS IN THE SOFTWARE.
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
#include "kdecoration_p.h"
|
|
|
|
|
|
|
|
#include <kconfig.h>
|
2007-10-05 22:21:25 +00:00
|
|
|
#include <kconfiggroup.h>
|
2013-09-02 09:22:59 +00:00
|
|
|
#include <QFontDatabase>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <QPalette>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
KDecorationOptionsPrivate::KDecorationOptionsPrivate()
|
2011-01-30 14:34:42 +00:00
|
|
|
: title_buttons_left(KDecorationOptions::defaultTitleButtonsLeft())
|
|
|
|
, title_buttons_right(KDecorationOptions::defaultTitleButtonsRight())
|
|
|
|
, custom_button_positions(false)
|
|
|
|
, show_tooltips(true)
|
|
|
|
, border_size(BorderNormal)
|
|
|
|
, cached_border_size(BordersCount) // invalid
|
|
|
|
, opMaxButtonRightClick(MaximizeOp)
|
|
|
|
, opMaxButtonMiddleClick(VMaximizeOp)
|
|
|
|
, opMaxButtonLeftClick(HMaximizeOp)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < NUM_COLORS * 2; ++i)
|
2007-04-29 17:35:43 +00:00
|
|
|
pal[i] = NULL;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
KDecorationOptionsPrivate::~KDecorationOptionsPrivate()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
int i;
|
2011-01-30 14:34:42 +00:00
|
|
|
for (i = 0; i < NUM_COLORS * 2; ++i) {
|
|
|
|
if (pal[i]) {
|
2007-04-29 17:35:43 +00:00
|
|
|
delete pal[i];
|
|
|
|
pal[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
unsigned long KDecorationOptionsPrivate::updateSettings(KConfig* config)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
unsigned long changed = 0;
|
|
|
|
KConfigGroup wmConfig(config, "WM");
|
|
|
|
|
|
|
|
// SettingColors
|
|
|
|
QColor old_colors[NUM_COLORS*2];
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0;
|
|
|
|
i < NUM_COLORS * 2;
|
|
|
|
++i)
|
2007-04-29 17:35:43 +00:00
|
|
|
old_colors[ i ] = colors[ i ];
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
QPalette appPal = QApplication::palette();
|
|
|
|
// normal colors
|
2011-01-30 14:34:42 +00:00
|
|
|
colors[ColorFrame] = appPal.color(QPalette::Active, QPalette::Background);
|
2007-04-29 17:35:43 +00:00
|
|
|
colors[ColorFrame] = wmConfig.readEntry("frame", colors[ColorFrame]);
|
|
|
|
colors[ColorHandle] = colors[ColorFrame];
|
|
|
|
colors[ColorHandle] = wmConfig.readEntry("handle", colors[ColorHandle]);
|
|
|
|
|
|
|
|
// full button configuration (background, blend, and foreground
|
2011-01-30 14:34:42 +00:00
|
|
|
if (QPixmap::defaultDepth() > 8)
|
2007-04-29 17:35:43 +00:00
|
|
|
colors[ColorButtonBg] = colors[ColorFrame].light(130);
|
|
|
|
else
|
|
|
|
colors[ColorButtonBg] = colors[ColorFrame];
|
|
|
|
colors[ColorButtonBg] = wmConfig.readEntry("activeTitleBtnBg",
|
2011-01-30 14:34:42 +00:00
|
|
|
colors[ColorFrame]);
|
|
|
|
colors[ColorTitleBar] = appPal.color(QPalette::Active, QPalette::Highlight);
|
2007-04-29 17:35:43 +00:00
|
|
|
colors[ColorTitleBar] = wmConfig.readEntry("activeBackground",
|
2011-01-30 14:34:42 +00:00
|
|
|
colors[ColorTitleBar]);
|
|
|
|
if (QPixmap::defaultDepth() > 8)
|
2007-04-29 17:35:43 +00:00
|
|
|
colors[ColorTitleBlend] = colors[ ColorTitleBar ].dark(110);
|
|
|
|
else
|
|
|
|
colors[ColorTitleBlend] = colors[ ColorTitleBar ];
|
|
|
|
colors[ColorTitleBlend] = wmConfig.readEntry("activeBlend",
|
2011-01-30 14:34:42 +00:00
|
|
|
colors[ColorTitleBlend]);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
colors[ColorFont] = appPal.color(QPalette::Active, QPalette::HighlightedText);
|
2007-04-29 17:35:43 +00:00
|
|
|
colors[ColorFont] = wmConfig.readEntry("activeForeground", colors[ColorFont]);
|
|
|
|
|
|
|
|
// inactive
|
|
|
|
colors[ColorFrame+NUM_COLORS] = wmConfig.readEntry("inactiveFrame",
|
2011-01-30 14:34:42 +00:00
|
|
|
colors[ColorFrame]);
|
2007-04-29 17:35:43 +00:00
|
|
|
colors[ColorTitleBar+NUM_COLORS] = colors[ColorFrame];
|
|
|
|
colors[ColorTitleBar+NUM_COLORS] = wmConfig.
|
2011-01-30 14:34:42 +00:00
|
|
|
readEntry("inactiveBackground", colors[ColorTitleBar+NUM_COLORS]);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (QPixmap::defaultDepth() > 8)
|
2007-04-29 17:35:43 +00:00
|
|
|
colors[ColorTitleBlend+NUM_COLORS] = colors[ ColorTitleBar+NUM_COLORS ].dark(110);
|
|
|
|
else
|
|
|
|
colors[ColorTitleBlend+NUM_COLORS] = colors[ ColorTitleBar+NUM_COLORS ];
|
|
|
|
colors[ColorTitleBlend+NUM_COLORS] =
|
|
|
|
wmConfig.readEntry("inactiveBlend", colors[ColorTitleBlend+NUM_COLORS]);
|
|
|
|
|
|
|
|
// full button configuration
|
2011-01-30 14:34:42 +00:00
|
|
|
if (QPixmap::defaultDepth() > 8)
|
2007-04-29 17:35:43 +00:00
|
|
|
colors[ColorButtonBg+NUM_COLORS] = colors[ColorFrame+NUM_COLORS].light(130);
|
|
|
|
else
|
|
|
|
colors[ColorButtonBg+NUM_COLORS] = colors[ColorFrame+NUM_COLORS];
|
|
|
|
colors[ColorButtonBg+NUM_COLORS] =
|
|
|
|
wmConfig.readEntry("inactiveTitleBtnBg",
|
2011-01-30 14:34:42 +00:00
|
|
|
colors[ColorButtonBg]);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
colors[ColorHandle+NUM_COLORS] =
|
|
|
|
wmConfig.readEntry("inactiveHandle", colors[ColorHandle]);
|
|
|
|
|
|
|
|
colors[ColorFont+NUM_COLORS] = colors[ColorFrame].dark();
|
|
|
|
colors[ColorFont+NUM_COLORS] = wmConfig.readEntry("inactiveForeground",
|
2011-01-30 14:34:42 +00:00
|
|
|
colors[ColorFont+NUM_COLORS]);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0;
|
|
|
|
i < NUM_COLORS * 2;
|
|
|
|
++i)
|
|
|
|
if (old_colors[ i ] != colors[ i ])
|
2007-04-29 17:35:43 +00:00
|
|
|
changed |= SettingColors;
|
|
|
|
|
|
|
|
// SettingFont
|
|
|
|
QFont old_activeFont = activeFont;
|
|
|
|
QFont old_inactiveFont = inactiveFont;
|
|
|
|
QFont old_activeFontSmall = activeFontSmall;
|
|
|
|
QFont old_inactiveFontSmall = inactiveFontSmall;
|
|
|
|
|
2013-09-02 09:22:59 +00:00
|
|
|
QFont activeFontGuess = QFontDatabase::systemFont(QFontDatabase::TitleFont);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
activeFont = wmConfig.readEntry("activeFont", activeFontGuess);
|
|
|
|
inactiveFont = wmConfig.readEntry("inactiveFont", activeFont);
|
|
|
|
|
|
|
|
activeFontSmall = activeFont;
|
2009-10-05 06:59:10 +00:00
|
|
|
// TODO: Is it useful ? (Temporary hack)
|
|
|
|
//activeFontSmall.setPointSize(activeFont.pointSize() - 2 > 0 ? activeFont.pointSize() - 2 : activeFont.pointSize()+1 );
|
2007-04-29 17:35:43 +00:00
|
|
|
activeFontSmall = wmConfig.readEntry("activeFontSmall", activeFontSmall);
|
|
|
|
inactiveFontSmall = wmConfig.readEntry("inactiveFontSmall", activeFontSmall);
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (old_activeFont != activeFont
|
|
|
|
|| old_inactiveFont != inactiveFont
|
|
|
|
|| old_activeFontSmall != activeFontSmall
|
|
|
|
|| old_inactiveFontSmall != inactiveFontSmall)
|
2007-04-29 17:35:43 +00:00
|
|
|
changed |= SettingFont;
|
|
|
|
|
|
|
|
KConfigGroup styleConfig(config, "Style");
|
2011-01-30 14:34:42 +00:00
|
|
|
// SettingsButtons
|
2007-04-29 17:35:43 +00:00
|
|
|
QString old_title_buttons_left = title_buttons_left;
|
|
|
|
QString old_title_buttons_right = title_buttons_right;
|
|
|
|
bool old_custom_button_positions = custom_button_positions;
|
|
|
|
custom_button_positions = styleConfig.readEntry("CustomButtonPositions", false);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (custom_button_positions) {
|
2007-11-15 20:13:50 +00:00
|
|
|
title_buttons_left = styleConfig.readEntry("ButtonsOnLeft", KDecorationOptions::defaultTitleButtonsLeft());
|
|
|
|
title_buttons_right = styleConfig.readEntry("ButtonsOnRight", KDecorationOptions::defaultTitleButtonsRight());
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2007-11-15 20:13:50 +00:00
|
|
|
title_buttons_left = KDecorationOptions::defaultTitleButtonsLeft();
|
|
|
|
title_buttons_right = KDecorationOptions::defaultTitleButtonsRight();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (old_custom_button_positions != custom_button_positions
|
|
|
|
|| (custom_button_positions &&
|
|
|
|
(old_title_buttons_left != title_buttons_left
|
|
|
|
|| old_title_buttons_right != title_buttons_right)))
|
2007-04-29 17:35:43 +00:00
|
|
|
changed |= SettingButtons;
|
|
|
|
|
|
|
|
// SettingTooltips
|
|
|
|
bool old_show_tooltips = show_tooltips;
|
|
|
|
show_tooltips = styleConfig.readEntry("ShowToolTips", true);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (old_show_tooltips != show_tooltips)
|
2007-04-29 17:35:43 +00:00
|
|
|
changed |= SettingTooltips;
|
|
|
|
|
|
|
|
// SettingBorder
|
|
|
|
|
|
|
|
BorderSize old_border_size = border_size;
|
2011-01-30 14:34:42 +00:00
|
|
|
int border_size_num = styleConfig.readEntry("BorderSize", (int)BorderNormal);
|
|
|
|
if (border_size_num >= 0 && border_size_num < BordersCount)
|
|
|
|
border_size = static_cast< BorderSize >(border_size_num);
|
2007-04-29 17:35:43 +00:00
|
|
|
else
|
|
|
|
border_size = BorderNormal;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (old_border_size != border_size)
|
2007-04-29 17:35:43 +00:00
|
|
|
changed |= SettingBorder;
|
|
|
|
cached_border_size = BordersCount; // invalid
|
|
|
|
|
|
|
|
// destroy cached values
|
|
|
|
int i;
|
2011-01-30 14:34:42 +00:00
|
|
|
for (i = 0; i < NUM_COLORS * 2; ++i) {
|
|
|
|
if (pal[i]) {
|
2007-04-29 17:35:43 +00:00
|
|
|
delete pal[i];
|
|
|
|
pal[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
KDecorationDefines::BorderSize KDecorationOptionsPrivate::findPreferredBorderSize(BorderSize size,
|
|
|
|
QList< BorderSize > sizes) const
|
|
|
|
{
|
|
|
|
for (QList< BorderSize >::ConstIterator it = sizes.constBegin();
|
|
|
|
it != sizes.constEnd();
|
|
|
|
++it)
|
|
|
|
if (size <= *it) // size is either a supported size, or *it is the closest larger supported
|
2007-04-29 17:35:43 +00:00
|
|
|
return *it;
|
|
|
|
return sizes.last(); // size is larger than all supported ones, return largest
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|