2010-10-12 21:51:57 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Marco Martin <mart@kde.org>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2011-11-01 19:27:55 +01:00
|
|
|
#include "framesvgitem.h"
|
2010-10-12 21:51:57 +02:00
|
|
|
|
2012-04-10 00:22:13 +02:00
|
|
|
#include <QPainter>
|
2010-10-12 21:51:57 +02:00
|
|
|
|
|
|
|
#include "kdebug.h"
|
2010-11-05 21:50:28 +01:00
|
|
|
|
2010-10-12 21:51:57 +02:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
FrameSvgItemMargins::FrameSvgItemMargins(Plasma::FrameSvg *frameSvg, QObject *parent)
|
|
|
|
: QObject(parent),
|
|
|
|
m_frameSvg(frameSvg)
|
|
|
|
{
|
2012-11-12 01:44:51 +01:00
|
|
|
//kDebug() << "margins at: " << left() << top() << right() << bottom();
|
2012-11-07 12:43:11 +01:00
|
|
|
connect(m_frameSvg, SIGNAL(repaintNeeded()), this, SLOT(update()));
|
2010-10-12 21:51:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
qreal FrameSvgItemMargins::left() const
|
|
|
|
{
|
|
|
|
return m_frameSvg->marginSize(LeftMargin);
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal FrameSvgItemMargins::top() const
|
|
|
|
{
|
|
|
|
return m_frameSvg->marginSize(TopMargin);
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal FrameSvgItemMargins::right() const
|
|
|
|
{
|
|
|
|
return m_frameSvg->marginSize(RightMargin);
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal FrameSvgItemMargins::bottom() const
|
|
|
|
{
|
|
|
|
return m_frameSvg->marginSize(BottomMargin);
|
|
|
|
}
|
|
|
|
|
2012-11-07 12:43:11 +01:00
|
|
|
void FrameSvgItemMargins::update()
|
|
|
|
{
|
|
|
|
emit marginsChanged();
|
|
|
|
}
|
|
|
|
|
2013-02-01 17:26:26 +01:00
|
|
|
FrameSvgItem::FrameSvgItem(QQuickItem *parent)
|
|
|
|
: QQuickItem(parent)
|
2010-10-12 21:51:57 +02:00
|
|
|
{
|
|
|
|
m_frameSvg = new Plasma::FrameSvg(this);
|
|
|
|
m_margins = new FrameSvgItemMargins(m_frameSvg, this);
|
2013-02-02 00:54:25 +01:00
|
|
|
setFlag(ItemHasContents, true);
|
2010-10-12 21:51:57 +02:00
|
|
|
connect(m_frameSvg, SIGNAL(repaintNeeded()), this, SLOT(doUpdate()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FrameSvgItem::~FrameSvgItem()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvgItem::setImagePath(const QString &path)
|
|
|
|
{
|
2012-11-07 12:43:11 +01:00
|
|
|
if (m_frameSvg->imagePath() == path) {
|
2012-08-12 00:13:21 +02:00
|
|
|
return;
|
2012-11-07 12:43:11 +01:00
|
|
|
}
|
2012-08-12 00:13:21 +02:00
|
|
|
|
2010-10-12 21:51:57 +02:00
|
|
|
m_frameSvg->setImagePath(path);
|
2011-03-27 12:37:23 +02:00
|
|
|
m_frameSvg->setElementPrefix(m_prefix);
|
2012-08-12 00:13:21 +02:00
|
|
|
|
2012-11-27 13:33:50 +01:00
|
|
|
if (implicitWidth() <= 0) {
|
|
|
|
setImplicitWidth(m_frameSvg->marginSize(Plasma::LeftMargin) + m_frameSvg->marginSize(Plasma::RightMargin));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (implicitHeight() <= 0) {
|
|
|
|
setImplicitHeight(m_frameSvg->marginSize(Plasma::TopMargin) + m_frameSvg->marginSize(Plasma::BottomMargin));
|
|
|
|
}
|
|
|
|
|
2012-08-12 00:13:21 +02:00
|
|
|
emit imagePathChanged();
|
2013-01-23 15:05:27 +01:00
|
|
|
m_margins->update();
|
2010-10-12 21:51:57 +02:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString FrameSvgItem::imagePath() const
|
|
|
|
{
|
|
|
|
return m_frameSvg->imagePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FrameSvgItem::setPrefix(const QString &prefix)
|
|
|
|
{
|
2012-11-07 12:43:11 +01:00
|
|
|
if (m_prefix == prefix) {
|
2012-08-12 00:13:21 +02:00
|
|
|
return;
|
2012-11-07 12:43:11 +01:00
|
|
|
}
|
2012-08-12 00:13:21 +02:00
|
|
|
|
2010-10-12 21:51:57 +02:00
|
|
|
m_frameSvg->setElementPrefix(prefix);
|
2011-03-27 12:37:23 +02:00
|
|
|
m_prefix = prefix;
|
2012-08-12 00:13:21 +02:00
|
|
|
|
2012-11-27 13:33:50 +01:00
|
|
|
if (implicitWidth() <= 0) {
|
|
|
|
setImplicitWidth(m_frameSvg->marginSize(Plasma::LeftMargin) + m_frameSvg->marginSize(Plasma::RightMargin));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (implicitHeight() <= 0) {
|
|
|
|
setImplicitHeight(m_frameSvg->marginSize(Plasma::TopMargin) + m_frameSvg->marginSize(Plasma::BottomMargin));
|
|
|
|
}
|
|
|
|
|
2012-08-12 00:13:21 +02:00
|
|
|
emit prefixChanged();
|
2012-11-07 12:43:11 +01:00
|
|
|
m_margins->update();
|
2010-10-12 21:51:57 +02:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString FrameSvgItem::prefix() const
|
|
|
|
{
|
2011-03-27 12:37:23 +02:00
|
|
|
return m_prefix;
|
2010-10-12 21:51:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FrameSvgItemMargins *FrameSvgItem::margins() const
|
|
|
|
{
|
|
|
|
return m_margins;
|
|
|
|
}
|
|
|
|
|
2010-11-05 21:50:28 +01:00
|
|
|
void FrameSvgItem::setEnabledBorders(const Plasma::FrameSvg::EnabledBorders borders)
|
|
|
|
{
|
2012-08-12 00:13:21 +02:00
|
|
|
if (m_frameSvg->enabledBorders() == borders)
|
|
|
|
return;
|
|
|
|
|
2010-11-05 21:50:28 +01:00
|
|
|
m_frameSvg->setEnabledBorders(borders);
|
2012-08-12 00:13:21 +02:00
|
|
|
emit enabledBordersChanged();
|
2010-11-05 21:50:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::FrameSvg::EnabledBorders FrameSvgItem::enabledBorders() const
|
|
|
|
{
|
|
|
|
return m_frameSvg->enabledBorders();
|
|
|
|
}
|
|
|
|
|
2013-02-02 00:54:25 +01:00
|
|
|
void FrameSvgItem::paint(QPainter *painter)
|
2010-10-12 21:51:57 +02:00
|
|
|
{
|
|
|
|
m_frameSvg->paintFrame(painter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvgItem::geometryChanged(const QRectF &newGeometry,
|
|
|
|
const QRectF &oldGeometry)
|
|
|
|
{
|
|
|
|
m_frameSvg->resizeFrame(newGeometry.size());
|
2013-02-01 17:26:26 +01:00
|
|
|
QQuickItem::geometryChanged(newGeometry, oldGeometry);
|
2010-10-12 21:51:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvgItem::doUpdate()
|
|
|
|
{
|
2012-11-27 13:33:50 +01:00
|
|
|
if (implicitWidth() <= 0) {
|
|
|
|
setImplicitWidth(m_frameSvg->marginSize(Plasma::LeftMargin) + m_frameSvg->marginSize(Plasma::RightMargin));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (implicitHeight() <= 0) {
|
|
|
|
setImplicitHeight(m_frameSvg->marginSize(Plasma::TopMargin) + m_frameSvg->marginSize(Plasma::BottomMargin));
|
|
|
|
}
|
|
|
|
|
2010-10-12 21:51:57 +02:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2012-11-27 13:33:50 +01:00
|
|
|
void FrameSvgItem::setImplicitWidth(qreal width)
|
|
|
|
{
|
|
|
|
if (implicitWidth() == width) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-01 17:26:26 +01:00
|
|
|
QQuickItem::setImplicitWidth(width);
|
2012-11-27 13:33:50 +01:00
|
|
|
|
|
|
|
emit implicitWidthChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal FrameSvgItem::implicitWidth() const
|
|
|
|
{
|
2013-02-01 17:26:26 +01:00
|
|
|
return QQuickItem::implicitWidth();
|
2012-11-27 13:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvgItem::setImplicitHeight(qreal height)
|
|
|
|
{
|
|
|
|
if (implicitHeight() == height) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-01 17:26:26 +01:00
|
|
|
QQuickItem::setImplicitHeight(height);
|
2012-11-27 13:33:50 +01:00
|
|
|
|
|
|
|
emit implicitHeightChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal FrameSvgItem::implicitHeight() const
|
|
|
|
{
|
2013-02-01 17:26:26 +01:00
|
|
|
return QQuickItem::implicitHeight();
|
2012-11-27 13:33:50 +01:00
|
|
|
}
|
|
|
|
|
2010-10-12 21:51:57 +02:00
|
|
|
} // Plasma namespace
|
|
|
|
|
2011-11-01 19:27:55 +01:00
|
|
|
#include "framesvgitem.moc"
|