#include "window.h" using namespace std; using namespace morpheo::tools::viewer::parser; using namespace morpheo::tools::viewer::bdd; using namespace morpheo::tools::viewer::graphics; void Window::mousePressEvent (QMouseEvent *e){ if(paint && (p.getArchitecture() != NULL)){ compo = p.getComponent(); QMouseEvent *mouseEvent = (QMouseEvent *) e; mouseX = mouseEvent->x(); mouseY = mouseEvent->y(); bool bc = false; int cx,cy,tx,ty; string cc,nc,type; bool found = false; for(QList::iterator it=compo->begin();it!=compo->end();++it){ Coord *co = it->get_Position(); int px = co->get_hg_x(); int py = co->get_hg_y(); int taillex = co->get_size_x(); int tailley = co->get_size_y(); QString t=QString::fromStdString(it->getType()).toLower(); if(e->type() == QMouseEvent::MouseButtonDblClick && e->button() == Qt::LeftButton){ if(mouseX >= px + MARGEX && mouseY >= py +MARGEY && mouseX <= px+taillex + MARGEX && mouseY <= py+tailley + MARGEY) { bc = false; paint = false; repaint(); found=true; this->setDisabled(true); } } if(found){ mess = new QWidget(); mess->setFixedSize(200,50); mess->move(200,50); QBoxLayout *b = new QBoxLayout(QBoxLayout::TopToBottom,0); QLabel *l = new QLabel(); l->setText("please wait while charging"); b->addWidget(l); mess->setLayout(b); mess->show(); mess_open = true; p=base->get_BasePos(t.toStdString()); entity = p.getEntity(); c = new Coord(250,250,250,250); port_east = entity->getPortEast(c); port_west = entity->getPortWest(c); port_north = entity->getPortNorth(c); port_south = entity->getPortSouth(c); if(cpt_level!=0) tab[cpt_level]=father; father = current; current = QString::fromStdString(t.toStdString()); cpt_level++; tab[cpt_level] = father; paint = true; repaint(); write_name(""); write_comment(""); write_type(""); ln->setText(""); lt->setText(""); comment->hide(); found = false; this->setDisabled(false); component_clicked = false; } if(e->type() == QMouseEvent::MouseButtonPress && e->button() == Qt::LeftButton){ if(mouseX >= px + MARGEX && mouseY >= py +MARGEY && mouseX <= px+taillex + MARGEX && mouseY <= py+tailley + MARGEY) { bc = true; nc = it->getName(); cx = px; cy = py; tx = taillex; ty = tailley; type = it->getType(); BaseP tp = base->get_BasePos(t.toStdString()); if(&tp != NULL) cc=tp.getComment(); component_clicked = true; } } } if(bc){ write_name(nc); write_type(type); ln->setText("component"); lt->setText("type"); write_comment(cc); } } } void Window::mouseMoveEvent(QMouseEvent *e){ bool b = false; bool b2 = false; bool b3 = false; int px,py,taillex,tailley,ppx,ppy; string s,s2,c,type; if(paint && (p.getArchitecture() != NULL) && !component_clicked){ compo = p.getComponent(); QMouseEvent *mouseEvent = (QMouseEvent *) e; mouseX = mouseEvent->x(); mouseY = mouseEvent->y(); for(QList::iterator it=compo->begin();it!=compo->end();++it){ Coord *co = it->get_Position(); px = co->get_hg_x(); py = co->get_hg_y(); taillex = co->get_size_x(); tailley = co->get_size_y(); QString t=QString::fromStdString(it->getType()).toLower(); QList *pm=it->getPortMap(); if(e->type() == QMouseEvent::MouseMove){ if(mouseX >= px + MARGEX && mouseY >= py +MARGEY && mouseX <= px+taillex + MARGEX && mouseY <= py+tailley + MARGEY) { b = true; s = it->getName(); type = it->getType(); BaseP tp=base->get_BasePos(t.toStdString()); if(&tp!=NULL) c=tp.getComment(); ppx = px; ppy = py; break; } else{ for (QList::iterator it3=pm->begin();it3!=pm->end();++it3) { Signal *sig=base->getSignal(&p,it->getName(),new PortMap(*it3)); if(mouseX >= sig->get_src_x() - 15 + MARGEX && mouseY >= sig->get_src_y() - 15 + MARGEY && mouseX <= sig->get_src_x() + 15 + MARGEX && mouseY <= sig->get_src_y() + 15 +MARGEY){ b2 = true; s = it3->getName(); break; } } } } } if(b){ write_name(s); write_type(type); ln->setText("component"); write_comment(c); lt->setText("type"); b3 = false; b2 = false; } if(b2){ write_name(s); write_type(""); lt->setText(""); write_comment(""); ln->setText("signal"); comment->hide(); b3 = false; b = false; } if(!b && !b2){ write_name(""); write_type(""); ln->setText(""); lt->setText(""); write_comment(""); comment->hide(); } } for(QList::iterator it=port_east.begin(); it!=port_east.end(); ++it){ portX = it->get_x(); portY = it->get_y(); if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 + MARGEY && mouseX <= portX + 15 +MARGEX && mouseY <= portY + 15 + MARGEY){ b3 = true; s2 = it->getName(); } } for(QList::iterator it=port_west.begin(); it!=port_west.end(); ++it){ portX = it->get_x() ; portY = it->get_y() ; if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 + MARGEY && mouseX <= portX + 15 + MARGEX && mouseY <= portY + 15 + MARGEY){ b3 = true; s2 = it->getName(); } } for(QList::iterator it=port_north.begin(); it!=port_north.end(); ++it){ portX = it->get_x() ; portY = it->get_y() ; if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 +MARGEY && mouseX <= portX + 15 + MARGEX && mouseY <= portY + 15 +MARGEY){ b3 = true; s2 = it->getName(); } } for(QList::iterator it=port_south.begin(); it!=port_south.end(); ++it){ portX = it->get_x() ; portY = it->get_y() ; if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 + MARGEY && mouseX <= portX + 15 +MARGEX && mouseY <= portY + 15 + MARGEY){ b3 = true; s2 = it->getName(); } } if(b3){ b = false; write_name(""); write_name(s2); write_type(type); ln->setText("signal"); lt->setText(""); write_comment(""); comment->hide(); } } void Window::_back(){ if(cpt_level==0){ QMessageBox *m = new QMessageBox(this); m->setText("can't go up, you're on the top level !"); m->addButton("ok",QMessageBox::YesRole); m->show(); } else{ this->setDisabled(true); paint = false; repaint(); cpt_level--; mess_charg = new QWidget(); mess_charg->setFixedSize(200,50); mess_charg->move(200,50); charg_open = true; QBoxLayout *b = new QBoxLayout(QBoxLayout::TopToBottom,0); QLabel *l = new QLabel(); l->setText("please wait while charging"); b->addWidget(l); mess_charg->setLayout(b); mess_charg->show(); p = base->get_BasePos(father.toStdString()); entity = p.getEntity(); c = new Coord(250,250,250,250); port_east = entity->getPortEast(c); port_west = entity->getPortWest(c); port_north = entity->getPortNorth(c); port_south = entity->getPortSouth(c); father = tab[cpt_level]; current = QString::fromStdString(entity->getName()); paint = true; repaint(); this->setDisabled(false); component_clicked = false; } }