Toolbar is now toggleable from menu.
[mussa.git] / qui / PathWindow.cxx
1 #include "qui/PathWindow.h"
2
3 #include <QAction>
4 #include <QDir>
5 #include <QFileDialog>
6 #include <QIcon>
7 #include <QMenuBar>
8 #include <QMessageBox>
9 #include <QStatusBar>
10 #include <QString>
11 #include <QToolBar>
12
13 #include "qui/PathScene.h"
14 #include "qui/ThresholdWidget.h"
15
16 #include <iostream>
17
18 PathWindow::PathWindow(QWidget *) :
19   closeAction(0) // initialize one of the pointers to null as a saftey flag
20 {
21   setupActions();
22   setupMainMenu();
23
24   scene = new PathScene(10000, 10, this);
25   setCentralWidget(scene);
26
27   mussaViewTB = new QToolBar("Path Views");
28   mussaViewTB->addAction(toggleMotifsAction);
29
30   ThresholdWidget *threshold = new ThresholdWidget;
31   threshold->setRange(21, 30);
32   scene->setClipPlane(21);
33   connect(threshold, SIGNAL(thresholdChanged(int)),
34           scene, SLOT(setClipPlane(int)));
35   mussaViewTB->addWidget(threshold);
36   addToolBar(mussaViewTB);
37
38   statusBar()->showMessage("Welcome to mussa", 2000);
39 }
40
41 void PathWindow::setupActions()
42 {
43   // we really don't want to run this more than once.
44   assert (closeAction == 0);
45
46   // the ever popular about box
47   aboutAction = new QAction(tr("&About"), this);
48   connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
49
50   // add exit
51   closeAction = new QAction(tr("&Close"), this);
52   closeAction->setStatusTip(tr("Close this window"));
53   connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
54   
55   createNewAnalysisAction = new QAction(tr("Define Analysis"), this);
56   connect(createNewAnalysisAction, SIGNAL(triggered()), 
57           this, SLOT(createNewAnalysis()));
58   
59   createSubAnalysisAction = new QAction(tr("Define SubAnalysis"), this);
60   connect(createSubAnalysisAction, SIGNAL(triggered()), 
61           this, SLOT(createSubAnalysis()));
62
63   loadMotifListAction = new QAction(tr("Load Motif List"), this);
64   connect(loadMotifListAction, SIGNAL(triggered()), 
65           this, SLOT(loadMotifList()));
66   
67   loadMupaAction = new QAction(tr("Load Mussa Parameters"), this);
68   connect(loadMupaAction, SIGNAL(triggered()), 
69           this, SLOT(loadMupa()));
70
71   loadSavedAnalysisAction = new QAction(tr("Load &Analysis"), this);
72   connect(loadSavedAnalysisAction, SIGNAL(triggered()), 
73           this, SLOT(loadSavedAnalysis()));
74
75   saveMotifListAction = new QAction(tr("Save Motifs"), this);
76   connect(saveMotifListAction, SIGNAL(triggered()), 
77           this, SLOT(saveMotifList()));
78
79   showMussaViewToolbarAction = new QAction(tr("Show Toolbar"), this);
80   connect(showMussaViewToolbarAction, SIGNAL(triggered()), 
81           this, SLOT(showMussaToolbar()));
82   showMussaViewToolbarAction->setCheckable(true);
83   showMussaViewToolbarAction->setChecked(true);
84
85   toggleMotifsAction = new QAction(tr("Toggle Motifs"), this);
86   connect(toggleMotifsAction, SIGNAL(triggered()), 
87           this, SLOT(toggleMotifs()));
88
89   toggleMotifsAction->setCheckable(true);
90   toggleMotifsAction->setIcon(QIcon("icons/motif_icon.png"));
91 }
92
93 void PathWindow::setupMainMenu()
94 {
95   // we need to run setupActions first
96   assert (closeAction != 0);
97   
98   QMenu *newMenu;
99   newMenu = menuBar()->addMenu(tr("&File"));
100   newMenu->addAction(createNewAnalysisAction);
101   newMenu->addAction(loadMupaAction);
102   newMenu->addAction(loadSavedAnalysisAction);
103   newMenu->addAction(createSubAnalysisAction);
104   newMenu->addSeparator();
105   newMenu->addAction(loadMotifListAction);
106   newMenu->addAction(saveMotifListAction);
107   newMenu->addSeparator();
108   newMenu->addAction(closeAction);
109
110   newMenu = menuBar()->addMenu(tr("&View"));
111   newMenu->addAction(showMussaViewToolbarAction);
112
113   newMenu = menuBar()->addMenu(tr("&Help"));
114   newMenu->addAction(aboutAction);
115 }
116   
117 void PathWindow::about()
118 {
119   QMessageBox::about(this, tr("About mussa"),
120       tr("Welcome to Multiple Species Sequence Analysis\n"
121          "(c) 2005-2006 California Institute of Technology\n"
122          "Tristan De Buysscher, Diane Trout\n"));
123 }
124
125 void PathWindow::createNewAnalysis()
126 {
127   NotImplementedBox();
128 }
129
130 void PathWindow::createSubAnalysis()
131 {
132   NotImplementedBox();
133 }
134
135 void PathWindow::loadMotifList()
136 {
137   NotImplementedBox();
138 }
139
140 void PathWindow::loadMupa()
141 {
142   QString caption("Load a mussa parameter file");
143   QString filter("Mussa Parameters (*.mupa)");
144   QString mupa_path = QFileDialog::getOpenFileName(this,
145                                                    caption, 
146                                                    QDir::currentPath(),
147                                                    filter);
148   mussaAnalysis.load_mupa_file(mupa_path.toStdString());
149 }
150
151 void PathWindow::loadSavedAnalysis()
152 {
153   NotImplementedBox();
154 }
155
156 void PathWindow::saveMotifList()
157 {
158   NotImplementedBox();
159 }
160
161 void PathWindow::showMussaToolbar()
162 {
163   std::clog << "isVis?" << mussaViewTB->isVisible() <<std::endl;
164   if (mussaViewTB->isVisible())
165     mussaViewTB->hide();
166   else
167     mussaViewTB->show();
168   std::clog << "isVis?" << mussaViewTB->isVisible() <<std::endl;
169 }
170
171 void PathWindow::toggleMotifs()
172 {
173   NotImplementedBox();
174 }
175
176 void PathWindow::NotImplementedBox()
177 {
178   QMessageBox::warning(this, QObject::tr("mussa"), QObject::tr("Not implemented yet"));
179 }      
180
181