-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
142 lines (132 loc) · 4.59 KB
/
mainwindow.cpp
File metadata and controls
142 lines (132 loc) · 4.59 KB
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
#include <QDebug>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "devices/tonegenerator.h"
#include "devices/audioinputdevice.h"
#include "widgets/FancyTabBar/fancytabbar.h"
Q_DECLARE_METATYPE(SamplesList)
Q_DECLARE_METATYPE(AudioChannels)
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
qRegisterMetaType <SamplesList> ();
qRegisterMetaType <AudioChannels> ();
ui->setupUi(this);
FancyTabBar* mainTabs = new FancyTabBar(FancyTabBar::TabBarPosition::Left);
mainTabs->insertTab(0, QIcon(":/icons/potentiometer.ico"), tr("Calibration"));
mainTabs->insertTab(1, QIcon(":/icons/oscilloscope.ico"), tr("Raw"));
mainTabs->insertTab(2, QIcon(":/icons/Lissajous_curve_1by2.svg.png"), tr("Analyze"));
mainTabs->insertTab(3, QIcon(":/icons/diagram_v2_14.ico"), tr("Diagnose"));
mainTabs->insertTab(4, QIcon(":/icons/application_x_desktop.ico"), tr("Options"));
mainTabs->insertTab(5, QIcon(":/icons/get_info.ico"), tr("About"));
mainTabs->setTabEnabled(0, true);
mainTabs->setTabEnabled(1, true);
mainTabs->setTabEnabled(2, true);
mainTabs->setTabEnabled(3, true);
mainTabs->setTabEnabled(4, true);
mainTabs->setTabEnabled(5, true);
mainTabs->setCurrentIndex(0);
ui->horizontalLayout->insertWidget(0, mainTabs);
connect(mainTabs, SIGNAL(currentChanged(int)), this, SLOT(showForm(int)));
m_gen = new ToneGenerator;
m_capture = new AudioInputThread;
m_formCalibration = new FormCalibration(m_gen, m_capture);
m_formRaw = new FormRaw(m_gen, m_capture);
m_formAnalyze = new FormAnalyze(m_gen, m_capture);
m_formDiagnose = new FormDiagnose(m_gen, m_capture);
m_formOptions = new FormOptions;
m_formAbout = new FormAbout;
ui->mainArea->addWidget(m_formCalibration);
ui->mainArea->addWidget(m_formRaw);
ui->mainArea->addWidget(m_formAnalyze);
ui->mainArea->addWidget(m_formDiagnose);
ui->mainArea->addWidget(m_formOptions);
ui->mainArea->addWidget(m_formAbout);
m_currentForm = m_formCalibration;
ui->mainArea->setCurrentWidget(m_currentForm);
// Start audio device only after enumeration completion
m_gen->start();
m_capture->start();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::showForm(int formId)
{
QWidget *newForm = nullptr;
switch (formId) {
case 0:
newForm = m_formCalibration;
break;
case 1:
newForm = m_formRaw;
break;
case 2:
newForm = m_formAnalyze;
break;
case 3:
newForm = m_formDiagnose;
break;
case 4:
newForm = m_formOptions;
break;
case 5:
newForm = m_formAbout;
break;
default:
qWarning() << "Unknown Form:" << formId;
Q_ASSERT(false);
return;
}
if (newForm == m_currentForm) {
return;
}
if (m_currentForm == m_formCalibration) {
qDebug() << "Close form \"Calibration\"";
m_formCalibration->leaveForm();
} else if (m_currentForm == m_formRaw) {
qDebug() << "Close form \"Raw\"";
m_formRaw->leaveForm();
} else if (m_currentForm == m_formAnalyze) {
qDebug() << "Close form \"Analyze\"";
m_formAnalyze->leaveForm();
} else if (m_currentForm == m_formDiagnose) {
qDebug() << "Close form \"Diagnose\"";
m_formDiagnose->leaveForm();
} else if (m_currentForm == m_formOptions) {
qDebug() << "Close form \"Options\"";
m_formOptions->leaveForm();
} else if (m_currentForm == m_formAbout) {
qDebug() << "Close form \"About\"";
} else {
qWarning() << "Unknown Form:" << formId;
Q_ASSERT(false);
return;
}
m_currentForm = newForm;
if (m_currentForm == m_formCalibration) {
qDebug() << "Open form \"Calibration\"";
m_formCalibration->enterForm();
} else if (m_currentForm == m_formRaw) {
qDebug() << "Open form \"Raw\"";
m_formRaw->enterForm();
} else if (m_currentForm == m_formAnalyze) {
qDebug() << "Open form \"Analyze\"";
m_formAnalyze->enterForm();
} else if (m_currentForm == m_formDiagnose) {
qDebug() << "Open form \"Diagnose\"";
m_formDiagnose->enterForm();
} else if (m_currentForm == m_formOptions) {
qDebug() << "Open form \"Options\"";
m_formOptions->enterForm();
} else if (m_currentForm == m_formAbout) {
qDebug() << "Open form \"About\"";
} else {
qWarning() << "Unknown Form:" << formId;
Q_ASSERT(false);
return;
}
ui->mainArea->setCurrentWidget(m_currentForm);
}