• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

parley

  • sources
  • kde-4.14
  • kdeedu
  • parley
  • src
  • practice
audiobutton.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  Copyright 2010 Daniel Laidig <d.laidig@gmx.de>
3  ***************************************************************************/
4 
5 /***************************************************************************
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  ***************************************************************************/
13 
14 #include "audiobutton.h"
15 
16 #include <kicon.h>
17 #include <klocale.h>
18 
19 using namespace Practice;
20 
21 AudioButton::AudioButton(QWidget *parent)
22  : QToolButton(parent), m_player(0)
23 {
24  setEnabled(false);
25  setIcon(KIcon("media-playback-start"));
26  setText(i18n("Play"));
27  setToolTip(i18n("Play"));
28  connect(this, SIGNAL(clicked(bool)), this, SLOT(playAudio()));
29  connect(parent, SIGNAL(stopAudio()), this, SLOT(stopAudio()));
30 }
31 
32 void AudioButton::setSoundFile(KUrl soundFile)
33 {
34  m_url = soundFile;
35  setEnabled(!m_url.path().isEmpty() && m_url.isLocalFile());
36 }
37 
38 void AudioButton::playAudio()
39 {
40  if (!m_player) {
41  m_player = Phonon::createPlayer(Phonon::NotificationCategory, m_url);
42  m_player->setParent(this);
43  connect(m_player, SIGNAL(stateChanged(Phonon::State, Phonon::State)), this, SLOT(playerStateChanged(Phonon::State)));
44  } else {
45  if (m_player->state() == Phonon::PlayingState) {
46  m_player->stop();
47  return;
48  }
49  m_player->setCurrentSource(m_url);
50  }
51  m_player->play();
52 }
53 
54 void AudioButton::stopAudio()
55 {
56  if (m_player && m_player->state() == Phonon::PlayingState) {
57  m_player->stop();
58  }
59 }
60 
61 void AudioButton::playerStateChanged(Phonon::State newState)
62 {
63  switch (newState) {
64  case Phonon::LoadingState: case Phonon::BufferingState: case Phonon::PlayingState:
65  setIcon(KIcon("media-playback-stop"));
66  setText(i18n("Stop"));
67  setToolTip(i18n("Stop"));
68  break;
69  case Phonon::StoppedState: case Phonon::PausedState: case Phonon::ErrorState:
70  setIcon(KIcon("media-playback-start"));
71  setToolTip(i18n("Play"));
72  setText(i18n("Play"));
73  break;
74  }
75 }
QWidget
Phonon::MediaObject::state
State state() const
Phonon::MediaObject::play
void play()
Phonon::createPlayer
MediaObject * createPlayer(Phonon::Category category, const MediaSource &source)
QAbstractButton::setIcon
void setIcon(const QIcon &icon)
audiobutton.h
QWidget::setEnabled
void setEnabled(bool)
QAbstractButton::clicked
void clicked(bool checked)
Practice::AudioButton::AudioButton
AudioButton(QWidget *parent)
Definition: audiobutton.cpp:21
Phonon::MediaObject::stop
void stop()
QToolButton
QObject::setParent
void setParent(QObject *parent)
Phonon::MediaObject::setCurrentSource
void setCurrentSource(const MediaSource &source)
Practice::AudioButton::setSoundFile
void setSoundFile(KUrl url)
Definition: audiobutton.cpp:32
QAbstractButton::setText
void setText(const QString &text)
QWidget::setToolTip
void setToolTip(const QString &)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:15:56 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

parley

Skip menu "parley"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal