In addition to being used as a file load, some objects return or take pixmaps and the QPixmap object facilitates that as well.

In addition to being used as a file load, some objects return or take pixmaps and the QPixmap object facilitates that as well.

Line 46:

Line 46:

==Svg==

==Svg==

Constructors:

Constructors:

−

*'''Svg(string fileName)'''': fileName can be a file in the desktop theme or the plasmoid package

+

*'''Svg(string fileName)'''': fileName can be a file in the desktop theme or the plasmoid package; it will first look in the "images" directory of the plasmoid package, then in the current desktop theme (and its fallbacks), then (from 4.11 onwards) in the "theme" directory of the plasmoid package.

Revision as of 19:19, 9 April 2013

Contents

Painting

See the "Painting and Layout" section, part of the Global Plasmoid object chapter, for information on using these classes within a widget.

Pixmaps

The QPixmap object allows widgets to use pixmaps for painting. Widgets may include pixmaps in various common formats (PNG, JPEG, GIF, etc.) in the contents/images/ directory of the Plasmoid package and load them by passing the name of the file into the pixmap constructor:

var pixmap =new QPixmap("myimage.png")

In addition to being used as a file load, some objects return or take pixmaps and the QPixmap object facilitates that as well.

Read-only properties:

booleannull: true if the pixmap is empty

QRectFrect: the rect of the pixmap

Functions:

QPixmapscaled(number width, number height): returns a scaled version of the pixmap with width and height dimensions.

Icons

(Since 4.4.1)

The QIcon object provides simple access to icons. They can be constructed using a String or a QPixmap, with the String version either loading a file from disk if given an absolute path (useful for loading icons from the Plasmoid's package) or from the desktop icon theme if given just a name (e.g. "file-open").

Read-only properties:

booleannull: true if the icon is empty

Functions:

addPixmap(QPixmap): adds another pixmap to this icon

addFile(String): adds another file to this icon

SVG Images

Plasma makes heavy usage of SVG images. More information on this industry standard scalable vector format can be found here:

Free and Open Source Software tools for creating SVGs include Inkscape and Karbon13. Widgets may include their own SVG files in the contents/images/ directory or may use SVG images that are part of the standard Plasma Desktop Theme as documented here:

Svg

Constructors:

Svg(string fileName)': fileName can be a file in the desktop theme or the plasmoid package; it will first look in the "images" directory of the plasmoid package, then in the current desktop theme (and its fallbacks), then (from 4.11 onwards) in the "theme" directory of the plasmoid package.

Read-only properties:

QSizeFsize: the current size of the svg

Read-write properties:

booleanmultipleImages: whether or not the svg contains multiple separate images

stringimagePath: the file path, including name of the svg

boolean 'usingRenderingCache: whether or not to cache rendered pixmaps; improves performance (at the cost of some disk and memory usage) for SVG data that is repeatedly rendered

Functions:

QSizeF elementSize(String svgElemen)

QRectF elementRect(String svgElemen)

booleanhasElement(String svgElement)

elementAtPoint(QPoint pos)

booleanisValid()

QPixmappixmap(String svgElement): a pixmap of the element in the svg rendered to the current size

QPixmappixmap(): a pixmap of the entire svg rendered to the current size

paint(QPainter painter, QPointF point)

paint(QPainter painter, QPointF point, String svgElement)

paint(QPainter painter, number x, number y)

paint(QPainter painter, number x, number y, String svgElement)

paint(QPainter painter, QRectF destination)

paint(QPainter painter, QRectF destination, String svgElement)

paint(QPainter painter, number y, number width, number height)

paint(QPainter painter, number x, number y, number width, number height, QString svgElement)

resize(number width, number height)

resize(QSizeF size)

resize(): resizes the SVG to the document size defined in the SVG itself

Signals:

repaintNeeded(): emitted when the SVG is in need of a repaint, such as when the theme changes and the SVG has reloaded its data

FrameSvg

Constructors:

FrameSvg(String fileName): fileName can be a file in the desktop theme or the plasmoid package

Read-only properties:

booleanmultipleImages: whether or not the svg contains multiple separate images

Functions:

setEnabledBorders(EnabledBorders borders): sets which borders are enabled when painting

EnabledBordersenabledBorders(): the borders which are enabled when painting

resizeFrame(QSizeF size): resizes the frame to size

QSizeFframeSize(): the size of the current frame

numbermarginSize(MarginEdge margin): the size of the margin for a given edge

getMargins(number left, number top, number right, number bottom): stores the margin values in the variables passed in

QRectFcontentsRect(): the rect containing the contents, e.g. the size of the SVG minus the space required by the enabled borders

setElementPrefix(Location): sets the frame element for the given location if it exists

setElementPrefix(String prefix): sets the element prefix

booleanhasElementPrefix(String prefix): returns true if the SVG contains a frame with the given prefix

booleanhasElementPrefix(Location location): true if the SVG contains a frame element for the given location

prefix()

mask()

setCacheAllRenderedFrames(bool)

cacheAllRenderedFrames()

QPixmapframePixmap(): a pixmap containing the current frame at the current size

paintFrame(QPainter painter)

paintFrame(QPainter painter, QPointF target)

paintFrame(QPainter painter, QRectF target)

paintFrame(QPainter painter, QRectF target, QRectF source)

Enumerations

EnabledBorder

NoBorder

TopBorder

BottomBorder

LeftBorder

RightBorder

AllBorders

Painting on the Canvas

QColor

Constructors:

QColor

QColor(string colorName)

QColor(number red, number green, number blue, number alpha)

Functions:

setThemeColor(ThemeColor color): sets the color to the appropriate ThemeColor