set default meaningful implicitWidth/height

svgItem has naturalSize as implicit size
framesvgitem has the sum of their borders
This commit is contained in:
Marco Martin 2012-11-27 13:33:50 +01:00
parent 01e84b4483
commit 3d21d43182
5 changed files with 146 additions and 0 deletions

View File

@ -83,6 +83,14 @@ void FrameSvgItem::setImagePath(const QString &path)
m_frameSvg->setImagePath(path);
m_frameSvg->setElementPrefix(m_prefix);
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));
}
emit imagePathChanged();
update();
}
@ -102,6 +110,14 @@ void FrameSvgItem::setPrefix(const QString &prefix)
m_frameSvg->setElementPrefix(prefix);
m_prefix = prefix;
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));
}
emit prefixChanged();
m_margins->update();
update();
@ -148,9 +164,49 @@ void FrameSvgItem::geometryChanged(const QRectF &newGeometry,
void FrameSvgItem::doUpdate()
{
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));
}
update();
}
void FrameSvgItem::setImplicitWidth(qreal width)
{
if (implicitWidth() == width) {
return;
}
QDeclarativeItem::setImplicitWidth(width);
emit implicitWidthChanged();
}
qreal FrameSvgItem::implicitWidth() const
{
return QDeclarativeItem::implicitWidth();
}
void FrameSvgItem::setImplicitHeight(qreal height)
{
if (implicitHeight() == height) {
return;
}
QDeclarativeItem::setImplicitHeight(height);
emit implicitHeightChanged();
}
qreal FrameSvgItem::implicitHeight() const
{
return QDeclarativeItem::implicitHeight();
}
} // Plasma namespace
#include "framesvgitem.moc"

View File

@ -102,6 +102,16 @@ class FrameSvgItem : public QDeclarativeItem
*/
Q_PROPERTY(Plasma::FrameSvg::EnabledBorders enabledBorders READ enabledBorders WRITE setEnabledBorders NOTIFY enabledBordersChanged)
/**
* suggested default size hint for width
*/
Q_PROPERTY(qreal implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged)
/**
* suggested default size hint for height
*/
Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged)
public:
FrameSvgItem(QDeclarativeItem *parent=0);
~FrameSvgItem();
@ -122,10 +132,18 @@ public:
void geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry);
void setImplicitWidth(qreal width);
qreal implicitWidth() const;
void setImplicitHeight(qreal height);
qreal implicitHeight() const;
signals:
void imagePathChanged();
void prefixChanged();
void enabledBordersChanged();
void implicitWidthChanged();
void implicitHeightChanged();
private Q_SLOTS:
void doUpdate();

View File

@ -54,6 +54,7 @@ public:
void setImplicitWidth(qreal width);
qreal implicitWidth() const;
void setImplicitHeight(qreal height);
qreal implicitHeight() const;

View File

@ -45,6 +45,13 @@ void SvgItem::setElementId(const QString &elementID)
return;
}
if (implicitWidth() <= 0) {
setImplicitWidth(naturalSize().width());
}
if (implicitHeight() <= 0) {
setImplicitHeight(naturalSize().height());
}
m_elementID = elementID;
emit elementIdChanged();
emit naturalSizeChanged();
@ -79,6 +86,14 @@ void SvgItem::setSvg(Plasma::Svg *svg)
connect(svg, SIGNAL(repaintNeeded()), this, SIGNAL(naturalSizeChanged()));
connect(svg, SIGNAL(sizeChanged()), this, SIGNAL(naturalSizeChanged()));
}
if (implicitWidth() <= 0) {
setImplicitWidth(naturalSize().width());
}
if (implicitHeight() <= 0) {
setImplicitHeight(naturalSize().height());
}
emit svgChanged();
emit naturalSizeChanged();
}
@ -126,9 +141,47 @@ void SvgItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q
void SvgItem::updateNeeded()
{
if (implicitWidth() <= 0) {
setImplicitWidth(naturalSize().width());
}
if (implicitHeight() <= 0) {
setImplicitHeight(naturalSize().height());
}
update();
}
void SvgItem::setImplicitWidth(qreal width)
{
if (implicitWidth() == width) {
return;
}
QDeclarativeItem::setImplicitWidth(width);
emit implicitWidthChanged();
}
qreal SvgItem::implicitWidth() const
{
return QDeclarativeItem::implicitWidth();
}
void SvgItem::setImplicitHeight(qreal height)
{
if (implicitHeight() == height) {
return;
}
QDeclarativeItem::setImplicitHeight(height);
emit implicitHeightChanged();
}
qreal SvgItem::implicitHeight() const
{
return QDeclarativeItem::implicitHeight();
}
} // Plasma namespace
#include "svgitem.moc"

View File

@ -56,6 +56,16 @@ class SvgItem : public QDeclarativeItem
*/
Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
/**
* suggested default size hint for width (default to naturalSize.width)
*/
Q_PROPERTY(qreal implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged)
/**
* suggested default size hint for height (default to naturalSize.height)
*/
Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged)
public:
SvgItem(QDeclarativeItem *parent=0);
~SvgItem();
@ -73,11 +83,19 @@ public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void setImplicitWidth(qreal width);
qreal implicitWidth() const;
void setImplicitHeight(qreal height);
qreal implicitHeight() const;
Q_SIGNALS:
void elementIdChanged();
void svgChanged();
void naturalSizeChanged();
void smoothChanged();
void implicitWidthChanged();
void implicitHeightChanged();
protected Q_SLOTS:
void updateNeeded();