• 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
  • editor
audiowidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  Copyright 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
4 
5  ***************************************************************************/
6 
7 /***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "audiowidget.h"
17 
18 #include <Phonon/MediaObject>
19 
20 #include <keduvocexpression.h>
21 
22 #include <KIcon>
23 #include <kdebug.h>
24 
25 using namespace Editor;
26 
27 AudioWidget::AudioWidget(QWidget *parent) : QWidget(parent)
28 {
29  setupUi(this);
30  m_currentTranslation = -1;
31  m_player = 0;
32 
33  connect(audioUrlRequester, SIGNAL(textChanged(const QString&)), SLOT(slotAudioFileChanged(const QString&)));
34  connect(playButton, SIGNAL(clicked()), SLOT(playAudio()));
35 // connect(recordButton, SIGNAL(clicked()), SLOT(recordAudio()));
36 
37  playButton->setEnabled(false);
38  playButton->setIcon(KIcon("media-playback-start"));
39  recordButton->setVisible(false);
40 // recordButton->setEnabled(false);
41 // recordButton->setIcon(KIcon("media-record"));
42  audioUrlRequester->setEnabled(false);
43 }
44 
45 void AudioWidget::setTranslation(KEduVocExpression* entry, int translation)
46 {
47  m_currentTranslation = translation;
48  m_entry = entry;
49 
50  if (m_entry) {
51  recordButton->setEnabled(true);
52  audioUrlRequester->setEnabled(true);
53  audioUrlRequester->setUrl(m_entry->translation(m_currentTranslation)->soundUrl().toLocalFile());
54  } else {
55  recordButton->setEnabled(false);
56  audioUrlRequester->setEnabled(false);
57  if (m_player) {
58  if (m_player->state() == Phonon::PlayingState) {
59  playButton->setEnabled(true);
60  } else {
61  playButton->setEnabled(false);
62  }
63  }
64  audioUrlRequester->clear();
65  }
66 }
67 
68 void AudioWidget::slotAudioFileChanged(const QString & url)
69 {
70  if (m_entry) {
71  m_entry->translation(m_currentTranslation)->setSoundUrl(KUrl(url));
72  }
73  playButton->setEnabled(!url.isEmpty());
74 }
75 
76 void AudioWidget::playAudio()
77 {
78  KUrl soundFile = m_entry->translation(m_currentTranslation)->soundUrl();
79 
80  if (!m_player) {
81  m_player = Phonon::createPlayer(Phonon::NotificationCategory, soundFile);
82  m_player->setParent(this);
83  connect(m_player, SIGNAL(finished()), SLOT(slotPlaybackFinished()));
84  } else {
85  if (m_player->state() == Phonon::PlayingState) {
86  m_player->stop();
87  slotPlaybackFinished();
88  return;
89  }
90  m_player->setCurrentSource(soundFile);
91  }
92  playButton->setIcon(KIcon("media-playback-stop"));
93  m_player->play();
94 }
95 
96 /*
97 void AudioWidget::recordAudio()
98 {
100 }
101 */
102 
103 void AudioWidget::slotPlaybackFinished()
104 {
105  playButton->setIcon(KIcon("media-playback-start"));
106  playButton->setEnabled(!audioUrlRequester->url().isEmpty());
107 }
108 
109 #include "audiowidget.moc"
QWidget
QWidget::setupUi
void setupUi(QWidget *widget)
Phonon::MediaObject::state
State state() const
Phonon::MediaObject::play
void play()
Phonon::createPlayer
MediaObject * createPlayer(Phonon::Category category, const MediaSource &source)
QString::isEmpty
bool isEmpty() const
Phonon::MediaObject::stop
void stop()
QString
QObject::setParent
void setParent(QObject *parent)
Phonon::MediaObject::setCurrentSource
void setCurrentSource(const MediaSource &source)
Editor::AudioWidget::setTranslation
void setTranslation(KEduVocExpression *entry, int translation)
Update the word.
Definition: audiowidget.cpp:45
Editor::AudioWidget::AudioWidget
AudioWidget(QWidget *parent=0)
Definition: audiowidget.cpp:27
audiowidget.h
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