~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kformula/flake/FixedElement.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE project
2
 
   Copyright (C) 2009 Jeremias Epperlein <jeeree@web.de>
3
 
 
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.
8
 
 
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.
13
 
 
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.
18
 
*/
19
 
 
20
 
#include "FixedElement.h"
21
 
#include "FormulaCursor.h"
22
 
#include <KoXmlWriter.h>
23
 
#include <KoXmlReader.h>
24
 
#include <QPainter>
25
 
 
26
 
#include <kdebug.h>
27
 
 
28
 
FixedElement::FixedElement( BasicElement* parent ) : BasicElement( parent )
29
 
{
30
 
}
31
 
 
32
 
FixedElement::~FixedElement()
33
 
{
34
 
}
35
 
 
36
 
 
37
 
BasicElement* FixedElement::elementAfter ( int position ) const
38
 
{
39
 
    if (position % 2 == 0) {
40
 
        return elementNext(position);
41
 
    } else {
42
 
        return 0;
43
 
    }
44
 
}
45
 
 
46
 
BasicElement* FixedElement::elementBefore ( int position ) const
47
 
{
48
 
    if (position % 2 == 1) {
49
 
        return elementNext(position);
50
 
    } else {
51
 
        return 0;
52
 
    }
53
 
}
54
 
 
55
 
BasicElement* FixedElement::elementNext ( int position ) const
56
 
{
57
 
        return childElements()[position/2];
58
 
}
59
 
 
60
 
 
61
 
QPainterPath FixedElement::selectionRegion(const int pos1, const int pos2) const 
62
 
{
63
 
    QPainterPath temp;
64
 
    Q_UNUSED(pos1);
65
 
    Q_UNUSED(pos2);
66
 
    return temp;
67
 
}
68
 
 
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) ) {
74
 
        return false;
75
 
    }
76
 
    switch (newcursor.direction()) {
77
 
    case MoveLeft:
78
 
        if (newcursor.position()==2*pos2+1) {
79
 
            newcursor.moveTo(newcursor.currentElement()->childElements()[pos2]);
80
 
        } else {
81
 
            newcursor.moveTo(newcursor.currentElement()->childElements()[pos1]);
82
 
        }
83
 
        break;
84
 
    case MoveRight:
85
 
        if (newcursor.position()==2*pos1) {
86
 
            newcursor.moveTo(newcursor.currentElement()->childElements()[pos1]);
87
 
        } else {
88
 
            newcursor.moveTo(newcursor.currentElement()->childElements()[pos2]);
89
 
        }
90
 
        break;
91
 
    case MoveUp:
92
 
    case MoveDown:
93
 
        return newcursor.moveCloseTo(childElements()[newcursor.direction()==MoveUp ? pos1 : pos2],oldcursor);
94
 
    case NoDirection:
95
 
        break;
96
 
    }
97
 
    return true;
98
 
}
99
 
 
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) ) {
105
 
        return false;
106
 
    }
107
 
    switch (newcursor.direction()) {
108
 
    case MoveLeft:
109
 
    case MoveRight:
110
 
        if (newcursor.position()/2==pos1) {
111
 
            newcursor.moveTo(newcursor.currentElement()->childElements()[pos1]);
112
 
        } else {
113
 
            newcursor.moveTo(newcursor.currentElement()->childElements()[pos2]);
114
 
        }
115
 
        break;
116
 
    case MoveUp:
117
 
    case MoveDown:
118
 
        return newcursor.moveCloseTo(childElements()[newcursor.direction()==MoveUp ? pos1 : pos2],oldcursor);
119
 
    case NoDirection:
120
 
        break;
121
 
    }
122
 
    return true;
123
 
}
124
 
 
125
 
bool FixedElement::moveSingleSituation ( FormulaCursor& newcursor, FormulaCursor& oldcursor, int pos )
126
 
{
127
 
    Q_UNUSED( oldcursor )
128
 
    switch (newcursor.direction()) {
129
 
    case MoveLeft:
130
 
        if (newcursor.position()%2==1) {
131
 
            newcursor.moveTo(newcursor.currentElement()->childElements()[pos]);
132
 
            break;
133
 
        }
134
 
        return false;
135
 
    case MoveRight:
136
 
        if (newcursor.position()%2==0) {
137
 
            newcursor.moveTo(newcursor.currentElement()->childElements()[pos]);
138
 
            break;
139
 
        }
140
 
    case MoveUp:
141
 
    case MoveDown:
142
 
        return false;
143
 
    case NoDirection:
144
 
        break;
145
 
    }
146
 
    return true;
147
 
}
148
 
 
149
 
 
150
 
bool FixedElement::acceptCursor ( const FormulaCursor& cursor )
151
 
{
152
 
    Q_UNUSED (cursor)
153
 
    return false;
154
 
}
155
 
 
156
 
QLineF FixedElement::cursorLine ( int position ) const
157
 
{
158
 
    QRectF tmp;
159
 
    if (position%2==1) {
160
 
        tmp=elementBefore(position)->absoluteBoundingRect();
161
 
        return QLineF(tmp.topRight(),tmp.bottomRight());
162
 
    } else {
163
 
        tmp=elementAfter(position)->absoluteBoundingRect();
164
 
        return QLineF(tmp.topLeft(),tmp.bottomLeft());
165
 
    }
166
 
}
167
 
 
168
 
int FixedElement::positionOfChild ( BasicElement* child ) const
169
 
{
170
 
    int tmp=childElements().indexOf(child);
171
 
    if (tmp==-1) {
172
 
        return -1;
173
 
    } else {
174
 
        return 2*tmp;
175
 
    }
176
 
}
177
 
 
178
 
bool FixedElement::loadElement ( KoXmlElement& tmp, RowElement** child )
179
 
{
180
 
    BasicElement *element;
181
 
    element = ElementFactory::createElement( tmp.tagName(), this );
182
 
    if( !element->readMathML( tmp ) ) {
183
 
        return false;
184
 
    }
185
 
    if (element->elementType()==Row) {
186
 
        delete (*child);
187
 
        (*child)=static_cast<RowElement*>(element);
188
 
    } else {
189
 
        (*child)->insertChild(0,element);
190
 
    }
191
 
    return true;
192
 
}
193
 
 
194
 
 
195
 
int FixedElement::endPosition() const
196
 
{
197
 
    return childElements().length()*2-1;
198
 
}