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

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

2eme release du viewer
Mise a jour graphique du Viewer.

  • Property svn:executable set to *
File size: 5.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  //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(file_open){
105    if (wa_open)
106      wa->close();
107    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
108      ws = new QWidget();
109      ws_open = true;//the "save" window is open
110      QBoxLayout *save_box = new QBoxLayout(QBoxLayout::LeftToRight,0);
111      ws->setWindowTitle("save : file name");
112      ws->setFixedSize(300,60);
113      ws->move(50,100);
114      file_name = new QLineEdit(ws);
115      QPushButton *ok_save = new QPushButton("ok",ws);
116      connect(ok_save,SIGNAL(clicked()),this,SLOT(_saveAsOk()));
117      save_box->addWidget(file_name);
118      save_box->addWidget(ok_save);
119      ws->setLayout(save_box);
120      ws->show();
121      save_as = false;
122      first_save = false;
123    }
124    else {
125      status->showMessage("file " + current_name + " saved",900);
126      is_save = true;//file saved
127    }
128    if(wa_open){
129      wa_open = false;
130      _open();
131    }
132  }
133  else{
134    QMessageBox *mess = new QMessageBox(this);
135    mess->setText("no file opened");
136    mess->addButton("ok",QMessageBox::YesRole);
137    mess->show(); 
138  }
139}
140
141void Window::_saveAs(){
142  if (wq_open){//if "quit" window is open, close it
143    wq->close();
144    wq_open = false;
145  }
146  save_as = true;
147  _save();
148}
149
150void Window::_saveAsOk(){
151  current_name = file_name->text();
152  ws->close();//close the "save" window
153  ws_open = false;
154  is_save = true;
155  status->showMessage("file " + current_name + " saved",900);
156  if(wa_open){
157    wa_open = false;
158    _open();
159  }
160  if(quit_demand)//if the user clicked on "quit" (but saved the file just before) -> quit the application
161    _quit2();
162}
163
164void Window::_close(){
165  paint = false;
166  lname->setText("");
167  winfo->show();
168  file_open = false;
169  repaint();
170}
171
172void Window::_quit(){
173  //if the file is not saved -> ask to the user if he wants to save it. If yes -> save, else quit.
174  if(file_open && !is_save){
175    wq_open = true;
176    quit_demand = true;
177    wq = new QWidget();
178    QBoxLayout *quit_box = new QBoxLayout(QBoxLayout::LeftToRight,0);
179    wq->setWindowTitle("save : file name");
180    wq->setFixedSize(500,60);
181    wq->move(50,100);
182    QLabel *label = new QLabel("do you want to save this file?");
183    QPushButton *yes_save = new QPushButton("yes",wq);
184    QPushButton *no_save = new QPushButton("no",wq);
185    connect(yes_save,SIGNAL(clicked()),this,SLOT(_saveAs()));
186    connect(no_save,SIGNAL(clicked()),this,SLOT(_quit2()));
187    quit_box->addWidget(label);
188    quit_box->addWidget(yes_save);
189    quit_box->addWidget(no_save);
190    wq->setLayout(quit_box);
191    wq->show();
192  }
193  else
194    _quit2();
195}
196 
197void Window::_quit2(){
198  /*test if there are windows (other than the main window) opened*/
199
200  if(wq_open)
201    wq->close();
202  if(wo_open)
203    wo->close();
204  if(ws_open)
205    ws->close();
206  if(wa_open)
207    wa->close();
208  if(param_open)
209    wparam->close();
210  if(info_open)
211    winfo->close();
212  close();
213}
214
215
216
217
Note: See TracBrowser for help on using the repository browser.