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