mirror of
https://github.com/miek/inspectrum.git
synced 2026-03-06 16:27:14 +01:00
Add a file picker
This commit is contained in:
@@ -13,6 +13,7 @@ MainWindow::MainWindow()
|
||||
addDockWidget(Qt::LeftDockWidgetArea, dock);
|
||||
|
||||
connect(dock, SIGNAL(fftSizeChanged(int)), &spectrogram, SLOT(setFFTSize(int)));
|
||||
connect(dock->fileOpenButton, SIGNAL(clicked()), &spectrogram, SLOT(pickFile()));
|
||||
connect(dock->powerMaxSlider, SIGNAL(valueChanged(int)), &spectrogram, SLOT(setPowerMax(int)));
|
||||
connect(dock->powerMinSlider, SIGNAL(valueChanged(int)), &spectrogram, SLOT(setPowerMin(int)));
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ public:
|
||||
~Spectrogram();
|
||||
|
||||
public slots:
|
||||
void pickFile();
|
||||
void setFFTSize(int size);
|
||||
void setPowerMax(int power);
|
||||
void setPowerMin(int power);
|
||||
|
||||
@@ -7,6 +7,9 @@ SpectrogramControls::SpectrogramControls(const QString & title, QWidget * parent
|
||||
widget = new QWidget(this);
|
||||
layout = new QFormLayout(widget);
|
||||
|
||||
fileOpenButton = new QPushButton("Open file...", widget);
|
||||
layout->addRow(fileOpenButton);
|
||||
|
||||
fftSizeSlider = new QSlider(Qt::Horizontal, widget);
|
||||
fftSizeSlider->setRange(7, 13);
|
||||
fftSizeSlider->setValue(10);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <QDockWidget>
|
||||
#include <QFormLayout>
|
||||
#include <QPushButton>
|
||||
#include <QSlider>
|
||||
|
||||
class SpectrogramControls : public QDockWidget {
|
||||
@@ -21,6 +22,7 @@ private:
|
||||
QFormLayout *layout;
|
||||
QSlider *fftSizeSlider;
|
||||
public:
|
||||
QPushButton *fileOpenButton;
|
||||
QSlider *powerMaxSlider;
|
||||
QSlider *powerMinSlider;
|
||||
};
|
||||
Reference in New Issue
Block a user