/* * MathPlanner 3.2 - 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. * */ // ************************************************************************************ // Integer Object // ************************************************************************************ #include "Layout.h" #include "AppControl.h" #include "MathHeaders.h" #include "AppControl.h" #include "Header.h" #include "Datasymbol.h" #include "Object_string.h" #include "Function_object.h" #include "Error.h" #include "ServerHeaders.h" #include "Operators.h" #include "Datastore.h" #include integer_object::~integer_object() { UnFocus(); delete let; delete index; } QString integer_object::GetName() { return(name); } void integer_object::Build() { CreateName(); integer_value=AppControl->integer_server->FindInteger(name,function); integer_no=AppControl->integer_server->GetIntegerNo(name,function); if (function->IsMainString(string)) global_value=AppControl->integer_server->FindInteger(name,NULL); else global_value=NULL; } math_node *integer_object::GetIntegerPointer() { return(integer_value); } void integer_object::SendCall(int call) { } int integer_object::GetIntegerNo() { return(integer_no); } void integer_object::SetValue(math_node v) { if (integer_value) *integer_value=v; if (global_value) *global_value=v; value=v; } math_node integer_object::Calculate() { if (integer_value) value = *integer_value; return(value); } void integer_object::Reset() { m_base_object::Reset(); name=""; index_string=""; letter=""; integer_value=NULL; global_value=NULL; } bool integer_object::AutoDeletion() { if ((HasFocus()==false || function->HasFocus()==false) && letter.isEmpty()) return(true); return(false); } integer_object::integer_object(DataStorage *msg) :m_base_object(msg) { Reset(); name=msg->ReadQString("io:NameField"); Type=OT_INTEGER_OBJECT; // This is not nessesery but set anyway ( stored in msg ) MainType=OMT_DATA; Priority=PRIORITY_NONE; SubObject=SUB_NONE; BreakName(); let=new m_display_box(bounds,&letter,1); index=new m_display_box(bounds,&index_string,16); let->SetID(1); index->SetID(2); let->SetParent(this); index->SetParent(this); let->cursor=1; let->c_mode=1; let->CalculateBounds(); index->CalculateBounds(); let->focus=true; } DataStorage *integer_object::BuildStorage() { DataStorage *msg=m_base_object::BuildStorage(); CreateName(); msg->AddQString("io:NameField",name); return(msg); } QFont integer_object::GetFont(int id) { if (id==2) return(string->GetFont(FONT_TYPE_INDEX)); return(string->GetFont(FONT_TYPE_NORMAL)); } QColor integer_object::GetColor(int id) { if (isSymbol() && id==1) return(AppControl->GetColor(FONT_TYPE_SYMBOL)); return(AppControl->GetColor(FONT_TYPE_NORMAL)); } integer_object::integer_object(QString s,ApplicationControl *a,m_function_object *o,string_object *str) :m_base_object(a,o,str) { Reset(); name=s; Type=OT_INTEGER_OBJECT; MainType=OMT_DATA; Priority=PRIORITY_NONE; SubObject=SUB_NONE; BreakName(); let=new m_display_box(bounds,&letter,1); index=new m_display_box(bounds,&index_string,16); let->SetID(1); index->SetID(2); let->SetParent(this); index->SetParent(this); let->cursor=1; let->c_mode=1; let->CalculateBounds(); index->CalculateBounds(); let->focus=true; integer_value=NULL; } void integer_object::BreakName() { symbol=false; if (name.at(0)>255) symbol=true; letter=name.left(1); index_string=name; index_string.remove(0,1); } void integer_object::CreateName() { name=letter; name.append(index_string); } bool integer_object::isSymbol() { if (name.at(0)>255) return(true); return(false); } void integer_object::CalculateBounds() { old_bounds=bounds; let->CalculateBounds(); index->CalculateBounds(); bounds.width=let->bounds.width+index->bounds.width; bounds.ascent=let->bounds.ascent; bounds.descent=index->bounds.descent+let->bounds.descent; } void integer_object::MoveTo(QPoint p) { bounds.SetPosition(p); let->MoveTo(p); index->MoveTo(p+QPoint(let->bounds.width,let->bounds.descent)); } void integer_object::Draw(QPainter *paint) { bool foc; foc=HasFocus(); let->Draw(paint,foc,false); index->Draw(paint,foc,false); if (Error_flag && !foc) { paint->setPen(error_pen); paint->drawRect(bounds.Rect()); } } void integer_object::KeyReceived(key_code key) { // *********************** // KEY DELIVERY HANDLER // *********************** if (key.code==Qt::Key_Down && key.modifiers==0 && let->focus==true) let->focus=false,index->focus=true; else if (key.code==Qt::Key_Up && key.modifiers==0 && index->focus==true) let->focus=true,index->focus=false; else if ((key.edit==true || key.integer==true || key.number==true || index->focus==true)) { // Finaly Pass Message To "Display Box" if (let->focus==true && key.number==false) let->KeyReceived(key); if (let->focus==true && key.number==true) KeyFeedback(key); if (index->focus==true) index->KeyReceived(key); Build(); } else KeyFeedback(key); } void integer_object::KeyFeedback(key_code key) { if (index->focus==true) { if (index->cursor==0) { index->focus=false,let->focus=true; } else { key.insert_mode=MODE_ADD_RIGHT; KeyOutput(key); } } else { if (let->cursor==0) key.insert_mode=MODE_ADD_LEFT; else key.insert_mode=MODE_ADD_RIGHT; KeyOutput(key); } } // ********************************** // value object // ********************************** value_object::~value_object() { UnFocus(); delete let; } void value_object::Build() { value.SetReal(strtod(letter.latin1(),NULL)); } math_node value_object::Calculate() { return(value); } void value_object::Reset() { m_base_object::Reset(); letter=""; } bool value_object::AutoDeletion() { if ((HasFocus()==false || function->HasFocus()==false) && letter.isEmpty()) return(true); return(false); } value_object::value_object(DataStorage *msg) :m_base_object(msg) { Reset(); letter=msg->ReadQString("vo:Letter"); Type=OT_VALUE_OBJECT; MainType=OMT_DATA; Priority=PRIORITY_NONE; SubObject=SUB_NONE; let=new m_display_box(bounds,&letter,25); let->SetParent(this); let->CalculateBounds(); let->focus=true; let->cursor=1; } DataStorage *value_object::BuildStorage() { DataStorage *msg=m_base_object::BuildStorage(); msg->AddQString("vo:Letter",letter); return(msg); } QFont value_object::GetFont(int id) { return(string->GetFont(FONT_TYPE_NORMAL)); } QColor value_object::GetColor(int id) { return(AppControl->GetColor(FONT_TYPE_NORMAL)); } value_object::value_object(QString s,class ApplicationControl *a,m_function_object *o,class string_object *str) :m_base_object(a,o,str) { Reset(); letter=s; Type=OT_VALUE_OBJECT; MainType=OMT_DATA; Priority=PRIORITY_NONE; SubObject=SUB_NONE; let=new m_display_box(bounds,&letter,20); let->SetParent(this); let->CalculateBounds(); let->focus=true; let->cursor=1; } void value_object::CalculateBounds() { old_bounds=bounds; let->CalculateBounds(); bounds=let->bounds; } void value_object::MoveTo(QPoint p) { bounds.SetPosition(p); let->MoveTo(p); } void value_object::Draw(QPainter *paint) { bool foc; foc=HasFocus(); let->Draw(paint,foc,false); if (Error_flag && !foc) { paint->setPen(error_pen); paint->drawRect(bounds.Rect()); } } void value_object::KeyReceived(key_code key) { if (key.spec==false || key.modifiers==0) { if (key.number || key.spec_num || key.edit) { // Finaly Pass Message To "Display Box" if (let->focus==true) let->KeyReceived(key); } else KeyFeedback(key); } else KeyFeedback(key); } void value_object::KeyFeedback(key_code key) { if (let->cursor==0) key.insert_mode=MODE_ADD_LEFT; else key.insert_mode=MODE_ADD_RIGHT; KeyOutput(key); }