/* * 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 dive_object::Calculate() { math_node uv,lv; uv=Upper->Calculate(); lv=Lower->Calculate(); value=mpl_div(uv,lv); return(value); } void dive_object::SendCall(int i) { Upper->SendCall(i); Lower->SendCall(i); } void dive_object::Build() { Upper->Build(); Lower->Build(); } void dive_object::InsertString(str_range ran,string_object *st) { st->CopyRange(ran,AppControl->Clipboard); st->Cut(ran,true); Upper->PasteSelection(AppControl->Clipboard); SetFocus(); mode=1; } void dive_object::Init() { if (mode==0) { Upper->SetFocus(); return; } if (mode==1) { Lower->SetFocus(); return; } SetFocus(); } void dive_object::SeekObject(QPoint p) { if (Upper->Bounds().Rect().contains(p)) { Upper->SeekObject(p); return; } if (Lower->Bounds().Rect().contains(p)) { Lower->SeekObject(p); return; } SetFocus(); } bool dive_object::AutoDeletion() { if (Upper->IsEmpty() && Lower->IsEmpty() && HasFocus()==false && Upper->HasFocus()==false && Lower->HasFocus()==false) return(true); return(false); } dive_object::dive_object(DataStorage *msg) :m_base_object(msg) { Reset(); dive.Init(AppControl); Type=OT_DIVE_OBJECT; MainType=OMT_OPERATOR; Priority=PRIORITY_NONE; SubObject=SUB_NONE; DataStorage *ar; ar=new DataStorage(); msg->ReadDataStorage("dive:Upper",ar); Upper=new string_object(ar,AppControl,function); delete ar; ar=new DataStorage(); msg->ReadDataStorage("dive:Lower",ar); Lower=new string_object(ar,AppControl,function); delete ar; function->AddString(Upper); function->AddString(Lower); Upper->SetParent(this); Lower->SetParent(this); mode=0; Bug("dive unarchived"); } dive_object::~dive_object() { delete Upper; delete Lower; } DataStorage *dive_object::BuildStorage() { DataStorage *ar; DataStorage *msg=m_base_object::BuildStorage(); ar=Upper->BuildStorage(); msg->AddDataStorage("dive:Upper",ar,false); delete ar; ar=Lower->BuildStorage(); msg->AddDataStorage("dive:Lower",ar,false); delete ar; return(msg); } dive_object::dive_object(ApplicationControl *a,m_function_object *o,string_object *str) :m_base_object(a,o,str) { Reset(); dive.Init(a); Type=OT_DIVE_OBJECT; MainType=OMT_OPERATOR; Priority=PRIORITY_NONE; SubObject=SUB_NONE; Upper=new string_object(10,AppControl,function); Lower=new string_object(10,AppControl,function); function->AddString(Upper); function->AddString(Lower); Upper->SetParent(this); Lower->SetParent(this); mode=0; } void dive_object::SetFontSize(int id) { Upper->SetFontSize(id); Lower->SetFontSize(id); } void dive_object::CalculateBounds() { int he; old_bounds=bounds; he=AppControl->CenterLine(string); Upper->CalculateBounds(); Lower->CalculateBounds(); dive.SetSize(0,Upper->Bounds()); dive.SetSize(1,Lower->Bounds()); bounds=dive.GetOuterRect(he); } void dive_object::MoveTo(QPoint p) { dive.SetPosition(p); bounds.SetPosition(p); Upper->MoveTo(dive.GetPosition(0)); Lower->MoveTo(dive.GetPosition(1)); } void dive_object::Draw(QPainter *paint) { bool foc; dive.Draw(paint); Upper->Draw(paint); Lower->Draw(paint); if (HasFocus() && function->HasFocus()) { paint->setPen(focus_pen); paint->drawRect(bounds.Rect()); } foc=(HasFocus() | Upper->HasFocus() | Lower->HasFocus() ) & function->HasFocus(); if (Error_flag && !foc) { paint->setPen(error_pen); paint->drawRect(bounds.Rect()); } } void dive_object::FocusNextObject() { if (curr<=0) curr=1,Upper->SetFocus(); else if (curr>=1) curr=0,Lower->SetFocus(); } void dive_object::KeyReceived(key_code key) { // *********************** // KEY DELIVERY HANDLER // *********************** if (key.code==Qt::Key_Up || key.code==Qt::Key_Down) { if (HasFocus()==true && key.code==Qt::Key_Down) Lower->SetFocus(),curr=0; if (HasFocus()==true && key.code==Qt::Key_Up) Upper->SetFocus(),curr=1; } else KeyFeedback(key); } void dive_object::KeyFeedback(key_code key) { key.insert_mode=MODE_AUTO; KeyOutput(key); } void dive_object::MessageReceived(DataStorage *msg,int rec) { if (rec==TO_OPERATOR) { if (ISMSG(MSG_1)) { Upper->CopyAll(AppControl->Clipboard); string->MarkForDeletion(string->index); string->RemoveFromString(string->index); string->ChangeIndex(-1); string->PasteSelection(AppControl->Clipboard); } if (ISMSG(MSG_2)) { Lower->CopyAll(AppControl->Clipboard); string->MarkForDeletion(string->index); string->RemoveFromString(string->index); string->ChangeIndex(-1); string->PasteSelection(AppControl->Clipboard); } if (ISMSG(MSG_3)) { class string_object *str; str=Lower; Lower=Upper; Upper=str; } } } base_object_message *dive_object::CreateControlObject() { Bug("########### do_mes created"); return(new do_mes(AppControl)); } do_mes::do_mes(ApplicationControl *a) :base_object_message(a) { hbox=new QHBox(); but1=new QToolButton(hbox); but2=new QToolButton(hbox); but3=new QToolButton(hbox); but1->setText("Swap"); but2->setText("Remove Lower"); but3->setText("Remove Upper"); but1->setAutoRaise(true); but2->setAutoRaise(true); but3->setAutoRaise(true); connect(but1,SIGNAL(clicked()),this,SLOT(Button1())); connect(but2,SIGNAL(clicked()),this,SLOT(Button2())); connect(but3,SIGNAL(clicked()),this,SLOT(Button3())); } do_mes::~do_mes() { delete but1; delete but2; delete but3; delete hbox; } QWidget *do_mes::MainWidget() { return(hbox); } void do_mes::Button1() { POSTMESSAGE(MSG_3,TO_OPERATOR); } void do_mes::Button2() { POSTMESSAGE(MSG_1,TO_OPERATOR); } void do_mes::Button3() { POSTMESSAGE(MSG_2,TO_OPERATOR); }