/* * 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" #include "Extern.h" math_node complex_object::Calculate() { value=Inner->Calculate(); if (value.type!=MN_REAL) Error_flag=true,AppControl->AddError(QObject::tr("Value type is not supported by this function")); if (Mode==1) value.SetComplex(mpl_cang(value.mpl.m.R)); if (Mode==0) value.SetComplex(mpl_cang(mpl_rad(value.mpl.m.R))); return(value); } void complex_object::SetFontSize(int id) { Inner->SetFontSize(id); } void complex_object::SendCall(int i) { Inner->SendCall(i); } void complex_object::Build() { Inner->Build(); } void complex_object::InsertString(str_range ran,string_object *st) { st->CopyRange(ran,AppControl->Clipboard); st->Cut(ran); Inner->PasteSelection(AppControl->Clipboard); SetFocus(); } void complex_object::Init() { Inner->SetFocus(); } void complex_object::SeekObject(QPoint p) { if (Inner->Bounds().Rect().contains(p)) { Inner->SeekObject(p); return; } SetFocus(); } bool complex_object::AutoDeletion() { if (Inner->IsEmpty() && Inner->HasFocus()==false) return(true); return(false); } complex_object::complex_object(DataStorage *msg) :m_base_object(msg) { Reset(); pare.Init(AppControl); DataStorage *ar; Type=OT_COMPLEX_OBJECT; MainType=OMT_OPERATOR; SubObject=SUB_NONE; Priority=PRIORITY_NONE; Mode=msg->ReadInt("cmp:mode"); ar=new DataStorage(); msg->ReadDataStorage("cmp:Inner",ar); Inner=new string_object(ar,AppControl,function); delete ar; function->AddString(Inner); Inner->SetParent(this); Bug("parenthesis unarchived"); } DataStorage *complex_object::BuildStorage() { DataStorage *msg=m_base_object::BuildStorage(); msg->AddInt("cmp:mode",Mode); DataStorage *ar=Inner->BuildStorage(); msg->AddDataStorage("cmp:Inner",ar); delete ar; return(msg); } complex_object::complex_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=AppControl->Prefs->Int("AngleMode"); Type=OT_COMPLEX_OBJECT; MainType=OMT_OPERATOR; SubObject=SUB_NONE; Priority=PRIORITY_NONE; function->AddString(Inner); Inner->SetParent(this); } complex_object::~complex_object() { delete Inner; } void complex_object::CalculateBounds() { Inner->CalculateBounds(); pare.SetSize(Inner->Bounds()); bounds=pare.GetOuterRect(); } void complex_object::MoveTo(QPoint p) { pare.SetPosition(p); bounds.SetPosition(p); Inner->MoveTo(pare.GetPosition()); } void complex_object::Draw(QPainter *paint) { paint->setPen(AppControl->GetColor(FONT_TYPE_OPERATOR)); paint->setBrush(AppControl->GetColor(FONT_TYPE_OPERATOR)); pare.Draw(paint); paint->setBrush(Qt::NoBrush); 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 complex_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 complex_object::KeyFeedback(key_code key) { key.insert_mode=MODE_AUTO; KeyOutput(key); } void complex_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_DEG)) Mode=0; if (ISMSG(MSG_RAD)) Mode=1; AppControl->CreateControlMenu(this); } } base_object_message *complex_object::CreateControlObject() { Bug("########### comp_mes created"); return(new comp_mes(AppControl)); } comp_mes::comp_mes(ApplicationControl *a) :base_object_message(a) { hbox=new QHBox(); but1=new QToolButton(hbox); but1->setText("Deg"); but1->setAutoRaise(true); but2=new QToolButton(hbox); but2->setText("Rad"); but2->setAutoRaise(true); but3=new QToolButton(hbox); but3->setText(QObject::tr("Remove")); but3->setAutoRaise(true); connect(but1,SIGNAL(clicked()),this,SLOT(Button())); connect(but2,SIGNAL(clicked()),this,SLOT(Button2())); connect(but3,SIGNAL(clicked()),this,SLOT(Button3())); } void comp_mes::ReadState(m_base_object *x) { class complex_object *t=(class complex_object *)x; but1->setEnabled(true),but2->setEnabled(true); if (t->Mode==0) but1->setDown(true),but2->setDown(false); else but1->setDown(false),but2->setDown(true); } comp_mes::~comp_mes() { delete but1; delete but2; delete but3; delete hbox; } QWidget *comp_mes::MainWidget() { return(hbox); } void comp_mes::Button() { POSTMESSAGE(MSG_DEG,TO_OPERATOR); } void comp_mes::Button2() { POSTMESSAGE(MSG_RAD,TO_OPERATOR); } void comp_mes::Button3() { POSTMESSAGE(MSG_REMOVE,TO_OPERATOR); }