Add margins.horizontal/vertical helpers that return added up margins along one axis.

Adding up margins along the horizontal or vertical axis is often
done to calculate sizing or spacing. This tends to result in scary-
long and bug-prone expression being bound to props, since nobody
seems to like to blowing them up into a code block with a separate
variable assignment. This aims to increase the readability of com-
plex expressions by summing axis margins into a single operand.

Change-Id: I39a37dde80b9314da0c69f3b33d26d26a9ff54d1
This commit is contained in:
Eike Hein 2014-10-13 15:14:56 +02:00
parent f5fb0dbc24
commit d3a9b5bb1f
2 changed files with 28 additions and 5 deletions

View File

@ -224,6 +224,16 @@ qreal FrameSvgItemMargins::bottom() const
}
}
qreal FrameSvgItemMargins::horizontal() const
{
return left() + right();
}
qreal FrameSvgItemMargins::vertical() const
{
return top() + bottom();
}
void FrameSvgItemMargins::update()
{
emit marginsChanged();

View File

@ -36,32 +36,43 @@ class SVGTextureNode;
/**
* @class FrameSvgItemMargins
*
* @short The size of margins for a frame.
* @short The sizes of a frame's margins.
*/
class FrameSvgItemMargins : public QObject
{
Q_OBJECT
/**
* width in pixels of the left margin
* Width in pixels of the left margin.
*/
Q_PROPERTY(qreal left READ left NOTIFY marginsChanged)
/**
* height in pixels of the top margin
* Height in pixels of the top margin.
*/
Q_PROPERTY(qreal top READ top NOTIFY marginsChanged)
/**
* width in pixels of the right margin
* Width in pixels of the right margin.
*/
Q_PROPERTY(qreal right READ right NOTIFY marginsChanged)
/**
* height in pixels of the bottom margin
* Height in pixels of the bottom margin.
*/
Q_PROPERTY(qreal bottom READ bottom NOTIFY marginsChanged)
/**
* Width in pixels of the left and right margins combined.
*/
Q_PROPERTY(qreal horizontal READ horizontal NOTIFY marginsChanged)
/**
* Height in pixels of the top and bottom margins combined.
*/
Q_PROPERTY(qreal vertical READ vertical NOTIFY marginsChanged)
public:
FrameSvgItemMargins(Plasma::FrameSvg *frameSvg, QObject *parent = 0);
@ -69,6 +80,8 @@ public:
qreal top() const;
qreal right() const;
qreal bottom() const;
qreal horizontal() const;
qreal vertical() const;
void setFixed(bool fixed);
bool isFixed() const;