25#include "koffice_export.h"
31class KOFFICEUI_EXPORT KoRect {
37 : m_tl(topleft), m_br(bottomright) {}
39 {m_tl = topleft; setSize(size);}
40 KoRect( const double &left, const double &top, const double &width, const double &height)
41 : m_tl(left,top), m_br(left+width,top+height) {}
44 bool isNull() const { return m_tl == m_br; }
46 bool isEmpty() const { return m_tl.x() > m_br.x() || m_tl.y() > m_br.y() || isNull(); }
48 bool isValid() const { return m_tl.x() <= m_br.x() && m_tl.y() <= m_br.y(); }
49 KoRect normalize() const;
51 double left() const { return m_tl.x(); }
52 double top() const { return m_tl.y(); }
53 double right() const { return m_br.x(); }
54 double bottom() const { return m_br.y(); }
56 double& rLeft() { return m_tl.rx(); }
57 double& rTop() { return m_tl.ry(); }
58 double& rRight() { return m_br.rx(); }
59 double& rBottom() { return m_br.ry(); }
61 double x() const { return left(); }
62 double y() const { return top(); }
64 void setLeft( const double &left) { m_tl.setX(left); }
65 void setTop( const double &top) { m_tl.setY(top); }
66 void setRight( const double &right) { m_br.setX(right); }
67 void setBottom( const double &bottom) { m_br.setY(bottom); }
69 void setX( const double &x) { m_tl.setX(x); }
70 void setY( const double &y) { m_tl.setY(y); }
72 KoPoint topLeft() const { return m_tl; }
73 KoPoint bottomRight() const { return m_br; }
78 void setTopLeft( const KoPoint &topleft);
79 void setBottomRight( const KoPoint &bottomright);
80 void setTopRight( const KoPoint &topright);
81 void setBottomLeft( const KoPoint &bottomleft);
83 void moveTopLeft( const KoPoint &topleft);
84 void moveBottomRight( const KoPoint &bottomright);
85 void moveTopRight( const KoPoint &topright);
86 void moveBottomLeft( const KoPoint &bottomleft);
88 void moveBy( const double &dx, const double &dy);
90 void setRect( const double &x, const double &y, const double &width, const double &height);
91 void setRect( const KoRect &rect);
92 void setCoords( const double &x1, const double &y1, const double &x2, const double &y2);
95 double width() const { return m_br.x()-m_tl.x(); }
96 double height() const { return m_br.y()-m_tl.y(); }
97 void setWidth( const double &width) { m_br.setX(m_tl.x()+width); }
98 void setHeight( const double &height) { m_br.setY(m_tl.y()+height); }
99 void setSize( const KoSize &size);
101 KoRect &operator|=( const KoRect &rhs);
102 KoRect &operator&=( const KoRect &rhs);
113 bool contains( const double &x, const double &y) const;
115 bool contains( const KoRect &r) const;
116 KoRect unite( const KoRect &r) const;
117 KoRect intersect( const KoRect &r) const;
118 bool intersects( const KoRect &r) const;
120 KoRect transform( const TQWMatrix &m) const;
121 KoRect translate( double dx, double dy) const;
123 TQRect toTQRect() const;
124 static KoRect fromTQRect( const TQRect &rect );
132KOFFICEUI_EXPORT bool operator==( const KoRect &lhs, const KoRect &rhs);
133KOFFICEUI_EXPORT bool operator!=( const KoRect &lhs, const KoRect &rhs);
137#define DEBUGRECT(rc) (rc).x() << "," << (rc).y() << " " << (rc).width() << "x" << (rc).height()
140inline kdbgstream operator<<( kdbgstream str, const KoRect & r ) { str << "[" << r.left() << "," << r.top() << " " << r.width() << "x" << r.height() << "]"; return str; }
141inline kndbgstream operator<<( kndbgstream str, const KoRect & ) { return str; }
144#define DEBUGREGION(reg) { TQMemArray<TQRect>rs=reg.rects(); for (int i=0;i<rs.size();++i) \
145 kdDebug()<<" "<<DEBUGRECT(rs[i] )<<endl; }
A point whose coordinates are floating-point values ( "double"s ).
A rect whose coordinates are floating-point values ( "double"s ).
bool contains(const KoPoint &p) const Returns if the point is contained in the rect.
A size whose coordinates are floating-point values ( "double"s ).
|