1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-21 16:29:43 +01:00

* Added TrackInfoWidget. WIP.

This commit is contained in:
Christian Muehlhaeuser 2012-05-05 17:00:06 +02:00
parent 906e1147e5
commit 61fb4744f3
3 changed files with 509 additions and 0 deletions

View File

@ -0,0 +1,212 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TrackInfoWidget.h"
#include "ui_TrackInfoWidget.h"
#include "ViewManager.h"
#include "SourceList.h"
#include "playlist/AlbumModel.h"
#include "utils/TomahawkUtils.h"
#include "utils/Logger.h"
using namespace Tomahawk;
TrackInfoWidget::TrackInfoWidget( const Tomahawk::query_ptr& query, QWidget* parent )
: QWidget( parent )
, ui( new Ui::TrackInfoWidget )
, m_infoId( uuid() )
{
ui->setupUi( this );
layout()->setSpacing( 0 );
ui->headerWidget->setStyleSheet( "QWidget#headerWidget { background-image: url(" RESPATH "images/playlist-header-tiled.png); }" );
ui->tracksWidget->setStyleSheet( "background-color: #bababa;" );
ui->statsLabel->setStyleSheet( "QLabel { background-image:url(); border: 2px solid #dddddd; background-color: #faf9f9; border-radius: 4px; padding: 12px; }" );
QFont f = font();
f.setBold( true );
f.setPixelSize( 18 );
ui->trackLabel->setFont( f );
ui->similarTracksLabel->setFont( f );
f.setPixelSize( 14 );
ui->artistLabel->setFont( f );
ui->albumLabel->setFont( f );
ui->byLabel->setFont( f );
ui->fromLabel->setFont( f );
f.setPixelSize( 12 );
ui->statsLabel->setFont( f );
ui->similarTracksView->setFrameShape( QFrame::NoFrame );
ui->similarTracksView->setAttribute( Qt::WA_MacShowFocusRect, 0 );
ui->similarTracksView->setStyleSheet( "QListView { background-color: transparent; } QListView::item { background-color: transparent; }" );
QPalette p = ui->trackLabel->palette();
p.setColor( QPalette::Foreground, Qt::white );
ui->trackLabel->setPalette( p );
ui->artistLabel->setPalette( p );
ui->albumLabel->setPalette( p );
ui->byLabel->setPalette( p );
ui->fromLabel->setPalette( p );
m_albumsModel = new AlbumModel( ui->similarTracksView );
ui->similarTracksView->setAlbumModel( m_albumsModel );
ui->similarTracksView->proxyModel()->sort( -1 );
m_pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultAlbumCover, TomahawkUtils::ScaledCover, QSize( 48, 48 ) );
load( query );
}
TrackInfoWidget::~TrackInfoWidget()
{
delete ui;
}
Tomahawk::playlistinterface_ptr
TrackInfoWidget::playlistInterface() const
{
return ui->similarTracksView->playlistInterface();
}
bool
TrackInfoWidget::isBeingPlayed() const
{
//tDebug() << Q_FUNC_INFO << "audioengine playlistInterface = " << AudioEngine::instance()->currentTrackPlaylist()->id();
//tDebug() << Q_FUNC_INFO << "albumsView playlistInterface = " << ui->albumsView->playlistInterface()->id();
//tDebug() << Q_FUNC_INFO << "tracksView playlistInterface = " << ui->tracksView->playlistInterface()->id();
if ( ui->similarTracksView->playlistInterface() == AudioEngine::instance()->currentTrackPlaylist() )
return true;
return false;
}
void
TrackInfoWidget::load( const query_ptr& query )
{
m_query = query;
m_artist = Artist::get( m_query->artist() );
if ( !m_query.isNull() )
{
disconnect( m_query.data(), SIGNAL( statsLoaded() ), this, SLOT( onStatsLoaded() ) );
disconnect( m_query.data(), SIGNAL( updated() ), this, SLOT( onCoverUpdated() ) );
disconnect( m_artist.data(), SIGNAL( statsLoaded() ), this, SLOT( onStatsLoaded() ) );
disconnect( m_artist.data(), SIGNAL( similarArtistsLoaded() ), this, SLOT( onSimilarArtistsLoaded() ) );
}
connect( m_artist.data(), SIGNAL( similarArtistsLoaded() ), SLOT( onSimilarArtistsLoaded() ) );
connect( m_artist.data(), SIGNAL( statsLoaded() ), SLOT( onStatsLoaded() ) );
connect( m_query.data(), SIGNAL( similarTracksLoaded() ), SLOT( onSimilarTracksLoaded() ) );
connect( m_query.data(), SIGNAL( updated() ), SLOT( onCoverUpdated() ) );
connect( m_query.data(), SIGNAL( statsLoaded() ), SLOT( onStatsLoaded() ) );
m_artist->loadStats();
m_query->loadStats();
onCoverUpdated();
ui->trackLabel->setText( query->track() );
ui->artistLabel->setText( query->artist() );
ui->albumLabel->setText( query->album() );
ui->fromLabel->setVisible( !query->album().isEmpty() );
m_query->similarTracks();
m_albumsModel->addArtists( m_artist->similarArtists() );
m_albumsModel->clear();
}
void
TrackInfoWidget::onCoverUpdated()
{
if ( m_query->cover( QSize( 0, 0 ) ).isNull() )
return;
m_pixmap = m_query->cover( ui->cover->size() );
ui->cover->setPixmap( m_pixmap );
}
void
TrackInfoWidget::onStatsLoaded()
{
QList< Tomahawk::PlaybackLog > history = m_query->playbackHistory( SourceList::instance()->getLocal() );
const unsigned int trackCounter = m_query->playbackCount( SourceList::instance()->getLocal() );
const unsigned int artistCounter = m_artist->playbackCount( SourceList::instance()->getLocal() );
QString stats;
if ( trackCounter )
stats = tr( "You've listened to this track %n time(s).", "", trackCounter );
else
stats = tr( "You've never listened to this track before." );
if ( history.count() )
{
stats += "\n" + tr( "You first listened to it on %1." ).arg( QDateTime::fromTime_t( history.first().timestamp ).toString( "dd MMM yyyy" ) );
}
if ( artistCounter )
stats += "\n" + tr( "You've listened to %1 %n time(s).", "", artistCounter ).arg( m_artist->name() );
else
stats += "\n" + tr( "You've never listened to %1 before." ).arg( m_artist->name() );
ui->statsLabel->setText( stats );
}
void
TrackInfoWidget::onSimilarArtistsLoaded()
{
Artist* artist = qobject_cast<Artist*>( sender() );
// m_albumsModel->addArtists( artist->similarArtists() );
}
void
TrackInfoWidget::onSimilarTracksLoaded()
{
m_albumsModel->addQueries( m_query->similarTracks() );
}
void
TrackInfoWidget::changeEvent( QEvent* e )
{
QWidget::changeEvent( e );
switch ( e->type() )
{
case QEvent::LanguageChange:
ui->retranslateUi( this );
break;
default:
break;
}
}

