-
Notifications
You must be signed in to change notification settings - Fork 3
/
ViewManager.cpp
202 lines (174 loc) · 6.68 KB
/
ViewManager.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
//ViewManager.cpp
#include "ViewManager.h"
#include "glwidget.h"
#include "HighlightDisplay.h"
#include "GtfReader.h"
#include "MainWindow.h"
#include "MdiChildWindow.h"
#include <QtGui/QScrollBar>
#include <algorithm>
/** *******************************************
ViewManager is the 'Multiple Document Interface' responsible for coordinating the existance of
multiple windows being open inside Skittle at any one time. Each window is tied to one file.
Changes to the dials are connected to each window and propagate to display updates.
Offsets must be handled as a special condition. Look at addNewView() to see what happens
when a new player comes on stage.
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.
UiVariables is a singleton and can be accessed anywhere by calling UiVariables::Instance(). It
is responsible for maintaining state all throughout the program.
********************************************/
ViewManager::ViewManager(MainWindow* window, UiVariables* gui)
: QMdiArea(window)
{
ui = gui;
mainWindow = window;
activeWidget = NULL;
setBackgroundRole(QPalette::Dark);
createConnections();
addNewView();
if(activeWidget)
activeWidget->parent->showMaximized();//if there's only one window, I'd like it maximized
}
void ViewManager::createConnections()
{
connect(this, SIGNAL(subWindowActivated(QMdiSubWindow*)), this, SLOT(changeSelection(QMdiSubWindow*)));
connect(mainWindow->addViewAction, SIGNAL(triggered()), this, SLOT(addNewView()));
/****CONNECT ui VARIABLES*******/
connect(ui, SIGNAL(internalsUpdated()), this, SLOT(updateCurrentDisplay()));
}
void ViewManager::uiToGlwidgetConnections(GLWidget* active)
{
// connect(active->parent, SIGNAL(IveBeenClicked(MdiChildWindow*)), this, SLOT(changeSelection(MdiChildWindow*)));
connect(mainWindow->moveAction, SIGNAL(triggered()), active, SLOT(on_moveButton_clicked()));
connect(mainWindow->selectAction, SIGNAL(triggered()), active, SLOT(on_selectButton_clicked()));
connect(mainWindow->findAction, SIGNAL(triggered()), active, SLOT(on_findButton_clicked()));
connect(mainWindow->screenCaptureAction, SIGNAL(triggered()), active, SLOT(on_screenCaptureButton_clicked()));
connect(mainWindow->resizeAction, SIGNAL(triggered()), active, SLOT(on_resizeButton_clicked()));
connect(mainWindow->zoomAction, SIGNAL(triggered()), active, SLOT(on_zoomButton_clicked()));
connect(mainWindow->addAnnotationAction, SIGNAL(triggered()), active, SLOT(on_addAnnotationButton_clicked()));
connect(mainWindow->zoomExtents, SIGNAL(clicked()), active, SLOT(zoomExtents()));
connect( active, SIGNAL(addGraphMode(AbstractGraph*)), mainWindow, SLOT(addDisplayActions(AbstractGraph*)));
connect( active, SIGNAL(addDivider()), mainWindow, SLOT(addDisplayDivider()));
active->createButtons();
}
//public slots
GLWidget* ViewManager::addNewView(bool suppressOpen)
{
if(activeWidget)
activeWidget->parent->showNormal();//this should be the equivalent of clicking 'restore' or not maximized
MdiChildWindow* child = new MdiChildWindow(mainWindow->tabWidget);
connect( child, SIGNAL(subWindowClosing(MdiChildWindow*)), this, SLOT(closeSubWindow(MdiChildWindow*)));
addSubWindow(child);
child->show();
views.push_back(child);
GLWidget* newGlWidget = child->glWidget;
newOffsetDial(newGlWidget);
uiToGlwidgetConnections(newGlWidget);
changeSelection(child);
if(suppressOpen == false)
mainWindow->openAction->trigger();
return newGlWidget;
}
void ViewManager::changeSelection(QMdiSubWindow* container)
{
if(container == NULL)
return;
const QObjectList children = container->children();
MdiChildWindow* newActiveMdi = NULL;
for(int i = 0; newActiveMdi == NULL && i < (int)children.size(); ++i )//look through children for an MdiChildWindow
newActiveMdi = dynamic_cast<MdiChildWindow*>(children.at(i));
if(newActiveMdi != NULL)
changeSelection(newActiveMdi);
}
void ViewManager::changeSelection(MdiChildWindow* newActiveMdi)
{
if(newActiveMdi == NULL || newActiveMdi->glWidget == activeWidget)
return;
GLWidget* oldActiveGlWidget = activeWidget;
int tabIndex = mainWindow->tabWidget->currentIndex();
if(oldActiveGlWidget != NULL)//deal with oldActiveGlWidget
{
oldActiveGlWidget->parent->hideSettingsTabs();
}
newActiveMdi->showSettingsTabs();
mainWindow->tabWidget->setCurrentIndex(tabIndex);
activeWidget = newActiveMdi->glWidget ;
activeWidget->setHorizontalScrollbarRange();
}
void ViewManager::closeSubWindow(MdiChildWindow* closing)
{
vector<MdiChildWindow*>::iterator it;
it = std::find(views.begin(), views.end(), closing);
views.erase(it);
if(closing->glWidget == activeWidget)
{
if( views.size() > 0)
changeSelection(views[0]);
else
activeWidget = NULL;
}
}
void ViewManager::changeFile(QString fileName)
{
if(!fileName.isEmpty() )
{
if(activeWidget == NULL )
{
addNewView(true);
}
activeWidget->loadFile(fileName);
activeWidget->trackReader->determineOutputFile(fileName);
//Attempt to load the skittle notes file for this file if it exists
if (QFile(fileName + "-skittle_notes.gff").exists())
{
addAnnotationDisplay(fileName + "-skittle_notes.gff");
}
}
}
void ViewManager::addAnnotationDisplay(QString fileName)
{
if(activeWidget != NULL)
{
activeWidget->addAnnotationDisplay(fileName);
}
}
void ViewManager::jumpToNextAnnotation()
{
if(activeWidget != NULL)
{
activeWidget->jumpToAnnotation(true);
}
}
void ViewManager::jumpToPrevAnnotation()
{
if(activeWidget != NULL)
{
activeWidget->jumpToAnnotation(false);
}
}
//PRIVATE FUNCTIONS//
bool ViewManager::newOffsetDial(GLWidget* gl)
{
ui->newOffsetDial(gl);
QSpinBox* offset = ui->getOffsetDial(gl);
if(offset)
{
offset->show();
mainWindow->settingToolBar->addWidget(offset);
return true;
}
return false;
}
UiVariables* ViewManager::vars(GLWidget* active)
{
return dynamic_cast<MdiChildWindow*>(active->parent)->ui;
}
void ViewManager::updateCurrentDisplay()
{
for(int i = 0; i < (int)views.size(); ++i)
views[i]->glWidget->invalidateDisplayGraphs();
}