2007-03-05 05:13:22 +01:00
|
|
|
/*
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2007 by Siraj Razick <siraj@kde.org>
|
|
|
|
* Copyright 2007 by Matias Valdenegro <mvaldenegro@informatica.utem.cl>
|
|
|
|
* Copyright 2007 by Matt Broadstone <mbroadst@gmail.com>
|
2007-03-05 05:13:22 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-09-14 22:17:11 +02:00
|
|
|
* it under the terms of the GNU Library General Public License as
|
2007-09-14 21:06:18 +02:00
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
2007-03-05 05:13:22 +01:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
#ifndef PUSHBUTTON_H
|
|
|
|
#define PUSHBUTTON_H
|
|
|
|
|
2007-04-22 11:35:04 +02:00
|
|
|
#include <QtCore/QObject>
|
|
|
|
#include <QtGui/QGraphicsTextItem>
|
|
|
|
#include <QtGui/QLayoutItem>
|
2007-05-25 04:27:33 +02:00
|
|
|
|
2007-08-07 16:58:00 +02:00
|
|
|
#include <KDE/KIcon>
|
2007-08-05 10:10:17 +02:00
|
|
|
|
2007-06-02 19:29:39 +02:00
|
|
|
#include <plasma/dataengine.h>
|
2007-07-23 00:16:40 +02:00
|
|
|
#include <plasma/widgets/widget.h>
|
2007-06-02 19:29:39 +02:00
|
|
|
#include <plasma/plasma_export.h>
|
2007-03-05 05:13:22 +01:00
|
|
|
|
2007-08-05 10:10:17 +02:00
|
|
|
class QStyleOptionButton;
|
2007-03-05 05:13:22 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2007-05-20 18:25:07 +02:00
|
|
|
/**
|
2007-07-23 00:16:40 +02:00
|
|
|
* Class that emulates a QPushButton inside Plasma
|
|
|
|
*
|
2007-10-04 19:36:21 +02:00
|
|
|
* @author Siraj Razick
|
2007-08-05 10:10:17 +02:00
|
|
|
* @author Matias Valdenegro
|
|
|
|
* @author Matt Broadstone
|
2007-07-23 00:16:40 +02:00
|
|
|
*
|
|
|
|
*
|
2007-05-20 18:25:07 +02:00
|
|
|
*/
|
2007-08-03 18:00:10 +02:00
|
|
|
class PLASMA_EXPORT PushButton : public Plasma::Widget
|
2007-03-05 05:13:22 +01:00
|
|
|
{
|
2007-05-25 04:27:33 +02:00
|
|
|
Q_OBJECT
|
2007-08-04 15:14:57 +02:00
|
|
|
Q_PROPERTY( QString text READ text WRITE setText )
|
2007-08-05 10:10:17 +02:00
|
|
|
Q_PROPERTY( QSizeF iconSize READ iconSize WRITE setIconSize )
|
|
|
|
Q_PROPERTY( KIcon icon READ icon WRITE setIcon )
|
2007-08-05 13:05:47 +02:00
|
|
|
Q_PROPERTY( bool flat READ isFlat WRITE setFlat )
|
2007-10-04 19:36:21 +02:00
|
|
|
Q_PROPERTY( bool checkable READ isCheckable WRITE setCheckable )
|
|
|
|
Q_PROPERTY( bool checked READ isChecked WRITE setChecked)
|
2007-08-05 10:10:17 +02:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Creates a new Plasma::PushButton.
|
|
|
|
* @param parent the Widge this button is parented to.
|
|
|
|
*/
|
|
|
|
explicit PushButton(Widget *parent = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new Plasma::PushButton with a text label.
|
|
|
|
* @param text the text to display next to the button.
|
|
|
|
* @param parent the QGraphicsItem this icon is parented to.
|
|
|
|
*/
|
|
|
|
explicit PushButton(const QString &text, Widget *parent = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new Plasma::PushButton with an icon and text
|
|
|
|
* @param icon the icon to display with this button.
|
|
|
|
* @param text the text to display with this button.
|
|
|
|
* @param parent the QGraphicsItem this icon is parented to.
|
|
|
|
*/
|
|
|
|
explicit PushButton(const KIcon &icon, const QString &text, Widget *parent = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys this Plasma::PushButton.
|
|
|
|
*/
|
|
|
|
virtual ~PushButton();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return text associated with this Plasma::PushButton
|
|
|
|
*/
|
2007-08-05 13:05:47 +02:00
|
|
|
QString text() const;
|
2007-08-05 10:10:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the text to be displayed by this button.
|
|
|
|
* @param text the text to display
|
|
|
|
*/
|
2007-08-05 13:05:47 +02:00
|
|
|
void setText(const QString &text);
|
2007-08-05 10:10:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the icon displayed by this button.
|
|
|
|
*/
|
2007-08-05 13:05:47 +02:00
|
|
|
KIcon icon() const;
|
2007-08-05 10:10:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the icon to be displayed by this Plasma::Icon.
|
|
|
|
* @param icon the KIcon to display.
|
|
|
|
*/
|
2007-08-05 13:05:47 +02:00
|
|
|
void setIcon(const KIcon &icon);
|
2007-08-05 10:10:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method to set the icon of this Plasma::PushButton
|
|
|
|
* based on the icon path, or name.
|
|
|
|
* @see KIconLoader
|
|
|
|
* @param path the path to, or name of the icon to display.
|
|
|
|
*/
|
|
|
|
Q_INVOKABLE void setIcon(const QString& path);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the size of the icon displayed by this Plasma::PushButton.
|
|
|
|
*/
|
2007-08-05 13:05:47 +02:00
|
|
|
QSizeF iconSize() const;
|
2007-08-05 10:10:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the size of icon shown by this button.
|
|
|
|
* @param size size of the icon.
|
|
|
|
*/
|
2007-08-05 13:05:47 +02:00
|
|
|
void setIconSize(const QSizeF &size);
|
2007-08-05 10:10:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return whether this button is currently in a down/pressed state.
|
|
|
|
*/
|
|
|
|
bool isDown() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return whether this button is drawn flat.
|
|
|
|
*/
|
|
|
|
bool isFlat() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether the button is drawn flat.
|
|
|
|
* @param flat whether to draw it flat or not.
|
|
|
|
*/
|
|
|
|
void setFlat(bool flat);
|
|
|
|
|
2007-10-04 19:36:21 +02:00
|
|
|
/**
|
|
|
|
* @return whether this button is checkable.
|
|
|
|
*/
|
|
|
|
bool isCheckable() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether the button is checkable.
|
|
|
|
* @param checkable whether button is checkable or not.
|
|
|
|
*/
|
|
|
|
void setCheckable(bool checkable);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return whether this button is checked.
|
|
|
|
*/
|
|
|
|
bool isChecked() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether the button is checked.
|
|
|
|
* @param checked whether button is checked or not.
|
|
|
|
*/
|
|
|
|
void setChecked(bool checked);
|
|
|
|
|
2007-08-05 19:03:18 +02:00
|
|
|
// NOTE: bogus
|
|
|
|
QSizeF minimumSize() const;
|
2008-02-29 18:50:57 +01:00
|
|
|
Qt::Orientations expandingDirections() const;
|
2008-04-13 15:23:39 +02:00
|
|
|
#ifdef REMOVE
|
2008-02-29 18:50:57 +01:00
|
|
|
QSizeF sizeHint() const;
|
2008-04-13 15:23:39 +02:00
|
|
|
#endif
|
2007-08-05 19:03:18 +02:00
|
|
|
|
2007-08-05 10:10:17 +02:00
|
|
|
Q_SIGNALS:
|
|
|
|
/**
|
|
|
|
* Triggered when the button has been clicked.
|
|
|
|
*/
|
|
|
|
void clicked();
|
|
|
|
|
2007-10-04 19:36:21 +02:00
|
|
|
/**
|
|
|
|
* Triggered when the checkable button has been toggled.
|
|
|
|
*/
|
|
|
|
void toggled(bool checked);
|
|
|
|
|
2007-08-05 10:10:17 +02:00
|
|
|
protected:
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
2007-11-15 04:35:12 +01:00
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
2007-08-05 10:10:17 +02:00
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
|
|
|
|
|
|
|
void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
|
|
|
|
|
|
|
private:
|
|
|
|
class Private ;
|
|
|
|
Private * const d;
|
2007-03-05 05:13:22 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#endif
|