[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/kformula/flake
From: Martin Pfeiffer <hubipete () gmx ! net>
Date: 2008-03-15 18:40:19
Message-ID: 1205606419.349955.7960.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 785980 by mpfeiffer:
* implement inserting for some elements
* clean up for SubSupElement
M +4 -5 FractionElement.cpp
M +4 -1 RowElement.cpp
M +46 -54 SubSupElement.cpp
M +12 -7 SubSupElement.h
M +13 -0 UnderOverElement.cpp
M +7 -0 UnderOverElement.h
--- trunk/koffice/kformula/flake/FractionElement.cpp #785979:785980
@@ -146,13 +146,12 @@
void FractionElement::insertChild( FormulaCursor* cursor, BasicElement* child )
{
- BasicElement* tmp = cursor->currentElement();
- if( tmp == m_numerator && m_numerator->elementType() == Basic )
+ if( cursor->currentElement() == m_numerator )
m_numerator = child;
- else if( tmp == m_denominator && m_denominator->elementType() == Basic )
+ else if( cursor->currentElement() == m_denominator )
m_denominator = child;
-
- delete tmp; // finally delete the old BasicElement
+// else
+ // TODO make some error
}
void FractionElement::removeChild( FormulaCursor* cursor, BasicElement* element )
--- trunk/koffice/kformula/flake/RowElement.cpp #785979:785980
@@ -71,7 +71,10 @@
void RowElement::insertChild( FormulaCursor* cursor, BasicElement* child )
{
- m_childElements.insert( cursor->position(), child );
+ if( cursor->currentElement() == this )
+ m_childElements.insert( cursor->position(), child );
+ // else
+ // TODO make some error
}
void RowElement::removeChild( FormulaCursor* cursor, BasicElement* child )
--- trunk/koffice/kformula/flake/SubSupElement.cpp #785979:785980
@@ -18,6 +18,7 @@
*/
#include "SubSupElement.h"
+#include "FormulaCursor.h"
#include "AttributeManager.h"
#include <KoXmlWriter.h>
#include <KoXmlReader.h>
@@ -26,17 +27,15 @@
SubSupElement::SubSupElement( BasicElement* parent ) : BasicElement( parent )
{
m_baseElement = new BasicElement( this );
- m_postSubscript = new BasicElement( this );
- m_postSuperscript = new BasicElement( this );
+ m_subScript = new BasicElement( this );
+ m_superScript = new BasicElement( this );
}
SubSupElement::~SubSupElement()
{
delete m_baseElement;
- //delete m_preSubscript;
- // delete m_preSuperscript;
- delete m_postSubscript;
- delete m_postSuperscript;
+ delete m_subScript;
+ delete m_superScript;
}
void SubSupElement::paint( QPainter& painter, AttributeManager* am )
@@ -59,16 +58,16 @@
// The yOffset is the amount the base element is moved down to make
// room for the superscript
double yOffset = 0;
- if(m_postSuperscript) {
- yOffset = m_postSuperscript->height() - m_baseElement->height()/2 + halfthinSpace;
+ if(m_superScript) {
+ yOffset = m_superScript->height() - m_baseElement->height()/2 + halfthinSpace;
yOffset = qMax( yOffset, superscriptshift );
}
double largestWidth = 0;
- if(m_postSubscript)
- largestWidth = m_postSubscript->width();
- if(m_postSuperscript) {
- largestWidth = qMax( largestWidth, m_postSuperscript->width());
- m_postSuperscript->setOrigin( QPointF( m_baseElement->width(), 0) );
+ if(m_subScript)
+ largestWidth = m_subScript->width();
+ if(m_superScript) {
+ largestWidth = qMax( largestWidth, m_superScript->width());
+ m_superScript->setOrigin( QPointF( m_baseElement->width(), 0) );
}
setWidth( m_baseElement->width() + largestWidth );
@@ -76,13 +75,13 @@
m_baseElement->setOrigin( QPointF( 0, yOffset ) );
- if(m_postSubscript) {
+ if(m_subScript) {
double yPos = yOffset +
qMax( m_baseElement->height()/2 + halfthinSpace,
- m_baseElement->height() - m_postSubscript->baseLine()
+ m_baseElement->height() - m_subScript->baseLine()
+ subscriptshift );
- m_postSubscript->setOrigin( QPointF( m_baseElement->width(), yPos ) );
- setHeight( yPos + m_postSubscript->height() );
+ m_subScript->setOrigin( QPointF( m_baseElement->width(), yPos ) );
+ setHeight( yPos + m_subScript->height() );
} else
setHeight( yOffset + m_baseElement->height() );
}
@@ -95,14 +94,21 @@
const QList<BasicElement*> SubSupElement::childElements()
{
QList<BasicElement*> tmp;
- tmp << m_baseElement;
- if(m_postSubscript)
- tmp << m_postSubscript;
- if(m_postSuperscript)
- tmp << m_postSuperscript;
- return tmp;
+ return tmp << m_baseElement << m_subScript << m_superScript;
}
+void SubSupElement::insertChild( FormulaCursor* cursor, BasicElement* child )
+{
+ if( cursor->currentElement() == m_baseElement )
+ m_baseElement = child;
+ else if( cursor->currentElement() == m_subScript )
+ m_subScript = child;
+ else if( cursor->currentElement() == m_superScript )
+ m_superScript = child;
+// else
+// TODO add some error
+}
+
QString SubSupElement::attributesDefaultValue( const QString& attribute ) const
{
return QString();
@@ -110,30 +116,19 @@
ElementType SubSupElement::elementType() const
{
- if( m_postSubscript && m_postSuperscript )
+ if( m_subScript->elementType() != Basic &&
+ m_superScript->elementType() != Basic )
return SubSupScript;
- else if( m_postSubscript )
+ else if( m_subScript->elementType() != Basic )
return SubScript;
- else if( m_postSuperscript )
+ else if( m_superScript->elementType() != Basic )
return SupScript;
- else
- return SubSupScript;
}
bool SubSupElement::readMathMLContent( const KoXmlElement& parent )
{
- QString name = parent.tagName().toLower();
BasicElement* tmpElement = 0;
KoXmlElement tmp;
- //The possibilities are msub, msup and msubsup
- if(!name.contains( "sub" )) {
- delete m_postSubscript;
- m_postSubscript = NULL;
- }
- if(!name.contains( "sup" )) {
- delete m_postSuperscript;
- m_postSuperscript = NULL;
- }
forEachElement( tmp, parent ) {
tmpElement = ElementFactory::createElement( tmp.tagName(), this );
if( !tmpElement->readMathML( tmp ) )
@@ -143,32 +138,29 @@
delete m_baseElement;
m_baseElement = tmpElement;
}
- else if( m_postSubscript && m_postSubscript->elementType() == Basic ) {
- delete m_postSubscript;
- m_postSubscript = tmpElement;
- Q_ASSERT(m_postSubscript);
+ else if( m_subScript->elementType() == Basic ) {
+ delete m_subScript;
+ m_subScript = tmpElement;
}
- else if( m_postSuperscript && m_postSuperscript->elementType() == Basic ) {
- delete m_postSuperscript;
- m_postSuperscript = tmpElement;
- Q_ASSERT(m_postSuperscript);
+ else if( m_superScript->elementType() == Basic ) {
+ delete m_superScript;
+ m_superScript = tmpElement;
}
else
return false;
}
- Q_ASSERT(m_baseElement); //We should have at least a BasicElement for the base
- Q_ASSERT(m_postSubscript || m_postSuperscript);
return true;
}
void SubSupElement::writeMathMLContent( KoXmlWriter* writer ) const
{
- m_baseElement->writeMathML( writer ); // Just save the children in
- // the right order
- if( m_postSubscript )
- m_postSubscript->writeMathML( writer );
+ // just save the children in the right order
+ m_baseElement->writeMathML( writer );
+
+ if( m_subScript->elementType() != Basic )
+ m_subScript->writeMathML( writer );
- if( m_postSuperscript )
- m_postSuperscript->writeMathML( writer );
+ if( m_superScript->elementType() != Basic )
+ m_superScript->writeMathML( writer );
}
--- trunk/koffice/kformula/flake/SubSupElement.h #785979:785980
@@ -61,6 +61,13 @@
*/
BasicElement* acceptCursor( const FormulaCursor* cursor );
+ /**
+ * Insert a new child at the cursor position
+ * @param cursor The cursor holding the position where to insert
+ * @param child A BasicElement to insert
+ */
+ void insertChild( FormulaCursor* cursor, BasicElement* child );
+
/// @return The default value of the attribute for this element
QString attributesDefaultValue( const QString& attribute ) const;
@@ -75,16 +82,14 @@
void writeMathMLContent( KoXmlWriter* writer ) const;
private:
- /// The BasicElement representing the base element
+ /// The base element
BasicElement* m_baseElement;
- //BasicElement* m_preSuperscript;
+ /// The subscript right to the m_baseElement
+ BasicElement* m_subScript;
- /// The BasicElement representing the subscript right to the base element
- BasicElement* m_postSubscript;
-
- /// The BasicElement representing the superscript right to the base element
- BasicElement* m_postSuperscript;
+ /// The superscript right to the m_baseElement
+ BasicElement* m_superScript;
};
#endif // SUBSUPELEMENT_H
--- trunk/koffice/kformula/flake/UnderOverElement.cpp #785979:785980
@@ -19,6 +19,7 @@
*/
#include "UnderOverElement.h"
+#include "FormulaCursor.h"
#include "AttributeManager.h"
#include <KoXmlReader.h>
#include <kdebug.h>
@@ -82,6 +83,18 @@
return 0;
}
+void UnderOverElement::insertChild( FormulaCursor* cursor, BasicElement* child )
+{
+ if( cursor->currentElement() == m_baseElement )
+ m_baseElement = child;
+ else if( cursor->currentElement() == m_underElement )
+ m_underElement = child;
+ else if( cursor->currentElement() == m_overElement )
+ m_overElement = child;
+// else
+// TODO make some error
+}
+
QString UnderOverElement::attributesDefaultValue( const QString& attribute ) const
{
/* if( m_overElement->elementType() == Operator )
--- trunk/koffice/kformula/flake/UnderOverElement.h #785979:785980
@@ -56,6 +56,13 @@
void layout( const AttributeManager* am );
/**
+ * Insert a new child at the cursor position
+ * @param cursor The cursor holding the position where to insert
+ * @param child A BasicElement to insert
+ */
+ void insertChild( FormulaCursor* cursor, BasicElement* child );
+
+ /**
* Implement the cursor behaviour for the element
* @param cursor The FormulaCursor that is moved around
* @return A this pointer if the element accepts if not the element to asked instead
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic