/* * MathPlanner 3.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 "Operators.h" #include "AppControl.h" #include "Error.h" #include "Function_object.h" #include "ConfigReader.h" #include "Datastore.h" #include "Object_string.h" math_node par_object::Calculate() { value=Inner->Calculate(); if (Opr==3) { if (value.type==MN_REAL) value.SetReal(fabs(value.mpl.m.R)); else if (value.type==MN_COMPLEX) value.SetReal(mpl_cmodul(value.Complex())); else if (value.type==MN_VECTOR) value.SetReal(mpl_length(value.Vector())); else Error_flag=true,AppControl->AddError(QObject::tr("Value type is not supported")); } return(value); } void par_object::SetFontSize(int id) { Inner->SetFontSize(id); } void par_object::Build() { Inner->Build(); } void par_object::SendCall(int i) { Inner->SendCall(i); } void par_object::InsertString(str_range ran,string_object *st) { st->CopyRange(ran,AppControl->Clipboard); st->Cut(ran,true); Inner->PasteSelection(AppControl->Clipboard); SetFocus(); } void par_object::Init() { Inner->SetFocus(); } void par_object::SeekObject(QPoint p) { if (Inner->Bounds().Rect().contains(p)) { Inner->SeekObject(p); return; } SetFocus(); } bool par_object::AutoDeletion() { if (Inner->IsEmpty() && Inner->HasFocus()==false) return(true); return(false); } par_object::par_object(DataStorage *msg) :m_base_object(msg) { Reset(); pare.Init(AppControl); DataStorage *ar; Type=OT_PARENTHESIS_OBJECT; MainType=OMT_OPERATOR; SubObject=SUB_NONE; Priority=PRIORITY_NONE; Opr=msg->ReadInt("par:type"); Mode=msg->ReadInt("par:mode"); ar=new DataStorage(); msg->ReadDataStorage("par:Inner",ar); Inner=new string_object(ar,AppControl,function); delete ar; function->AddString(Inner); Inner->SetParent(this); Bug("parenthesis unarchived"); } DataStorage *par_object::BuildStorage() { DataStorage *msg=m_base_object::BuildStorage(); msg->AddInt("par:type",Opr); msg->AddInt("par:mode",Mode); DataStorage *ar=Inner->BuildStorage(); msg->AddDataStorage("par:Inner",ar); delete ar; return(msg); } par_object::par_object(int type,ApplicationControl *a,m_function_object *o,class string_object *str) :m_base_object(a,o,str) { Reset(); pare.Init(a); Inner=new string_object(10,AppControl,function); Inner->SetFontSize(string->GetFontSize()); Mode=0; // 0=Auto 1=base 2=center Opr=type; Type=OT_PARENTHESIS_OBJECT; MainType=OMT_OPERATOR; SubObject=SUB_NONE; Priority=PRIORITY_NONE; function->AddString(Inner); Inner->SetParent(this); } par_object::~par_object() { delete Inner; } void par_object::CalculateBounds() { int op=Opr; if (op>3) op=3; Inner->CalculateBounds(); layout_rect lo=Inner->Bounds(); pare.SetSize(lo,op); int cl=AppControl->CenterLine(string); bounds=pare.GetOuterRect(cl,Mode); } void par_object::MoveTo(QPoint p) { pare.SetPosition(p); bounds.SetPosition(p); Inner->MoveTo(pare.GetPosition()); } void par_object::Draw(QPainter *paint) { pare.Draw(paint); Inner->Draw(paint); if (HasFocus() && function->HasFocus()) { paint->setPen(focus_pen); paint->drawRect(bounds.Rect()); } if (Error_flag && !HasFocus()) { paint->setPen(error_pen); paint->drawRect(bounds.Rect()); } } void par_object::KeyReceived(key_code key) { if (key.code==Qt::Key_Down) { if (HasFocus()==true && key.code==Qt::Key_Down) Inner->SetFocus(); } else KeyFeedback(key); } void par_object::KeyFeedback(key_code key) { key.insert_mode=MODE_AUTO; KeyOutput(key); } void par_object::MessageReceived(DataStorage *msg,int rec) { if (rec==TO_OPERATOR) { if (ISMSG(MSG_REMOVE)) { Inner->CopyAll(AppControl->Clipboard); string->MarkForDeletion(string->index); string->RemoveFromString(string->index); string->ChangeIndex(-1); string->PasteSelection(AppControl->Clipboard); } if (ISMSG(MSG_DATA)) Opr=msg->ReadInt("Oper"); if (ISMSG(MSG_SIGNAL)) Mode=msg->ReadInt("Data"); AppControl->CreateControlMenu(this); } } base_object_message *par_object::CreateControlObject() { Bug("########### par_mes created"); return(new par_mes(AppControl)); } par_mes::par_mes(ApplicationControl *a) :base_object_message(a) { hbox=new QHBox(); combo=new QComboBox(hbox); combo->insertItem(QString("(( ))")); combo->insertItem(QString("[[ ]]")); combo->insertItem(QString("{{ }}")); combo->insertItem(QString("Abs")); combo2=new QComboBox(hbox); combo2->insertItem(QObject::tr("Automatic")); combo2->insertItem(QObject::tr("Baseline")); combo2->insertItem(QObject::tr("Center")); but1=new QToolButton(hbox); but1->setText(QObject::tr("Remove")); but1->setAutoRaise(true); connect(but1,SIGNAL(clicked()),this,SLOT(Button())); connect(combo,SIGNAL(activated(int)),this,SLOT(Combo(int))); connect(combo2,SIGNAL(activated(int)),this,SLOT(Combo2(int))); } void par_mes::ReadState(m_base_object *x) { class par_object *t=(class par_object *)x; combo->setCurrentItem(t->Opr); combo2->setCurrentItem(t->Mode); } par_mes::~par_mes() { delete but1; delete combo; delete combo2; delete hbox; } QWidget *par_mes::MainWidget() { return(hbox); } void par_mes::Button() { POSTMESSAGE(MSG_REMOVE,TO_OPERATOR); } void par_mes::Combo(int index) { DataStorage *msg=MESSAGE(MSG_DATA); msg->AddInt("Oper",index); PostMessage(msg,TO_OPERATOR); } void par_mes::Combo2(int index) { DataStorage *msg=MESSAGE(MSG_SIGNAL); msg->AddInt("Data",index); PostMessage(msg,TO_OPERATOR); }