kformula/flake

EncloseElement.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2006-2007 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com>
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 #include "EncloseElement.h"
00021 #include "AttributeManager.h"
00022 #include <QPainter>
00023 #include "kdebug.h"
00024 
00025 EncloseElement::EncloseElement( BasicElement* parent ) : RowElement( parent )
00026 {
00027 }
00028 
00029 void EncloseElement::paint( QPainter& painter, AttributeManager* )
00030 {
00031     painter.save();
00032     QPen pen;
00033     pen.setWidth( 1 );
00034     painter.setPen( pen );
00035     painter.drawPath( m_enclosePath );
00036     painter.restore();
00037 }
00038 
00039 void EncloseElement::layout( const AttributeManager* am )
00040 {
00041     // TODO: actuarial (how does it look?) - radical - circle (how to determine extends )
00042     m_enclosePath = QPainterPath();
00043     QString tmpstring = am->stringOf( "notation", this );
00044     QList<QString> tmp=tmpstring.split(" ");
00045     RowElement::layout( am );
00046     QRectF tmpRect = boundingRect();
00047 /*    if( tmp.contains( "longdiv" ) ) {
00048         m_enclosePath.moveTo( 0, 0 );
00049         m_enclosePath.lineTo();
00050     }*/
00051     if( tmp.contains( "left" ) ) {
00052         m_enclosePath.moveTo( 0, 0 );
00053         m_enclosePath.lineTo( 0, tmpRect.height() );
00054     }
00055     if( tmp.contains( "right" ) ) {
00056         m_enclosePath.moveTo( tmpRect.width(), 0 );
00057         m_enclosePath.lineTo( tmpRect.width(), tmpRect.height() );
00058     }
00059     if( tmp.contains( "top" ) ) {
00060         m_enclosePath.moveTo( 0, 0 );
00061         m_enclosePath.lineTo( tmpRect.width(), 0 );
00062     }
00063     if( tmp.contains( "bottom" ) ) {
00064         m_enclosePath.moveTo( 0, tmpRect.height() );
00065         m_enclosePath.lineTo( tmpRect.width(), tmpRect.height());
00066     }
00067     if( tmp.contains( "box" ) ) {        // TODO spacing is missing - might look odd
00068         m_enclosePath.addRect( 0, 0, tmpRect.width(), tmpRect.height() );
00069     }
00070     if( tmp.contains( "roundedbox" ) ) { // TODO spacing is missing - might look odd
00071     m_enclosePath.addRoundRect( 0, 0, tmpRect.width(), tmpRect.height(), 25 );
00072     }
00073     if( tmp.contains( "updiagonalstrike" ) ) {
00074         m_enclosePath.moveTo( 0, tmpRect.height() );
00075         m_enclosePath.lineTo( tmpRect.width(), 0 );
00076     }
00077     if( tmp.contains( "downdiagonalstrike" ) ) {
00078         m_enclosePath.moveTo( 0, 0 );
00079         m_enclosePath.lineTo( tmpRect.width(), tmpRect.height() );
00080     }
00081     if( tmp.contains( "verticalstrike" ) ) {
00082         m_enclosePath.moveTo( tmpRect.width()/2, 0 );
00083         m_enclosePath.lineTo( tmpRect.width()/2, tmpRect.height() );
00084     }
00085     if( tmp.contains( "horizontalstrike" ) ) {
00086         m_enclosePath.moveTo( 0, tmpRect.height()/2 );
00087         m_enclosePath.lineTo( tmpRect.width(), tmpRect.height()/2 );
00088     }
00089     setWidth( tmpRect.width() );
00090     setHeight( tmpRect.height() );
00091 }
00092 
00093 ElementType EncloseElement::elementType() const
00094 {
00095     return Enclose;
00096 }
00097