33
33
#include " ActionCycle.h"
34
34
35
35
36
- MainWindow::MainWindow (QWidget *parent) :
37
- QMainWindow(parent),
38
- ui(new Ui::MainWindow),
39
- m_dirty(false ),
40
- m_dirtyable(false )
36
+ MainWindow::MainWindow (QWidget* _parent)
37
+ : QMainWindow(_parent)
38
+ , ui(new Ui::MainWindow)
39
+ , m_dirty(false )
40
+ , m_dirtyable(false )
41
+ , m_autoGenerateMode(NO_GENERATION)
41
42
{
42
43
ui->setupUi (this );
43
44
@@ -61,14 +62,15 @@ MainWindow::MainWindow(QWidget *parent) :
61
62
62
63
m_scene = new NodalScene (ui->nodalView );
63
64
m_scene->setBackgroundBrush (Qt::black);
65
+ connect (m_scene, &NodalScene::dirtyChanged, this , &MainWindow::setDirty);
64
66
65
67
ui->nodalView ->setScene (m_scene);
66
68
ui->nodalView ->setZoomLimits (0.1 , 5.0 );
67
69
ui->nodalView ->init ();
68
70
ui->nodalView ->show ();
69
- connect (ui->nodalView , &NodalView::dirtyChanged, this , &MainWindow::setDirty);
70
71
71
72
m_signal.setComponent (m_scene->getOutput ()->component ());
73
+ connect (m_scene->getOutput (), &NodeItem::outputChanged, this , &MainWindow::onOutputChanged);
72
74
73
75
// ===== Edit Menu =====
74
76
@@ -139,6 +141,13 @@ MainWindow::MainWindow(QWidget *parent) :
139
141
act_loop->setCheckable (true );
140
142
connect (act_loop, SIGNAL (triggered (bool )), &m_signal, SLOT (loop (bool )));
141
143
144
+ m_act_autoGenerateGroup = new QActionGroup (this );
145
+ m_act_autoGenerateGroup->addAction (" No auto-generation" )->setCheckable (true );
146
+ m_act_autoGenerateGroup->addAction (" Auto-generate on play" )->setCheckable (true );
147
+ m_act_autoGenerateGroup->addAction (" Auto-generate on change" )->setCheckable (true );
148
+ m_act_autoGenerateGroup->actions ()[0 ]->setChecked (true );
149
+ connect (m_act_autoGenerateGroup, SIGNAL (triggered (QAction*)), this , SLOT (changeAutoGenerate (QAction*)));
150
+
142
151
// ===== File Edit =====
143
152
144
153
QAction* act_newFile = new QAction (" New" , this );
@@ -205,6 +214,9 @@ MainWindow::MainWindow(QWidget *parent) :
205
214
ui->menuAudio ->addAction (act_stop);
206
215
ui->menuAudio ->addAction (act_loop);
207
216
217
+ QMenu* menu_autoGenerate = ui->menuAudio ->addMenu (" Auto-Generation" );
218
+ menu_autoGenerate->addActions (m_act_autoGenerateGroup->actions ());
219
+
208
220
ui->mainToolBar ->clear ();
209
221
ui->mainToolBar ->addAction (act_newFile);
210
222
ui->mainToolBar ->addAction (act_openFile);
@@ -268,23 +280,23 @@ MainWindow::~MainWindow()
268
280
delete ui;
269
281
}
270
282
271
- void MainWindow::setFileName (QString fileName )
283
+ void MainWindow::setFileName (QString _fileName )
272
284
{
273
- m_fileName = fileName ;
274
- qDebug () << " FileName:" << fileName ;
275
- if (fileName .isNull () || fileName .isEmpty ())
285
+ m_fileName = _fileName ;
286
+ qDebug () << " FileName:" << _fileName ;
287
+ if (_fileName .isNull () || _fileName .isEmpty ())
276
288
{
277
289
m_windowTitle = " Untitled" ;
278
290
}
279
291
else
280
292
{
281
- m_windowTitle = fileName .mid (fileName .lastIndexOf (' /' ) + 1 );
293
+ m_windowTitle = _fileName .mid (_fileName .lastIndexOf (' /' ) + 1 );
282
294
283
295
// add new filename in recent files
284
296
QSettings settings;
285
297
QStringList files = settings.value (" recentFileList" ).toStringList ();
286
- files.removeAll (fileName );
287
- files.prepend (fileName );
298
+ files.removeAll (_fileName );
299
+ files.prepend (_fileName );
288
300
while (files.size () > maxRecentFile)
289
301
files.removeLast ();
290
302
@@ -297,7 +309,7 @@ void MainWindow::setFileName(QString fileName)
297
309
updateRecentFileActions ();
298
310
}
299
311
300
- void MainWindow::closeEvent (QCloseEvent *event )
312
+ void MainWindow::closeEvent (QCloseEvent* _event )
301
313
{
302
314
QMessageBox::StandardButton reply = askSaveChanges (" closing" );
303
315
@@ -310,11 +322,11 @@ void MainWindow::closeEvent(QCloseEvent *event)
310
322
QSettings settings;
311
323
settings.setValue (" geometry" , saveGeometry ());
312
324
settings.setValue (" windowState" , saveState ());
313
- event ->accept ();
325
+ _event ->accept ();
314
326
}
315
327
else
316
328
{
317
- event ->ignore ();
329
+ _event ->ignore ();
318
330
}
319
331
}
320
332
@@ -325,15 +337,15 @@ void MainWindow::readSettings()
325
337
restoreState (settings.value (" windowState" ).toByteArray ());
326
338
}
327
339
328
- void MainWindow::mousePressEvent (QMouseEvent *event )
340
+ void MainWindow::mousePressEvent (QMouseEvent* _event )
329
341
{
330
342
QWidget* focusedWidget = qApp->focusWidget ();
331
- if (focusedWidget != nullptr && focusedWidget != childAt (event ->x (), event ->y ()))
343
+ if (focusedWidget != nullptr && focusedWidget != childAt (_event ->x (), _event ->y ()))
332
344
{
333
345
focusedWidget->clearFocus ();
334
346
}
335
347
336
- QMainWindow::mousePressEvent (event );
348
+ QMainWindow::mousePressEvent (_event );
337
349
}
338
350
339
351
void MainWindow::newFile ()
@@ -393,7 +405,7 @@ void MainWindow::open()
393
405
394
406
void MainWindow::openRecent ()
395
407
{
396
- QAction * action = qobject_cast<QAction *>(sender ());
408
+ QAction* action = qobject_cast<QAction*>(sender ());
397
409
if (action)
398
410
{
399
411
openFile (action->data ().toString ());
@@ -467,6 +479,11 @@ void MainWindow::quit()
467
479
468
480
void MainWindow::playPause (int _index)
469
481
{
482
+ if (m_autoGenerateMode == GENERATE_ON_PLAY)
483
+ {
484
+ m_signal.generate ();
485
+ }
486
+
470
487
switch (_index)
471
488
{
472
489
case 0 :
@@ -490,14 +507,37 @@ void MainWindow::setDirty()
490
507
}
491
508
}
492
509
493
- void MainWindow::changeVolume (int value)
510
+ void MainWindow::changeVolume (int _value)
511
+ {
512
+ m_signal.setVolume (qreal (_value) / 100.0 );
513
+ }
514
+
515
+ void MainWindow::changeDuration (qreal _value)
516
+ {
517
+ m_signal.setDuration (_value);
518
+ }
519
+
520
+ void MainWindow::changeAutoGenerate (QAction* _action)
494
521
{
495
- m_signal.setVolume (qreal (value) / 100.0 );
522
+ int actionIndex = -1 ;
523
+ for (int i = 0 ; i < m_act_autoGenerateGroup->actions ().size (); ++i)
524
+ {
525
+ if (_action == m_act_autoGenerateGroup->actions ()[i])
526
+ {
527
+ actionIndex = i;
528
+ }
529
+ }
530
+
531
+ Q_ASSERT (actionIndex >= 0 && actionIndex < AUTO_GENERATION_MODE_COUNT);
532
+ m_autoGenerateMode = static_cast <AutoGenerationMode>(actionIndex);
496
533
}
497
534
498
- void MainWindow::changeDuration (qreal value )
535
+ void MainWindow::onOutputChanged ( )
499
536
{
500
- m_signal.setDuration (value);
537
+ if (m_autoGenerateMode == GENERATE_ON_CHANGE)
538
+ {
539
+ m_signal.generate ();
540
+ }
501
541
}
502
542
503
543
void MainWindow::createActions ()
@@ -510,31 +550,31 @@ void MainWindow::createMenus()
510
550
511
551
}
512
552
513
- void MainWindow::openFile (QString fileName )
553
+ void MainWindow::openFile (QString _fileName )
514
554
{
515
- if (QFile::exists (fileName ))
555
+ if (QFile::exists (_fileName ))
516
556
{
517
557
m_dirtyable = false ;
518
558
qreal duration;
519
- m_scene->load (fileName , duration);
559
+ m_scene->load (_fileName , duration);
520
560
m_signal.setDuration (duration);
521
561
m_dirtyable = true ;
522
- setFileName (fileName );
562
+ setFileName (_fileName );
523
563
}
524
564
}
525
565
526
- void MainWindow::saveFile (QString fileName )
566
+ void MainWindow::saveFile (QString _fileName )
527
567
{
528
- setFileName (fileName );
568
+ setFileName (_fileName );
529
569
m_dirtyable = false ;
530
- m_scene->save (fileName , m_signal.duration ());
570
+ m_scene->save (_fileName , m_signal.duration ());
531
571
m_dirtyable = true ;
532
572
}
533
573
534
- QMessageBox::StandardButton MainWindow::askSaveChanges (QString action )
574
+ QMessageBox::StandardButton MainWindow::askSaveChanges (QString _action )
535
575
{
536
576
return (!m_dirty) ? QMessageBox::Ignore
537
- : QMessageBox::question (this , " Save your work!" , " Some changes in your work are not saved.\n Do you want to save before " + action + " ?" ,
577
+ : QMessageBox::question (this , " Save your work!" , " Some changes in your work are not saved.\n Do you want to save before " + _action + " ?" ,
538
578
QMessageBox::Save|QMessageBox::Ignore|QMessageBox::Cancel);
539
579
}
540
580
0 commit comments