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