2009-09-15 07:12:54 +00:00
|
|
|
#ifndef oxygenbutton_h
|
|
|
|
#define oxygenbutton_h
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2009-09-15 07:12:54 +00:00
|
|
|
// oxygenbutton.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>
|
2009-09-20 07:42:03 +00:00
|
|
|
#include <QtCore/QTimeLine>
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2009-09-15 07:12:54 +00:00
|
|
|
#include "oxygen.h"
|
|
|
|
#include "oxygenclient.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
|
|
|
{
|
2009-09-15 07:12:54 +00:00
|
|
|
class OxygenClient;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
enum ButtonStatus {
|
|
|
|
Normal,
|
|
|
|
Hovered,
|
2009-09-09 00:55:55 +00:00
|
|
|
Pressed
|
2009-08-22 08:24:06 +00:00
|
|
|
};
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
Q_DECLARE_FLAGS(ButtonState, ButtonStatus)
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-15 07:12:54 +00:00
|
|
|
class OxygenButton : public KCommonDecorationButton
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
|
|
|
public:
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//! constructor
|
2009-09-15 07:12:54 +00:00
|
|
|
explicit OxygenButton(OxygenClient &parent,
|
2009-08-22 08:24:06 +00:00
|
|
|
const QString &tip=NULL,
|
|
|
|
ButtonType type=ButtonHelp);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//! destructor
|
2009-09-15 07:12:54 +00:00
|
|
|
~OxygenButton();
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//! destructor
|
|
|
|
QSize sizeHint() const;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//! reset
|
|
|
|
void reset(long unsigned int)
|
|
|
|
{repaint();}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//! button type
|
|
|
|
ButtonType type( void ) const
|
|
|
|
{ return type_; }
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
protected:
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//! press event
|
|
|
|
void mousePressEvent(QMouseEvent* );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//! release event
|
|
|
|
void mouseReleaseEvent(QMouseEvent* );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//! enter event
|
|
|
|
void enterEvent( QEvent* );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//! leave event
|
|
|
|
void leaveEvent(QEvent* );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//! paint
|
|
|
|
void paintEvent(QPaintEvent* );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
//! draw icon
|
|
|
|
void drawIcon(QPainter*, QPalette&, ButtonType& );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//! color
|
|
|
|
QColor buttonDetailColor(const QPalette& );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-19 21:12:57 +00:00
|
|
|
//! color
|
|
|
|
QColor buttonDetailColor(const QPalette&, bool active );
|
|
|
|
|
|
|
|
//! opacity
|
|
|
|
qreal opacity( void ) const
|
|
|
|
{ return qreal( timeLine_.currentFrame() ) / qreal(timeLine_.endFrame()); }
|
|
|
|
|
|
|
|
//! true if timeline is running
|
|
|
|
bool timeLineIsRunning( void ) const
|
|
|
|
{ return timeLine_.state() == QTimeLine::Running; }
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
private:
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//! parent client
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenClient &client_;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//! helper
|
2009-09-04 04:22:26 +00:00
|
|
|
OxygenHelper &helper_;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//! button type
|
|
|
|
ButtonType type_;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//! button status
|
|
|
|
ButtonState status_;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
bool colorCacheInvalid_;
|
|
|
|
QColor cachedButtonDetailColor_;
|
2009-09-16 17:09:33 +00:00
|
|
|
|
|
|
|
//! timeline used for smooth transitions
|
2009-09-17 03:43:55 +00:00
|
|
|
QTimeLine timeLine_;
|
2009-09-16 17:09:33 +00:00
|
|
|
|
2009-08-22 08:24:06 +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
|