From ac7aa3281bd4ef78f6fe749799ab7551e192b4f1 Mon Sep 17 00:00:00 2001 From: Mike Walters Date: Wed, 15 Jul 2015 01:25:53 +0100 Subject: [PATCH] Add docked controls + hook up slider for FFT size --- inspectrum.pro | 4 ++-- mainwindow.cpp | 8 +++++++- mainwindow.h | 2 ++ spectrogram.cpp | 7 +++++++ spectrogram.h | 6 ++++++ spectrogramcontrols.cpp | 23 +++++++++++++++++++++++ spectrogramcontrols.h | 23 +++++++++++++++++++++++ 7 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 spectrogramcontrols.cpp create mode 100644 spectrogramcontrols.h diff --git a/inspectrum.pro b/inspectrum.pro index 9d012b4..01fb30a 100644 --- a/inspectrum.pro +++ b/inspectrum.pro @@ -4,5 +4,5 @@ TARGET = inspectrum TEMPLATE = app LIBS += -lfftw3f -HEADERS += mainwindow.h inputsource.h spectrogram.h -SOURCES += main.cpp mainwindow.cpp inputsource.cpp spectrogram.cpp +HEADERS += mainwindow.h inputsource.h spectrogram.h spectrogramcontrols.h +SOURCES += main.cpp mainwindow.cpp inputsource.cpp spectrogram.cpp spectrogramcontrols.cpp diff --git a/mainwindow.cpp b/mainwindow.cpp index 409eb39..67be37d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -7,4 +7,10 @@ MainWindow::MainWindow() setWindowTitle(tr("inspectrum")); scrollArea.setWidget(&spectrogram); setCentralWidget(&scrollArea); -} + + dock = new SpectrogramControls(tr("Controls"), this); + dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + addDockWidget(Qt::LeftDockWidgetArea, dock); + + connect(dock, SIGNAL(fftSizeChanged(int)), &spectrogram, SLOT(setFFTSize(int))); +} \ No newline at end of file diff --git a/mainwindow.h b/mainwindow.h index bc7628f..9424354 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -3,6 +3,7 @@ #include #include #include "spectrogram.h" +#include "spectrogramcontrols.h" class MainWindow : public QMainWindow { @@ -14,4 +15,5 @@ public: private: QScrollArea scrollArea; Spectrogram spectrogram; + SpectrogramControls *dock; }; \ No newline at end of file diff --git a/spectrogram.cpp b/spectrogram.cpp index 2a03a7a..31af904 100644 --- a/spectrogram.cpp +++ b/spectrogram.cpp @@ -49,4 +49,11 @@ void Spectrogram::paintEvent(QPaintEvent *event) } qDebug() << "Paint: " << timer.elapsed() << "ms"; +} + +void Spectrogram::setFFTSize(int size) +{ + inputSource->setFFTSize(size); + update(); + resize(inputSource->GetWidth(), inputSource->GetHeight()); } \ No newline at end of file diff --git a/spectrogram.h b/spectrogram.h index 165d11b..54a588f 100644 --- a/spectrogram.h +++ b/spectrogram.h @@ -4,13 +4,19 @@ #include "inputsource.h" class Spectrogram : public QWidget { + Q_OBJECT + public: Spectrogram(); ~Spectrogram(); +public slots: + void setFFTSize(int size); + protected: void paintEvent(QPaintEvent *event); + private: InputSource *inputSource; }; \ No newline at end of file diff --git a/spectrogramcontrols.cpp b/spectrogramcontrols.cpp new file mode 100644 index 0000000..53c653b --- /dev/null +++ b/spectrogramcontrols.cpp @@ -0,0 +1,23 @@ +#include "spectrogramcontrols.h" +#include + +SpectrogramControls::SpectrogramControls(const QString & title, QWidget * parent) + : QDockWidget::QDockWidget(title, parent) +{ + QWidget *widget = new QWidget; + fftSizeSlider = new QSlider(Qt::Horizontal); + fftSizeSlider->setRange(7, 13); + fftSizeSlider->setValue(10); + + layout = new QFormLayout; + layout->addRow(new QLabel(tr("FFT size:")), fftSizeSlider); + widget->setLayout(layout); + setWidget(widget); + + connect(fftSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(fftSizeSliderChanged(int))); +} + +void SpectrogramControls::fftSizeSliderChanged(int size) +{ + emit fftSizeChanged((int)pow(2, size)); +} \ No newline at end of file diff --git a/spectrogramcontrols.h b/spectrogramcontrols.h new file mode 100644 index 0000000..9266620 --- /dev/null +++ b/spectrogramcontrols.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include +#include + +class SpectrogramControls : public QDockWidget { + Q_OBJECT + +public: + SpectrogramControls(const QString & title, QWidget * parent); + +signals: + void fftSizeChanged(int size); + +private slots: + void fftSizeSliderChanged(int size); + +private: + QWidget *widget; + QFormLayout *layout; + QSlider *fftSizeSlider; +}; \ No newline at end of file