Skip to content

Commit

Permalink
GUI: Panel preview sound code
Browse files Browse the repository at this point in the history
  • Loading branch information
fdde authored and DrMcCoy committed Dec 29, 2017
1 parent 5435e14 commit ef884e0
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 180 deletions.
77 changes: 58 additions & 19 deletions src/gui/panelpreviewsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,58 @@ namespace GUI {

W_OBJECT_IMPL(PanelPreviewSound)

PanelPreviewSound::PanelPreviewSound(QWidget *UNUSED(parent))
{
_ui.setupUi(this);
_ui.volSlider->setMaximum(100);
PanelPreviewSound::PanelPreviewSound(QWidget *UNUSED(parent)) {
_layoutGrid = new QGridLayout(this);
_layoutHorizontal = new QHBoxLayout();
_layoutHorizontal_2 = new QHBoxLayout();
_layoutVertical = new QVBoxLayout();

_timer = new QTimer(this);

changeVolume(20);
_labelVolume = new QLabel(this);
_labelPosition = new QLabel(this);
_labelPercent = new QLabel(this);
_labelDuration = new QLabel(this);

connect(_ui.play, &QPushButton::clicked, this, &PanelPreviewSound::play);
connect(_ui.pause, &QPushButton::clicked, this, &PanelPreviewSound::pause);
connect(_ui.stop, &QPushButton::clicked, this, &PanelPreviewSound::stop);
connect(_ui.volSlider, &QSlider::valueChanged, this, &PanelPreviewSound::changeVolume);
_buttonPlay = new QPushButton(this);
_buttonPause = new QPushButton(this);
_buttonStop = new QPushButton(this);

_sliderPosition = new QSlider(this);
_sliderVolume = new QSlider(this);

_sliderPosition->setOrientation(Qt::Horizontal);

_buttonPlay->setText(tr("Play"));
_buttonPause->setText(tr("Pause"));
_buttonStop->setText(tr("Stop"));

_layoutHorizontal->addWidget(_labelPosition);
_layoutHorizontal->addWidget(_labelPercent);
_layoutHorizontal->addWidget(_labelDuration);

_layoutHorizontal_2->addWidget(_buttonPlay);
_layoutHorizontal_2->addWidget(_buttonPause);
_layoutHorizontal_2->addWidget(_buttonStop);

_layoutVertical->addWidget(_labelVolume);
_layoutVertical->addWidget(_sliderVolume);

_layoutGrid->addWidget(_sliderPosition, 0, 0);
_layoutGrid->addLayout(_layoutHorizontal, 1, 0);
_layoutGrid->addLayout(_layoutVertical, 0, 1);
_layoutGrid->addLayout(_layoutHorizontal_2, 2, 0);

_layoutGrid->setSizeConstraint(QLayout::SetFixedSize);

_sliderVolume->setMaximum(100);

changeVolume(5);

connect(_buttonPlay, &QPushButton::clicked, this, &PanelPreviewSound::play);
connect(_buttonPause, &QPushButton::clicked, this, &PanelPreviewSound::pause);
connect(_buttonStop, &QPushButton::clicked, this, &PanelPreviewSound::stop);
connect(_sliderVolume, &QSlider::valueChanged, this, &PanelPreviewSound::changeVolume);
connect(_timer, &QTimer::timeout, this, &PanelPreviewSound::update);

_timer->start(50);
Expand Down Expand Up @@ -85,14 +124,14 @@ void PanelPreviewSound::stop() {
}

void PanelPreviewSound::changeVolume(int value) {
_ui.volSlider->setValue(value);
_ui.volume->setText(QString("%1%").arg(_ui.volSlider->value()));
_sliderVolume->setValue(value);
_labelVolume->setText(QString("%1%").arg(_sliderVolume->value()));

SoundMan.setListenerGain((double)value / (double)100);
}

void PanelPreviewSound::positionChanged(qint64 position) {
_ui.posSlider->setValue(position/100);
_sliderPosition->setValue(position/100);
}

QString PanelPreviewSound::formatTime(uint64 t) const {
Expand Down Expand Up @@ -143,9 +182,9 @@ int PanelPreviewSound::getSliderPos(uint64 total, uint64 t) const {
}

void PanelPreviewSound::setButtons(bool enablePlay, bool enablePause, bool enableStop) {
_ui.play->setEnabled(enablePlay);
_ui.pause->setEnabled(enablePause);
_ui.stop->setEnabled(enableStop);
_buttonPlay->setEnabled(enablePlay);
_buttonPause->setEnabled(enablePause);
_buttonStop->setEnabled(enableStop);
}

void PanelPreviewSound::update() {
Expand All @@ -155,11 +194,11 @@ void PanelPreviewSound::update() {
QString total = formatTime(_duration);
QString percent = formatPercent(_duration, t);

_ui.position->setText(played);
_ui.percent->setText(percent);
_ui.duration->setText(total);
_labelPosition->setText(played);
_labelPercent->setText(percent);
_labelDuration->setText(total);

_ui.posSlider->setValue(getSliderPos(_duration, t));
_sliderPosition->setValue(getSliderPos(_duration, t));

bool isPlaying = SoundMan.isPlaying(_sound);
bool isPaused = SoundMan.isPaused(_sound);
Expand Down
24 changes: 18 additions & 6 deletions src/gui/panelpreviewsound.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,37 @@
#include "src/common/ustring.h"
#include "src/sound/types.h"

#include "ui/ui_previewsound.h"

namespace GUI {

class ResourceTreeItem;

class PanelPreviewSound : public QFrame
{
class PanelPreviewSound : public QFrame {
W_OBJECT(PanelPreviewSound)

private:
QGridLayout *_layoutGrid;
QHBoxLayout *_layoutHorizontal;
QHBoxLayout *_layoutHorizontal_2;
QVBoxLayout *_layoutVertical;

QSlider *_sliderPosition;
QSlider *_sliderVolume;

QLabel *_labelPosition;
QLabel *_labelDuration;
QLabel *_labelPercent;
QLabel *_labelVolume;

QPushButton *_buttonPlay;
QPushButton *_buttonPause;
QPushButton *_buttonStop;

const ResourceTreeItem *_currentItem;

Sound::ChannelHandle _sound;
uint64 _duration;
QTimer *_timer;

Ui::PreviewSound _ui;

public:
PanelPreviewSound(QWidget *parent = 0);

Expand Down
1 change: 0 additions & 1 deletion src/gui/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ noinst_LTLIBRARIES += src/gui/libgui.la
QT_UI_FORMS_BUILT = \
ui/ui_mainwindow.h \
ui/ui_resourceinfo.h \
ui/ui_previewsound.h \
ui/ui_previewtext.h \
$(EMPTY)

Expand Down
154 changes: 0 additions & 154 deletions ui/previewsound.ui

This file was deleted.

0 comments on commit ef884e0

Please sign in to comment.