diff options
Diffstat (limited to 'client/macrowindow.cc')
-rw-r--r-- | client/macrowindow.cc | 154 |
1 files changed, 114 insertions, 40 deletions
diff --git a/client/macrowindow.cc b/client/macrowindow.cc index ac44b06..2206929 100644 --- a/client/macrowindow.cc +++ b/client/macrowindow.cc @@ -47,6 +47,8 @@ MacroWindow::MacroWindow(NetCom *netcom, QDomNode &xml_doc, QString course, bool collapsed, bool compact) : Collapser() { + waschanged = false; + this->course = course; this->netcom = netcom; @@ -115,7 +117,7 @@ void MacroWindow::initMacro(QDomNode &node) widgets += widgetBuilder(child, mainwidget, this); } - // Insert their values (this must be done last for lua progs to work properly) + // Insert their values (this must be done last for scripts to work properly) for (int i=0; i<children.count();i++) { QDomNode child = children.at(i); setValues(child, this); @@ -140,7 +142,7 @@ bool MacroWindow::doCommit() QVector< Widget* >::iterator i = widgets.begin(); while (i != widgets.end()) { Widget* w = *i; - if(!w->isValid()) faulty++; // Regexp check, returns valid if entry passed + if(!w->isDisabled() && !w->isValid()) faulty++; // Regexp check, returns valid if entry passed i++; } @@ -167,24 +169,40 @@ void MacroWindow::commit() // close(); } else { QMessageBox::critical(NULL, "Fejl", - "Makroen er ikke udfyldt korrekt, prøv igen.\n" + "Makroen " + macrotitle + " er ikke udfyldt korrekt, prøv igen.\n" , QMessageBox::Ok); } } void MacroWindow::reset() { + /* QMessageBox::warning(NULL, tr("Reset"), tr("Du har valgt at nulstille de indtastede data.\n" "Er du sikker?"), QMessageBox::Yes | QMessageBox::Cancel); printf("MacroWindow -> resetting...\n"); + */ + QVector< Widget* >::iterator i = widgets.begin(); + while (i != widgets.end()) { + Widget* w = *i; + w->reset(); + i++; + } + + QVector< Widget* >::iterator j = auxwidgets.begin(); + while (j != auxwidgets.end()) { + Widget* w = *j; + w->reset(); + j++; + } + + waschanged = false; } void MacroWindow::cancel() { - printf("MacroWindow -> cancelling...\n"); - // close(); + collapseWrapper(); } void MacroWindow::cont(QString name) @@ -208,7 +226,7 @@ void MacroWindow::cont(QString name) // close(); } else { QMessageBox::critical(NULL, "Fejl", - "Makroen er ikke udfyldt korrekt, prøv igen.\n", + "Makroen " + macrotitle + " er ikke udfyldt korrekt, prøv igen.\n", QMessageBox::Ok); } printf("%s : MacroWindow -> continuing...\n", macro.toStdString().c_str()); @@ -235,7 +253,7 @@ void MacroWindow::cont_nocommit(QString name) // close(); } else { QMessageBox::critical(NULL, "Fejl", - "Makroen er ikke udfyldt korrekt, prøv igen.\n", + "Makroen " + macrotitle + " er ikke udfyldt korrekt, prøv igen.\n", QMessageBox::Ok); } printf("%s : MacroWindow -> continuing...\n", macro.toStdString().c_str()); @@ -272,49 +290,105 @@ void MacroWindow::addAuxWidgets(QVector< Widget* > ws) auxwidgets += ws; } -void MacroWindow::toggleMacro() +void MacroWindow::addWidgets(QVector< Widget* > ws) { - if(isCollapsed()) { - widgets.clear(); - auxwidgets.clear(); - luaprograms.clear(); + widgets += ws; +} - QDomDocument xml_doc = netcom->send(course, macro); +void MacroWindow::expandWrapper() +{ + if(!isCollapsed()) return; - // - // TODO: This is where the dependency checking should occur. - // + widgets.clear(); + auxwidgets.clear(); + luaprograms.clear(); + waschanged = false; + + QDomDocument xml_doc = netcom->send(course, macro); + + // + // TODO: This is where the dependency checking should occur. + // + + // Initiate the new macro window with the xml document and push + // it to the window list + QDomNodeList courses = xml_doc.documentElement().childNodes(); + QDomNode coursenode = courses.at(0); // There can be only one! (Swush, flomp) + QDomNodeList macronodes = coursenode.childNodes(); + for(int j = 0; j < macronodes.count(); j++) { + QDomNode macronode = macronodes.at(j); - // Initiate the new macro window with the xml document and push - // it to the window list - QDomNodeList courses = xml_doc.documentElement().childNodes(); - QDomNode coursenode = courses.at(0); // There can be only one! (Swush, flomp) - QDomNodeList macronodes = coursenode.childNodes(); - for(int j = 0; j < macronodes.count(); j++) { - QDomNode macronode = macronodes.at(j); + if(true || macronode.childNodes().count()) { + // macrowindows.push_back( new MacroWindow( netcom, macronode ) ); + QDomElement xml_elem = macronode.toElement(); - if(true || macronode.childNodes().count()) { - // macrowindows.push_back( new MacroWindow( netcom, macronode ) ); - QDomElement xml_elem = macronode.toElement(); + if(xml_elem.tagName() == "macro") { - if(xml_elem.tagName() == "macro") { - - // Assign the macro name and version to QStrings for use when comitting - QString macroname; - if(xml_elem.hasAttribute("name")) { - if(xml_elem.attribute("name") == macro) { - // update me! - initMacro(macronode); - } + // Assign the macro name and version to QStrings for use when comitting + QString macroname; + if(xml_elem.hasAttribute("name")) { + if(xml_elem.attribute("name") == macro) { + // update me! + initMacro(macronode); } - } - } + } + } } - setExpandedWidget(mainwidget); - expand(); + } + setExpandedWidget(mainwidget); + expand(); + + QVector< Widget* >::iterator i = widgets.begin(); + while (i != widgets.end()) { + Widget* w = *i; + if(w->setKeyboardFocus()) break; + i++; + } +} +void MacroWindow::collapseWrapper() +{ + if(isCollapsed()) return; + + if(waschanged) { + switch(QMessageBox::warning(NULL, + "Gem ændringerne i makroen?", + "Du har valgt at lukke makroen " + macrotitle + ".\n" + "Ønsker du at gemme inden du lukker?", + QMessageBox::Save | QMessageBox::Close | QMessageBox::Cancel)) { + case QMessageBox::Save: + if(doCommit()) setCollapsed(true); + else QMessageBox::critical(NULL, + "Fejl", + "Makroen " + macrotitle + " er ikke udfyldt korrekt, prøv igen.\n", + QMessageBox::Ok); + + break; + case QMessageBox::Close: + collapse(); + break; + case QMessageBox::Cancel: + default: + // emit expanding(); // signal the other to close again (if any) + break; + } } else { collapse(); - } } + +void MacroWindow::toggleMacro() +{ + if(isCollapsed()) { + expandWrapper(); + } else { + collapseWrapper(); + } +} + +void MacroWindow::macroChanged() +{ + printf("This macro was changed!\n"); + emit macroHasChanged(); + waschanged = true; +} |