/* * MathPlanner 3.1 - 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 "AppControl.h" #include "Paper.h" #include "Datastore.h" #include "Frame.h" #include "Error.h" MathFrame::MathFrame(DataStorage *msg,ApplicationControl *a,Paper *p) :QObject() { AppControl=a; paper=p; active=false; multi=false; ObjectType=msg->ReadInt("Object"); msg->ReadQRect("Bounds",&bounds); msg->ReadQColor("MF:C",&color); ascent=msg->ReadInt("MF:A"); frame_enabled=msg->ReadInt("MF:FE"); resize_enabled=msg->ReadInt("MF:RE"); old_bounds=bounds; } MathFrame::~MathFrame() { } void MathFrame::MessageReceived(DataStorage *msg,int rec) { if (rec==TO_FRAME) { if (ISMSG(MSG_PASTE)) PostMessage(msg,TO_PAPER); if (ISMSG(MSG_COPY)) PostMessage(msg,TO_PAPER); if (ISMSG(MSG_CUT)) PostMessage(msg,TO_PAPER); } } void MathFrame::PostMessage(DataStorage *msg,int dest) { if (dest==TO_PAPER) paper->MessageReceived(msg,dest); else if (dest==TO_APPCONTROL || dest==TO_MATHCONTROL || dest==TO_MAIN) AppControl->PostMessage(msg,dest); } MathWindow *MathFrame::MainWindow() { return(AppControl->MainWindow()); } void MathFrame::Selected() { } void MathFrame::Activate() { active=true; } void MathFrame::DeActivate() { active=false; } bool MathFrame::IsActive() { return(active); } DataStorage *MathFrame::BuildStorage() { DataStorage *msg=new DataStorage(); msg->AddInt("Object",ObjectType); msg->AddQRect("Bounds",&bounds); msg->AddQColor("MF:C",color); msg->AddInt("MF:FE",(int)frame_enabled); msg->AddInt("MF:RE",(int)resize_enabled); msg->AddInt("MF:A",ascent); return(msg); } MathFrame::MathFrame(int type,QRect b,ApplicationControl *a,Paper *p,int as) :QObject() { ObjectType=type; old_bounds=bounds=b; AppControl=a; paper=p; ascent=as; active=false; multi=false; } int MathFrame::Type() { return(ObjectType); } QRect MathFrame::Bounds(bool old) { if (old) return(bounds|old_bounds); return(bounds); } void MathFrame::ResetBounds() { old_bounds=bounds; } void MathFrame::Enable(bool f,bool r,bool a) { frame_enabled=f; resize_enabled=r; always=a; } bool MathFrame::IsEmpty() { return(empty); } void MathFrame::SetColor(QColor c) { color=c; } void MathFrame::SetBounds(QRect b,int as) { old_bounds=bounds|old_bounds; QPoint pos=Position(); // Save the position first bounds=b; ascent=as; resizerect.setSize(QSize(10,10)); resizerect.moveBottomRight(bounds.bottomRight()); MoveTo(pos); // Restore position } void MathFrame::MoveTo(QPoint p) { old_bounds=bounds|old_bounds; bounds.moveTopLeft(p-QPoint(0,ascent)); resizerect.setSize(QSize(10,10)); resizerect.moveBottomRight(bounds.bottomRight()); } QPoint MathFrame::Position() { return(bounds.topLeft()+QPoint(0,ascent)); } int MathFrame::Ascent() { return(ascent); } void MathFrame::CalculateBounds() { old_bounds=bounds|old_bounds; resizerect.setSize(QSize(10,10)); resizerect.moveBottomRight(bounds.bottomRight()); } void MathFrame::MousePressed(QPoint p) { } bool MathFrame::IsInBounds(QPoint p) { return(bounds.contains(p)); } bool MathFrame::IsInResizeArea(QPoint p) { if (resize_enabled) { resizerect.setSize(QSize(10,10)); resizerect.moveBottomRight(bounds.bottomRight()); return(resizerect.contains(p)); } return(false); } bool MathFrame::HasFocus() { if (paper->GetFocus()==this) return(true); return(false); } void MathFrame::UnFocus() { paper->UnFocusCurrentFunction(); } void MathFrame::SetFocus() { paper->FocusFunction(this); } void MathFrame::Draw(QPainter *paint) { QPen pen(color,0,Qt::DotLine); if (frame_enabled || multi) { paint->setPen(pen); IsInResizeArea(QPoint(0,0)); if (HasFocus() || always || multi) paint->drawRect(bounds); if (HasFocus() && resize_enabled) paint->drawRect(resizerect); } }