/* * 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. * */ // ************************************************************************************ // Imaginary Object // ************************************************************************************ #include "Datasymbol.h" #include "AppControl.h" #include "Error.h" #include "Function_object.h" #include "ConfigReader.h" #include "Datastore.h" #include "Object_string.h" void imaginary_object::KeyReceived(key_code key) { key.insert_mode=MODE_AUTO; KeyOutput(key); } imaginary_object::imaginary_object(DataStorage *msg) :m_base_object(msg) { Reset(); Opr=msg->ReadInt("im:op"); letter=msg->ReadQString("im:let"); } DataStorage *imaginary_object::BuildStorage() { DataStorage *msg=m_base_object::BuildStorage(); msg->AddInt("im:op",Opr); msg->AddQString("im:let",letter); return(msg); } math_node imaginary_object::Calculate() { if (Opr==0) { mpl_complex z; z.r=0; z.i=1; return(math_node(z)); } if (Opr==1) { mpl_vector z; z.i=1; z.j=0; z.k=0; return(math_node(z)); } if (Opr==2) { mpl_vector z; z.i=0; z.j=1; z.k=0; return(math_node(z)); } if (Opr==3) { mpl_vector z; z.i=0; z.j=0; z.k=1; return(math_node(z)); } return(0); } imaginary_object::imaginary_object(int op,ApplicationControl *a,m_function_object *o,class string_object *str) :m_base_object(a,o,str) { Reset(); Opr=op; Type=OT_IMAGINARY_OBJECT; Priority=PRIORITY_NONE; SubObject=SUB_NONE; MainType=OMT_DATA; if (Opr==0) letter=AppControl->Prefs->String("ImaginaryUnit"); if (Opr==1) letter=AppControl->Prefs->String("Vector_I"); if (Opr==2) letter=AppControl->Prefs->String("Vector_J"); if (Opr==3) letter=AppControl->Prefs->String("Vector_K"); } QFont imaginary_object::GetFont(int id) { return(string->GetFont(FONT_TYPE_NORMAL)); } QColor imaginary_object::GetColor(int id) { return(AppControl->GetColor(FONT_TYPE_OPERATOR)); } void imaginary_object::CalculateBounds() { old_bounds=bounds; QFontMetrics met(GetFont()); bounds.width=met.width(letter); bounds.ascent=met.ascent(); bounds.descent=met.descent(); } void imaginary_object::MoveTo(QPoint p) { bounds.SetPosition(p); } void imaginary_object::Draw(QPainter *paint) { QColor co=GetColor(); QFont font=GetFont(); paint->setPen(co); paint->setBrush(co); paint->setFont(font); paint->drawText(bounds.Position(),letter); paint->setBrush(QBrush::NoBrush); if (HasFocus() && function->HasFocus()) { paint->setPen(focus_pen); paint->drawRect(bounds.Rect()); } if (Error_flag && (!HasFocus() || !function->HasFocus())) { paint->setPen(error_pen); paint->drawRect(bounds.Rect()); } }