Logo    
KDWinUtils
Helper library for MFC to Qt migration
Loading...
Searching...
No Matches
krect.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** This file is part of KDWinutils, KDAB's MFC to Qt migration tool.
4**
5** Copyright (C) 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6** All rights reserved.
7**
8** This file is intended solely for use by the migration tools and services
9** provided by Klarälvdalens Datakonsult AB.
10**
11** Any other use or distribution of this software that is not otherwise agreed
12** upon in writing and signed by an authorized representative of Klarälvdalens
13** Datakonsult AB, KDAB (USA) LLC, KDAB (Deutschland) GmbH & Co. K.G.,
14** KDAB (France) SAS, KDAB (UK), Ltd., or any future subsidiary of Klarälvdalens
15** Datakonsult AB is hereby prohibited.
16**
17** Contact info@kdab.com if any conditions stated above are unclear to you.
18**
19****************************************************************************/
20
21#pragma once
22
24
25#include <QRect>
26
27#include "kpoint.h"
28#include "ksize.h"
29
31
40{
41public:
42 int &left = m_topLeft.x;
43 int &top = m_topLeft.y;
44 int &right = m_bottomRight.x;
45 int &bottom = m_bottomRight.y;
46
48 explicit KRect(int l, int t, int r, int b);
49 explicit KRect(const KPoint &cp, const KSize &cs);
50 explicit KRect(const KPoint &topLeft, const KPoint &bottomRight);
51
52 // Rule of 5.
53 // These are needed because of the presence of reference members.
54 ~KRect() = default;
55 KRect(const KRect &rect);
56 KRect(KRect &&rect) noexcept;
57 KRect &operator=(const KRect &rect);
58 KRect &operator=(KRect &&rect) noexcept;
59 void swap(KRect &rect) noexcept;
60
61 // QRect specific methods
62 /* implicit */ KRect(const QRect &qr);
63 KRect &operator=(const QRect &rect);
64 QRect toQRect() const;
65 /* implicit */ operator QRect() const;
66
67#ifdef KDWINUTILS_WITHMFC
68 // CRect specific methods, available only on Windows with MFC set
69 explicit KRect(const CRect &cr);
70 KRect &operator=(const CRect &rect);
71 CRect toCRect() const;
72 /* implicit */ operator CRect() const;
73#endif // KDWINUTILS_WITHMFC
74
75 // MFC API from here on
77
78 void operator+=(const KPoint &point);
80 void operator+=(const KSize &size);
82 void operator+=(const KRect &rect);
83
85 void operator-=(const KPoint &point);
87 void operator-=(const KSize &size);
89 void operator-=(const KRect &rect);
90
92 void operator&=(const KRect &rect);
93
95 void operator|=(const KRect &rect);
96
99 const KPoint &BottomRight() const;
100
103
105 void CopyRect(const KRect *rect);
107 void CopyRect(const KRect &rect);
108
110 void DeflateRect(int x, int y);
112 void DeflateRect(const KSize &size);
114 void DeflateRect(const KRect &rect);
116 void DeflateRect(int l, int t, int r, int b);
117
119 bool EqualRect(const KRect *cr) const;
121 bool EqualRect(const KRect &cr) const;
122
124 int Height() const;
125
127 void InflateRect(int x, int y);
129 void InflateRect(const KSize &size);
131 void InflateRect(const KRect &rect);
133 void InflateRect(int l, int t, int r, int b);
134
136 bool IntersectRect(const KRect *rect1, const KRect *rect2);
138 bool IntersectRect(const KRect &rect1, const KRect &rect2);
139
141 bool IsRectEmpty() const;
142
144 bool IsRectNull() const;
145
147 void MoveToX(int x);
149 void MoveToY(int y);
150
152 void MoveToXY(int x, int y) noexcept;
154 void MoveToXY(const KPoint &point) noexcept;
155
158
160 void OffsetRect(int x, int y);
162 void OffsetRect(const KPoint &point);
164 void OffsetRect(const KSize &size);
165
167 bool PtInRect(const KPoint &point) const;
168
170 void SetRect(int left, int top, int right, int bottom);
171
174
176 KSize Size() const;
177
179 bool SubtractRect(const KRect *rectSrc1, const KRect *rectSrc2);
181 bool SubtractRect(const KRect &rectSrc1, const KRect &rectSrc2);
182
186 const KPoint &TopLeft() const;
187
189 void UnionRect(const KRect *rectSrc1, const KRect *rectSrc2);
191 void UnionRect(const KRect &rectSrc1, const KRect &rectSrc2);
192
194 int Width() const;
195
196private:
197 KPoint m_topLeft;
198 KPoint m_bottomRight;
199};
200
203KDWINUTILS_EXPORT bool operator==(const KRect &lhs, const KRect &rhs) noexcept;
206KDWINUTILS_EXPORT bool operator!=(const KRect &lhs, const KRect &rhs) noexcept;
207
223
239
246
The KPoint class defines a point in the plane using integer precision.
Definition kpoint.h:43
KRect operator+(const KPoint &lhs, const KRect &rhs)
Returns a KRect that is offset by a KPoint.
KRect operator-(const KPoint &lhs, const KRect &rhs)
Returns a KRect that is offset by the negation of a KPoint.
The KRect class defines a rectangle in the plane using integer precision.
Definition krect.h:40
~KRect()=default
void MoveToXY(const KPoint &point) noexcept
Moves KRect to the specified x- and y-coordinates.
KRect operator+(const KRect &lhs, const KSize &rhs)
Returns a KRect offset by a KSize.
void operator&=(const KRect &rect)
Sets Krect equal to the intersection of Krect and a rectangle.
void UnionRect(const KRect *rectSrc1, const KRect *rectSrc2)
Sets KRect equal to the union of two rectangles.
void operator-=(const KRect &rect)
Deflates Krect.
void InflateRect(int x, int y)
Increases the width and height of KRect.
KRect(int l, int t, int r, int b)
KRect(const CRect &cr)
void NormalizeRect()
Standardizes the height and width of KRect.
void OffsetRect(const KSize &size)
Moves KRect by the specified offsets.
void operator-=(const KPoint &point)
Subtracts the specified offsets from Krect.
void operator+=(const KPoint &point)
Adds the specified offsets to Krect.
int Width() const
Calculates the width of KRect.
void MoveToX(int x)
Moves KRect to the specified x-coordinate.
KRect operator|(const KRect &lhs, const KRect &rhs)
Creates the union of KRect and a rectangle and returns the resulting KRect.
void swap(KRect &rect) noexcept
KRect & operator=(const CRect &rect)
KRect operator-(const KRect &lhs, const KRect &rhs)
Deflates KRect and returns the resulting KRect.
KPoint CenterPoint() const
Returns the centerpoint of KRect.
KRect operator+(const KRect &lhs, const KPoint &rhs)
Returns a KRect offset by a KPoint.
KRect operator-(const KRect &lhs, const KSize &rhs)
Subtracts the given offsets from KRect.
bool operator!=(const KRect &lhs, const KRect &rhs) noexcept
Checks for inequality between 2 rects.
void DeflateRect(const KSize &size)
Decreases the width and height of KRect.
bool operator==(const KRect &lhs, const KRect &rhs) noexcept
Checks for equality between 2 rects.
void DeflateRect(int l, int t, int r, int b)
Decreases the width and height of KRect.
void operator|=(const KRect &rect)
Sets Krect equal to the union of Krect and a rectangle.
void InflateRect(const KSize &size)
Increases the width and height of KRect.
KPoint & BottomRight()
Returns the bottom-right point of KRect.
void DeflateRect(const KRect &rect)
Decreases the width and height of KRect.
void operator-=(const KSize &size)
Subtracts the specified offsets from Krect.
KRect & operator=(const KRect &rect)
void InflateRect(int l, int t, int r, int b)
Increases the width and height of KRect.
bool IntersectRect(const KRect *rect1, const KRect *rect2)
Sets KRect equal to the intersection of two rectangles.
void InflateRect(const KRect &rect)
Increases the width and height of KRect.
const KPoint & BottomRight() const
bool SubtractRect(const KRect &rectSrc1, const KRect &rectSrc2)
Subtracts one rectangle from another.
KRect operator&(const KRect &lhs, const KRect &rhs)
Creates the intersection of KRect and a rectangle and returns the resulting KRect .
KRect & operator=(const QRect &rect)
bool PtInRect(const KPoint &point) const
Determines whether the specified point lies within KRect.
const KPoint & TopLeft() const
Returns the top-left point of KRect.
void MoveToY(int y)
Moves KRect to the specified y-coordinate.
void SetRect(int left, int top, int right, int bottom)
Sets the dimensions of KRect.
QRect toQRect() const
void CopyRect(const KRect &rect)
Copies the dimensions of a source rectangle to KRect.
void SetRectEmpty()
Sets KRect to an empty rectangle (all coordinates equal to 0).
KRect operator-(const KRect &lhs, const KPoint &rhs)
Subtracts the given offsets from Krect.
KRect(KRect &&rect) noexcept
KSize Size() const
Calculates the size of KRect.
KRect operator+(const KRect &lhs, const KRect &rhs)
Inflates KRect and returns the resulting KRect.
bool IsRectNull() const
Determines whether the top, bottom, left, and right member variables are all equal to 0.
void operator+=(const KRect &rect)
Inflates Krect.
void operator+=(const KSize &size)
Adds the specified offsets to Krect.
KRect(const KRect &rect)
bool EqualRect(const KRect *cr) const
Determines whether KRect is equal to the given rectangle.
CRect toCRect() const
KRect(const KPoint &cp, const KSize &cs)
bool SubtractRect(const KRect *rectSrc1, const KRect *rectSrc2)
Subtracts one rectangle from another.
void CopyRect(const KRect *rect)
Copies the dimensions of a source rectangle to KRect.
int Height() const
Calculates the height of KRect.
void UnionRect(const KRect &rectSrc1, const KRect &rectSrc2)
Sets KRect equal to the union of two rectangles.
KRect(const KPoint &topLeft, const KPoint &bottomRight)
bool IsRectEmpty() const
Determines whether KRect is empty. KRect is empty if the width and/or height are 0.
void MoveToXY(int x, int y) noexcept
Moves KRect to the specified x- and y-coordinates.
KRect(const QRect &qr)
void OffsetRect(int x, int y)
Moves KRect by the specified offsets.
KRect & operator=(KRect &&rect) noexcept
void OffsetRect(const KPoint &point)
Moves KRect by the specified offsets.
bool EqualRect(const KRect &cr) const
Determines whether KRect is equal to the given rectangle.
void DeflateRect(int x, int y)
Decreases the width and height of KRect.
KPoint & TopLeft()
Returns the top-left point of KRect.
bool IntersectRect(const KRect &rect1, const KRect &rect2)
Sets KRect equal to the intersection of two rectangles.
The KSize class defines the size of a two-dimensional object using integer point precision.
Definition ksize.h:43
KRect operator-(const KSize &lhs, const KRect &rhs)
Returns a KRect that is offset by the negation of a KSize.
KRect operator+(const KSize &lhs, const KRect &rhs)
Returns a KRect that is offset by a KSize.
#define KDWINUTILS_EXPORT
Definition kdwinutils_export.h:31
#define KDWINUTILS_BEGIN_NAMESPACE
Definition kdwinutils_global.h:27
#define KDWINUTILS_END_NAMESPACE
Definition kdwinutils_global.h:28