Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

proposition.cpp

Go to the documentation of this file.
00001 /*
00002  Modular Psi - A graph tracker of the Parapsychologcal scientific development
00003  Copyright (C) 2005 Leonardo Stern
00004 
00005  This program is free software; you can redistribute it and/or modify it under
00006  the terms of the Common Public License Version 1.0 or (at your option) any later version.
00007 
00008  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
00009  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00010  See the Common Public License for more details.
00011 
00012  You should have received a copy of the Common Public License along with this program;
00013 */
00014 
00015 #include "proposition.hpp"
00016 #include "propositiongraph.hpp"
00017 #include "edge.hpp"
00018 #include "node.hpp"
00019 #include "nodelist.hpp"
00020 #include "edgelist.hpp"
00021 #include "categorylist.hpp"
00022 #include "utils.hpp"
00023 
00024 #include <qpainter.h>
00025 #include <qstring.h>
00026 
00027 Proposition::Proposition ( QWidget *parent, const char* name, WFlags f )  
00028     : Node ( parent, name, f  )
00029 {
00030     init();
00031 }
00032 
00033 Proposition::~Proposition()
00034 {
00035     // NOOP
00036 }
00037 
00038 void Proposition::init()
00039 {
00040     setPublicName(" ");
00041     setDescription(" ");
00042     propFillColor = COLOR_PROP_DEFAULT;
00043     borderColor = COLOR_PROP_BORDER;
00044     fillColor = propFillColor;
00045     textColor = COLOR_PROP_BORDER;
00046 }
00047 
00048 void Proposition::setTrust(float confianca)
00049 {
00050     p_trust = confianca;
00051     setChanged(true);
00052     fillColor = trust2rgb (confianca);
00053     propFillColor = fillColor;
00054     if (confianca > 0.8 || (confianca > 0 && confianca < 0.3) )
00055         textColor = COLOR_TEXT_ALTERNATE;
00056     else
00057         textColor = COLOR_PROP_BORDER;
00058     repaint();
00059 }
00060 
00061 
00062 void Proposition::setCategory(QString newcat) 
00063 {
00064         if (graph->categories->operator[](newcat))
00065                 cat = graph->categories->operator[](newcat); 
00066         else
00067                 cat = graph->categories->operator[]("Not Categorized");
00068         borderColor = cat->color();
00069 }
00070 
00071 void Proposition::setCategoryId(QString newcat) 
00072 {
00073         QString realname;
00074         realname = "Not Categorized";
00075         QDictIterator<Category> ix( *graph->categories );
00076     for( ; ix.current(); ++ix )
00077     {
00078         if (newcat == ix.current()->id())
00079                 realname = ix.current()->name();
00080     }
00081     setCategory(realname);
00082 }
00083 
00084 void Proposition::setReferences(QString newReferences)
00085 {
00086         p_references = newReferences;
00087 }
00088 
00089 Edge * Proposition::connect(Proposition* destino, float confianca)
00090 {
00091     Edge* e = new Edge(graph->gui->props,this,destino);
00092     e->setTrust(confianca);
00093     return e;
00094 }
00095 
00096 void Proposition::disconnect(Edge* e)
00097 {
00098     e->source()->outgoing->remove(e);
00099     e->target()->incoming->remove(e);
00100 }
00101 
00102 void Proposition::paintEvent (QPaintEvent*)
00103 {
00104     QPainter painter(this);
00105     painter.setViewport(0,0,width()  ,height() );
00106     draw(&painter);
00107 }
00108 
00109 void Proposition::draw(QPainter* painter)
00110 {
00111     painter->setBrush(fillColor);
00112     painter->setPen(borderColor);
00113         painter->drawEllipse(0,0,width(),height());
00114         painter->setPen(textColor);
00115     painter->drawText(10,10,width()-20,height()-20,Qt::AlignCenter,publicName());
00116 }
00117 
00118 void Proposition::changeActive( QColor thisColor)
00119 {
00120         fillColor = thisColor;
00121         repaint();
00122         if ( (graph->propositionSelected() != NULL)
00123                         && (graph->propositionSelected() != this))
00124                 {
00125                         graph->propositionSelected()->fillColor = graph->propositionSelected()->propFillColor;
00126                         graph->propositionSelected()->repaint();
00127                 }
00128         graph->setPropositionSelected(this);
00129 }
00130 
00131 void Proposition::mousePressEvent (QMouseEvent *e)
00132 {
00133         switch(graph->status()) {
00134                 // New Proposition Created
00135                 case STATUS_NEWPROP:
00136                         graph->newProposition(this);
00137                         graph->addStack.push(this);
00138                         graph->setStatus(STATUS_NOOP);
00139                         break;
00140                 // New Connection - Source Node Click
00141                 case STATUS_CONN_SOURCE:
00142                         changeActive(COLOR_SOURCE);
00143                         graph->setStatus(STATUS_CONN_TARGET);
00144                         break;
00145                 // finish new connection creation       
00146                 case STATUS_CONN_TARGET:
00147                         graph->connect(graph->propositionSelected(),this);
00148                         graph->useDot();
00149                         graph->setChanged(true);
00150                         changeActive(COLOR_PROP_SELECTED);
00151                         graph->setStatus(STATUS_NOOP);
00152                         break;
00153                 // delete proposition   
00154                 case STATUS_PROP_DELETE:
00155                         graph->deleteProp(this);
00156                         graph->delStack.push(this);
00157                         graph->setStatus(STATUS_NOOP);
00158                         break;
00159                 default: // noop
00160                         changeActive(COLOR_PROP_SELECTED);
00161                         break;
00162         } 
00163 }
Untitled Document Pesquisa Psi SourceForge.net Logo