2009-08-22 08:24:06 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2009-09-15 07:12:54 +00:00
|
|
|
// oxygenclient.cpp
|
2009-08-22 08:24:06 +00:00
|
|
|
// -------------------
|
2009-09-09 00:55:55 +00:00
|
|
|
//
|
2009-08-24 16:14:11 +00:00
|
|
|
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
2009-08-25 04:15:13 +00:00
|
|
|
// Copyright (c) 2006, 2007 Casper Boemann <cbr@boemann.dk>
|
|
|
|
// Copyright (c) 2006, 2007 Riccardo Iaconelli <riccardo@kde.org>
|
2009-08-22 08:24:06 +00:00
|
|
|
//
|
|
|
|
// 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
|
2009-09-09 00:55:55 +00:00
|
|
|
// IN THE SOFTWARE.
|
2009-08-22 08:24:06 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-09-16 06:09:31 +00:00
|
|
|
#include "oxygenclient.h"
|
|
|
|
#include "oxygenclient.moc"
|
|
|
|
|
|
|
|
#include "oxygen.h"
|
|
|
|
#include "oxygenbutton.h"
|
2009-09-17 22:40:06 +00:00
|
|
|
#include "oxygenshadowcache.h"
|
2009-09-16 06:09:31 +00:00
|
|
|
#include "oxygensizegrip.h"
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
#include <cassert>
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
#include <kdeversion.h>
|
|
|
|
#include <KLocale>
|
|
|
|
#include <KColorUtils>
|
2009-09-07 02:26:37 +00:00
|
|
|
#include <KDebug>
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2009-09-20 07:42:03 +00:00
|
|
|
#include <QtGui/QLabel>
|
|
|
|
#include <QtGui/QPainter>
|
|
|
|
#include <QtGui/QApplication>
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2009-09-15 07:12:54 +00:00
|
|
|
namespace Oxygen
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________
|
|
|
|
static void oxkwincleanupBefore()
|
|
|
|
{
|
2009-09-17 22:40:06 +00:00
|
|
|
|
2009-09-26 04:23:27 +00:00
|
|
|
oxygenHelper()->invalidateCaches();
|
|
|
|
oxygenShadowCache()->invalidateCaches();
|
2009-09-17 22:40:06 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________
|
|
|
|
void renderDot(QPainter *p, const QPointF &point, qreal diameter)
|
|
|
|
{
|
|
|
|
p->drawEllipse(QRectF(point.x()-diameter/2, point.y()-diameter/2, diameter, diameter));
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenClient::OxygenClient(KDecorationBridge *b, KDecorationFactory *f):
|
2009-09-09 00:55:55 +00:00
|
|
|
KCommonDecorationUnstable(b, f),
|
2009-08-22 08:24:06 +00:00
|
|
|
colorCacheInvalid_(true),
|
2009-09-14 23:10:19 +00:00
|
|
|
sizeGrip_( 0 ),
|
2009-09-18 01:32:27 +00:00
|
|
|
timeLine_( 200, this ),
|
2009-10-02 02:52:41 +00:00
|
|
|
titleTimeLine_( 200, this ),
|
2009-09-26 04:23:27 +00:00
|
|
|
helper_(*oxygenHelper()),
|
2009-08-22 08:24:06 +00:00
|
|
|
initialized_( false )
|
|
|
|
{ qAddPostRoutine(oxkwincleanupBefore); }
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenClient::~OxygenClient()
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// delete sizegrip if any
|
|
|
|
if( hasSizeGrip() ) deleteSizeGrip();
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
QString OxygenClient::visibleName() const
|
2009-09-15 06:25:06 +00:00
|
|
|
{ return i18n("Oxygen"); }
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenClient::init()
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
KCommonDecoration::init();
|
|
|
|
widget()->setAttribute(Qt::WA_NoSystemBackground );
|
|
|
|
widget()->setAutoFillBackground( false );
|
2009-09-18 01:32:27 +00:00
|
|
|
|
|
|
|
// initialize timeLine
|
|
|
|
timeLine_.setFrameRange( 0, maxAnimationIndex );
|
|
|
|
timeLine_.setCurveShape( QTimeLine::EaseInOutCurve );
|
|
|
|
connect( &timeLine_, SIGNAL( frameChanged( int ) ), widget(), SLOT( update() ) );
|
|
|
|
connect( &timeLine_, SIGNAL( finished() ), widget(), SLOT( update() ) );
|
|
|
|
|
2009-10-02 02:52:41 +00:00
|
|
|
// initialize titleTimeLine
|
|
|
|
titleTimeLine_.setFrameRange( 0, maxAnimationIndex );
|
|
|
|
titleTimeLine_.setCurveShape( QTimeLine::EaseInOutCurve );
|
|
|
|
connect( &titleTimeLine_, SIGNAL( frameChanged( int ) ), widget(), SLOT( update() ) );
|
|
|
|
connect( &titleTimeLine_, SIGNAL( finished() ), widget(), SLOT( update() ) );
|
|
|
|
connect( &titleTimeLine_, SIGNAL( finished() ), this, SLOT( updateOldCaption() ) );
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
initialized_ = true;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-06 18:29:57 +00:00
|
|
|
// in case of preview, one wants to make the label used
|
|
|
|
// for the central widget transparent. This allows one to have
|
|
|
|
// the correct background (with gradient) rendered
|
2009-09-09 00:55:55 +00:00
|
|
|
// Remark: this is minor (and safe) a hack.
|
2009-09-06 18:29:57 +00:00
|
|
|
// This should be moved upstream (into kwin/lib/kdecoration)
|
2009-09-09 00:55:55 +00:00
|
|
|
if( isPreview() )
|
|
|
|
{
|
|
|
|
|
2009-09-06 18:29:57 +00:00
|
|
|
QList<QLabel*> children( widget()->findChildren<QLabel*>() );
|
2009-09-16 06:09:31 +00:00
|
|
|
for( QList<QLabel*>::iterator iter = children.begin(); iter != children.end(); ++iter )
|
2009-09-06 18:29:57 +00:00
|
|
|
{ (*iter)->setAutoFillBackground( false ); }
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-06 18:29:57 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
resetConfiguration();
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-10 05:13:25 +00:00
|
|
|
//___________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenClient::reset( unsigned long changed )
|
2009-09-10 05:13:25 +00:00
|
|
|
{
|
|
|
|
if( changed & SettingCompositing )
|
|
|
|
{
|
|
|
|
updateWindowShape();
|
|
|
|
widget()->update();
|
|
|
|
}
|
2009-09-14 19:21:39 +00:00
|
|
|
|
2009-09-10 05:13:25 +00:00
|
|
|
KCommonDecorationUnstable::reset( changed );
|
|
|
|
}
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
bool OxygenClient::decorationBehaviour(DecorationBehaviour behaviour) const
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
switch (behaviour)
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case DB_MenuClose:
|
|
|
|
return true;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case DB_WindowMask:
|
|
|
|
return false;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
default:
|
|
|
|
return KCommonDecoration::decorationBehaviour(behaviour);
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
int OxygenClient::layoutMetric(LayoutMetric lm, bool respectWindowState, const KCommonDecorationButton *btn) const
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
bool maximized( isMaximized() );
|
|
|
|
int frameBorder( configuration().frameBorder() );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-24 16:14:11 +00:00
|
|
|
// used to increase hit area on the sides of the widget
|
|
|
|
int extraBorder = (maximized && compositingActive()) ? 0 : EXTENDED_HITAREA;
|
2009-08-22 08:24:06 +00:00
|
|
|
int buttonSize( configuration().buttonSize() );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
switch (lm)
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
|
|
|
case LM_BorderLeft:
|
|
|
|
case LM_BorderRight:
|
|
|
|
case LM_BorderBottom:
|
|
|
|
{
|
2009-08-24 16:14:11 +00:00
|
|
|
int border( 0 );
|
2009-09-20 17:51:06 +00:00
|
|
|
if( respectWindowState && maximized && lm != LM_BorderBottom )
|
|
|
|
{
|
|
|
|
|
2009-08-24 16:14:11 +00:00
|
|
|
border = 0;
|
2009-09-20 17:51:06 +00:00
|
|
|
|
2009-09-15 07:12:54 +00:00
|
|
|
} else if( lm == LM_BorderBottom && frameBorder >= OxygenConfiguration::BorderNoSide ) {
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
// for tiny border, the convention is to have a larger bottom area in order to
|
2009-09-04 01:50:20 +00:00
|
|
|
// make resizing easier
|
|
|
|
border = qMax(frameBorder, 4);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-15 07:12:54 +00:00
|
|
|
} else if( frameBorder < OxygenConfiguration::BorderTiny ) {
|
2009-09-09 16:28:01 +00:00
|
|
|
|
2009-09-09 07:40:07 +00:00
|
|
|
border = 0;
|
2009-09-09 16:28:01 +00:00
|
|
|
|
2009-09-04 01:50:20 +00:00
|
|
|
} else {
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
border = frameBorder;
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-24 16:14:11 +00:00
|
|
|
return border + extraBorder;
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case LM_TitleEdgeTop:
|
|
|
|
{
|
2009-08-24 16:14:11 +00:00
|
|
|
int border = 0;
|
2009-09-09 00:55:55 +00:00
|
|
|
if( !( respectWindowState && maximized ))
|
|
|
|
{
|
|
|
|
border = TFRAMESIZE;
|
2009-09-05 03:12:26 +00:00
|
|
|
if( configuration().drawTitleOutline() ) border += HFRAMESIZE/2;
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-24 16:14:11 +00:00
|
|
|
return border + extraBorder;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case LM_TitleEdgeBottom:
|
|
|
|
{
|
2009-09-04 18:58:40 +00:00
|
|
|
if( configuration().drawTitleOutline() ) return HFRAMESIZE/2;
|
|
|
|
else return 0;
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case LM_TitleEdgeLeft:
|
|
|
|
case LM_TitleEdgeRight:
|
|
|
|
{
|
2009-08-24 16:14:11 +00:00
|
|
|
int border = 0;
|
2009-09-09 00:55:55 +00:00
|
|
|
if( !(respectWindowState && maximized) )
|
2009-08-24 16:14:11 +00:00
|
|
|
{ border = 6; }
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-24 16:14:11 +00:00
|
|
|
return border + extraBorder;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case LM_TitleBorderLeft:
|
|
|
|
case LM_TitleBorderRight:
|
2009-09-04 18:58:40 +00:00
|
|
|
{
|
|
|
|
int border = 5;
|
|
|
|
if( configuration().drawTitleOutline() ) border += 2*HFRAMESIZE;
|
|
|
|
return border;
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case LM_ButtonWidth:
|
|
|
|
case LM_ButtonHeight:
|
|
|
|
case LM_TitleHeight:
|
|
|
|
{
|
|
|
|
if (respectWindowState && isToolWindow()) {
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
return buttonSize;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
} else {
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
return buttonSize;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case LM_ButtonSpacing:
|
|
|
|
return 1;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case LM_ButtonMarginTop:
|
|
|
|
return 0;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// outer margin for shadow/glow
|
|
|
|
case LM_OuterPaddingLeft:
|
|
|
|
case LM_OuterPaddingRight:
|
|
|
|
case LM_OuterPaddingTop:
|
|
|
|
case LM_OuterPaddingBottom:
|
2009-09-17 22:40:06 +00:00
|
|
|
return oxygenShadowCache()->shadowSize() - extraBorder;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
default:
|
|
|
|
return KCommonDecoration::layoutMetric(lm, respectWindowState, btn);
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
KCommonDecorationButton *OxygenClient::createButton(::ButtonType type)
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case MenuButton:
|
2009-09-15 07:12:54 +00:00
|
|
|
return new OxygenButton(*this, i18n("Menu"), ButtonMenu);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case HelpButton:
|
2009-09-15 07:12:54 +00:00
|
|
|
return new OxygenButton(*this, i18n("Help"), ButtonHelp);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case MinButton:
|
2009-09-15 07:12:54 +00:00
|
|
|
return new OxygenButton(*this, i18n("Minimize"), ButtonMin);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case MaxButton:
|
2009-09-15 07:12:54 +00:00
|
|
|
return new OxygenButton(*this, i18n("Maximize"), ButtonMax);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case CloseButton:
|
2009-09-15 07:12:54 +00:00
|
|
|
return new OxygenButton(*this, i18n("Close"), ButtonClose);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case AboveButton:
|
2009-09-15 07:12:54 +00:00
|
|
|
return new OxygenButton(*this, i18n("Keep Above Others"), ButtonAbove);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case BelowButton:
|
2009-09-15 07:12:54 +00:00
|
|
|
return new OxygenButton(*this, i18n("Keep Below Others"), ButtonBelow);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case OnAllDesktopsButton:
|
2009-09-15 07:12:54 +00:00
|
|
|
return new OxygenButton(*this, i18n("On All Desktops"), ButtonSticky);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case ShadeButton:
|
2009-09-15 07:12:54 +00:00
|
|
|
return new OxygenButton(*this, i18n("Shade Button"), ButtonShade);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//_________________________________________________________
|
|
|
|
QColor reduceContrast(const QColor &c0, const QColor &c1, double t)
|
|
|
|
{
|
|
|
|
double s = KColorUtils::contrastRatio(c0, c1);
|
|
|
|
if (s < t)
|
|
|
|
return c1;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
double l = 0.0, h = 1.0;
|
|
|
|
double x = s, a;
|
|
|
|
QColor r = c1;
|
2009-09-09 00:55:55 +00:00
|
|
|
for (int maxiter = 16; maxiter; --maxiter)
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
a = 0.5 * (l + h);
|
|
|
|
r = KColorUtils::mix(c0, c1, a);
|
|
|
|
x = KColorUtils::contrastRatio(c0, r);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
if (fabs(x - t) < 0.01) break;
|
|
|
|
if (x > t) h = a;
|
|
|
|
else l = a;
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
return r;
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
QRegion OxygenClient::calcMask( void ) const
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
if( isMaximized() )
|
2009-08-22 08:24:06 +00:00
|
|
|
{ return widget()->rect(); }
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
QRect frame( widget()->rect() );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// dimensions
|
|
|
|
int w=frame.width();
|
|
|
|
int h=frame.height();
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// multipliers
|
|
|
|
int left = 1;
|
|
|
|
int right = 1;
|
|
|
|
int top = 1;
|
|
|
|
int bottom = 1;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-05 20:04:17 +00:00
|
|
|
// disable bottom corners when border frame is too small and window is not shaded
|
2009-09-15 07:12:54 +00:00
|
|
|
if( configuration().frameBorder() == OxygenConfiguration::BorderNone && !isShade() ) bottom = 0;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
int sw = layoutMetric( LM_OuterPaddingLeft );
|
|
|
|
int sh = layoutMetric( LM_OuterPaddingTop );
|
|
|
|
|
|
|
|
w -= sw + layoutMetric( LM_OuterPaddingRight );
|
|
|
|
h -= sh + layoutMetric( LM_OuterPaddingBottom );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
|
2009-09-02 20:20:18 +00:00
|
|
|
QRegion mask(sw + 4*left, sh + 0*top, w-4*(left+right), h-0*(top+bottom));
|
|
|
|
mask += QRegion(sw + 0*left, sh + 4*top, w-0*(left+right), h-4*(top+bottom));
|
|
|
|
mask += QRegion(sw + 2*left, sh + 1*top, w-2*(left+right), h-1*(top+bottom));
|
2009-09-09 00:55:55 +00:00
|
|
|
mask += QRegion(sw + 1*left, sh + 2*top, w-1*(left+right), h-2*(top+bottom));
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
return mask;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
QColor OxygenClient::titlebarTextColor(const QPalette &palette)
|
2009-09-18 19:47:53 +00:00
|
|
|
{
|
|
|
|
if( timeLineIsRunning() ) return KColorUtils::mix(
|
|
|
|
titlebarTextColor( palette, false ),
|
|
|
|
titlebarTextColor( palette, true ),
|
|
|
|
opacity() );
|
|
|
|
else return titlebarTextColor( palette, isActive() );
|
|
|
|
}
|
|
|
|
|
|
|
|
//_________________________________________________________
|
|
|
|
QColor OxygenClient::titlebarTextColor(const QPalette &palette, bool active)
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
if( configuration().drawTitleOutline() )
|
|
|
|
{
|
|
|
|
|
2009-09-18 19:47:53 +00:00
|
|
|
return options()->color(ColorFont, active);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-18 19:47:53 +00:00
|
|
|
} else if( active ){
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
return palette.color(QPalette::Active, QPalette::WindowText);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
} else {
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
if(colorCacheInvalid_)
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
QColor ab = palette.color(QPalette::Active, QPalette::Window);
|
|
|
|
QColor af = palette.color(QPalette::Active, QPalette::WindowText);
|
|
|
|
QColor nb = palette.color(QPalette::Inactive, QPalette::Window);
|
|
|
|
QColor nf = palette.color(QPalette::Inactive, QPalette::WindowText);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
colorCacheInvalid_ = false;
|
|
|
|
cachedTitlebarTextColor_ = reduceContrast(nb, nf, qMax(qreal(2.5), KColorUtils::contrastRatio(ab, KColorUtils::mix(ab, af, 0.4))));
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
return cachedTitlebarTextColor_;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenClient::renderWindowBackground( QPainter* painter, const QRect& rect, const QWidget* widget, const QPalette& palette ) const
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-15 07:12:54 +00:00
|
|
|
if( configuration().blendColor() == OxygenConfiguration::NoBlending )
|
2009-09-09 00:55:55 +00:00
|
|
|
{
|
|
|
|
|
2009-09-04 18:58:40 +00:00
|
|
|
painter->fillRect( rect, palette.color( widget->window()->backgroundRole() ) );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2009-09-04 18:58:40 +00:00
|
|
|
int offset = layoutMetric( LM_OuterPaddingTop );
|
2009-09-04 04:20:59 +00:00
|
|
|
int height = 64 + configuration().buttonSize() - 22;
|
2009-09-15 07:12:54 +00:00
|
|
|
const QWidget* window( isPreview() ? OxygenClient::widget() : widget->window() );
|
2009-09-06 18:04:11 +00:00
|
|
|
helper().renderWindowBackground(painter, rect, widget, window, palette, offset, height );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-04 18:58:40 +00:00
|
|
|
//_________________________________________________________
|
2009-09-20 17:51:06 +00:00
|
|
|
void OxygenClient::renderWindowBorder( QPainter* painter, const QRect& clipRect, const QWidget* widget, const QPalette& palette, TileSet::Tiles tiles ) const
|
2009-09-04 18:58:40 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-15 07:12:54 +00:00
|
|
|
const QWidget* window = (isPreview()) ? OxygenClient::widget() : widget->window();
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-04 18:58:40 +00:00
|
|
|
// get coordinates relative to the client area
|
2009-09-06 18:04:11 +00:00
|
|
|
// this is annoying. One could use mapTo if this was taking const QWidget* and not
|
2009-09-09 00:55:55 +00:00
|
|
|
// const QWidget* as argument.
|
2009-09-06 18:04:11 +00:00
|
|
|
const QWidget* w = widget;
|
|
|
|
QPoint position( 0, 0 );
|
|
|
|
while ( w != window && !w->isWindow() && w != w->parentWidget() ) {
|
|
|
|
position += w->geometry().topLeft();
|
|
|
|
w = w->parentWidget();
|
2009-09-09 00:55:55 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 18:58:40 +00:00
|
|
|
// save painter
|
2009-09-26 21:21:39 +00:00
|
|
|
if( clipRect.isValid() )
|
|
|
|
{
|
|
|
|
painter->save();
|
|
|
|
painter->setClipRegion(clipRect,Qt::IntersectClip);
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-15 07:12:54 +00:00
|
|
|
QRect r = (isPreview()) ? OxygenClient::widget()->rect():window->rect();
|
2009-09-17 22:40:06 +00:00
|
|
|
qreal shadowSize( oxygenShadowCache()->shadowSize() );
|
|
|
|
r.adjust( shadowSize, shadowSize, -shadowSize, -shadowSize );
|
2009-09-04 18:58:40 +00:00
|
|
|
r.adjust(0,0, 1, 1);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-09 17:02:07 +00:00
|
|
|
// mask and painting frame
|
|
|
|
QRegion mask;
|
|
|
|
QRect frame;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-09 17:02:07 +00:00
|
|
|
// top line
|
2009-09-20 17:51:06 +00:00
|
|
|
if( tiles&TileSet::Top )
|
2009-09-09 17:02:07 +00:00
|
|
|
{
|
2009-09-17 22:40:06 +00:00
|
|
|
int shadowSize = 5;
|
2009-09-26 04:57:27 +00:00
|
|
|
if( timeLineIsRunning() ) shadowSize*=opacity();
|
|
|
|
|
2009-09-04 18:58:40 +00:00
|
|
|
int height = HFRAMESIZE;
|
|
|
|
QRect rect( r.topLeft()-position, QSize( r.width(), height ) );
|
2009-09-17 22:40:06 +00:00
|
|
|
helper().slab( palette.color( widget->backgroundRole() ), 0, shadowSize )->render( rect.adjusted(-shadowSize-1, 0, shadowSize+1, 2 ), painter, TileSet::Bottom );
|
2009-09-09 17:02:07 +00:00
|
|
|
mask += rect;
|
|
|
|
frame |= rect;
|
2009-09-04 18:58:40 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-09 17:02:07 +00:00
|
|
|
// bottom line
|
2009-09-20 17:51:06 +00:00
|
|
|
if( configuration().frameBorder() > OxygenConfiguration::BorderNone && (tiles&TileSet::Bottom) )
|
2009-09-04 18:58:40 +00:00
|
|
|
{
|
|
|
|
int height = qMin( HFRAMESIZE, layoutMetric( LM_BorderBottom ) );
|
2009-09-09 17:02:07 +00:00
|
|
|
QRect rect( r.bottomLeft()-position-QPoint(0,height), QSize( r.width(), height ) );
|
|
|
|
mask += rect;
|
|
|
|
frame |= rect;
|
2009-09-04 18:58:40 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-04 18:58:40 +00:00
|
|
|
// left and right
|
2009-09-15 07:12:54 +00:00
|
|
|
if( configuration().frameBorder() >= OxygenConfiguration::BorderTiny )
|
2009-09-04 18:58:40 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-04 18:58:40 +00:00
|
|
|
// left
|
2009-09-20 17:51:06 +00:00
|
|
|
if( tiles&TileSet::Left )
|
2009-09-04 18:58:40 +00:00
|
|
|
{
|
|
|
|
int width = qMin( HFRAMESIZE, layoutMetric( LM_BorderLeft ) );
|
2009-09-09 17:02:07 +00:00
|
|
|
QRect rect( r.topLeft()-position, QSize( width, r.height() ) );
|
|
|
|
mask += rect;
|
|
|
|
frame |= rect;
|
2009-09-04 18:58:40 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-04 18:58:40 +00:00
|
|
|
// right
|
2009-09-20 17:51:06 +00:00
|
|
|
if( tiles&TileSet::Right )
|
2009-09-04 18:58:40 +00:00
|
|
|
{
|
|
|
|
int width = qMin( HFRAMESIZE, layoutMetric( LM_BorderRight ) );
|
2009-09-09 17:02:07 +00:00
|
|
|
QRect rect( r.topRight()-position-QPoint(width,0), QSize( width, r.height() ) );
|
|
|
|
mask += rect;
|
|
|
|
frame |= rect;
|
2009-09-04 18:58:40 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-04 18:58:40 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-09 17:02:07 +00:00
|
|
|
// paint
|
2009-09-20 17:51:06 +00:00
|
|
|
if( !mask.isEmpty() )
|
|
|
|
{
|
|
|
|
painter->setClipRegion( mask, Qt::IntersectClip);
|
|
|
|
renderWindowBackground(painter, frame, widget, palette );
|
|
|
|
}
|
2009-09-09 17:02:07 +00:00
|
|
|
|
2009-09-04 18:58:40 +00:00
|
|
|
// restore painter
|
2009-09-26 21:21:39 +00:00
|
|
|
if( clipRect.isValid() )
|
|
|
|
{ painter->restore(); }
|
2009-09-04 18:58:40 +00:00
|
|
|
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-18 01:32:27 +00:00
|
|
|
//_________________________________________________________
|
|
|
|
void OxygenClient::renderSeparator( QPainter* painter, const QRect& clipRect, const QWidget* widget, const QColor& color ) const
|
|
|
|
{
|
|
|
|
|
|
|
|
const QWidget* window = (isPreview()) ? OxygenClient::widget() : widget->window();
|
|
|
|
|
|
|
|
// get coordinates relative to the client area
|
|
|
|
// this is annoying. One could use mapTo if this was taking const QWidget* and not
|
|
|
|
// const QWidget* as argument.
|
|
|
|
QPoint position( 0, 0 );
|
|
|
|
{
|
|
|
|
const QWidget* w = widget;
|
|
|
|
while ( w != window && !w->isWindow() && w != w->parentWidget() ) {
|
|
|
|
position += w->geometry().topLeft();
|
|
|
|
w = w->parentWidget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// setup painter
|
2009-09-26 21:21:39 +00:00
|
|
|
if (clipRect.isValid())
|
|
|
|
{
|
|
|
|
painter->save();
|
|
|
|
painter->setClipRegion(clipRect,Qt::IntersectClip);
|
|
|
|
}
|
2009-09-18 01:32:27 +00:00
|
|
|
|
|
|
|
QRect r = (isPreview()) ? OxygenClient::widget()->rect():window->rect();
|
|
|
|
qreal shadowSize( oxygenShadowCache()->shadowSize() );
|
|
|
|
r.adjust( shadowSize, shadowSize, -shadowSize, -shadowSize );
|
|
|
|
r.adjust(0,0, 1, 1);
|
|
|
|
|
|
|
|
int extraBorder = ( isMaximized() && compositingActive() ) ? 0 : EXTENDED_HITAREA;
|
|
|
|
|
|
|
|
// dimensions
|
|
|
|
const int titleHeight = layoutMetric(LM_TitleHeight);
|
|
|
|
const int titleTop = layoutMetric(LM_TitleEdgeTop) + r.top() - extraBorder;
|
|
|
|
|
|
|
|
// dimensions
|
|
|
|
int x,y,w,h;
|
|
|
|
r.getRect(&x, &y, &w, &h);
|
|
|
|
|
2009-09-26 21:21:39 +00:00
|
|
|
QColor local( color );
|
|
|
|
if( timeLineIsRunning() ) local = helper().alphaColor( color, opacity() );
|
|
|
|
helper().drawSeparator( painter, QRect(x, titleTop+titleHeight-1.5, w, 2).translated( -position ), local, Qt::Horizontal);
|
|
|
|
|
|
|
|
if (clipRect.isValid()) { painter->restore(); }
|
2009-09-18 01:32:27 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-10-04 01:36:14 +00:00
|
|
|
//_________________________________________________________
|
2009-10-06 05:35:24 +00:00
|
|
|
QRect OxygenClient::titleRect( const QRect& frame ) const
|
2009-10-04 01:36:14 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
int extraBorder = ( isMaximized() && compositingActive() ) ? 0 : EXTENDED_HITAREA;
|
|
|
|
|
|
|
|
// dimensions
|
|
|
|
const int titleHeight = layoutMetric(LM_TitleHeight);
|
|
|
|
const int titleTop = layoutMetric(LM_TitleEdgeTop) + frame.top() - extraBorder;
|
|
|
|
const int titleEdgeLeft = layoutMetric(LM_TitleEdgeLeft);
|
|
|
|
const int marginLeft = layoutMetric(LM_TitleBorderLeft);
|
|
|
|
const int marginRight = layoutMetric(LM_TitleBorderRight);
|
|
|
|
|
|
|
|
const int titleLeft = frame.left() + titleEdgeLeft + buttonsLeftWidth() + marginLeft;
|
|
|
|
const int titleWidth = frame.width() -
|
|
|
|
titleEdgeLeft - layoutMetric(LM_TitleEdgeRight) -
|
|
|
|
buttonsLeftWidth() - buttonsRightWidth() -
|
|
|
|
marginLeft - marginRight;
|
|
|
|
|
2009-10-06 05:35:24 +00:00
|
|
|
// maximum rect allocated for title
|
|
|
|
return QRect( titleLeft, titleTop-1, titleWidth, titleHeight );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//_________________________________________________________
|
|
|
|
QRect OxygenClient::titleBoundingRect( QPainter* painter, const QRect& frame, const QString& caption ) const
|
|
|
|
{
|
|
|
|
|
|
|
|
QRect titleRect( OxygenClient::titleRect( frame ) );
|
2009-10-04 01:36:14 +00:00
|
|
|
|
|
|
|
// get title bounding rect
|
|
|
|
QRect boundingRect = painter->boundingRect( titleRect, configuration().titleAlignment() | Qt::AlignVCenter, caption );
|
|
|
|
|
2009-10-06 05:35:24 +00:00
|
|
|
// adjust to make sure bounding rect
|
2009-10-06 07:33:44 +00:00
|
|
|
// 1/ has same vertical alignment as original titleRect
|
|
|
|
// 2/ does not exceeds available horizontal space
|
|
|
|
boundingRect.setTop( titleRect.top() );
|
2009-10-06 05:35:24 +00:00
|
|
|
boundingRect.setBottom( titleRect.bottom() );
|
|
|
|
boundingRect.setLeft( qMax( boundingRect.left(), titleRect.left() ) );
|
|
|
|
boundingRect.setRight( qMin( boundingRect.right(), titleRect.right() ) );
|
2009-10-04 01:36:14 +00:00
|
|
|
return boundingRect;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-09-04 18:58:40 +00:00
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenClient::renderTitleOutline( QPainter* painter, const QRect& rect, const QPalette& palette ) const
|
2009-09-04 18:58:40 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-04 18:58:40 +00:00
|
|
|
// shadow
|
|
|
|
{
|
2009-09-17 22:40:06 +00:00
|
|
|
int shadowSize = 7;
|
2009-09-26 04:57:27 +00:00
|
|
|
if( timeLineIsRunning() ) shadowSize *= opacity();
|
2009-09-17 22:40:06 +00:00
|
|
|
int voffset = -shadowSize;
|
2009-09-04 18:58:40 +00:00
|
|
|
if( !isMaximized() ) voffset += HFRAMESIZE;
|
2009-09-17 22:40:06 +00:00
|
|
|
helper().slab( palette.color( widget()->backgroundRole() ), 0, shadowSize )->render( rect.adjusted(0, voffset, 0, 0 ), painter, TileSet::Bottom|TileSet::Left|TileSet::Right );
|
2009-09-26 04:57:27 +00:00
|
|
|
|
2009-09-04 18:58:40 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-04 18:58:40 +00:00
|
|
|
// center
|
|
|
|
{
|
2009-09-26 04:57:27 +00:00
|
|
|
int offset = 4;
|
|
|
|
if( timeLineIsRunning() ) offset *= opacity();
|
|
|
|
|
2009-09-04 18:58:40 +00:00
|
|
|
int voffset = isMaximized() ? 0:HFRAMESIZE;
|
2009-09-26 04:57:27 +00:00
|
|
|
renderWindowBackground(painter, rect.adjusted( offset, voffset, -offset, -offset ), widget(), palette );
|
2009-09-04 18:58:40 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-04 18:58:40 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-10-02 02:52:41 +00:00
|
|
|
//_________________________________________________________
|
|
|
|
void OxygenClient::renderTitleText( QPainter* painter, const QRect& rect, Qt::Alignment alignment, QColor color) const
|
|
|
|
{
|
|
|
|
if( titleTimeLineIsRunning() )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( !oldCaption().isEmpty() )
|
|
|
|
{
|
|
|
|
color.setAlphaF( 1.0 - titleOpacity() );
|
|
|
|
painter->setPen( color );
|
|
|
|
painter->drawText( rect, alignment, oldCaption() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !caption().isEmpty() )
|
|
|
|
{
|
|
|
|
color.setAlphaF( titleOpacity() );
|
|
|
|
painter->setPen( color );
|
|
|
|
painter->drawText( rect, alignment, caption() );
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if( !caption().isEmpty() ) {
|
|
|
|
|
|
|
|
painter->setPen( color );
|
|
|
|
painter->drawText( rect, alignment, caption() );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenClient::activeChange( void )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// update size grip so that it gets the right color
|
2009-09-28 05:04:23 +00:00
|
|
|
// also make sure it is remaped to from z stack,
|
|
|
|
// unless hidden
|
|
|
|
if( hasSizeGrip() && !(isShade() || isMaximized() ))
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-01 14:10:46 +00:00
|
|
|
sizeGrip().activeChange();
|
2009-08-22 08:24:06 +00:00
|
|
|
sizeGrip().update();
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-18 01:32:27 +00:00
|
|
|
// reset animation
|
|
|
|
if( animateActiveChange() )
|
|
|
|
{
|
|
|
|
timeLine_.setDirection( isActive() ? QTimeLine::Forward : QTimeLine::Backward );
|
|
|
|
if(timeLine_.state() == QTimeLine::NotRunning )
|
|
|
|
{ timeLine_.start(); }
|
|
|
|
}
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
KCommonDecorationUnstable::activeChange();
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-08-29 20:04:24 +00:00
|
|
|
|
2009-09-05 17:17:57 +00:00
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenClient::maximizeChange( void )
|
2009-09-09 00:55:55 +00:00
|
|
|
{
|
|
|
|
if( hasSizeGrip() ) sizeGrip().setVisible( !( isShade() || isMaximized() ) );
|
2009-09-05 17:17:57 +00:00
|
|
|
KCommonDecorationUnstable::maximizeChange();
|
|
|
|
}
|
|
|
|
|
2009-08-29 20:04:24 +00:00
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenClient::shadeChange( void )
|
2009-09-09 00:55:55 +00:00
|
|
|
{
|
|
|
|
if( hasSizeGrip() ) sizeGrip().setVisible( !( isShade() || isMaximized() ) );
|
2009-08-29 20:04:24 +00:00
|
|
|
KCommonDecorationUnstable::shadeChange();
|
|
|
|
}
|
|
|
|
|
2009-10-02 02:52:41 +00:00
|
|
|
//_________________________________________________________
|
|
|
|
void OxygenClient::captionChange( void )
|
|
|
|
{
|
|
|
|
KCommonDecorationUnstable::captionChange();
|
|
|
|
|
|
|
|
if( !animateTitleChange() ) return;
|
|
|
|
if( titleTimeLineIsRunning() ) titleTimeLine_.stop();
|
|
|
|
titleTimeLine_.start();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
QPalette OxygenClient::backgroundPalette( const QWidget* widget, QPalette palette ) const
|
2009-09-09 00:55:55 +00:00
|
|
|
{
|
|
|
|
|
2009-09-26 04:57:27 +00:00
|
|
|
if( configuration().drawTitleOutline() )
|
|
|
|
{
|
|
|
|
if( timeLineIsRunning() )
|
|
|
|
{
|
|
|
|
|
|
|
|
QColor inactiveColor( backgroundColor( widget, palette, false ) );
|
|
|
|
QColor activeColor( backgroundColor( widget, palette, true ) );
|
|
|
|
QColor mixed( KColorUtils::mix( inactiveColor, activeColor, opacity() ) );
|
|
|
|
palette.setColor( widget->window()->backgroundRole(), mixed );
|
|
|
|
|
|
|
|
} else if( isActive() ) {
|
|
|
|
|
|
|
|
palette.setColor( widget->window()->backgroundRole(), options()->color( KDecorationDefines::ColorTitleBar, true ) );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
return palette;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-26 04:57:27 +00:00
|
|
|
//_________________________________________________________
|
|
|
|
QColor OxygenClient::backgroundColor( const QWidget* widget, QPalette palette, bool active ) const
|
|
|
|
{
|
|
|
|
|
|
|
|
return ( configuration().drawTitleOutline() && active ) ?
|
|
|
|
options()->color( KDecorationDefines::ColorTitleBar, true ):
|
|
|
|
palette.color( widget->window()->backgroundRole() );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//________________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenClient::updateWindowShape()
|
2009-09-09 00:55:55 +00:00
|
|
|
{
|
|
|
|
|
2009-08-31 00:54:04 +00:00
|
|
|
if(isMaximized() || compositingActive() )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
clearMask();
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-24 16:14:11 +00:00
|
|
|
} else {
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
setMask( calcMask() );
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//___________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenClient::resetConfiguration( void )
|
2009-09-09 00:55:55 +00:00
|
|
|
{
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
if( !initialized_ ) return;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-15 07:12:54 +00:00
|
|
|
configuration_ = OxygenFactory::configuration( *this );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-10-02 02:52:41 +00:00
|
|
|
// animations duration
|
|
|
|
timeLine_.setDuration( configuration_.animationsDuration() );
|
|
|
|
titleTimeLine_.setDuration( configuration_.animationsDuration() );
|
|
|
|
|
|
|
|
// need to update old caption
|
|
|
|
updateOldCaption();
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// handle size grip
|
2009-09-09 00:55:55 +00:00
|
|
|
if( configuration_.drawSizeGrip() )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
if( !hasSizeGrip() ) createSizeGrip();
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
} else if( hasSizeGrip() ) deleteSizeGrip();
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//_________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenClient::paintEvent( QPaintEvent* event )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// factory
|
2009-09-15 07:12:54 +00:00
|
|
|
if(!( initialized_ && OxygenFactory::initialized() ) ) return;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// palette
|
|
|
|
QPalette palette = widget()->palette();
|
|
|
|
palette.setCurrentColorGroup( (isActive() ) ? QPalette::Active : QPalette::Inactive );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// painter
|
|
|
|
QPainter painter(widget());
|
|
|
|
painter.setClipRegion( event->region() );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// define frame
|
|
|
|
QRect frame = widget()->rect();
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// base color
|
2009-09-04 18:58:40 +00:00
|
|
|
QColor color = palette.window().color();
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// draw shadows
|
2009-09-20 17:51:06 +00:00
|
|
|
if( compositingActive() )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-17 22:40:06 +00:00
|
|
|
|
2009-09-20 17:51:06 +00:00
|
|
|
TileSet *tileSet( 0 );
|
|
|
|
if( configuration().useOxygenShadows() && timeLineIsRunning() ) tileSet = oxygenShadowCache()->tileSet( this, timeLine_.currentFrame() );
|
|
|
|
else tileSet = oxygenShadowCache()->tileSet( this );
|
2009-09-18 01:32:27 +00:00
|
|
|
|
2009-09-20 17:51:06 +00:00
|
|
|
if( !isMaximized() ) tileSet->render( frame.adjusted( 4, 4, -4, -4), &painter, TileSet::Ring);
|
|
|
|
else if( isShade() ) tileSet->render( frame.adjusted( 0, 4, 0, -4), &painter, TileSet::Bottom);
|
2009-09-17 22:40:06 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-24 16:14:11 +00:00
|
|
|
// adjust frame
|
2009-09-17 22:40:06 +00:00
|
|
|
qreal shadowSize( oxygenShadowCache()->shadowSize() );
|
|
|
|
frame.adjust( shadowSize, shadowSize, -shadowSize, -shadowSize );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// adjust mask
|
2009-08-31 00:54:04 +00:00
|
|
|
if( compositingActive() || isPreview() )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-24 16:14:11 +00:00
|
|
|
if( isMaximized() ) {
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
painter.setClipRect( frame, Qt::IntersectClip );
|
|
|
|
|
2009-08-24 16:14:11 +00:00
|
|
|
} else {
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-24 16:14:11 +00:00
|
|
|
int x, y, w, h;
|
|
|
|
frame.getRect(&x, &y, &w, &h);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-24 16:14:11 +00:00
|
|
|
// multipliers
|
|
|
|
int left = 1;
|
|
|
|
int right = 1;
|
|
|
|
int top = 1;
|
|
|
|
int bottom = 1;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-05 20:04:17 +00:00
|
|
|
// disable bottom corners when border frame is too small and window is not shaded
|
2009-09-15 07:12:54 +00:00
|
|
|
if( configuration().frameBorder() == OxygenConfiguration::BorderNone && !isShade() ) bottom = 0;
|
2009-08-24 16:14:11 +00:00
|
|
|
QRegion mask( x+5*left, y+0*top, w-5*(left+right), h-0*(top+bottom));
|
|
|
|
mask += QRegion(x+0*left, y+5*top, w-0*(left+right), h-5*(top+bottom));
|
|
|
|
mask += QRegion(x+2*left, y+2*top, w-2*(left+right), h-2*(top+bottom));
|
|
|
|
mask += QRegion(x+3*left, y+1*top, w-3*(left+right), h-1*(top+bottom));
|
2009-09-09 00:55:55 +00:00
|
|
|
mask += QRegion(x+1*left, y+3*top, w-1*(left+right), h-3*(top+bottom));
|
2009-09-07 06:59:38 +00:00
|
|
|
|
2009-09-14 19:21:39 +00:00
|
|
|
// in no-border configuration, an extra pixel is added to the mask
|
|
|
|
// in order to get the corners color right in case of title highlighting.
|
2009-09-15 07:12:54 +00:00
|
|
|
if( configuration().frameBorder() == OxygenConfiguration::BorderNone )
|
2009-09-07 06:59:38 +00:00
|
|
|
{ mask += QRegion(x+0*left, y+4*top, w-0*(left+right), h-4*(top+bottom)); }
|
|
|
|
|
2009-09-08 00:50:22 +00:00
|
|
|
painter.setClipRegion( mask, Qt::IntersectClip );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-24 16:14:11 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
|
2009-08-24 16:14:11 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// window background
|
|
|
|
renderWindowBackground( &painter, frame, widget(), palette );
|
2009-09-20 17:51:06 +00:00
|
|
|
if( drawTitleOutline() )
|
|
|
|
{
|
|
|
|
if( !isMaximized() ) renderWindowBorder( &painter, frame, widget(), backgroundPalette( widget(), palette ) );
|
|
|
|
else if( isShade() ) renderWindowBorder( &painter, frame, widget(), backgroundPalette( widget(), palette ), TileSet::Bottom );
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// clipping
|
2009-08-31 00:54:04 +00:00
|
|
|
if( compositingActive() ) painter.setClipping(false);
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2009-10-04 01:36:14 +00:00
|
|
|
// title bounding rect
|
2009-09-04 18:58:40 +00:00
|
|
|
painter.setFont( options()->font(isActive(), false) );
|
2009-10-04 01:36:14 +00:00
|
|
|
QRect boundingRect( titleBoundingRect( &painter, frame, caption() ) );
|
2009-09-04 18:58:40 +00:00
|
|
|
|
2009-10-04 01:36:14 +00:00
|
|
|
// title outline
|
2009-09-18 01:32:27 +00:00
|
|
|
if( drawTitleOutline() )
|
2009-10-06 07:33:44 +00:00
|
|
|
{ renderTitleOutline( &painter, boundingRect.adjusted( -2*HFRAMESIZE, -layoutMetric(LM_TitleEdgeTop), 2*HFRAMESIZE, 2 ), backgroundPalette( widget(), palette ) ); }
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-10-04 01:36:14 +00:00
|
|
|
// draw title text
|
|
|
|
renderTitleText( &painter, boundingRect, configuration().titleAlignment() | Qt::AlignVCenter, titlebarTextColor( backgroundPalette( widget(), palette ) ) );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-18 01:32:27 +00:00
|
|
|
// separator
|
|
|
|
if( drawSeparator() ) renderSeparator(&painter, frame, widget(), color );
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// adjust if there are shadows
|
2009-09-18 01:32:27 +00:00
|
|
|
if( compositingActive() ) frame.adjust(-1,-1, 1, 1);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// shadow and resize handles
|
2009-10-07 21:24:23 +00:00
|
|
|
if( true )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-10-07 21:24:23 +00:00
|
|
|
if( !isMaximized() )
|
2009-09-20 17:51:06 +00:00
|
|
|
{
|
|
|
|
|
2009-10-07 21:24:23 +00:00
|
|
|
if( configuration().frameBorder() >= OxygenConfiguration::BorderTiny )
|
|
|
|
{
|
2009-10-07 00:54:15 +00:00
|
|
|
|
2009-10-07 21:24:23 +00:00
|
|
|
helper().drawFloatFrame(
|
|
|
|
&painter, frame, backgroundPalette( widget(), palette ).color( widget()->backgroundRole() ),
|
|
|
|
!compositingActive(), isActive() && configuration().useOxygenShadows(),
|
|
|
|
KDecoration::options()->color(ColorTitleBar)
|
|
|
|
);
|
2009-09-20 17:51:06 +00:00
|
|
|
|
2009-10-07 21:24:23 +00:00
|
|
|
} else {
|
2009-09-20 17:51:06 +00:00
|
|
|
|
2009-10-07 21:24:23 +00:00
|
|
|
// for tiny borders, use a frame that matches the titlebar only
|
|
|
|
QRect local( frame.topLeft(), QSize( frame.width(), layoutMetric(LM_TitleHeight) + layoutMetric(LM_TitleEdgeTop) ) );
|
|
|
|
helper().drawFloatFrame(
|
|
|
|
&painter, local, backgroundPalette( widget(), palette ).color( widget()->backgroundRole() ),
|
|
|
|
false, isActive() && configuration().useOxygenShadows(),
|
|
|
|
KDecoration::options()->color(ColorTitleBar)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if( isShade() ) {
|
|
|
|
|
|
|
|
// for shaded maximized windows adjust frame and draw the bottom part of it
|
2009-09-20 17:51:06 +00:00
|
|
|
helper().drawFloatFrame(
|
2009-10-07 21:24:23 +00:00
|
|
|
&painter, frame.adjusted( -4, 0, 4, 0 ), backgroundPalette( widget(), palette ).color( widget()->backgroundRole() ),
|
|
|
|
!compositingActive(), isActive(),
|
2009-10-07 00:54:15 +00:00
|
|
|
KDecoration::options()->color(ColorTitleBar),
|
2009-10-07 21:24:23 +00:00
|
|
|
TileSet::Bottom
|
2009-09-20 17:51:06 +00:00
|
|
|
);
|
2009-08-24 16:14:11 +00:00
|
|
|
|
2009-10-07 21:24:23 +00:00
|
|
|
}
|
2009-10-07 00:54:15 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if( configuration().frameBorder() >= OxygenConfiguration::BorderTiny )
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
// dimensions
|
|
|
|
int x,y,w,h;
|
|
|
|
frame.getRect(&x, &y, &w, &h);
|
|
|
|
|
2009-09-20 17:51:06 +00:00
|
|
|
if( isResizable() && !isShade() && !isMaximized() )
|
2009-09-09 00:55:55 +00:00
|
|
|
{
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// Draw the 3-dots resize handles
|
2009-10-07 21:24:23 +00:00
|
|
|
qreal cenY = h / 2 + y + 0.5;
|
|
|
|
qreal posX = w + x - 2.5;
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
painter.setPen(Qt::NoPen);
|
|
|
|
painter.setBrush(QColor(0, 0, 0, 66));
|
|
|
|
renderDot(&painter, QPointF(posX, cenY - 3), 1.8);
|
|
|
|
renderDot(&painter, QPointF(posX, cenY), 1.8);
|
|
|
|
renderDot(&painter, QPointF(posX, cenY + 3), 1.8);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-24 16:14:11 +00:00
|
|
|
// Draw the 3-dots resize handles
|
2009-09-05 20:04:17 +00:00
|
|
|
if( isResizable() && !isShade() && !configuration().drawSizeGrip() )
|
2009-08-24 16:14:11 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
painter.setPen(Qt::NoPen);
|
|
|
|
painter.setBrush(QColor(0, 0, 0, 66));
|
|
|
|
|
|
|
|
painter.translate(x + w-9, y + h-9);
|
|
|
|
renderDot(&painter, QPointF(2.5, 6.5), 1.8);
|
|
|
|
renderDot(&painter, QPointF(5.5, 5.5), 1.8);
|
|
|
|
renderDot(&painter, QPointF(6.5, 2.5), 1.8);
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//_________________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenClient::createSizeGrip( void )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
assert( !hasSizeGrip() );
|
2009-08-29 19:31:24 +00:00
|
|
|
if( ( isResizable() && windowId() != 0 ) || isPreview() )
|
2009-09-09 00:55:55 +00:00
|
|
|
{
|
2009-09-15 07:12:54 +00:00
|
|
|
sizeGrip_ = new OxygenSizeGrip( this );
|
2009-09-07 17:41:42 +00:00
|
|
|
sizeGrip().setVisible( !( isMaximized() || isShade() ) );
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//_________________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenClient::deleteSizeGrip( void )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
|
|
|
assert( hasSizeGrip() );
|
2009-09-14 23:10:19 +00:00
|
|
|
sizeGrip_->deleteLater();
|
|
|
|
sizeGrip_ = 0;
|
2009-09-09 00:55:55 +00:00
|
|
|
}
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|