1
1
/***********************************************************************
2
2
* Copyright 2008 David Edmundson <kde@davidedmundson.co.uk>
3
* Copyright 2010 Ian Monroe <ian@monroe.nu>
4
4
* This program is free software; you can redistribute it and/or
5
5
* modify it under the terms of the GNU General Public License as
6
6
* published by the Free Software Foundation; either version 2 of
7
7
* the License or (at your option) version 3 or any later version
8
8
* accepted by the membership of KDE e.V. (or its successor approved
9
* by the membership of KDE e.V.), which shall act as a proxy
9
* by the membership of KDE e.V.), which shall act as a proxy
10
10
* defined in Section 14 of version 3 of the license.
12
12
* This program is distributed in the hope that it will be useful,
19
19
***********************************************************************/
21
21
#include "audioView.h"
23
#include "analyzer/blockAnalyzer.h"
22
25
#include "theStream.h"
26
#include "videoWindow.h"
30
#include <QGraphicsItem>
31
#include <QGraphicsGridLayout>
32
#include <QGraphicsPixmapItem>
35
#include <Plasma/Label>
38
#include <KStandardDirs>
27
AudioView::AudioView( QWidget *parent)
31
setAutoFillBackground(true);
33
pal.setColor( QPalette::Window, Qt::black );
43
AudioView::AudioView( QWidget *parent)
44
: QGraphicsView( parent )
51
2 | Image | # - Track |
54
m_widget = new QGraphicsWidget();
55
m_layout = new QGraphicsGridLayout();
56
m_layout->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
57
QGraphicsScene* scene = new QGraphicsScene();
59
#define setup_label(l) \
60
l = new ExpandingTextItem(m_widget); \
61
l->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
64
setup_label(m_artist);
65
m_layout->addItem(m_artist, 0, 1, Qt::AlignVCenter);
67
m_layout->addItem(m_album, 1, 1, Qt::AlignVCenter);
69
m_layout->addItem(m_track, 2, 1, Qt::AlignVCenter);
71
// m_analyzer = new BlockAnalyzer(0);
72
// QGraphicsProxyWidget* analyzerWidget = scene->addWidget(m_analyzer);
73
// analyzerWidget->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
74
// analyzerWidget->setMinimumHeight(100.0);
75
// analyzerWidget->setMaximumWidth(450.0);
76
// analyzerWidget->setMaximumHeight(300.0);
77
// m_layout->addItem(analyzerWidget, 3, 0, 1, 2, Qt::AlignCenter);
78
// engine()->setupAnalyzer(m_analyzer);
79
// m_layout->setRowMinimumHeight(2, 100.0);
81
m_widget->setLayout(m_layout);
83
scene->addItem(m_widget);
87
AudioView::~AudioView()
88
{//scene deleted automatically
91
void AudioView::resizeEvent(QResizeEvent *event)
93
QGraphicsView::resizeEvent(event);
94
QRectF newRect(QPointF(0.0,0.0), event->size());
95
scene()->setSceneRect(newRect);
96
m_widget->resize( event->size());
97
kDebug() << scene()->sceneRect() << m_widget->rect();
100
#define COVER_WIDTH 100.0
101
#define COVER_COLUMN_WIDTH (COVER_WIDTH+3.0)
38
104
AudioView::updateText()
40
m_message = TheStream::prettyTitle();
45
AudioView::paintEvent(QPaintEvent* event)
47
QPainter painter(this);
48
painter.setPen(Qt::white);
49
painter.drawText(rect(), Qt::AlignCenter, m_message);
53
AudioView::~AudioView()
106
QString artist = TheStream::metaData( Phonon::ArtistMetaData );
107
kDebug() << "its being set: " << artist << scene()->sceneRect();
108
m_artist->setPlainText(artist);
109
QString album = TheStream::metaData( Phonon::AlbumMetaData );
110
m_album->setPlainText(album);
113
QString trackName = TheStream::metaData( Phonon::TitleMetaData );
114
QString trackNumber = TheStream::metaData( Phonon::TracknumberMetaData );
116
if ( trackNumber.toInt(&okInt) > 0 && okInt)
118
trackString = QString( trackNumber + QLatin1String(" - ") + trackName );
121
trackString = trackName;
123
m_track->setPlainText( trackString );
124
{ //somewhat of a longshot: try to find Amarok cover for the music
125
QString imagePath = checkForAmarokImage( artist, album );
126
if(imagePath.isNull())
130
m_layout->setColumnFixedWidth(0, 0.0);
134
m_layout->setColumnFixedWidth(0, COVER_COLUMN_WIDTH);
137
m_image = new QGraphicsPixmapItem();
138
scene()->addItem( m_image );
139
m_image->setPos( 3.0, 3.0 );
141
QPixmap cover( imagePath );
142
m_image->setPixmap( cover );
143
qreal width = static_cast<qreal>( cover.width() );
144
qreal scale = COVER_WIDTH / width;
145
m_image->setScale( scale );
151
AudioView::checkForAmarokImage(const QString& artist, const QString& album)
153
KMD5 context( artist.toLower().toLocal8Bit() + album.toLower().toLocal8Bit() );
154
const QByteArray md5sum = context.hexDigest();
155
QString location = KStandardDirs::locate("data", QLatin1String("amarok/albumcovers/large/") + QLatin1String( md5sum ));
156
if(QFileInfo(location).exists())
58
164
#include "audioView.moc"