~ubuntu-branches/ubuntu/natty/kdemultimedia/natty-proposed

« back to all changes in this revision

Viewing changes to dragonplayer/src/app/audioView.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Debian Qt/KDE Maintainers
  • Date: 2011-05-26 02:41:36 UTC
  • mfrom: (0.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 108.
  • Revision ID: james.westby@ubuntu.com-20110526024136-jjwsigfy402jhupm
Tags: upstream-4.6.3
ImportĀ upstreamĀ versionĀ 4.6.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***********************************************************************
2
2
 * Copyright 2008  David Edmundson <kde@davidedmundson.co.uk>
3
 
 *
 
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.
11
11
 *
12
12
 * This program is distributed in the hope that it will be useful,
19
19
 ***********************************************************************/
20
20
 
21
21
#include "audioView.h"
 
22
 
 
23
#include "analyzer/blockAnalyzer.h"
 
24
#include "textItem.h"
22
25
#include "theStream.h"
 
26
#include "videoWindow.h"
 
27
 
 
28
 
 
29
#include <QFileInfo>
 
30
#include <QGraphicsItem>
 
31
#include <QGraphicsGridLayout>
 
32
#include <QGraphicsPixmapItem>
 
33
#include <QLabel>
 
34
 
 
35
#include <Plasma/Label>
 
36
#include <KDebug>
 
37
#include <KMD5>
 
38
#include <KStandardDirs>
23
39
 
24
40
namespace Dragon
25
41
{
26
42
 
27
 
AudioView::AudioView( QWidget *parent) 
28
 
    : QWidget( parent )
29
 
{
30
 
   m_message.clear();
31
 
   setAutoFillBackground(true);
32
 
   QPalette pal;
33
 
   pal.setColor( QPalette::Window, Qt::black );
34
 
   setPalette( pal );
35
 
}
 
43
AudioView::AudioView( QWidget *parent)
 
44
    : QGraphicsView( parent )
 
45
    , m_image(0)
 
46
{
 
47
/*
 
48
   |  0    |   1       |
 
49
 0 | Image | Artist    |
 
50
 1 | Image | Album     |
 
51
 2 | Image | # - Track |
 
52
 3 |    Analyzer       |
 
53
 */
 
54
    m_widget = new QGraphicsWidget();
 
55
    m_layout = new QGraphicsGridLayout();
 
56
    m_layout->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
 
57
    QGraphicsScene* scene = new QGraphicsScene();
 
58
 
 
59
    #define setup_label(l) \
 
60
      l = new ExpandingTextItem(m_widget); \
 
61
      l->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
 
62
 
 
63
 
 
64
    setup_label(m_artist);
 
65
    m_layout->addItem(m_artist, 0, 1, Qt::AlignVCenter);
 
66
    setup_label(m_album);
 
67
    m_layout->addItem(m_album, 1, 1, Qt::AlignVCenter);
 
68
    setup_label(m_track);
 
69
    m_layout->addItem(m_track, 2, 1,  Qt::AlignVCenter);
 
70
 
 
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);
 
80
 
 
81
    m_widget->setLayout(m_layout);
 
82
    setScene(scene);
 
83
    scene->addItem(m_widget);
 
84
    #undef setup_label
 
85
}
 
86
 
 
87
AudioView::~AudioView()
 
88
{//scene deleted automatically
 
89
}
 
90
 
 
91
void AudioView::resizeEvent(QResizeEvent *event)
 
92
{
 
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();
 
98
}
 
99
 
 
100
#define COVER_WIDTH 100.0
 
101
#define COVER_COLUMN_WIDTH (COVER_WIDTH+3.0)
36
102
 
37
103
void
38
104
AudioView::updateText()
39
105
{
40
 
    m_message = TheStream::prettyTitle();
41
 
    repaint();
42
 
}
43
 
 
44
 
void
45
 
AudioView::paintEvent(QPaintEvent* event)
46
 
{
47
 
  QPainter painter(this);
48
 
  painter.setPen(Qt::white);
49
 
  painter.drawText(rect(), Qt::AlignCenter, m_message);
50
 
}
51
 
 
52
 
 
53
 
AudioView::~AudioView()
54
 
{
55
 
}
 
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);
 
111
    QString trackString;
 
112
    {
 
113
        QString trackName = TheStream::metaData( Phonon::TitleMetaData );
 
114
        QString trackNumber = TheStream::metaData( Phonon::TracknumberMetaData );
 
115
        bool okInt = false;
 
116
        if ( trackNumber.toInt(&okInt) > 0 && okInt)
 
117
        {
 
118
            trackString =  QString( trackNumber + QLatin1String(" - ") + trackName );
 
119
        }
 
120
        else
 
121
            trackString = trackName;
 
122
    }
 
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())
 
127
        {
 
128
            delete m_image;
 
129
            m_image = 0;
 
130
            m_layout->setColumnFixedWidth(0, 0.0);
 
131
        }
 
132
        else
 
133
        {
 
134
            m_layout->setColumnFixedWidth(0, COVER_COLUMN_WIDTH);
 
135
            if(!m_image)
 
136
            {
 
137
                m_image = new QGraphicsPixmapItem();
 
138
                scene()->addItem( m_image );
 
139
                m_image->setPos( 3.0, 3.0 );
 
140
            }
 
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 );
 
146
        }
 
147
    }
 
148
}
 
149
 
 
150
QString
 
151
AudioView::checkForAmarokImage(const QString& artist, const QString& album)
 
152
{
 
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())
 
157
        return location;
 
158
    else
 
159
        return QString();
 
160
}
 
161
 
56
162
 
57
163
}
58
164
#include "audioView.moc"