2009-09-14 19:21:39 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2009-09-15 07:12:54 +00:00
|
|
|
// oxygenshadowconfiguration.cpp
|
2009-09-14 19:21:39 +00:00
|
|
|
// -------------------
|
|
|
|
//
|
|
|
|
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-09-16 06:09:31 +00:00
|
|
|
#include "oxygenshadowconfiguration.h"
|
|
|
|
|
2009-09-14 19:21:39 +00:00
|
|
|
#include <cassert>
|
|
|
|
#include <kdecoration.h>
|
|
|
|
|
2009-09-15 07:12:54 +00:00
|
|
|
namespace Oxygen
|
2009-09-14 19:21:39 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenShadowConfiguration::OxygenShadowConfiguration( QPalette::ColorGroup colorGroup ):
|
2009-09-14 19:21:39 +00:00
|
|
|
colorGroup_( colorGroup ),
|
|
|
|
shadowSize_( 25.5 ),
|
|
|
|
horizontalOffset_( 0 ),
|
|
|
|
useOuterColor_( false )
|
|
|
|
{
|
|
|
|
|
|
|
|
// check colorgroup
|
2009-09-14 22:36:29 +00:00
|
|
|
assert( colorGroup == QPalette::Active || colorGroup == QPalette::Inactive );
|
2009-09-14 19:21:39 +00:00
|
|
|
|
|
|
|
// vertical offset
|
2009-09-15 07:12:54 +00:00
|
|
|
verticalOffset_ = ( OxygenShadowConfiguration::colorGroup() == QPalette::Active ) ? 0:0.2;
|
2009-09-14 19:21:39 +00:00
|
|
|
|
|
|
|
// colors
|
2009-09-15 07:12:54 +00:00
|
|
|
innerColor_ = ( OxygenShadowConfiguration::colorGroup() == QPalette::Active ) ?
|
2009-09-14 19:21:39 +00:00
|
|
|
KDecoration::options()->color( KDecorationDefines::ColorTitleBar, true ):
|
|
|
|
QColor( Qt::black );
|
|
|
|
|
|
|
|
outerColor_ = outerColor2_ = calcOuterColor();
|
|
|
|
midColor_ = calcMidColor();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenShadowConfiguration::OxygenShadowConfiguration( QPalette::ColorGroup colorGroup, KConfigGroup group ):
|
2009-09-14 19:21:39 +00:00
|
|
|
colorGroup_( colorGroup )
|
|
|
|
{
|
|
|
|
|
|
|
|
// get default configuration
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenShadowConfiguration defaultConfiguration( OxygenShadowConfiguration::colorGroup() );
|
|
|
|
|
|
|
|
setShadowSize( group.readEntry( OxygenConfig::SHADOW_SIZE, defaultConfiguration.shadowSize() ) );
|
|
|
|
setHorizontalOffset( group.readEntry( OxygenConfig::SHADOW_HOFFSET, defaultConfiguration.horizontalOffset() ) );
|
|
|
|
setVerticalOffset( group.readEntry( OxygenConfig::SHADOW_VOFFSET, defaultConfiguration.verticalOffset() ) );
|
|
|
|
setInnerColor( group.readEntry( OxygenConfig::SHADOW_INNER_COLOR, defaultConfiguration.innerColor() ) );
|
|
|
|
setOuterColor( group.readEntry( OxygenConfig::SHADOW_OUTER_COLOR, defaultConfiguration.outerColor() ) );
|
|
|
|
setUseOuterColor( group.readEntry( OxygenConfig::SHADOW_USE_OUTER_COLOR, defaultConfiguration.useOuterColor() ) );
|
2009-09-14 19:21:39 +00:00
|
|
|
setOuterColor2( calcOuterColor() );
|
|
|
|
setMidColor( calcMidColor() );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
bool OxygenShadowConfiguration::operator == ( const OxygenShadowConfiguration& other ) const
|
2009-09-14 19:21:39 +00:00
|
|
|
{
|
|
|
|
assert( colorGroup() == other.colorGroup() );
|
|
|
|
return
|
|
|
|
shadowSize() == other.shadowSize() &&
|
|
|
|
horizontalOffset() == other.horizontalOffset() &&
|
|
|
|
verticalOffset() == other.verticalOffset() &&
|
|
|
|
innerColor() == other.innerColor() &&
|
|
|
|
outerColor() == other.outerColor() &&
|
|
|
|
useOuterColor() == other.useOuterColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenShadowConfiguration::write( KConfigGroup& group ) const
|
2009-09-14 19:21:39 +00:00
|
|
|
{
|
2009-09-15 07:12:54 +00:00
|
|
|
group.writeEntry( OxygenConfig::SHADOW_SIZE, shadowSize() );
|
|
|
|
group.writeEntry( OxygenConfig::SHADOW_HOFFSET, horizontalOffset() );
|
|
|
|
group.writeEntry( OxygenConfig::SHADOW_VOFFSET, verticalOffset() );
|
|
|
|
group.writeEntry( OxygenConfig::SHADOW_INNER_COLOR, innerColor().name() );
|
|
|
|
group.writeEntry( OxygenConfig::SHADOW_OUTER_COLOR, outerColor().name() );
|
|
|
|
group.writeEntry( OxygenConfig::SHADOW_USE_OUTER_COLOR, useOuterColor() );
|
2009-09-14 19:21:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenShadowConfiguration::setInnerColor( QColor color )
|
|
|
|
{ innerColor_ = color.isValid() ? color : OxygenShadowConfiguration( colorGroup() ).innerColor(); }
|
2009-09-14 19:21:39 +00:00
|
|
|
|
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenShadowConfiguration::setMidColor( QColor color )
|
|
|
|
{ midColor_ = color.isValid() ? color : OxygenShadowConfiguration( colorGroup() ).midColor(); }
|
2009-09-14 19:21:39 +00:00
|
|
|
|
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenShadowConfiguration::setOuterColor( QColor color )
|
|
|
|
{ outerColor_ = color.isValid() ? color : OxygenShadowConfiguration( colorGroup() ).outerColor(); }
|
2009-09-14 19:21:39 +00:00
|
|
|
|
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenShadowConfiguration::setOuterColor2( QColor color )
|
|
|
|
{ outerColor2_ = color.isValid() ? color : OxygenShadowConfiguration( colorGroup() ).outerColor2(); }
|
2009-09-14 19:21:39 +00:00
|
|
|
|
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
QColor OxygenShadowConfiguration::calcOuterColor( void ) const
|
2009-09-14 19:21:39 +00:00
|
|
|
{
|
2009-09-15 07:12:54 +00:00
|
|
|
QColor innerColor( OxygenShadowConfiguration::innerColor() );
|
2009-09-14 19:21:39 +00:00
|
|
|
assert( innerColor.isValid() );
|
|
|
|
|
|
|
|
// should contain a more ellaborate mathematical formula
|
|
|
|
// to calculate outer color from inner color
|
|
|
|
return innerColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
QColor OxygenShadowConfiguration::calcMidColor( void ) const
|
2009-09-14 19:21:39 +00:00
|
|
|
{
|
2009-09-15 07:12:54 +00:00
|
|
|
QColor innerColor( OxygenShadowConfiguration::innerColor() );
|
|
|
|
QColor outerColor( OxygenShadowConfiguration::outerColor() );
|
2009-09-14 19:21:39 +00:00
|
|
|
assert( innerColor.isValid() && outerColor.isValid() );
|
|
|
|
|
|
|
|
// should contain a more ellaborate mathematical formula
|
|
|
|
// to calculate mid color from inner and outer colors
|
|
|
|
return outerColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|