source: trunk/IPs/systemC/processor/Morpheo/Tools/Viewer/Graphics/src/Graphics_window_actions.cpp @ 20

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

1ere release du Viewer :

  • Parseur xml sur Base de données
  • Chargement d'un fichier de positions
  • Dessin du top-level
  • Dessin des ports du top level
  • Dessin des sous composants
  • Dessin des ports de ces sous composants

les valeurs de positions et de taille sont en %.

  • Property svn:executable set to *
File size: 6.4 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
8
9/*signals actions implementation*/
10
11void Window::_open(){
12  //if no file open or if the file opened has been saved -> open other file, else -> ask for saving file
13  if(!file_open || is_save){
14    wo = new QWidget();
15    wo_open = true; //the "open" window is open
16    if(wa_open)
17      wa->close();
18    QBoxLayout *open_box = new QBoxLayout(QBoxLayout::TopToBottom,0);
19    wo->setWindowTitle("open : file name");
20    wo->setFixedSize(500,500);
21    wo->move(50,100);
22    QDirModel *dir = new QDirModel();
23    QTreeView *tree = new QTreeView(wo);
24    tree->resize(400,400);
25    tree->setModel(dir);
26    tree->setRootIndex(dir->index("./data/"));
27    file_name = new QLineEdit(wo);
28    file_name->setText("data/");
29    QPushButton *ok_open = new QPushButton("ok",wo);
30    connect(ok_open,SIGNAL(clicked()),this,SLOT(_open_end()));
31    open_box->addWidget(tree);
32    open_box->addWidget(file_name);
33    open_box->addWidget(ok_open);
34    wo->setLayout(open_box);
35    wo->show();
36  }
37  else{
38    wa_open = true;
39    file_open = false;
40    wa = new QWidget();
41    QBoxLayout *other_box = new QBoxLayout(QBoxLayout::LeftToRight,0);
42    wa->setFixedSize(500,60);
43    wa->move(50,100);
44    QLabel *label = new QLabel("do you want to save this file?");
45    QPushButton *yes_save = new QPushButton("yes",wa);
46    QPushButton *no_save = new QPushButton("no",wa);
47    if(current_name!=NULL)
48      connect(yes_save,SIGNAL(clicked()),this,SLOT(_save()));
49    else 
50      connect(yes_save,SIGNAL(clicked()),this,SLOT(_saveAs()));
51    connect(no_save,SIGNAL(clicked()),this,SLOT(_open()));
52    other_box->addWidget(label);
53    other_box->addWidget(yes_save);
54    other_box->addWidget(no_save);
55    wa->setLayout(other_box);
56    wa->show();
57  }
58}
59
60
61void Window::_open_end(){
62  current_name=file_name->text();
63  wo->close();
64  wo_open = false;//the "open" window is now closed
65  if(!is_parse){
66    parse = new Parse();
67    is_parse=true;
68  }
69  if(parse->open_file( current_name.toStdString())==-1)
70    _open_error();
71  else{
72  paint = false;
73  repaint();
74  _init_file();
75  }
76}
77
78void Window::_init_file(){
79  is_save = true;
80  base = parse->getBaseV();//parse the base and open the file
81  base->afficheBaseConsole();
82  file_open = true;
83  QList <BaseP> *liste_compo = base->getBaseP();
84  p = liste_compo->at(0);
85  entity = p.getEntity();
86  c = new Coord(250,250,250,250);
87  port_east = entity->getPortEast(c);
88  port_west = entity->getPortWest(c);
89  port_north = entity->getPortNorth(c);
90  port_south = entity->getPortSouth(c);
91  paint = true;
92  repaint();
93}
94
95void Window::_open_error(){
96  QMessageBox *error = new QMessageBox(this);
97  error->setText("error : file doesn't exist or is not a valid format");
98  error->addButton("ok",QMessageBox::YesRole);
99  error->show(); 
100} 
101
102
103void Window::_save(){
104  if (wa_open)
105    wa->close();
106  if(save_as || first_save || (current_name==NULL)){//if "save as" or if it's the first time the user click on save (new file) -> save as
107    ws = new QWidget();
108    ws_open = true;//the "save" window is open
109    QBoxLayout *save_box = new QBoxLayout(QBoxLayout::LeftToRight,0);
110    ws->setWindowTitle("save : file name");
111    ws->setFixedSize(300,60);
112    ws->move(50,100);
113    file_name = new QLineEdit(ws);
114    QPushButton *ok_save = new QPushButton("ok",ws);
115    connect(ok_save,SIGNAL(clicked()),this,SLOT(_saveAsOk()));
116    save_box->addWidget(file_name);
117    save_box->addWidget(ok_save);
118    ws->setLayout(save_box);
119    ws->show();
120    save_as = false;
121    first_save = false;
122  }
123  else {
124    status->showMessage("file " + current_name + " saved",900);
125    is_save = true;//file saved
126  }
127  if(wa_open){
128    wa_open = false;
129    _open();
130  }
131}
132
133void Window::_saveAs(){
134  if (wq_open){//if "quit" window is open, close it
135    wq->close();
136    wq_open = false;
137  }
138  save_as = true;
139  _save();
140}
141
142void Window::_saveAsOk(){
143  current_name = file_name->text();
144  ws->close();//close the "save" window
145  ws_open = false;
146  is_save = true;
147  status->showMessage("file " + current_name + " saved",900);
148  if(wa_open){
149    wa_open = false;
150    _open();
151  }
152  if(quit_demand)//if the user clicked on "quit" (but saved the file just before) -> quit the application
153    _quit2();
154}
155
156void Window::_close(){
157  paint = false;
158  repaint();
159}
160
161void Window::_quit(){
162  //if the file is not saved -> ask to the user if he wants to save it. If yes -> save, else quit.
163  if(file_open && !is_save){
164    wq_open = true;
165    quit_demand = true;
166    wq = new QWidget();
167    QBoxLayout *quit_box = new QBoxLayout(QBoxLayout::LeftToRight,0);
168    wq->setWindowTitle("save : file name");
169    wq->setFixedSize(500,60);
170    wq->move(50,100);
171    QLabel *label = new QLabel("do you want to save this file?");
172    QPushButton *yes_save = new QPushButton("yes",wq);
173    QPushButton *no_save = new QPushButton("no",wq);
174    connect(yes_save,SIGNAL(clicked()),this,SLOT(_saveAs()));
175    connect(no_save,SIGNAL(clicked()),this,SLOT(_quit2()));
176    quit_box->addWidget(label);
177    quit_box->addWidget(yes_save);
178    quit_box->addWidget(no_save);
179    wq->setLayout(quit_box);
180    wq->show();
181  }
182  else
183    _quit2();
184}
185 
186void Window::_quit2(){
187  /*test if there are windows (other than the main window) opened*/
188
189  if(wq_open)
190    wq->close();
191  if(wo_open)
192    wo->close();
193  if(ws_open)
194    ws->close();
195  if(wa_open)
196    wa->close();
197  if(param_open)
198    wparam->close();
199  if(info_open)
200    winfo->close();
201  close();
202}
203
204void Window::_zoomIn(){
205  cout << "zoom in" << endl;
206}
207
208void Window::_zoomOut(){
209  cout << "zoom out" << endl;
210}
211
212void Window::_defautZoom(){
213  cout << "defaut zoom" << endl;
214}
215
216void Window::_level(){
217  cout << "level" <<endl;
218}
219
220void Window::_informations(){
221  if(!info_open){//if the informations window is not open, open it,else close it
222    this->winformations();
223    info_open = true;
224  }
225  else{ 
226    winfo->close();
227    info_open = false;
228  }
229}
230
231void Window::_parameters(){//if the parameteres  window is not open, open it,else close it
232  if(!param_open){
233    this->wparameters();
234    param_open = true;
235  }
236  else{ 
237    wparam->close();
238    param_open = false;
239  }
240}
241
242void Window::_about(){
243  QMessageBox *mess = new QMessageBox(this);
244  mess->setText("Viewer beta 1.0\n\nmade by : \nChou Philippe\nLafaye Michaël\nRosière Mathieu\n\nLip6 - 2007");
245  mess->addButton("ok",QMessageBox::YesRole);
246  mess->show(); 
247}
248
249
Note: See TracBrowser for help on using the repository browser.