]> ruin.nu Git - hbs.git/blob - bs/bsview.cpp
Added the possibility to add new battles.
[hbs.git] / bs / bsview.cpp
1 /***************************************************************************
2                           bcview.cpp  -  description
3                              -------------------
4     begin                : Sun Jun 17 19:19:58 CEST 2001
5     copyright            : (C) 2001 by Michael Andreen
6     email                : whale@linux.nu
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #include "bsview.h"
19
20 //standard library
21 #include <iostream>
22 #include <map>
23 #include <vector>
24 #include <string>
25
26 using namespace std;
27
28 //QT includes
29 #include <qlistview.h>
30 #include <qwidgetstack.h>
31
32 #include "battlesum.h"
33 #include "scanview.h"
34 #include "ui/infoview.h"
35 #include "tickview.h"
36 #include "ui/fleetviewbase.h"
37 #include "fleet.h"
38
39 BSView::BSView(QWidget *parent, BSDoc *doc) : QSplitter(parent)
40 {
41   /** connect doc with the view*/
42   connect(doc, SIGNAL(documentChanged()), this, SLOT(slotDocumentChanged()));
43         
44         m_doc = doc;
45         
46         m_LeftSplit = new QSplitter(QSplitter::Vertical, this);
47         m_RightSplit = new QSplitter(QSplitter::Vertical, this);
48
49         //setting up the listview
50         m_NumberView = new QListView(m_LeftSplit);
51         m_NumberView->addColumn("Name");
52         m_NumberView->addColumn("Number");
53         m_NumberView->addColumn("ETA");
54         addBattle("test");
55
56         m_InfoView = new InfoView(m_LeftSplit);
57         
58         //the right side
59         m_TickView = new TickView(m_RightSplit);
60         m_FleetViews = new QWidgetStack(m_RightSplit);
61         m_ScanView = new ScanView(m_RightSplit);
62         
63         //the widget stack
64         m_BattleSum = new BattleSum();
65         m_FleetViews->addWidget(m_BattleSum, 0);
66         m_FleetView = new FleetViewBase();
67         m_FleetViews->addWidget(m_FleetView, 1);
68
69         //m_FleetViews->raiseWidget(0);
70         connect(m_NumberView, SIGNAL(selectionChanged(QListViewItem *)), SLOT(slotFleetSelection(QListViewItem *))); 
71 }
72
73 BSView::~BSView()
74 {
75 }
76
77 //////////////////////////////////////////////////////////////////////////
78 //
79 void BSView::addBattle(QString name)
80 {
81         QListViewItem* battle = new QListViewItem(m_NumberView, name);
82         QListViewItem* def = new QListViewItem(battle, tr("Defenders"),"", "","1");
83         (void) new QListViewItem(battle, tr("Attackers"),"", "","2");
84         (void) new QListViewItem(def, tr("Home Planet"), "","","1");
85 }
86
87 ///////////////////////////////////////////////////////////////////////////////
88 //
89 /***This function clears the listview and then iterates through the battles
90  * and recreates the listview hierarchy.
91  */
92 void BSView::slotDocumentChanged()
93 {
94         m_NumberView->clear();
95         
96         map<QString, map<QString, map<QString, Fleet> > >& battles = m_doc->Battles();  
97
98         for (map<QString, map<QString, map<QString, Fleet> > >::iterator i = battles.begin(); i != battles.end(); i++)
99         {
100                 QString b = (*i).first;
101                 QListViewItem* battle = new QListViewItem(m_NumberView, b);
102
103                 for (map<QString, map<QString, Fleet> >::iterator j = battles[b].begin(); j != battles[b].end(); j++)
104                 {
105                         QString g = (*j).first;
106                         QListViewItem* group = new QListViewItem(battle, g);
107
108                         for (map<QString, Fleet>::iterator k = battles[b][g].begin(); k != battles[b][g].end(); k++)
109                         {                               
110                                 (void) new QListViewItem(group, (*k).first);
111                         }
112                 }
113         }
114 }
115
116 //////////////////////////////////////////////////////////////////////////////
117 //
118 void BSView::slotFleetSelection(QListViewItem *lvi)
119 {
120         //cout << lvi->parent()->text(2).toLocal8bit() << endl;
121 //      for (int i = 0; i < 5; i++)
122 //              cout << lvi->text(i).local8Bit() << endl;
123         
124
125         if (lvi->parent() == '\0')
126         {
127                 m_FleetViews->raiseWidget(0);
128         }
129         else if (lvi->parent()->parent() == '\0')
130         {
131                         m_FleetView->slotHomePlanet(false);
132                 if (lvi->text(0) == tr("Friendly"))
133                 {
134                         m_FleetView->slotAttacker(false);
135                 }
136                 else
137                 {
138                         m_FleetView->slotAttacker(true);
139                 }
140                 m_FleetViews->raiseWidget(1);
141                 
142         }
143         else
144         {
145                 if (lvi->parent()->text(0) == tr("Friendly"))
146                 {
147                         m_FleetView->slotAttacker(false);
148                         m_FleetView->slotHomePlanet(false);
149                         if (lvi->text(0) == tr("Home Planet"))
150                         {
151                                 m_FleetView->slotHomePlanet(true);
152                         }
153                 }
154                 else
155                 {
156                         m_FleetView->slotAttacker(true);
157                         m_FleetView->slotHomePlanet(false);
158                 }
159                 m_FleetViews->raiseWidget(1);
160                                 
161         }
162
163         
164 }