Plasma
svg.cpp
72 SharedSvgRenderer::SharedSvgRenderer(const QString &filename, const QString &styleSheet, QHash<QString, QRectF> &interestingElements, QObject *parent)
85 SharedSvgRenderer::SharedSvgRenderer(const QByteArray &contents, const QString &styleSheet, QHash<QString, QRectF> &interestingElements, QObject *parent)
101 bool SharedSvgRenderer::load(const QByteArray &contents, const QString &styleSheet, QHash<QString, QRectF> &interestingElements)
113 if (reader.readNext() == QXmlStreamReader::StartElement && reader.qualifiedName() == QLatin1String("style")
136 static const QRegularExpression idExpr(QLatin1String("id\\s*?=\\s*?(['\"])(\\d+?-\\d+?-.*?)\\1"));
157 QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1Char('/') + QStringLiteral("plasma-svgelements");
173 void SvgRectsCache::insert(Plasma::SvgPrivate::CacheId cacheId, const QRectF &rect, unsigned int lastModified)
178 void SvgRectsCache::insert(uint id, const QString &filePath, const QRectF &rect, unsigned int lastModified)
296 void SvgRectsCache::insertSizeHintForId(const QString &path, const QString &id, const QSize &size)
302 ret += QString::number(s.width()) % QLatin1Char('x') % QString::number(s.height()) % QLatin1Char(',');
346 return imageGroup.readEntry(QStringLiteral("NaturalSize_") % QString::number(scaleFactor), QSizeF());
355 std::copy_if(list.begin(), list.end(), std::back_inserter(filtered), [](const QString element) {
418 return CacheId{idSize.width(), idSize.height(), path, elementId.toString(), status, devicePixelRatio, scaleFactor, -1, 0, lastModified};
424 auto cacheId = CacheId{double(size.width()), double(size.height()), path, id, status, devicePixelRatio, scaleFactor, colorGroup, 0, lastModified};
445 if (isThemed == themed && ((themed && themePath == actualPath) || (!themed && path == actualPath))) {
483 QObject::connect(cacheAndColorsTheme(), SIGNAL(themeChanged()), q, SLOT(themeChanged()), Qt::UniqueConnection);
516 if ((themed && !path.isEmpty() && lastModifiedDate.isValid()) || QFileInfo::exists(actualPath)) {
563 const QList<QSize> elementSizeHints = SvgRectsCache::instance()->sizeHintsForId(path, elementId);
570 && (!bestFit.isValid() || (bestFit.width() * bestFit.height()) > (hint.width() * hint.height()))) {
576 actualElementId = QString::number(bestFit.width()) % QLatin1Char('-') % QString::number(bestFit.height()) % QLatin1Char('-') % elementId;
598 if (cacheRendering && lastModified == SvgRectsCache::instance()->lastModifiedTimeFromCache(path)
607 QRectF finalRect = makeUniform(renderer->boundsOnElement(actualElementId), QRect(QPoint(0, 0), size));
633 cacheAndColorsTheme()->insertIntoCache(id, p, QString::number((qint64)q, 16) % QLatin1Char('_') % actualElementId);
672 QHash<QString, SharedSvgRenderer::Ptr>::const_iterator it = s_renderers.constFind(styleCrc + path);
697 const CacheId cacheId({-1.0, -1.0, path, elementId, status, devicePixelRatio, scaleFactor, -1, 0, lastModified});
753 // we need to check the id before createRenderer(), otherwise it may generate a different id compared to the previous cacheId)( call
760 // This code will usually never be run because createRenderer already caches all the boundingRect in the elements in the svg
762 ? renderer->transformForElement(elementIdString).map(renderer->boundsOnElement(elementIdString)).boundingRect()
770 elementRect = QRectF(elementRect.x() * dx, elementRect.y() * dy, elementRect.width() * dx, elementRect.height() * dy);
793 QObject::connect(actualTheme()->d, SIGNAL(applicationPaletteChange()), q, SLOT(colorsChanged()));
795 QObject::disconnect(actualTheme()->d, SIGNAL(applicationPaletteChange()), q, SLOT(colorsChanged()));
895 connect(SvgRectsCache::instance(), &SvgRectsCache::lastModifiedChanged, this, [this](const QString &filePath, unsigned int lastModified) {
912 //(it needs to be integer to have lines contained inside a svg piece to keep being pixel aligned)
935 //(it needs to be integer to have lines contained inside a svg piece to keep being pixel aligned)
997 QPixmap pix((elementID.isNull() || d->multipleImages) ? d->findInCache(elementID, ratio, size()) : d->findInCache(elementID, ratio));
1017 painter->drawPixmap(QRectF(rect.topLeft(), rect.size()), pix, QRectF(QPointF(0, 0), pix.size()));
1020 void Svg::paint(QPainter *painter, int x, int y, int width, int height, const QString &elementID)
1044 if (qFuzzyCompare(size.width(), d->size.width()) && qFuzzyCompare(size.height(), d->size.height())) {
Q_INVOKABLE QRectF elementRect(const QString &elementId) const
The bounding rect of a given element.
Definition: svg.cpp:1072
int devicePixelRatio() const const
bool isNull() const const
StartElement
qreal height() const const
Definition: Theme.qml:10
QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QString number(int n, int base)
ReadOnly
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
void start()
int size() const const
void setScaleFactor(qreal factor)
Setting a scale factor greater than one it will result in final images scaled by it.
Definition: svg.cpp:931
Q_EMITQ_EMIT
QSize size() const const
Q_INVOKABLE QImage image(const QSize &size, const QString &elementID=QString())
Returns an image of the SVG represented by this object.
Definition: svg.cpp:987
bool isEmpty() const const
qreal x() const const
qreal y() const const
Q_INVOKABLE QSize elementSize(const QString &elementId) const
Find the size of a given element.
Definition: svg.cpp:1062
void clear()
void fill(const QColor &color)
void setUsingRenderingCache(bool useCache)
Sets whether or not to cache the results of rendering to pixmaps.
Definition: svg.cpp:1137
QAction * load(const QObject *recvr, const char *slot, QObject *parent)
QString writableLocation(QStandardPaths::StandardLocation type)
bool insert(Part *part, qint64 *insertId=nullptr)
qreal scaleFactor() const
Setting a scale factor greater than one it will result in final images scaled by it.
Definition: svg.cpp:956
int width() const const
void setTheme(Plasma::Theme *theme)
Sets the Plasma::Theme to use with this Svg object.
Definition: svg.cpp:1167
KIOFILEWIDGETS_EXPORT QStringList list(const QString &fileClass)
void statusChanged(Plasma::Svg::Status status)
Emitted when the status changes.
bool exists() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QHash::iterator insert(const Key &key, const T &value)
static void colorize(QImage &image, const QColor &col, float value)
Q_GLOBAL_STATIC(Internal::StaticControl, s_instance) class ControlPrivate
bool isEmpty() const const
bool isValid() const const
virtual bool eventFilter(QObject *watched, QEvent *event)
QString toString() const const
int height() const const
QPointF topLeft() const const
void timeout()
bool isEmpty() const const
QByteArray toUtf8() const const
void setUseSystemColors(bool system)
Sets whether the Svg uses the global system theme for its colors or the Plasma theme.
Definition: svg.cpp:1152
void setContainsMultipleImages(bool multiple)
Set whether the SVG contains a single image or multiple ones.
Definition: svg.cpp:1115
Q_SCRIPTABLE CaptureState status()
static KIconLoader * global()
QSize toSize() const const
UniqueConnection
KCALENDARCORE_EXPORT uint qHash(const KCalendarCore::Period &key)
bool isEmpty() const const
Q_INVOKABLE void paint(QPainter *painter, const QPointF &point, const QString &elementID=QString())
Paints all or part of the SVG represented by this object.
Definition: svg.cpp:993
QImage toImage() const const
QAction * hint(const QObject *recvr, const char *slot, QObject *parent)
bool contains(char ch) const const
virtual void setImagePath(const QString &svgFilePath)
Set the SVG file to render.
Definition: svg.cpp:1125
bool isAbsolutePath(const QString &path)
bool isValid() const const
QString & replace(int position, int n, QChar after)
QString & remove(int position, int n)
bool isNull() const const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
Q_INVOKABLE QPixmap pixmap(const QString &elementID=QString())
Returns a pixmap of the SVG represented by this object.
Definition: svg.cpp:978
qint64 toSecsSinceEpoch() const const
GenericCacheLocation
bool isEmpty() const const
bool load(const QString &filename)
const char * constData() const const
QString path(const QString &relativePath)
QString & insert(int position, QChar ch)
QString fromLatin1(const char *str, int size)
bool isValid(QStringView ifopt)
KCOREADDONS_EXPORT Result match(QStringView pattern, QStringView str)
qreal width() const const
bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, QGenericReturnArgument ret, QGenericArgument val0, QGenericArgument val1, QGenericArgument val2, QGenericArgument val3, QGenericArgument val4, QGenericArgument val5, QGenericArgument val6, QGenericArgument val7, QGenericArgument val8, QGenericArgument val9)
Status
Q_INVOKABLE bool isValid() const
Check whether this object is backed by a valid SVG file.
Definition: svg.cpp:1096
QFuture< typename Sequence::value_type > filtered(const Sequence &sequence, KeepFunctor filterFunction)
void reserve(int size)
bool isValid() const const
QPaintDevice * device() const const
QList::iterator begin()
Q_INVOKABLE bool hasElement(const QString &elementId) const
Check whether an element exists in the loaded SVG.
Definition: svg.cpp:1082
QSizeF size() const const
Q_INVOKABLE void resize()
Resizes the rendered image to the natural size of the SVG.
Definition: svg.cpp:1052
int size() const const
KGuiItem ok()
bool containsMultipleImages() const
Whether the SVG contains multiple images.
Definition: svg.cpp:1120
QList::iterator end()
SimpleConfig
QVector< V > values(const QMultiHash< K, V > &c)
KIconTheme * theme() const
QString & append(QChar ch)
transparent
void setDevicePixelRatio(qreal scaleFactor)
void repaintNeeded()
Emitted whenever the SVG data has changed in such a way that a repaint is required.
void setColorGroup(Plasma::Theme::ColorGroup group)
Set a color group for the Svg.
Definition: svg.cpp:961
qreal width() const const
bool isUsingRenderingCache() const
Whether the rendering cache is being used.
Definition: svg.cpp:1142
qreal height() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Mar 23 2023 04:18:17 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Mar 23 2023 04:18:17 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.