]> ruin.nu Git - hbs.git/blob - bs/bsview.cpp
some minor ui changes
[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->setRootIsDecorated(true);  
52         m_NumberView->addColumn("Name");
53         m_NumberView->addColumn("Number");
54         m_NumberView->addColumn("ETA");
55         //addBattle("NO BATTLES");
56
57         m_InfoView = new InfoView(m_LeftSplit);
58         
59         //the right side
60         m_TickView = new TickView(m_RightSplit);
61         m_FleetViews = new QWidgetStack(m_RightSplit);
62         m_ScanView = new ScanView(m_RightSplit);
63         
64         //the widget stack
65         m_BattleSum = new BattleSum();
66         m_FleetViews->addWidget(m_BattleSum, 0);
67         m_FleetView = new FleetViewBase();
68         m_FleetViews->addWidget(m_FleetView, 1);
69
70         //m_FleetViews->raiseWidget(0);
71         connect(m_NumberView, SIGNAL(selectionChanged(QListViewItem *)), SLOT(slotFleetSelection(QListViewItem *))); 
72 }
73
74 BSView::~BSView()
75 {
76 }
77
78 //////////////////////////////////////////////////////////////////////////
79 //
80 void BSView::addBattle(QString name)
81 {
82         QListViewItem* battle = new QListViewItem(m_NumberView, name);
83         QListViewItem* def = new QListViewItem(battle, tr("Friendly"),"", "","1");
84         (void) new QListViewItem(battle, tr("Hostile"),"", "","2");
85         (void) new QListViewItem(def, tr("Home Planet"), "","","1");
86 }
87
88 ///////////////////////////////////////////////////////////////////////////////
89 //
90 /***This function clears the listview and then iterates through the battles
91  * and recreates the listview hierarchy.
92  */
93 void BSView::slotDocumentChanged()
94 {
95         m_NumberView->clear();
96         
97         map<QString, map<QString, map<QString, Fleet> > >& battles = m_doc->Battles();  
98
99         for (map<QString, map<QString, map<QString, Fleet> > >::iterator i = battles.begin(); i != battles.end(); i++)
100         {
101                 QString b = (*i).first;
102                 QListViewItem* battle = new QListViewItem(m_NumberView, b);
103
104                 for (map<QString, map<QString, Fleet> >::iterator j = battles[b].begin(); j != battles[b].end(); j++)
105                 {
106                         QString g = (*j).first;
107                         QListViewItem* group = new QListViewItem(battle, g);
108
109                         for (map<QString, Fleet>::iterator k = battles[b][g].begin(); k != battles[b][g].end(); k++)
110                         {                               
111                                 (void) new QListViewItem(group, (*k).first);
112                         }
113                 }
114         }
115 }
116
117 //////////////////////////////////////////////////////////////////////////////
118 //
119 void BSView::slotFleetSelection(QListViewItem *lvi)
120 {
121         //cout << lvi->parent()->text(2).toLocal8bit() << endl;
122 //      for (int i = 0; i < 5; i++)
123 //              cout << lvi->text(i).local8Bit() << endl;
124         
125
126         if (lvi->parent() == '\0')
127         {
128                 m_FleetViews->raiseWidget(0);
129         }
130         else if (lvi->parent()->parent() == '\0')
131         {
132                         m_FleetView->slotHomePlanet(false);
133                 if (lvi->text(0) == tr("Friendly"))
134                 {
135                         m_FleetView->slotAttacker(false);
136                 }
137                 else
138                 {
139                         m_FleetView->slotAttacker(true);
140                 }
141                 m_FleetViews->raiseWidget(1);
142                 
143         }
144         else
145         {
146                 if (lvi->parent()->text(0) == tr("Friendly"))
147                 {
148                         m_FleetView->slotAttacker(false);
149                         m_FleetView->slotHomePlanet(false);
150                         if (lvi->text(0) == tr("Home Planet"))
151                         {
152                                 m_FleetView->slotHomePlanet(true);
153                         }
154                 }
155                 else
156                 {
157                         m_FleetView->slotAttacker(true);
158                         m_FleetView->slotHomePlanet(false);
159                 }
160                 m_FleetViews->raiseWidget(1);
161                                 
162         }
163
164         
165 }