source: trunk/IPs/systemC/processor/Morpheo/Tools/Viewer/Graphics/src/Graphics_mouseEvent.cpp @ 28

Last change on this file since 28 was 28, checked in by chou, 17 years ago

release 3.1 à jour : affichage du nom des signaux lors du passage de la souris

  • Property svn:executable set to *
File size: 6.8 KB
Line 
1#include "window.h"
2
3using namespace std;
4using namespace morpheo::tools::viewer::parser;
5using namespace morpheo::tools::viewer::bdd;
6using namespace morpheo::tools::viewer::graphics;
7
8void Window::mousePressEvent (QMouseEvent *e){
9 
10  if(paint && (p.getArchitecture() != NULL)){
11
12    compo = p.getComponent();
13   
14   
15    QMouseEvent *mouseEvent = (QMouseEvent *) e;
16   
17    mouseX = mouseEvent->x();
18    mouseY = mouseEvent->y();
19   
20    bool bc = false;
21    int cx,cy,tx,ty;
22    string cc,nc;
23    bool found = false;
24
25    for(QList<Component>::iterator it=compo->begin();it!=compo->end();++it){
26      Coord *co = it->get_Position();
27      int px = co->get_hg_x();
28      int py = co->get_hg_y();
29      int taillex = co->get_size_x();
30      int tailley = co->get_size_y();
31      QString t=QString::fromStdString(it->getType()).toLower();
32      if(e->type() == QMouseEvent::MouseButtonDblClick && e->button() == Qt::LeftButton){
33       
34        if(mouseX >= px + MARGEX  && mouseY >= py +MARGEY && mouseX <= px+taillex + MARGEX  && mouseY <= py+tailley + MARGEY) {
35         
36          bc = false;
37          paint = false;
38          repaint();
39          found=true;
40          this->setDisabled(true);
41        }
42      }
43      if(found){ 
44        mess = new QWidget();
45        mess->setFixedSize(200,50);
46        mess->move(200,50);
47        QBoxLayout *b = new QBoxLayout(QBoxLayout::TopToBottom,0);
48        QLabel *l = new QLabel();
49        l->setText("please wait while charging");
50        b->addWidget(l);
51        mess->setLayout(b);
52        mess->show();
53        mess_open = true;
54
55        p=base->get_BasePos(t.toStdString());
56        entity = p.getEntity();
57        c = new Coord(250,250,250,250);
58        port_east = entity->getPortEast(c);
59        port_west = entity->getPortWest(c);
60        port_north = entity->getPortNorth(c);
61        port_south = entity->getPortSouth(c);
62        if(cpt_level!=0)
63          tab[cpt_level]=father;
64        father = current;
65        current = QString::fromStdString(t.toStdString());
66        cpt_level++;
67        tab[cpt_level] = father;
68        paint = true;
69        this->releaseMouse();
70        repaint();
71        write_name("");
72        write_comment("");
73        erase_position();
74        erase_size();
75        found = false;
76        this->setDisabled(false);
77      }
78     
79      if(e->type() == QMouseEvent::MouseButtonPress && e->button() == Qt::LeftButton){
80        if(mouseX >= px + MARGEX  && mouseY >= py +MARGEY && mouseX <= px+taillex + MARGEX  && mouseY <= py+tailley + MARGEY) {
81          bc = true;
82          nc = it->getName();
83          cx = px;
84          cy = py;
85          tx = taillex;
86          ty = tailley;
87          BaseP tp = base->get_BasePos(t.toStdString());
88          if(&tp != NULL)
89                cc=tp.getComment();
90          component_clicked = true;
91        }
92      }
93    }
94    if(bc){
95      write_name(nc);
96      write_position(cx,cy);
97      write_size(tx,ty);
98      write_comment(cc);
99    }
100  }
101}
102
103
104void Window::mouseMoveEvent(QMouseEvent *e){
105
106   bool b  = false;
107   bool b2 = false;
108   bool b3 = false;
109   int px,py,taillex,tailley,ppx,ppy;
110   string s,s2,c;
111
112   if(paint && (p.getArchitecture() != NULL) && !component_clicked){
113
114    compo = p.getComponent();
115   
116    QMouseEvent *mouseEvent = (QMouseEvent *) e;
117
118    mouseX = mouseEvent->x();
119    mouseY = mouseEvent->y();
120   
121    for(QList<Component>::iterator it=compo->begin();it!=compo->end();++it){
122      Coord *co = it->get_Position();
123      px = co->get_hg_x();
124      py = co->get_hg_y();
125      taillex = co->get_size_x();
126      tailley = co->get_size_y();
127     
128      QList<PortMap> *pm=it->getPortMap();
129
130      if(e->type() == QMouseEvent::MouseMove){
131        if(mouseX >= px + MARGEX  && mouseY >= py +MARGEY && mouseX <= px+taillex + MARGEX  && mouseY <= py+tailley + MARGEY) {
132          b = true;
133          s = it->getName();
134          BaseP tp=base->get_BasePos(it->getName());
135          if(&tp!=NULL)
136            c=tp.getComment();
137          ppx = px;
138          ppy = py;
139          break;
140        }
141        else{
142          for (QList<PortMap>::iterator it3=pm->begin();it3!=pm->end();++it3) {
143                Signal *sig=base->getSignal(&p,it->getName(),new PortMap(*it3));
144                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){
145                  b2 = true;
146                  s = it3->getName();
147                  break;
148                }
149          }
150        }   
151      }
152    }
153   
154    if(b){
155      write_name(s);
156      write_position(ppx,ppy);
157      write_size(taillex,tailley);
158      write_comment(c);
159      b3 = false;
160      b2 = false;
161    }
162   
163    if(b2){
164      write_name(s);
165      erase_position();
166      write_comment("");
167      b3 = false;
168      b = false;
169    }
170
171    if(!b && !b2){
172      write_name("");
173      erase_position();
174      write_comment("");
175      erase_size();
176    }
177     
178   }
179 
180 
181   for(QList<Port>::iterator it=port_east.begin(); it!=port_east.end(); ++it){
182      portX = it->get_x();
183      portY = it->get_y();
184      if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 + MARGEY && mouseX <= portX + 15 +MARGEX && mouseY <= portY + 15 + MARGEY){
185        b3 = true;
186        s2 = it->getName();
187      }
188   } 
189   
190   for(QList<Port>::iterator it=port_west.begin(); it!=port_west.end(); ++it){
191     portX = it->get_x() ;
192     portY = it->get_y() ;
193     if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 + MARGEY && mouseX <= portX + 15 + MARGEX && mouseY <= portY + 15 + MARGEY){
194       b3 = true;
195       s2 = it->getName();
196     }
197   }
198   
199   for(QList<Port>::iterator it=port_north.begin(); it!=port_north.end(); ++it){
200     portX = it->get_x() ;
201     portY = it->get_y() ;
202     if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 +MARGEY && mouseX <= portX + 15 + MARGEX && mouseY <= portY + 15 +MARGEY){
203        b3 = true;
204        s2 = it->getName();
205     }
206   }
207   
208    for(QList<Port>::iterator it=port_south.begin(); it!=port_south.end(); ++it){
209      portX = it->get_x() ;
210      portY = it->get_y() ;
211      if(mouseX >= portX - 15 + MARGEX && mouseY >= portY - 15 + MARGEY && mouseX <= portX + 15 +MARGEX && mouseY <= portY + 15 + MARGEY){
212        b3 = true;
213        s2 = it->getName();
214      }
215    }
216    if(b3){
217      b = false;
218      write_name("");
219      erase_position();
220      write_name(s2);
221      erase_size();
222    }
223}
224
225
226   
227 
228void Window::_back(){
229  if(cpt_level==0){
230    QMessageBox *m = new QMessageBox(this);
231    m->setText("can't go up, you're on the top level !");
232    m->addButton("ok",QMessageBox::YesRole);
233    m->show(); 
234  }
235 
236  else{
237    this->setDisabled(true);
238    paint = false;
239    repaint();
240    cpt_level--;
241    mess_charg = new QWidget();
242    mess_charg->setFixedSize(200,50);
243    mess_charg->move(200,50);
244    charg_open = true;
245    QBoxLayout *b = new QBoxLayout(QBoxLayout::TopToBottom,0);
246    QLabel *l = new QLabel();
247    l->setText("please wait while charging");
248    b->addWidget(l);
249    mess_charg->setLayout(b);
250    mess_charg->show();
251   
252    p = base->get_BasePos(father.toStdString());
253    entity = p.getEntity();
254    c = new Coord(250,250,250,250);
255    port_east = entity->getPortEast(c);
256    port_west = entity->getPortWest(c);
257    port_north = entity->getPortNorth(c);
258    port_south = entity->getPortSouth(c);
259    father = tab[cpt_level];
260    current = QString::fromStdString(entity->getName());
261    paint = true;
262    repaint();
263    this->setDisabled(false);
264  }
265}
266
Note: See TracBrowser for help on using the repository browser.