lib

KoBorder.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2000, 2001 Thomas Zander <zander@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 as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef KoBorder_h
00021 #define KoBorder_h
00022 
00023 #include <qcolor.h>
00024 #include <qpen.h>
00025 #include <koffice_export.h>
00026 class QDomElement;
00027 class KoZoomHandler;
00028 class QPainter;
00029 
00033 class KOTEXT_EXPORT KoBorder : public Qt
00034 {
00035     friend class KoTextCursor;
00036 public:
00037     // Update the DTDs if you add something here!
00038     enum BorderStyle {SOLID = 0, DASH = 1, DOT = 2, DASH_DOT = 3, DASH_DOT_DOT = 4, DOUBLE_LINE = 5};
00039     enum BorderType { LeftBorder = 0, RightBorder, TopBorder, BottomBorder };
00040 
00041     KoBorder();
00042     KoBorder( const QColor & c, BorderStyle s, double width );
00043     QColor color;
00044     void setPenWidth(double _w);
00045     void setStyle(BorderStyle _style);
00046     // deprecated
00047     BorderStyle getStyle() const {return m_style;}
00048     BorderStyle style() const {return m_style;}
00049     double penWidth() const{ return ptPenWidth;}
00050     double width() const { return ptWidth; }
00051 
00052     bool operator==( const KoBorder _brd ) const;
00053     bool operator!=( const KoBorder _brd ) const;
00054 
00055     // Load from XML
00056     static KoBorder loadBorder( const QDomElement & elem );
00057     void loadFoBorder( const QString& border );
00058     // Save to XML
00059     void save( QDomElement & elem ) const;
00060     QString saveFoBorder() const;
00061 
00062     // String to style enum, and vice versa, for UI.
00063     static BorderStyle getStyle( const QString &style );
00064     static QString getStyle( const BorderStyle &style );
00065 
00066     // Zoom the border width. If ptWidth is 0, minborder is returned.
00067     static int zoomWidthX( double ptWidth, KoZoomHandler * zoomHandler, int minborder ); // For left/right borders
00068     static int zoomWidthY( double ptWidth, KoZoomHandler * zoomHandler, int minborder ); // For top/bottom borders
00069 
00070     // Get a ready-to-use QPen for this border.
00071     // defaultColor is the color to use for QColor() - either defaultTextColor() or defaultBgColor().
00072     static QPen borderPen( const KoBorder & brd, int width, QColor defaultColor );
00073 
00074     // The do-it-all method :)
00075     // Draws in @p painter the 4 borders on the _outside_ of @p rect.
00076     // If a border is of size 0, minborder will be applied (no border if 0, defaultPen otherwise)
00077     static void drawBorders( QPainter& painter, KoZoomHandler * zoomHandler, const QRect& rect,
00078                              const KoBorder& left, const KoBorder& right,
00079                              const KoBorder& top, const KoBorder& bottom,
00080                              int minborder, const QPen& defaultPen, bool drawTopBorder = true , bool drawBottomBorder = true );
00081 private:
00082     double ptWidth;
00083     double ptPenWidth;
00084     BorderStyle m_style;
00085 };
00086 
00087 /******************************
00088   kdDebug support
00089 *******************************/
00090 #include <kdebug.h>
00091 
00092 inline kdbgstream operator<<( kdbgstream str, const KoBorder & b )  {
00093     str << "[ color:" << b.color << " width:" << b.width() << " penWidth:" << b.penWidth() << " style:" << KoBorder::getStyle( b.getStyle() ) << "]"; return str;
00094 }
00095 inline kndbgstream operator<<( kndbgstream str, const KoBorder & )  { return str; }
00096 
00097 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys