1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 22:26:32 +02:00

* Simplify Dashboard.

This commit is contained in:
Christian Muehlhaeuser
2014-08-13 08:02:07 +02:00
parent 87a43fad9d
commit 21fcefb843
3 changed files with 44 additions and 428 deletions

View File

@@ -20,6 +20,7 @@
#include "Dashboard.h"
#include "ui_DashboardWidget.h"
#include "ui_HeaderWidget.h"
#include "libtomahawk-widgets/PlaylistDelegate.h"
@@ -30,6 +31,7 @@
#include "widgets/RecentlyPlayedPlaylistsModel.h"
#include "MetaPlaylistInterface.h"
#include "audio/AudioEngine.h"
#include "playlist/TrackView.h"
#include "playlist/AlbumModel.h"
#include "playlist/RecentlyPlayedModel.h"
#include "playlist/dynamic/GeneratorInterface.h"
@@ -65,129 +67,62 @@ Dashboard::~Dashboard()
DashboardWidget::DashboardWidget( QWidget* parent )
: QWidget( parent )
, ui( new Ui::DashboardWidget )
, uiHeader( new Ui::HeaderWidget )
{
QWidget* widget = new QWidget;
QWidget* headerWidget = new QWidget;
ui->setupUi( widget );
ui->lineAbove->setStyleSheet( QString( "QFrame { border: 1px solid black; }" ) );
ui->lineBelow->setStyleSheet( QString( "QFrame { border: 1px solid %1; }" ).arg( TomahawkStyle::HEADER_BACKGROUND.name() ) );
uiHeader->setupUi( headerWidget );
headerWidget->setFixedHeight( 160 );
{
m_tracksModel = new RecentlyPlayedModel( ui->tracksView, HISTORY_TRACK_ITEMS );
ui->tracksView->proxyModel()->setStyle( PlayableProxyModel::Short );
ui->tracksView->overlay()->setEnabled( false );
ui->tracksView->setPlaylistModel( m_tracksModel );
ui->tracksView->setAutoResize( true );
ui->tracksView->setAlternatingRowColors( false );
m_tracksModel = new RecentlyPlayedModel( ui->trackView->trackView(), HISTORY_TRACK_ITEMS );
ui->trackView->setPlayableModel( m_tracksModel );
ui->trackView->setCaption( tr( "Recently Played Tracks" ) );
ui->trackView->trackView()->setUniformRowHeights( false );
// ui->trackView->trackView()->setAutoResize( true );
m_tracksModel->setSource( source_ptr() );
QPalette p = ui->tracksView->palette();
p.setColor( QPalette::Text, TomahawkStyle::PAGE_TRACKLIST_TRACK_SOLVED );
p.setColor( QPalette::BrightText, TomahawkStyle::PAGE_TRACKLIST_TRACK_UNRESOLVED );
p.setColor( QPalette::Foreground, TomahawkStyle::PAGE_TRACKLIST_NUMBER );
p.setColor( QPalette::Highlight, TomahawkStyle::PAGE_TRACKLIST_HIGHLIGHT );
p.setColor( QPalette::HighlightedText, TomahawkStyle::PAGE_TRACKLIST_HIGHLIGHT_TEXT );
ui->tracksView->setPalette( p );
TomahawkStyle::stylePageFrame( ui->tracksView );
TomahawkStyle::stylePageFrame( ui->trackFrame );
}
{
RecentPlaylistsModel* model = new RecentPlaylistsModel( HISTORY_PLAYLIST_ITEMS, this );
QFont f = uiHeader->artistLabel->font();
f.setBold( true );
f.setPointSize( 16 );
ui->playlistWidget->setFrameShape( QFrame::NoFrame );
ui->playlistWidget->setAttribute( Qt::WA_MacShowFocusRect, 0 );
ui->playlistWidget->setItemDelegate( new PlaylistDelegate() );
ui->playlistWidget->setModel( model );
ui->playlistWidget->overlay()->resize( 380, 86 );
ui->playlistWidget->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
QPalette p = uiHeader->artistLabel->palette();
p.setColor( QPalette::Foreground, Qt::white );
QPalette p = ui->playlistWidget->palette();
p.setColor( QPalette::Text, TomahawkStyle::HEADER_TEXT );
p.setColor( QPalette::BrightText, TomahawkStyle::HEADER_TEXT );
p.setColor( QPalette::Foreground, TomahawkStyle::HEADER_TEXT );
p.setColor( QPalette::Highlight, TomahawkStyle::HEADER_TEXT );
p.setColor( QPalette::HighlightedText, TomahawkStyle::HEADER_BACKGROUND );
ui->playlistWidget->setPalette( p );
ui->playlistWidget->setMinimumHeight( 400 );
TomahawkStyle::styleScrollBar( ui->playlistWidget->verticalScrollBar() );
TomahawkStyle::stylePageFrame( ui->playlistWidget );
TomahawkStyle::stylePageFrame( ui->playlistFrame );
updatePlaylists();
connect( ui->playlistWidget, SIGNAL( activated( QModelIndex ) ), SLOT( onPlaylistActivated( QModelIndex ) ) );
connect( model, SIGNAL( emptinessChanged( bool ) ), this, SLOT( updatePlaylists() ) );
}
{
m_recentAlbumsModel = new AlbumModel( ui->additionsView );
ui->additionsView->setPlayableModel( m_recentAlbumsModel );
ui->additionsView->proxyModel()->sort( -1 );
TomahawkStyle::styleScrollBar( ui->additionsView->verticalScrollBar() );
TomahawkStyle::stylePageFrame( ui->additionsView );
TomahawkStyle::stylePageFrame( ui->additionsFrame );
}
{
QFont f = ui->label->font();
f.setFamily( "Pathway Gothic One" );
QPalette p = ui->label->palette();
p.setColor( QPalette::Foreground, TomahawkStyle::PAGE_CAPTION );
ui->label->setFont( f );
ui->label_2->setFont( f );
ui->label->setPalette( p );
ui->label_2->setPalette( p );
}
{
QFont f = ui->playlistLabel->font();
f.setFamily( "Pathway Gothic One" );
QPalette p = ui->playlistLabel->palette();
p.setColor( QPalette::Foreground, TomahawkStyle::HEADER_TEXT );
ui->playlistLabel->setFont( f );
ui->playlistLabel->setPalette( p );
uiHeader->artistLabel->setFont( f );
uiHeader->artistLabel->setPalette( p );
uiHeader->artistLabel->setText( tr( "Dashboard" ).toUpper() );
}
{
QScrollArea* area = new QScrollArea();
area->setWidgetResizable( true );
area->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn );
area->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
area->setWidget( widget );
QPalette pal = palette();
pal.setBrush( backgroundRole(), TomahawkStyle::HEADER_BACKGROUND );
pal.setBrush( backgroundRole(), Qt::white );
area->setPalette( pal );
area->setAutoFillBackground( true );
area->setFrameShape( QFrame::NoFrame );
area->setAttribute( Qt::WA_MacShowFocusRect, 0 );
QVBoxLayout* layout = new QVBoxLayout();
layout->addWidget( headerWidget );
layout->addWidget( area );
setLayout( layout );
TomahawkUtils::unmarginLayout( layout );
}
{
QPalette pal = palette();
pal.setBrush( backgroundRole(), TomahawkStyle::PAGE_BACKGROUND );
ui->widget->setPalette( pal );
ui->widget->setAutoFillBackground( true );
}
MetaPlaylistInterface* mpl = new MetaPlaylistInterface();
mpl->addChildInterface( ui->tracksView->playlistInterface() );
mpl->addChildInterface( ui->additionsView->playlistInterface() );
mpl->addChildInterface( ui->trackView->trackView()->playlistInterface() );
m_playlistInterface = playlistinterface_ptr( mpl );
connect( SourceList::instance(), SIGNAL( ready() ), SLOT( onSourcesReady() ) );
connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) );
connect( ui->trackView, SIGNAL( pixmapChanged( QPixmap ) ), uiHeader->headerWidget, SLOT( setBackground( QPixmap ) ) );
}
@@ -207,10 +142,7 @@ DashboardWidget::playlistInterface() const
bool
DashboardWidget::jumpToCurrentTrack()
{
if ( ui->tracksView->jumpToCurrentTrack() )
return true;
if ( ui->additionsView->jumpToCurrentTrack() )
if ( ui->trackView->trackView()->jumpToCurrentTrack() )
return true;
return false;
@@ -220,59 +152,7 @@ DashboardWidget::jumpToCurrentTrack()
bool
DashboardWidget::isBeingPlayed() const
{
if ( ui->additionsView->isBeingPlayed() )
return true;
return AudioEngine::instance()->currentTrackPlaylist() == ui->tracksView->playlistInterface();
}
void
DashboardWidget::onSourcesReady()
{
foreach ( const source_ptr& source, SourceList::instance()->sources() )
onSourceAdded( source );
updateRecentAdditions();
}
void
DashboardWidget::onSourceAdded( const Tomahawk::source_ptr& source )
{
connect( source->dbCollection().data(), SIGNAL( changed() ), SLOT( updateRecentAdditions() ), Qt::UniqueConnection );
}
void
DashboardWidget::updateRecentAdditions()
{
m_recentAlbumsModel->addFilteredCollection( collection_ptr(), 20, DatabaseCommand_AllAlbums::ModificationTime, true );
}
void
DashboardWidget::updatePlaylists()
{
int num = ui->playlistWidget->model()->rowCount( QModelIndex() );
if ( num == 0 )
{
ui->playlistWidget->overlay()->setText( tr( "No recently created playlists in your network." ) );
ui->playlistWidget->overlay()->show();
}
else
ui->playlistWidget->overlay()->hide();
}
void
DashboardWidget::onPlaylistActivated( const QModelIndex& item )
{
Tomahawk::playlist_ptr pl = item.data( RecentlyPlayedPlaylistsModel::PlaylistRole ).value< Tomahawk::playlist_ptr >();
if ( Tomahawk::dynplaylist_ptr dynplaylist = pl.dynamicCast< Tomahawk::DynamicPlaylist >() )
ViewManager::instance()->show( dynplaylist );
else
ViewManager::instance()->show( pl );
return AudioEngine::instance()->currentTrackPlaylist() == ui->trackView->trackView()->playlistInterface();
}

View File

@@ -43,6 +43,7 @@ class BasicHeader;
namespace Ui
{
class DashboardWidget;
class HeaderWidget;
}
namespace Tomahawk
@@ -66,19 +67,15 @@ public:
virtual bool jumpToCurrentTrack();
public slots:
void updatePlaylists();
void updateRecentAdditions();
private slots:
void onSourcesReady();
void onSourceAdded( const Tomahawk::source_ptr& source );
void onPlaylistActivated( const QModelIndex& );
protected:
void changeEvent( QEvent* e );
private:
Ui::DashboardWidget *ui;
Ui::HeaderWidget *uiHeader;
RecentlyPlayedModel* m_tracksModel;
AlbumModel* m_recentAlbumsModel;
@@ -104,7 +101,7 @@ public:
int sortValue() Q_DECL_OVERRIDE { return 2; }
bool showInfoBar() const Q_DECL_OVERRIDE { return true; }
bool showInfoBar() const Q_DECL_OVERRIDE { return false; }
};

