Crystal Icons added to repository + Added icons to 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   aboutAction->setIcon(QIcon("icons/info.png"));
50
51   // add exit
52   closeAction = new QAction(tr("&Close"), this);
53   closeAction->setStatusTip(tr("Close this window"));
54   connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
55   closeAction->setIcon(QIcon("icons/exit.png"));
56   
57   createNewAnalysisAction = new QAction(tr("Define Analysis"), this);
58   connect(createNewAnalysisAction, SIGNAL(triggered()), 
59           this, SLOT(createNewAnalysis()));
60   createNewAnalysisAction->setIcon(QIcon("icons/filenew.png"));
61   
62   createSubAnalysisAction = new QAction(tr("Define SubAnalysis"), this);
63   connect(createSubAnalysisAction, SIGNAL(triggered()), 
64           this, SLOT(createSubAnalysis()));
65
66   loadMotifListAction = new QAction(tr("Load Motif List"), this);
67   connect(loadMotifListAction, SIGNAL(triggered()), 
68           this, SLOT(loadMotifList()));
69   
70   loadMupaAction = new QAction(tr("Load Mussa Parameters"), this);
71   connect(loadMupaAction, SIGNAL(triggered()), 
72           this, SLOT(loadMupa()));
73
74   loadSavedAnalysisAction = new QAction(tr("Load &Analysis"), this);
75   connect(loadSavedAnalysisAction, SIGNAL(triggered()), 
76           this, SLOT(loadSavedAnalysis()));
77   loadSavedAnalysisAction->setIcon(QIcon("icons/fileopen.png"));
78
79   saveMotifListAction = new QAction(tr("Save Motifs"), this);
80   connect(saveMotifListAction, SIGNAL(triggered()), 
81           this, SLOT(saveMotifList()));
82   saveMotifListAction->setIcon(QIcon("icons/filesave.png"));
83
84   showMussaViewToolbarAction = new QAction(tr("Show Toolbar"), this);
85   connect(showMussaViewToolbarAction, SIGNAL(triggered()), 
86           this, SLOT(showMussaToolbar()));
87   showMussaViewToolbarAction->setCheckable(true);
88   showMussaViewToolbarAction->setChecked(true);
89
90   toggleMotifsAction = new QAction(tr("Toggle Motifs"), this);
91   connect(toggleMotifsAction, SIGNAL(triggered()), 
92           this, SLOT(toggleMotifs()));
93
94   toggleMotifsAction->setCheckable(true);
95   toggleMotifsAction->setIcon(QIcon("icons/motif_icon.png"));
96 }
97
98 void PathWindow::setupMainMenu()
99 {
100   // we need to run setupActions first
101   assert (closeAction != 0);
102   
103   QMenu *newMenu;
104   newMenu = menuBar()->addMenu(tr("&File"));
105   newMenu->addAction(createNewAnalysisAction);
106   newMenu->addAction(loadMupaAction);
107   newMenu->addAction(loadSavedAnalysisAction);
108   newMenu->addAction(createSubAnalysisAction);
109   newMenu->addSeparator();
110   newMenu->addAction(loadMotifListAction);
111   newMenu->addAction(saveMotifListAction);
112   newMenu->addSeparator();
113   newMenu->addAction(closeAction);
114
115   newMenu = menuBar()->addMenu(tr("&View"));
116   newMenu->addAction(showMussaViewToolbarAction);
117
118   newMenu = menuBar()->addMenu(tr("&Help"));
119   newMenu->addAction(aboutAction);
120 }
121   
122 void PathWindow::about()
123 {
124   QMessageBox::about(this, tr("About mussa"),
125       tr("Welcome to Multiple Species Sequence Analysis\n"
126          "(c) 2005-2006 California Institute of Technology\n"
127          "Tristan De Buysscher, Diane Trout\n"));
128 }
129
130 void PathWindow::createNewAnalysis()
131 {
132   NotImplementedBox();
133 }
134
135 void PathWindow::createSubAnalysis()
136 {
137   NotImplementedBox();
138 }
139
140 void PathWindow::loadMotifList()
141 {
142   NotImplementedBox();
143 }
144
145 void PathWindow::loadMupa()
146 {
147   QString caption("Load a mussa parameter file");
148   QString filter("Mussa Parameters (*.mupa)");
149   QString mupa_path = QFileDialog::getOpenFileName(this,
150                                                    caption, 
151                                                    QDir::currentPath(),
152                                                    filter);
153   mussaAnalysis.load_mupa_file(mupa_path.toStdString());
154 }
155
156 void PathWindow::loadSavedAnalysis()
157 {
158   NotImplementedBox();
159 }
160
161 void PathWindow::saveMotifList()
162 {
163   NotImplementedBox();
164 }
165
166 void PathWindow::showMussaToolbar()
167 {
168   std::clog << "isVis?" << mussaViewTB->isVisible() <<std::endl;
169   if (mussaViewTB->isVisible())
170     mussaViewTB->hide();
171   else
172     mussaViewTB->show();
173   std::clog << "isVis?" << mussaViewTB->isVisible() <<std::endl;
174 }
175
176 void PathWindow::toggleMotifs()
177 {
178   NotImplementedBox();
179 }
180
181 void PathWindow::NotImplementedBox()
182 {
183   QMessageBox::warning(this, QObject::tr("mussa"), QObject::tr("Not implemented yet"));
184 }      
185
186