/* * MathPlanner 3.1.0 - Mathematical design tool. * Copyright(C) 2002 Jarmo Nikkanen * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation. * * You should have received a copy of the GNU General Public License with this program. * */ #include #include #include "AppControl.h" #include "Paper.h" #include "Error.h" #include "Memory.h" #include "ServerHeaders.h" #include "Math.h" #include "DragDrop.h" #include "ConfigReader.h" #include "Datastore.h" #include "Function_object.h" #include "Extern.h" #include "Object_string.h" #include "FrameObjects.h" #include #include #include #include #include #include #include #include int cursortype; int z_factor; DataStorage *Paper::BuildStorage() // Delete data returned by this function { int i=0,c=0; DataStorage *ar,*msg; char name[30]; msg=new DataStorage(); MathFrame *f; if (function) { for (i=0,c=0;iAddInt("Paper:FC",c); if (function) { for (i=0,c=0;iBuildStorage(); if (ar) msg->AddDataStorage(name,ar,false); if (ar) delete ar; } } } return(msg); } void Paper::New() { int i; // Reload default preferences Prefs->Load(); POSTMESSAGE(MSG_CONFIGURATION,TO_APPCONTROL); POSTMESSAGE(MSG_RESETNAME,TO_MAIN); // Clear servers if (AppControl->function_server) AppControl->function_server->DeleteAllFunctions(); if (AppControl->integer_server) AppControl->integer_server->DeleteAllIntegers(); // UnFocus and Delete functions if exists Focused_function=(-1); if (function) { for(i=0;iReadInt("Paper:FC"); if (Function_count<32) Function_count=32; SetFunctionSpace(Function_count); Bug("Start UnArchiving Function"); if (function) { for (i=0;iContains(name)) { ar=new DataStorage(); msg->ReadDataStorage(name,ar); int Ob=ar->ReadInt("Object"); if (Ob==PAPER_OBJECT_FUNCTION) function[i]=new m_function_object(ar,AppControl,this); if (Ob==PAPER_OBJECT_IMAGE) function[i]=new PaperImage(ar,AppControl,this); if (Ob==PAPER_OBJECT_QPICTURE) function[i]=new PaperQPicture(ar,AppControl,this); if (Ob==PAPER_OBJECT_TEXT) function[i]=new PaperText(ar,AppControl,this); // if (Ob==PAPER_OBJECT_GRAPH) function[i]=new PaperGraph(ar,AppControl,this); delete ar; } } } UpDate(); Bug("Paper_object unarchived"); } void Paper::CalculateAll() { int i,x,count; class MathFrame *f; Bug("START CALCULATE ALL"); AppControl->AddError(""); if (AppControl->integer_server) AppControl->integer_server->DeleteAllIntegers(); if (AppControl->function_server) AppControl->function_server->DeleteAllFunctions(); count=OrderFunctions(); x=0; i=0; for(x=0;xObjectType==PAPER_OBJECT_FUNCTION) { m_function_object *fo=(m_function_object *)f; fo->SetModify(); fo->Build(); AppControl->integer_server->SetLocalValues(fo); fo->Calculate(); } /* if (f->ObjectType==PAPER_OBJECT_GRAPH) { PaperGraph *fo=(PaperGraph *)f; fo->DrawFunctions(); } */ // ************** MATH FRAME EXECUTION ****************** } } } Bug("calculate completed"); } int Paper::OrderFunctions() { int i,k,top_f,last,count; int pos,x,y,top,line,max; max=2147483640; line=0; count=0; last=0; for(i=0;iPosition().y(); x=function[k]->Position().x(); pos=(y*2000)+(x/5); if (posline) top=pos,top_f=k; } } if (top!=max) { Order[i]=top_f; line=top; } else { Order[i]=(-1); break; } } return(count); } void Paper::UpDate() { class m_function_object *fuo; class MathFrame *f; int i; Bug("******** UPDATE CALLED ************"); PaperLimits=Prefs->Rect("PaperWidth","PaperHeight"); Grid=Prefs->Int("GridSize"); if (Grid==0) Grid=1; GridColor=Prefs->Color("GridColor"); Printable=QRect(Prefs->Int("LeftMargin"),Prefs->Int("TopMargin"), PaperLimits.width()-Prefs->Int("RightMargin")-Prefs->Int("LeftMargin"), PaperLimits.height()-Prefs->Int("BottomMargin")-Prefs->Int("TopMargin")); int x=PaperLimits.width(); int y=PaperLimits.height(); int z=z_factor; //AppControl->ZoomFactor(); QRect re=Scale(z,QRect(0,0,x,y)); if (geometry().size()!=re.size()) setGeometry(re); setEraseColor(Prefs->Color("PaperColor")); setBackgroundMode(Qt::NoBackground); CalculateAll(); for(i=0;iObjectType==PAPER_OBJECT_FUNCTION) { fuo=(m_function_object *)f; fuo->SendCall(CALL_SYNTAXCHK); Bug("******** UPDATE: CALCULATE BOUNDS ************"); fuo->CalculateBounds(); Bug("******** UPDATE: MOVETO ************"); fuo->MoveTo(fuo->Position()); // Update position CHECK CHECK Bug("Passed"); } } } if (AppControl->function_server) { AppControl->CreateFunctionMenu(AppControl->function_server->CreateFunctionList()); } repaint(false); } // FOCUS CONTROL FOCUS CONTROL FOCUS CONTROL void Paper::UnFocusCurrentFunction() { CalculateAll(); int no=Focused_function; Focused_function=(-1); if (no!=(-1)) { if (function[no]) { function[no]->DeActivate(); if (function[no]->ObjectType==PAPER_OBJECT_FUNCTION) { m_function_object *fo=(m_function_object *)function[no]; fo->SendCall(CALL_SYNTAXCHK); fo->SetModify(); fo->AutoDelete(); } DrawFunction(function[no]); } } } void Paper::FocusFunction(int no) { int i; if (no!=Focused_function) { UnFocusCurrentFunction(); if (no!=(-1)) if (!function[no]->IsActive()) function[no]->Selected(); } Focused_function=no; if (no!=(-1)) { DrawFunction(function[no]); bool clear=true; for (i=0;iObjectType==PAPER_OBJECT_FUNCTION) return((m_function_object *)function[Focused_function]); } return(NULL); } // ********************************************************** int Paper::FindFunctionIndex(class MathFrame *f) { int i; for(i=0;iIsEmpty()) DeleteFunction(i); } } void Paper::DrawGrid(QPainter *paint) { int i; int x=Grid; int y=Grid; QColor c=GridColor; QColor cc(c.red()*8/10,c.green()*8/10,c.blue()*8/10); QRect rect=Printable; int ri=rect.right(); int bo=rect.bottom(); int le=rect.left(); int to=rect.top(); QPen pen(c,0,Qt::DashLine); QPen pen2(cc,0,Qt::DashLine); paint->setPen(pen); paint->setWindow(PaperLimits); for(i=x+rect.left();idrawLine(QPoint(i,to),QPoint(i,bo)); for(i=y+rect.top();idrawLine(QPoint(le,i),QPoint(ri,i)); paint->setPen(pen2); paint->drawRect(rect); } void Paper::DrawFunction(MathFrame *f,bool rep) { int zoom=z_factor; //AppControl->ZoomFactor(); int i=FindFunctionIndex(f); if (i!=(-1)) { Bug("*** DrawFunction Called ***"); if (f->ObjectType==PAPER_OBJECT_FUNCTION) { m_function_object *fo=(m_function_object *)f; fo->Calculate(); } f->CalculateBounds(); f->MoveTo(f->Position()); QRect bo=f->Bounds(true); int x=(bo.left()*zoom/100)-2; int y=(bo.top()*zoom/100)-2; int xx=(bo.right()*zoom/100)+2; int yy=(bo.bottom()*zoom/100)+2; if (rep) { repaint(x,y,xx-x,yy-y,false); f->ResetBounds(); } } } void Paper::Snap(QPoint p,int *x,int *y) { QPaintDeviceMetrics met(this); int zoom=z_factor; int sx=Grid*met.logicalDpiX()*zoom/2500; int sy=sx; //*x=((p.x()-(sx/2))/sx)*sx; //*y=((p.y()-(sy/2))/sy)*sy; *x=(p.x()/sx)*sx; *y=(p.y()/sy)*sy; } QPoint Paper::ScreenToDocument(QPoint p) { int zoom=z_factor; //AppControl->ZoomFactor(); int x=p.x()*100/zoom; int y=p.y()*100/zoom; return(QPoint(x,y)); } QRect Paper::ScreenToDocument(QRect r) { int zoom=z_factor; //AppControl->ZoomFactor(); int x=r.left()*100/zoom; int y=r.top()*100/zoom; int xx=r.right()*100/zoom; int yy=r.bottom()*100/zoom; QRect re; re.setCoords(x,y,xx,yy); return(re); } void Paper::paintEvent(QPaintEvent *pe) { QPixmap buffer(size(),-1,QPixmap::BestOptim); QPainter paint; paint.begin(&buffer,this); paint.setClipRect(pe->rect()); paint.setClipping(true); paint.eraseRect(pe->rect()); if (Grid>1) DrawGrid(&paint); paint.setWindow(Scale(100,PaperLimits)); paint.setViewport(0,0,width(),height()); Draw(&paint,pe->rect(),false); if (selectrect && selectrect_begin) DrawSelectionRect(&paint); paint.end(); bitBlt(this,pe->rect().topLeft(),&buffer,pe->rect()); } void Paper::DrawSelectionRect(QPainter *paint) { QPen pen; pen.setColor(Qt::black); pen.setWidth(0); pen.setStyle(Qt::DotLine); paint->setPen(pen); paint->drawRect(selectionrect); } void Paper::Draw(QPainter *pd,QRect drawrect,bool all) { MathFrame *f; int i; for(i=0;iBounds()) || all) { Bug("**** DRAWING FUNCTION *****"); f->Draw(pd); //pd->flush(); } } } } QImage Paper::CreateImage(MathFrame *function) { QPixmap pixmap(function->bounds.size()); function->MoveTo(QPoint(0,0)); QPainter paint; paint.begin(&pixmap); function->Draw(&paint); paint.end(); QImage image=pixmap.convertToImage(); return(image); } void Paper::AddGraph() { /* AppControl->DocumentChanged(); MathFrame *f=GetFocus(); FocusNone(); if (f) if (f->ObjectType==PAPER_OBJECT_GRAPH) { AppControl->Graph->SetGraph((class PaperGraph *)f,false); return; } class PaperGraph *pg=new PaperGraph(QRect(0,0,200,150),AppControl,this); AddFunction(QPoint(0,0),pg); AppControl->Graph->SetGraph(pg,true); */ } void Paper::CopyObject() // Used in copy-paste not in dnd { int Type; if (Selections()>1) { QMessageBox::information( this, "CopyObject","Unable to copy more than one object at a time"); return; } MathFrame *f=GetFocus(); if (f) { Type=f->ObjectType; if (Type==PAPER_OBJECT_FUNCTION) QApplication::clipboard()->setData(new MathDragObject(this,f)); if (Type==PAPER_OBJECT_IMAGE) { PaperImage *I=(PaperImage *)f; QApplication::clipboard()->setData(new ImageDragObject(I->Pixmap())); } if (Type==PAPER_OBJECT_QPICTURE) { PaperQPicture *I=(PaperQPicture *)f; QApplication::clipboard()->setData(new QPictureDragObject(I->Picture())); } if (Type==PAPER_OBJECT_TEXT) { PaperText *I=(PaperText *)f; QApplication::clipboard()->setData(new QTextDrag(I->Text())); } /* if (Type==PAPER_OBJECT_GRAPH) QApplication::clipboard()->setData(new MathDragObject(this,f)); */ } } void Paper::PasteObject(QPoint point) // Used in copy-paste not in dnd { QImage img; QMimeSource *mime=QApplication::clipboard()->data(); AppControl->DocumentChanged(); // Lets see what we have in clipboard // And choose the action if (mime) { if (DataDragObject::canDecode(mime)) { DataStorage *msg=DataDragObject::Decode(mime); if (ISMSG(MSG_COPY)) { POSTMESSAGE(MSG_PASTE,TO_STRING); } delete msg; return; } if (QTextDrag::canDecode(mime)) { if (point==QPoint(0,0)) SelectPosition(MSG_PASTEPOSITION,TO_PAPER); else { QString text; if (QTextDrag::decode(mime,text)) { AddFunction(point,new PaperText(text,AppControl,this)); } } return; } if (QPictureDragObject::canDecode(mime)) { if (point==QPoint(0,0)) SelectPosition(MSG_PASTEPOSITION,TO_PAPER); else { QPicture *pic=QPictureDragObject::Decode(mime); AddFunction(point,new PaperQPicture(pic,AppControl,this)); } return; } if (ImageDragObject::canDecode(mime)) { if (point==QPoint(0,0)) SelectPosition(MSG_PASTEPOSITION,TO_PAPER); else { img=ImageDragObject::Decode(mime); AddFunction(point,new PaperImage(img,AppControl,this)); } return; } if (MathDragObject::canDecode(mime)) { DataStorage *d=MathDragObject::Decode(mime); if (d) { MathFrame *f=NULL; //PaperGraph *g; int Type=d->ReadInt("Object"); if (Type==PAPER_OBJECT_FUNCTION) f=new m_function_object(d,AppControl,this); /* if (Type==PAPER_OBJECT_GRAPH) { g=new PaperGraph(d,AppControl,this); g->DrawFunctions(); f=g; }*/ delete d; AddFunction(point,f); return; } } } // if mime } void Paper::dragEnterEvent(QDragEnterEvent *event) { if (MathDragObject::canDecode(event)) { event->accept(true); return; } if (QTextDrag::canDecode(event)) { event->accept(true); return; } if (QPictureDragObject::canDecode(event)) { event->accept(true); return; } if (ImageDragObject::canDecode(event)) { event->accept(true); return; } } void Paper::dropEvent(QDropEvent* event) { int x,y; QImage img; QString text,no,doc; const char *tp; int i; AppControl->DocumentChanged(); if (AppControl->Prefs->Int("Show_drop_formats")==1) { tp=event->format(0); i=1; while(tp) { text.append(tp); text.append("\n"); tp=event->format(i++); } QMessageBox::information( this, "QMimeSource::format() Output",QString(text+"\n:are supported")); } QPoint p=ScreenToDocument(event->pos()); Snap(p,&x,&y); if (MathDragObject::canDecode(event)) { // Drop math objects DataStorage *d=MathDragObject::Decode(event); if (d) { MathFrame *f=NULL; //PaperGraph *g; int Type=d->ReadInt("Object"); if (Type==PAPER_OBJECT_FUNCTION) f=new m_function_object(d,AppControl,this); /* if (Type==PAPER_OBJECT_GRAPH) { g=new PaperGraph(d,AppControl,this); g->DrawFunctions(); f=g; }*/ delete d; AddFunction(QPoint(x,y),f); UpDate(); return; } } if (QTextDrag::canDecode(event)) { // Droping text and files(text,pictures) if (QTextDrag::decode(event,text)) { if (text.find("file:")==0) { // Droping files QString file_name=text; file_name.remove(0,5); QFileInfo info(file_name); int type=0; QString ext=info.extension(); ext.lower(); if (ext==QString("txt")) type=3; if (ext==QString("html")) type=1; if (ext==QString("htm")) type=1; if (ext==QString("xpm")) type=2; if (ext==QString("png")) type=2; if (ext==QString("bmp")) type=4; if (ext==QString("xbm")) type=4; if (ext==QString("pnm")) type=4; if (ext==QString("jpeg")) type=4; if (ext==QString("jpg")) type=4; if (ext==QString("mng")) type=4; if (ext==QString("gif")) type=4; if (ext==QString("svg")) type=5; if (type==1 || type==3) { QFile file(file_name); if ( file.open(IO_ReadOnly) ) { // file opened successfully QTextStream t( &file ); if (type==3) doc=QStyleSheet::convertFromPlainText(t.read()); else doc=t.read(); AddFunction(QPoint(x,y),new PaperText(doc,AppControl,this)); } } if (type==2 || type==4) { QImage img(file_name); if (img.isNull()==false) AddFunction(QPoint(x,y),new PaperImage(img,AppControl,this)); else QMessageBox::warning(this,"Drop Image","Unable to drop this object."); } if (type==5) { QPicture *pic=new QPicture(); pic->load(file_name,"svg"); if (pic->isNull()==false) AddFunction(QPoint(x,y),new PaperQPicture(pic,AppControl,this)); else QMessageBox::warning(this,"Drop SVG","Unable to drop this object."); } }// Files end else { // Droping text bool ric=QStyleSheet::mightBeRichText(text); if (ric==false) text=QStyleSheet::convertFromPlainText(text); AddFunction(QPoint(x,y),new PaperText(text,AppControl,this)); } return; } return; } if (QPictureDragObject::canDecode(event)) { QPicture *pic=QPictureDragObject::Decode(event); AddFunction(QPoint(x,y),new PaperQPicture(pic,AppControl,this)); return; } if (ImageDragObject::canDecode(event)) { img=ImageDragObject::Decode(event); AddFunction(QPoint(x,y),new PaperImage(img,AppControl,this)); return; } } void Paper::SelectPosition(int what,int to) { selectposition=true; sel_pos_msg=what; sel_pos_to=to; } void Paper::SelectRect(int what,int to) { selectrect=true; selectrect_begin=false; sel_rect_msg=what; sel_rect_to=to; } void Paper::FindSelectedFunctions() { int i; selections=0; for(i=(Function_count-1);i>=0;i--) { // from top to bottom if (function[i]) { if (selectionrect.contains(function[i]->Bounds())) { if (selections<60) { selected[selections++]=function[i]; function[i]->multi=true; } else ErrorReport("MathPlanner","Too many selected functions"); } } } } MathFrame *Paper::SelectedFunction(int no) { if (no=0;i--) if (function[i]) { if (function[i]->multi) bo=bo|function[i]->Bounds(true); function[i]->multi=false; } repaint(bo,false); } int Paper::Selections() { return(selections); } void Paper::mouseReleaseEvent(QMouseEvent *me) { Begin_move=false; Begin_resize=false; Timer.stop(); if (multiselection) FindSelectedFunctions(); if (selectrect && selectrect_begin) { DataStorage *msg=MESSAGE(sel_rect_msg); msg->AddQRect("rect",&selectionrect); selectrect=false; selectrect_begin=false; PostMessage(msg,sel_rect_to); repaint(selectionrect,false); selectionrect=QRect(0,0,0,0); } multiselection=false; } void Paper::CursorAction(QPoint p) { int i; QCursor PosC=QCursor(Qt::CrossCursor); QCursor MovC=QCursor(Qt::SizeAllCursor); QCursor RezC=QCursor(Qt::SizeFDiagCursor); QCursor StdC=QCursor(Qt::ArrowCursor); QCursor HanC=QCursor(Qt::PointingHandCursor); if (cursortype!=4) cursortype=0; if ((selectposition || selectrect) && cursortype!=1) { if (selectrect) setCursor(RectCursor); else setCursor(PosC); cursortype=1; } else for(i=(Function_count-1);i>=0;i--) { // from top to bottom if (function[i]) { if (function[i]->IsInBounds(p) && function[i]->HasFocus()) { if (function[i]->Type()!=PAPER_OBJECT_FUNCTION) { if (function[i]->IsInResizeArea(p)) { if (cursortype!=2) { setCursor(RezC); cursortype=2; } } else { if (cursortype!=3) { setCursor(MovC); cursortype=3; } } } break; } // in bounds } } // for if (cursortype==0) { setCursor(StdC); cursortype=4; } } bool Paper::MoveFunction(MathFrame *f,QPoint p) { int x,y; Snap(p,&x,&y); QPoint point(x,y); QRect print=Scale(100,PaperLimits); bool out=false; if (point.x()Bounds().width())>print.right()) out=true; if ((point.y()+f->Bounds().height())>print.bottom()) out=true; QPoint pp=f->Position(); if (pp.x()Bounds().width())>print.right()) out=false; if ((pp.y()+f->Bounds().height())>print.bottom()) out=false; if (out==false) { if (f->Position()!=point) { f->MoveTo(point); DrawFunction(f,false); } } return(out); } void Paper::mouseMoveEvent(QMouseEvent *me) { int x,y,i; bool out; QPoint point,p; if (Timer.isActive()) Timer.start(1000,true); point=me->pos(); mouseposition=point; p=ScreenToDocument(point); CursorAction(p); // Selection Area if (selectrect && selectrect_begin) { selectionrect=QRect(selectrect_begin_point,point); repaint(selectionrect | selectionrect_old,false); selectionrect_old=selectionrect; } // MOVE RESIZE AREA if (Focused_function!=(-1) && (Begin_move==true || Begin_resize==true)) { AppControl->DocumentChanged(); MathFrame *f=GetFocus(); point=me->pos(); p=ScreenToDocument(point)-Begin_move_align; QRect bo(0,0,0,0); if (Begin_move==true) { for(i=0;iBounds(true); SelectedFunction(i)->ResetBounds(); } } repaint(bo,false); } if (Begin_resize==true) { Snap(p,&x,&y); QPoint po(x,y); QRect print=Scale(100,PaperLimits); out=false; if ((po.x()-10)Bounds().left()) out=true; if ((po.y()-10)Bounds().top()) out=true; if (po.x()>print.right()) out=true; if (po.y()>print.bottom()) out=true; if (out==false) { QRect bo=f->Bounds(); bo.setRight(po.x()); bo.setBottom(po.y()); f->SetBounds(bo); DrawFunction(f); } } } } void Paper::StartDragging() { if (Selections()>1) { QMessageBox::information( this, "DragObject","Unable to copy more than one object at a time"); return; } MathFrame *f=GetFocus(); Timer.stop(); if (f) { int Type=f->ObjectType; if (Type==PAPER_OBJECT_FUNCTION) { QDragObject *mdrag=new MathDragObject(this,f); mdrag->setPixmap(DragImage,QPoint(16,16)); Begin_move=false; mdrag->drag(); } /* if (Type==PAPER_OBJECT_GRAPH) { QDragObject *mdrag=new MathDragObject(this,f); mdrag->setPixmap(DragImage,QPoint(16,16)); Begin_move=false; mdrag->drag(); } */ if (Type==PAPER_OBJECT_IMAGE) { PaperImage *I=(PaperImage *)f; QDragObject *mdrag=new ImageDragObject(I->Pixmap(),this); mdrag->setPixmap(DragImage,QPoint(16,16)); Begin_move=false; mdrag->drag(); } if (Type==PAPER_OBJECT_QPICTURE) { PaperQPicture *I=(PaperQPicture *)f; QDragObject *mdrag=new QPictureDragObject(I->Picture(),this); mdrag->setPixmap(DragImage,QPoint(16,16)); Begin_move=false; mdrag->drag(); } if (Type==PAPER_OBJECT_TEXT) { PaperText *I=(PaperText *)f; QDragObject *mdrag=new QTextDrag(I->Text(),this); mdrag->setPixmap(DragImage,QPoint(16,16)); Begin_move=false; mdrag->drag(); } } } QPoint Paper::FixedFunctionPosition(int no) { if (function[no]) return(function[no]->Position()); return(QPoint(0,0)); } void Paper::TimeOut() { StartDragging(); } void Paper::mousePressEvent(QMouseEvent *me) { int x,y,zoom,i,k; bool emptyarea; if (Selections()<2) Timer.start(1000,true); QPoint point=me->pos(); DeleteEmptyFunctions(); zoom=z_factor; //AppControl->ZoomFactor(); QPoint p=ScreenToDocument(point); Snap(p,&x,&y); point=QPoint(x,y); if (selectposition) { DataStorage *msg=MESSAGE(sel_pos_msg); msg->AddQPoint("point",&point); selectposition=false; PostMessage(msg,sel_pos_to); } else if (selectrect) { selectrect_begin=true; selectrect_begin_point=point; } else { emptyarea=true; for(i=(Function_count-1);i>=0;i--) { // from top to bottom if (function[i]) { if (function[i]->IsInBounds(p)) { FocusFunction(i); Begin_resize=Begin_move=false; emptyarea=false; // Double click will activate the function if (me->type()==QEvent::MouseButtonDblClick && function[i]->IsActive()==false) function[i]->Activate(); else { if (function[i]->IsInResizeArea(p)) { Begin_resize=true; Begin_move_align=point-function[i]->Bounds().bottomRight(); } else { Begin_move=true; Begin_move_align=point; for(k=0;kPosition(); } } function[i]->MousePressed(p); } // else DblClick break; // No need to seek more functions } } } if (emptyarea) { // mouse pressed on empty area UnFocusCurrentFunction(); ClearSelections(); if (me->type()==QEvent::MouseButtonDblClick) { // Double Clicked AppControl->DocumentChanged(); UnFocusCurrentFunction(); if (me->button()==Qt::LeftButton) AddFunction(point,new m_function_object(p,AppControl,this)); } else if (selectrect==false) { multiselection=true; SelectRect(MSG_MULTISELECTION,TO_PAPER); selectrect_begin=true; selectrect_begin_point=point; } } } // selectposition } bool Paper::CheckPoint(QPoint p) { int i; for(i=0;i=0) { if (function[no]) { QRect bo=function[no]->Bounds(); if (function[no]->HasFocus()) function[no]->UnFocus(); delete function[no]; function[no]=NULL; repaint(bo,false); } } } // Not Operational void Paper::SetNewFunctionAfter(MathFrame *func) { int x,y; QPoint p=func->Position(); int zoom=z_factor; //AppControl->ZoomFactor(); x=p.x(); y=p.y(); y+=(func->Bounds().height()*100/zoom); y+=Grid; Snap(QPoint(x,y),&x,&y); AddFunction(QPoint(x,y),new m_function_object(QPoint(x*zoom,y*zoom),AppControl,this)); } void Paper::AddFunction(QPoint p,MathFrame *func,bool flag) { int i; AppControl->CreateControlMenu(NULL); // Reset control menu for(i=0;iCalculateBounds(); func->MoveTo(p); Bug("Paper:AddFunction Function Added"); FocusFunction(i); return; } } if (flag==false) { // Prevent Looping AddFunctionSpace(50); AddFunction(p,func,true); return; } ErrorReport("Paper::AddFunction()","No space in function list"); } QRect Paper::Scale(int zoom,QRect b) { QPaintDeviceMetrics met(this); int w=b.width()*met.logicalDpiX()*zoom/2500; int h=b.height()*met.logicalDpiY()*zoom/2500; return(QRect(0,0,w,h)); } Paper::Paper(QWidget *pa,QRect bounds,class ApplicationControl *Aplc) :QWidget(pa) { int i; z_factor=100; setAcceptDrops(true); setMouseTracking(true); setBackgroundMode(Qt::NoBackground); Prefs=Aplc->Prefs; AppControl=Aplc; selectposition=false; selectrect=false; selectrect_begin=false; multiselection=false; selections=0; for(i=0;i<64;i++) selected[i]=NULL; connect(&Timer,SIGNAL(timeout()),this,SLOT(TimeOut())); setFocusPolicy(QWidget::ClickFocus); setEraseColor(Prefs->Color("PaperColor")); PaperLimits=Prefs->Rect("PaperWidth","PaperHeight"); Grid=Prefs->Int("GridSize"); GridColor=Prefs->Color("GridColor"); Printable=QRect(Prefs->Int("LeftMargin"),Prefs->Int("TopMargin"), PaperLimits.width()-Prefs->Int("RightMargin")-Prefs->Int("LeftMargin"), PaperLimits.height()-Prefs->Int("BottomMargin")-Prefs->Int("TopMargin")); function_mem=new NMemory(); Order_mem=new NMemory(); Position_mem=new NMemory(); Focused_function=-1; SetFunctionSpace(20); if (!DragImage.load(image_path+QString("/Drag.xpm"))) ErrorReport("MathPlanner","No Image Drag.xpm"); if (!CRectPixmap.load(image_path+QString("/cursor_rect.xpm"))) ErrorReport("MathPlanner","No Image cursor_rect.xpm"); RectCursor=QCursor(CRectPixmap,CRectPixmap); setGeometry(Scale(z_factor,PaperLimits)); //AppControl->ZoomFactor(100); } void Paper::AddFunctionSpace(int amount) { Function_count+=amount; function_mem->SetSizeTo(Function_count*sizeof(MathFrame *),true); Order_mem->SetSizeTo(Function_count*sizeof(int),true); Position_mem->SetSizeTo(Function_count*sizeof(QPoint),true); function=(MathFrame **)function_mem->Address(); Order=(int *)Order_mem->Address(); } void Paper::SetFunctionSpace(int amount) { Function_count=amount; function_mem->SetSizeTo(Function_count*sizeof(class MathFrame *),false); Order_mem->SetSizeTo(Function_count*sizeof(int),false); Position_mem->SetSizeTo(Function_count*sizeof(QPoint),false); function=(class MathFrame **)function_mem->Address(); Order=(int *)Order_mem->Address(); } void Paper::MessageReceived(DataStorage *msg,int rec) { if (rec==TO_PAPER) { if (ISMSG(MSG_PASTE)) PasteObject(); if (ISMSG(MSG_COPY)) CopyObject(); if (ISMSG(MSG_CUT)) DeleteCurrentFunction(); if (ISMSG(MSG_PASTEPOSITION)) { QPoint point; msg->ReadQPoint("point",&point); PasteObject(point); } } } void Paper::PostMessage(DataStorage *msg,int dest) { if (dest==TO_PAPER) MessageReceived(msg,dest); if (dest==TO_STRING || dest==TO_OPERATOR) { if (GetFocus()) GetFocus()->PostMessage(msg,dest); } if (dest==TO_FRAME) { // Do not pass messages to frame if there is selections if (GetFocus() && Selections()<2) GetFocus()->MessageReceived(msg,dest); else MessageReceived(msg,TO_PAPER); } if (dest==TO_APPCONTROL || dest==TO_MATHCONTROL || dest==TO_MAIN) { AppControl->PostMessage(msg,dest); } } void Paper::keyPressEvent(QKeyEvent *ke) { //Pass Key Codes To Object int ch; int co,code; key_code key; int i; QString uni; Bug("&&& KeyDown"); char std_operator_keys[10]={"+-*/=:<>"}; std_operator_keys[8]=-1; char non_integers[40]={"+-*!/=()[]{}#$%&?^,;:<>|"}; non_integers[24]=-1; // exclude edit keys int specialkeys[40]={Qt::Key_Insert,Qt::Key_Home,Qt::Key_PageUp,Qt::Key_PageDown, Qt::Key_Tab,Qt::Key_Enter,Qt::Key_End,Qt::Key_Space, Qt::Key_Up,Qt::Key_Down,Qt::Key_Return,-1}; int editkeys[40]={Qt::Key_Left,Qt::Key_Right,Qt::Key_Delete,Qt::Key_Backspace,-1}; key.code=0; key.unicode=QString(""); key.number=false; key.spec=false; key.edit=false, key.non=false; key.oper=false; key.spec_num=false; key.integer=false; key.insert_mode=MODE_AUTO; // MODE_ADD_RIGHT m_function_object *func_o; func_o=GetFunctionFocus(); if (func_o) { ch=key.ascii=ke->ascii(); uni=key.unicode=ke->text(); code=key.code=ke->key(); key.modifiers=ke->state(); // KEY TYPES if (ch>='0' && ch<='9') key.number=true; // Number Key if (ch>='a' && ch<='z') key.integer=true; // Integer Key if (ch>='A' && ch<='Z') key.integer=true; if (uni.at(0)>=QChar(0x390) && uni.at(0)<=QChar(0x3D0)) key.integer=true; //if (exclude_i && ch=='i') key.integer=false; //Add: key type text i=co=0; while (co!=(-1)) { co=editkeys[i++]; if (code==co) key.edit=true,co=(-1); // Edit Key } i=co=0; while (co!=(-1)) { co=specialkeys[i++]; if (code==co) key.spec=true,co=(-1); // Special Key } i=co=0; while (co!=(-1)) { co=non_integers[i++]; if (ch==co) key.non=true,co=(-1); // Non integer Key } i=co=0; while (co!=(-1)) { co=std_operator_keys[i++]; if (ch==co) key.oper=true,co=(-1); // Non integer Key } if (ch=='.') key.spec_num=true; bool pass=key.number|key.edit|key.integer|key.non|key.spec|key.spec_num|key.oper; if (code==Qt::Key_Escape) { // Reset Application update with mouseEvent selectposition=false; selectrect=false; selectrect_begin=false; QMouseEvent me( QEvent::MouseMove, mouseposition, 0, 0 ); QApplication::sendEvent( this, &me ); } if (code==Qt::Key_Return) CalculateAll(); if (ke->state()!=Qt::ControlButton && code!=Qt::Key_Control && pass) { func_o->KeyReceived(key); } } }