-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainWidget.cpp
338 lines (271 loc) · 10 KB
/
mainWidget.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
#include "mainWidget.h"
#include <iostream>
#include <QDebug>
#include <QMenuBar>
#include <QFileDialog>
#include <QFileInfo>
#include <QMessageBox>
#include <QCloseEvent>
#include <QSplitter>
#include "scene.h"
using namespace std;
const QString MainWindow::_DEFAULT_FILE_NAME = "untitled";
const QString MainWindow::_APPLICATION_NAME = "CurveApp";
const QString MainWindow::_APPLICATION_EXTENSION = ".yan";
QDir MainWindow::_CURRENT_PATH = QDir::currentPath();
MainWindow::MainWindow()
: QMainWindow(),
_timer(new QTimer(this)) {
createActions();
createMenus();
_toolsWidget = new ToolsWidget(this);
_drawingWidget = new DrawingWidget(this);
_animationWidget = new AnimationWidget(this);
QSplitter *sp1 = new QSplitter(Qt::Horizontal);
QSplitter *sp2 = new QSplitter(Qt::Vertical);
sp2->addWidget(_drawingWidget);
sp2->addWidget(_animationWidget);
sp1->addWidget(_toolsWidget);
sp1->addWidget(sp2);
sp1->setStretchFactor(0,1);
sp1->setStretchFactor(1,10);
sp2->setStretchFactor(0,8);
sp2->setStretchFactor(1,1);
connect(_timer,SIGNAL(timeout()),this,SLOT(timerEvent()));
setCentralWidget(sp1);
setCurrentFile("");
}
MainWindow::~MainWindow() {
// delete widgets here
}
void MainWindow::timerEvent() {
Scene *sce = Scene::get();
sce->setCurrentFrame((sce->currentFrame()+1)%sce->nbFrames());
_drawingWidget->frameChanged();
_toolsWidget->updateFrameNumber();
refresh();
}
void MainWindow::createActions() {
_newAct = new QAction(tr("&New"), this);
_newAct->setShortcuts(QKeySequence::New);
_newAct->setStatusTip(tr("Create a new file"));
connect(_newAct,SIGNAL(triggered()),this,SLOT(newFile()));
_openAct = new QAction(tr("&Open..."), this);
_openAct->setShortcuts(QKeySequence::Open);
_openAct->setStatusTip(tr("Open an existing file"));
connect(_openAct,SIGNAL(triggered()),this,SLOT(open()));
_saveAct = new QAction(tr("&Save"), this);
_saveAct->setShortcuts(QKeySequence::Save);
_saveAct->setStatusTip(tr("Save the document to disk"));
connect(_saveAct,SIGNAL(triggered()),this,SLOT(save()));
_exitAct = new QAction(tr("E&xit"), this);
_exitAct->setShortcuts(QKeySequence::Quit);
_exitAct->setStatusTip(tr("Exit the application"));
connect(_exitAct,SIGNAL(triggered()),this,SLOT(closeAppli()));
_copyAct = new QAction(tr("Copy"), this);
_copyAct->setShortcut(QKeySequence::Copy);
_copyAct->setStatusTip(tr("Copy selection"));
connect(_copyAct,SIGNAL(triggered()),this,SLOT(copy()));
_pasteAct = new QAction(tr("Paste"), this);
_pasteAct->setShortcut(QKeySequence::Paste);
_pasteAct->setStatusTip(tr("Paste selection"));
connect(_pasteAct,SIGNAL(triggered()),this,SLOT(paste()));
_selectAllAct = new QAction(tr("Select all"), this);
_selectAllAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_A));
_selectAllAct->setStatusTip(tr("Select/unselect all nodes"));
connect(_selectAllAct,SIGNAL(triggered()),this,SLOT(selectAll()));
#ifdef __APPLE__
// Workaround on Mac to avoid Qt bug (copy, paste, selectAll disabled) when opening QFileDialog
// https://forum.qt.io/topic/51950/qt-mac-osx-few-menu-items-are-disabled-after-qfiledialog
_copyAct->setMenuRole(QAction::NoRole);
_pasteAct->setMenuRole(QAction::NoRole);
_selectAllAct->setMenuRole(QAction::NoRole);
#endif
_helpAct = new QAction(tr("&Help"), this);
_helpAct->setStatusTip(tr("Show the bichmoute's Help"));
connect(_helpAct,SIGNAL(triggered()),this,SLOT(help()));
_aboutAct = new QAction(tr("&About"), this);
_aboutAct->setStatusTip(tr("Show the bichmoute's About box"));
connect(_aboutAct,SIGNAL(triggered()),this,SLOT(about()));
Qt::Modifier frameNavModifier;
#ifdef __APPLE__
// specific shortcut on OS X
frameNavModifier = Qt::CTRL;
#else
frameNavModifier = Qt::SHIFT;
#endif
_nextFrameAct = new QAction(tr("Next Frame"), this);
_nextFrameAct->setShortcut(QKeySequence(frameNavModifier + Qt::Key_Right));
_nextFrameAct->setStatusTip(tr("Increment current frame"));
connect(_nextFrameAct,SIGNAL(triggered()),this,SLOT(nextFrame()));
_prevFrameAct = new QAction(tr("Prev Frame"), this);
_prevFrameAct->setShortcut(QKeySequence(frameNavModifier + Qt::Key_Left));
_prevFrameAct->setStatusTip(tr("Decrement current frame"));
connect(_prevFrameAct,SIGNAL(triggered()),this,SLOT(prevFrame()));
_firstFrameAct = new QAction(tr("First Frame"), this);
_firstFrameAct->setShortcut(QKeySequence(frameNavModifier + Qt::Key_Up));
_firstFrameAct->setStatusTip(tr("Cursor at the first frame"));
connect(_firstFrameAct,SIGNAL(triggered()),this,SLOT(firstFrame()));
_lastFrameAct = new QAction(tr("Last Frame"), this);
_lastFrameAct->setShortcut(QKeySequence(frameNavModifier + Qt::Key_Down));
_lastFrameAct->setStatusTip(tr("Cursor at the last frame"));
connect(_lastFrameAct,SIGNAL(triggered()),this,SLOT(lastFrame()));
_playAct = new QAction(tr("Play"), this);
_playAct->setShortcut(QKeySequence(Qt::Key_P));
_playAct->setStatusTip(tr("Start animation"));
connect(_playAct,SIGNAL(triggered()),this,SLOT(play()));
_stopAct = new QAction(tr("Stop"), this);
_stopAct->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_P));
_stopAct->setStatusTip(tr("Stop animation"));
connect(_stopAct,SIGNAL(triggered()),this,SLOT(stop()));
_settingsAct = new QAction(tr("Anim. Settings"), this);
_settingsAct->setStatusTip(tr("Set range and framerate"));
connect(_settingsAct,SIGNAL(triggered()),this,SLOT(settings()));
}
void MainWindow::createMenus() {
_fileMenu = menuBar()->addMenu(tr("&File"));
_fileMenu->addAction(_newAct);
_fileMenu->addAction(_openAct);
_fileMenu->addAction(_saveAct);
_fileMenu->addSeparator();
_fileMenu->addAction(_exitAct);
_editMenu = menuBar()->addMenu(tr("&Edit"));
_editMenu->addAction(_copyAct);
_editMenu->addAction(_pasteAct);
_editMenu->addAction(_selectAllAct);
_editMenu->addSeparator();
_editMenu->addAction(_settingsAct);
_animMenu = menuBar()->addMenu(tr("&Animate"));
_animMenu->addAction(_playAct);
_animMenu->addAction(_stopAct);
_animMenu->addSeparator();
_animMenu->addAction(_nextFrameAct);
_animMenu->addAction(_prevFrameAct);
_animMenu->addAction(_firstFrameAct);
_animMenu->addAction(_lastFrameAct);
_helpMenu = menuBar()->addMenu(tr("&Help"));
_helpMenu->addAction(_helpAct);
_helpMenu->addAction(_aboutAct);
}
void MainWindow::newFile() {
if(maybeSave()) {
clearAll();
setCurrentFile("");
}
}
void MainWindow::open() {
cout << __FILE__ << " - " << __FUNCTION__ << ": TODO!" << endl;
}
bool MainWindow::save() {
if(_currentFile.isEmpty()) {
return saveAs();
} else {
cout << __FILE__ << " - " << __FUNCTION__ << ": TODO!" << endl;
return false;
}
}
bool MainWindow::saveAs() {
cout << __FILE__ << " - " << __FUNCTION__ << ": TODO!" << endl;
return false;
}
void MainWindow::copy() {
cout << __FILE__ << " - " << __FUNCTION__ << ": TODO!" << endl;
}
void MainWindow::paste() {
cout << __FILE__ << " - " << __FUNCTION__ << ": TODO!" << endl;
}
void MainWindow::selectAll() {
cout << __FILE__ << " - " << __FUNCTION__ << ": TODO!" << endl;
}
void MainWindow::help() {
cout << __FILE__ << " - " << __FUNCTION__ << ": TODO!" << endl;
}
void MainWindow::about() {
QString h = tr("<center><font size='12'> BICHMOUTE (VERSION 1.0)</font></center><br>"
"Description :<br> This small application allows you to animate amazing stuff thanks to our incredible work !<br>"
"Copyright (C) 2017. <br>"
"<br>"
"<a href='http://maverick.inria.fr/~Romain.Vergne/'>Romain Vergne</a> <br>"
"( <a href='mailto:romain.couderc@grenoble-inp.org'>romain.couderc@grenoble-inp.org</a> ) <br>"
"( <a href='mailto:theo.lambert@grenoble-inp.org' >theo.lambert@grenoble-inp.org )<br>"
"( <a href='mailto:theo.moins@grenoble-inp.org' >theo.moins@grenoble-inp.org )<br>"
"( <a href='mailto:william.didier@grenoble-inp.org' >william.didier@grenoble-inp.org )<br>"
);
QMessageBox::about(this,"About",h);
}
bool MainWindow::closeAppli() {
return close();
}
void MainWindow::nextFrame() {
cout << __FILE__ << " - " << __FUNCTION__ << ": TODO!" << endl;
}
void MainWindow::prevFrame() {
cout << __FILE__ << " - " << __FUNCTION__ << ": TODO!" << endl;
}
void MainWindow::firstFrame() {
cout << __FILE__ << " - " << __FUNCTION__ << ": TODO!" << endl;
}
void MainWindow::lastFrame() {
cout << __FILE__ << " - " << __FUNCTION__ << ": TODO!" << endl;
}
void MainWindow::play() {
}
void MainWindow::stop() {
}
void MainWindow::settings() {
cout << __FILE__ << " - " << __FUNCTION__ << ": TODO!" << endl;
// AnimationSettings *w = new AnimationSettings(_graphWidget);
// w->show();
}
bool MainWindow::maybeSave() {
// QMessageBox::StandardButton ret;
// ret = QMessageBox::warning(this,tr("Question"),tr("Do you want to save your scene?"),
// QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
// if(ret==QMessageBox::Save)
// return save();
// else //if(ret==QMessageBox::Cancel)
// return false;
return true;
}
void MainWindow::clearAll() {
cout << __FILE__ << " - " << __FUNCTION__ << ": DONE" << endl;
}
void MainWindow::closeEvent(QCloseEvent *event) {
if(maybeSave()) {
clearAll();
event->accept();
} else {
event->ignore();
}
}
void MainWindow::setCurrentFile(const QString &fileName) {
_currentFile = fileName;
QString shownName = _currentFile;
if(_currentFile.isEmpty())
shownName = _DEFAULT_FILE_NAME+_APPLICATION_EXTENSION;
setWindowFilePath(shownName);
}
void MainWindow::playAnimation() {
if(!Scene::get()->isAnimated()) {
_timer->setInterval((int)(1000.0f/(float)Scene::get()->fps()));
_timer->start();
Scene::get()->setAnimated(true);
}
}
void MainWindow::stopAnimation() {
if(Scene::get()->isAnimated()) {
_timer->stop();
Scene::get()->setAnimated(false);
}
}
void MainWindow::sceneSizeChanged() {
Scene *sce = Scene::get();
_drawingWidget->setResol(sce->width(),sce->height());
}
void MainWindow::nbFramesChanged() {
_animationWidget->resetResol();
_animationWidget->refresh();
}
void MainWindow::fpsChanged() {
_timer->setInterval((int)(1000.0f/(float)Scene::get()->fps()));
}