2007-03-08 00:27:37 +01:00
|
|
|
/*
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
|
2007-03-08 00:27:37 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-08-06 13:20:02 +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-03-08 00:27:37 +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 PLASMA_SVG_H
|
|
|
|
#define PLASMA_SVG_H
|
|
|
|
|
|
|
|
#include <QtCore/QObject>
|
|
|
|
|
2007-06-02 19:29:39 +02:00
|
|
|
#include <plasma/plasma_export.h>
|
2007-03-08 00:27:37 +01:00
|
|
|
|
2007-04-22 11:35:04 +02:00
|
|
|
class QPainter;
|
|
|
|
class QPoint;
|
2007-05-21 16:28:03 +02:00
|
|
|
class QPointF;
|
2007-04-23 01:04:47 +02:00
|
|
|
class QRect;
|
2007-05-21 16:28:03 +02:00
|
|
|
class QRectF;
|
2007-04-23 01:04:47 +02:00
|
|
|
class QSize;
|
2007-05-21 16:28:03 +02:00
|
|
|
class QSizeF;
|
2007-08-02 18:14:35 +02:00
|
|
|
class QMatrix;
|
2007-04-22 11:35:04 +02:00
|
|
|
|
2007-03-08 00:27:37 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
class SvgPrivate;
|
|
|
|
class PanelSvgPrivate;
|
|
|
|
|
2007-05-27 10:01:31 +02:00
|
|
|
/**
|
2008-08-25 19:47:48 +02:00
|
|
|
* @class Svg plasma/svg.h <Plasma/Svg>
|
|
|
|
*
|
|
|
|
* @short A theme aware image-centric SVG class
|
2007-05-27 10:01:31 +02:00
|
|
|
*
|
|
|
|
* Plasma::Svg provides a class for rendering SVG images to a QPainter in a
|
|
|
|
* convenient manner. Unless an absolute path to a file is provided, it loads
|
|
|
|
* the SVG document using Plasma::Theme. It also provides a number of internal
|
|
|
|
* optimizations to help lower the cost of painting SVGs, such as caching.
|
2008-08-25 19:47:48 +02:00
|
|
|
*
|
|
|
|
* @see Plasma::PanelSvg
|
2007-05-27 10:01:31 +02:00
|
|
|
**/
|
2007-05-20 22:13:46 +02:00
|
|
|
class PLASMA_EXPORT Svg : public QObject
|
2007-03-08 00:27:37 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2008-09-15 17:32:01 +02:00
|
|
|
Q_ENUMS(ContentType)
|
|
|
|
Q_PROPERTY(QSize size READ size)
|
|
|
|
Q_PROPERTY(bool multipleImages READ containsMultipleImages WRITE setContainsMultipleImages)
|
|
|
|
Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath)
|
2007-03-08 00:27:37 +01:00
|
|
|
|
|
|
|
public:
|
2007-05-29 22:27:51 +02:00
|
|
|
|
2007-03-08 00:27:37 +01:00
|
|
|
/**
|
|
|
|
* Constructs an SVG object that implicitly shares and caches rendering
|
|
|
|
* As opposed to QSvgRenderer, which this class uses internally,
|
|
|
|
* Plasma::Svg represents an image generated from an SVG. As such, it
|
|
|
|
* has a related size and transform matrix (the latter being provided
|
|
|
|
* by the painter used to paint the image).
|
|
|
|
*
|
|
|
|
* The size is initialized to be the SVG's native size.
|
|
|
|
*
|
|
|
|
* @arg parent options QObject to parent this to
|
2007-05-21 16:28:03 +02:00
|
|
|
*
|
|
|
|
* @related Plasma::Theme
|
2007-03-08 00:27:37 +01:00
|
|
|
*/
|
2008-04-23 15:07:41 +02:00
|
|
|
explicit Svg(QObject* parent = 0);
|
2007-03-08 00:27:37 +01:00
|
|
|
~Svg();
|
|
|
|
|
2007-05-29 22:27:51 +02:00
|
|
|
|
2007-03-08 00:27:37 +01:00
|
|
|
/**
|
|
|
|
* Paints the SVG represented by this object
|
|
|
|
* @arg painter the QPainter to use
|
|
|
|
* @arg point the position to start drawing; the entire svg will be
|
|
|
|
* drawn starting at this point.
|
|
|
|
*/
|
2007-07-22 19:41:47 +02:00
|
|
|
Q_INVOKABLE void paint(QPainter* painter, const QPointF& point,
|
2007-07-22 22:00:13 +02:00
|
|
|
const QString& elementID = QString());
|
2007-03-08 00:27:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Paints the SVG represented by this object
|
|
|
|
* @arg painter the QPainter to use
|
|
|
|
* @arg x the horizontal coordinate to start painting from
|
|
|
|
* @arg y the vertical coordinate to start painting from
|
|
|
|
*/
|
2007-07-22 19:41:47 +02:00
|
|
|
Q_INVOKABLE void paint(QPainter* painter, int x, int y,
|
2007-07-22 22:00:13 +02:00
|
|
|
const QString& elementID = QString());
|
2007-03-08 00:27:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Paints the SVG represented by this object
|
|
|
|
* @arg painter the QPainter to use
|
|
|
|
* @arg rect the rect to draw into; if small than the current size
|
|
|
|
* of the
|
|
|
|
* drawn starting at this point.
|
|
|
|
*/
|
2007-07-22 19:41:47 +02:00
|
|
|
Q_INVOKABLE void paint(QPainter* painter, const QRectF& rect,
|
2007-07-22 22:00:13 +02:00
|
|
|
const QString& elementID = QString());
|
2007-03-08 00:27:37 +01:00
|
|
|
|
2008-04-16 16:31:43 +02:00
|
|
|
/**
|
|
|
|
* Currently set size of the SVG
|
|
|
|
* @return the current size of a given element
|
|
|
|
**/
|
|
|
|
QSize size() const;
|
|
|
|
|
2007-03-08 00:27:37 +01:00
|
|
|
/**
|
|
|
|
* Resizes the rendered image. Rendering will actually take place on
|
|
|
|
* the next call to paint.
|
|
|
|
* @arg width the new width
|
|
|
|
* @arg height the new height
|
|
|
|
**/
|
2008-04-16 19:23:58 +02:00
|
|
|
Q_INVOKABLE void resize( qreal width, qreal height );
|
2007-03-08 00:27:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Resizes the rendered image. Rendering will actually take place on
|
|
|
|
* the next call to paint.
|
|
|
|
* @arg size the new size of the image
|
|
|
|
**/
|
2007-07-20 23:00:11 +02:00
|
|
|
Q_INVOKABLE void resize( const QSizeF& size );
|
2007-05-19 00:05:00 +02:00
|
|
|
|
2007-05-21 00:56:38 +02:00
|
|
|
/**
|
|
|
|
* Resizes the rendered image to the natural size of the SVG.
|
|
|
|
* Rendering will actually take place on the next call to paint.
|
|
|
|
**/
|
2007-07-20 23:00:11 +02:00
|
|
|
Q_INVOKABLE void resize();
|
2007-05-21 00:56:38 +02:00
|
|
|
|
2007-05-19 00:05:00 +02:00
|
|
|
/**
|
|
|
|
* Size of a given element
|
|
|
|
* @arg elementId the id of the element to check
|
2007-07-27 01:07:26 +02:00
|
|
|
* @return the current size of a given element, given the current size of the Svg
|
2007-05-19 00:05:00 +02:00
|
|
|
**/
|
2007-07-20 23:00:11 +02:00
|
|
|
Q_INVOKABLE QSize elementSize( const QString& elementId ) const;
|
2007-03-08 00:27:37 +01:00
|
|
|
|
2007-07-27 01:07:26 +02:00
|
|
|
/**
|
|
|
|
* The bounding rect of a given element
|
|
|
|
* @arg elementId the id of the element to check
|
|
|
|
* @return the current rect of a given element, given the current size of the Svg
|
|
|
|
**/
|
2008-04-16 16:31:43 +02:00
|
|
|
Q_INVOKABLE QRectF elementRect(const QString& elementId) const;
|
2007-07-27 01:07:26 +02:00
|
|
|
|
2007-05-29 22:27:51 +02:00
|
|
|
/**
|
|
|
|
* Check when an element exists in the loaded Svg
|
|
|
|
* @arg elementId the id of the element to check
|
|
|
|
* @return true if the element is defined in the Svg, otherwise false
|
|
|
|
**/
|
2008-04-16 16:31:43 +02:00
|
|
|
Q_INVOKABLE bool hasElement( const QString& elementId ) const;
|
2007-05-29 22:27:51 +02:00
|
|
|
|
2007-11-17 22:34:28 +01:00
|
|
|
/**
|
|
|
|
* Returns the element (by id) at the given point. An empty string is
|
|
|
|
* returned if no element is at that point.
|
|
|
|
*/
|
|
|
|
Q_INVOKABLE QString elementAtPoint(const QPoint &point) const;
|
|
|
|
|
2007-07-23 02:50:10 +02:00
|
|
|
/**
|
|
|
|
* @return true if the SVG file exists and the document is valid,
|
|
|
|
* otherwise false. This method can be expensive as it
|
|
|
|
* causes disk access.
|
|
|
|
**/
|
|
|
|
Q_INVOKABLE bool isValid() const;
|
|
|
|
|
2008-04-17 11:09:48 +02:00
|
|
|
/**
|
|
|
|
* Set if the svg contains a single image or multiple ones.
|
|
|
|
* @arg multiple true if the svg contains multiple images
|
|
|
|
*/
|
|
|
|
void setContainsMultipleImages(bool multiple);
|
2007-05-29 22:27:51 +02:00
|
|
|
|
2008-04-17 11:09:48 +02:00
|
|
|
/**
|
|
|
|
* @return whether or not the svg contains multiple images or not
|
|
|
|
*/
|
|
|
|
bool containsMultipleImages() const;
|
2007-05-29 22:27:51 +02:00
|
|
|
|
2007-12-19 21:29:22 +01:00
|
|
|
/**
|
|
|
|
* Convenience method for setting the svg file to use for the Svg.
|
|
|
|
* @arg svgFilePath the filepath including name of the svg.
|
|
|
|
*/
|
2008-04-16 22:48:53 +02:00
|
|
|
void setImagePath(const QString &svgFilePath);
|
2007-12-19 21:29:22 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method to get the svg filepath and name of svg.
|
|
|
|
* @return the svg's filepath including name of the svg.
|
|
|
|
*/
|
2008-04-16 22:48:53 +02:00
|
|
|
QString imagePath() const;
|
2007-12-19 21:29:22 +01:00
|
|
|
|
2007-03-08 00:27:37 +01:00
|
|
|
Q_SIGNALS:
|
|
|
|
void repaintNeeded();
|
|
|
|
|
|
|
|
private:
|
2008-07-01 20:56:43 +02:00
|
|
|
SvgPrivate* const d;
|
2008-04-16 22:30:18 +02:00
|
|
|
|
2008-04-17 00:01:51 +02:00
|
|
|
Q_PRIVATE_SLOT(d, void themeChanged())
|
|
|
|
Q_PRIVATE_SLOT(d, void colorsChanged())
|
2008-07-01 20:56:43 +02:00
|
|
|
|
|
|
|
friend class SvgPrivate;
|
|
|
|
friend class PanelSvgPrivate;
|
2007-03-08 00:27:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // Plasma namespace
|
|
|
|
|
|
|
|
#endif // multiple inclusion guard
|
|
|
|
|