Source Code (Use browser search to find items of interest.)
Class Index
kformula'FormulaDisplay (./koffice/kformula/old/widget.h:122)
class FormulaDisplay : public QWidget
{
Q_OBJECT
public:
int getPos();
FormulaDisplay( QWidget *parent=0, const char *name=0);
// ~FormulaDisplay();
QString name;
void setCursor(QRect re);
void setCurrent(int cur);
int getCurrent();
int addBlock(int Type = -1,int ID = -1,int nextID = -1,int prevID = -1,
QString Cont = "", int Child1 = -1,int Child2=-1, int Child3=-1);
void checkAndCreate(FormulaBlock *bl);
void deleteIt(FormulaBlock *bl);
FormulaBlock *Blocks[2000];
bool isFree[2000];
int firstfree;
int corr,xOff,yOff;
protected slots:
void keyPressEvent(QKeyEvent *k);
void mousePressEvent( QMouseEvent *a );
void toggleCursor();
void setGreek(bool on);
void change(const char * newcont);
void addB0();
void addB1();
void addB2();
void addB3();
void addB4();
void addB5();
void addB4bis();
void line(int i);
void addCh1();
void addCh2();
void addCh3();
void pro();
void dele();
void reduceAll();
void reduce();
void reduceRecur();
void enlargeAll();
void enlarge();
void enlargeRecur();
protected:
void drawCursor();
void paintEvent( QPaintEvent * );
private:
KLocale *klo;
QPainter *painter;
QTimer *cursorTimer;
int current;
int pos;
QRect cursorPos;
bool isBlack;
bool showIt;
signals:
void ChText(const char *);
void ChType(int);
};
kformula'FormulaDisplay::FormulaDisplay() (./koffice/kformula/old/widget.cpp:466)
FormulaDisplay::FormulaDisplay( QWidget *parent=0, const char *name=0 )
: QWidget(parent,name)
{
klo = new KLocale("kde");
painter = new QPainter(this);
for(firstfree=0;firstfree<2000;firstfree++)
isFree[firstfree]=TRUE;
// Blocks[firstfree]=NULL;
isFree[0]=FALSE;
firstfree=1;
current=0;
pos=0;
name= "KDE Formula Display";
cursorTimer= new QTimer();
connect(cursorTimer,SIGNAL(timeout()),this,SLOT(toggleCursor()));
cursorTimer->start(500);
Blocks[0] = new FormulaBlock(this,-1,0,-1,-1,"");
}
kformula'FormulaDisplay::keyPressEvent() (./koffice/kformula/old/widget.cpp:485)
void FormulaDisplay::keyPressEvent( QKeyEvent *k )
{
int c,prev,next,c1,c2,c3,len,type;
c=getCurrent();
prev=Blocks[c]->getprev();
next=Blocks[c]->getnext();
c1=Blocks[c]->getchild1();
c2=Blocks[c]->getchild2();
c3=Blocks[c]->getchild3();
type=Blocks[c]->gettype();
len=Blocks[c]->getcont().length();
if(k->key()==Key_Left) {
if((type==0)&&(pos>0)) pos--;
else
if(prev!=-1)setCurrent(prev);
}
if(k->key()==Key_Right) {
if((type==0)&&(pos<len)) pos++;
else
if(next!=-1) setCurrent(next);
else
if(c1!=-1) setCurrent(c1);
else
if(c2!=-1) setCurrent(c2);
}
if(k->key()==Key_Up) {
if(c1!=-1) setCurrent(c1);
else
if(prev!=-1) setCurrent(prev);
}
if(k->key()==Key_Down) {
if(c2!=-1) setCurrent(c2);
else
if(prev!=-1) setCurrent(prev);
}
if(k->key()==Key_Backspace) {
if(pos>0) { pos--;
Blocks[c]->getcont().remove(pos,1);
}
}
else
if(k->key()==Key_Delete) {
if(type==0) Blocks[c]->getcont().remove(pos,1); else deleteIt(Blocks[c]);
} else
if((k->ascii()>32)&&(k->ascii()<127))
{
c1=c;
c2=c1;
if(Blocks[c1]->gettype()>0) {
next=Blocks[c1]->getnext();
c2=addBlock(0,-1,next,c1,"");
Blocks[c1]->setnext(c2); }
else Blocks[c1]->settype(0);
setCurrent(c2);
Blocks[getCurrent()]->getcont().insert(pos,k->ascii());
pos++;
}
ChText(Blocks[getCurrent()]->getcont());
ChType(Blocks[getCurrent()]->gettype());
update();
}
kformula'FormulaDisplay::paintEvent() (./koffice/kformula/old/widget.cpp:551)
void FormulaDisplay::paintEvent( QPaintEvent * )
{
Blocks[0]->getDimensions(); // Get dimension of Block0 (all formula dimension)
painter->setPen( black );
Blocks[0]->PaintIt(painter,1+xOff,1+yOff+Blocks[0]->getLYU(),1);
isBlack=FALSE;
}
kformula'FormulaDisplay::getPos() (./koffice/kformula/old/widget.cpp:560)
int FormulaDisplay::getPos()
{
return pos;
}
kformula'FormulaDisplay::setCurrent() (./koffice/kformula/old/widget.cpp:565)
void FormulaDisplay::setCurrent(int cur)
{
if(current!=cur) pos=Blocks[cur]->getcont().length();
Blocks[current]->setactive(0);
Blocks[cur]->setactive(1);
current=cur;
ChText(Blocks[cur]->getcont()); //Signals
ChType(Blocks[cur]->gettype());
}
kformula'FormulaDisplay::getCurrent() (./koffice/kformula/old/widget.cpp:575)
int FormulaDisplay::getCurrent()
{
return (current);
}
kformula'FormulaDisplay::mousePressEvent() (./koffice/kformula/old/widget.cpp:580)
void FormulaDisplay::mousePressEvent( QMouseEvent *a)
{
setCurrent(Blocks[0]->getClick(a->pos()));
repaint();
if(a->button()==RightButton){
QPopupMenu *mousepopup = new QPopupMenu;
QPopupMenu *convert = new QPopupMenu;
QPopupMenu *fontpopup = new QPopupMenu;
fontpopup->insertItem(klocale("Font +"), this, SLOT(enlarge()), ALT+Key_K);
fontpopup->insertItem(klocale("Font -"), this, SLOT(reduce()), ALT+Key_K);
fontpopup->insertItem(klocale("Font + (also Children)"), this, SLOT(enlargeRecur()), ALT+Key_K);
fontpopup->insertItem(klocale("Font - (also Children)"), this, SLOT(reduceRecur()), ALT+Key_K);
fontpopup->insertItem(klocale("All Font +"), this, SLOT(enlargeAll()), ALT+Key_K);
fontpopup->insertItem(klocale("All Font -"), this, SLOT(reduceAll()), ALT+Key_K);
// convert->insertItem(klocale("Simple Text"), parent->_part, SLOT(slotQuit()), ALT+Key_E);
// convert->insertItem("AAAARGGHHH", _part, SLOT(slotQuit()), ALT+Key_E);
mousepopup->insertItem(klocale("Proprieties"), this,SLOT(pro()), ALT+Key_E);
mousepopup->insertItem(klocale("Delete"), this,SLOT(dele()), ALT+Key_E);
mousepopup->insertSeparator();
mousepopup->insertItem(klocale("Change font.."),fontpopup);
mousepopup->insertItem(klocale("Convert to.."),convert);
// mousepopup->insertSeparator();
// mousepopup->insertItem(klocale("Quit"), _part, SLOT(slotQuit()), ALT+Key_Q);
mousepopup->popup(mapToGlobal(a->pos()));
}
}
kformula'FormulaDisplay::setCursor() (./koffice/kformula/old/widget.cpp:606)
void FormulaDisplay::setCursor(QRect re)
{
cursorPos = re;
}
/*
FormulaDisplay SLOTS
*/
kformula'FormulaDisplay::setGreek() (./koffice/kformula/old/widget.cpp:617)
void FormulaDisplay::setGreek(bool on)
{
if (on)
Blocks[getCurrent()]->fontc.setFamily("Symbol");
else
Blocks[getCurrent()]->fontc.setFamily("utopia");
repaint();
}
kformula'FormulaDisplay::change() (./koffice/kformula/old/widget.cpp:625)
void FormulaDisplay::change(const char * newcont)
{
if (Blocks[getCurrent()]->gettype()==-1) Blocks[getCurrent()]->settype(0);
Blocks[getCurrent()]->setcont(newcont);
repaint();
}
kformula'FormulaDisplay::toggleCursor() (./koffice/kformula/old/widget.cpp:632)
void FormulaDisplay::toggleCursor()
{
drawCursor();
}
kformula'FormulaDisplay::drawCursor() (./koffice/kformula/old/widget.cpp:637)
void FormulaDisplay::drawCursor()
{
//QPainter paint;
showIt=hasFocus();
if((showIt)||(isBlack&&(!showIt))) {
//painter->begin();
painter->drawWinFocusRect(cursorPos);
//painter->end();
isBlack=!isBlack;
}
}
kformula'FormulaDisplay::reduce() (./koffice/kformula/old/widget.cpp:649)
void FormulaDisplay::reduce()
{
Blocks[getCurrent()]->reduceFont(0);
repaint();
}
kformula'FormulaDisplay::reduceRecur() (./koffice/kformula/old/widget.cpp:654)
void FormulaDisplay::reduceRecur()
{
Blocks[getCurrent()]->reduceFont(1);
repaint();
}
kformula'FormulaDisplay::reduceAll() (./koffice/kformula/old/widget.cpp:659)
void FormulaDisplay::reduceAll()
{
Blocks[getCurrent()]->reduceFont(2);
repaint();
}
kformula'FormulaDisplay::enlarge() (./koffice/kformula/old/widget.cpp:665)
void FormulaDisplay::enlarge()
{
Blocks[getCurrent()]->enlargeFont(0);
repaint();
}
kformula'FormulaDisplay::enlargeRecur() (./koffice/kformula/old/widget.cpp:670)
void FormulaDisplay::enlargeRecur()
{
Blocks[getCurrent()]->enlargeFont(1);
repaint();
}
kformula'FormulaDisplay::enlargeAll() (./koffice/kformula/old/widget.cpp:675)
void FormulaDisplay::enlargeAll()
{
Blocks[getCurrent()]->enlargeFont(2);
repaint();
}
kformula'FormulaDisplay::addCh3() (./koffice/kformula/old/widget.cpp:681)
void FormulaDisplay::addCh3()
{
int nextold=-1;
int Id;
nextold=Blocks[getCurrent()]->getchild3();
Id=addBlock(-1,-1,nextold,getCurrent(),"");
Blocks[getCurrent()]->setchild3(Id);
if(Blocks[getCurrent()]->gettype()==2) Blocks[Id]->reduceFont(1);
setCurrent(Id);
repaint();
}
kformula'FormulaDisplay::line() (./koffice/kformula/old/widget.cpp:693)
void FormulaDisplay::line(int i)
{
if(i==1) Blocks[getCurrent()]->setcont("line");
else
Blocks[getCurrent()]->setcont("vertical space");
repaint();
}
kformula'FormulaDisplay::addCh2() (./koffice/kformula/old/widget.cpp:701)
void FormulaDisplay::addCh2()
{
int nextold=-1;
int Id;
nextold=Blocks[getCurrent()]->getchild2();
Id=addBlock(-1,-1,nextold,getCurrent(),"");
Blocks[getCurrent()]->setchild2(Id);
if(Blocks[getCurrent()]->gettype()<4) Blocks[Id]->reduceFont(1);
setCurrent(Id);
repaint();
}
kformula'FormulaDisplay::addCh1() (./koffice/kformula/old/widget.cpp:712)
void FormulaDisplay::addCh1()
{
int nextold=-1;
int Id;
nextold=Blocks[getCurrent()]->getchild1();
Id=addBlock(-1,-1,nextold,getCurrent(),"");
Blocks[getCurrent()]->setchild1(Id);
if(Blocks[getCurrent()]->gettype()==0) Blocks[Id]->reduceFont(1);
setCurrent(Id);
repaint();
}
kformula'FormulaDisplay::pro() (./koffice/kformula/old/widget.cpp:724)
void FormulaDisplay::pro()
{
new ProData(Blocks[getCurrent()],this); //proprieties
checkAndCreate(Blocks[getCurrent()]);
ChText(Blocks[getCurrent()]->getcont());
ChType(Blocks[getCurrent()]->gettype());
setFocus();
update();
}
kformula'FormulaDisplay::dele() (./koffice/kformula/old/widget.cpp:734)
void FormulaDisplay::dele()
{
deleteIt(Blocks[getCurrent()]);
}
kformula'FormulaDisplay::addB1() (./koffice/kformula/old/widget.cpp:739)
void FormulaDisplay::addB1()
{
int nextold=-1;
int Id,cur;
cur=getCurrent();
Id=cur;
if(Blocks[cur]->gettype()!=-1) { nextold=Blocks[cur]->getnext();
Id=addBlock(1,-1,nextold,cur,"c");
Blocks[cur]->setnext(Id); }
else {
Blocks[cur]->settype(1);
checkAndCreate(Blocks[cur]);
}
setCurrent(Blocks[Id]->getchild1());
repaint();
}
kformula'FormulaDisplay::addB2() (./koffice/kformula/old/widget.cpp:756)
void FormulaDisplay::addB2()
{
int nextold=-1;
int Id,cur;
cur=getCurrent();
Id=cur;
if(Blocks[cur]->gettype()!=-1) { nextold=Blocks[cur]->getnext();
Id=addBlock(2,-1,nextold,cur,"c");
Blocks[cur]->setnext(Id); }
else {
Blocks[cur]->settype(2);
checkAndCreate(Blocks[cur]);
}
setCurrent(Blocks[Id]->getchild1());
repaint();
}
kformula'FormulaDisplay::addB0() (./koffice/kformula/old/widget.cpp:773)
void FormulaDisplay::addB0()
{
int nextold=-1;
int Id,cur;
cur=getCurrent();
Id=cur;
nextold=Blocks[cur]->getnext();
Id=addBlock(-1,-1,nextold,cur,"");
Blocks[cur]->setnext(Id);
setCurrent(Id);
repaint();
}
kformula'FormulaDisplay::addB5() (./koffice/kformula/old/widget.cpp:786)
void FormulaDisplay::addB5()
{
int nextold=-1;
int Id,cur;
cur=getCurrent();
Id=cur;
if(Blocks[cur]->gettype()!=-1) {
nextold=Blocks[cur]->getnext();
Id=addBlock(5,-1,nextold,cur,"");
Blocks[cur]->setnext(Id); }
else {
Blocks[cur]->settype(5);
Blocks[cur]->setcont(">");
checkAndCreate(Blocks[cur]);
}
setCurrent(Blocks[Id]->getchild1());
repaint();
}
kformula'FormulaDisplay::addB4() (./koffice/kformula/old/widget.cpp:805)
void FormulaDisplay::addB4()
{
int nextold=-1;
int Id,cur;
cur=getCurrent();
Id=cur;
if(Blocks[cur]->gettype()!=-1) { nextold=Blocks[cur]->getnext();
Id=addBlock(4,-1,nextold,cur,"line");
Blocks[cur]->setnext(Id); }
else {
Blocks[cur]->settype(4);
Blocks[cur]->setcont("line");
checkAndCreate(Blocks[cur]);
}
setCurrent(Blocks[Id]->getchild1());
repaint();
}
kformula'FormulaDisplay::addB4bis() (./koffice/kformula/old/widget.cpp:822)
void FormulaDisplay::addB4bis()
{
int nextold=-1;
int Id,cur;
cur=getCurrent();
Id=cur;
if(Blocks[cur]->gettype()!=-1) { nextold=Blocks[cur]->getnext();
Id=addBlock(4,-1,nextold,cur,"vertical space");
Blocks[cur]->setnext(Id); }
else {
Blocks[cur]->settype(4);
Blocks[cur]->setcont("vertical space");
checkAndCreate(Blocks[cur]);
}
setCurrent(Blocks[Id]->getchild1());
repaint();
}
kformula'FormulaDisplay::addB3() (./koffice/kformula/old/widget.cpp:840)
void FormulaDisplay::addB3()
{
int nextold=-1;
int Id,cur;
cur=getCurrent();
Id=cur;
if(Blocks[cur]->gettype()!=-1) { nextold=Blocks[cur]->getnext();
Id=addBlock(3,-1,nextold,cur,"()");
Blocks[cur]->setnext(Id); }
else {
Blocks[cur]->settype(3);
Blocks[cur]->setcont("()");
checkAndCreate(Blocks[cur]);
}
setCurrent(Blocks[Id]->getchild1());
repaint();
}
kformula'FormulaDisplay::addBlock() (./koffice/kformula/old/widget.cpp:859)
int FormulaDisplay::addBlock(int Type = -1,int ID = -1,int nextID = -1,int prevID = -1,
QString Cont = "", int Child1 = -1,int Child2=-1, int Child3=-1)
{
if (ID==-1) ID=firstfree;
isFree[ID]=FALSE;
for(firstfree=1;!isFree[firstfree];firstfree++)
;
//QString s;
//s.sprintf("First free block: %i",firstfree);
// warning(s);
Blocks[ID]= new FormulaBlock(this,Type,ID,nextID,prevID,Cont,Child1,Child2,Child3);
checkAndCreate(Blocks[ID]);
return (ID);
}
kformula'FormulaDisplay::deleteIt() (./koffice/kformula/old/widget.cpp:876)
void FormulaDisplay::deleteIt(FormulaBlock *bl)
{
int id=bl->getID();
if(id!=0) {
int next=bl->getnext();
int prev=bl->getprev();
int child1=bl->getchild1();
int child2=bl->getchild2();
int child3=bl->getchild3();
if(next!=-1) Blocks[next]->setprev(prev);
if(prev!=-1) {
if(Blocks[prev]->getnext()==id) Blocks[prev]->setnext(next);
if(Blocks[prev]->getchild1()==id) Blocks[prev]->setchild1(next);
if(Blocks[prev]->getchild2()==id) Blocks[prev]->setchild2(next);
if((Blocks[prev]->getchild3()==id)/*&&(Blocks[prev]->gettype()!=4)*/) Blocks[prev]->setchild3(next);
}
if(child1!=-1) deleteIt(Blocks[child1]);
if(child2!=-1) deleteIt(Blocks[child2]);
if((child3!=-1)/*&&(bl->gettype()!=4)*/) deleteIt(Blocks[child3]);
checkAndCreate(Blocks[prev]);
if(prev!=-1) setCurrent(prev);
isFree[id]=TRUE;
delete bl;
update();
}
else KMsgBox::message(this,klocale("Error"),
klocale("Can not delete First Block !!"));
}
kformula'FormulaDisplay::checkAndCreate() (./koffice/kformula/old/widget.cpp:905)
void FormulaDisplay::checkAndCreate(FormulaBlock *bl)
{
int ID;
ID=bl->getID();
switch (bl->gettype())
{
case 1:
if (bl->getchild1()==-1) bl->setchild1(addBlock(-1,-1,-1,ID,""));
break;
case 2:
if (bl->getchild1()==-1) bl->setchild1(addBlock(-1,-1,-1,ID,""));
break;
case 3:
if(bl->getcont()=="") bl->setcont("()");
if (bl->getchild1()==-1) bl->setchild1(addBlock(-1,-1,-1,ID,""));
break;
case 4:
if (bl->getcont()=="") bl->setcont("line");
if (bl->getchild1()==-1) bl->setchild1(addBlock(-1,-1,-1,ID,""));
if (bl->getchild2()==-1) bl->setchild2(addBlock(-1,-1,-1,ID,""));
if (bl->getsp()==-1) bl->setsp(10);
break;
case 5:
if (bl->getcont()=="") bl->setcont(">");
if (bl->getchild1()==-1) bl->setchild1(addBlock(-1,-1,-1,ID,""));
break;
}
}
/*
CLASS FormulaBlock
a component of AFormula
Structure of a Block:
Prev(BL)---BL-------Next(Bl)
/ | \
/ | \
child1 child2 child3
Prev(child1)=prev(child2)=prev(child3)=BL
more info about child1,child2,child3 on widget.h
*/