Source Code (Use browser search to find items of interest.)
Class Index
kformula'BasicElement (./koffice/kformula/BasicElement.h:38)
class BasicElement
{
public:
/*
* Normal constructor, Get font from prev element
*/
BasicElement(KFormulaContainer *Formula,
BasicElement *Prev=0,
int Relation=-1,
BasicElement *Next=0,
QString Content="");
/*
* Link Next & Prev removing itself
*/
virtual ~BasicElement();
/*
* each derived class must implement its own Draw()
* "prev" is responsable for x,y
*
*/
virtual void draw(QPoint drawPoint,int resolution = 72);
/*
* Must be called by draw()
* RootElement may need to rewrite it.
*/
virtual void drawIndexes(QPainter *pen,int resolution);
/*
* each derived class must implement its own CheckSize()
* void because autostore size in Data
*/
virtual void checkSize();
/*
* Check if needed children exists.
*
*/
virtual void check();
/*
* Must be called by draw()
* RootElement may need to rewrite it.
*/
virtual void checkIndexesSize();
/*
* Scale Font size
*/
void scaleNumericFont(int level);
/*
* Set Font size
*/
virtual void setNumericFont(int newValue);
/*
* Change pointer of next element
*/
void setNext(BasicElement *newNext);
/*
* Change poniter of previous element
*/
void setPrev(BasicElement *newPrev);
/*
* Sets the beActive flag status
*
*/
void setActive(bool ac) { beActive=ac; }
/*
* Useful for Mouse click
*/
virtual BasicElement *isInside(QPoint point);
virtual QRect getCursor(int atPos);
/*
* Return element font
*/
int getNumericFont() const { return numericFont; }
/*
* Return globalsize (see globalSize)
*/
QRect getSize() const { return globalSize; }
/*
* Return next
*/
BasicElement * getNext() const { return next; }
/*
* Return prev
*/
BasicElement * getPrev() const { return prev; }
/*
* Return index
*/
BasicElement * getIndex(int ind) const { return index[ind]; }
/*
* Return child
*/
BasicElement * getChild(int chi) const { if(chi<childrenNumber) return child[chi]; else return 0L; }
/*
* Return the default color of element
*/
QColor *getColor() const { return defaultColor; }
QString getContent() const {return content;}
/*
* Various Set-GetFunction
*/
void setContent(QString a) {content=a.copy();}
QString getContent() { return content;}
void setIndex(BasicElement *e,int i) {index[i]=e; }
void setChild(BasicElement *e,int i) {child[i]=e; }
void setColor(QColor *c) {defaultColor=c; }
void setRelation(int r) {relation=r; }
/*
* Update the eList of kformuladoc
*
*/
virtual void makeList(bool active=0);
/*
* change type
* clone MUST be a derived class of BasicElement
* Note:every link with children is lost
* Use this function only to change from BasicElement
*/
void substituteElement(BasicElement *clone);
/*
* insert an element between this element and prev
*/
void insertElement(BasicElement *element);
/*
* delete this element, its children & index
*/
void deleteElement();
/*
* At the moment they do nothing.
*
*/
virtual void save(ostream& out);
virtual void load(istream& in);
protected:
/*
* I know nothing about the future of this member
*/
KFormulaContainer *formula;
/*
* realtionship with prev
* -1=I'm its Next
* 0..3=Index 0..3
* 4..n=child[n-4]
*/
int relation;
/*
* Next & previous Elements
*/
BasicElement *next;
BasicElement *prev;
/*
* Index printed near the corners of element
* Those aren't integral or Sum limits
* But left_up may be root index
* 0=left_up,1=left_down,2=right_up,3=right_down
*/
BasicElement *index[4];
/*
* each dervied class could add children
* Sum,integral,matrix,fraction,root,delimiter,decoration need children
* Plaintext,TextSymbol,operators do not need children
* adding a:
* BasicElement *child[n]
*/
QArray<BasicElement *> child;
/*
* The number of children.
*/
int childrenNumber;
/*
* The number of children.
*/
int minChildren;
/*
* real data: text,symbol code,delimiter code,matrix rows&cols
*/
QString content;
/*
* Size of (family+next) & next elements
*/
QRect globalSize; //y=0 base line
/*
* Size of family & indexes
* This name isn't very good.I'm sorry.
*/
QRect localSize;
/*
* Size of Family:father & children (without indexes )
*/
QRect familySize;
/*
* Area where I am painted (last time)
* localSize+drawPoint
*/
QRect myArea;
/*
* Font
*
QFont font;
*/
/*
* numericFont correspond to
* font.pointSize for text,
* a Scale value for symbols & decoration
* the number of line of a drawed(not pixmap) Root, Integral or Bracket
*/
int numericFont;
/*
* When editing defaultColor may be overiden
* if defaultColor is 0 it use formula->defaultColor
*/
QColor *defaultColor;
/*
* True if element is current (edited) element
*/
bool beActive;
/*
* Cursor Internal position
* In TextElement it is the position of the cursor into the contentstring
* pos==0 Before element
* pos!=0 After.
*/
};
kformula'BasicElement::BasicElement() (./koffice/kformula/BasicElement.cc:16)
BasicElement::BasicElement(KFormulaContainer *Formula,
BasicElement *Prev,
int Relation,
BasicElement *Next,
QString Content)
{
formula=Formula;
prev=Prev;
relation=Relation;
next=Next;
content=Content;
if(prev!=NULL) {
numericFont=prev->getNumericFont();
//warning("Font OK");
} else
numericFont=24;
childrenNumber=0;
minChildren=0;
index[0]=0L;
index[1]=0L;
index[2]=0L;
index[3]=0L;
beActive=FALSE;
}
kformula'BasicElement::~BasicElement() (./koffice/kformula/BasicElement.cc:41)
BasicElement::~BasicElement()
{
/* See deleteElement to
* Link prev with next & remove itself
*/
}
kformula'BasicElement::isInside() (./koffice/kformula/BasicElement.cc:49)
BasicElement *BasicElement::isInside(QPoint point)
{
int i;
if(myArea.contains(point)) {
BasicElement *aValue=0L;
if(next!=0)
if((aValue=next->isInside(point))!=0L)
return aValue;
for(i=0;i<4;i++)
if(index[i]!=0)
if((aValue=index[i]->isInside(point))!=0L)
return aValue;
for(i=0;i<childrenNumber;i++)
{
if(child[i]!=0)
{
warning("Child %i",i);
if((aValue=child[i]->isInside(point))!=0L)
return aValue;
}
}
return this;
} else
return 0L;
}
kformula'BasicElement::draw() (./koffice/kformula/BasicElement.cc:79)
void BasicElement::draw(QPoint drawPoint,int resolution)
{
QPainter *pen = formula->painter();
// QRect globalArea;
int x = drawPoint.x();
int y = drawPoint.y();
if( beActive )
pen->setPen(Qt::red);
pen->setBrush(Qt::NoBrush);
pen->drawRect(x+familySize.x(),y-5,10,10);
myArea=globalSize;
myArea.moveBy(x,y);
#ifdef RECT
pen->drawRect(myArea);
#endif
if(beActive)
pen->setPen(Qt::blue);
drawIndexes(pen,resolution);
if(beActive)
pen->setPen(Qt::black);
if(next!=0L) next->draw(drawPoint+QPoint(localSize.width(),0),resolution);
}
kformula'BasicElement::drawIndexes() (./koffice/kformula/BasicElement.cc:104)
void BasicElement::drawIndexes(QPainter *,int resolution)
{
//draw point
QPoint dp = myArea.topLeft()-globalSize.topLeft();
if(index[0]!=0L)
index[0]->draw(dp + familySize.topLeft() -
index[0]->getSize().bottomRight(),
resolution);
if(index[1]!=0L)
index[1]->draw(dp + familySize.bottomLeft() -
index[1]->getSize().topRight(),
resolution);
if(index[2]!=0L)
index[2]->draw(dp + familySize.topRight() -
index[2]->getSize().bottomLeft(),
resolution);
if(index[3]!=0L)
index[3]->draw(dp + familySize.bottomRight() -
index[3]->getSize().topLeft(),
resolution);
}
kformula'BasicElement::checkSize() (./koffice/kformula/BasicElement.cc:127)
void BasicElement::checkSize()
{
//warning("%p",this);
QRect nextDimension;
if (next!=0L)
{
next->checkSize();
nextDimension=next->getSize();
}
localSize=QRect(0,-5,10,10);
familySize=localSize;
checkIndexesSize(); //This will change localSize adding Indexes Size
familySize.moveBy(-localSize.left(),0);
localSize.moveBy(-localSize.left(),0);
globalSize=localSize;
nextDimension.moveBy(localSize.width(),0);
globalSize=globalSize.unite(nextDimension);
}
kformula'BasicElement::check() (./koffice/kformula/BasicElement.cc:148)
void BasicElement::check()
{
int i=0;
for(i=0;i<childrenNumber;i++)
if (child[i]==0L)
if (i<minChildren)
child[i]=new BasicElement(formula,this,i+4);
}
kformula'BasicElement::checkIndexesSize() (./koffice/kformula/BasicElement.cc:157)
void BasicElement::checkIndexesSize()
{
QRect indexDimension;
QPoint vectorT;
int i;
for(i=0;i<4;i++)
if (index[i]!=0L) index[i]->checkSize();
if(index[0]!=0L)
{
indexDimension=index[0]->getSize();
vectorT=familySize.topLeft()-indexDimension.bottomRight();
indexDimension.moveBy(vectorT.x(),vectorT.y());
localSize=localSize.unite(indexDimension);
}
if(index[1]!=0L)
{
indexDimension=index[1]->getSize();
vectorT=familySize.bottomLeft()-indexDimension.topRight();
indexDimension.moveBy(vectorT.x(),vectorT.y());
localSize=localSize.unite(indexDimension);
}
if(index[2]!=0L)
{
indexDimension=index[2]->getSize();
vectorT=familySize.topRight()-indexDimension.bottomLeft();
indexDimension.moveBy(vectorT.x(),vectorT.y());
localSize=localSize.unite(indexDimension);
}
if(index[3]!=0L)
{
indexDimension=index[3]->getSize();
vectorT=familySize.bottomRight()-indexDimension.topLeft();
indexDimension.moveBy(vectorT.x(),vectorT.y());
localSize=localSize.unite(indexDimension);
}
}
kformula'BasicElement::scaleNumericFont() (./koffice/kformula/BasicElement.cc:195)
void BasicElement::scaleNumericFont(int level)
{
if((level & FN_ELEMENT)>0) {
if ((level & FN_REDUCE)>0)
{
if((level & FN_BYNUM)>0)
setNumericFont(numericFont-(level & 255));
else {
int den=(level & 15);
int num=((level>>4) & 15);
setNumericFont((numericFont*num)/den);
}
} else {
if((level & FN_BYNUM)>0)
setNumericFont(numericFont+(level & 255));
else
{
int num=(level & 15);
int den=((level>>4) & 15);
setNumericFont((numericFont*num)/den);
}
}
}
int ps;
if(level & FN_INDEXES)
for(ps=0;ps<4;ps++)
if(index[ps]!=0L) index[ps]->scaleNumericFont(level|FN_ALL);
if(level & FN_NEXT)
if(next!=0) next->scaleNumericFont(level|FN_ALL);
if(level & FN_CHILDREN)
{
for(ps=0;ps<childrenNumber;ps++)
if(child[ps]!=0L)child[ps]->scaleNumericFont(level|FN_ALL);
}
if(numericFont<FN_MIN) numericFont=FN_MIN;
if(numericFont>FN_MAX) numericFont=FN_MAX;
}
kformula'BasicElement::setNext() (./koffice/kformula/BasicElement.cc:236)
void BasicElement::setNext(BasicElement *newNext)
{
next=newNext;
}
kformula'BasicElement::setPrev() (./koffice/kformula/BasicElement.cc:241)
void BasicElement::setPrev(BasicElement *newPrev)
{
prev=newPrev;
}
kformula'BasicElement::setNumericFont() (./koffice/kformula/BasicElement.cc:246)
void BasicElement::setNumericFont(int value)
{
numericFont=value;
}
kformula'BasicElement::substituteElement() (./koffice/kformula/BasicElement.cc:251)
void BasicElement::substituteElement(BasicElement *clone)
{
int i;
clone->setContent(content);
clone->setNext(next);
clone->setPrev(prev);
for(i=0;i<4;i++) {
clone->setIndex(index[i],i);
if(index[i]!=0L) index[i]->setPrev(clone);
}
clone->setNumericFont(numericFont);
clone->setColor(defaultColor);
clone->setRelation(relation);
if(prev!=0L)
{
if(relation<4)
{
if(relation>=0)
prev->setIndex(clone,relation);
else
prev->setNext(clone);
}
else
prev->setChild(clone,relation-4);
}
else //I'm the first element!!
formula->setFirstElement(clone);
warning("Substituted %p with %p, waiting to be deleted",this,clone);
}
kformula'BasicElement::insertElement() (./koffice/kformula/BasicElement.cc:283)
void BasicElement::insertElement(BasicElement *element)
{
element->setPrev(prev);
if(prev!=0L)
{
if(relation<4)
{
if(relation>=0)
prev->setIndex(element,relation);
else
prev->setNext(element);
}
else
prev->setChild(element,relation-4);
}
else //I'm the first element!!
formula->setFirstElement(element);
prev=element;
element->setRelation(relation);
element->setNext(this);
relation=-1;
}
kformula'BasicElement::deleteElement() (./koffice/kformula/BasicElement.cc:308)
void BasicElement::deleteElement()
{
warning("deleteElement of -> %p prev %p next %p",this,prev,next);
if(next!=0L)
{
next->setPrev(prev);
next->setRelation(relation);
}
if(prev!=0L)
{
if(relation<4)
{
if(relation>=0)
prev->setIndex(next,relation);
else
prev->setNext(next);
}
else
prev->setChild(next,relation-4);
}
else //I'm the first element.
if(next!=0L)
formula->setFirstElement(next);
else
formula->setFirstElement(new BasicElement(formula));
int nc=0;
while (nc<childrenNumber)
{
if (child[nc]!=0L)
{
warning("I'm %p, I delete my child[%d]=%p i.e. %d of %d",this,nc,child[nc],nc+1,childrenNumber);
child[nc]->deleteElement();
}
else
nc++;
}
while (nc<4)
{
if (index[nc]!=0L)
index[nc]->deleteElement();
else
nc++;
}
delete this; // It is a good call ?
}
kformula'BasicElement::save() (./koffice/kformula/BasicElement.cc:359)
void BasicElement::save(ostream& out)
{
out << "TYPE=" << -1 << " "
<< "CONTENT=" << content.utf8().data() << " "
<< "NUMERICFONT=" << numericFont << " "
<< " >" << endl;
for(int i=0;i<4;i++)
if(index[i]!=0L)
{
out << " <ELEM INDEX=" << i << " ";
index[i]->save(out);
}
for(int i=0;i<childrenNumber;i++)
if(child[i]!=0L)
{
out << " <ELEM CHILD=" << i << " ";
child[i]->save(out);
}
if(next!=0)
{
out << " <ELEM NEXT ";
next->save(out);
}
out << "</ELEM>" << endl;
}
kformula'BasicElement::load() (./koffice/kformula/BasicElement.cc:387)
void BasicElement::load(istream& )
{
}
kformula'BasicElement::makeList() (./koffice/kformula/BasicElement.cc:391)
void BasicElement::makeList(bool active)
{
// warning("make list %p " ,this);
bool basic;
basic=(typeid(*this) == typeid(BasicElement));
if(!basic)
formula->addElement(this, 0);
// warning("append");
beActive=0;
for(int i=0;i<2;i++)
if(index[i]!=0) {
// warning("call for index%d %p",i,index[i]);
index[i]->makeList(active);
}
// warning("index OK");
for(int i=0;i<childrenNumber;i++)
if(child[i]!=0)
{
// warning("call for child%d %p",i,child[i]);
child[i]->makeList(active);
}
if(basic)
formula->addElement(this);
// warning("children done");
for(int i=2;i<4;i++)
if(index[i]!=0) {
// warning("call for index%d %p",i,index[i]);
index[i]->makeList(active);
}
if(next!=0)
next->makeList(active);
else if(!basic)
formula->addElement(this);
}
kformula'BasicElement::getCursor() (./koffice/kformula/BasicElement.cc:432)
QRect BasicElement::getCursor(int atPos)
{
QPoint dp = myArea.topLeft()-globalSize.topLeft();
if (typeid(*this) == typeid(BasicElement))
return (QRect(dp.x()+familySize.x()+3,dp.y()-8,5,16));
else
{
if(atPos==0)
return (QRect(dp.x()+localSize.x(),dp.y()-7,5,14));
else
return (QRect(dp.x()+localSize.right(),dp.y()-8,5,16));
}
return QRect(0,0,0,0);
}