View File

@ -0,0 +1,95 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \class TrackInfoWidget
* \brief ViewPage, which displays a track
*
* This Tomahawk ViewPage displays a track
* It is our default ViewPage when showing an track via ViewManager.
*
*/
#ifndef TRACKINFOWIDGET_H
#define TRACKINFOWIDGET_H
#include <QtGui/QWidget>
#include "PlaylistInterface.h"
#include "ViewPage.h"
#include "infosystem/InfoSystem.h"
#include "DllMacro.h"
#include "Typedefs.h"
class AlbumModel;
namespace Ui
{
class TrackInfoWidget;
}
class DLLEXPORT TrackInfoWidget : public QWidget, public Tomahawk::ViewPage
{
Q_OBJECT
public:
TrackInfoWidget( const Tomahawk::query_ptr& query, QWidget* parent = 0 );
~TrackInfoWidget();
virtual QWidget* widget() { return this; }
virtual Tomahawk::playlistinterface_ptr playlistInterface() const;
virtual QString title() const { return QString(); }
virtual QString description() const { return QString(); }
virtual QString longDescription() const { return QString(); }
virtual QPixmap pixmap() const { if ( m_pixmap.isNull() ) return Tomahawk::ViewPage::pixmap(); else return m_pixmap; }
virtual bool isTemporaryPage() const { return true; }
virtual bool showStatsBar() const { return false; }
virtual bool showInfoBar() const { return false; }
virtual bool jumpToCurrentTrack() { return false; }
virtual bool isBeingPlayed() const;
public slots:
void load( const Tomahawk::query_ptr& query );
protected:
void changeEvent( QEvent* e );
private slots:
void onCoverUpdated();
void onStatsLoaded();
void onSimilarArtistsLoaded();
void onSimilarTracksLoaded();
private:
Ui::TrackInfoWidget *ui;
Tomahawk::query_ptr m_query;
Tomahawk::artist_ptr m_artist;
AlbumModel* m_albumsModel;
QPixmap m_pixmap;
QString m_infoId;
};
#endif // TRACKINFOWIDGET_H

View File

@ -0,0 +1,202 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TrackInfoWidget</class>
<widget class="QWidget" name="TrackInfoWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>852</width>
<height>571</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,1">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QWidget" name="headerWidget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="margin">
<number>12</number>
</property>
<item>
<widget class="QLabel" name="cover">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>128</width>
<height>128</height>
</size>
</property>
<property name="text">
<string>Cover</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>16</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="trackLabel">
<property name="text">
<string>Track</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="byLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>by </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="artistLabel">
<property name="text">
<string>Artist</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="fromLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>from </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="albumLabel">
<property name="text">
<string>Album</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>16</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="statsLabel">
<property name="text">
<string>Statistics</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="tracksWidget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="similarTracksLabel">
<property name="text">
<string>Similar Tracks</string>
</property>
<property name="indent">
<number>8</number>
</property>
</widget>
</item>
<item>
<widget class="AlbumView" name="similarTracksView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>AlbumView</class>
<extends>QListView</extends>
<header>playlist/AlbumView.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>