1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "UBGraphicsAudioItem.h"
#include "UBGraphicsAudioItemDelegate.h"
#include "UBGraphicsDelegateFrame.h"
#include "core/memcheck.h"
UBGraphicsAudioItem::UBGraphicsAudioItem(const QUrl& pAudioFileUrl, QGraphicsItem *parent):
UBGraphicsMediaItem(pAudioFileUrl,parent)
{
update();
mAudioOutput = new Phonon::AudioOutput ( Phonon::MusicCategory, this );
mMediaObject = new Phonon::MediaObject ( this );
mMediaObject->setTickInterval ( 1000 );
Phonon::createPath ( mMediaObject, mAudioOutput );
mMediaObject->clearQueue();
mSource = Phonon::MediaSource(pAudioFileUrl);
mMediaObject->setCurrentSource (mSource );
connect (mMediaObject,SIGNAL ( tick ( qint64 ) ), this, SLOT ( tick ( qint64 ) ) );
connect(mMediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(onStateChanged(Phonon::State,Phonon::State)));
mAudioWidget = new QWidget();
mSeekSlider = new Phonon::SeekSlider ( mAudioWidget );
mSeekSlider->setMediaObject ( mMediaObject );
QPalette palette;
palette.setBrush ( QPalette::Light, Qt::darkGray );
mTimeLcd = new QLCDNumber;
mTimeLcd->setPalette ( palette );
mTimeLcd->display ( "00:00" );
QHBoxLayout *seekerLayout = new QHBoxLayout;
seekerLayout->addWidget ( mSeekSlider );
seekerLayout->addWidget ( mTimeLcd );
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout ( seekerLayout );
mAudioWidget->setLayout ( mainLayout );
setWidget ( mAudioWidget );
UBGraphicsAudioItemDelegate* delegate = new UBGraphicsAudioItemDelegate ( this, mMediaObject );
delegate->init();
setDelegate ( delegate );
mDelegate->frame()->setOperationMode ( UBGraphicsDelegateFrame::Resizing );
}
void UBGraphicsAudioItem::onStateChanged(Phonon::State newState, Phonon::State oldState)
{
qDebug() << "STATE CHANGED!";
qDebug() << "old state:" << oldState;
qDebug() << "new state:" << newState;
if(oldState == Phonon::ErrorState)
{
qDebug() << "ERROR! : " << mMediaObject->errorString();
}
else if(newState == Phonon::LoadingState)
{
int itotaltime = mMediaObject->totalTime();
qDebug() << "[Loading State entered!] Total time : " << itotaltime;
}
}
UBGraphicsAudioItem::~UBGraphicsAudioItem()
{
//NOOP
}
UBItem* UBGraphicsAudioItem::deepCopy() const
{
QUrl audioUrl = this->mediaFileUrl();
UBGraphicsAudioItem *copy = new UBGraphicsAudioItem(audioUrl, parentItem());
copy->setPos(this->pos());
copy->setZValue(this->zValue());
copy->setTransform(this->transform());
copy->setFlag(QGraphicsItem::ItemIsMovable, true);
copy->setFlag(QGraphicsItem::ItemIsSelectable, true);
copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType));
copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked));
copy->setUuid(this->uuid()); // this is OK as long as Videos are imutable
copy->setSourceUrl(this->sourceUrl());
copy->resize(this->size());
// TODO UB 4.7 complete all members
return copy;
}
void UBGraphicsAudioItem::tick ( qint64 time )
{
QTime displayTime ( 0, ( time / 60000 ) % 60, ( time / 1000 ) % 60 );
mTimeLcd->display ( displayTime.toString ( "mm:ss" ) );
}