There can be only one (filename convention)
[mussa.git] / qui / PathWindow.cpp
1 #include <QAction>
2 #include <QDir>
3 #include <QFileDialog>
4 #include <QHBoxLayout>
5 #include <QIcon>
6 #include <QMenuBar>
7 #include <QMessageBox>
8 #include <QScrollBar>
9 #include <QSpinBox>
10 #include <QStatusBar>
11 #include <QString>
12 #include <QToolBar>
13 #include <QWhatsThis>
14
15 #include "qui/PathScene.hpp"
16 #include "qui/PathWidget.hpp"
17 #include "qui/PathWindow.hpp"
18 #include "qui/ThresholdWidget.hpp"
19 #include "qui/ImageSaveDialog.hpp"
20
21 #include <iostream>
22
23 PathWindow::PathWindow(Mussa *analysis, QWidget *) :
24   closeAction(0) // initialize one of the pointers to null as a saftey flag
25 {
26   scene = new PathScene(analysis, this);
27
28   setupActions();
29   setupMainMenu();
30
31   //This next setWhatsThis function prevents
32   // a segfault when using WhatsThis feature with 
33   // opengl widget.
34   scene->setWhatsThis(tr("Mussa in OpenGL!"));
35   // make a widget so we can have a scroll bar
36   PathWidget *path_widget = new PathWidget(scene, this);
37   setCentralWidget(path_widget);
38
39   mussaViewTB = new QToolBar("Path Views");
40   mussaViewTB->addAction(toggleMotifsAction);
41
42   QSpinBox *zoom = new QSpinBox();
43   zoom->setWhatsThis("zoom magnification factor");
44   zoom->setRange(2,1000);
45   mussaViewTB->addWidget(zoom);
46   connect(zoom, SIGNAL(valueChanged(int)), scene, SLOT(setZoom(int)));
47   
48   ThresholdWidget *threshold = new ThresholdWidget;
49   threshold->setRange(19, 30);
50   threshold->setThreshold(19);
51   scene->setClipPlane(20);
52   // FIXME: for when we get the paths drawn at the appropriate depth
53   //connect(threshold, SIGNAL(thresholdChanged(int)),
54   //        scene, SLOT(setClipPlane(int)));
55   connect(threshold, SIGNAL(thresholdChanged(int)),
56           scene, SLOT(setSoftThreshold(int)));
57   mussaViewTB->addWidget(threshold);
58
59   //Image Save Dialog
60   imageSaveDialog = new ImageSaveDialog(scene, this);
61
62   addToolBar(mussaViewTB);
63
64   statusBar()->showMessage("Welcome to mussa", 2000);
65 }
66
67 void PathWindow::setupActions()
68 {
69   // we really don't want to run this more than once.
70   assert (closeAction == 0);
71
72   // the ever popular about box
73   aboutAction = new QAction(tr("&About"), this);
74   connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
75   aboutAction->setIcon(QIcon("icons/info.png"));
76
77   // add exit
78   closeAction = new QAction(tr("&Close"), this);
79   closeAction->setStatusTip(tr("Close this window"));
80   connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
81   closeAction->setIcon(QIcon("icons/exit.png"));
82   
83   createNewAnalysisAction = new QAction(tr("Define Analysis"), this);
84   connect(createNewAnalysisAction, SIGNAL(triggered()), 
85           this, SLOT(createNewAnalysis()));
86   createNewAnalysisAction->setIcon(QIcon("icons/filenew.png"));
87   
88   createSubAnalysisAction = new QAction(tr("Define SubAnalysis"), this);
89   connect(createSubAnalysisAction, SIGNAL(triggered()), 
90           this, SLOT(createSubAnalysis()));
91
92   loadMotifListAction = new QAction(tr("Load Motif List"), this);
93   connect(loadMotifListAction, SIGNAL(triggered()), 
94           this, SLOT(loadMotifList()));
95   
96   loadMupaAction = new QAction(tr("Load Mussa Parameters"), this);
97   connect(loadMupaAction, SIGNAL(triggered()), 
98           scene, SLOT(loadMupa()));
99
100   loadSavedAnalysisAction = new QAction(tr("Load &Analysis"), this);
101   connect(loadSavedAnalysisAction, SIGNAL(triggered()), 
102           scene, SLOT(loadSavedAnalysis()));
103   loadSavedAnalysisAction->setIcon(QIcon("icons/fileopen.png"));
104
105   saveMotifListAction = new QAction(tr("Save Motifs"), this);
106   connect(saveMotifListAction, SIGNAL(triggered()), 
107           this, SLOT(saveMotifList()));
108   saveMotifListAction->setIcon(QIcon("icons/filesave.png"));
109
110   showMussaViewToolbarAction = new QAction(tr("Show Toolbar"), this);
111   connect(showMussaViewToolbarAction, SIGNAL(triggered()), 
112           this, SLOT(showMussaToolbar()));
113   showMussaViewToolbarAction->setCheckable(true);
114   showMussaViewToolbarAction->setChecked(true);
115
116   toggleMotifsAction = new QAction(tr("Toggle Motifs"), this);
117   connect(toggleMotifsAction, SIGNAL(triggered()), 
118           this, SLOT(toggleMotifs()));
119   toggleMotifsAction->setCheckable(true);
120   toggleMotifsAction->setIcon(QIcon("icons/motif_icon.png"));
121   toggleMotifsAction->setWhatsThis(tr("Toggle motif annotations on/off\n\n"
122                                    "You can load motif annotations via "
123                                    "'File->Load Motif List' menu option."));
124
125   whatsThisAction = QWhatsThis::createAction(this);
126   whatsThisAction->setIcon(QIcon("icons/help.png"));
127
128   //Save pixel map action
129   saveOpenGlPixmapAction = new QAction(tr("Save to image..."), this);
130   connect(saveOpenGlPixmapAction, (SIGNAL(triggered())),
131           this, SLOT(promptSaveOpenGlPixmap()));
132   saveOpenGlPixmapAction->setIcon(QIcon("icons/image2.png"));
133 }
134
135 void PathWindow::setupMainMenu()
136 {
137   // we need to run setupActions first
138   assert (closeAction != 0);
139   
140   QMenu *newMenu;
141   newMenu = menuBar()->addMenu(tr("&File"));
142   newMenu->addAction(createNewAnalysisAction);
143   newMenu->addAction(loadMupaAction);
144   newMenu->addAction(loadSavedAnalysisAction);
145   newMenu->addAction(createSubAnalysisAction);
146   newMenu->addSeparator();
147   newMenu->addAction(loadMotifListAction);
148   newMenu->addAction(saveMotifListAction);
149   newMenu->addSeparator();
150   newMenu->addAction(saveOpenGlPixmapAction);
151   newMenu->addSeparator();
152   newMenu->addAction(closeAction);
153
154   newMenu = menuBar()->addMenu(tr("&View"));
155   newMenu->addAction(showMussaViewToolbarAction);
156
157   newMenu = menuBar()->addMenu(tr("&Help"));
158   newMenu->addAction(whatsThisAction);
159   newMenu->addSeparator();
160   newMenu->addAction(aboutAction);
161 }
162   
163 void PathWindow::about()
164 {
165   QMessageBox::about(this, tr("About mussa"),
166       tr("Welcome to Multiple Species Sequence Analysis\n"
167          "(c) 2005-2006 California Institute of Technology\n"
168          "Tristan De Buysscher, Diane Trout\n"));
169 }
170
171 void PathWindow::createNewAnalysis()
172 {
173   NotImplementedBox();
174 }
175
176 void PathWindow::createSubAnalysis()
177 {
178   NotImplementedBox();
179 }
180
181 void PathWindow::loadMotifList()
182 {
183   NotImplementedBox();
184 }
185
186 void PathWindow::saveMotifList()
187 {
188   NotImplementedBox();
189 }
190
191 void PathWindow::showMussaToolbar()
192 {
193   std::clog << "isVis?" << mussaViewTB->isVisible() <<std::endl;
194   if (mussaViewTB->isVisible())
195     mussaViewTB->hide();
196   else
197     mussaViewTB->show();
198   std::clog << "isVis?" << mussaViewTB->isVisible() <<std::endl;
199 }
200
201 void PathWindow::toggleMotifs()
202 {
203   NotImplementedBox();
204 }
205
206 void PathWindow::NotImplementedBox()
207 {
208   QMessageBox::warning(this, QObject::tr("mussa"), QObject::tr("Not implemented yet"));
209 }      
210
211 void PathWindow::promptSaveOpenGlPixmap()
212 {
213   QSize size;
214   size = scene->size();
215   imageSaveDialog->setSize(size.width(), size.height());
216   int result = imageSaveDialog->exec();
217   std::cout << "Result: " << result << "\n";
218 }
219