/* * 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. * */ // ************************************************************************************ // Symbol Object // ************************************************************************************ #include "AppControl.h" #include "MathHeaders.h" #include "AppControl.h" #include "Header.h" #include "Datasymbol.h" #include "Object_string.h" #include "Function_object.h" #include "Datastore.h" void symbol_object::KeyReceived(key_code key) { key.insert_mode=MODE_AUTO; KeyOutput(key); } symbol_object::symbol_object(DataStorage *msg) :m_base_object(msg) { Reset(); letter=msg->ReadQString("sy:Letter"); } DataStorage *symbol_object::BuildStorage() { DataStorage *msg=m_base_object::BuildStorage(); msg->AddQString("sy:Letter",letter); return(msg); } symbol_object::symbol_object(QString s,int ty,ApplicationControl *a,m_function_object *o,class string_object *str) :m_base_object(a,o,str) { Reset(); letter=s; Type=ty; Priority=PRIORITY_NONE; SubObject=SUB_NONE; MainType=OMT_STRING_OPERATOR; } void symbol_object::SetSymbol(QString s) { letter=s; } QFont symbol_object::GetFont(int id) { return(string->GetFont(FONT_TYPE_NORMAL)); } QColor symbol_object::GetColor(int id) { return(AppControl->GetColor(FONT_TYPE_OPERATOR)); } void symbol_object::CalculateBounds() { old_bounds=bounds; QFontMetrics met(GetFont()); bounds.width=met.width(letter); bounds.ascent=met.ascent(); bounds.descent=met.descent(); if (letter.contains("_PLOT")) { bounds.width=(bounds.ascent+bounds.descent)/4; } } void symbol_object::MoveTo(QPoint p) { bounds.SetPosition(p); } void symbol_object::Draw(QPainter *paint) { int radi,cl; QColor co=GetColor(); QFont font=GetFont(); paint->setPen(co); paint->setBrush(co); paint->setFont(font); radi=bounds.width/2; if (radi<2) radi=2; cl=AppControl->CenterLine(string); QPoint p=bounds.Position()-QPoint(-(bounds.width*2/5),cl); if (letter.contains("_PLOT")) paint->drawEllipse(p.x(),p.y(),radi,radi); else 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()); } }