/* * MathPlanner 3.1.1 - 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 "Par.h" #include "Layout.h" #include "AppControl.h" #include "Error.h" #include "Gfx.h" #include "Header.h" #include "ConfigReader.h" #include QPoint layout_rect::Position() { return(QPoint(x,y)); } QRect layout_rect::Rect() { return(QRect(x,y-ascent,width,ascent+descent)); } void layout_rect::SetPosition(QPoint pos) { x=pos.x(); y=pos.y(); } exp_layout::exp_layout() { } void exp_layout::Init(ApplicationControl *appc) { margin=appc->Prefs->Int("Exp_margin"); spacing=appc->Prefs->Int("Exp_spacing"); alt=appc->Prefs->Int("Exp_alt"); } void exp_layout::SetSize(int id,layout_rect rect) { inner[id%2]=rect; } layout_rect exp_layout::GetOuterRect() { pos=QPoint(0,0); layout_rect o; int adj=inner[1].descent; if (adj<((inner[0].ascent+inner[0].descent)/2)) adj=0; int al=inner[0].ascent+alt; o.width=margin+margin+inner[0].width+inner[1].width+spacing; o.ascent=inner[1].ascent+adj+al+margin; o.descent=inner[0].descent+margin; inner[0].x=margin; inner[0].y=0; inner[1].x=margin+spacing+inner[0].width; inner[1].y=(-al)-adj; return(o); } layout_rect exp_layout::GetRect(int id) { return(inner[id%2]); } QPoint exp_layout::GetPosition(int id) { return(QPoint(inner[id%2].x,inner[id%2].y)+pos); } void exp_layout::SetPosition(QPoint p) { pos=p; } // *********************************************************** // *********************************************************** // *********************************************************** string_layout::string_layout() { } void string_layout::Init(ApplicationControl *appc) { margin=appc->Prefs->Int("String_margin"); spacing=appc->Prefs->Int("String_spacing"); } void string_layout::SetSize(int id,layout_rect rect) { inner[id%64]=rect; } layout_rect string_layout::GetOuterRect(int count) { layout_rect o; int i; int as,de; o.width=2*margin; pos=QPoint(0,0); o.ascent=0, o.descent=0; for (i=0;i1 && i<(count-1)) o.width+=spacing; as=inner[i].ascent+margin; de=inner[i].descent+margin; if (as>o.ascent) o.ascent=as; if (de>o.descent) o.descent=de; if (i>0) inner[i].x=inner[i-1].x+inner[i-1].width+spacing; else inner[i].x=margin; inner[i].y=0; } return(o); } layout_rect string_layout::GetRect(int id) { return(inner[id%64]); } QPoint string_layout::GetPosition(int id) { return(QPoint(inner[id%64].x,inner[id%64].y)+pos); } void string_layout::SetPosition(QPoint p) { pos=p; } // *********************************************************** // *********************************************************** // *********************************************************** text_layout::text_layout() { } void text_layout::Init(ApplicationControl *appc) { margin=appc->Prefs->Int("Text_margin"); } layout_rect text_layout::GetOuterRect(QFont font,QString string,bool bound) { layout_rect o; text=string; pos=QPoint(0,0); QFontMetrics met(font); o.ascent=met.ascent()+margin; o.descent=met.descent()+margin; o.width=0; ypos=0; xpos=0; if (!string.isEmpty()) { if (bound) o.width=met.boundingRect(string).width(); else o.width=met.width(string); o.width+=2*margin; xpos=margin; } return(o); } void text_layout::Draw(QPainter *paint) { paint->drawText(xpos+pos.x(),ypos+pos.y(),text); } void text_layout::SetPosition(QPoint p) { pos=p; } // *********************************************************** // *********************************************************** // *********************************************************** par_layout::par_layout() { } void par_layout::Draw(QPainter *paint) { int aw; aw=inner.ascent+inner.descent; draw_par->Draw(id,aw,0,pos+QPoint(para.x,para.y),paint); draw_par->Draw(id,aw,1,pos+QPoint(parb.x,parb.y),paint); } void par_layout::Init(ApplicationControl *appc) { margin=appc->Prefs->Int("Par_top_margin"); spacing=appc->Prefs->Int("Par_spacing"); alt=appc->Prefs->Int("Par_grap"); side=appc->Prefs->Int("Par_side_margin"); AppControl=appc; } void par_layout::SetSize(layout_rect rect,int i) { id=i; inner=rect; } layout_rect par_layout::GetOuterRect(int cl,int mode) { int as,de,adj; layout_rect o; pos=QPoint(0,0); //int al=((inner.ascent*alt)/100); int aw=inner.ascent+inner.descent; int cp=inner.ascent-(aw/2); if (mode==0) if (abs(cl-cp)>alt) mode=2; else mode=1; if (mode==2) { adj=(aw/2)-inner.ascent+cl; para=draw_par->Bounds(id,aw); parb=para; as=0; //para.ascent; de=0; //para.descent; if (as<(inner.ascent+adj)) as=inner.ascent+adj; if (de<(inner.descent-adj)) de=inner.descent-adj; o.ascent=as+margin; o.descent=de+margin; o.width=(2*(side+spacing+para.width))+inner.width; inner.x=side+spacing+para.width; inner.y=-adj; } if (mode==1) { para=draw_par->Bounds(id,aw); parb=para; as=0; //para.ascent; de=0; //para.descent; if (asPrefs->Int("Dive_margin"); spacing=appc->Prefs->Int("Dive_spacing"); alt=appc->Prefs->Int("Dive_space"); width=appc->Prefs->Int("Line_width"); AppControl=appc; } void dive_layout::SetSize(int id,layout_rect rect) { inner[id%2]=rect; } layout_rect dive_layout::GetOuterRect(int al) { int centu=0,centl=0; pos=QPoint(0,0); layout_rect o; adjust=al; o.width=inner[0].width; if (o.widthGetColor(FONT_TYPE_OPERATOR); int y=width/2; paint->fillRect(pos.x()+margin+spacing,pos.y()-y-adjust,wid,width,QBrush(col)); } // *********************************************************** // *********************************************************** // *********************************************************** complex_layout::complex_layout() { } void complex_layout::Draw(QPainter *paint) { layout_rect rect=inner; rect.SetPosition(QPoint(-in+xpos,in)+pos); rect.width+=in; paint->setPen(AppControl->GetColor(FONT_TYPE_OPERATOR)); draw_complex_angle(rect.Rect(),paint,width); } void complex_layout::Init(ApplicationControl *appc) { margin=appc->Prefs->Int("Cmp_margin"); spacing=appc->Prefs->Int("Cmp_spacing"); in=appc->Prefs->Int("Cmp_inner"); width=appc->Prefs->Int("Line_width"); AppControl=appc; } void complex_layout::SetSize(layout_rect rect) { inner=rect; } layout_rect complex_layout::GetOuterRect() { layout_rect o; QRect siz; inner.SetPosition(QPoint(0,0)); complex_angle_size(inner.Rect(),&siz); o.ascent=inner.ascent+margin; o.descent=siz.height()-inner.ascent+margin+in; o.width=siz.width()+2*margin+spacing+in; xpos=(siz.width()-inner.width)+spacing+margin+in; return(o); } layout_rect complex_layout::GetRect() { return(inner); } QPoint complex_layout::GetPosition() { return(QPoint(xpos,0)+pos); } void complex_layout::SetPosition(QPoint p) { pos=p; } // *********************************************************** // *********************************************************** // *********************************************************** root_layout::root_layout() { } void root_layout::Draw(QPainter *paint) { layout_rect rect=inner[0]; rect.SetPosition(QPoint(-in+inner[0].x,inner[0].y)+pos); rect.width+=in; rect.ascent+=in; paint->setPen(AppControl->GetColor(FONT_TYPE_OPERATOR)); draw_square_root(rect.Rect(),paint,width); } void root_layout::Init(ApplicationControl *appc) { margin=appc->Prefs->Int("Sqrt_margin"); spacing=appc->Prefs->Int("Sqrt_spacing"); in=appc->Prefs->Int("Sqrt_inner"); width=appc->Prefs->Int("Line_width"); AppControl=appc; } void root_layout::SetSize(int id,layout_rect rect) { inner[id%2]=rect; } layout_rect root_layout::GetOuterRect() { layout_rect o; int width,height,adj,h,wi,dp,he,po; inner[0].SetPosition(QPoint(1000,1000)); inner[1].SetPosition(QPoint(0,0)); square_root_size(inner[0].Rect(),&height,&adj,&width,&he,&dp,&po); if (inner[1].width>dp) wi=inner[1].width-dp; else wi=0; po+=wi; dp+=wi; o.descent=(adj-inner[0].ascent); o.ascent=height-o.descent; o.width=wi+width+2*margin+spacing+in; h=(he+inner[1].ascent+inner[1].descent)-o.descent+in; if (h>o.ascent) o.ascent=h; xpos=po+spacing+margin+in; inner[0].SetPosition(QPoint(xpos,0)); //inner[1].SetPosition(QPoint(dp-inner[1].width+spacing+margin,o.descent-he-inner[1].descent-in)); inner[1].SetPosition(QPoint(spacing+margin,o.descent-he-inner[1].descent-in)); o.ascent+=(margin+in); o.descent+=margin; return(o); } layout_rect root_layout::GetRect(int id) { return(inner[id%2]); } QPoint root_layout::GetPosition(int id) { return(QPoint(inner[id%2].x,inner[id%2].y)+pos); } void root_layout::SetPosition(QPoint p) { pos=p; } // *********************************************************** // *********************************************************** // *********************************************************** matrix_layout::matrix_layout() { } void matrix_layout::Init(ApplicationControl *appc) { margin=appc->Prefs->Int("String_margin"); spacing=appc->Prefs->Int("String_spacing"); } // Set slots from top left to right void matrix_layout::SetSize(int id,layout_rect rect) { inner[id%64]=rect; } layout_rect matrix_layout::GetOuterRect(int x,int y,int pw) { layout_rect o; int i,k,po=0,ypos; int as,de,wi,width,height; x=x%64; y=y%64; if (x<1) x=1; if (y<1) y=1; // Setup global data rows=y; cols=x; point_width=pw; // Reset for (k=0;krow_asc[k]) row_asc[k]=as; if (de>row_des[k]) row_des[k]=de; if (wi>col_wid[i]) col_wid[i]=wi; po++; } } // Calculate total height and width for (k=0,height=0;k0) { for (k=0;kdrawText(QPoint(xp,yp)+pos,","); } } } } // *********************************************************** // *********************************************************** // *********************************************************** sigma_layout::sigma_layout() { } void sigma_layout::Draw(QPainter *paint) { int aw=inner[0].ascent+inner[0].descent; draw_sigma->Draw(id,aw,pos+QPoint(para.x,para.y),paint); } void sigma_layout::Init(ApplicationControl *appc) { margin=appc->Prefs->Int("Sigma_margin"); spacing=appc->Prefs->Int("Sigma_spacing"); in=appc->Prefs->Int("Sigma_top_spacing"); base=appc->Prefs->Int("Sigma_grap"); AppControl=appc; } void sigma_layout::SetSize(int id,layout_rect rect) { inner[id%3]=rect; } layout_rect sigma_layout::GetOuterRect(int i,int cl) { int wi,wii; layout_rect o; pos=QPoint(0,0); id=i; int aw=inner[0].ascent+inner[0].descent; int adj=inner[0].ascent-(aw/2); int bc=cl-adj; //if (bc<=in && base) bc=0,cl=adj; if (bc>(-base) && bcBounds(id,aw); wi=(para.width/2); int up=inner[1].width/2; int dn=inner[2].width/2; int hei=(para.ascent+para.descent)+2*in; if (aw>hei && (up>(wi+spacing) || dn>(wi+spacing))) hei=aw; if (up>wi) wi=up; if (dn>wi) wi=dn; wi+=margin; wii=(para.width/2)+spacing+inner[0].width; if (up>wii) wii=up; if (dn>wii) wii=dn; wii+=margin; o.ascent=hei/2+margin+inner[1].ascent+inner[1].descent+cl; o.descent=hei/2+margin+inner[2].ascent+inner[2].descent-cl; o.width=wi+wii; inner[0].x=spacing+wi+(para.width/2); inner[0].y=-bc; inner[1].x=wi-up; inner[1].y=-(hei/2+cl+inner[1].descent); inner[2].x=wi-dn; inner[2].y=hei/2-cl+inner[2].ascent; para.x=wi-(para.width/2); para.y=-cl; return(o); } layout_rect sigma_layout::GetRect(int id) { return(inner[id%3]); } QPoint sigma_layout::GetPosition(int id) { return(QPoint(inner[id%3].x,inner[id%3].y)+pos); } void sigma_layout::SetPosition(QPoint p) { pos=p; } // *********************************************************** // *********************************************************** // *********************************************************** linepar_layout::linepar_layout() { } void linepar_layout::Draw(QPainter *paint) { orect.SetPosition(pos); QRect rect=orect.Rect(); QPoint a=rect.topLeft(); QPoint b=rect.topRight(); he=rect.height(); int m=margin; paint->setPen(AppControl->GetColor(FONT_TYPE_OPERATOR)); if (mode>0) { paint->moveTo(a.x()+5+m,a.y()+m); paint->lineTo(a.x()+m,a.y()+m); paint->lineTo(a.x()+m,a.y()+he-m); paint->lineTo(a.x()+5+m,a.y()+he-m); } if (mode>1) { paint->moveTo(b.x()-5-m,b.y()+m); paint->lineTo(b.x()-m,b.y()+m); paint->lineTo(b.x()-m,b.y()+he-m); paint->lineTo(b.x()-5-m,b.y()+he-m); } } void linepar_layout::Init(ApplicationControl *appc) { margin=appc->Prefs->Int("Matrix_margin"); spacing=appc->Prefs->Int("Matrix_spacing"); AppControl=appc; } void linepar_layout::SetSize(layout_rect rect) { inner=rect; } layout_rect linepar_layout::GetOuterRect(int cl,int m) { layout_rect o; int adj; mode=m; int aw=inner.ascent+inner.descent; adj=(aw/2)-inner.ascent+cl; int as=inner.ascent+adj; int de=inner.descent-adj; o.ascent=as+margin; o.descent=de+margin; o.width=(2*(spacing+margin))+inner.width; inner.x=margin+spacing; inner.y=-adj; orect=o; return(o); } layout_rect linepar_layout::GetRect() { return(inner); } QPoint linepar_layout::GetPosition() { return(QPoint(inner.x,inner.y)+pos); } void linepar_layout::SetPosition(QPoint p) { pos=p; }