-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.cpp
132 lines (109 loc) · 3.74 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
#include "MainWindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setMainWindow();
}
MainWindow::~MainWindow()
{
}
void MainWindow::setMainWindow()
{
//Creating new widget wdg to set layout manually
wdg = new QWidget(this);
QVBoxLayout *vbox = new QVBoxLayout(wdg);
createMenu();
//Creating Buttons
createButtonBox();
//Creating BPM sliders
createBPMBox();
//Creating volume sliders
createVolumeBox();
//Creating Stress first beat? checkbox
createCheckBox();
//vbox->addStretch(1);
vbox->addWidget(volumeGroupBox);
vbox->addWidget(BPMGroupBox);
vbox->addWidget(buttonBox);
vbox->addWidget(firstBeatBox);
setCentralWidget(wdg);
}
void MainWindow::createMenu()
{
//Create menus
QAction *quit = new QAction("&Quit", this);
QMenu *file = menuBar()->addMenu("&File");
file->addAction(quit);
connect(quit, &QAction::triggered,
[=]() {
QApplication::quit();
});
//Creating instances of ticker and timer here
//Done so that the connection between ticker and timer is possible
ticker = new Ticker(this);
timer = new Timer(this);
connect(timer, &Timer::timeout, ticker, &Ticker::playSound);
}
void MainWindow::createVolumeBox()
{
volumeGroupBox = new QGroupBox(tr("Volume"), this);
QHBoxLayout *layout = new QHBoxLayout();
volSlider = new QSlider(Qt::Horizontal , this);
volSlider->setRange(0,100);
volSlider->setSliderPosition(60);
volumeLabel = new QLabel("60", this);
connect(volSlider, static_cast<void (QSlider::*)(int)>(&QSlider::valueChanged),
volumeLabel, static_cast<void (QLabel::*)(int)>(&QLabel::setNum));
connect(volSlider, static_cast<void (QSlider::*)(int)>(&QSlider::valueChanged),
ticker, static_cast<void (Ticker::*)(int)>(&Ticker::setVolumeLevel));
layout->addWidget(volSlider);
layout->addWidget(volumeLabel);
volumeGroupBox->setLayout(layout);
}
void MainWindow::createBPMBox()
{
BPMGroupBox = new QGroupBox(tr("Metronome BPM"), this);
label = new QLabel("BPM", this);
QHBoxLayout *hboxBPMSlider = new QHBoxLayout();
BPMSlider = new QSlider(Qt::Horizontal , this);
spinBox = new QSpinBox(this);
spinBox->setRange(1, 200);
BPMSlider->setRange(1,200);
// Connect spinBox to set slider
connect(spinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
[=] () {
BPMSlider->setValue(spinBox->value());
});
// Connect Slider to set BPM to spinBox
connect(BPMSlider, &QSlider::valueChanged,
[=] () {
spinBox->setValue(BPMSlider->value());
});
// Connect the BPM Slider values to the ticking value of timer class
connect(BPMSlider, &QSlider::valueChanged,
[=] () {
timer->setTickingValue(BPMSlider->value());
});
BPMSlider->setSliderPosition(60);
hboxBPMSlider->addWidget(BPMSlider);
hboxBPMSlider->addWidget(spinBox);
hboxBPMSlider->addWidget(label);
BPMGroupBox->setLayout(hboxBPMSlider);
}
void MainWindow::createButtonBox()
{
buttonBox = new QGroupBox(this);
QHBoxLayout *hboxButtons = new QHBoxLayout();
playBtn = new QPushButton("Play", this);
stopBtn = new QPushButton("Stop", this);
connect(playBtn, &QPushButton::clicked ,timer, &Timer::start);
connect(stopBtn, &QPushButton::clicked ,timer, &Timer::stop);
hboxButtons->addWidget(playBtn, 1, Qt::AlignRight);
hboxButtons->addWidget(stopBtn, 0);
buttonBox->setLayout(hboxButtons);
}
void MainWindow::createCheckBox() {
firstBeatBox = new QCheckBox("Stress first beat?");
firstBeatBox->setChecked(true);
connect(firstBeatBox, &QCheckBox::stateChanged, ticker, &Ticker::reqToStressFirstBeat);
}