2011-02-24 16:37:04 +00:00
|
|
|
#ifndef oxygenbutton_h
|
|
|
|
#define oxygenbutton_h
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2010-05-02 18:34:08 +00:00
|
|
|
// Button.h
|
2009-08-22 08:24:06 +00:00
|
|
|
// -------------------
|
2009-09-09 00:55:55 +00:00
|
|
|
//
|
2009-08-24 15:43:15 +00:00
|
|
|
// Copyright (c) 2006, 2007 Riccardo Iaconelli <riccardo@kde.org>
|
|
|
|
// Copyright (c) 2006, 2007 Casper Boemann <cbr@boemann.dk>
|
|
|
|
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
|
|
|
//
|
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
|
|
|
|
// IN THE SOFTWARE.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <kcommondecoration.h>
|
|
|
|
|
2010-05-02 18:38:05 +00:00
|
|
|
#include "oxygenfactory.h"
|
2010-03-02 03:40:34 +00:00
|
|
|
#include "oxygenanimation.h"
|
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
|
|
|
{
|
2010-05-02 18:34:08 +00:00
|
|
|
class Client;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
enum ButtonStatus {
|
|
|
|
Normal,
|
|
|
|
Hovered,
|
|
|
|
Pressed
|
|
|
|
};
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
Q_DECLARE_FLAGS(ButtonState, ButtonStatus)
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
class Button : public KCommonDecorationButton
|
|
|
|
{
|
2009-10-14 15:36:38 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
Q_OBJECT
|
2009-10-14 15:36:38 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! declare animation progress property
|
|
|
|
Q_PROPERTY( qreal glowIntensity READ glowIntensity WRITE setGlowIntensity )
|
2009-11-17 21:56:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
public:
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! constructor
|
|
|
|
explicit Button(Client &parent,
|
2010-10-19 22:42:05 +00:00
|
|
|
const QString &tip=QString(),
|
2010-05-02 18:34:08 +00:00
|
|
|
ButtonType type=ButtonHelp );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! destructor
|
|
|
|
~Button();
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! destructor
|
|
|
|
QSize sizeHint() const;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! button type
|
|
|
|
ButtonType type( void ) const
|
2011-02-24 16:37:04 +00:00
|
|
|
{ return _type; }
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! set force inactive
|
|
|
|
/*! returns true if value was actually changed */
|
|
|
|
void setForceInactive( const bool& value )
|
2011-02-24 16:37:04 +00:00
|
|
|
{ _forceInactive = value; }
|
2009-10-14 15:36:38 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! configuration reset
|
|
|
|
virtual void reset( unsigned long );
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//!@name glow animation
|
|
|
|
//@{
|
|
|
|
void setGlowIntensity( qreal value )
|
2010-08-28 02:52:26 +00:00
|
|
|
{
|
2011-02-24 16:37:04 +00:00
|
|
|
if( _glowIntensity == value ) return;
|
|
|
|
_glowIntensity = value;
|
2010-08-28 02:52:26 +00:00
|
|
|
update();
|
|
|
|
}
|
2009-11-17 21:56:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
qreal glowIntensity( void ) const
|
2011-02-24 16:37:04 +00:00
|
|
|
{ return _glowIntensity; }
|
2009-11-17 21:56:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//@}
|
2009-11-17 21:56:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
protected:
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! press event
|
|
|
|
void mousePressEvent(QMouseEvent* );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! release event
|
|
|
|
void mouseReleaseEvent(QMouseEvent* );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! enter event
|
|
|
|
void enterEvent( QEvent* );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! leave event
|
|
|
|
void leaveEvent(QEvent* );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! paint
|
|
|
|
void paintEvent(QPaintEvent* );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! draw icon
|
2010-07-05 17:39:25 +00:00
|
|
|
void drawIcon(QPainter*);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! color
|
2010-08-28 19:58:22 +00:00
|
|
|
QColor buttonDetailColor(const QPalette& ) const;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! color
|
2010-08-28 19:58:22 +00:00
|
|
|
QColor buttonDetailColor(const QPalette& palette, bool active ) const
|
|
|
|
{
|
2011-04-28 15:28:46 +00:00
|
|
|
if( _type == ButtonItemClose )
|
|
|
|
{
|
|
|
|
|
|
|
|
return active ?
|
|
|
|
palette.color(QPalette::Active, QPalette::WindowText ):
|
|
|
|
_helper.inactiveTitleBarTextColor( palette );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return active ?
|
|
|
|
palette.color(QPalette::Active, QPalette::ButtonText ):
|
|
|
|
_helper.inactiveButtonTextColor( palette );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-08-28 19:58:22 +00:00
|
|
|
}
|
2009-09-19 21:12:57 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! true if animation is in progress
|
|
|
|
bool isAnimated( void ) const
|
2011-02-24 16:37:04 +00:00
|
|
|
{ return _glowAnimation->isRunning(); }
|
2009-09-19 21:12:57 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! true if button is active
|
|
|
|
bool isActive( void ) const;
|
2009-10-14 15:36:38 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! true if buttons hover are animated
|
|
|
|
bool animateButtonHover( void ) const;
|
2010-02-02 21:55:56 +00:00
|
|
|
|
2010-07-05 17:39:25 +00:00
|
|
|
//!@name button properties
|
|
|
|
//@{
|
|
|
|
|
|
|
|
//! true if button if of menu type
|
|
|
|
bool isMenuButton( void ) const
|
2011-02-24 16:37:04 +00:00
|
|
|
{ return _type == ButtonMenu || _type == ButtonItemMenu; }
|
2010-07-05 17:39:25 +00:00
|
|
|
|
|
|
|
//! true if button is of toggle type
|
|
|
|
bool isToggleButton( void ) const
|
2011-02-24 16:37:04 +00:00
|
|
|
{ return _type == ButtonSticky || _type == ButtonAbove || _type == ButtonBelow; }
|
2010-07-05 17:39:25 +00:00
|
|
|
|
|
|
|
//! true if button if of close type
|
|
|
|
bool isCloseButton( void ) const
|
2011-02-24 16:37:04 +00:00
|
|
|
{ return _type == ButtonClose || _type == ButtonItemClose; }
|
2010-07-05 17:39:25 +00:00
|
|
|
|
|
|
|
//! true if button has decoration
|
|
|
|
bool hasDecoration( void ) const
|
2011-02-24 16:37:04 +00:00
|
|
|
{ return !isMenuButton() && _type != ButtonItemClose; }
|
2010-07-05 17:39:25 +00:00
|
|
|
|
|
|
|
//@}
|
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
private:
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! parent client
|
2011-02-24 16:37:04 +00:00
|
|
|
const Client &_client;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! helper
|
2011-02-24 16:37:04 +00:00
|
|
|
DecoHelper &_helper;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! button type
|
2011-02-24 16:37:04 +00:00
|
|
|
ButtonType _type;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! button status
|
2011-02-24 16:37:04 +00:00
|
|
|
ButtonState _status;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! true if button should be forced inactive
|
2011-02-24 16:37:04 +00:00
|
|
|
bool _forceInactive;
|
2009-10-14 15:36:38 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! glow animation
|
2011-02-24 16:37:04 +00:00
|
|
|
//Animation::Pointer _glowAnimation;
|
|
|
|
Animation* _glowAnimation;
|
2009-11-17 21:56:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! glow intensity
|
2011-02-24 16:37:04 +00:00
|
|
|
qreal _glowIntensity;
|
2009-11-17 21:56:04 +00:00
|
|
|
|
2009-09-16 17:09:33 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
};
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-15 07:12:54 +00:00
|
|
|
} //namespace Oxygen
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
#endif
|