View File

@@ -6,14 +6,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>965</width>
<height>616</height>
<width>828</width>
<height>635</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true" extracomment="not translatable because not shown to the user">Form</string>
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
@@ -21,284 +21,23 @@
<number>0</number>
</property>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>16</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>16</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>12</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>12</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="trackFrame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<property name="spacing">
<number>4</number>
</property>
<property name="leftMargin">
<number>8</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<pointsize>20</pointsize>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Recently Played Tracks</string>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="PlaylistView" name="tracksView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="headerHidden">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="additionsFrame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="spacing">
<number>4</number>
</property>
<property name="leftMargin">
<number>8</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<family>Arial</family>
<pointsize>20</pointsize>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Recent Additions</string>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="GridView" name="additionsView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>190</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="Line" name="lineAbove">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>1</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<widget class="ContextView" name="trackView" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="Line" name="lineBelow">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>1</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="playlistContainer" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>12</number>
</property>
<property name="topMargin">
<number>16</number>
</property>
<property name="rightMargin">
<number>12</number>
</property>
<property name="bottomMargin">
<number>16</number>
</property>
<item>
<widget class="QFrame" name="playlistFrame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing">
<number>4</number>
</property>
<property name="leftMargin">
<number>8</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="QLabel" name="playlistLabel">
<property name="font">
<font>
<pointsize>20</pointsize>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Newest Stations &amp; Playlists</string>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="Tomahawk::Widgets::PlaylistWidget" name="playlistWidget"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>PlaylistView</class>
<extends>QTreeView</extends>
<header location="global">playlist/PlaylistView.h</header>
</customwidget>
<customwidget>
<class>GridView</class>
<extends>QListView</extends>
<header location="global">playlist/GridView.h</header>
</customwidget>
<customwidget>
<class>Tomahawk::Widgets::PlaylistWidget</class>
<extends>QListWidget</extends>
<header>libtomahawk-widgets/PlaylistWidget.h</header>
<class>ContextView</class>
<extends>QWidget</extends>
<header>playlist/ContextView.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>