23#include <QGraphicsSceneResizeEvent>
33#include "private/themedwidgetinterface_p.h"
39class FramePrivate :
public ThemedWidgetInterface<Frame>
42 FramePrivate(Frame *parent)
43 : ThemedWidgetInterface<Frame>(parent),
67void FramePrivate::syncBorders()
70 qreal left, top, right, bottom;
75 QFontMetricsF fm(q->font());
79 q->setContentsMargins(left, top, right, bottom);
84 d(new FramePrivate(this))
91 connect(d->svg, SIGNAL(repaintNeeded()), SLOT(syncBorders()));
125void Frame::setEnabledBorders(
const FrameSvg::EnabledBorders borders)
134FrameSvg::EnabledBorders Frame::enabledBorders()
const
139void Frame::setText(QString text)
147QString Frame::text()
const
152void Frame::setImage(
const QString &path)
154 if (d->imagePath == path) {
164 bool absolutePath = !path.isEmpty() &&
166 !QDir::isRelativePath(path)
168 (path[0] ==
'/' || path.startsWith(QLatin1String(
":/")))
173 d->absImagePath = path;
179 if (path.isEmpty()) {
183 KMimeType::Ptr mime = KMimeType::findByPath(d->absImagePath);
185 if (!mime->is(
"image/svg+xml") && !mime->is(
"application/x-gzip")) {
186 d->pixmap =
new QPixmap(d->absImagePath);
193QString Frame::image()
const
198void Frame::setStyleSheet(
const QString &styleSheet)
204QString Frame::styleSheet()
const
206 return d->styleSheet;
221 if (!d->text.isNull()) {
222 QFontMetricsF fm(font());
224 textRect.setHeight(fm.height());
225 painter->setFont(font());
227 painter->drawText(textRect, Qt::AlignHCenter|Qt::AlignTop, d->text);
230 if (!d->imagePath.isNull()) {
231 if (d->pixmap && !d->pixmap->isNull()) {
232 painter->drawPixmap(contentsRect(), *d->pixmap, d->pixmap->rect());
233 }
else if (d->image) {
234 d->image->
paint(painter, contentsRect());
239void Frame::resizeEvent(QGraphicsSceneResizeEvent *event)
244 d->image->
resize(contentsRect().size());
247 QGraphicsWidget::resizeEvent(event);
250QSizeF Frame::sizeHint(Qt::SizeHint which,
const QSizeF & constraint)
const
252 QSizeF hint = QGraphicsWidget::sizeHint(which, constraint);
254 if (!d->image && !layout()) {
255 QFontMetricsF fm(font());
257 qreal left, top, right, bottom;
260 hint.setHeight(fm.height() + top + bottom);
261 if (which == Qt::MinimumSize || which == Qt::PreferredSize) {
262 QRectF rect = fm.boundingRect(d->text);
263 hint.setWidth(rect.width() + left + right);
270void Frame::changeEvent(QEvent *event)
272 d->changeEvent(event);
273 QGraphicsWidget::changeEvent(event);
Provides an SVG with borders.
Q_INVOKABLE void paintFrame(QPainter *painter, const QRectF &target, const QRectF &source=QRectF())
Paints the loaded SVG with the elements that represents the border.
Q_INVOKABLE void getMargins(qreal &left, qreal &top, qreal &right, qreal &bottom) const
Convenience method that extracts the size of the four margins in the four output parameters.
Q_INVOKABLE void resizeFrame(const QSizeF &size)
Resize the frame maintaining the same border size.
Q_INVOKABLE void setImagePath(const QString &path)
Loads a new Svg.
EnabledBorders enabledBorders
Q_INVOKABLE QRectF contentsRect() const
void setEnabledBorders(const EnabledBorders borders)
Sets what borders should be painted.
Q_INVOKABLE void setElementPrefix(Plasma::Location location)
Sets the prefix (.
A theme aware image-centric SVG class.
Q_INVOKABLE void paint(QPainter *painter, const QPointF &point, const QString &elementID=QString())
Paints all or part of the SVG represented by this object.
void setImagePath(const QString &svgFilePath)
Set the SVG file to render.
Q_INVOKABLE void resize(qreal width, qreal height)
Resizes the rendered image.
Q_INVOKABLE QString imagePath(const QString &name) const
Retrieve the path for an SVG image in the current theme.
static Theme * defaultTheme()
Singleton pattern accessor.
@ TextColor
the text color to be used by items resting on the background
Namespace for everything in libplasma.