2008-02-06 17:51:07 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2008 by Aaron Seigo <aseigo@kde.org>
|
|
|
|
* Copyright 2008 Marco Martin <notmart@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
#ifndef PLASMA_PANELSVG_H
|
|
|
|
#define PLASMA_PANELSVG_H
|
2008-02-06 17:51:07 +01:00
|
|
|
|
|
|
|
#include <QtCore/QObject>
|
2008-03-02 03:18:10 +01:00
|
|
|
#include <QtGui/QPixmap>
|
2008-02-06 17:51:07 +01:00
|
|
|
|
|
|
|
#include <plasma/plasma_export.h>
|
|
|
|
|
2008-02-06 20:12:21 +01:00
|
|
|
#include <plasma/plasma.h>
|
2008-02-06 17:51:07 +01:00
|
|
|
#include <plasma/svg.h>
|
|
|
|
|
|
|
|
class QPainter;
|
|
|
|
class QPoint;
|
|
|
|
class QPointF;
|
|
|
|
class QRect;
|
|
|
|
class QRectF;
|
|
|
|
class QSize;
|
|
|
|
class QSizeF;
|
|
|
|
class QMatrix;
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
class PanelSvgPrivate;
|
|
|
|
|
2008-08-25 19:47:48 +02:00
|
|
|
/**
|
|
|
|
* @class PanelSvg plasma/panelsvg.h <Plasma/PanelSvg>
|
|
|
|
*
|
|
|
|
* @short Provides an SVG with borders.
|
|
|
|
*
|
|
|
|
* When using SVG images for a background of an object that may change
|
|
|
|
* its aspect ratio, such as a dialog, simply scaling a single image
|
|
|
|
* may not be enough.
|
|
|
|
*
|
|
|
|
* PanelSvg allows SVGs to provide several elements for borders as well
|
|
|
|
* as a central element, each of which are scaled individually. These
|
|
|
|
* elements should be named
|
|
|
|
*
|
|
|
|
* - @c center - the central element, which will be scaled in both directions
|
|
|
|
* - @c top - the top border; the height is fixed, but it will be scaled
|
|
|
|
* horizontally to the same width as @c center
|
|
|
|
* - @c bottom - the bottom border; scaled in the same way as @c top
|
|
|
|
* - @c left - the left border; the width is fixed, but it will be scaled
|
|
|
|
* vertically to the same height as @c center
|
|
|
|
* - @c right - the right border; scaled in the same way as @c left
|
|
|
|
* - @c topleft - fixed size; must be the same height as @c top and the same
|
|
|
|
* width as @c left
|
|
|
|
* - @c bottomleft, @c topright, @c bottomright - similar to @c topleft
|
|
|
|
*
|
|
|
|
* @c center must exist, but all the others are optional. @c topleft and
|
|
|
|
* @c topright will be ignored if @c top does not exist, and similarly for
|
|
|
|
* @c bottomleft and @c bottomright.
|
|
|
|
*
|
|
|
|
* @see Plamsa::Svg
|
|
|
|
**/
|
2008-04-16 22:17:36 +02:00
|
|
|
class PLASMA_EXPORT PanelSvg : public Svg
|
2008-02-06 17:51:07 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* These flags represents what borders should be drawn
|
|
|
|
*/
|
2008-05-03 18:03:44 +02:00
|
|
|
enum EnabledBorder { NoBorder = 0,
|
|
|
|
TopBorder = 1,
|
2008-04-16 22:17:36 +02:00
|
|
|
BottomBorder = 2,
|
|
|
|
LeftBorder = 4,
|
|
|
|
RightBorder = 8,
|
|
|
|
AllBorders = TopBorder | BottomBorder |
|
|
|
|
LeftBorder | RightBorder
|
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(EnabledBorders, EnabledBorder)
|
2008-02-06 17:51:07 +01:00
|
|
|
|
|
|
|
/**
|
2008-04-16 19:23:58 +02:00
|
|
|
* Constructs a new PanelSvg that paints the proper named subelements
|
2008-04-25 18:18:51 +02:00
|
|
|
* as borders. It may also be used as a regular Plasma::Svg object
|
|
|
|
* for direct access to elements in the Svg.
|
2008-02-06 17:51:07 +01:00
|
|
|
*
|
|
|
|
* @arg parent options QObject to parent this to
|
|
|
|
*
|
|
|
|
* @related Plasma::Theme
|
|
|
|
*/
|
2008-04-23 15:07:41 +02:00
|
|
|
explicit PanelSvg(QObject* parent = 0);
|
2008-04-16 19:23:58 +02:00
|
|
|
~PanelSvg();
|
2008-02-06 17:51:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads a new Svg
|
|
|
|
* @arg imagePath the new file
|
|
|
|
*/
|
2008-04-22 22:25:28 +02:00
|
|
|
void setImagePath(const QString& path);
|
2008-02-06 17:51:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets what borders should be painted
|
|
|
|
* @arg flags borders we want to paint
|
|
|
|
*/
|
2008-04-16 22:17:36 +02:00
|
|
|
void setEnabledBorders(const EnabledBorders borders);
|
2008-02-06 17:51:07 +01:00
|
|
|
|
|
|
|
/**
|
2008-04-16 22:17:36 +02:00
|
|
|
* Convenience method to get the enabled borders
|
2008-02-06 17:51:07 +01:00
|
|
|
* @return what borders are painted
|
|
|
|
*/
|
2008-04-16 22:17:36 +02:00
|
|
|
EnabledBorders enabledBorders() const;
|
2008-02-06 17:51:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Resize the panel maintaining the same border size
|
|
|
|
* @arg size the new size of the panel
|
|
|
|
*/
|
2008-04-23 22:38:09 +02:00
|
|
|
void resizePanel(const QSizeF& size);
|
2008-04-16 22:17:36 +02:00
|
|
|
|
2008-05-03 18:03:44 +02:00
|
|
|
/**
|
|
|
|
* @returns the size of the panel
|
|
|
|
*/
|
|
|
|
QSizeF panelSize() const;
|
|
|
|
|
2008-02-06 17:51:07 +01:00
|
|
|
/**
|
|
|
|
* Returns the margin size given the margin edge we want
|
|
|
|
* @arg edge the margin edge we want, top, bottom, left or right
|
|
|
|
* @return the margin size
|
|
|
|
*/
|
2008-02-06 20:12:21 +01:00
|
|
|
qreal marginSize(const Plasma::MarginEdge edge) const;
|
2008-02-06 17:51:07 +01:00
|
|
|
|
2008-05-01 11:49:30 +02:00
|
|
|
/**
|
|
|
|
* Convenience method that extracts the size of the four margins
|
|
|
|
* in the four output parameters
|
|
|
|
* @arg left left margin size
|
|
|
|
* @arg top top margin size
|
|
|
|
* @arg right right margin size
|
|
|
|
* @arg bottom bottom margin size
|
|
|
|
*/
|
|
|
|
void getMargins(qreal &left, qreal &top, qreal &right, qreal &bottom) const;
|
|
|
|
|
2008-08-23 22:36:09 +02:00
|
|
|
/**
|
|
|
|
* @return the rectangle of the center element, taking the margins into account.
|
|
|
|
*/
|
|
|
|
QRectF contentsRect() const;
|
|
|
|
|
2008-02-15 10:04:12 +01:00
|
|
|
/**
|
2008-04-16 22:17:36 +02:00
|
|
|
* Sets the prefix (@see setElementPrefix) to 'north', 'south', 'west' and 'east'
|
2008-03-23 18:50:49 +01:00
|
|
|
* when the location is TopEdge, BottomEdge, LeftEdge and RightEdge,
|
|
|
|
* respectively. Clears the prefix in other cases.
|
|
|
|
* @arg location location
|
|
|
|
*/
|
2008-04-16 22:17:36 +02:00
|
|
|
void setElementPrefix(Plasma::Location location);
|
2008-03-23 18:50:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the prefix for the SVG elements to be used for painting. For example,
|
|
|
|
* if prefix is 'active', then instead of using the 'top' element of the SVG
|
|
|
|
* file to paint the top border, 'active-top' element will be used. The same
|
|
|
|
* goes for other SVG elements.
|
|
|
|
*
|
|
|
|
* If the elements with prefixes are not present, the default ones are used.
|
|
|
|
* (for the sake of speed, the test is present only for the 'center' element)
|
|
|
|
*
|
|
|
|
* Setting the prefix manually resets the location to Floating.
|
|
|
|
* If the
|
|
|
|
* @arg prefix prefix for the SVG element names
|
|
|
|
*/
|
2008-04-16 22:17:36 +02:00
|
|
|
void setElementPrefix(const QString & prefix);
|
2008-03-23 18:50:49 +01:00
|
|
|
|
2008-05-01 22:09:24 +02:00
|
|
|
/**
|
|
|
|
* @return true if the svg has the necessary elements with the given prefix
|
|
|
|
* to draw a panel
|
|
|
|
* @arg prefix the given prefix we want to check if drawable
|
|
|
|
*/
|
|
|
|
bool hasElementPrefix(const QString & prefix) const;
|
|
|
|
|
2008-05-02 15:25:04 +02:00
|
|
|
/**
|
|
|
|
* This is an overloaded method provided for convenience equivalent to
|
|
|
|
* hasElementPrefix("north"), hasElementPrefix("south")
|
|
|
|
* hasElementPrefix("west") and hasElementPrefix("east")
|
|
|
|
* @return true if the svg has the necessary elements with the given prefix
|
|
|
|
* to draw a panel.
|
|
|
|
* @arg location the given prefix we want to check if drawable
|
|
|
|
*/
|
|
|
|
bool hasElementPrefix(Plasma::Location location) const;
|
|
|
|
|
2008-03-23 18:50:49 +01:00
|
|
|
/**
|
2008-04-16 19:23:58 +02:00
|
|
|
* Returns the prefix for SVG elements of the PanelSvg
|
2008-03-23 18:50:49 +01:00
|
|
|
* @return the prefix
|
|
|
|
*/
|
|
|
|
QString prefix();
|
|
|
|
|
2008-03-05 22:03:27 +01:00
|
|
|
/**
|
|
|
|
* Returns a monochrome mask that tightly contains the fully opaque areas of the svg
|
|
|
|
* @return a monochrome bitmap of opaque areas
|
|
|
|
*/
|
|
|
|
QBitmap mask() const;
|
|
|
|
|
2008-04-21 16:01:46 +02:00
|
|
|
/**
|
|
|
|
* Sets whether saving all the rendered prefixes in a cache or not
|
|
|
|
* @arg cache if use the cache or not
|
|
|
|
*/
|
|
|
|
void setCacheAllRenderedPanels(bool cache);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return if all the different prefixes should be kept in a cache when rendered
|
|
|
|
*/
|
|
|
|
bool cacheAllRenderedPanels() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes the internal cache freeing memory: use this if you want to switch the rendered
|
|
|
|
* element and you don't plan to switch back to the previous one for a long time and you
|
|
|
|
* used setUseCache(true)
|
|
|
|
*/
|
|
|
|
void clearCache();
|
|
|
|
|
2008-02-06 17:51:07 +01:00
|
|
|
/**
|
|
|
|
* Paints the loaded SVG with the elements that represents the border
|
|
|
|
* @arg painter the QPainter to use
|
2008-07-27 19:20:27 +02:00
|
|
|
* @arg target the target rectangle on the paint device
|
|
|
|
* @arg source the portion rectangle of the source image
|
2008-02-06 17:51:07 +01:00
|
|
|
*/
|
2008-09-23 01:15:57 +02:00
|
|
|
Q_INVOKABLE void paintPanel(QPainter* painter, const QRectF& target,
|
|
|
|
const QRectF& source = QRectF());
|
2008-07-27 19:20:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Paints the loaded SVG with the elements that represents the border
|
|
|
|
* This is an overloaded member provided for convenience
|
|
|
|
* @arg painter the QPainter to use
|
|
|
|
* @arg pos where to paint the svg
|
|
|
|
*/
|
|
|
|
Q_INVOKABLE void paintPanel(QPainter* painter, const QPointF& pos = QPointF(0, 0));
|
2008-02-06 17:51:07 +01:00
|
|
|
|
|
|
|
private:
|
2008-07-01 20:56:43 +02:00
|
|
|
PanelSvgPrivate * const d;
|
2008-04-16 22:17:36 +02:00
|
|
|
|
2008-04-17 00:01:51 +02:00
|
|
|
Q_PRIVATE_SLOT(d, void updateSizes())
|
2008-05-24 17:33:35 +02:00
|
|
|
Q_PRIVATE_SLOT(d, void updateNeeded())
|
2008-02-06 17:51:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // Plasma namespace
|
2008-02-06 20:24:48 +01:00
|
|
|
|
2008-04-16 22:17:36 +02:00
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::PanelSvg::EnabledBorders)
|
2008-02-06 20:24:48 +01:00
|
|
|
|
2008-02-06 17:51:07 +01:00
|
|
|
#endif // multiple inclusion guard
|