2007-05-29 09:59:50 +02:00
|
|
|
/*
|
2007-08-08 07:29:50 +02:00
|
|
|
* Copyright (C) 2007 by Siraj Razick <siraj@kde.org>
|
|
|
|
* Copyright (C) 2007 by Riccardo Iaconelli <riccardo@kde.org>
|
|
|
|
* Copyright (C) 2007 by Matt Broadstone <mbroadst@gmail.com>
|
2008-04-14 11:50:39 +02:00
|
|
|
* Copyright 2008 by Ménard Alexis <darktears31@gmail.com>
|
2007-07-20 08:28:51 +02: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
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
2007-07-20 08:28:51 +02: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.
|
|
|
|
*/
|
2007-05-29 09:59:50 +02:00
|
|
|
|
2007-06-05 20:39:59 +02:00
|
|
|
#ifndef ICON_H
|
|
|
|
#define ICON_H
|
2007-05-29 09:59:50 +02:00
|
|
|
|
2007-07-23 00:01:10 +02:00
|
|
|
#include <QtCore/QObject>
|
|
|
|
#include <QtGui/QGraphicsTextItem>
|
2007-08-11 00:24:49 +02:00
|
|
|
#include <QtGui/QIcon>
|
2008-04-14 11:50:39 +02:00
|
|
|
#include <QGraphicsWidget>
|
2007-08-05 20:03:26 +02:00
|
|
|
|
2007-06-02 19:29:39 +02:00
|
|
|
#include <plasma/dataengine.h>
|
2007-07-21 00:54:56 +02:00
|
|
|
#include <plasma/phase.h>
|
2007-06-02 19:29:39 +02:00
|
|
|
#include <plasma/plasma_export.h>
|
2007-05-29 09:59:50 +02:00
|
|
|
|
2007-07-23 00:01:10 +02:00
|
|
|
class QAction;
|
2007-06-17 01:38:56 +02:00
|
|
|
|
2007-07-28 21:27:56 +02:00
|
|
|
/**
|
|
|
|
* This class provides a generic Icon for the Plasma desktop. An icon, in this
|
|
|
|
* sense, is not restricted to just an image, but can also contain text. Currently,
|
|
|
|
* the Icon class is primarily used for desktop items, but is designed to be used
|
|
|
|
* anywhere an icon is needed in an applet.
|
|
|
|
*
|
|
|
|
* @author Siraj Razick <siraj@kde.org>
|
|
|
|
* @author Matt Broadstone <mbroadst@gmail.com>
|
|
|
|
*/
|
2007-05-29 09:59:50 +02:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-04-13 23:47:47 +02:00
|
|
|
class PLASMA_EXPORT Icon : public QGraphicsWidget
|
2007-05-29 09:59:50 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2007-08-04 15:14:57 +02:00
|
|
|
Q_PROPERTY( QString text READ text WRITE setText )
|
|
|
|
Q_PROPERTY( QString infoText READ infoText WRITE setInfoText )
|
2007-08-11 00:24:49 +02:00
|
|
|
Q_PROPERTY( QIcon icon READ icon WRITE setIcon )
|
2007-12-26 13:37:54 +01:00
|
|
|
Q_PROPERTY( QSizeF iconSize READ iconSize )
|
2007-12-19 21:32:31 +01:00
|
|
|
Q_PROPERTY( QString svg WRITE setSvg )
|
2007-08-05 19:11:46 +02:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Creates a new Plasma::Icon.
|
|
|
|
* @param parent the QGraphicsItem this icon is parented to.
|
|
|
|
*/
|
|
|
|
explicit Icon(QGraphicsItem *parent = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience constructor to create a Plasma::Icon with text.
|
|
|
|
* @param text the text that will be displayed with this icon.
|
|
|
|
* @param parent the QGraphicsItem this icon is parented to.
|
|
|
|
*/
|
|
|
|
explicit Icon(const QString &text, QGraphicsItem *parent = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new Plasma::Icon with text and an icon.
|
|
|
|
* @param icon the icon that will be displayed with this icon.
|
|
|
|
* @param text the text that will be displayed with this icon.
|
|
|
|
* @param parent The QGraphicsItem this icon is parented to.
|
|
|
|
*/
|
2007-08-11 00:24:49 +02:00
|
|
|
Icon(const QIcon &icon, const QString &text, QGraphicsItem *parent = 0);
|
2007-08-05 19:11:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys this Plasma::Icon.
|
|
|
|
*/
|
|
|
|
virtual ~Icon();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the text associated with this icon.
|
|
|
|
*/
|
|
|
|
QString text() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the text associated with this icon.
|
|
|
|
* @param text the text to associate with this icon.
|
|
|
|
*/
|
|
|
|
void setText(const QString &text);
|
|
|
|
|
2007-12-19 21:32:31 +01:00
|
|
|
/**
|
|
|
|
* Convenience method to set the svg image to use when given the filepath and name of svg.
|
|
|
|
* @param svgFilePath the svg filepath including name of the svg.
|
2007-12-22 06:31:57 +01:00
|
|
|
* @param svgIconElement the svg element to use when displaying the svg. Defaults to all of them.
|
2007-12-19 21:32:31 +01:00
|
|
|
*/
|
2007-12-22 06:31:57 +01:00
|
|
|
void setSvg(const QString &svgFilePath, const QString &svgIconElement = QString());
|
2007-12-19 21:32:31 +01:00
|
|
|
|
2007-08-05 19:11:46 +02:00
|
|
|
/**
|
|
|
|
* Returns the meta text associated with this icon.
|
|
|
|
*/
|
|
|
|
QString infoText() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the additional information to be displayed by
|
|
|
|
* this icon.
|
|
|
|
* @param text additional meta text associated with this icon.
|
|
|
|
*/
|
|
|
|
void setInfoText(const QString &text);
|
|
|
|
|
2007-08-05 20:03:26 +02:00
|
|
|
/**
|
|
|
|
* @return the icon associated with this icon.
|
|
|
|
*/
|
2007-08-11 00:24:49 +02:00
|
|
|
QIcon icon() const;
|
2007-08-05 20:03:26 +02:00
|
|
|
|
2007-08-05 19:11:46 +02:00
|
|
|
/**
|
|
|
|
* Sets the graphical icon for this Plasma::Icon.
|
2007-08-05 20:03:26 +02:00
|
|
|
* @param icon the KIcon to associate with this icon.
|
2007-08-05 19:11:46 +02:00
|
|
|
*/
|
2007-08-11 00:24:49 +02:00
|
|
|
void setIcon(const QIcon& icon);
|
2007-08-05 19:11:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method to set the icon of this Plasma::Icon
|
|
|
|
* using a QString path to the icon.
|
|
|
|
* @param icon the path to the icon to associate with this Plasma::Icon.
|
|
|
|
*/
|
|
|
|
Q_INVOKABLE void setIcon(const QString& icon);
|
|
|
|
|
|
|
|
/**
|
2007-08-05 20:03:26 +02:00
|
|
|
* @return the size of this Plasma::Icon's graphical icon.
|
2007-08-05 19:11:46 +02:00
|
|
|
*/
|
2007-08-05 20:03:26 +02:00
|
|
|
QSizeF iconSize() const;
|
2007-08-05 19:11:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Plasma::Icon allows the user to specify a number of actions
|
|
|
|
* (current four) to be displayed around the widget. This method
|
|
|
|
* allows for a created QAction (not a KAction!) to be added to
|
|
|
|
* the Plasma::Icon.
|
|
|
|
* @param action the QAction to associate with this icon.
|
|
|
|
*/
|
|
|
|
void addAction(QAction* action);
|
|
|
|
|
2007-11-10 16:16:33 +01:00
|
|
|
/**
|
2007-12-28 12:29:56 +01:00
|
|
|
* let set the orientation of the icon
|
|
|
|
* Qt::Vertical: text under the icon
|
|
|
|
* Qt::Horizontal text at a side of the icon depending
|
|
|
|
* by the direction of the language
|
|
|
|
* @param orientation the orientation we want
|
2007-11-10 16:16:33 +01:00
|
|
|
*/
|
2007-12-28 12:29:56 +01:00
|
|
|
void setOrientation(Qt::Orientation orientation);
|
2007-11-10 16:16:33 +01:00
|
|
|
|
2008-01-01 21:58:36 +01:00
|
|
|
/**
|
|
|
|
* inverts the layout of the icons if the orientation is horizontal,
|
|
|
|
* normally we get icon on the left with left-to-right languages
|
|
|
|
* @param invert if we want to invert the layout of icons
|
|
|
|
*/
|
|
|
|
void invertLayout(bool invert);
|
|
|
|
|
2008-01-02 11:39:29 +01:00
|
|
|
/**
|
|
|
|
* @return if the layout of the icons should appear inverted or not
|
|
|
|
*/
|
|
|
|
bool invertedLayout() const;
|
|
|
|
|
2007-12-23 11:51:00 +01:00
|
|
|
/**
|
|
|
|
* @return optimal size given a size for the icon
|
|
|
|
* @param iconWidth desidered width of the icon
|
|
|
|
*/
|
|
|
|
QSizeF sizeFromIconSize(const qreal iconWidth) const;
|
|
|
|
|
2007-12-26 14:44:57 +01:00
|
|
|
/**
|
|
|
|
* @return the number of lines allowed to display
|
|
|
|
*/
|
|
|
|
int numDisplayLines();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param numLines the number of lines to show in the display.
|
|
|
|
*/
|
|
|
|
void setNumDisplayLines(int numLines);
|
|
|
|
|
2008-01-03 22:22:24 +01:00
|
|
|
/**
|
|
|
|
* Sets whether or not to draw a background area for the icon
|
|
|
|
*
|
|
|
|
* @arg draw true if a background should be drawn or not
|
|
|
|
*/
|
|
|
|
void setDrawBackground(bool draw);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if a background area is to be drawn for the icon
|
|
|
|
*/
|
|
|
|
bool drawBackground() const;
|
2007-12-23 11:51:00 +01:00
|
|
|
|
2008-01-11 19:17:24 +01:00
|
|
|
/**
|
|
|
|
* reimplemented from QGraphicsItem
|
|
|
|
*/
|
|
|
|
QPainterPath shape() const;
|
|
|
|
|
2007-12-17 16:57:54 +01:00
|
|
|
public Q_SLOTS:
|
|
|
|
/**
|
|
|
|
* Sets the appearance of the icon to pressed or restores the appearance
|
|
|
|
* to normal. This does not simulate a mouse button press.
|
|
|
|
* @param pressed whether to appear as pressed (true) or as normal (false)
|
|
|
|
*/
|
|
|
|
void setPressed(bool pressed = true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcut for setPressed(false)
|
|
|
|
*/
|
|
|
|
void setUnpressed();
|
2007-12-16 11:09:07 +01:00
|
|
|
|
2007-08-05 19:11:46 +02:00
|
|
|
protected:
|
2008-04-13 23:47:47 +02:00
|
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
2007-08-05 19:11:46 +02:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
/**
|
2008-01-11 00:29:05 +01:00
|
|
|
* Indicates when the icon has been pressed.
|
|
|
|
*/
|
2007-08-05 19:11:46 +02:00
|
|
|
void pressed(bool down);
|
|
|
|
|
|
|
|
/**
|
2008-01-11 00:29:05 +01:00
|
|
|
* Indicates when the icon has been clicked.
|
|
|
|
*/
|
2007-08-05 19:11:46 +02:00
|
|
|
void clicked();
|
|
|
|
|
2008-01-10 21:18:11 +01:00
|
|
|
/**
|
2008-01-11 00:29:05 +01:00
|
|
|
* Indicates when the icon has been double-clicked
|
|
|
|
*/
|
2008-01-10 21:18:11 +01:00
|
|
|
void doubleClicked();
|
|
|
|
|
2008-01-11 21:30:25 +01:00
|
|
|
/**
|
|
|
|
* Indicates when the icon has been activated following the single
|
|
|
|
* or doubleclick settings
|
|
|
|
*/
|
|
|
|
void activated();
|
|
|
|
|
2007-08-05 19:11:46 +02:00
|
|
|
protected:
|
|
|
|
bool isDown();
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
2008-01-11 00:29:05 +01:00
|
|
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
2007-08-05 19:11:46 +02:00
|
|
|
|
|
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
|
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
|
|
|
|
|
|
|
public:
|
|
|
|
class Private;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
**/
|
|
|
|
void drawActionButtonBase(QPainter* painter, const QSize &size, int element);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void init();
|
2007-12-26 13:37:54 +01:00
|
|
|
void layoutIcons(const QStyleOptionGraphicsItem *option);
|
2008-02-27 01:50:07 +01:00
|
|
|
void hoverEffect(bool);
|
2007-08-05 19:11:46 +02:00
|
|
|
|
|
|
|
Private * const d;
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void actionDestroyed(QObject* obj);
|
2008-02-27 01:50:07 +01:00
|
|
|
void readColors();
|
|
|
|
void hoverAnimationUpdate(qreal progress);
|
|
|
|
|
2007-05-29 09:59:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Plasma
|
|
|
|
|
2007-07-20 08:28:51 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
// Add these to UrlIcon
|
|
|
|
void setUrl(const KUrl& url);
|
|
|
|
KUrl url() const;
|
|
|
|
*/
|
|
|
|
|
2007-05-29 09:59:50 +02:00
|
|
|
#endif
|