source: trunk/IPs/systemC/processor/Morpheo/Tools/Viewer/Graphics/src/Graphics_file_actions.cpp @ 30

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

Morpheo Viewer Release 4.0 :
changements graphiques .

  • Property svn:executable set to *
File size: 4.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
8
9/*signals actions implementation*/
10
11void Window::_open(){
12  QString current2;
13  if(!file_open && is_save){//if no file open or if the file opened has been saved -> open other file, else -> ask for saving file
14    current2 = QFileDialog::getOpenFileName(this,"", "./data");
15    if(current2!=""){
16      this->setDisabled(true);
17      current_name = current2;
18      if(parse->open_file( current_name.toStdString(),0)==-1)
19        _open_error();
20      else{
21        paint = false;
22        repaint();
23        _init_file();
24      }
25    }
26  }
27  else{
28    file_open = false;
29    if(!is_save){
30      wa_open = true;
31      wa = new QWidget();
32      QBoxLayout *other_box = new QBoxLayout(QBoxLayout::LeftToRight,0);
33      wa->setFixedSize(500,60);
34      wa->move(50,100);
35      QLabel *label = new QLabel("do you want to save this file?");
36      QPushButton *yes_save = new QPushButton("yes",wa);
37      QPushButton *no_save = new QPushButton("no",wa);
38      if(current_name!=NULL)
39        connect(yes_save,SIGNAL(clicked()),this,SLOT(_save()));
40      else 
41        connect(yes_save,SIGNAL(clicked()),this,SLOT(_saveAs()));
42      connect(no_save,SIGNAL(clicked()),this,SLOT(_open()));
43      other_box->addWidget(label);
44      other_box->addWidget(yes_save);
45      other_box->addWidget(no_save);
46      wa->setLayout(other_box);
47      wa->show();
48    }
49    else{
50      parse->closeBaseV();
51      _open();
52    }
53  }
54}
55
56void Window::_init_file(){
57  is_save = true;
58  base = parse->getBaseV();//parse the base and open the file
59  #ifdef DEBUG_ALL
60  base->afficheBaseConsole();
61  #endif
62  cpt_level = 0;
63 
64  tab[cpt_level] = "";
65  file_open = true;
66  QList <BaseP> *liste_compo = base->getBaseP();
67  p = liste_compo->at(0);
68  entity = p.getEntity();
69  current = QString::fromStdString(entity->getName());
70  c = new Coord(250,250,250,250);
71  port_east = entity->getPortEast(c);
72  port_west = entity->getPortWest(c);
73  port_north = entity->getPortNorth(c);
74  port_south = entity->getPortSouth(c);
75  paint = true;
76  repaint();
77  this->setDisabled(false);
78  setMouseTracking(true);
79}
80
81void Window::_open_error(){
82  QMessageBox *error = new QMessageBox(this);
83  error->setText("error : file doesn't exist or is not a valid format");
84  error->addButton("ok",QMessageBox::YesRole);
85  error->show(); 
86} 
87
88
89void Window::_save(){
90  if(file_open){
91    if (wa_open)
92      wa->close();
93    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
94      current_name = QFileDialog::getSaveFileName(this,"","./data");
95      save_as = false;
96      first_save = false;
97    }
98    else {
99      status->showMessage("file " + current_name + " saved",900);
100      is_save = true;//file saved
101    }
102    if(wa_open){
103      wa_open = false;
104      _open();
105    }
106  }
107  else{
108    QMessageBox *mess = new QMessageBox(this);
109    mess->setText("no file opened");
110    mess->addButton("ok",QMessageBox::YesRole);
111    mess->show(); 
112  }
113}
114
115void Window::_saveAs(){
116  if (wq_open){//if "quit" window is open, close it
117    wq->close();
118    wq_open = false;
119  }
120  save_as = true;
121  _save();
122}
123
124void Window::_saveAsOk(){
125  is_save = true;
126  status->showMessage("file " + current_name + " saved",900);
127  if(wa_open){
128    wa_open = false;
129    _open();
130  }
131  if(quit_demand)//if the user clicked on "quit" (but saved the file just before) -> quit the application
132    _quit2();
133}
134
135void Window::_close(){
136  paint = false;
137  parse->closeBaseV();
138  lname->setText("");
139  ln->setText("");
140  lt->setText("");
141  write_name("");
142  write_comment("");
143  comment->hide();
144  winfo->show();
145  file_open = false;
146  repaint();
147}
148
149void Window::_quit(){
150  //if the file is not saved -> ask to the user if he wants to save it. If yes -> save, else quit.
151  if(file_open && !is_save){
152    wq_open = true;
153    quit_demand = true;
154    wq = new QWidget();
155    QBoxLayout *quit_box = new QBoxLayout(QBoxLayout::LeftToRight,0);
156    wq->setWindowTitle("save : file name");
157    wq->setFixedSize(500,60);
158    wq->move(50,100);
159    QLabel *label = new QLabel("do you want to save this file?");
160    QPushButton *yes_save = new QPushButton("yes",wq);
161    QPushButton *no_save = new QPushButton("no",wq);
162    connect(yes_save,SIGNAL(clicked()),this,SLOT(_saveAs()));
163    connect(no_save,SIGNAL(clicked()),this,SLOT(_quit2()));
164    quit_box->addWidget(label);
165    quit_box->addWidget(yes_save);
166    quit_box->addWidget(no_save);
167    wq->setLayout(quit_box);
168    wq->show();
169  }
170  else
171    _quit2();
172}
173 
174void Window::_quit2(){
175  /*test if there are windows (other than the main window) opened*/
176
177  if(wq_open)
178    wq->close();
179  if(wa_open)
180    wa->close();
181  if(param_open)
182    wparam->close();
183  if(info_open)
184    winfo->close();
185  close();
186}
187
188
189
190
Note: See TracBrowser for help on using the repository browser.