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;
72 svg->getMargins(left, top, right, bottom);
75 QFontMetricsF fm(q->font());
79 q->setContentsMargins(left, top, right, bottom);
84 d(new FramePrivate(this))
87 d->svg->setImagePath(
"widgets/frame");
88 d->svg->setElementPrefix(
"plain");
91 connect(d->svg, SIGNAL(repaintNeeded()), SLOT(syncBorders()));
106 d->svg->setElementPrefix(
"raised");
109 d->svg->setElementPrefix(
"sunken");
113 d->svg->setElementPrefix(
"plain");
125void Frame::setEnabledBorders(
const FrameSvg::EnabledBorders borders)
127 if (borders != d->svg->enabledBorders()) {
128 d->svg->setEnabledBorders(borders);
134FrameSvg::EnabledBorders Frame::enabledBorders()
const
136 return d->svg->enabledBorders();
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);
189 d->image->setImagePath(path);
193QString Frame::image()
const
198void Frame::setStyleSheet(
const QString &styleSheet)
204QString Frame::styleSheet()
const
206 return d->styleSheet;
219 d->svg->paintFrame(painter);
221 if (!d->text.isNull()) {
222 QFontMetricsF fm(font());
223 QRectF textRect = d->svg->contentsRect();
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)
241 d->svg->resizeFrame(event->newSize());
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;
258 d->svg->getMargins(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.
A theme aware image-centric SVG class.
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.