-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
198 lines (175 loc) · 6.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
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
#include <QFileDialog>
#include <QDebug>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "plot.h"
#include "configdialog.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Table of markers
ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
connect(ui->buttonMarkerAdd,SIGNAL(clicked()),ui->plot,SLOT(addMarker()));
connect(ui->plot,SIGNAL(MarkerListUpdate(int)),this,SLOT(tableWidget_update(int)));
// connecting markers actions
connect(ui->actionMark_save, SIGNAL(triggered()), ui->plot, SLOT(saveXml()));
// Horizontal ScrollBar config
ui->horizontalScrollBar->setMinimum(0);
ui->horizontalScrollBar->setMaximum(0);
connect(ui->horizontalScrollBar,SIGNAL(valueChanged(int)),ui->plot,SLOT(setImgOffset(int)));
connect(ui->plot,SIGNAL(ImgOffset(int)),ui->horizontalScrollBar,SLOT(setValue(int)));
connect(ui->plot,SIGNAL(MaximumOffset(int)),this,SLOT(setScrollBarMaximumValue(int)));
//splitter default size
QList<int> size;
size.append(10);
size.append(800);
ui->splitter_2->setSizes(size);
ui->zoomSpinBox->setValue(ui->plot->settings->plotZoomX() * 100);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionImageGenerator_triggered()
{
filePath = QFileDialog::getOpenFileName(this, tr("Open File"),QDir::homePath(),tr("WAV files")+" (*.wav)");
if(filePath != "")
ui->plot->openFile(filePath);
else
qDebug() << "Can't open file - should be in message box"; // hange it to message box
}
void MainWindow::setScrollBarMaximumValue(int value)
{
ui->horizontalScrollBar->setMinimum(0);
ui->horizontalScrollBar->setMaximum(value);
}
void MainWindow::on_actionSplit_triggered()
{
ui->plot->splitFile();
}
void MainWindow::on_actionPreferences_triggered()
{
ConfigDialog dialog(ui->plot->settings,this);
if (dialog.exec() == QDialog::Accepted)
{ // reload settings
ui->plot->loadSettings();
if (ui->plot->file && dialog.reloadFile())
ui->plot->openFile( ui->plot->file->fileName() );
}
}
void MainWindow::on_actionExit_triggered()
{
exit(0);
}
void MainWindow::on_buttonRefreshPlot_clicked()
{
qDebug() << ui->zoomSpinBox->value() << ui->plot->zoom()*100;
if(static_cast<int>(ui->zoomSpinBox->value()) != static_cast<int>(ui->plot->zoom()*100)) //reopening file and all configurations
{
ui->plot->setZoom(ui->zoomSpinBox->value()/100);
qDebug() <<"regenerated";
}
else //refreshing all parametrs and images
ui->plot->refreshPlot();
}
void MainWindow::on_actionMark_detect_triggered()
{
if(!ui->plot->isOpened())
qDebug() << "MainWindow::on_actionMark_detect_triggered() -- read file first";
//detecting Beeps
ui->plot->detectBeeps();
//table filling
for(int i=0; i<ui->plot->markerList.count();i++)
{
ui->tableWidget->setRowCount(i+1); // adding new row
QTableWidgetItem *item = new QTableWidgetItem(ui->plot->markerList[i].label()); // making new item for table
ui->tableWidget->setItem(i,0,item); // adding item to table
}
ui->tableWidget->update(); // update table
}
void MainWindow::on_tableWidget_cellChanged(int row, int column)
{
if(row > -1 && row < ui->plot->markerList.count())
ui->plot->markerList[row].setLabel(ui->tableWidget->item(row,column)->text());
}
void MainWindow::on_tableWidget_itemSelectionChanged()
{
//qDebug() << "item selection changed: " << ui->tableWidget->currentRow() << ui->tableWidget->selectedItems().first()->row();
ui->textEdit->setPlainText(ui->plot->markerList[ui->tableWidget->currentRow()].note());
ui->plot->selectMarker(ui->tableWidget->currentRow()); // selecting proper marker
}
void MainWindow::on_textEdit_textChanged()
{
if(ui->tableWidget->currentRow() != -1)
{
ui->plot->markerList[ui->tableWidget->currentRow()].setNote(ui->textEdit->toPlainText());
}
}
void MainWindow::tableWidget_update(int index)
{
ui->tableWidget->clearSelection(); // clearing selection
if(index != -1 )
{
ui->tableWidget->insertRow(index); // inserting new row in index position (end of table)
QTableWidgetItem *item = new QTableWidgetItem(ui->plot->markerList[index].label()); // new item
ui->tableWidget->setItem(index,0,item); // adding item
ui->tableWidget->activateWindow(); // setting table active
ui->tableWidget->selectRow(index); // selecting new row
}
else
{
for (int i = 0;i<ui->tableWidget->rowCount();i++)
{
ui->tableWidget->clearSelection(); // clearing sellection (nessesery for removing row)
QTableWidgetItem *item = ui->tableWidget->item(0,0); // taking pointer of item to delete it
delete item;
ui->tableWidget->removeRow(0);
}
ui->tableWidget->setRowCount(0);
}
ui->tableWidget->update(); // uptade table
}
void MainWindow::on_buttonMarkerDelete_clicked()
{
int index = ui->tableWidget->currentRow(); // taking index of curent selected row
ui->tableWidget->clearSelection(); // clearing sellection (nessesery for removing row)
QTableWidgetItem *item = ui->tableWidget->item(ui->tableWidget->currentRow(),0); // taking pointer of item to delete it
delete item;
if (ui->tableWidget->rowCount() > 1) // if ther is more then one maker
ui->tableWidget->removeRow(index); // delete specyfic row
else ui->tableWidget->setRowCount(0); // set row number to 0
ui->plot->delMarker(index); // deleting selected row form Marker List Vector
ui->plot->selectMarker(ui->tableWidget->currentRow()); // selecting next marker and refreshing plot
}
void MainWindow::closeEvent(QCloseEvent *)
{
if (ui->plot->settings->clearTempDir())
{
QDir dir = QDir::temp();
QStringList files = dir.entryList(QStringList("*.fft"),QDir::Files);
if (files.isEmpty())
return;
qDebug() << "Deleting temporary files...";
foreach (QString fileName, files)
{
if (QFile::remove(dir.absolutePath() + QDir::separator() + fileName))
qDebug() << fileName << "deleted";
}
}
}
void MainWindow::on_actionMark_load_triggered()
{
ui->plot->loadXml();
// load markers to table widget
for(int i=0; i<ui->plot->markerList.count();i++)
{
ui->tableWidget->setRowCount(i+1); // adding new row
QTableWidgetItem *item = new QTableWidgetItem(ui->plot->markerList[i].label()); // making new item for table
ui->tableWidget->setItem(i,0,item); // adding item to table
}
ui->tableWidget->update(); // update table
ui->plot->update();
}