kformula/flake

FencedElement.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
00003                       Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
00004                  2006 Martin Pfeiffer <hubipete@gmx.net>
00005    Copyright (C) 2006-2007 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include "FencedElement.h"
00024 #include "OperatorElement.h"
00025 #include "AttributeManager.h"
00026 #include <QPainter>
00027 
00028 FencedElement::FencedElement( BasicElement* parent ) : RowElement( parent )
00029 {}
00030 
00031 void FencedElement::paint( QPainter& painter, AttributeManager* am )
00032 {
00033     Q_UNUSED( am )
00034 
00035     QPen pen( painter.pen() );
00036     pen.setWidth( 1 );
00037     painter.setPen( pen );
00038     painter.drawPath( m_fence );
00039 }
00040 
00041 void FencedElement::layout( const AttributeManager* am )
00042 {
00043     m_fence = QPainterPath();  // empty path buffer
00044     OperatorElement op;
00045     m_fence.addPath( op.renderForFence( am->stringOf( "open", this ), Prefix ) );
00046 
00047     const QStringList separators = am->stringOf( "separators", this ).split( ' ' );
00048     int count = 0;
00049     foreach( const BasicElement* tmp, childElements() ) {
00050         m_fence.moveTo( m_fence.currentPosition() + QPointF( tmp->width() , 0.0 ) );
00051         if( tmp != childElements().last() )
00052             m_fence.addPath( op.renderForFence( separators[ count ], Infix ) );
00053         count++;
00054     }
00055 
00056     m_fence.addPath( op.renderForFence( am->stringOf( "close", this ), Postfix ) );
00057 
00058     setWidth( m_fence.boundingRect().width() );
00059     setHeight( m_fence.boundingRect().height() );
00060 }
00061 
00062 QString FencedElement::attributesDefaultValue( const QString& attribute ) const
00063 {
00064     if( attribute == "open" )
00065         return "(";
00066     else if( attribute == "close" )
00067         return ")";
00068     else if( attribute == "separators" )
00069         return ",";
00070     else
00071         return QString();
00072 }
00073     
00074 ElementType FencedElement::elementType() const
00075 {
00076     return Fenced;
00077 }
00078