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