/* * MathPlanner 3.2.0 - Mathematical design tool. * Copyright(C) 2003 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 "Datasymbol.h" #include "Extern.h" #include // *************************************** // Matrix object // *************************************** math_node matrix_object::Calculate() { math_node r; r.SetReal(0); return(r); } void matrix_object::SeekObject(QPoint p) { int i; for (i=0;iBounds().Rect().contains(p)) { Inner[i]->SeekObject(p); return; } } SetFocus(); } void matrix_object::Init() { Inner[0]->SetFocus(); } void matrix_object::Build() { int i; for (i=0;iBuild(); } void matrix_object::SetFontSize(int id) { int i; for (i=0;iSetFontSize(id); } void matrix_object::SendCall(int c) { int i; for (i=0;iSendCall(c); } void matrix_object::Reset() { m_base_object::Reset(); int i; for (i=0;i<64;i++) Inner[i]=NULL; enable_par=2; curr=0; MatrixLo.Init(AppControl); ParLo.Init(AppControl); } bool matrix_object::AutoDeletion() { return(false); } matrix_object::matrix_object(DataStorage *msg) :m_base_object(msg) { int i; char name[32]; QString str; Type=OT_MATRIX_OBJECT; MainType=OMT_OPERATOR; SubObject=SUB_NONE; Priority=PRIORITY_NONE; Reset(); Row=msg->ReadInt("mx:row"); Col=msg->ReadInt("mx:col"); Cnt=Row*Col; enable_par=msg->ReadInt("mx:ep"); for(i=0;iReadDataStorage(name,ar); Inner[i] = new string_object(ar,AppControl,function); delete ar; function->AddString(Inner[i]); Inner[i]->SetParent(this); } Bug("matrix object unarchived"); } matrix_object::~matrix_object() { int i; for (i=0;i<64;i++) if (Inner[i]) delete Inner[i]; } DataStorage *matrix_object::BuildStorage() { int i; char name[32]; QString str; DataStorage *ar; DataStorage *msg=m_base_object::BuildStorage(); msg->AddInt("mx:ep",enable_par); msg->AddInt("mx:row",Row); msg->AddInt("mx:col",Col); for (i=0;iBuildStorage(); sprintf(name,"mx:in%d",i); msg->AddDataStorage(name,ar); delete ar; } return(msg); } matrix_object::matrix_object(int c,int r,int p,ApplicationControl *a,m_function_object *o,class string_object *str) :m_base_object(a,o,str) { int i; Reset(); enable_par=p; Row=r; Col=c; Cnt=Row*Col; if (Cnt>64) ErrorReport("Matrix Object","Too many slots"),Cnt=1,Row=1,Col=1; Type=OT_MATRIX_OBJECT; MainType=OMT_OPERATOR; SubObject=SUB_NONE; Priority=PRIORITY_NONE; for (i=0;iAddString(Inner[i]); Inner[i]->SetParent(this); } } void matrix_object::ChangeLayout(int c,int r) { int i; if (r<1) r=1; if (c<1) c=1; r=r%64; c=c%64; Row=r; Col=c; Cnt=Row*Col; if (Cnt>64) { ErrorReport("Matrix Object","Too many slots"); Cnt=1,Row=1,Col=1; } function->UnFocusAll(); for(i=0;iAddString(Inner[i]); Inner[i]->SetParent(this); } } /* for(i=Cnt;i<64;i++) { if (Inner[i]) delete Inner[i]; Inner[i]=NULL; } */ } void matrix_object::CalculateBounds() { int i,wi; QFontMetrics met(string->GetFont(FONT_TYPE_OPERATOR)); wi=met.width(","); int cl=AppControl->CenterLine(string); for (i=0;iCalculateBounds(); MatrixLo.SetSize(i,Inner[i]->Bounds()); } ParLo.SetSize(MatrixLo.GetOuterRect(Col,Row,wi)); bounds=ParLo.GetOuterRect(cl,enable_par); } void matrix_object::MoveTo(QPoint p) { int i; bounds.SetPosition(p); ParLo.SetPosition(p); MatrixLo.SetPosition(ParLo.GetPosition()); for (i=0;iMoveTo(MatrixLo.GetPosition(i)); } } void matrix_object::Draw(QPainter *paint) { int i; bool foc; paint->setPen(AppControl->GetColor(FONT_TYPE_NORMAL)); MatrixLo.Draw(paint); ParLo.Draw(paint); for (i=0;iDraw(paint); if (HasFocus() && function->HasFocus()) { paint->setPen(focus_pen); paint->drawRect(bounds.Rect()); } } void matrix_object::KeyReceived(key_code key) { // *********************** // KEY DELIVERY HANDLER // *********************** if (key.code==Qt::Key_Up && key.modifiers==0) { curr--; Inner[curr%Cnt]->SetFocus(); } else if (key.code==Qt::Key_Down && key.modifiers==0) { curr++; Inner[curr%Cnt]->SetFocus(); } else KeyFeedback(key); } void matrix_object::KeyFeedback(key_code key) { key.insert_mode=MODE_AUTO; KeyOutput(key); } void matrix_object::MessageReceived(DataStorage *msg,int rec) { if (rec==TO_OPERATOR) { if (ISMSG(MSG_DATA)) enable_par=msg->ReadInt("Oper"); if (ISMSG(MSG_SIGNAL)) { if (msg->Contains("Col") && msg->Contains("Row")) { ChangeLayout(msg->ReadInt("Col"),msg->ReadInt("Row")); NBug(3,"Colums ",msg->ReadInt("Col")); NBug(3,"Rows ",msg->ReadInt("Row")); } } AppControl->CreateControlMenu(this); } } void matrix_mes::ReadState(m_base_object *x) { class matrix_object *t=(class matrix_object *)x; combo->setCurrentItem(t->enable_par); QString co,ro; co=co.setNum(t->Col); ro=ro.setNum(t->Row); but1->setText(co); but2->setText(ro); } base_object_message *matrix_object::CreateControlObject() { Bug("########### matrix_mes created"); return(new matrix_mes(AppControl)); } matrix_mes::matrix_mes(ApplicationControl *a) :base_object_message(a) { hbox=new QHBox(); combo=new QComboBox(hbox); combo->insertItem(QString("None")); combo->insertItem(QString("Left")); combo->insertItem(QString("Both")); but1=new QLineEdit(hbox); but2=new QLineEdit(hbox); but3=new QToolButton(hbox); but3->setText("Update"); connect(but3,SIGNAL(clicked()),this,SLOT(Button())); connect(combo,SIGNAL(activated(int)),this,SLOT(Combo(int))); } matrix_mes::~matrix_mes() { delete but1; delete but2; delete but3; delete combo; delete hbox; } QWidget *matrix_mes::MainWidget() { return(hbox); } void matrix_mes::Button() { DataStorage *msg=MESSAGE(MSG_SIGNAL); msg->AddInt("Col",but1->text().toInt()); msg->AddInt("Row",but2->text().toInt()); PostMessage(msg,TO_OPERATOR); } void matrix_mes::Combo(int index) { DataStorage *msg=MESSAGE(MSG_DATA); msg->AddInt("Oper",index); PostMessage(msg,TO_OPERATOR); }