summaryrefslogtreecommitdiff
path: root/client/mainwindow.cc
diff options
context:
space:
mode:
authordeva <deva>2009-06-30 17:31:53 +0000
committerdeva <deva>2009-06-30 17:31:53 +0000
commit9a773bc9ed736301b5ac6f6f8798056194398011 (patch)
treea113908743936aea97975adb6f4f1c7f49e6b007 /client/mainwindow.cc
parentb31e7fba17d1e5c1264c0829c4da258c32aa80c3 (diff)
Removed console on win32 unless, compiled in debug mode. First attempt on a macro dependency system.
Diffstat (limited to 'client/mainwindow.cc')
-rw-r--r--client/mainwindow.cc109
1 files changed, 42 insertions, 67 deletions
diff --git a/client/mainwindow.cc b/client/mainwindow.cc
index fd55ba0..c59a877 100644
--- a/client/mainwindow.cc
+++ b/client/mainwindow.cc
@@ -60,7 +60,6 @@ MainWindow::MainWindow(QString cpr, QString course, QString host, quint16 port,
w->setLayout(new QVBoxLayout());
this->course = course;
- // status->showMessage("Makroen blev succesfuldt indlęst.");
setStatusBar(status);
init();
@@ -94,13 +93,8 @@ void MainWindow::init()
initialising = false;
}
-void MainWindow::update()
+void MainWindow::updateCourseHeaders(QDomNode coursenode)
{
- QDomDocument xml_doc = netcom.send(course);
-
- QDomNodeList courses = xml_doc.documentElement().childNodes();
- QDomNode coursenode = courses.at(0); // There can be only one! (Swush, flomp)
-
QDomElement course_elem = coursenode.toElement();
QString course_title = course_elem.attribute("title");
QString course_name = course_elem.attribute("name");
@@ -117,82 +111,63 @@ void MainWindow::update()
}
statusBar()->showMessage(course_title + " (" + course_name + ")");
+}
+
+
+void MainWindow::update()
+{
+ QDomDocument xml_doc = netcom.send(course);
+
+ QDomNodeList courses = xml_doc.documentElement().childNodes();
+ QDomNode coursenode = courses.at(0); // There can be only one! (Swush, flomp)
+
+ updateCourseHeaders(coursenode);
QDomNodeList macronodes = coursenode.childNodes();
for(int j = 0; j < macronodes.count(); j++) {
QDomNode macronode = macronodes.at(j);
+ QDomElement macroelement = macronode.toElement();
- QDomElement xml_elem = macronode.toElement();
-
- if(xml_elem.tagName() == "macro") {
-
- if(xml_elem.hasAttribute("header")) {
- // Macro is a special headline macro.
- // Simply create a headline, and ignore the rest.
+ QString macroname = macroelement.attribute("name");
- // Only add header on initial contruction.
- if(initialising == true) {
- QLabel *header = new QLabel();
- header->setText(xml_elem.attribute("header"));
- QFont headerfont = header->font();
- headerfont.setBold(true);
- headerfont.setPointSize(headerfont.pointSize() + 2);
- header->setFont(headerfont);
- w->layout()->addWidget(header);
- }
+ bool found = false;
- continue;
- }
+ Macros::iterator i = macros.begin();
+ while(i != macros.end()) {
+ if(i->name == macroname) found |= true;
+ i++;
+ }
- QString macroname;
- if(xml_elem.hasAttribute("name")) macroname = xml_elem.attribute("name");
-
- if(macros.find(macroname) == macros.end()) {
- bool isstatic = false;
- bool iscompact = false;
- if(xml_elem.attribute("static", "false") == "true") isstatic = true;
- if(xml_elem.attribute("compact", "false") == "true") iscompact = true;
- macros[macroname] = new MacroWindow(&netcom, macronode, course, !isstatic, iscompact);
- macros[macroname]->isstatic = isstatic;
-
- MacroDrawer *g = new MacroDrawer(macros[macroname], xml_elem.attribute("caption", macroname));
- connect(g, SIGNAL(toggle()), macros[macroname], SLOT(toggleMacro()));
-
- ((QBoxLayout*)w->layout())->addWidget(g);
-
- QHBoxLayout *l = new QHBoxLayout();
- l->setContentsMargins(10,0,10,0);
- g->setLayout(l);
- l->addWidget(macros[macroname]);
- connect(macros[macroname], SIGNAL(updateOnCommit()), this, SLOT(update()));
- {
- QFont f = macros[macroname]->font();
- f.setBold(false);
- f.setItalic(false);
- macros[macroname]->setFont(f);
- }
-
- } else {
-
- macros[macroname]->update(macronode);
- if(xml_elem.attribute("static", "false") == "false") {
- macros[macroname]->setCollapsed(true);
- }
+ if(found == false || macroelement.hasAttribute("header")) {
+ QString num;
+ num.sprintf("%4d", j);
+ Macro macro(macronode);
+ macros[num + macro.name] = macro;
+ }
+ }
- }
+ {
+ Macros::iterator i = macros.begin();
+ while(i != macros.end()) {
+ Macro &macro = i.value();
+ macro.init((QBoxLayout*)w->layout(), macros, initialising, netcom, course);
+ if(macro.window != NULL) connect(macro.window, SIGNAL(updateOnCommit()), this, SLOT(update()));
+ i++;
}
}
// Make sure that all macros will collapse when a new one is expanded.
- QMap< QString, MacroWindow* >::iterator i = macros.begin();
+ Macros::iterator i = macros.begin();
while(i != macros.end()) {
- MacroWindow *m1 = i.value();
-
- QMap< QString, MacroWindow* >::iterator j = macros.begin();
+ Macro &_m1 = i.value();
+ MacroWindow *m1 = _m1.window;
+
+ Macros::iterator j = macros.begin();
while(j != macros.end()) {
- MacroWindow *m2 = j.value();
+ Macro &_m2 = j.value();
+ MacroWindow *m2 = _m2.window;
- if(m1 != m2 && m2->isstatic == false) {
+ if(m1 && m2 && m1 != m2 && _m2.isstatic == false) {
// Remove old connection (if any), to avoid multiple connections.
disconnect(m1, SIGNAL(expanding()), m2, SLOT(collapseWrapper()));