2007-06-15 20:48:52 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// oxygenbutton.h
|
|
|
|
// -------------------
|
|
|
|
// Oxygen window decoration for KDE.
|
|
|
|
// -------------------
|
2007-11-02 15:30:53 +00:00
|
|
|
// Copyright (c) 2006, 2007 Riccardo Iaconelli <riccardo@kde.org>
|
2007-06-15 20:48:52 +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
|
|
|
|
// IN THE SOFTWARE.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-10-17 10:30:43 +00:00
|
|
|
#include <QPainter>
|
|
|
|
|
2007-06-15 20:48:52 +00:00
|
|
|
#include "oxygen.h"
|
2008-05-30 17:47:24 +00:00
|
|
|
#include "oxygenclient.h"
|
2007-10-05 22:21:25 +00:00
|
|
|
#include <kconfiggroup.h>
|
2008-10-19 10:31:32 +00:00
|
|
|
#include <QApplication>
|
2007-10-05 22:21:25 +00:00
|
|
|
|
2007-06-15 20:48:52 +00:00
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
KDE_EXPORT KDecorationFactory* create_factory()
|
|
|
|
{
|
|
|
|
return new Oxygen::OxygenFactory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
namespace Oxygen
|
|
|
|
{
|
|
|
|
|
2008-10-19 10:31:32 +00:00
|
|
|
OxygenHelper *oxygenHelper(); // referenced from definition in oxygendclient.cpp
|
|
|
|
|
2007-06-15 20:48:52 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// OxygenFactory Class //
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
bool OxygenFactory::initialized_ = false;
|
2008-10-08 13:42:24 +00:00
|
|
|
Qt::Alignment OxygenFactory::titleAlignment_ = Qt::AlignLeft;
|
2008-06-07 23:06:31 +00:00
|
|
|
bool OxygenFactory::showStripes_ = true;
|
2009-03-09 22:36:39 +00:00
|
|
|
int OxygenFactory::borderSize_ = 4; // BorderSize::BorderNormal
|
2007-06-15 20:48:52 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// OxygenFactory()
|
|
|
|
// ----------------
|
|
|
|
// Constructor
|
|
|
|
|
|
|
|
OxygenFactory::OxygenFactory()
|
|
|
|
{
|
|
|
|
readConfig();
|
|
|
|
initialized_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ~OxygenFactory()
|
|
|
|
// -----------------
|
|
|
|
// Destructor
|
|
|
|
|
|
|
|
OxygenFactory::~OxygenFactory() { initialized_ = false; }
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// createDecoration()
|
|
|
|
// -----------------
|
|
|
|
// Create the decoration
|
|
|
|
|
|
|
|
KDecoration* OxygenFactory::createDecoration(KDecorationBridge* b)
|
|
|
|
{
|
2007-11-29 14:11:02 +00:00
|
|
|
return (new OxygenClient(b, this))->decoration();
|
2007-06-15 20:48:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// reset()
|
|
|
|
// -------
|
|
|
|
// Reset the handler. Returns true if decorations need to be remade, false if
|
|
|
|
// only a repaint is necessary
|
|
|
|
|
|
|
|
bool OxygenFactory::reset(unsigned long changed)
|
|
|
|
{
|
|
|
|
// read in the configuration
|
|
|
|
initialized_ = false;
|
|
|
|
bool confchange = readConfig();
|
|
|
|
initialized_ = true;
|
|
|
|
|
|
|
|
if (confchange ||
|
|
|
|
(changed & (SettingDecoration | SettingButtons | SettingBorder))) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
resetDecorations(changed);
|
|
|
|
return false;
|
|
|
|
}
|
2009-03-09 22:36:39 +00:00
|
|
|
|
|
|
|
// taken from plastik
|
|
|
|
switch(KDecoration::options()->preferredBorderSize( this )) {
|
|
|
|
case BorderTiny:
|
|
|
|
borderSize_ = 2;
|
|
|
|
break;
|
|
|
|
case BorderLarge:
|
|
|
|
borderSize_ = 8;
|
|
|
|
break;
|
|
|
|
case BorderVeryLarge:
|
|
|
|
borderSize_ = 12;
|
|
|
|
break;
|
|
|
|
case BorderHuge:
|
|
|
|
borderSize_ = 18;
|
|
|
|
break;
|
|
|
|
case BorderVeryHuge:
|
|
|
|
borderSize_ = 27;
|
|
|
|
break;
|
|
|
|
case BorderOversized:
|
|
|
|
borderSize_ = 40;
|
|
|
|
break;
|
|
|
|
case BorderNormal:
|
|
|
|
default:
|
|
|
|
borderSize_ = 4;
|
|
|
|
}
|
2007-06-15 20:48:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// readConfig()
|
|
|
|
// ------------
|
|
|
|
// Read in the configuration file
|
|
|
|
|
|
|
|
bool OxygenFactory::readConfig()
|
|
|
|
{
|
|
|
|
// create a config object
|
2008-01-02 17:14:42 +00:00
|
|
|
KConfig config("oxygenrc");
|
|
|
|
KConfigGroup group = config.group("Windeco");
|
2007-06-15 20:48:52 +00:00
|
|
|
|
|
|
|
// grab settings
|
2008-10-08 13:42:24 +00:00
|
|
|
Qt::Alignment oldalign = titleAlignment_;
|
|
|
|
QString value = group.readEntry("TitleAlignment", "Left");
|
|
|
|
if (value == "Left")
|
|
|
|
titleAlignment_ = Qt::AlignLeft;
|
|
|
|
else if (value == "Center")
|
|
|
|
titleAlignment_ = Qt::AlignHCenter;
|
|
|
|
else if (value == "Right")
|
|
|
|
titleAlignment_ = Qt::AlignRight;
|
2007-06-15 20:48:52 +00:00
|
|
|
|
2009-03-09 22:36:39 +00:00
|
|
|
int oldBorderSize = borderSize_;
|
|
|
|
switch(KDecoration::options()->preferredBorderSize( this )) {
|
|
|
|
case BorderTiny:
|
|
|
|
borderSize_ = 2;
|
|
|
|
break;
|
|
|
|
case BorderLarge:
|
|
|
|
borderSize_ = 8;
|
|
|
|
break;
|
|
|
|
case BorderVeryLarge:
|
|
|
|
borderSize_ = 12;
|
|
|
|
break;
|
|
|
|
case BorderHuge:
|
|
|
|
borderSize_ = 18;
|
|
|
|
break;
|
|
|
|
case BorderVeryHuge:
|
|
|
|
borderSize_ = 27;
|
|
|
|
break;
|
|
|
|
case BorderOversized:
|
|
|
|
borderSize_ = 40;
|
|
|
|
break;
|
|
|
|
case BorderNormal:
|
|
|
|
default:
|
|
|
|
borderSize_ = 4;
|
|
|
|
}
|
2009-02-15 21:16:10 +00:00
|
|
|
|
|
|
|
bool oldstripes = showStripes_;
|
2008-06-07 23:06:31 +00:00
|
|
|
showStripes_ = group.readEntry( "ShowStripes", true );
|
|
|
|
|
2009-02-15 21:16:10 +00:00
|
|
|
if (oldalign == titleAlignment_ && oldstripes == showStripes_
|
2009-03-09 22:36:39 +00:00
|
|
|
&& oldBorderSize == borderSize_)
|
2007-06-15 20:48:52 +00:00
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-11-02 16:28:27 +00:00
|
|
|
bool OxygenFactory::supports( Ability ability ) const
|
|
|
|
{
|
|
|
|
switch( ability ) {
|
2007-11-29 17:14:26 +00:00
|
|
|
// announce
|
2007-11-02 16:28:27 +00:00
|
|
|
case AbilityAnnounceButtons:
|
2007-11-29 17:14:26 +00:00
|
|
|
case AbilityAnnounceColors:
|
|
|
|
// buttons
|
2007-11-02 16:28:27 +00:00
|
|
|
case AbilityButtonMenu:
|
|
|
|
case AbilityButtonHelp:
|
|
|
|
case AbilityButtonMinimize:
|
|
|
|
case AbilityButtonMaximize:
|
|
|
|
case AbilityButtonClose:
|
2008-06-01 19:03:09 +00:00
|
|
|
case AbilityButtonOnAllDesktops:
|
2008-03-21 17:10:51 +00:00
|
|
|
case AbilityButtonAboveOthers:
|
|
|
|
case AbilityButtonBelowOthers:
|
2007-11-29 18:41:23 +00:00
|
|
|
case AbilityButtonSpacer:
|
2008-10-16 16:13:18 +00:00
|
|
|
case AbilityButtonShade:
|
2008-10-17 10:30:43 +00:00
|
|
|
// compositing
|
|
|
|
case AbilityCompositingShadow: // TODO: UI option to use default shadows instead
|
2009-06-10 21:02:50 +00:00
|
|
|
case AbilityUsesAlphaChannel:
|
2007-11-02 16:28:27 +00:00
|
|
|
return true;
|
2007-11-29 17:14:26 +00:00
|
|
|
// no colors supported at this time
|
2007-11-02 16:28:27 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
2007-06-15 20:48:52 +00:00
|
|
|
|
2009-03-09 22:36:39 +00:00
|
|
|
QList< OxygenFactory::BorderSize >
|
|
|
|
OxygenFactory::borderSizes() const
|
|
|
|
{
|
|
|
|
// the list must be sorted
|
|
|
|
return QList< BorderSize >() << BorderTiny << BorderNormal <<
|
|
|
|
BorderLarge << BorderVeryLarge << BorderHuge <<
|
|
|
|
BorderVeryHuge << BorderOversized;
|
|
|
|
}
|
|
|
|
|
2007-06-15 20:48:52 +00:00
|
|
|
} //namespace Oxygen
|