KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
size.h
1/**
2 * @brief A 2D size extending QSizeF with grow/shrink helpers and Rectangle conversion.
3 */
4#ifndef SIZE_H
5#define SIZE_H
6#include <QSizeF>
7#include "Kanoop/kanoopcommon.h"
8
9class Rectangle;
10
11/**
12 * @brief Extends QSizeF with convenient grow/shrink operations and Rectangle conversion.
13 */
14class KANOOP_EXPORT Size : public QSizeF
15{
16public:
17 /** @brief Default constructor — creates a null (0x0) size. */
18 Size() : QSizeF() {}
19 /** @brief Construct from a QSizeF.
20 * @param other Source QSizeF */
21 Size(const QSizeF& other) : QSizeF(other) {}
22 /** @brief Construct from a QSize (integer dimensions).
23 * @param other Source QSize */
24 Size(const QSize& other) : QSizeF(other) {}
25 /**
26 * @brief Construct from explicit width and height.
27 * @param w Width
28 * @param h Height
29 */
30 Size(double w, double h) : QSizeF(w, h) {}
31
32 /**
33 * @brief Convert this size to a Rectangle positioned at the origin.
34 * @return Rectangle(0, 0, width, height)
35 */
37
38 /**
39 * @brief Grow both dimensions by the given amount.
40 * @param amount Amount to add to width and height
41 */
42 void grow(double amount);
43
44 /**
45 * @brief Shrink both dimensions by the given amount.
46 * @param amount Amount to subtract from width and height
47 */
48 void shrink(double amount);
49
50 /**
51 * @brief Format this size as "w, h".
52 * @return String representation
53 */
54 QString toString() const { return QString("%1, %2").arg(width()).arg(height()); }
55
56 /**
57 * @brief Parse a Size from a string produced by toString().
58 * @param value String of the form "w, h"
59 * @return Parsed Size
60 */
61 static Size fromString(const QString& value);
62};
63
64#endif // SIZE_H
A 2D rectangle extending QRectF with edge, corner, and geometric query helpers.
Definition rectangle.h:16
Extends QSizeF with convenient grow/shrink operations and Rectangle conversion.
Definition size.h:15
Size(double w, double h)
Construct from explicit width and height.
Definition size.h:30
Size()
Default constructor — creates a null (0x0) size.
Definition size.h:18
void shrink(double amount)
Shrink both dimensions by the given amount.
Rectangle toRectangle() const
Convert this size to a Rectangle positioned at the origin.
void grow(double amount)
Grow both dimensions by the given amount.
QString toString() const
Format this size as "w, h".
Definition size.h:54
Size(const QSize &other)
Construct from a QSize (integer dimensions).
Definition size.h:24
Size(const QSizeF &other)
Construct from a QSizeF.
Definition size.h:21
static Size fromString(const QString &value)
Parse a Size from a string produced by toString().