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

parley

  • sources
  • kde-4.12
  • 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 }
30 
31 void AudioButton::setSoundFile(KUrl soundFile)
32 {
33  m_url = soundFile;
34  setEnabled(!m_url.path().isEmpty() && m_url.isLocalFile());
35 }
36 
37 void AudioButton::playAudio()
38 {
39  if (!m_player)
40  {
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::playerStateChanged(Phonon::State newState)
55 {
56  switch(newState) {
57  case Phonon::LoadingState: case Phonon::BufferingState: case Phonon::PlayingState:
58  setIcon(KIcon("media-playback-stop"));
59  setText(i18n("Stop"));
60  setToolTip(i18n("Stop"));
61  break;
62  case Phonon::StoppedState: case Phonon::PausedState: case Phonon::ErrorState:
63  setIcon(KIcon("media-playback-start"));
64  setToolTip(i18n("Play"));
65  setText(i18n("Play"));
66  break;
67  }
68 }
QWidget
audiobutton.h
Practice::AudioButton::AudioButton
AudioButton(QWidget *parent)
Definition: audiobutton.cpp:21
Practice::AudioButton::setSoundFile
void setSoundFile(KUrl url)
Definition: audiobutton.cpp:31
QToolButton
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:05 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
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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