/* * 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. * */ // This program creates mathematical toolbars #include #include "Error.h" #include "Header.h" #include "ConfigReader.h" #include "Extern.h" #include "Datastore.h" #include "MathControl.h" #include "AppControl.h" #include "Math.h" MathControl::MathControl(ApplicationControl *x) :QObject(x->MainWindow()) { AppControl=x; Prefs=x->Prefs; QAccel *a = new QAccel(AppControl->MainWindow()); a->connectItem( a->insertItem(QKeySequence(Prefs->String("AccelPow"))),this,SLOT(TPower())); a->connectItem( a->insertItem(QKeySequence(Prefs->String("AccelSqrt"))),this,SLOT(TSqrt())); a->connectItem( a->insertItem(QKeySequence(Prefs->String("AccelPar"))),this,SLOT(TParA())); a->connectItem( a->insertItem(QKeySequence(Prefs->String("AccelE"))),this,SLOT(Te())); a->connectItem( a->insertItem(QKeySequence(Prefs->String("AccelExp"))),this,SLOT(TExp())); a->connectItem( a->insertItem(QKeySequence(Prefs->String("AccelLn"))),this,SLOT(Tln())); a->connectItem( a->insertItem(QKeySequence(Prefs->String("AccelLog"))),this,SLOT(TLog())); a->connectItem( a->insertItem(QKeySequence(Prefs->String("AccelSin"))),this,SLOT(TSin())); a->connectItem( a->insertItem(QKeySequence(Prefs->String("AccelCos"))),this,SLOT(TCos())); a->connectItem( a->insertItem(QKeySequence(Prefs->String("AccelTan"))),this,SLOT(TTan())); a->connectItem( a->insertItem(QKeySequence(Prefs->String("AccelAsin"))),this,SLOT(TaSin())); a->connectItem( a->insertItem(QKeySequence(Prefs->String("AccelAcos"))),this,SLOT(TaCos())); a->connectItem( a->insertItem(QKeySequence(Prefs->String("AccelAtan"))),this,SLOT(TaTan())); a->connectItem( a->insertItem(QKeySequence(Prefs->String("AccelImag"))),this,SLOT(TImaginary())); a->connectItem( a->insertItem(QKeySequence(Prefs->String("AccelCang"))),this,SLOT(TCAng())); a->connectItem( a->insertItem(QKeySequence(Prefs->String("AccelPiiConstant"))),this,SLOT(TPiiConst())); ControlBar=new QToolBar(AppControl->MainWindow()); OperatorBar=new QToolBar(AppControl->MainWindow()); OperatorBar->setOrientation(Qt::Vertical); AppControl->MainWindow()->moveToolBar(OperatorBar,QMainWindow::Left); ComplexBar=new QToolBar(AppControl->MainWindow()); ComplexBar->setOrientation(Qt::Vertical); AppControl->MainWindow()->moveToolBar(ComplexBar,QMainWindow::Left); if (Prefs->Int("UseGUIfont")) { QFont font(Prefs->String("GUIFont"),Prefs->Int("GUIFontSize")); OperatorBar->setFont(font); ComplexBar->setFont(font); } ControlBarSetup(); CreateOperatorBar(); CreateComplexBar(); } void MathControl::ControlBarSetup() { expmodecombo=new QComboBox(ControlBar); expmodecombo->setMaximumWidth(120); expmodecombo->insertItem(QObject::tr("Automatic")); expmodecombo->insertItem(QObject::tr("Exponent")); expmodecombo->insertItem(QObject::tr("Exp - 3")); connect(expmodecombo,SIGNAL(activated(int)),this,SLOT(Send(int))); digitcount=new QComboBox(ControlBar); digitcount->setMaximumWidth(60); connect(digitcount,SIGNAL(activated(int)),this,SLOT(Send(int))); QString str; int i; for(i=2;i<17;i+=2) digitcount->insertItem(str.setNum(i)); ControlBar->addSeparator(); fontsizecombo=new QComboBox(ControlBar); fontsizecombo->setMaximumWidth(80); fontsizecombo->insertItem(QObject::tr("Normal")); fontsizecombo->insertItem(QObject::tr("Medium")); fontsizecombo->insertItem(QObject::tr("Small")); connect(fontsizecombo,SIGNAL(activated(int)),this,SLOT(SetFont(int))); answercombo=new QComboBox(ControlBar); answercombo->setMaximumWidth(160); answercombo->insertItem(QObject::tr("Component")); answercombo->insertItem(QObject::tr("Complex-Deg")); answercombo->insertItem(QObject::tr("Complex-Rad")); connect(answercombo,SIGNAL(activated(int)),this,SLOT(Send(int))); ControlBar->addSeparator(); rational=new QToolButton(ControlBar); rational->setMaximumWidth(40); rational->setMaximumHeight(20); rational->setToggleButton(true); rational->setText("Rat"); connect(rational,SIGNAL(clicked()),this,SLOT(Send())); ControlBar->addSeparator(); QToolTip::add(expmodecombo,tr("Select exponent mode")); QToolTip::add(fontsizecombo,tr("Select font size")); QToolTip::add(rational,tr("Show the answer in rational mode if possible")); QToolTip::add(digitcount,tr("Set digitcount")); QToolTip::add(answercombo,tr("Set display style of answer (complex only)")); } void MathControl::Send(int) { SendFunctionStatus(); } void MathControl::Send() { SendFunctionStatus(); } void MathControl::SetFont(int x) { DataStorage *msg=MESSAGE(MSG_FONTSIZE); msg->AddInt("size",x); PostMessage(msg,TO_STRING); } void MathControl::MessageReceived(DataStorage *msg,int rec) { if (rec==TO_MATHCONTROL) { if (msg->Contains("digitm")) expmodecombo->setCurrentItem(msg->ReadInt("digitm")); if (msg->Contains("digits")) digitcount->setCurrentItem((msg->ReadInt("digits")-2)/2); if (msg->Contains("size")) fontsizecombo->setCurrentItem(msg->ReadInt("size")); if (msg->Contains("answer")) answercombo->setCurrentItem(msg->ReadInt("answer")); if (msg->Contains("rat")) rational->setOn(msg->ReadInt("rat")); } else PostMessage(msg,rec); } void MathControl::PostMessage(DataStorage *msg,int dest) { AppControl->PostMessage(msg,dest); } void MathControl::SendFunctionStatus() { DataStorage *msg=MESSAGE(MSG_STATUS); msg->AddInt("digitm",expmodecombo->currentItem()); msg->AddInt("digits",2+(digitcount->currentItem()*2)); msg->AddInt("answer",answercombo->currentItem()); msg->AddInt("rat",rational->isOn()); PostMessage(msg,TO_FRAME); } void MathControl::Command(int x) { DataStorage *msg=MESSAGE(MSG_MATHCOMMAND); msg->AddInt("Oper",x); PostMessage(msg,TO_STRING); } void MathControl::CreateOperatorBar() { int i,x=0; for(i=0;i<7;i++) opr_b[x++]=new QToolButton(OperatorBar); OperatorBar->addSeparator(); for(i=0;i<6;i++) opr_b[x++]=new QToolButton(OperatorBar); OperatorBar->addSeparator(); for(i=0;i<6;i++) opr_b[x++]=new QToolButton(OperatorBar); OperatorBar->addSeparator(); for(i=0;i<3;i++) opr_b[x++]=new QToolButton(OperatorBar); OperatorBar->addSeparator(); for(i=0;i<7;i++) opr_b[x++]=new QToolButton(OperatorBar); i=0; opr_b[i]->setText(QObject::tr("Sqrt")); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TSqrt())); opr_b[i]->setText(QObject::tr("Dive")); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TDive())); opr_b[i]->setText(QObject::tr("Power")); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TPower())); opr_b[i]->setText("Log"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TLog())); opr_b[i]->setText("ln"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(Tln())); opr_b[i]->setText("Exp"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TExp())); opr_b[i]->setText("e"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(Te())); opr_b[i]->setText("Sin"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TSin())); opr_b[i]->setText("Cos"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TCos())); opr_b[i]->setText("Tan"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TTan())); opr_b[i]->setText("aSin"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TaSin())); opr_b[i]->setText("aCos"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TaCos())); opr_b[i]->setText("aTan"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TaTan())); opr_b[i]->setText("Min"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TMin())); opr_b[i]->setText("Max"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TMax())); opr_b[i]->setText("Fact"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TFact())); opr_b[i]->setText("Frac"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TFrac())); opr_b[i]->setText("Int"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TInt())); opr_b[i]->setText("Abs"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TAbs())); opr_b[i]->setText("(( ))"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TParA())); opr_b[i]->setText("[[ ]]"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TParB())); opr_b[i]->setText("{{ }}"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TParC())); opr_b[i]->setText("Sigma"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TSigma())); opr_b[i]->setText("Pii"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TPii())); opr_b[i]->setText("Integ"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TInteg())); opr_b[i]->setText("Loop"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TLoop())); opr_b[i]->setText("DefFN1"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TDef())); opr_b[i]->setText("DefFN2"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TDef2())); opr_b[i]->setText("DefFN3"); connect(opr_b[i++],SIGNAL(clicked()),this,SLOT(TDef3())); } void MathControl::CreateComplexBar() { int i,x=0; for(i=0;i<7;i++) opr_c[x++]=new QToolButton(ComplexBar); ComplexBar->addSeparator(); for(i=0;i<5;i++) opr_c[x++]=new QToolButton(ComplexBar); ComplexBar->addSeparator(); for(i=0;i<1;i++) opr_c[x++]=new QToolButton(ComplexBar); i=0; opr_c[i]->setText(" i "); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TImaginary())); opr_c[i]->setText("/__"); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TCAng())); opr_c[i]->setText("arg z"); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TArg())); opr_c[i]->setText("mod z"); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TModul())); opr_c[i]->setText("Z*"); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TConj())); opr_c[i]->setText("Re z"); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TRez())); opr_c[i]->setText("Im z"); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TImz())); opr_c[i]->setText(" i "); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TVectI())); opr_c[i]->setText(" j "); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TVectJ())); opr_c[i]->setText(" k "); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TVectK())); opr_c[i]->setText("len"); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TVLen())); opr_c[i]->setText("cross"); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TVCross())); //opr_c[i]->setText("unit"); opr_c[i]->setEnabled(false); //connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TUnit())); //opr_c[i]->setText("4x4"); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TMatrix())); /* opr_c[i]->setText("nxm"); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TParA())); opr_c[i]->setText("1x3"); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TParB())); opr_c[i]->setText("2x2"); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TParC())); opr_c[i]->setText("3x3"); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TSigma())); opr_c[i]->setText("Det"); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TPii())); opr_c[i]->setText("Trans"); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TDef())); opr_c[i]->setText("Inv"); connect(opr_c[i++],SIGNAL(clicked()),this,SLOT(TSin())); */ } void MathControl::TSqrt() { Command(T_SQRT); } void MathControl::TDive() { Command(T_DIVE); } void MathControl::TPower() { Command(T_POWER); } void MathControl::TLog() { Command(T_LOG); } void MathControl::Tln() { Command(T_LN); } void MathControl::TExp() { Command(T_EXP); } void MathControl::Te() { Command(T_E); } void MathControl::TMin() { Command(T_MIN); } void MathControl::TMax() { Command(T_MAX); } void MathControl::TAbs() { Command(T_ABS); } void MathControl::TParA() { Command(T_PAR_A); } void MathControl::TParB() { Command(T_PAR_B); } void MathControl::TParC() { Command(T_PAR_C); } void MathControl::TSin() { Command(T_SIN); } void MathControl::TCos() { Command(T_COS); } void MathControl::TTan() { Command(T_TAN); } void MathControl::TCot() { Command(T_COT); } void MathControl::TaSin() { Command(T_ASIN); } void MathControl::TaCos() { Command(T_ACOS); } void MathControl::TaTan() { Command(T_ATAN); } void MathControl::TaCot() { Command(T_ACOT); } void MathControl::TFact() { Command(T_FACTORIAL); } void MathControl::TFrac() { Command(T_FRAC); } void MathControl::TInt() { Command(T_INT); } void MathControl::TSigma() { Command(T_SIGMA); } void MathControl::TPii() { Command(T_BIG_PII); } void MathControl::TInteg() { Command(T_INTEGRAL); } void MathControl::TLoop() { Command(T_LOOP); } void MathControl::TDef() { Command(T_FUNCTION_DEF); } void MathControl::TDef2() { Command(T_FUNCTION_DEF_2); } void MathControl::TDef3() { Command(T_FUNCTION_DEF_3); } void MathControl::TVLen() { Command(T_LENGTH); } void MathControl::TVCross() { Command(T_CROSS); } void MathControl::TConj() { Command(T_CONJUGANT); } void MathControl::TUnit() { Command(T_UNIT); } void MathControl::TMatrix() { Command(T_MATRIX); } void MathControl::TPiiConst() { POSTMESSAGE(MSG_PIICONSTANT,TO_MAIN); } // COMPLEX void MathControl::TImaginary() { Command(T_IMAGINARY); } void MathControl::TVectI() { Command(T_VECTOR_I); } void MathControl::TVectJ() { Command(T_VECTOR_J); } void MathControl::TVectK() { Command(T_VECTOR_K); } void MathControl::TArg() { Command(T_ARG_Z); } void MathControl::TModul() { Command(T_MODUL_Z); } void MathControl::TRez() { Command(T_REZ); } void MathControl::TImz() { Command(T_IMZ); } void MathControl::TCAng() { Command(T_COMPLEX_A); }