F:/KPlato/koffice/libs/kofficecore/KoRect.h

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 David Faure <faure@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2, as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016  * Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #ifndef koRect_h
00020 #define koRect_h
00021 
00022 #include "KoPoint.h"
00023 #include "KoSize.h"
00024 #include <QRect>
00025 #include "koffice_export.h"
00026 
00031 class KOFFICECORE_EXPORT KoRect {
00032 
00033 public:
00034     KoRect()
00035         : m_tl(), m_br() {}
00036     KoRect(const KoPoint &topleft, const KoPoint &bottomright)
00037         : m_tl(topleft), m_br(bottomright) {}
00038     KoRect(const KoPoint &topleft, const KoSize &size)
00039         {m_tl = topleft; setSize(size);}
00040     KoRect(const double &left, const double &top, const double &width, const double &height)
00041         : m_tl(left,top), m_br(left+width,top+height) {}
00042     ~KoRect() {}
00043 
00044     bool isNull() const { return m_tl == m_br; }
00045     // Like QRect, a null KoRect is empty.
00046     bool isEmpty() const { return m_tl.x() > m_br.x() || m_tl.y() > m_br.y() || isNull(); }
00047     // Unlike QRect, a null KoRect is valid (0-sized).
00048     bool isValid() const { return m_tl.x() <= m_br.x() && m_tl.y() <= m_br.y(); }
00049     KoRect normalize() const;
00050 
00051     double left() const { return m_tl.x(); }
00052     double top() const { return m_tl.y(); }
00053     double right() const { return m_br.x(); }
00054     double bottom() const { return m_br.y(); }
00055 
00056     double& rLeft() { return m_tl.rx(); }
00057     double& rTop() { return m_tl.ry(); }
00058     double& rRight() { return m_br.rx(); }
00059     double& rBottom() { return m_br.ry(); }
00060 
00061     double x() const { return left(); }
00062     double y() const { return top(); }
00063 
00064     void setLeft(const double &left) { m_tl.setX(left); }
00065     void setTop(const double &top) { m_tl.setY(top); }
00066     void setRight(const double &right) { m_br.setX(right); }
00067     void setBottom(const double &bottom) { m_br.setY(bottom); }
00068 
00069     void setX(const double &x) { m_tl.setX(x); } //same as setLeft()
00070     void setY(const double &y) { m_tl.setY(y); } //same as setTop()
00071 
00072     KoPoint topLeft() const { return m_tl; }
00073     KoPoint bottomRight() const { return m_br; }
00074     KoPoint topRight() const { return KoPoint(m_br.x(), m_tl.y()); }
00075     KoPoint bottomLeft() const { return KoPoint(m_tl.x(), m_br.y()); }
00076     KoPoint center() const;
00077 
00078     void setTopLeft(const KoPoint &topleft);
00079     void setBottomRight(const KoPoint &bottomright);
00080     void setTopRight(const KoPoint &topright);
00081     void setBottomLeft(const KoPoint &bottomleft);
00082 
00083     void moveTopLeft(const KoPoint &topleft);
00084     void moveBottomRight(const KoPoint &bottomright);
00085     void moveTopRight(const KoPoint &topright);
00086     void moveBottomLeft(const KoPoint &bottomleft);
00087     //void moveCenter(const KoPoint &center);
00088     void moveBy(const double &dx, const double &dy);
00089 
00090     void setRect(const double &x, const double &y, const double &width, const double &height);
00091     void setRect(const KoRect &rect);
00092     void setCoords(const double &x1, const double &y1, const double &x2, const double &y2);
00093 
00094     KoSize size() const;
00095     double width() const { return m_br.x()-m_tl.x(); }
00096     double height() const { return m_br.y()-m_tl.y(); }
00097     void setWidth(const double &width) { m_br.setX(m_tl.x()+width); }
00098     void setHeight(const double &height) { m_br.setY(m_tl.y()+height); }
00099     void setSize(const KoSize &size);
00100 
00101     KoRect &operator|=(const KoRect &rhs);
00102     KoRect &operator&=(const KoRect &rhs);
00111     bool contains(const KoPoint &p) const;
00113     bool contains(const double &x, const double &y) const;
00115     bool contains(const KoRect &r) const;
00116     KoRect unite(const KoRect &r) const;
00117     KoRect intersect(const KoRect &r) const;
00118     bool intersects(const KoRect &r) const;
00119 
00120     KoRect transform(const QMatrix &m) const;
00121     KoRect translate(double dx, double dy) const;
00122 
00123     QRect toQRect() const;
00124     static KoRect fromQRect( const QRect &rect );
00125 
00126 private:
00127     KoPoint m_tl, m_br;
00128 };
00129 
00130 KOFFICECORE_EXPORT KoRect operator|(const KoRect &lhs, const KoRect &rhs);
00131 KOFFICECORE_EXPORT KoRect operator&(const KoRect &lhs, const KoRect &rhs);
00132 KOFFICECORE_EXPORT bool operator==(const KoRect &lhs, const KoRect &rhs);
00133 KOFFICECORE_EXPORT bool operator!=(const KoRect &lhs, const KoRect &rhs);
00134 
00135 
00137 #define DEBUGRECT(rc) (rc).x() << "," << (rc).y() << " " << (rc).width() << "x" << (rc).height()
00138 
00139 //inline kdbgstream operator<<( kdbgstream str, const KoRect & r )  { str << "[" << r.left() << ", " << r.top() << " - " << r.right() << ", " << r.bottom() << "]"; return str; }
00140 inline kdbgstream operator<<( kdbgstream str, const KoRect & r )  { str << "[" << r.left() << "," << r.top() << " " << r.width() << "x" << r.height() << "]"; return str; }
00141 inline kndbgstream operator<<( kndbgstream str, const KoRect & )  { return str; }
00142 
00144 #define DEBUGREGION(reg) { Q3MemArray<QRect>rs=reg.rects(); for (int i=0;i<rs.size();++i) \
00145                            kDebug()<<"  "<<DEBUGRECT(rs[i] )<<endl; }
00146 // You can now use kDebug() << theregion << endl; (kdebug.h)
00147 
00148 #endif

Généré le Wed Nov 22 23:41:04 2006 pour KPlato par  doxygen 1.5.1-p1