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

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

Release 3 du viewer:
Etape 1 et 2 du projet complet et à jour.

  • Property svn:executable set to *
File size: 5.9 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    QPushButton *ok_open = new QPushButton("ok",wo);
29    connect(ok_open,SIGNAL(clicked()),this,SLOT(_open_end()));
30    open_box->addWidget(tree);
31    open_box->addWidget(file_name);
32    open_box->addWidget(ok_open);
33    wo->setLayout(open_box);
34    wo->show();
35  }
36  else{
37    wa_open = true;
38    file_open = false;
39    wa = new QWidget();
40    QBoxLayout *other_box = new QBoxLayout(QBoxLayout::LeftToRight,0);
41    wa->setFixedSize(500,60);
42    wa->move(50,100);
43    QLabel *label = new QLabel("do you want to save this file?");
44    QPushButton *yes_save = new QPushButton("yes",wa);
45    QPushButton *no_save = new QPushButton("no",wa);
46    if(current_name!=NULL)
47      connect(yes_save,SIGNAL(clicked()),this,SLOT(_save()));
48    else 
49      connect(yes_save,SIGNAL(clicked()),this,SLOT(_saveAs()));
50    connect(no_save,SIGNAL(clicked()),this,SLOT(_open()));
51    other_box->addWidget(label);
52    other_box->addWidget(yes_save);
53    other_box->addWidget(no_save);
54    wa->setLayout(other_box);
55    wa->show();
56  }
57}
58
59
60void Window::_open_end(){
61  current_name=file_name->text();
62  wo->close();
63  wo_open = false;//the "open" window is now closed
64  if(!is_parse){
65    parse = new Parse();
66    is_parse=true;
67  }
68  if(parse->open_file( current_name.toStdString(),0)==-1)
69    _open_error();
70  else{
71  paint = false;
72  repaint();
73  _init_file();
74  }
75}
76
77void Window::_init_file(){
78  is_save = true;
79  base = parse->getBaseV();//parse the base and open the file
80  #ifdef DEBUG_ALL
81  base->afficheBaseConsole();
82  #endif
83  cpt_level = 0;
84 
85  tab[cpt_level] = "";
86  file_open = true;
87  QList <BaseP> *liste_compo = base->getBaseP();
88  p = liste_compo->at(0);
89  entity = p.getEntity();
90  current = QString::fromStdString(entity->getName());
91  c = new Coord(250,250,250,250);
92  port_east = entity->getPortEast(c);
93  port_west = entity->getPortWest(c);
94  port_north = entity->getPortNorth(c);
95  port_south = entity->getPortSouth(c);
96  paint = true;
97  repaint();
98  setMouseTracking(true);
99}
100
101void Window::_open_error(){
102  QMessageBox *error = new QMessageBox(this);
103  error->setText("error : file doesn't exist or is not a valid format");
104  error->addButton("ok",QMessageBox::YesRole);
105  error->show(); 
106} 
107
108
109void Window::_save(){
110  if(file_open){
111    if (wa_open)
112      wa->close();
113    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
114      ws = new QWidget();
115      ws_open = true;//the "save" window is open
116      QBoxLayout *save_box = new QBoxLayout(QBoxLayout::LeftToRight,0);
117      ws->setWindowTitle("save : file name");
118      ws->setFixedSize(300,60);
119      ws->move(50,100);
120      file_name = new QLineEdit(ws);
121      QPushButton *ok_save = new QPushButton("ok",ws);
122      connect(ok_save,SIGNAL(clicked()),this,SLOT(_saveAsOk()));
123      save_box->addWidget(file_name);
124      save_box->addWidget(ok_save);
125      ws->setLayout(save_box);
126      ws->show();
127      save_as = false;
128      first_save = false;
129    }
130    else {
131      status->showMessage("file " + current_name + " saved",900);
132      is_save = true;//file saved
133    }
134    if(wa_open){
135      wa_open = false;
136      _open();
137    }
138  }
139  else{
140    QMessageBox *mess = new QMessageBox(this);
141    mess->setText("no file opened");
142    mess->addButton("ok",QMessageBox::YesRole);
143    mess->show(); 
144  }
145}
146
147void Window::_saveAs(){
148  if (wq_open){//if "quit" window is open, close it
149    wq->close();
150    wq_open = false;
151  }
152  save_as = true;
153  _save();
154}
155
156void Window::_saveAsOk(){
157  current_name = file_name->text();
158  ws->close();//close the "save" window
159  ws_open = false;
160  is_save = true;
161  status->showMessage("file " + current_name + " saved",900);
162  if(wa_open){
163    wa_open = false;
164    _open();
165  }
166  if(quit_demand)//if the user clicked on "quit" (but saved the file just before) -> quit the application
167    _quit2();
168}
169
170void Window::_close(){
171  paint = false;
172  lname->setText("");
173  winfo->show();
174  file_open = false;
175  repaint();
176}
177
178void Window::_quit(){
179  //if the file is not saved -> ask to the user if he wants to save it. If yes -> save, else quit.
180  if(file_open && !is_save){
181    wq_open = true;
182    quit_demand = true;
183    wq = new QWidget();
184    QBoxLayout *quit_box = new QBoxLayout(QBoxLayout::LeftToRight,0);
185    wq->setWindowTitle("save : file name");
186    wq->setFixedSize(500,60);
187    wq->move(50,100);
188    QLabel *label = new QLabel("do you want to save this file?");
189    QPushButton *yes_save = new QPushButton("yes",wq);
190    QPushButton *no_save = new QPushButton("no",wq);
191    connect(yes_save,SIGNAL(clicked()),this,SLOT(_saveAs()));
192    connect(no_save,SIGNAL(clicked()),this,SLOT(_quit2()));
193    quit_box->addWidget(label);
194    quit_box->addWidget(yes_save);
195    quit_box->addWidget(no_save);
196    wq->setLayout(quit_box);
197    wq->show();
198  }
199  else
200    _quit2();
201}
202 
203void Window::_quit2(){
204  /*test if there are windows (other than the main window) opened*/
205
206  if(wq_open)
207    wq->close();
208  if(wo_open)
209    wo->close();
210  if(ws_open)
211    ws->close();
212  if(wa_open)
213    wa->close();
214  if(param_open)
215    wparam->close();
216  if(info_open)
217    winfo->close();
218  close();
219}
220
221
222
223
Note: See TracBrowser for help on using the repository browser.