koRect.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
#ifndef koRect_h
00020
#define koRect_h
00021
00022
#include "koPoint.h"
00023
#include "koSize.h"
00024
#include <qrect.h>
00025
00030 class KoRect {
00031
00032
public:
00033
KoRect()
00034 : m_tl(), m_br() {}
00035
KoRect(
const KoPoint &topleft,
const KoPoint &bottomright)
00036 : m_tl(topleft), m_br(bottomright) {}
00037
KoRect(
const KoPoint &topleft,
const KoSize &size)
00038 {m_tl = topleft; setSize(size);}
00039
KoRect(
const double &left,
const double &top,
const double &width,
const double &height)
00040 : m_tl(left,top), m_br(left+width,top+height) {}
00041 ~
KoRect() {}
00042
00043
bool isNull()
const {
return m_tl == m_br; }
00044
00045
bool isEmpty()
const {
return m_tl.
x() > m_br.
x() || m_tl.
y() > m_br.
y() || isNull(); }
00046
00047
bool isValid()
const {
return m_tl.
x() <= m_br.
x() && m_tl.
y() <= m_br.
y(); }
00048
KoRect normalize()
const;
00049
00050
double left()
const {
return m_tl.
x(); }
00051
double top()
const {
return m_tl.
y(); }
00052
double right()
const {
return m_br.
x(); }
00053
double bottom()
const {
return m_br.
y(); }
00054
00055
double& rLeft() {
return m_tl.
rx(); }
00056
double& rTop() {
return m_tl.
ry(); }
00057
double& rRight() {
return m_br.
rx(); }
00058
double& rBottom() {
return m_br.
ry(); }
00059
00060
double x()
const {
return left(); }
00061
double y()
const {
return top(); }
00062
00063
void setLeft(
const double &left) { m_tl.
setX(left); }
00064
void setTop(
const double &top) { m_tl.
setY(top); }
00065
void setRight(
const double &right) { m_br.
setX(right); }
00066
void setBottom(
const double &bottom) { m_br.
setY(bottom); }
00067
00068
void setX(
const double &x) { m_tl.
setX(x); }
00069
void setY(
const double &y) { m_tl.
setY(y); }
00070
00071
KoPoint topLeft()
const {
return m_tl; }
00072
KoPoint bottomRight()
const {
return m_br; }
00073
KoPoint topRight()
const {
return KoPoint(m_br.
x(), m_tl.
y()); }
00074
KoPoint bottomLeft()
const {
return KoPoint(m_tl.
x(), m_br.
y()); }
00075
KoPoint center()
const;
00076
00077
void moveTopLeft(
const KoPoint &topleft);
00078
void moveBottomRight(
const KoPoint &bottomright);
00079
void moveTopRight(
const KoPoint &topright);
00080
void moveBottomLeft(
const KoPoint &bottomleft);
00081
00082
void moveBy(
const double &dx,
const double &dy);
00083
00084
void setRect(
const double &x,
const double &y,
const double &width,
const double &height);
00085
void setRect(
const KoRect &rect);
00086
void setCoords(
const double &x1,
const double &y1,
const double &x2,
const double &y2);
00087
00088
KoSize size()
const;
00089
double width()
const {
return m_br.
x()-m_tl.
x(); }
00090
double height()
const {
return m_br.
y()-m_tl.
y(); }
00091
void setWidth(
const double &width) { m_br.
setX(m_tl.
x()+width); }
00092
void setHeight(
const double &height) { m_br.
setY(m_tl.
y()+height); }
00093
void setSize(
const KoSize &size);
00094
00095
KoRect &operator|=(
const KoRect &rhs);
00096
KoRect &operator&=(
const KoRect &rhs);
00097
bool contains(
const KoPoint &p,
bool proper=
false)
const;
00098
bool contains(
const double &x,
const double &y,
bool proper=
false)
const;
00099
bool contains(
const KoRect &r,
bool proper=
false)
const;
00100
KoRect unite(
const KoRect &r)
const;
00101
KoRect intersect(
const KoRect &r)
const;
00102
bool intersects(
const KoRect &r)
const;
00103
00104
KoRect transform(
const QWMatrix &m)
const;
00105
KoRect translate(
double dx,
double dy)
const;
00106
00107
QRect toQRect()
const;
00108
static KoRect fromQRect(
const QRect &rect );
00109
00110
private:
00111
KoPoint m_tl, m_br;
00112 };
00113
00114
KoRect operator|(
const KoRect &lhs,
const KoRect &rhs);
00115
KoRect operator&(
const KoRect &lhs,
const KoRect &rhs);
00116
bool operator==(
const KoRect &lhs,
const KoRect &rhs);
00117
bool operator!=(
const KoRect &lhs,
const KoRect &rhs);
00118
00119
00121
#define DEBUGRECT(rc) (rc).x() << "," << (rc).y() << " " << (rc).width() << "x" << (rc).height()
00122
00123
00124
inline kdbgstream operator<<( kdbgstream str,
const KoRect & r ) { str <<
"[" << r.
left() <<
"," << r.
top() <<
" " << r.
width() <<
"x" << r.
height() <<
"]";
return str; }
00125
inline kndbgstream operator<<( kndbgstream str,
const KoRect & ) {
return str; }
00126
00128
#define DEBUGREGION(reg) { QMemArray<QRect>rs=reg.rects(); for (int i=0;i<rs.size();++i) \
00129
kdDebug()<<" "<<DEBUGRECT(rs[i] )<<endl; }
00130
00131
00132
#endif
This file is part of the documentation for lib Library Version 1.3.5.