/* * MathPlanner 3.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. * */ // UPDATES: SetupFonts() Must be called after document/setup changes #include #include "AppControl.h" #include "Error.h" #include "Par.h" #include "Header.h" #include "Object_string.h" #include "Math.h" #include "ConfigReader.h" #include "ServerHeaders.h" #include "Setup.h" #include "Extern.h" #include "Datastore.h" #include "FrameObjects.h" #include "MathControl.h" #include class draw_par_class *draw_par; class draw_sigma_class *draw_sigma; class DataStorage PublicMsg; void ApplicationControl::CreateControlMenu(m_base_object *obj) { Bug("################ Control Menu Called"); int ot=0; if (obj) ot=obj->Type; base_object_message *b=base_om[ot]; if (b==NULL && obj) { b=base_om[ot]=obj->CreateControlObject(); if (b) wstack->addWidget(b->MainWidget(),ot); } if (b && obj) b->ReadState(obj); else ot=0; // Call Null Widget wstack->raiseWidget(ot); QSize size=wstack->visibleWidget()->sizeHint(); wstack->setFixedSize(size); ObjectBar->updateGeometry(); Bug("###### Control Menu Ends"); } void ApplicationControl::CreateFunctionMenu(QStringList list) { if (function_server) { FunctionMenu->clear(); for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { FunctionMenu->insertItem(*it); } } } void ApplicationControl::DocumentChanged(bool f) { documentchanged=f; } bool ApplicationControl::IsChanged() { return(documentchanged); } ApplicationControl::ApplicationControl(MathWindow *p) :QObject(p) { int i; SetModeFlag(MPL_MF_ALPHA,true); SetModeFlag(MPL_MF_BW,false); documentchanged=true; for(i=0;i<50;i++) base_om[i]=NULL; parent=p; Prefs=new config_file_reader(); create_table_of_numbers(500); integer_server=new int_server(); function_server=new function_serv(); TextControlBar=new TextControl(this); MathControlBar=new MathControl(this); Clipboard=new DataStorage(); Setup=new setup(parent,Prefs,this); Unit=new mpl_unit(Prefs); SetupFonts(); draw_par=new draw_par_class(); draw_par->Init(0,QString("/Par.xpm"),Prefs->Color("PaperColor"),Prefs->Color("OperatorFontColor"),Prefs->Int("Par_size_factor")); draw_par->Init(1,QString("/ParB.xpm"),Prefs->Color("PaperColor"),Prefs->Color("OperatorFontColor"),Prefs->Int("Par_size_factor")); draw_par->Init(2,QString("/ParC.xpm"),Prefs->Color("PaperColor"),Prefs->Color("OperatorFontColor"),Prefs->Int("Par_size_factor")); draw_par->Init(3,QString("/ParD.xpm"),Prefs->Color("PaperColor"),Prefs->Color("OperatorFontColor"),Prefs->Int("Par_size_factor")); draw_sigma=new draw_sigma_class(); draw_sigma->Init(0,QString("/Sigma.xpm"),Prefs->Color("PaperColor"),Prefs->Color("OperatorFontColor"),Prefs->Int("Sigma_size_factor")); draw_sigma->Init(1,QString("/Pii.xpm"),Prefs->Color("PaperColor"),Prefs->Color("OperatorFontColor"),Prefs->Int("Sigma_size_factor")); draw_sigma->Init(2,QString("/Integ.xpm"),Prefs->Color("PaperColor"),Prefs->Color("OperatorFontColor"),Prefs->Int("Sigma_size_factor")); draw_sigma->Init(3,QString("/Loop.xpm"),Prefs->Color("PaperColor"),Prefs->Color("OperatorFontColor"),Prefs->Int("Sigma_size_factor")); FunctionMenu=new QPopupMenu(); connect(FunctionMenu,SIGNAL(activated(int)),this,SLOT(SetFunction(int))); ObjectBar=new QToolBar(parent); ObjectBar->setMinimumWidth(44); ObjectBar->setMaximumWidth(1000); wstack=new QWidgetStack(ObjectBar); wstack->setMinimumWidth(44); wstack->setMaximumWidth(1000); QWidget *wi=new QWidget(parent); wi->setFixedHeight(22); wi->setFixedWidth(22); wstack->addWidget(wi,0); // Add Null Widget } MathWindow *ApplicationControl::MainWindow() { return(parent); } QPixmap ApplicationControl::LoadIcon(QString name) { QPixmap pm; QString path=Prefs->String("KDEIconTheme"); if (pm.load(kde_dir+"/share/icons/"+path+"/22x22/actions/"+name+".png")) return(pm); if (pm.load(kde_dir+"/share/icons/"+path+"/32x32/actions/"+name+".png")) return(pm); if (pm.load(home_path+"/.kde/share/icons/"+path+"/22x22/actions/"+name+".png")) return(pm); if (pm.load(home_path+"/.kde/share/icons/"+path+"/32x32/actions/"+name+".png")) return(pm); if (pm.load(kde_dir+"/share/icons/hicolor/22x22/actions/"+name+".png")) return(pm); if (pm.load(kde_dir+"/share/icons/hicolor/32x32/actions/"+name+".png")) return(pm); if (pm.load("/opt/kde3/share/icons/hicolor/22x22/actions/"+name+".png")) return(pm); if (pm.load("/opt/kde3/share/icons/hicolor/32x32/actions/"+name+".png")) return(pm); if (pm.load(image_path+"/"+name+".png")) return(pm); if (pm.load(kde_dir+"/share/icons/"+path+"/22x22/apps/"+name+".png")) return(pm); if (pm.load(kde_dir+"/share/icons/"+path+"/32x32/apps/"+name+".png")) return(pm); if (pm.load(kde_dir+"/share/icons/hicolor/22x22/apps/"+name+".png")) return(pm); if (pm.load(kde_dir+"/share/icons/hicolor/32x32/apps/"+name+".png")) return(pm); ErrorReport("Icon Not Found",name+".png"); return(pm); } void ApplicationControl::SetupFonts() { QFont::insertSubstitution(Prefs->String("BaseFont"),Prefs->String("SymbolFont")); font[FONT_TYPE_NORMAL]=QFont(Prefs->String("BaseFont"),12,Prefs->Int("BaseFontWeight"),(bool)Prefs->Int("BaseFontItalic")); font[FONT_TYPE_OPERATOR]=QFont(Prefs->String("OperatorFont"),12,Prefs->Int("OperatorFontWeight"),(bool)Prefs->Int("OperatorFontItalic")); font[FONT_TYPE_INDEX]=QFont(Prefs->String("IndexFont"),12,Prefs->Int("IndexFontWeight"),(bool)Prefs->Int("IndexFontItalic")); font[FONT_TYPE_FUNCTION]=QFont(Prefs->String("FunctionFont"),12,Prefs->Int("FunctionFontWeight"),(bool)Prefs->Int("FunctionFontItalic")); bool fonterror=false; QString re,ree,act; QFontInfo info(font[FONT_TYPE_NORMAL]); re=font[FONT_TYPE_NORMAL].family().lower(); if (info.family().lower()!=re) fonterror=true,ree=re,act=info.family().lower(); QFontInfo info2(font[FONT_TYPE_OPERATOR]); re=font[FONT_TYPE_OPERATOR].family().lower(); if (info2.family().lower()!=re) fonterror=true,ree=re,act=info2.family().lower(); QFontInfo info3(font[FONT_TYPE_INDEX]); re=font[FONT_TYPE_INDEX].family().lower(); if (info3.family().lower()!=re) fonterror=true,ree=re,act=info3.family().lower(); QFontInfo info4(font[FONT_TYPE_FUNCTION]); re=font[FONT_TYPE_FUNCTION].family().lower(); if (info4.family().lower()!=re) fonterror=true,ree=re,act=info4.family().lower(); if (fonterror) { QMessageBox::critical( 0, "Font Setup", QObject::tr("Requested font ("+ree+") not found. Edit the preferences\n\n Replaced with ("+act+")")+ QObject::tr("\n\nApplication will now continue." )); } color[FONT_TYPE_NORMAL]=Prefs->Color("BaseFontColor"); color[FONT_TYPE_SYMBOL]=Prefs->Color("SymbolFontColor"); color[FONT_TYPE_OPERATOR]=Prefs->Color("OperatorFontColor"); color[FONT_TYPE_INDEX]=Prefs->Color("IndexFontColor"); color[FONT_TYPE_FUNCTION]=Prefs->Color("FunctionFontColor"); centerline=Prefs->Int("BaseFontCenterLine"); fontsize[FONT_SIZE_NORMAL]=Prefs->Int("FontSizeNormal"); fontsize[FONT_SIZE_SMALL]=Prefs->Int("FontSizeSmall"); fontsize[FONT_SIZE_INDEX]=Prefs->Int("FontSizeIndex"); fontsize[FONT_SIZE_INDEX_SMALL]=Prefs->Int("FontSizeIndexSmall"); fontsize[FONT_SIZE_EXPONENT_SMALL]=Prefs->Int("FontSizeExpSmall"); #ifdef BUG_REPORT QFontDatabase db; QStringList list2; QStringList::Iterator it2; QStringList list=db.families(); for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { Bug( (char *)(*it).latin1() ); } #endif } int ApplicationControl::CenterLine(string_object *str) { QFont f=str->GetFont(FONT_TYPE_NORMAL); QFontMetrics met(f); int he=met.ascent()*centerline/100; return(he); } void ApplicationControl::SetFunction(int id) { DataStorage *msg=MESSAGE(MSG_MATHCOMMAND); msg->AddInt("Oper",T_FUNCTION); msg->AddQString("func",FunctionMenu->text(id)); PostMessage(msg,TO_STRING); } void ApplicationControl::AddError(QString er) { parent->statusBar()->message(er); } void ApplicationControl::SetModeFlag(int m,bool bw) { mode_flag[m]=bw; } bool ApplicationControl::GetModeFlag(int m) { return(mode_flag[m]); } QColor ApplicationControl::GetColor(int id) { if (mode_flag[MPL_MF_BW]) return(QColor(0,0,0)); return(color[id]); } QFont ApplicationControl::GetFont(int id) { if (id==FONT_TYPE_SYMBOL) ErrorReport("App::GetFont","Illegal request"); return(font[id]); } int ApplicationControl::GetFontSize(int id) { return(fontsize[id]); } void ApplicationControl::MessageReceived(DataStorage *msg,int rec) { if (ISMSG(MSG_CONFIGURATION)) SetupFonts(); } void ApplicationControl::PostMessage(DataStorage *msg,int dest) { if (dest==TO_MATHCONTROL) MathControlBar->MessageReceived(msg,dest); else if (dest==TO_APPCONTROL) MessageReceived(msg,dest); else if (dest==TO_MAIN) MainWindow()->MessageReceived(msg,dest); else MainWindow()->PostMessage(msg,dest); }