1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  *
16  * Author: John Abraham <john.abraham.in@gmail.com>
17  */
18 #include "netanim.h"
19 #include "animatormode.h"
20 #include "statsmode.h"
21 #include "packetsmode.h"
22 #ifdef WITH_NS3
23 #include "designer/designermode.h"
24 #endif
25 
26 namespace netanim
27 {
28 
NetAnim()29 NetAnim::NetAnim ():
30   m_tabWidget (new QTabWidget)
31 {
32 
33   AnimatorMode * animatorTab = AnimatorMode::getInstance ();
34   m_tabWidget->addTab (animatorTab->getCentralWidget (), animatorTab->getTabName ());
35   m_TabMode[0] = animatorTab;
36 
37 
38   StatsMode * statsTab = StatsMode::getInstance ();
39   m_tabWidget->addTab (statsTab->getCentralWidget (), statsTab->getTabName ());
40   m_TabMode[1] = statsTab;
41 
42 
43   PacketsMode * packetsTab = PacketsMode::getInstance ();
44   m_tabWidget->addTab (packetsTab->getCentralWidget (), packetsTab->getTabName ());
45   m_TabMode[2] = packetsTab;
46 
47 #ifdef WITH_NS3
48   DesignerMode * designerMode = new DesignerMode;
49   m_tabWidget->addTab (designerMode->getCentralWidget (), designerMode->getTabName ());
50 #endif
51   QObject::connect (m_tabWidget, SIGNAL (currentChanged (int)), this, SLOT (currentTabChangedSlot (int)));
52   m_tabWidget->setCurrentIndex (0);
53   QRect geometry = QApplication::desktop ()->screenGeometry ();
54   int minimumDimension = std::min (geometry.width (), geometry.height ());
55   m_tabWidget->setGeometry (0, 0, minimumDimension, minimumDimension);
56   m_tabWidget->showMaximized ();
57   m_tabWidget->show ();
58   animatorTab->start ();
59 }
60 
61 
62 void
currentTabChangedSlot(int currentIndex)63 NetAnim::currentTabChangedSlot (int currentIndex)
64 {
65   for (TabIndexModeMap_t::const_iterator i = m_TabMode.begin ();
66       i != m_TabMode.end ();
67       ++i)
68     {
69       if (currentIndex == i->first)
70         {
71           i->second->setFocus (true);
72           continue;
73         }
74       i->second->setFocus (false);
75     }
76 
77 }
78 
79 QTabWidget *
getTabWidget()80 NetAnim::getTabWidget()
81 {
82   return m_tabWidget;
83 }
84 
85 } // namespace netanim
86 
87