summaryrefslogtreecommitdiffstats
path: root/sigmodr/widgets/SoundUI.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-03-01 20:44:32 -0500
committerBen Boeckel <MathStuf@gmail.com>2009-03-01 20:44:32 -0500
commit1430a9e2b52109f3f57cfa7a9bb2f68e0dda1365 (patch)
tree4e577a25fadedb054e58921a1ced00941d488c90 /sigmodr/widgets/SoundUI.cpp
parent4ed55e72070115125732f5125d3da8efd09ffb2b (diff)
Made the rest of the widgets use pimpl
Diffstat (limited to 'sigmodr/widgets/SoundUI.cpp')
-rw-r--r--sigmodr/widgets/SoundUI.cpp105
1 files changed, 53 insertions, 52 deletions
diff --git a/sigmodr/widgets/SoundUI.cpp b/sigmodr/widgets/SoundUI.cpp
index 14d20a8a..891b0d07 100644
--- a/sigmodr/widgets/SoundUI.cpp
+++ b/sigmodr/widgets/SoundUI.cpp
@@ -17,6 +17,7 @@
// Header include
#include "SoundUI.h"
+#include "SoundUI_p.h"
// Sigmod includes
#include <sigmod/Game.h>
@@ -37,109 +38,109 @@
// Qt includes
#include <QtCore/QBuffer>
-#include <QtCore/QFile>
#include <QtCore/QTime>
#include <QtGui/QLabel>
-#include <QtGui/QVBoxLayout>
-#include <QtUiTools/QUiLoader>
using namespace Sigmod;
using namespace Sigmodr::Widgets;
SoundUI::SoundUI(Sound* sound, QWidget* parent) :
- ObjectUI(parent),
+ ObjectUI(sound, parent),
+ d(new Private(new Sound(*sound)))
+{
+ setWidget(d->makeWidgets(this));
+}
+
+void SoundUI::apply()
+{
+ *qobject_cast<Sound*>(m_object) = *d->m_sound;
+ ObjectUI::apply();
+}
+
+void SoundUI::discard()
+{
+ *d->m_sound = *qobject_cast<Sound*>(m_object);
+ d->resetGui();
+ ObjectUI::discard();
+}
+
+SoundUI::Private::Private(Sound* sound) :
+ ObjectUIPrivate(sound),
+ m_sound(sound),
m_output(new Phonon::AudioOutput(Phonon::MusicCategory, this)),
m_media(new Phonon::MediaObject(this)),
m_buffer(new QBuffer)
{
- setObjects(sound, new Sound(*sound));
}
-SoundUI::~SoundUI()
+SoundUI::Private::~Private()
{
+ delete m_sound;
delete m_media;
delete m_buffer;
}
-void SoundUI::initGui()
+QWidget* SoundUI::Private::makeWidgets(ObjectUI* widget)
{
- QFile file(":/gui/sound.ui");
- file.open(QFile::ReadOnly);
- QWidget *formWidget = QUiLoader().load(&file, this);
- file.close();
- ui_name = formWidget->findChild<KLineEdit*>("varName");
- Phonon::SeekSlider* seeker = formWidget->findChild<Phonon::SeekSlider*>("seeker");
- ui_time = formWidget->findChild<QLabel*>("label");
- ui_play = formWidget->findChild<KPushButton*>("buttonPlay");
- ui_stop = formWidget->findChild<KPushButton*>("buttonStop");
- Phonon::VolumeSlider* sliderVolume = formWidget->findChild<Phonon::VolumeSlider*>("sliderVolume");
- KPushButton* buttonBrowse = formWidget->findChild<KPushButton*>("buttonBrowse");
- Phonon::createPath(m_media, m_output);
- m_media->setTickInterval(100);
- seeker->setMediaObject(m_media);
- sliderVolume->setAudioOutput(m_output);
+ QWidget *form = openUiFile(":/gui/sound.ui", widget);
+ ui_name = form->findChild<KLineEdit*>("varName");
+ Phonon::SeekSlider* seeker = form->findChild<Phonon::SeekSlider*>("seeker");
+ ui_time = form->findChild<QLabel*>("label");
+ ui_play = form->findChild<KPushButton*>("buttonPlay");
+ ui_stop = form->findChild<KPushButton*>("buttonStop");
+ Phonon::VolumeSlider* sliderVolume = form->findChild<Phonon::VolumeSlider*>("sliderVolume");
+ KPushButton* buttonBrowse = form->findChild<KPushButton*>("buttonBrowse");
connect(m_media, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
connect(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), this, SLOT(stateChanged(Phonon::State)));
connect(ui_play, SIGNAL(clicked()), m_media, SLOT(play()));
connect(ui_stop, SIGNAL(clicked()), m_media, SLOT(stop()));
- QVBoxLayout* layout = new QVBoxLayout;
- layout->addWidget(formWidget);
- setLayout(layout);
+ Phonon::createPath(m_media, m_output);
+ m_media->setTickInterval(100);
+ seeker->setMediaObject(m_media);
+ sliderVolume->setAudioOutput(m_output);
ui_play->setIcon(KIcon("media-playback-start"));
ui_stop->setIcon(KIcon("media-playback-stop"));
buttonBrowse->setIcon(KIcon("document-open"));
+ return form;
}
-void SoundUI::refreshGui()
+void SoundUI::Private::refreshGui()
{
resetAudioData();
}
-void SoundUI::setGui()
-{
- ui_name->setText(qobject_cast<Sound*>(modified())->name());
-}
-
-void SoundUI::apply()
-{
- *qobject_cast<Sound*>(original()) = *qobject_cast<Sound*>(modified());
- emit(changed(false));
-}
-
-void SoundUI::discard()
+void SoundUI::Private::resetGui()
{
- *qobject_cast<Sound*>(modified()) = *qobject_cast<Sound*>(original());
- setGui();
- emit(changed(false));
+ ui_name->setText(m_sound->name());
}
-void SoundUI::nameChanged(const QString& name)
+void SoundUI::Private::nameChanged(const QString& name)
{
const int cursor = ui_name->cursorPosition();
- qobject_cast<Sound*>(modified())->setName(name);
+ m_sound->setName(name);
ui_name->setCursorPosition(cursor);
}
-void SoundUI::browse()
+void SoundUI::Private::browse()
{
- QFile file(KFileDialog::getOpenFileName(KUrl("kfiledialog:///audio"), "audio/*|Audio files", this));
+ QFile file(KFileDialog::getOpenFileName(KUrl("kfiledialog:///audio"), "audio/*|Audio files", NULL));
if (file.open(QIODevice::ReadOnly))
{
- qobject_cast<Sound*>(modified())->setData(file.readAll());
+ m_sound->setData(file.readAll());
file.close();
resetAudioData();
}
}
-void SoundUI::stateChanged(Phonon::State newState)
+void SoundUI::Private::stateChanged(Phonon::State newState)
{
switch (newState)
{
case Phonon::ErrorState:
if (m_media->errorType() == Phonon::FatalError)
- KMessageBox::warningContinueCancel(this, "Fatal Error", m_media->errorString());
+ KMessageBox::warningContinueCancel(NULL, "Fatal Error", m_media->errorString());
else
- KMessageBox::warningContinueCancel(this, "Error", m_media->errorString());
+ KMessageBox::warningContinueCancel(NULL, "Error", m_media->errorString());
break;
case Phonon::PlayingState:
disconnect(ui_play, SIGNAL(clicked()), m_media, SLOT(play()));
@@ -167,15 +168,15 @@ void SoundUI::stateChanged(Phonon::State newState)
}
}
-void SoundUI::resetAudioData()
+void SoundUI::Private::resetAudioData()
{
m_media->stop();
- m_buffer->setData(qobject_cast<Sound*>(modified())->data());
+ m_buffer->setData(m_sound->data());
m_media->setCurrentSource(m_buffer);
tick(0);
}
-void SoundUI::tick(qint64 time)
+void SoundUI::Private::tick(qint64 time)
{
QTime currentTime(0, (time / 60000) % 60, (time / 1000) % 60, time % 1000);
qint64 total = ((m_media->state() == Phonon::BufferingState) ? 0 : m_media->totalTime());