From a467b8f2e86434e28c5b3cc8ec336f6dbfadd8a6 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sun, 4 Sep 2011 04:23:10 +0200 Subject: [PATCH] * Added initial ContextView. Yikes. --- src/libtomahawk/CMakeLists.txt | 15 + src/libtomahawk/context/ContextPage.cpp | 94 ++++++ src/libtomahawk/context/ContextPage.h | 91 ++++++ src/libtomahawk/context/ContextWidget.cpp | 293 ++++++++++++++++++ src/libtomahawk/context/ContextWidget.h | 86 +++++ src/libtomahawk/context/ContextWidget.ui | 76 +++++ .../context/pages/RelatedArtistsContext.cpp | 125 ++++++++ .../context/pages/RelatedArtistsContext.h | 67 ++++ .../context/pages/TopTracksContext.cpp | 128 ++++++++ .../context/pages/TopTracksContext.h | 67 ++++ src/libtomahawk/context/pages/WebContext.cpp | 37 +++ src/libtomahawk/context/pages/WebContext.h | 45 +++ .../context/pages/WikipediaContext.cpp | 43 +++ .../context/pages/WikipediaContext.h | 74 +++++ src/libtomahawk/globalactionmanager.cpp | 2 +- src/libtomahawk/playlist/infobar/infobar.cpp | 9 +- src/libtomahawk/playlist/infobar/infobar.h | 5 + src/libtomahawk/playlist/infobar/infobar.ui | 259 +++++++--------- .../playlist/playlistitemdelegate.cpp | 2 +- src/libtomahawk/playlist/playlistmodel.cpp | 2 +- src/libtomahawk/playlist/trackview.cpp | 17 +- src/libtomahawk/playlist/trackview.h | 8 + src/libtomahawk/viewmanager.cpp | 100 ++---- src/libtomahawk/viewmanager.h | 26 +- src/libtomahawk/viewpage.h | 1 - src/libtomahawk/widgets/HeaderLabel.cpp | 20 +- src/libtomahawk/widgets/HeaderLabel.h | 8 +- .../widgets/infowidgets/ArtistInfoWidget.cpp | 5 +- src/tomahawkwindow.cpp | 96 +++++- src/tomahawkwindow.h | 10 + 30 files changed, 1553 insertions(+), 258 deletions(-) create mode 100644 src/libtomahawk/context/ContextPage.cpp create mode 100644 src/libtomahawk/context/ContextPage.h create mode 100644 src/libtomahawk/context/ContextWidget.cpp create mode 100644 src/libtomahawk/context/ContextWidget.h create mode 100644 src/libtomahawk/context/ContextWidget.ui create mode 100644 src/libtomahawk/context/pages/RelatedArtistsContext.cpp create mode 100644 src/libtomahawk/context/pages/RelatedArtistsContext.h create mode 100644 src/libtomahawk/context/pages/TopTracksContext.cpp create mode 100644 src/libtomahawk/context/pages/TopTracksContext.h create mode 100644 src/libtomahawk/context/pages/WebContext.cpp create mode 100644 src/libtomahawk/context/pages/WebContext.h create mode 100644 src/libtomahawk/context/pages/WikipediaContext.cpp create mode 100644 src/libtomahawk/context/pages/WikipediaContext.h diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 6a6f84cab..6bcd65ce3 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -40,6 +40,13 @@ set( libSources audio/audioengine.cpp + context/ContextPage.cpp + context/ContextWidget.cpp + context/pages/TopTracksContext.cpp + context/pages/RelatedArtistsContext.cpp + context/pages/WikipediaContext.cpp + context/pages/WebContext.cpp + database/database.cpp database/fuzzyindex.cpp database/databasecollection.cpp @@ -234,6 +241,13 @@ set( libHeaders audio/audioengine.h + context/ContextPage.h + context/ContextWidget.h + context/pages/TopTracksContext.h + context/pages/RelatedArtistsContext.h + context/pages/WikipediaContext.h + context/pages/WebContext.h + database/database.h database/fuzzyindex.h database/databaseworker.h @@ -417,6 +431,7 @@ set( libUI ${libUI} widgets/infowidgets/AlbumInfoWidget.ui playlist/topbar/topbar.ui playlist/infobar/infobar.ui + context/ContextWidget.ui ) include_directories( . ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/.. .. diff --git a/src/libtomahawk/context/ContextPage.cpp b/src/libtomahawk/context/ContextPage.cpp new file mode 100644 index 000000000..2a71f5716 --- /dev/null +++ b/src/libtomahawk/context/ContextPage.cpp @@ -0,0 +1,94 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#include "ContextPage.h" + +#include + +using namespace Tomahawk; + + +void +ContextProxyPage::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget ) +{ + painter->save(); + + painter->setRenderHint( QPainter::Antialiasing, true ); + painter->setPen( StyleHelper::headerHighlightColor() ); + painter->setBrush( StyleHelper::headerHighlightColor() ); + painter->drawRoundedRect( option->rect, 4.0, 4.0 ); + + QFont f( font() ); + f.setBold( true ); + f.setPixelSize( 14 ); + painter->setFont( f ); + painter->setPen( Qt::white ); + + QRect r( 1, 1, option->rect.width(), 19 ); + QTextOption to( Qt::AlignCenter ); + painter->drawText( r, m_page->title(), to ); + + painter->restore(); + + QGraphicsWidget::paint( painter, option, widget ); +} + + +void +ContextProxyPage::setPage( Tomahawk::ContextPage* page ) +{ + m_page = page; + + QGraphicsWebView* testWebView = qobject_cast( page->widget() ); + if ( testWebView ) + { + setContentsMargins( 4, 4, 4, 4 ); + } + + QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(); + layout->setContentsMargins( 4, 20, 4, 4 ); + layout->addItem( page->widget() ); + setLayout( layout ); + + page->widget()->installEventFilter( this ); + page->widget()->installSceneEventFilter( this ); +} + + +bool +ContextProxyPage::eventFilter( QObject* watched, QEvent* event ) +{ + if ( event->type() == QEvent::GrabMouse ) + { + emit focused(); + } + + return QGraphicsWidget::eventFilter( watched, event ); +} + + +bool +ContextProxyPage::sceneEvent( QEvent* event ) +{ + if ( event->type() == QEvent::GrabMouse ) + { + emit focused(); + } + + return QGraphicsWidget::sceneEvent( event ); +} diff --git a/src/libtomahawk/context/ContextPage.h b/src/libtomahawk/context/ContextPage.h new file mode 100644 index 000000000..83bae8902 --- /dev/null +++ b/src/libtomahawk/context/ContextPage.h @@ -0,0 +1,91 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#ifndef CONTEXTPAGE_H +#define CONTEXTPAGE_H + +#include +#include +#include + +#include "typedefs.h" +#include "playlistinterface.h" +#include "utils/stylehelper.h" +#include "utils/tomahawkutils.h" + +#include "dllmacro.h" +#include + +namespace Tomahawk +{ + +class DLLEXPORT ContextPage : public QObject +{ + Q_OBJECT + +public: + ContextPage() {} + virtual ~ContextPage() {} + + virtual QGraphicsWidget* widget() = 0; + virtual Tomahawk::PlaylistInterface* playlistInterface() const = 0; + + virtual QString title() const = 0; + virtual QString description() const = 0; + virtual QPixmap pixmap() const { return QPixmap( RESPATH "icons/tomahawk-icon-128x128.png" ); } + + virtual bool jumpToCurrentTrack() = 0; + +public slots: + virtual void setQuery( const Tomahawk::query_ptr& query ) = 0; + +signals: + void nameChanged( const QString& ); + void descriptionChanged( const QString& ); + void pixmapChanged( const QPixmap& ); + void destroyed( QWidget* widget ); +}; + + +class DLLEXPORT ContextProxyPage : public QGraphicsWidget +{ + Q_OBJECT + +public: + ContextProxyPage() : QGraphicsWidget() + {} + + Tomahawk::ContextPage* page() const { return m_page; } + void setPage( Tomahawk::ContextPage* page ); + + virtual bool eventFilter( QObject* watched, QEvent* event ); + +signals: + void focused(); + +protected: + virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget ); + virtual bool sceneEvent( QEvent* event ); + +private: + Tomahawk::ContextPage* m_page; +}; + +}; // ns + +#endif //CONTEXTPAGE_H diff --git a/src/libtomahawk/context/ContextWidget.cpp b/src/libtomahawk/context/ContextWidget.cpp new file mode 100644 index 000000000..8546518db --- /dev/null +++ b/src/libtomahawk/context/ContextWidget.cpp @@ -0,0 +1,293 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#include "ContextWidget.h" +#include "ui_ContextWidget.h" + +#include +#include +#include +#include + +#include "context/ContextPage.h" +#include "context/pages/RelatedArtistsContext.h" +#include "context/pages/TopTracksContext.h" +#include "context/pages/WikipediaContext.h" + +#include "playlist/artistview.h" +#include "playlist/treemodel.h" + +#define ANIMATION_TIME 450 +#define SLIDE_TIME 350 + +using namespace Tomahawk; + + +ContextWidget::ContextWidget( QWidget* parent ) + : QWidget( parent ) + , ui( new Ui::ContextWidget ) + , m_minHeight( 24 ) + , m_currentView( 0 ) +{ + ui->setupUi( this ); + TomahawkUtils::unmarginLayout( layout() ); + setContentsMargins( 0, 0, 0, 0 ); + + m_scene = new QGraphicsScene( this ); + + TopTracksContext* ttc = new TopTracksContext(); + RelatedArtistsContext* rac = new RelatedArtistsContext(); + WebContext* wiki = new WikipediaContext(); + WebContext* lastfm = new LastfmContext(); + + m_views << ttc; + m_views << rac; + m_views << wiki; + m_views << lastfm; + + foreach ( ContextPage* view, m_views ) + { + ContextProxyPage* page = new ContextProxyPage(); + page->setPage( view ); + m_scene->addItem( page ); + + connect( page, SIGNAL( focused() ), SLOT( onPageFocused() ) ); + m_pages << page; + } + + ui->contextView->setScene( m_scene ); + ui->contextView->setFrameShape( QFrame::NoFrame ); + ui->contextView->setStyleSheet( "background: transparent" ); + ui->contextView->setAttribute( Qt::WA_MacShowFocusRect, 0 ); + ui->contextView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); + + ui->contextView->hide(); + + QPalette p = palette(); + p.setBrush( QPalette::Window, QColor( 0x70, 0x70, 0x70 ) ); + setPalette( p ); + + QPalette whitePal = ui->toggleButton->palette(); + whitePal.setColor( QPalette::Foreground, Qt::white ); + ui->toggleButton->setPalette( whitePal ); + + QFont boldFont = ui->toggleButton->font(); + boldFont.setPixelSize( 12 ); + boldFont.setBold( true ); + ui->toggleButton->setFont( boldFont ); + ui->toggleButton->setText( tr( "Open Dashboard" ) ); + + setAutoFillBackground( true ); + setFixedHeight( m_minHeight ); + + connect( ui->toggleButton, SIGNAL( clicked() ), SLOT( toggleSize() ) ); + + m_timeLine = new QTimeLine( ANIMATION_TIME, this ); + m_timeLine->setUpdateInterval( 20 ); + m_timeLine->setEasingCurve( QEasingCurve::OutCubic ); + + connect( m_timeLine, SIGNAL( frameChanged( int ) ), SLOT( onAnimationStep( int ) ) ); + connect( m_timeLine, SIGNAL( finished() ), SLOT( onAnimationFinished() ) ); +} + + +ContextWidget::~ContextWidget() +{ +} + + +void +ContextWidget::layoutViews( bool animate ) +{ + int smallViewWidth = 120; + float smallViewOpacity = 0.6; + + int margin = 6; + int maxVisible = 2; + int itemSize = ( m_scene->sceneRect().width() - smallViewWidth * 2 ) / maxVisible; + int firstPos = margin; + float opacity; + + if ( m_currentView > 0 ) + firstPos = smallViewWidth; + + if ( m_currentView + maxVisible >= m_pages.count() ) + { + int delta = m_pages.count() - m_currentView; + firstPos = m_scene->sceneRect().width() - ( delta * itemSize ) + 1; + } + + for ( int i = 0; i < m_pages.count(); i++ ) + { + QGraphicsWidget* view = m_pages.at( i ); + + int x = firstPos - ( ( m_currentView - i ) * itemSize ); + + if ( ( x < smallViewWidth && x < firstPos ) || i > m_currentView + maxVisible - 1 ) + { + opacity = smallViewOpacity; + } + else + { + opacity = 1.0; + } + + { + QPropertyAnimation* animation = new QPropertyAnimation( view, "opacity" ); + animation->setDuration( SLIDE_TIME ); + animation->setEndValue( opacity ); + animation->start(); + } + + QRect rect( x, margin, itemSize - margin * 2, m_scene->sceneRect().height() - margin * 2 ); + if ( animate ) + { + { + QPropertyAnimation* animation = new QPropertyAnimation( view, "geometry" ); + animation->setDuration( SLIDE_TIME ); + animation->setEndValue( rect ); + animation->start(); + } + } + else + { + view->setGeometry( rect ); + } + } +} + + +void +ContextWidget::onPageFocused() +{ + ContextProxyPage* widget = qobject_cast< ContextProxyPage* >( sender() ); + + int i = 0; + foreach ( ContextProxyPage* view, m_pages ) + { + if ( view == widget ) + { + m_currentView = i; + layoutViews( true ); + return; + } + + i++; + } +} + + +void +ContextWidget::fadeOut( bool animate ) +{ + foreach ( QGraphicsWidget* view, m_pages ) + { + if ( animate ) + { + QPropertyAnimation* animation = new QPropertyAnimation( view, "opacity" ); + animation->setDuration( SLIDE_TIME ); + animation->setEndValue( 0.0 ); + animation->start(); + } + else + view->setOpacity( 0.0 ); + } +} + + +void +ContextWidget::setQuery( const Tomahawk::query_ptr& query, bool force ) +{ + if ( query.isNull() ) + return; + if ( !force && !m_query.isNull() && query->artist() == m_query->artist() ) + return; + + m_query = query; + if ( height() > m_minHeight ) + { + foreach ( ContextProxyPage* proxy, m_pages ) + { + proxy->page()->setQuery( query ); + } + + layoutViews( true ); + } +} + + +void +ContextWidget::toggleSize() +{ + m_maxHeight = TomahawkUtils::tomahawkWindow()->height() * 0.3; + + if ( height() == m_minHeight ) + { + ui->toggleButton->setText( tr( "Close Dashboard" ) ); + + m_timeLine->setFrameRange( height(), m_maxHeight ); + m_timeLine->setDirection( QTimeLine::Forward ); + m_timeLine->start(); + } + else + { + ui->toggleButton->setText( tr( "Open Dashboard" ) ); + ui->contextView->hide(); + + m_timeLine->setFrameRange( m_minHeight, height() ); + m_timeLine->setDirection( QTimeLine::Backward ); + m_timeLine->start(); + } +} + + +void +ContextWidget::onAnimationStep( int frame ) +{ + setFixedHeight( frame ); +} + + +void +ContextWidget::onAnimationFinished() +{ + if ( m_timeLine->direction() == QTimeLine::Forward ) + { + setFixedHeight( m_maxHeight ); + ui->contextView->show(); + + fadeOut( false ); + m_scene->setSceneRect( ui->contextView->viewport()->rect() ); + layoutViews( false ); + setQuery( m_query, true ); + } + else + { + setFixedHeight( m_minHeight ); + } +} + + +void +ContextWidget::resizeEvent( QResizeEvent* e ) +{ + QWidget::resizeEvent( e ); + + m_scene->setSceneRect( ui->contextView->viewport()->rect() ); + layoutViews( false ); +} diff --git a/src/libtomahawk/context/ContextWidget.h b/src/libtomahawk/context/ContextWidget.h new file mode 100644 index 000000000..fc79648ac --- /dev/null +++ b/src/libtomahawk/context/ContextWidget.h @@ -0,0 +1,86 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#ifndef CONTEXTWIDGET_H +#define CONTEXTWIDGET_H + +#include + +#include "dllmacro.h" + +#include "query.h" + +class QGraphicsScene; +class QGraphicsWebView; +class QGraphicsWidget; +class QTimeLine; + +namespace Tomahawk +{ + class ContextPage; + class ContextProxyPage; +} + +namespace Ui +{ + class ContextWidget; +} + +class DLLEXPORT ContextWidget : public QWidget +{ +Q_OBJECT + +public: + ContextWidget( QWidget* parent = 0 ); + ~ContextWidget(); + +public slots: + void setQuery( const Tomahawk::query_ptr& query, bool force = false ); + + void toggleSize(); + +private slots: + void onPageFocused(); + + void onAnimationStep( int frame ); + void onAnimationFinished(); + +protected: + void resizeEvent( QResizeEvent* e ); + +private: + void fadeOut( bool animate ); + + void layoutViews( bool animate = true ); + + Ui::ContextWidget* ui; + + int m_minHeight; + int m_maxHeight; + QTimeLine* m_timeLine; + + QGraphicsScene* m_scene; + QList m_views; + QList m_pages; + + int m_currentView; + + Tomahawk::query_ptr m_query; +}; + +#endif // CONTEXTWIDGET_H diff --git a/src/libtomahawk/context/ContextWidget.ui b/src/libtomahawk/context/ContextWidget.ui new file mode 100644 index 000000000..efb8358b7 --- /dev/null +++ b/src/libtomahawk/context/ContextWidget.ui @@ -0,0 +1,76 @@ + + + ContextWidget + + + + 0 + 0 + 774 + 72 + + + + + 0 + 0 + + + + + 0 + 72 + + + + InfoBar + + + + + + + 0 + 0 + + + + Dashboard + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + Qt::Vertical + + + + 1 + 16 + + + + + + + + + + + + + + HeaderLabel + QLabel +
widgets/HeaderLabel.h
+
+
+ + +
diff --git a/src/libtomahawk/context/pages/RelatedArtistsContext.cpp b/src/libtomahawk/context/pages/RelatedArtistsContext.cpp new file mode 100644 index 000000000..8827ce734 --- /dev/null +++ b/src/libtomahawk/context/pages/RelatedArtistsContext.cpp @@ -0,0 +1,125 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#include "RelatedArtistsContext.h" + +#include + +#include "playlist/artistview.h" +#include "playlist/treemodel.h" + +using namespace Tomahawk; + + +RelatedArtistsContext::RelatedArtistsContext() + : ContextPage() + , m_infoId( uuid() ) +{ + m_relatedView = new ArtistView(); + m_relatedModel = new TreeModel( m_relatedView ); + m_relatedModel->setColumnStyle( TreeModel::TrackOnly ); + m_relatedView->setTreeModel( m_relatedModel ); + m_relatedView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + m_relatedView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + m_relatedView->header()->setVisible( false ); + m_relatedView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); + + QPalette pal = m_relatedView->palette(); + pal.setColor( QPalette::Window, QColor( 0, 0, 0, 0 ) ); + m_relatedView->setPalette( pal ); + + m_proxy = new QGraphicsProxyWidget(); + m_proxy->setWidget( m_relatedView ); + + connect( Tomahawk::InfoSystem::InfoSystem::instance(), + SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), + SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) ); + + connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) ); +} + + +RelatedArtistsContext::~RelatedArtistsContext() +{ +} + + +void +RelatedArtistsContext::setQuery( const Tomahawk::query_ptr& query ) +{ + if ( !m_query.isNull() && query->artist() == m_query->artist() ) + return; + + m_query = query; + + Tomahawk::InfoSystem::InfoCriteriaHash artistInfo; + artistInfo["artist"] = query->artist(); + + Tomahawk::InfoSystem::InfoRequestData requestData; + requestData.caller = m_infoId; + requestData.customData = QVariantMap(); + requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( artistInfo ); + + requestData.type = Tomahawk::InfoSystem::InfoArtistSimilars; + Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData ); +} + + +void +RelatedArtistsContext::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ) +{ + if ( requestData.caller != m_infoId ) + return; + + InfoSystem::InfoCriteriaHash trackInfo; + trackInfo = requestData.input.value< InfoSystem::InfoCriteriaHash >(); + + if ( output.canConvert< QVariantMap >() ) + { + if ( trackInfo["artist"] != m_query->artist() ) + { + qDebug() << "Returned info was for:" << trackInfo["artist"] << "- was looking for:" << m_query->artist(); + return; + } + } + + QVariantMap returnedData = output.value< QVariantMap >(); + switch ( requestData.type ) + { + case InfoSystem::InfoArtistSimilars: + { + m_relatedModel->clear(); + const QStringList artists = returnedData["artists"].toStringList(); + foreach ( const QString& artist, artists ) + { + m_relatedModel->addArtists( Artist::get( artist ) ); + } + break; + } + + default: + return; + } +} + + +void +RelatedArtistsContext::infoSystemFinished( QString target ) +{ + Q_UNUSED( target ); +} diff --git a/src/libtomahawk/context/pages/RelatedArtistsContext.h b/src/libtomahawk/context/pages/RelatedArtistsContext.h new file mode 100644 index 000000000..a079f0365 --- /dev/null +++ b/src/libtomahawk/context/pages/RelatedArtistsContext.h @@ -0,0 +1,67 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#ifndef RELATEDARTISTSCONTEXT_H +#define RELATEDARTISTSCONTEXT_H + +#include + +#include "dllmacro.h" + +#include "query.h" +#include "context/ContextPage.h" +#include "infosystem/infosystem.h" + +class TreeModel; +class ArtistView; + +class DLLEXPORT RelatedArtistsContext : public Tomahawk::ContextPage +{ +Q_OBJECT + +public: + RelatedArtistsContext(); + ~RelatedArtistsContext(); + + virtual QGraphicsWidget* widget() { return m_proxy; } + + virtual Tomahawk::PlaylistInterface* playlistInterface() const { return 0; } + + virtual QString title() const { return tr( "Related Artists" ); } + virtual QString description() const { return QString(); } + + virtual bool jumpToCurrentTrack() { return false; } + +public slots: + virtual void setQuery( const Tomahawk::query_ptr& query ); + +private slots: + void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); + void infoSystemFinished( QString target ); + +private: + ArtistView* m_relatedView; + TreeModel* m_relatedModel; + + QGraphicsProxyWidget* m_proxy; + + QString m_infoId; + Tomahawk::query_ptr m_query; +}; + +#endif // RELATEDARTISTSCONTEXT_H diff --git a/src/libtomahawk/context/pages/TopTracksContext.cpp b/src/libtomahawk/context/pages/TopTracksContext.cpp new file mode 100644 index 000000000..0306c5801 --- /dev/null +++ b/src/libtomahawk/context/pages/TopTracksContext.cpp @@ -0,0 +1,128 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#include "TopTracksContext.h" + +#include "playlist/playlistmodel.h" +#include "playlist/playlistview.h" + +using namespace Tomahawk; + + +TopTracksContext::TopTracksContext() + : ContextPage() + , m_infoId( uuid() ) +{ + m_topHitsView = new PlaylistView(); + m_topHitsView->setUpdatesContextView( false ); + m_topHitsModel = new PlaylistModel( m_topHitsView ); + m_topHitsModel->setStyle( TrackModel::Short ); + m_topHitsView->setTrackModel( m_topHitsModel ); + m_topHitsView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + m_topHitsView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); + + QPalette pal = m_topHitsView->palette(); + pal.setColor( QPalette::Window, QColor( 0, 0, 0, 0 ) ); + m_topHitsView->setPalette( pal ); + + m_proxy = new QGraphicsProxyWidget(); + m_proxy->setWidget( m_topHitsView ); + + connect( Tomahawk::InfoSystem::InfoSystem::instance(), + SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), + SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) ); + + connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) ); +} + + +TopTracksContext::~TopTracksContext() +{ +} + + +void +TopTracksContext::setQuery( const Tomahawk::query_ptr& query ) +{ + if ( !m_query.isNull() && query->artist() == m_query->artist() ) + return; + + m_query = query; + + Tomahawk::InfoSystem::InfoCriteriaHash artistInfo; + artistInfo["artist"] = query->artist(); + + Tomahawk::InfoSystem::InfoRequestData requestData; + requestData.caller = m_infoId; + requestData.customData = QVariantMap(); + requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( artistInfo ); + + requestData.type = Tomahawk::InfoSystem::InfoArtistSongs; + Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData ); +} + + +void +TopTracksContext::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ) +{ + if ( requestData.caller != m_infoId ) + return; + + InfoSystem::InfoCriteriaHash trackInfo; + trackInfo = requestData.input.value< InfoSystem::InfoCriteriaHash >(); + + if ( output.canConvert< QVariantMap >() ) + { + if ( trackInfo["artist"] != m_query->artist() ) + { + qDebug() << "Returned info was for:" << trackInfo["artist"] << "- was looking for:" << m_query->artist(); + return; + } + } + + QVariantMap returnedData = output.value< QVariantMap >(); + switch ( requestData.type ) + { + case InfoSystem::InfoArtistSongs: + { + m_topHitsModel->clear(); + const QStringList tracks = returnedData["tracks"].toStringList(); + + int i = 0; + foreach ( const QString& track, tracks ) + { + query_ptr query = Query::get( m_query->artist(), track, QString(), uuid() ); + m_topHitsModel->append( query ); + + if ( ++i == 15 ) + break; + } + break; + } + + default: + return; + } +} + + +void +TopTracksContext::infoSystemFinished( QString target ) +{ + Q_UNUSED( target ); +} diff --git a/src/libtomahawk/context/pages/TopTracksContext.h b/src/libtomahawk/context/pages/TopTracksContext.h new file mode 100644 index 000000000..46db47f53 --- /dev/null +++ b/src/libtomahawk/context/pages/TopTracksContext.h @@ -0,0 +1,67 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#ifndef TOPTRACKSCONTEXT_H +#define TOPTRACKSCONTEXT_H + +#include + +#include "dllmacro.h" + +#include "query.h" +#include "context/ContextPage.h" +#include "infosystem/infosystem.h" + +class PlaylistModel; +class PlaylistView; + +class DLLEXPORT TopTracksContext : public Tomahawk::ContextPage +{ +Q_OBJECT + +public: + TopTracksContext(); + ~TopTracksContext(); + + virtual QGraphicsWidget* widget() { return m_proxy; } + + virtual Tomahawk::PlaylistInterface* playlistInterface() const { return 0; } + + virtual QString title() const { return tr( "Top Hits" ); } + virtual QString description() const { return QString(); } + + virtual bool jumpToCurrentTrack() { return false; } + +public slots: + virtual void setQuery( const Tomahawk::query_ptr& query ); + +private slots: + void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); + void infoSystemFinished( QString target ); + +private: + PlaylistView* m_topHitsView; + PlaylistModel* m_topHitsModel; + + QGraphicsProxyWidget* m_proxy; + + QString m_infoId; + Tomahawk::query_ptr m_query; +}; + +#endif // TOPTRACKSCONTEXT_H diff --git a/src/libtomahawk/context/pages/WebContext.cpp b/src/libtomahawk/context/pages/WebContext.cpp new file mode 100644 index 000000000..807bd5775 --- /dev/null +++ b/src/libtomahawk/context/pages/WebContext.cpp @@ -0,0 +1,37 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#include "WebContext.h" + +using namespace Tomahawk; + + +WebContext::WebContext() + : ContextPage() +{ + m_webView = new QGraphicsWebView(); + + QPalette pal = m_webView->palette(); + pal.setColor( QPalette::Window, QColor( 0, 0, 0, 0 ) ); + m_webView->setPalette( pal ); +} + + +WebContext::~WebContext() +{ +} diff --git a/src/libtomahawk/context/pages/WebContext.h b/src/libtomahawk/context/pages/WebContext.h new file mode 100644 index 000000000..c901e6120 --- /dev/null +++ b/src/libtomahawk/context/pages/WebContext.h @@ -0,0 +1,45 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#ifndef WEBCONTEXT_H +#define WEBCONTEXT_H + +#include + +#include "dllmacro.h" + +#include "query.h" +#include "context/ContextPage.h" + +class DLLEXPORT WebContext : public Tomahawk::ContextPage +{ +Q_OBJECT + +public: + WebContext(); + ~WebContext(); + + QGraphicsWebView* webView() const { return m_webView; } + virtual QGraphicsWidget* widget() { return m_webView; } + +private: + QGraphicsWebView* m_webView; + Tomahawk::query_ptr m_query; +}; + +#endif // WEBCONTEXT_H diff --git a/src/libtomahawk/context/pages/WikipediaContext.cpp b/src/libtomahawk/context/pages/WikipediaContext.cpp new file mode 100644 index 000000000..e0ce65684 --- /dev/null +++ b/src/libtomahawk/context/pages/WikipediaContext.cpp @@ -0,0 +1,43 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#include "WikipediaContext.h" + +using namespace Tomahawk; + + +void +WikipediaContext::setQuery( const Tomahawk::query_ptr& query ) +{ + if ( !m_query.isNull() && query->artist() == m_query->artist() ) + return; + + m_query = query; + webView()->load( QString( "http://en.wikipedia.org/w/index.php?printable=yes&title=%1" ).arg( query->artist() ) ); +} + + +void +LastfmContext::setQuery( const Tomahawk::query_ptr& query ) +{ + if ( !m_query.isNull() && query->artist() == m_query->artist() ) + return; + + m_query = query; + webView()->load( QString( "http://last.fm/music/%1" ).arg( query->artist() ) ); +} diff --git a/src/libtomahawk/context/pages/WikipediaContext.h b/src/libtomahawk/context/pages/WikipediaContext.h new file mode 100644 index 000000000..5c8d45c16 --- /dev/null +++ b/src/libtomahawk/context/pages/WikipediaContext.h @@ -0,0 +1,74 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#ifndef WIKIPEDIACONTEXT_H +#define WIKIPEDIACONTEXT_H + +#include + +#include "dllmacro.h" + +#include "query.h" +#include "WebContext.h" + +class DLLEXPORT WikipediaContext : public WebContext +{ +Q_OBJECT + +public: + WikipediaContext() : WebContext() {} + ~WikipediaContext() {} + + virtual Tomahawk::PlaylistInterface* playlistInterface() const { return 0; } + + virtual QString title() const { return tr( "Wikipedia" ); } + virtual QString description() const { return QString(); } + + virtual bool jumpToCurrentTrack() { return false; } + +public slots: + virtual void setQuery( const Tomahawk::query_ptr& query ); + +private: + Tomahawk::query_ptr m_query; +}; + + +class DLLEXPORT LastfmContext : public WebContext +{ +Q_OBJECT + +public: + LastfmContext() : WebContext() {} + ~LastfmContext() {} + + virtual Tomahawk::PlaylistInterface* playlistInterface() const { return 0; } + + virtual QString title() const { return tr( "Last.fm" ); } + virtual QString description() const { return QString(); } + + virtual bool jumpToCurrentTrack() { return false; } + +public slots: + virtual void setQuery( const Tomahawk::query_ptr& query ); + +private: + Tomahawk::query_ptr m_query; +}; + +#endif // WIKIPEDIACONTEXT_H diff --git a/src/libtomahawk/globalactionmanager.cpp b/src/libtomahawk/globalactionmanager.cpp index eb3841e74..83c5105a6 100644 --- a/src/libtomahawk/globalactionmanager.cpp +++ b/src/libtomahawk/globalactionmanager.cpp @@ -467,7 +467,7 @@ GlobalActionManager::handleSearchCommand( const QUrl& url ) return false; ViewManager::instance()->showSuperCollection(); - ViewManager::instance()->topbar()->setFilter( queryStr ); +// ViewManager::instance()->topbar()->setFilter( queryStr ); return true; } diff --git a/src/libtomahawk/playlist/infobar/infobar.cpp b/src/libtomahawk/playlist/infobar/infobar.cpp index 8382aa4b8..0bbf69075 100644 --- a/src/libtomahawk/playlist/infobar/infobar.cpp +++ b/src/libtomahawk/playlist/infobar/infobar.cpp @@ -20,22 +20,25 @@ #include "ui_infobar.h" #include -#include #include +#include "context/ContextWidget.h" #include "utils/tomahawkutils.h" #include "utils/logger.h" +#define ANIMATION_TIME 400 #define IMAGE_HEIGHT 64 +using namespace Tomahawk; + InfoBar::InfoBar( QWidget* parent ) : QWidget( parent ) , ui( new Ui::InfoBar ) { ui->setupUi( this ); - layout()->setSpacing( 0 ); - layout()->setContentsMargins( 0, 0, 0, 0 ); + TomahawkUtils::unmarginLayout( layout() ); + layout()->setContentsMargins( 8, 4, 8, 4 ); QFont boldFont = ui->captionLabel->font(); boldFont.setPixelSize( 18 ); diff --git a/src/libtomahawk/playlist/infobar/infobar.h b/src/libtomahawk/playlist/infobar/infobar.h index 5f8939a34..ed658e9d9 100644 --- a/src/libtomahawk/playlist/infobar/infobar.h +++ b/src/libtomahawk/playlist/infobar/infobar.h @@ -23,6 +23,11 @@ #include "dllmacro.h" +#include "query.h" + +class QTimeLine; +class ContextWidget; + namespace Ui { class InfoBar; diff --git a/src/libtomahawk/playlist/infobar/infobar.ui b/src/libtomahawk/playlist/infobar/infobar.ui index 571499508..70fd1c7c5 100644 --- a/src/libtomahawk/playlist/infobar/infobar.ui +++ b/src/libtomahawk/playlist/infobar/infobar.ui @@ -6,8 +6,8 @@ 0 0 - 800 - 72 + 774 + 80 @@ -25,168 +25,149 @@ InfoBar - + - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 16 - 20 - - - - - - - - - 64 - 64 - - - - TextLabel - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 16 - 20 - - - - - - + - QLayout::SetMinimumSize + QLayout::SetDefaultConstraint - - - - 0 - 0 - - - - TextLabel - - - - - - - - 0 - 0 - - - - TextLabel - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 16 - 20 - - - - - - - - QLayout::SetMaximumSize - - - - - - 0 - 0 - - + - 0 - 62 - - - - - 16777215 - 62 + 64 + 64 TextLabel - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - + Qt::Horizontal + + QSizePolicy::Fixed + - 40 - 1 + 16 + 20 + + + + QLayout::SetDefaultConstraint + + + + + + 0 + 0 + + + + TextLabel + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + 0 + 0 + + + + TextLabel + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 16 + 20 + + + + + + + + QLayout::SetMaximumSize + + + + + + 0 + 0 + + + + + 0 + 62 + + + + + 16777215 + 62 + + + + TextLabel + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + Qt::Horizontal + + + + 40 + 1 + + + + + + - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 16 - 20 - - - - diff --git a/src/libtomahawk/playlist/playlistitemdelegate.cpp b/src/libtomahawk/playlist/playlistitemdelegate.cpp index 6c3f9931b..070bab047 100644 --- a/src/libtomahawk/playlist/playlistitemdelegate.cpp +++ b/src/libtomahawk/playlist/playlistitemdelegate.cpp @@ -117,7 +117,7 @@ PlaylistItemDelegate::prepareStyleOption( QStyleOptionViewItemV4* option, const opacity = item->query()->results().first()->score(); opacity = qMax( (float)0.3, opacity ); - QColor textColor = TomahawkUtils::alphaBlend( option->palette.color( QPalette::Foreground ), option->palette.color( QPalette::Background ), opacity ); + QColor textColor = TomahawkUtils::alphaBlend( option->palette.color( QPalette::Text ), option->palette.color( QPalette::BrightText ), opacity ); option->palette.setColor( QPalette::Text, textColor ); } diff --git a/src/libtomahawk/playlist/playlistmodel.cpp b/src/libtomahawk/playlist/playlistmodel.cpp index bb30a1be6..6ac509ec6 100644 --- a/src/libtomahawk/playlist/playlistmodel.cpp +++ b/src/libtomahawk/playlist/playlistmodel.cpp @@ -176,8 +176,8 @@ PlaylistModel::clear() emit beginResetModel(); delete m_rootItem; m_rootItem = 0; - emit endResetModel(); m_rootItem = new TrackModelItem( 0, this ); + emit endResetModel(); } } diff --git a/src/libtomahawk/playlist/trackview.cpp b/src/libtomahawk/playlist/trackview.cpp index 845e309f3..13a60b82e 100644 --- a/src/libtomahawk/playlist/trackview.cpp +++ b/src/libtomahawk/playlist/trackview.cpp @@ -24,11 +24,11 @@ #include "trackheader.h" #include "viewmanager.h" -#include "queueview.h" #include "trackmodel.h" #include "trackproxymodel.h" #include "audio/audioengine.h" +#include "context/ContextWidget.h" #include "widgets/overlaywidget.h" #include "dynamic/widgets/LoadingSpinner.h" #include "utils/tomahawkutils.h" @@ -48,6 +48,7 @@ TrackView::TrackView( QWidget* parent ) , m_loadingSpinner( new LoadingSpinner( this ) ) , m_resizing( false ) , m_dragging( false ) + , m_updateContextView( true ) , m_contextMenu( new ContextMenu( this ) ) { setMouseTracking( true ); @@ -154,6 +155,20 @@ TrackView::setTrackModel( TrackModel* model ) } +void +TrackView::currentChanged( const QModelIndex& current, const QModelIndex& /* previous */ ) +{ + if ( !m_updateContextView ) + return; + + TrackModelItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( current ) ); + if ( item ) + { + ViewManager::instance()->context()->setQuery( item->query() ); + } +} + + void TrackView::onItemActivated( const QModelIndex& index ) { diff --git a/src/libtomahawk/playlist/trackview.h b/src/libtomahawk/playlist/trackview.h index d2eec8344..f3956bf80 100644 --- a/src/libtomahawk/playlist/trackview.h +++ b/src/libtomahawk/playlist/trackview.h @@ -62,6 +62,9 @@ explicit TrackView( QWidget* parent = 0 ); QModelIndex contextMenuIndex() const { return m_contextMenuIndex; } void setContextMenuIndex( const QModelIndex& idx ) { m_contextMenuIndex = idx; } + bool updatesContextView() const { return m_updateContextView; } + void setUpdatesContextView( bool b ) { m_updateContextView = b; } + public slots: void onItemActivated( const QModelIndex& index ); @@ -84,6 +87,9 @@ protected: void paintEvent( QPaintEvent* event ); void keyPressEvent( QKeyEvent* event ); +protected slots: + virtual void currentChanged( const QModelIndex& current, const QModelIndex& previous ); + private slots: void onItemResized( const QModelIndex& index ); void onFilterChanged( const QString& filter ); @@ -105,6 +111,8 @@ private: bool m_dragging; QRect m_dropRect; + bool m_updateContextView; + QModelIndex m_hoveredIndex; QModelIndex m_contextMenuIndex; Tomahawk::ContextMenu* m_contextMenu; diff --git a/src/libtomahawk/viewmanager.cpp b/src/libtomahawk/viewmanager.cpp index 3a090e294..c56a15664 100644 --- a/src/libtomahawk/viewmanager.cpp +++ b/src/libtomahawk/viewmanager.cpp @@ -22,6 +22,7 @@ #include #include "audio/audioengine.h" +#include "context/ContextWidget.h" #include "utils/animatedsplitter.h" #include "infobar/infobar.h" #include "topbar/topbar.h" @@ -31,7 +32,6 @@ #include "collectionview.h" #include "playlistmodel.h" #include "playlistview.h" -#include "queueview.h" #include "trackproxymodel.h" #include "trackmodel.h" #include "artistview.h" @@ -77,37 +77,27 @@ ViewManager::ViewManager( QObject* parent ) m_widget->setLayout( new QVBoxLayout() ); - m_topbar = new TopBar(); +// m_topbar = new TopBar(); m_infobar = new InfoBar(); m_stack = new QStackedWidget(); - m_splitter = new AnimatedSplitter(); +/* m_splitter = new AnimatedSplitter(); m_splitter->setOrientation( Qt::Vertical ); m_splitter->setChildrenCollapsible( false ); m_splitter->setGreedyWidget( 0 ); - m_splitter->addWidget( m_stack ); + m_splitter->addWidget( m_stack );*/ - m_queueButton = new QPushButton(); - m_queueButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed ); - m_queueButton->setText( tr( "Click to show queue" ) ); -#ifdef Q_OS_MAC - // QPushButtons on mac have lots of weird layouting issues. Fix them by forcing the widget rect for layout calculations - m_queueButton->setAttribute( Qt::WA_LayoutUsesWidgetRect ); -#endif +// m_splitter->addWidget( m_queueView ); +// m_splitter->hide( 1, false ); - m_queueView = new QueueView( m_splitter ); - m_queueModel = new PlaylistModel( m_queueView ); - m_queueView->queue()->setPlaylistModel( m_queueModel ); - m_queueView->queue()->playlistModel()->setReadOnly( false ); - AudioEngine::instance()->setQueue( m_queueView->queue()->proxyModel() ); - - m_splitter->addWidget( m_queueView ); - m_splitter->hide( 1, false ); + m_contextWidget = new ContextWidget(); m_widget->layout()->addWidget( m_infobar ); - m_widget->layout()->addWidget( m_topbar ); - m_widget->layout()->addWidget( m_splitter ); - m_widget->layout()->addWidget( m_queueButton ); +// m_widget->layout()->addWidget( m_topbar ); +// m_widget->layout()->addWidget( m_splitter ); + m_widget->layout()->addWidget( m_stack ); + m_widget->layout()->addWidget( m_contextWidget ); +// m_widget->layout()->addWidget( m_queueButton ); m_superCollectionView = new ArtistView(); m_superCollectionModel = new TreeModel( m_superCollectionView ); @@ -132,12 +122,11 @@ ViewManager::ViewManager( QObject* parent ) connect( AudioEngine::instance(), SIGNAL( playlistChanged( Tomahawk::PlaylistInterface* ) ), this, SLOT( playlistInterfaceChanged( Tomahawk::PlaylistInterface* ) ) ); connect( &m_filterTimer, SIGNAL( timeout() ), SLOT( applyFilter() ) ); - connect( m_queueButton, SIGNAL( clicked() ), SLOT( showQueue() ) ); - connect( m_topbar, SIGNAL( filterTextChanged( QString ) ), SLOT( setFilter( QString ) ) ); +/* connect( m_topbar, SIGNAL( filterTextChanged( QString ) ), SLOT( setFilter( QString ) ) ); connect( m_topbar, SIGNAL( flatMode() ), SLOT( setTableMode() ) ); connect( m_topbar, SIGNAL( artistMode() ), SLOT( setTreeMode() ) ); - connect( m_topbar, SIGNAL( albumMode() ), SLOT( setAlbumMode() ) ); + connect( m_topbar, SIGNAL( albumMode() ), SLOT( setAlbumMode() ) );*/ } @@ -148,13 +137,6 @@ ViewManager::~ViewManager() } -PlaylistView* -ViewManager::queue() const -{ - return m_queueView->queue(); -} - - PlaylistView* ViewManager::createPageForPlaylist( const playlist_ptr& pl ) { @@ -218,10 +200,10 @@ ViewManager::show( const Tomahawk::dynplaylist_ptr& playlist ) setPage( m_dynamicWidgets.value( playlist ).data() ); - if ( playlist->mode() == Tomahawk::OnDemand ) - m_queueView->hide(); +/* if ( playlist->mode() == Tomahawk::OnDemand ) + hideQueue(); else - m_queueView->show(); + showQueue();*/ emit numSourcesChanged( SourceList::instance()->count() ); @@ -491,42 +473,6 @@ ViewManager::setAlbumMode() } -void -ViewManager::showQueue() -{ - if ( QThread::currentThread() != thread() ) - { - qDebug() << "Reinvoking in correct thread:" << Q_FUNC_INFO; - QMetaObject::invokeMethod( this, "showQueue", Qt::QueuedConnection ); - return; - } - - m_queueButton->setText( tr( "Click to hide queue" ) ); - disconnect( m_queueButton, SIGNAL( clicked() ), this, SLOT( showQueue() ) ); - connect( m_queueButton, SIGNAL( clicked() ), SLOT( hideQueue() ) ); - - m_splitter->show( 1 ); -} - - -void -ViewManager::hideQueue() -{ - if ( QThread::currentThread() != thread() ) - { - qDebug() << "Reinvoking in correct thread:" << Q_FUNC_INFO; - QMetaObject::invokeMethod( this, "hideQueue", Qt::QueuedConnection ); - return; - } - - m_queueButton->setText( tr( "Click to show queue" ) ); - disconnect( m_queueButton, SIGNAL( clicked() ), this, SLOT( hideQueue() ) ); - connect( m_queueButton, SIGNAL( clicked() ), SLOT( showQueue() ) ); - - m_splitter->hide( 1 ); -} - - void ViewManager::historyBack() { @@ -699,7 +645,7 @@ ViewManager::updateView() connect( currentPlaylistInterface()->object(), SIGNAL( shuffleModeChanged( bool ) ), SIGNAL( shuffleModeChanged( bool ) ) ); - m_topbar->setFilter( currentPlaylistInterface()->filter() ); +// m_topbar->setFilter( currentPlaylistInterface()->filter() ); } if ( currentPage()->showStatsBar() && currentPlaylistInterface() ) @@ -716,19 +662,19 @@ ViewManager::updateView() emit modeChanged( currentPlaylistInterface()->viewMode() ); } - if ( currentPage()->queueVisible() ) - m_queueView->show(); +/* if ( currentPage()->queueVisible() ) + showQueue(); else - m_queueView->hide(); + hideQueue();*/ emit statsAvailable( currentPage()->showStatsBar() ); emit modesAvailable( currentPage()->showModes() ); emit filterAvailable( currentPage()->showFilter() ); - if ( !currentPage()->showStatsBar() && !currentPage()->showModes() && !currentPage()->showFilter() ) +/* if ( !currentPage()->showStatsBar() && !currentPage()->showModes() && !currentPage()->showFilter() ) m_topbar->setVisible( false ); else - m_topbar->setVisible( true ); + m_topbar->setVisible( true );*/ m_infobar->setVisible( currentPage()->showInfoBar() ); m_infobar->setCaption( currentPage()->title() ); diff --git a/src/libtomahawk/viewmanager.h b/src/libtomahawk/viewmanager.h index bc3dd5c67..edcba014c 100644 --- a/src/libtomahawk/viewmanager.h +++ b/src/libtomahawk/viewmanager.h @@ -25,6 +25,7 @@ #include "collection.h" #include "playlistinterface.h" +#include "playlist/queueview.h" #include "viewpage.h" #include "widgets/welcomewidget.h" #include "widgets/whatshotwidget.h" @@ -40,9 +41,9 @@ class ArtistView; class CollectionModel; class CollectionFlatModel; class CollectionView; +class ContextWidget; class PlaylistModel; class PlaylistView; -class QueueView; class TrackProxyModel; class TrackModel; class TreeProxyModel; @@ -71,8 +72,11 @@ public: ~ViewManager(); QWidget* widget() const { return m_widget; } - PlaylistView* queue() const; - TopBar* topbar() const { return m_topbar; } + InfoBar* infobar() const { return m_infobar; } + ContextWidget* context() const { return m_contextWidget; } + + PlaylistView* queue() const { return m_queue->queue(); } + void setQueue( QueueView* queue ) { m_queue = queue; } bool isSuperCollectionVisible() const; bool isNewPlaylistPageVisible() const; @@ -120,6 +124,9 @@ signals: void tempPageActivated( Tomahawk::ViewPage* ); void viewPageActivated( Tomahawk::ViewPage* ); + void showQueueRequested(); + void hideQueueRequested(); + public slots: Tomahawk::ViewPage* showSuperCollection(); Tomahawk::ViewPage* showWelcomePage(); @@ -137,13 +144,13 @@ public slots: void historyBack(); void removeFromHistory( Tomahawk::ViewPage* p ); + void showQueue() { emit showQueueRequested(); } + void hideQueue() { emit hideQueueRequested(); } + void setTreeMode(); void setTableMode(); void setAlbumMode(); - void showQueue(); - void hideQueue(); - void setRepeatMode( Tomahawk::PlaylistInterface::RepeatMode mode ); void setShuffled( bool enabled ); @@ -172,18 +179,15 @@ private: QWidget* m_widget; InfoBar* m_infobar; - TopBar* m_topbar; - QPushButton* m_queueButton; + ContextWidget* m_contextWidget; QStackedWidget* m_stack; AnimatedSplitter* m_splitter; - PlaylistModel* m_queueModel; - QueueView* m_queueView; - AlbumModel* m_superAlbumModel; AlbumView* m_superAlbumView; TreeModel* m_superCollectionModel; ArtistView* m_superCollectionView; + QueueView* m_queue; WelcomeWidget* m_welcomeWidget; WhatsHotWidget* m_whatsHotWidget; diff --git a/src/libtomahawk/viewpage.h b/src/libtomahawk/viewpage.h index 44b17250c..629fb66dc 100644 --- a/src/libtomahawk/viewpage.h +++ b/src/libtomahawk/viewpage.h @@ -34,7 +34,6 @@ class DLLEXPORT ViewPage { public: ViewPage() {} - virtual ~ViewPage() {} virtual QWidget* widget() = 0; diff --git a/src/libtomahawk/widgets/HeaderLabel.cpp b/src/libtomahawk/widgets/HeaderLabel.cpp index 6b86b04e5..39b659fd3 100644 --- a/src/libtomahawk/widgets/HeaderLabel.cpp +++ b/src/libtomahawk/widgets/HeaderLabel.cpp @@ -18,6 +18,7 @@ #include "HeaderLabel.h" +#include #include #include "utils/logger.h" @@ -51,6 +52,23 @@ HeaderLabel::sizeHint() const } +void +HeaderLabel::mousePressEvent( QMouseEvent* event ) +{ + QFrame::mousePressEvent( event ); + m_time.start(); +} + + +void +HeaderLabel::mouseReleaseEvent( QMouseEvent* event ) +{ + QFrame::mouseReleaseEvent( event ); + if ( m_time.elapsed() < qApp->doubleClickInterval() ) + emit clicked(); +} + + void HeaderLabel::paintEvent( QPaintEvent* /* event */ ) { @@ -58,7 +76,7 @@ HeaderLabel::paintEvent( QPaintEvent* /* event */ ) QRect r = contentsRect(); StyleHelper::horizontalHeader(&p, r); - QTextOption to( Qt::AlignVCenter ); + QTextOption to( alignment() | Qt::AlignVCenter ); r.adjust( 8, 0, -8, 0 ); p.setPen( StyleHelper::headerTextColor() ); p.drawText( r, text(), to ); diff --git a/src/libtomahawk/widgets/HeaderLabel.h b/src/libtomahawk/widgets/HeaderLabel.h index 8a53c2f78..7bcb94f27 100644 --- a/src/libtomahawk/widgets/HeaderLabel.h +++ b/src/libtomahawk/widgets/HeaderLabel.h @@ -20,6 +20,7 @@ #define HEADERLABEL_H #include +#include #include "dllmacro.h" @@ -38,14 +39,19 @@ public: QSize minimumSizeHint() const { return sizeHint(); } QSize sizeHint() const; -public slots: +signals: + void clicked(); protected: // void changeEvent( QEvent* e ); void paintEvent( QPaintEvent* event ); + void mousePressEvent( QMouseEvent* event ); + void mouseReleaseEvent( QMouseEvent* event ); + private: QWidget* m_parent; + QTime m_time; }; #endif // HEADERLABEL_H diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp index dbd2a53f6..64655cad7 100644 --- a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp @@ -33,6 +33,7 @@ using namespace Tomahawk; + ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget* parent ) : QWidget( parent ) , ui( new Ui::ArtistInfoWidget ) @@ -120,10 +121,7 @@ void ArtistInfoWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ) { if ( requestData.caller != m_infoId ) - { -// qDebug() << "Info of wrong type or not with our identifier"; return; - } InfoSystem::InfoCriteriaHash trackInfo; trackInfo = requestData.input.value< InfoSystem::InfoCriteriaHash >(); @@ -137,7 +135,6 @@ ArtistInfoWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestD } } -qDebug() << "ARTISTINFOWIDGET got infosystem info for:" << m_title << output.value< Tomahawk::InfoSystem::InfoGenericMap >(); QVariantMap returnedData = output.value< QVariantMap >(); switch ( requestData.type ) { diff --git a/src/tomahawkwindow.cpp b/src/tomahawkwindow.cpp index 0aa067e41..0cd8439fd 100644 --- a/src/tomahawkwindow.cpp +++ b/src/tomahawkwindow.cpp @@ -43,7 +43,6 @@ #include "sourcetree/sourcetreeview.h" #include "utils/animatedsplitter.h" #include "utils/proxystyle.h" -#include "utils/widgetdragfilter.h" #include "utils/xspfloader.h" #include "widgets/newplaylistwidget.h" #include "widgets/searchwidget.h" @@ -59,6 +58,7 @@ #include "tomahawktrayicon.h" #include "playlist/dynamic/GeneratorInterface.h" #include "scanmanager.h" +#include "playlist/queueview.h" #include "tomahawkapp.h" #ifdef Q_OS_WIN32 @@ -80,7 +80,10 @@ TomahawkWindow::TomahawkWindow( QWidget* parent ) { setWindowIcon( QIcon( RESPATH "icons/tomahawk-icon-128x128.png" ) ); - new ViewManager( this ); + ViewManager* vm = new ViewManager( this ); + connect( vm, SIGNAL( showQueueRequested() ), SLOT( showQueue() ) ); + connect( vm, SIGNAL( hideQueueRequested() ), SLOT( hideQueue() ) ); + ui->setupUi( this ); applyPlatformTweaks(); @@ -96,7 +99,8 @@ TomahawkWindow::TomahawkWindow( QWidget* parent ) // set initial state onSipDisconnected(); - ViewManager::instance()->showWelcomePage(); + vm->setQueue( m_queueView ); + vm->showWelcomePage(); } @@ -184,28 +188,49 @@ TomahawkWindow::setupSideBar() QWidget* sidebarWidget = new QWidget(); sidebarWidget->setLayout( new QVBoxLayout() ); - AnimatedSplitter* sidebar = new AnimatedSplitter(); - sidebar->setOrientation( Qt::Vertical ); - sidebar->setChildrenCollapsible( false ); + m_sidebar = new AnimatedSplitter(); + m_sidebar->setOrientation( Qt::Vertical ); + m_sidebar->setChildrenCollapsible( false ); - m_searchWidget = new QSearchField( sidebar ); + m_searchWidget = new QSearchField( m_sidebar ); m_searchWidget->setPlaceholderText( "Global Search..." ); connect( m_searchWidget, SIGNAL( returnPressed() ), this, SLOT( onFilterEdited() ) ); m_sourcetree = new SourceTreeView(); - TransferView* transferView = new TransferView( sidebar ); - PipelineStatusView* pipelineView = new PipelineStatusView( sidebar ); + TransferView* transferView = new TransferView( m_sidebar ); + PipelineStatusView* pipelineView = new PipelineStatusView( m_sidebar ); - sidebar->addWidget( m_searchWidget ); - sidebar->addWidget( m_sourcetree ); - sidebar->addWidget( transferView ); - sidebar->addWidget( pipelineView ); + m_queueButton = new QPushButton(); + m_queueButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed ); + m_queueButton->setText( tr( "Click to show queue" ) ); + #ifdef Q_OS_MAC + // QPushButtons on mac have lots of weird layouting issues. Fix them by forcing the widget rect for layout calculations + m_queueButton->setAttribute( Qt::WA_LayoutUsesWidgetRect ); + #endif - sidebar->setGreedyWidget( 1 ); - sidebar->hide( 1, false ); - sidebar->hide( 2, false ); + connect( m_queueButton, SIGNAL( clicked() ), SLOT( showQueue() ) ); - sidebarWidget->layout()->addWidget( sidebar ); + m_queueView = new QueueView( m_sidebar ); + m_queueModel = new PlaylistModel( m_queueView ); + m_queueModel->setStyle( PlaylistModel::Short ); + m_queueView->queue()->setPlaylistModel( m_queueModel ); + m_queueView->queue()->playlistModel()->setReadOnly( false ); + AudioEngine::instance()->setQueue( m_queueView->queue()->proxyModel() ); + + m_sidebar->addWidget( m_searchWidget ); + m_sidebar->addWidget( m_sourcetree ); + m_sidebar->addWidget( transferView ); + m_sidebar->addWidget( pipelineView ); + m_sidebar->addWidget( m_queueView ); + + m_sidebar->setGreedyWidget( 1 ); + m_sidebar->hide( 1, false ); + m_sidebar->hide( 2, false ); + m_sidebar->hide( 3, false ); + m_sidebar->hide( 4, false ); + + sidebarWidget->layout()->addWidget( m_sidebar ); + sidebarWidget->layout()->addWidget( m_queueButton ); sidebarWidget->setContentsMargins( 0, 0, 0, 0 ); sidebarWidget->layout()->setContentsMargins( 0, 0, 0, 0 ); sidebarWidget->layout()->setMargin( 0 ); @@ -225,6 +250,7 @@ TomahawkWindow::setupSideBar() ui->actionShowOfflineSources->setChecked( TomahawkSettings::instance()->showOfflineSources() ); } + void TomahawkWindow::setupUpdateCheck() { @@ -663,6 +689,42 @@ TomahawkWindow::onFilterEdited() } +void +TomahawkWindow::showQueue() +{ + if ( QThread::currentThread() != thread() ) + { + qDebug() << "Reinvoking in correct thread:" << Q_FUNC_INFO; + QMetaObject::invokeMethod( this, "showQueue", Qt::QueuedConnection ); + return; + } + + m_queueButton->setText( tr( "Click to hide queue" ) ); + disconnect( m_queueButton, SIGNAL( clicked() ), this, SLOT( showQueue() ) ); + connect( m_queueButton, SIGNAL( clicked() ), SLOT( hideQueue() ) ); + + m_sidebar->show( 4 ); +} + + +void +TomahawkWindow::hideQueue() +{ + if ( QThread::currentThread() != thread() ) + { + qDebug() << "Reinvoking in correct thread:" << Q_FUNC_INFO; + QMetaObject::invokeMethod( this, "hideQueue", Qt::QueuedConnection ); + return; + } + + m_queueButton->setText( tr( "Click to show queue" ) ); + disconnect( m_queueButton, SIGNAL( clicked() ), this, SLOT( hideQueue() ) ); + connect( m_queueButton, SIGNAL( clicked() ), SLOT( showQueue() ) ); + + m_sidebar->hide( 4 ); +} + + void TomahawkWindow::minimize() { diff --git a/src/tomahawkwindow.h b/src/tomahawkwindow.h index f6980f78a..8343841b2 100644 --- a/src/tomahawkwindow.h +++ b/src/tomahawkwindow.h @@ -35,6 +35,9 @@ class QAction; class MusicScanner; class AudioControls; class TomahawkTrayIcon; +class PlaylistModel; +class QueueView; +class AnimatedSplitter; namespace Ui { @@ -95,6 +98,9 @@ private slots: void onSearch( const QString& search ); void onFilterEdited(); + void showQueue(); + void hideQueue(); + void minimize(); void maximize(); @@ -114,6 +120,10 @@ private: TomahawkTrayIcon* m_trayIcon; SourceTreeView* m_sourcetree; QPushButton* m_statusButton; + QPushButton* m_queueButton; + PlaylistModel* m_queueModel; + QueueView* m_queueView; + AnimatedSplitter* m_sidebar; Tomahawk::result_ptr m_currentTrack; QString m_windowTitle;