[21] | 1 | #include "window.h" |
---|
| 2 | |
---|
| 3 | using namespace std; |
---|
| 4 | using namespace morpheo::tools::viewer::parser; |
---|
| 5 | using namespace morpheo::tools::viewer::bdd; |
---|
| 6 | using namespace morpheo::tools::viewer::graphics; |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | /*signals actions implementation*/ |
---|
| 10 | |
---|
[32] | 11 | /*open function*/ |
---|
[21] | 12 | void Window::_open(){ |
---|
[30] | 13 | QString current2; |
---|
| 14 | 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 |
---|
[33] | 15 | current2 = QFileDialog::getOpenFileName(this,"", "./data",tr("(*.pos)")); |
---|
[32] | 16 | this->setDisabled(true); |
---|
| 17 | /*if a file has been opened*/ |
---|
[30] | 18 | if(current2!=""){ |
---|
| 19 | current_name = current2; |
---|
| 20 | if(parse->open_file( current_name.toStdString(),0)==-1) |
---|
| 21 | _open_error(); |
---|
| 22 | else{ |
---|
| 23 | paint = false; |
---|
| 24 | repaint(); |
---|
| 25 | _init_file(); |
---|
| 26 | } |
---|
| 27 | } |
---|
[21] | 28 | } |
---|
| 29 | else{ |
---|
| 30 | file_open = false; |
---|
[30] | 31 | if(!is_save){ |
---|
| 32 | wa_open = true; |
---|
| 33 | wa = new QWidget(); |
---|
| 34 | QBoxLayout *other_box = new QBoxLayout(QBoxLayout::LeftToRight,0); |
---|
| 35 | wa->setFixedSize(500,60); |
---|
| 36 | wa->move(50,100); |
---|
| 37 | QLabel *label = new QLabel("do you want to save this file?"); |
---|
| 38 | QPushButton *yes_save = new QPushButton("yes",wa); |
---|
| 39 | QPushButton *no_save = new QPushButton("no",wa); |
---|
| 40 | if(current_name!=NULL) |
---|
| 41 | connect(yes_save,SIGNAL(clicked()),this,SLOT(_save())); |
---|
| 42 | else |
---|
| 43 | connect(yes_save,SIGNAL(clicked()),this,SLOT(_saveAs())); |
---|
| 44 | connect(no_save,SIGNAL(clicked()),this,SLOT(_open())); |
---|
| 45 | other_box->addWidget(label); |
---|
| 46 | other_box->addWidget(yes_save); |
---|
| 47 | other_box->addWidget(no_save); |
---|
| 48 | wa->setLayout(other_box); |
---|
| 49 | wa->show(); |
---|
| 50 | } |
---|
| 51 | else{ |
---|
| 52 | parse->closeBaseV(); |
---|
| 53 | _open(); |
---|
| 54 | } |
---|
[21] | 55 | } |
---|
| 56 | } |
---|
| 57 | |
---|
[32] | 58 | /*initialize the database when a file has been opened*/ |
---|
[21] | 59 | void Window::_init_file(){ |
---|
| 60 | is_save = true; |
---|
| 61 | base = parse->getBaseV();//parse the base and open the file |
---|
[32] | 62 | //#ifdef DEBUG_ALL |
---|
[26] | 63 | base->afficheBaseConsole(); |
---|
[32] | 64 | //#endif |
---|
[26] | 65 | cpt_level = 0; |
---|
| 66 | |
---|
| 67 | tab[cpt_level] = ""; |
---|
[21] | 68 | file_open = true; |
---|
| 69 | QList <BaseP> *liste_compo = base->getBaseP(); |
---|
| 70 | p = liste_compo->at(0); |
---|
| 71 | entity = p.getEntity(); |
---|
[26] | 72 | current = QString::fromStdString(entity->getName()); |
---|
[21] | 73 | c = new Coord(250,250,250,250); |
---|
| 74 | port_east = entity->getPortEast(c); |
---|
| 75 | port_west = entity->getPortWest(c); |
---|
| 76 | port_north = entity->getPortNorth(c); |
---|
| 77 | port_south = entity->getPortSouth(c); |
---|
| 78 | paint = true; |
---|
| 79 | repaint(); |
---|
[32] | 80 | display_param(); |
---|
[33] | 81 | wparam->close(); |
---|
| 82 | this->_parameters(); |
---|
| 83 | this->_parameters(); |
---|
[30] | 84 | this->setDisabled(false); |
---|
[26] | 85 | setMouseTracking(true); |
---|
[21] | 86 | } |
---|
| 87 | |
---|
[32] | 88 | /*if user entered a wrong file name*/ |
---|
[21] | 89 | void Window::_open_error(){ |
---|
| 90 | QMessageBox *error = new QMessageBox(this); |
---|
| 91 | error->setText("error : file doesn't exist or is not a valid format"); |
---|
| 92 | error->addButton("ok",QMessageBox::YesRole); |
---|
| 93 | error->show(); |
---|
[32] | 94 | this->setDisabled(false); |
---|
[21] | 95 | } |
---|
| 96 | |
---|
[32] | 97 | /*save functions*/ |
---|
[21] | 98 | void Window::_save(){ |
---|
| 99 | if(file_open){ |
---|
| 100 | if (wa_open) |
---|
| 101 | wa->close(); |
---|
[32] | 102 | if(save_as){//if "save as" |
---|
[33] | 103 | current_name = QFileDialog::getSaveFileName(this,"","./data",tr("(*.cfg)")); |
---|
[21] | 104 | save_as = false; |
---|
[32] | 105 | parse->save_file(current_name.toStdString(),0); |
---|
[21] | 106 | } |
---|
| 107 | else { |
---|
[32] | 108 | parse->save_file(current.toStdString(),0); |
---|
| 109 | status->showMessage("file " + current + " saved",900); |
---|
[21] | 110 | is_save = true;//file saved |
---|
| 111 | } |
---|
| 112 | if(wa_open){ |
---|
| 113 | wa_open = false; |
---|
| 114 | _open(); |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | else{ |
---|
| 118 | QMessageBox *mess = new QMessageBox(this); |
---|
| 119 | mess->setText("no file opened"); |
---|
| 120 | mess->addButton("ok",QMessageBox::YesRole); |
---|
| 121 | mess->show(); |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | void Window::_saveAs(){ |
---|
| 126 | if (wq_open){//if "quit" window is open, close it |
---|
| 127 | wq->close(); |
---|
| 128 | wq_open = false; |
---|
| 129 | } |
---|
| 130 | save_as = true; |
---|
| 131 | _save(); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | void Window::_saveAsOk(){ |
---|
| 135 | is_save = true; |
---|
| 136 | status->showMessage("file " + current_name + " saved",900); |
---|
| 137 | if(wa_open){ |
---|
| 138 | wa_open = false; |
---|
| 139 | _open(); |
---|
| 140 | } |
---|
| 141 | if(quit_demand)//if the user clicked on "quit" (but saved the file just before) -> quit the application |
---|
| 142 | _quit2(); |
---|
| 143 | } |
---|
| 144 | |
---|
[32] | 145 | /*close function*/ |
---|
[21] | 146 | void Window::_close(){ |
---|
| 147 | paint = false; |
---|
[32] | 148 | repaint(); |
---|
[30] | 149 | parse->closeBaseV(); |
---|
[32] | 150 | erase_line(ln,lname); |
---|
| 151 | erase_line(lt,ltype); |
---|
| 152 | erase_comment(); |
---|
[21] | 153 | winfo->show(); |
---|
[32] | 154 | wscroll->hide(); |
---|
| 155 | scroll_hide = true; |
---|
| 156 | wparam->show(); |
---|
[21] | 157 | file_open = false; |
---|
| 158 | } |
---|
| 159 | |
---|
[32] | 160 | /*quit functions*/ |
---|
[21] | 161 | void 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 | } |
---|
[32] | 185 | /*close all the windows opened*/ |
---|
[21] | 186 | void Window::_quit2(){ |
---|
| 187 | /*test if there are windows (other than the main window) opened*/ |
---|
| 188 | |
---|
| 189 | if(wq_open) |
---|
| 190 | wq->close(); |
---|
| 191 | if(wa_open) |
---|
| 192 | wa->close(); |
---|
| 193 | if(param_open) |
---|
| 194 | wparam->close(); |
---|
| 195 | if(info_open) |
---|
| 196 | winfo->close(); |
---|
| 197 | close(); |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | |
---|
| 201 | |
---|
| 202 | |
---|