diff --git a/plugins/formulashape/KoM2MMLForumulaTool.cpp b/plugins/formulashape/KoM2MMLForumulaTool.cpp index 404a7f407c4..8ddfbf91fe3 100644 --- a/plugins/formulashape/KoM2MMLForumulaTool.cpp +++ b/plugins/formulashape/KoM2MMLForumulaTool.cpp @@ -1,142 +1,162 @@ /* This file is part of the KDE project Copyright (C) 2011 Cyrille Berger This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "KoM2MMLForumulaTool.h" #include "KoFormulaShape.h" #include #include #include #include #include #include "FormulaCommand.h" #include #include #include "FormulaCommandUpdate.h" +#include +#include KoM2MMLFormulaTool::KoM2MMLFormulaTool(KoCanvasBase* canvas): KoToolBase(canvas) { } void KoM2MMLFormulaTool::activate(KoToolBase::ToolActivation toolActivation, const QSet< KoShape* >& shapes) { foreach (KoShape *shape, shapes) { m_formulaShape = dynamic_cast( shape ); if( m_formulaShape ) break; } if( m_formulaShape == 0 ) // none found { emit done(); return; } + QString source; + FormulaElement* element = m_formulaShape->formulaData()->formulaElement(); + foreach(BasicElement* elt, element->childElements()) + { + if(elt->elementType() == Annotation) + { + source = static_cast(elt)->content(); + } + } + + if(m_lineEdit) + { + m_lineEdit->setText(source); + } } void KoM2MMLFormulaTool::mouseMoveEvent(KoPointerEvent* event) { } void KoM2MMLFormulaTool::mousePressEvent(KoPointerEvent* event) { } void KoM2MMLFormulaTool::mouseReleaseEvent(KoPointerEvent* event) { } void KoM2MMLFormulaTool::paint(QPainter& painter, const KoViewConverter& converter) { } QWidget* KoM2MMLFormulaTool::createOptionWidget() { QWidget* widget = new QWidget; - QHBoxLayout* layout = new QHBoxLayout; + QVBoxLayout* layout = new QVBoxLayout; widget->setLayout(layout); m_lineEdit = new QLineEdit(widget); layout->addWidget(m_lineEdit); m_errorLabel = new QLabel(widget); layout->addWidget(m_errorLabel); m_errorLabel->setText(""); - layout->addSpacerItem(); + layout->addSpacerItem(new QSpacerItem(0,0)); connect(m_lineEdit, SIGNAL(editingFinished()), SLOT(textEdited())); connect(m_lineEdit, SIGNAL(returnPressed()), SLOT(textEdited())); return widget; } // Not sure why but the toStdString/fromStdString in QString are not accessible inline std::string QStringtoStdString(const QString& str) { const QByteArray asc = str.toAscii(); return std::string(asc.constData(), asc.length()); } inline QString QStringfromStdString(const std::string &s) { return QString::fromAscii(s.data(), int(s.size())); } void KoM2MMLFormulaTool::textEdited() { if(!m_formulaShape) return; if(!m_lineEdit) return; std::string source = QStringtoStdString(m_lineEdit->text()); std::string mathml; std::string errmsg; if(m2mml(source, mathml, &errmsg)) { KoXmlDocument tmpDocument; tmpDocument.setContent( QStringfromStdString(mathml), false, 0, 0, 0 ); FormulaElement* formulaElement = new FormulaElement(); // create a new root element formulaElement->readMathML( tmpDocument.documentElement() ); // and load the new formula + + AnnotationElement* annot = new AnnotationElement; + annot->setContent(m_lineEdit->text()); + formulaElement->insertChild(0, annot); canvas()->addCommand(new FormulaCommandUpdate(m_formulaShape, new FormulaCommandLoad(m_formulaShape->formulaData(), formulaElement))); - m_errorLabel->setText(""); + m_errorLabel->setText(""); } else { m_errorLabel->setText(QStringfromStdString(errmsg)); } } KoM2MMLFormulaToolFactory::KoM2MMLFormulaToolFactory() : KoToolFactoryBase("KoM2MMLFormulaToolFactoryId") { setToolTip( i18n( "Edit formula with matlab syntax" ) ); setToolType( dynamicToolType() ); setIcon( "edittext" ); setPriority( 1 ); setActivationShapeId( KoFormulaShapeId ); } KoM2MMLFormulaToolFactory::~KoM2MMLFormulaToolFactory() {} KoToolBase* KoM2MMLFormulaToolFactory::createTool( KoCanvasBase* canvas ) { return new KoM2MMLFormulaTool( canvas ); } #include "KoM2MMLForumulaTool.moc"