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.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-03-02 03:40:34 +00:00
|
|
|
#include "oxygenanimation.h"
|
2012-11-23 09:09:39 +00:00
|
|
|
#include "oxygendecorationdefines.h"
|
|
|
|
#include "oxygendecohelper.h"
|
|
|
|
|
|
|
|
#include <kcommondecoration.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
|
|
|
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
|
|
|
|
2011-09-13 12:19:47 +00:00
|
|
|
//! declare animation progress property
|
|
|
|
Q_PROPERTY( qreal glowIntensity READ glowIntensity WRITE setGlowIntensity )
|
2009-11-17 21:56:04 +00:00
|
|
|
|
2011-09-13 12:19:47 +00:00
|
|
|
public:
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2011-09-13 12:19:47 +00:00
|
|
|
//! constructor
|
|
|
|
explicit Button(Client&, const QString& = QString(), ButtonType = 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;
|
2011-09-19 13:20:07 +00:00
|
|
|
parentUpdate();
|
2010-08-28 02:52:26 +00:00
|
|
|
}
|
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
|
|
|
|
2011-09-19 13:16:43 +00:00
|
|
|
//! render buttn to provided painter
|
|
|
|
void paint(QPainter& );
|
|
|
|
|
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
|
2011-06-28 07:09:31 +00:00
|
|
|
void mousePressEvent( QMouseEvent* );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! release event
|
2011-06-28 07:09:31 +00:00
|
|
|
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
|
2011-06-28 07:09:31 +00:00
|
|
|
void leaveEvent( QEvent* );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2011-06-28 07:24:02 +00:00
|
|
|
//! resize event
|
|
|
|
void resizeEvent( QResizeEvent* );
|
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! paint
|
2011-06-28 07:09:31 +00:00
|
|
|
void paintEvent( QPaintEvent* );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2011-09-19 14:23:29 +00:00
|
|
|
// parent update
|
|
|
|
void parentUpdate( void );
|
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! draw icon
|
2011-06-28 07:09:31 +00:00
|
|
|
void drawIcon( QPainter* );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! color
|
2011-06-28 07:09:31 +00:00
|
|
|
QColor buttonDetailColor( const QPalette& ) const;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//! color
|
2011-06-28 07:09:31 +00:00
|
|
|
QColor buttonDetailColor( const QPalette& palette, bool active ) const
|
2010-08-28 19:58:22 +00:00
|
|
|
{
|
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
|
2011-07-18 05:36:44 +00:00
|
|
|
bool buttonAnimationsEnabled( 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
|
|
|
|
|
|
|
//@}
|
|
|
|
|
2013-07-30 04:47:50 +00:00
|
|
|
private Q_SLOTS:
|
2012-11-09 12:44:50 +00:00
|
|
|
void slotAppMenuHidden();
|
|
|
|
|
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
|
2013-10-09 07:52:30 +00:00
|
|
|
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
|
|
|
|
2011-06-28 07:24:02 +00:00
|
|
|
//! backing store pixmap (when compositing is not active)
|
|
|
|
QPixmap _pixmap;
|
|
|
|
|
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-09-22 20:22:37 +00:00
|
|
|
unsigned int _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
|