forked from josiahseaman/skittle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.cpp
562 lines (479 loc) · 20.3 KB
/
MainWindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
#include <QtGui>
#include <QScrollArea>
#include <QtGui/QScrollBar>
#include <QtGui/QCheckBox>
#include <QtCore/QProcess>
#include <QtCore/QStringList>
#include <iostream>
#include <string>
#include <sstream>
#include "MainWindow.h"
#include "FastaReader.h"
#include "GtfReader.h"
#include "glwidget.h"
#include "AbstractGraph.h"
#include "NucleotideDisplay.h"
#include "RepeatMap.h"
#include "AnnotationDisplay.h"
#include "CylinderDisplay.h"
#include "RepeatOverviewDisplay.h"
#include "OligomerDisplay.h"
#include "HighlightDisplay.h"
#include "ViewManager.h"
#include "TextureCanvas.h"
/** *******************************************
MainWindow is the primary UI frame for Qt Widgets. It is the master window
that the OS interfaces with. It contains a series of QToolBar with the UI elements
that can be moved around by the user (Visualization Graphs, Mouse Tools,
Sequence View Settings, File Actions, Information Display).
These same buttons are tied to actions which can be triggered from the standard window
menu bar in all applications. The arrangement of buttons on the screen is remembered
between instances of the program as a user preference.
In addition to the actions, buttons and layout, all the logic for internal connections
is within: createUiConnections(), createFileConnections() and addDisplayActions().
Window Hierarchy:
MainWindow -> (1) Viewmanager -> (many) MdiChildWindow -> (1) GLWidget -> (1)FastaReader -> (1)File
MainWindow is at the top of a window hierarchy. The center widget of MainWindow is a single
ViewManager which inherits from MdiArea. The multiple document interface (MDI) can have multiple
MdiChildWindows. Each MdiChildWindow has only one GLWidget tied to one file. MainWindow is
the primary owner of the UiVariables object that is passed for signals all throughout the program.
********************************************/
MainWindow::MainWindow()
{
textArea = NULL;
setDockOptions(QMainWindow::AllowNestedDocks|QMainWindow::AllowTabbedDocks|QMainWindow::AnimatedDocks);
setWindowTitle( "Skittle Genome Visualizer");
createDocks();
createUiVars();
createActions();
createMenus();
createToolbars();
createStatusBar();
createUiConnections();
readSettings();
viewManager = new ViewManager(this, ui);
setCentralWidget(viewManager);
createFileConnections();
ensureDocksAreVisible();
setWindowIcon(QIcon(":/skittle.svg"));
//openAction->trigger();
}
void MainWindow::addDisplayActions(AbstractGraph* display)
{
if(display->actionLabel.size() > 0)
{
QAction* presetAction = new QAction(QString(display->actionLabel.c_str()),this);
presetAction->setStatusTip(QString(display->actionTooltip.c_str()));
presetAction->setToolTip(QString(display->actionTooltip.c_str()));
//presetAction->setData(QString(display->actionData.c_str()));
display->toggleButton = presetAction;
connect(presetAction,SIGNAL(triggered()),display, SLOT(toggleVisibility()));
connect(display, SIGNAL(deleteButton(QAction*)), this, SLOT(removeGraphButton(QAction*)));
//this section of code inserts a new displayAction at the beginning of the list, rather than appending it
//this is for the sake of the AnnotationDisplays which are added last and listed first
presetMenu->addAction(presetAction);
QAction* before = NULL;
QList<QAction*> list = presetToolBar->actions();
if(!list.isEmpty())
before = list.first();
presetToolBar->insertAction(before, presetAction);
display->setButtonFont();
}
else
{
print("Tried to add display mode with no label, aborting...");
}
}
void MainWindow::showUpdateButton()
{
updateSkittle->setVisible(true);
connect(updateSkittle, SIGNAL(triggered()), this, SLOT(closeAndUpdateSkittle()));
}
void MainWindow::closeAndUpdateSkittle()
{
print("Update command received.");
QString program = QString("Skittle.exe");
QStringList arguments;
arguments<<"update";
/* Create a QProcess instance. It does not matter if it is created on the stack or
* on the heap. - Ahem, I tested it on Linux only. :-)*/
QProcess* updateProcess = new QProcess();
updateProcess->start(program, arguments);
this->close();
}
void MainWindow::removeGraphButton(QAction* presetAction)
{
presetMenu->removeAction(presetAction);
presetToolBar->removeAction(presetAction);
}
void MainWindow::addDisplayDivider()
{
presetToolBar->addSeparator();
}
void MainWindow::createUiVars()
{
settingToolBar = addToolBar("Sequence View Settings");
settingToolBar->setObjectName("Sequence View Settings");
QFont boldFont = QFont();
boldFont.setBold(true);
QLabel* activeW = new QLabel("Active Window:");
activeW->setFont(boldFont);
settingToolBar->addWidget(activeW);
settingToolBar->addSeparator();
//Note:Creating the visual representation of UiVariables is split between Mainwindow and the UiVariables constructor
ui = UiVariables::Instance();
ui->textArea = textArea;
vector<QSpinBox*> dials = ui->getDialPointers();
int i = 0;
settingToolBar->addWidget(new QLabel("Width"));
settingToolBar->addWidget(dials[i++]);
doubleDisplayWidth = new QPushButton("x2",this);
settingToolBar->addWidget(doubleDisplayWidth);
halveDisplayWidth = new QPushButton("/2",this);
settingToolBar->addWidget(halveDisplayWidth);
zoomExtents = new QPushButton("Scale to \nChromosome",this);
settingToolBar->addWidget(zoomExtents);
settingToolBar->addWidget(new QLabel("Scale"));
settingToolBar->addWidget(dials[i++]);
settingToolBar->addWidget(new QLabel("Zoom"));
settingToolBar->addWidget(dials[i++]);
settingToolBar->addWidget(new QLabel("Start Index"));
settingToolBar->addWidget(dials[i++]);
settingToolBar->addWidget(new QLabel("Display Length"));
settingToolBar->addWidget(dials[i++]);
//settingToolBar->addSeparator();
QLabel* multiW = new QLabel("Multiple Windows:");
multiW->setFont(boldFont);
settingToolBar->addWidget(multiW);
settingToolBar->addSeparator();
//QActionGroup* multiGroup = new QActionGroup(this);
settingToolBar->addWidget( new QLabel("Offsets:"));
}
void MainWindow::createActions()
{
moveAction = new QAction("Move",this);
moveAction->setToolTip(QString("Horizontal and vertical scroll"));
resizeAction = new QAction("Resize",this);
resizeAction->setToolTip(QString("Adjust Width and Start position"));
zoomAction = new QAction("Zoom",this);
zoomAction->setToolTip(QString("Shift+Click to zoom out"));
selectAction = new QAction("Select",this);
selectAction->setToolTip(QString("Displays index and sequence information"));
addAnnotationAction = new QAction("Annotate",this);
addAnnotationAction->setToolTip(QString("Select a region and enter text to create a new annotation in ..skittle_notes.gtf"));
findAction = new QAction("&Find",this);
screenCaptureAction = new QAction("Screen &Capture", this);
screenCaptureAction->setToolTip(QString("Take a screen shot"));
nextAnnotationAction = new QAction("Next Annotation",this);
prevAnnotationAction = new QAction("Previous Annotation",this);
//browseCommunityAction = new QAction("Browse Community Research",this);
//delAnnotationAction = new QAction("Delete Current Bookmark",this);
/*****TODO: NOT CURRENTLY IN USE ********/
findSequenceAction = new QAction("Find Sequence",this);
findSequenceAction->setStatusTip("Find Arbitrary Sequence");
findNextAction = new QAction("Find Next", this);
findNextAction->setStatusTip("Jump to Next Instance of Current Sequence");
findPrevAction = new QAction("Find Previous", this);
findPrevAction->setStatusTip("Jump to Previous Instance of Current Sequence");
QIcon uIcon = QIcon(":/updatebutton.png");
updateSkittle =new QAction(uIcon, QString("Click here to update"), this);
updateSkittle->setVisible(false);
addViewAction = new QAction("New Window",this);
openAction = new QAction("&Open File",this);
openAction->setStatusTip("Open a Sequence File");
openGtfAction = new QAction("Open Annotation",this);
openGtfAction->setStatusTip("Open GTF / GFF Annotation File");
exitAction = new QAction("E&xit",this);
helpAction = new QAction("Online &Help",this);
aboutQtAct = new QAction("About Qt", this);
exitAction->setStatusTip("Close Program");
}
void MainWindow::createMenus()
{
fileMenu = menuBar()->addMenu("&File");
fileMenu->addAction(openAction);
fileMenu->addAction(addViewAction);
fileMenu->addSeparator();
fileMenu->addAction(openGtfAction);
fileMenu->addAction(screenCaptureAction);
fileMenu->addAction(exitAction);
/*searchMenu = menuBar()->addMenu("&Search");
searchMenu->addAction(findSequenceAction);
searchMenu->addAction(findNextAction);
searchMenu->addAction(findPrevAction);*/
viewMenu = menuBar()->addMenu("&View");
presetMenu = viewMenu->addMenu("Visualization Graphs");
annotationMenu = menuBar()->addMenu("&Annotations");
annotationMenu->addAction(nextAnnotationAction);
annotationMenu->addAction(prevAnnotationAction);
//annotationMenu->addAction(browseCommunityAction);
//annotationMenu->addAction(delAnnotationAction);
toolMenu = menuBar()->addMenu("&Mouse Tools");
toolMenu->addAction(moveAction);
toolMenu->addAction(resizeAction);
toolMenu->addAction(zoomAction);
toolMenu->addAction(selectAction);
toolMenu->addAction(findAction);
toolMenu->addAction(addAnnotationAction);
toolActionGroup = new QActionGroup(this);
toolActionGroup->addAction(moveAction);
toolActionGroup->addAction(resizeAction);
toolActionGroup->addAction(zoomAction);
toolActionGroup->addAction(selectAction);
toolActionGroup->addAction(findAction);
toolActionGroup->addAction(addAnnotationAction);
colorSettingsMenu = menuBar()->addMenu("Color &Settings");
colorGroup = new QActionGroup( this );
QSignalMapper* signalMapper = new QSignalMapper(this);
connect(signalMapper, SIGNAL(mapped(int)), this, SIGNAL(colorSelected(int)));
connect(this, SIGNAL(colorSelected(int)), ui, SLOT(changeColorSetting(int)));
createColorPalleteAction(QString("Classic"), UiVariables::CLASSIC, QIcon(":/icons/classic.png"), colorGroup, signalMapper );
createColorPalleteAction(QString("Summer (Color Blind Safe)"), UiVariables::COLORBLINDSAFE, QIcon(":/icons/colorblindsafe.png"), colorGroup, signalMapper );
createColorPalleteAction(QString("Spring (Color Blind Safe)"), UiVariables::BETTERCBSAFE, QIcon(":/icons/colorblindsafe2.png"), colorGroup, signalMapper );
createColorPalleteAction(QString("Dark Classic"), UiVariables::DARK, QIcon(":/icons/dark.png"), colorGroup, signalMapper );
createColorPalleteAction(QString("DRuMS"), UiVariables::DRUMS, QIcon(":/icons/drums.png"), colorGroup, signalMapper );
createColorPalleteAction(QString("Blues"), UiVariables::BLUES, QIcon(":/icons/blues.png"), colorGroup, signalMapper );
createColorPalleteAction(QString("Reds"), UiVariables::REDS, QIcon(":/icons/reds.png"), colorGroup, signalMapper );
QMenu* helpMenu = menuBar()->addMenu("&Help");
helpMenu->addAction(helpAction);
helpMenu->addAction(aboutQtAct);
}
QAction* MainWindow::createColorPalleteAction(QString label, int colorPallete, QIcon palleteIcon, QActionGroup* group, QSignalMapper* signalMapper)
{
QAction* colorPalleteAction = new QAction (palleteIcon, label, this );
colorPalleteAction->setCheckable(true);
colorPalleteAction->setActionGroup(group);
colorSettingsMenu->addAction(colorPalleteAction);
signalMapper->setMapping(colorPalleteAction, colorPallete);
connect(colorPalleteAction, SIGNAL(triggered()), signalMapper, SLOT(map()));
return colorPalleteAction;
}
void MainWindow::createToolbars()
{
QFont boldFont = QFont();
boldFont.setBold(true);
fileToolBar = addToolBar("File Actions");
fileToolBar->setObjectName("file");
fileToolBar->setIconSize( QSize( 100, 20 ) );
fileToolBar->addAction(updateSkittle);
fileToolBar->addAction(openAction);
fileToolBar->addAction(addViewAction);
fileToolBar->addAction(openGtfAction);
fileToolBar->addAction(nextAnnotationAction);
fileToolBar->addAction(prevAnnotationAction);
fileToolBar->addAction(screenCaptureAction);
//annotationToolBar->addAction(browseCommunityAction);
//annotationToolBar->addAction(delAnnotationAction);
presetToolBar = new QToolBar("Visualization Graphs");
presetToolBar->setObjectName("Visualization Graphs");
presetToolBar->setOrientation(Qt::Horizontal);
toolToolBar = addToolBar("Mouse Tools");
toolToolBar->setObjectName("Mouse Tools");
toolToolBar->addAction(moveAction);
toolToolBar->addAction(resizeAction);
toolToolBar->addAction(zoomAction);
toolToolBar->addAction(selectAction);
toolToolBar->addAction(findAction);
toolToolBar->addAction(addAnnotationAction);
//previous location of createUiVars()
addToolBar(Qt::RightToolBarArea,presetToolBar);
addToolBar(Qt::LeftToolBarArea,toolToolBar);
addToolBar(Qt::LeftToolBarArea,fileToolBar);
addToolBar(Qt::TopToolBarArea,settingToolBar);
}
void MainWindow::ensureDocksAreVisible()
{
presetToolBar->setVisible(true);
toolToolBar->setVisible(true);
fileToolBar->setVisible(true);
settingToolBar->setVisible(true);
infoDock->setVisible(true);
}
void MainWindow::createDocks()
{
infoDock = new QDockWidget("Information Display", this);
infoDock->setObjectName("infodock");
infoDock->setAllowedAreas(Qt::AllDockWidgetAreas);
infoDock->setFeatures(QDockWidget::NoDockWidgetFeatures);//in particular we want to avoid Closable
infoDock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
tabWidget = new QTabWidget(infoDock);
infoDock->setWidget(tabWidget);
textArea = new QTextEdit(tabWidget);
tabWidget->addTab(textArea, QString("Text Output"));
addDockWidget(Qt::BottomDockWidgetArea, infoDock);
/*
QWidget *filters = new QWidget;
QVBoxLayout *filterLayout = new QVBoxLayout;
QTabWidget *tabWidget = new QTabWidget();
tabWidget->addTab(new QListWidget, "Presets");
//tabWidget->addTab(new QTreeView, "Advanced");
QTableWidget *propsWidget = new QTableWidget(4,3);
filterLayout->addWidget(tabWidget);
filterLayout->addWidget(propsWidget);
filters->setLayout(filterLayout);*/
}
void MainWindow::createStatusBar()
{
//QLabel *statusTip = new QLabel("This is a status Tip",this);
//QProgressBar *processStatus = new QProgressBar(this);
//processStatus->setMinimumWidth(300);
//processStatus->setMaximumWidth(300);
//processStatus->setValue(75);
//QLabel *processState = new QLabel("Loading...",this);
//statusBar()->addPermanentWidget(processStatus);
//statusBar()->addPermanentWidget(processState);
statusBar()->showMessage(tr("Ready"));
}
void MainWindow::createUiConnections()
{ /******Internal UI Logic*********/
connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
connect(helpAction, SIGNAL(triggered()), this, SLOT(helpDialog()));
connect(doubleDisplayWidth, SIGNAL(clicked()), this, SLOT(doubleWidth()));
connect(halveDisplayWidth, SIGNAL(clicked()), this, SLOT(halveWidth()));
// connect(zoomExtents, SIGNAL(clicked()), , SLOT(zoomExtents()));
}
void MainWindow::createFileConnections()
{
//Consider making this a function-call chain.... or handling this specifically, in a thread.
connect(openAction, SIGNAL(triggered()), this, SLOT(open()));
connect(this, SIGNAL(newFileOpen(QString)), viewManager, SLOT(changeFile(QString)));
connect(openGtfAction, SIGNAL(triggered()), this, SLOT(openGtf()));
connect(this, SIGNAL(newGtfFileOpen(QString)), viewManager, SLOT(addAnnotationDisplay(QString)));
connect(nextAnnotationAction, SIGNAL(triggered()), viewManager, SLOT(jumpToNextAnnotation()));
connect(prevAnnotationAction, SIGNAL(triggered()), viewManager, SLOT(jumpToPrevAnnotation()));
}
void MainWindow::open()
{
QString fileName = QFileDialog::getOpenFileName(
this,"Open Sequence File",
"",
"FASTA files (*.fa *.fasta);; Image files (*.png *.xpm *.jpg);; Text files (*.txt);; All files (*)"
);
if (!fileName.isEmpty())
emit newFileOpen(fileName);
}
void MainWindow::open(QString fileName)
{
if (!fileName.isEmpty())
emit newFileOpen(fileName);
}
void MainWindow::changeWindowName(std::string name)
{
string title = "Skittle Genome Visualizer";
title.append(name);
setWindowTitle( "Skittle Genome Visualizer");
}
void MainWindow::openGtf()
{
QString fileName = QFileDialog::getOpenFileName(this,"Open GTF File", "", tr("Annotation files (*.gtf *.gff);; Any files (*)"));
if (!fileName.isEmpty())
emit newGtfFileOpen(fileName);
}
void MainWindow::doubleWidth()
{
ui->setWidth( 2 * ui->getWidth() );
}
void MainWindow::halveWidth()
{
ui->setWidth( (int)(0.5 * ui->getWidth()) );
}
void MainWindow::updateProgress(int val)
{
//processStatus->setValue(val);
}
void MainWindow::updateState(QString state){
//processState->setText(state);
}
void MainWindow::updateStatus(QString tip){
statusBar()->showMessage(tip);
}
void MainWindow::closeEvent(QCloseEvent *event)
{
writeSettings();
event->accept();
// QMainWindow::closeEvent(event);
}
void MainWindow::readSettings()
{
print("Reading User Settings");
QSettings settings("Skittle", "Preferences");
settings.beginGroup("mainWindow");
restoreGeometry(settings.value("geometry").toByteArray());
restoreState(settings.value("state").toByteArray());
QList<QAction*> colorIndex = colorGroup->actions();
colorIndex[settings.value("nucleotideColors").toInt()]->trigger();
settings.endGroup();
}
void MainWindow::writeSettings()
{
print("Writing Settings");
QSettings settings("Skittle", "Preferences");
settings.beginGroup("mainWindow");
settings.setValue("geometry", saveGeometry());
settings.setValue("state", saveState());
settings.setValue("nucleotideColors", ui->getColorSetting() );
settings.endGroup();
}
void MainWindow::helpDialog()
{
/*QMessageBox help(this);
help.setText("Up to date help information can be found at http://dnaskittle.com/faq.");
help.exec();*/
QMessageBox mb(this);
QString c("About Qt");
mb.setWindowTitle(c);
mb.setText(QString(
"<h3>About Skittle</h3>"
"<p>Skittle is an Open Source program for browsing genome sequences.</p>"
"<p>Up to date help information is available online at "
"<a href=\"http://dnaskittle.com/faq/\">http://DNASkittle.com/faq/</a> </p>"
"<p>For those new to the program, there is a tutorial at "
"<a href=\"http://dnaskittle.com/getting-started/\">http://DNASkittle.com/getting-started/</a>"
" that walks through the basic tools of Skittle and some real world"
" genome patterns that can be identified with Skittle.</p>"
));
/** /
#ifndef QT_NO_IMAGEFORMAT_XPM
QImage logo(qtlogo_xpm);
#else
QImage logo;
#endif
if (qGray(mb.palette().color(QPalette::Active, QPalette::Text).rgb()) >
qGray(mb.palette().color(QPalette::Active, QPalette::Base).rgb()))
{
// light on dark, adjust some colors
logo.setColor(0, 0xffffffff);
logo.setColor(1, 0xff666666);
logo.setColor(2, 0xffcccc66);
logo.setColor(4, 0xffcccccc);
logo.setColor(6, 0xffffff66);
logo.setColor(7, 0xff999999);
logo.setColor(8, 0xff3333ff);
logo.setColor(9, 0xffffff33);
logo.setColor(11, 0xffcccc99);
}
QPixmap pm = QPixmap::fromImage(logo);
if (!pm.isNull())
mb.setIconPixmap(pm);*/
#if defined(Q_OS_WINCE)
mb.setDefaultButton(mb.addButton(QMessageBox::Ok));
#else
mb.addButton(QMessageBox::Ok);
#endif
mb.exec();
}
/**********Print Functions**********/
void MainWindow::print(const char* str)
{
if(textArea != NULL)
textArea->append(QString(str));
}
void MainWindow::print(QString str)
{
if(textArea != NULL)
textArea->append(str);
}
void MainWindow::reportFinished(){
print("Report Finished");
}