mirror of
https://github.com/miek/inspectrum.git
synced 2026-03-03 15:04:19 +01:00
Add a file picker
This commit is contained in:
@@ -2,16 +2,16 @@
|
||||
|
||||
#include <QDebug>
|
||||
#include <QElapsedTimer>
|
||||
#include <QFileDialog>
|
||||
#include <QPainter>
|
||||
#include <QPaintEvent>
|
||||
#include <QRect>
|
||||
|
||||
Spectrogram::Spectrogram()
|
||||
{
|
||||
inputSource = new InputSource("/home/mike/Downloads/hubsan-chopped.cfile", 1024);
|
||||
inputSource = nullptr;
|
||||
powerMax = 0.0f;
|
||||
powerMin = -50.0f;
|
||||
resize(inputSource->GetWidth(), inputSource->GetHeight());
|
||||
}
|
||||
|
||||
Spectrogram::~Spectrogram()
|
||||
@@ -19,6 +19,24 @@ Spectrogram::~Spectrogram()
|
||||
delete inputSource;
|
||||
}
|
||||
|
||||
void Spectrogram::pickFile()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(
|
||||
this, tr("Open File"), "", tr("Sample file (*.cfile *.bin);;All files (*.*)")
|
||||
);
|
||||
if (fileName != nullptr) {
|
||||
try {
|
||||
InputSource *newFile = new InputSource(fileName.toUtf8().constData(), (inputSource != nullptr) ? inputSource->GetWidth() : 1024);
|
||||
delete inputSource;
|
||||
inputSource = newFile;
|
||||
resize(inputSource->GetWidth(), inputSource->GetHeight());
|
||||
} catch (std::runtime_error e) {
|
||||
// TODO: display error
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class T> const T& clamp (const T& value, const T& min, const T& max) {
|
||||
return std::min(max, std::max(min, value));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user