1
/* This file is part of the KDE project
2
Copyright (C) 2009 Jeremias Epperlein <jeeree@web.de>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
20
#include "FixedElement.h"
21
#include "FormulaCursor.h"
22
#include <KoXmlWriter.h>
23
#include <KoXmlReader.h>
28
FixedElement::FixedElement( BasicElement* parent ) : BasicElement( parent )
32
FixedElement::~FixedElement()
37
BasicElement* FixedElement::elementAfter ( int position ) const
39
if (position % 2 == 0) {
40
return elementNext(position);
46
BasicElement* FixedElement::elementBefore ( int position ) const
48
if (position % 2 == 1) {
49
return elementNext(position);
55
BasicElement* FixedElement::elementNext ( int position ) const
57
return childElements()[position/2];
61
QPainterPath FixedElement::selectionRegion(const int pos1, const int pos2) const
69
bool FixedElement::moveHorSituation(FormulaCursor& newcursor, FormulaCursor& oldcursor, int pos1, int pos2) {
70
if ((newcursor.position()/2==pos1 && newcursor.direction()==MoveUp) ||
71
(newcursor.position()/2==pos2 && newcursor.direction()==MoveDown) ||
72
(newcursor.position()==2*pos1 && newcursor.direction()==MoveLeft) ||
73
(newcursor.position()==2*pos2+1 && newcursor.direction()==MoveRight) ) {
76
switch (newcursor.direction()) {
78
if (newcursor.position()==2*pos2+1) {
79
newcursor.moveTo(newcursor.currentElement()->childElements()[pos2]);
81
newcursor.moveTo(newcursor.currentElement()->childElements()[pos1]);
85
if (newcursor.position()==2*pos1) {
86
newcursor.moveTo(newcursor.currentElement()->childElements()[pos1]);
88
newcursor.moveTo(newcursor.currentElement()->childElements()[pos2]);
93
return newcursor.moveCloseTo(childElements()[newcursor.direction()==MoveUp ? pos1 : pos2],oldcursor);
100
bool FixedElement::moveVertSituation(FormulaCursor& newcursor, FormulaCursor& oldcursor, int pos1, int pos2) {
101
if ((newcursor.position()/2==pos1 && newcursor.direction()==MoveUp) ||
102
(newcursor.position()/2==pos2 && newcursor.direction()==MoveDown) ||
103
(newcursor.position()%2==0 && newcursor.direction()==MoveLeft) ||
104
(newcursor.position()%2==1 && newcursor.direction()==MoveRight) ) {
107
switch (newcursor.direction()) {
110
if (newcursor.position()/2==pos1) {
111
newcursor.moveTo(newcursor.currentElement()->childElements()[pos1]);
113
newcursor.moveTo(newcursor.currentElement()->childElements()[pos2]);
118
return newcursor.moveCloseTo(childElements()[newcursor.direction()==MoveUp ? pos1 : pos2],oldcursor);
125
bool FixedElement::moveSingleSituation ( FormulaCursor& newcursor, FormulaCursor& oldcursor, int pos )
127
Q_UNUSED( oldcursor )
128
switch (newcursor.direction()) {
130
if (newcursor.position()%2==1) {
131
newcursor.moveTo(newcursor.currentElement()->childElements()[pos]);
136
if (newcursor.position()%2==0) {
137
newcursor.moveTo(newcursor.currentElement()->childElements()[pos]);
150
bool FixedElement::acceptCursor ( const FormulaCursor& cursor )
156
QLineF FixedElement::cursorLine ( int position ) const
160
tmp=elementBefore(position)->absoluteBoundingRect();
161
return QLineF(tmp.topRight(),tmp.bottomRight());
163
tmp=elementAfter(position)->absoluteBoundingRect();
164
return QLineF(tmp.topLeft(),tmp.bottomLeft());
168
int FixedElement::positionOfChild ( BasicElement* child ) const
170
int tmp=childElements().indexOf(child);
178
bool FixedElement::loadElement ( KoXmlElement& tmp, RowElement** child )
180
BasicElement *element;
181
element = ElementFactory::createElement( tmp.tagName(), this );
182
if( !element->readMathML( tmp ) ) {
185
if (element->elementType()==Row) {
187
(*child)=static_cast<RowElement*>(element);
189
(*child)->insertChild(0,element);
195
int FixedElement::endPosition() const
197
return childElements().length()*2-1;