kformula/flake
FencedElement.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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();
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
|