F:/KPlato/koffice/libs/kotext/KoBorderPreview.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KOffice project
00002    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00003    Copyright (C) 2006 Thomas Zander <zander@kde.org>
00004    Copyright (C) 2006 David Faure <faure@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "KoBorderPreview.h"
00023 #include <QPainter>
00024 
00025 KoBorderPreview::KoBorderPreview( QWidget* parent )
00026     :QFrame(parent)
00027 {
00028 }
00029 
00030 void KoBorderPreview::mousePressEvent( QMouseEvent *_ev )
00031 {
00032     emit choosearea(_ev);
00033 }
00034 
00035 void KoBorderPreview::setBorder( KoBorder::BorderType which, const KoBorder& border)
00036 {
00037     switch( which ) {
00038     case KoBorder::TopBorder:
00039         setTopBorder( border );
00040         break;
00041     case KoBorder::BottomBorder:
00042         setBottomBorder( border );
00043         break;
00044     case KoBorder::LeftBorder:
00045         setLeftBorder( border );
00046         break;
00047     case KoBorder::RightBorder:
00048         setRightBorder( border );
00049         break;
00050     default:
00051         kError() << "KoBorderPreview: unknown border type" << endl;
00052     }
00053 }
00054 
00055 void KoBorderPreview::drawContents( QPainter* painter )
00056 {
00057     QRect r = contentsRect();
00058     QFontMetrics fm( font() );
00059 
00060     painter->fillRect( r.x() + fm.width( 'W' ), r.y() + fm.height(), r.width() - 2 * fm.width( 'W' ),
00061                        r.height() - 2 * fm.height(), Qt::white );
00062     painter->setClipRect( r.x() + fm.width( 'W' ), r.y() + fm.height(), r.width() - 2 * fm.width( 'W' ),
00063                           r.height() - 2 * fm.height() );
00064 
00065     bool leftdouble = m_leftBorder.width() > 0 && m_leftBorder.getStyle() == KoBorder::DOUBLE_LINE;
00066     bool rightdouble = m_rightBorder.width() > 0 && m_rightBorder.getStyle() == KoBorder::DOUBLE_LINE;
00067     bool topdouble = m_topBorder.width() > 0 && m_topBorder.getStyle() == KoBorder::DOUBLE_LINE;
00068     bool bottomdouble = m_bottomBorder.width() > 0 && m_bottomBorder.getStyle() == KoBorder::DOUBLE_LINE;
00069 
00070     if ( m_topBorder.width() > 0 ) {
00071         painter->setPen( setBorderPen( m_topBorder ) );
00072         painter->drawLine( r.x() + 20, r.y() + 30, r.right() - 19, r.y() + 30 );
00073         if ( m_topBorder.getStyle()==KoBorder::DOUBLE_LINE)
00074             painter->drawLine( int(r.x() + 20 + ( leftdouble ? m_leftBorder.width() + 1 : 0) ),
00075                                int(r.y() + 30 + m_topBorder.width()+1),
00076                                int(r.right() - 19 - ( rightdouble ? m_rightBorder.width() + 1 : 0) ),
00077                                int(r.y() + 30 + m_topBorder.width()+1)
00078                              );
00079     }
00080 
00081     if ( m_bottomBorder.width() > 0 ) {
00082         painter->setPen( setBorderPen( m_bottomBorder ) );
00083         painter->drawLine( r.x() + 20, r.bottom() - 30, r.right() - 19, r.bottom() - 30 );
00084         if ( m_bottomBorder.getStyle()==KoBorder::DOUBLE_LINE)
00085             painter->drawLine( int(r.x() + 20 + ( leftdouble ? m_leftBorder.width() + 1 : 0) ),
00086                                int(r.bottom() - 30 - m_bottomBorder.width()-1),
00087                                int(r.right() - 19 - ( rightdouble ? m_rightBorder.width() + 1 : 0) ),
00088                                int(r.bottom() - 30 - m_bottomBorder.width() - 1)
00089                              );
00090     }
00091 
00092     if ( m_leftBorder.width() > 0 ) {
00093         painter->setPen( setBorderPen( m_leftBorder ) );
00094         painter->drawLine( r.x() + 20, r.y() + 30, r.x() + 20, r.bottom() - 29 );
00095         if ( m_leftBorder.getStyle()==KoBorder::DOUBLE_LINE)
00096             painter->drawLine( int(r.x() + 20 + m_leftBorder.width() +1),
00097                                int(r.y() + 30 + ( topdouble ? m_topBorder.width() + 1 : 0) ),
00098                                int(r.x() + 20 + m_leftBorder.width() +1),
00099                                int(r.bottom() - 29 - ( bottomdouble ? m_bottomBorder.width() + 1 : 0) )
00100                              );
00101     }
00102 
00103     if ( m_rightBorder.width() > 0 ) {
00104         painter->setPen( setBorderPen( m_rightBorder ) );
00105         painter->drawLine( r.right() - 20, r.y() + 30, r.right() - 20, r.bottom() - 29 );
00106         if ( m_rightBorder.getStyle()==KoBorder::DOUBLE_LINE)
00107             painter->drawLine( int(r.right() - 20 - m_rightBorder.width() - 1 ),
00108                                int(r.y() + 30 + ( topdouble ? m_topBorder.width() + 1 : 0) ),
00109                                int(r.right() - 20 - m_rightBorder.width() - 1),
00110                                int(r.bottom() - 29 - ( bottomdouble ? m_bottomBorder.width() + 1 : 0) )
00111                              );
00112     }
00113 }
00114 
00115 QPen KoBorderPreview::setBorderPen( KoBorder _brd )
00116 {
00117     QPen pen( Qt::black, 1, Qt::SolidLine );
00118 
00119     pen.setWidth( static_cast<int>( _brd.penWidth() ) );
00120     pen.setColor( _brd.color );
00121 
00122     switch ( _brd.getStyle() ) {
00123     case KoBorder::SOLID:
00124         pen.setStyle( Qt::SolidLine );
00125         break;
00126     case KoBorder::DASH:
00127         pen.setStyle( Qt::DashLine );
00128         break;
00129     case KoBorder::DOT:
00130         pen.setStyle( Qt::DotLine );
00131         break;
00132     case KoBorder::DASH_DOT:
00133         pen.setStyle( Qt::DashDotLine );
00134         break;
00135     case KoBorder::DASH_DOT_DOT:
00136         pen.setStyle( Qt::DashDotDotLine );
00137         break;
00138     case KoBorder::DOUBLE_LINE:
00139         pen.setStyle( Qt::SolidLine );
00140         break;
00141     }
00142 
00143     return QPen( pen );
00144 }
00145 
00146 #include "KoBorderPreview.moc"

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