1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

first work on new breadcrumb

This commit is contained in:
Leo Franchi 2011-10-25 17:59:12 -04:00
parent 2277c14882
commit 4db10f8195
9 changed files with 511 additions and 21 deletions

View File

@ -39,6 +39,7 @@
GetNewStuffDelegate::GetNewStuffDelegate( QObject* parent )
: QStyledItemDelegate ( parent )
, m_hoveringOver( -1 )
, m_widestTextWidth( 0 )
, m_hoveringOver( -1 )
{

View File

@ -229,6 +229,8 @@ set( libSources
widgets/breadcrumbbuttonbase.cpp
widgets/headerbreadcrumb.cpp
widgets/siblingcrumbbutton.cpp
widgets/Breadcrumb.cpp
widgets/BreadcrumbButton.cpp
jobview/JobStatusView.cpp
jobview/JobStatusModel.cpp
@ -457,6 +459,8 @@ set( libHeaders
widgets/breadcrumbbuttonbase.h
widgets/headerbreadcrumb.h
widgets/siblingcrumbbutton.h
widgets/Breadcrumb.h
widgets/BreadcrumbButton.h
jobview/JobStatusView.h
jobview/JobStatusModel.h

View File

@ -172,7 +172,7 @@ RoviPlugin::makeRequest( QUrl url )
url.addQueryItem( "apikey", m_apiKey );
url.addEncodedQueryItem( "sig", generateSig() );
// qDebug() << "url:" << url.toString();
qDebug() << "Rovi request url:" << url.toString();
return m_nam->get( QNetworkRequest( url ) );
}

View File

@ -0,0 +1,170 @@
/* === This file is part of Tomahawk Player - <http://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 "Breadcrumb.h"
#include "BreadcrumbButton.h"
#include "utils/stylehelper.h"
#include "kbreadcrumbselectionmodel.h"
#include "utils/logger.h"
#include <QStylePainter>
#include <QPushButton>
#include <QHBoxLayout>
#include <QPropertyAnimation>
#include <QDebug>
using namespace Tomahawk;
Breadcrumb::Breadcrumb( QWidget* parent, Qt::WindowFlags f )
: QWidget( parent, f )
, m_model( 0 )
, m_selModel( 0 )
, m_buttonlayout( new QHBoxLayout( this ) )
{
m_buttonlayout->setSpacing( 0 );
m_buttonlayout->setMargin( 0 );
m_buttonlayout->setAlignment( Qt::AlignLeft );
setAutoFillBackground( true );
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
setLayoutDirection( Qt::LeftToRight );
setLayout( m_buttonlayout );
show();
}
Breadcrumb::~Breadcrumb()
{
}
void
Breadcrumb::setModel( QAbstractItemModel* model )
{
m_model = model;
if ( m_selModel )
delete m_selModel;
m_selModel = new KBreadcrumbSelectionModel( new QItemSelectionModel( m_model ) );
// connect( m_selMode, SIGNAL( currentChanged( QModelIndex, QModelIndex) ), this, SLOT( updateButtons( QModelIndex, QModelIndex ) ) );
updateButtons( QModelIndex() );
}
void
Breadcrumb::setRootIcon( const QPixmap& pm )
{
m_rootIcon = pm;
QPushButton* button = new QPushButton( QIcon( m_rootIcon ), "", this );
button->setFlat( true );
button->setStyleSheet( "QPushButton{ background-color: transparent; border: none; width:16px; height:16px;}" );
m_buttonlayout->insertWidget( 0, button );
m_buttonlayout->insertSpacing( 0,5 );
m_buttonlayout->insertSpacing( 2,5 );
}
void
Breadcrumb::paintEvent( QPaintEvent* )
{
QStylePainter p( this );
StyleHelper::horizontalHeader( &p, rect() );
}
// updateFrom is the item that has changed---all children must be recomputed
// if invalid, redo the whole breadcrumb
void
Breadcrumb::updateButtons( const QModelIndex& updateFrom )
{
qDebug() << "Updating buttons:" << updateFrom.data();
int cur = 0;
QModelIndex idx;
for ( cur = 0; cur < m_buttons.count(); cur++ )
{
qDebug() << "Checking if this breadcrumb item changed:" << sel[ cur ].data() << updateFrom.data() << ( sel[ cur ] != updateFrom);
if ( m_buttons[ cur ].currentIndex() == updateFrom )
break;
idx = m_buttons[ cur ].currentIndex();
}
// Ok, changed all indices that are at cur or past it. lets update them
// When we get to the "end" of the tree, the leaf node is the chart itself
qDebug() << "DONE and beginning iteration:" << idx.data();
while ( m_model->rowCount( idx ) > 0 )
{
qDebug() << "CHANGED AND iterating:" << idx.data();
BreadcrumbButton* btn = 0;
if ( m_buttons.size() <= cur )
{
// We have to create a new button, doesn't exist yet
btn = new BreadcrumbButton( this, m_model );
connect( btn, SIGNAL( currentIndexChanged( QModelIndex ) ), this, SLOT( breadcrumbComboChanged( QModelIndex ) ) );
m_buttonlayout->addWidget( btn );
// Animate all buttons except the first
if ( m_buttons.count() > 0 )
{
QWidget* neighbor = m_buttonlayout->itemAt( m_buttonlayout->count() - 2 )->widget();
QPropertyAnimation* animation = new QPropertyAnimation( btn, "pos" );
animation->setDuration( 300 );
animation->setStartValue( neighbor->pos() );
animation->setEndValue( btn->pos() );
animation->start( QAbstractAnimation::DeleteWhenStopped );
}
m_buttons.append( btn );
}
else
{
// Got a button already, we just want to change the contents
btn = m_buttons[ cur ];
}
// The children of idx are what populates this combobox.
// It takes care of setting the default/user-populated value.
btn->setParentIndex( idx );
// Repeat with children
idx = btn->currentIndex();
cur++;
}
// Now we're at the leaf, lets activate the chart
emit activateIndex( idx );
}
void
Breadcrumb::breadcrumbComboChanged( const QModelIndex& childSelected )
{
// Some breadcrumb buttons' combobox changed. lets update the child breadcrumbs
tDebug() << "Combo changed:" << childSelected.data();
m_selModel->select( childSelected, QItemSelectionModel::SelectCurrent );
updateButtons( childSelected );
}
// void
// Breadcrumb::currentIndexChanged( const QModelIndex& current, const QModelIndex& previous )
// {
//
// }
//

View File

@ -0,0 +1,84 @@
/* === This file is part of Tomahawk Player - <http://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/>.
*/
#ifndef TOMAHAWK_BREADCRUMB_H
#define TOMAHAWK_BREADCRUMB_H
#include <QWidget>
#include <QModelIndex>
class QHBoxLayout;
class QAbstractItemModel;
class KBreadcrumbSelectionModel;
namespace Tomahawk {
class BreadcrumbButton;
/**
* A breadcrumb widget for Tomahawk's needs.
*
* This breadcrumb operates on a QAIM. It uses a KBreadcrumbSelectionModel to manage the visible
* breadcrumb selection.
* This breadcrumb always expands fully to the deepest child.
* Selections are remembered when switching to/from in parent nodes
* Items that have a DefaultRole set will automatically select the default unless the user has
* made a previous selection, which is saved in the UserSelection role
*/
class Breadcrumb : public QWidget
{
Q_OBJECT
public:
enum ExtraRoles {
DefaultRole = Qt::UserRole + 1,
UserSelectedRole = Qt::UserRole + 2
};
explicit Breadcrumb( QWidget* parent = 0, Qt::WindowFlags f = 0 );
virtual ~Breadcrumb();
void setModel( QAbstractItemModel* model );
QAbstractItemModel* model() const { return m_model; }
void setRootIcon( const QPixmap& pm );
protected:
virtual void paintEvent( QPaintEvent* );
signals:
void activateIndex( const QModelIndex& idx );
private slots:
void breadcrumbComboChanged( const QModelIndex& );
private:
// Takes an index in the selection model to update from (updates from that to all children)
void updateButtons( const QModelIndex& fromIndex );
QAbstractItemModel* m_model;
KBreadcrumbSelectionModel* m_selModel;
QPixmap m_rootIcon;
QHBoxLayout* m_buttonlayout;
QList<BreadcrumbButton*> m_buttons;
};
}
#endif // TOMAHAWK_BREADCRUMB_H

View File

@ -0,0 +1,169 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2011, Casey Link <unnamedrambler@gmail.com>
* 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 "BreadcrumbButton.h"
#include "Breadcrumb.h"
#include "combobox.h"
#include "utils/stylehelper.h"
#include "utils/tomahawkutils.h"
#include <QPaintEvent>
#include <QPainter>
using namespace Tomahawk;
BreadcrumbButton::BreadcrumbButton( Breadcrumb* parent, QAbstractItemModel* model )
: QWidget( parent )
, m_breadcrumb( parent )
, m_model( model )
, m_combo( new ComboBox( this ) )
{
setFixedHeight( TomahawkUtils::headerHeight() );
m_combo->setSizeAdjustPolicy( QComboBox::AdjustToContents );
connect( m_combo, SIGNAL( activated( int ) ), SLOT( comboboxActivated( int ) ) );
}
void
BreadcrumbButton::paintEvent( QPaintEvent* )
{
QPainter p( this );
QStyleOption opt;
opt.initFrom( this );
QRect r = opt.rect;
StyleHelper::horizontalHeader( &p, r ); // draw the background
if( !hasChildren() )
return;
bool reverse = opt.direction == Qt::RightToLeft;
int menuButtonWidth = 12;
int rightSpacing = 10;
int left = !reverse ? r.right()-rightSpacing - menuButtonWidth : r.left();
int right = !reverse ? r.right()-rightSpacing : r.left() + menuButtonWidth;
int height = sizeHint().height();
QRect arrowRect( ( left + right ) / 2 + ( reverse ? 6 : -6 ), 0, height, height );
QStyleOption arrowOpt = opt;
arrowOpt.rect = arrowRect;
QLine l1( left, 0, right, height/2 );
QLine l2( left, height, right, height/2 );
p.setRenderHint( QPainter::Antialiasing, true );
// Draw the shadow
QColor shadow( 0, 0, 0, 100 );
p.translate( 0, -1 );
p.setPen( shadow );
p.drawLine( l1 );
p.drawLine( l2 );
// Draw the main arrow
QColor foreGround( "#747474" );
p.translate( 0, 1 );
p.setPen( foreGround );
p.drawLine( l1 );
p.drawLine( l2 );
}
QSize
BreadcrumbButton::sizeHint() const
{
// our width = width of combo + 20px for right-arrow and spacing
const int padding = hasChildren() ? 20 : 5;
return m_combo->sizeHint() + QSize( padding, 0 );
}
void
BreadcrumbButton::setParentIndex( const QModelIndex& idx )
{
m_parentIndex = idx;
// Populate listview with list of children.
// Then try to find a default
QStringList list;
int count = m_model->rowCount( m_parentIndex );
int defaultIndex = -1, userSelected = -1;
for ( int i = 0; i < count; ++i )
{
QModelIndex idx = m_model->index( i, 0, m_parentIndex );
if ( idx.isValid() )
{
list << idx.data().toString();
if ( idx.data( Breadcrumb::DefaultRole ).toBool() )
defaultIndex = i;
if ( idx.data( Breadcrumb::UserSelectedRole ).toBool() )
userSelected = i;
}
}
m_combo->clear();
m_combo->addItems( list );
if ( userSelected > -1 )
m_combo->setCurrentIndex( userSelected );
else if ( defaultIndex > -1 )
m_combo->setCurrentIndex( defaultIndex );
m_curIndex = m_model->index( m_combo->currentIndex(), 0, m_parentIndex );
m_combo->adjustSize();
/*
if ( m_combo->count() && list.count() )
{
// Check if it's the same, Don't change if it is, as it'll cause flickering
QStringList old;
for ( int i = 0; i < m_combo->count(); i++ )
old << m_combo->itemText( i );
if ( list == old )
return;
}*/
}
void
BreadcrumbButton::comboboxActivated( int idx )
{
m_model->setData( m_curIndex, false, Breadcrumb::UserSelectedRole );
QModelIndex selected = m_model->index( idx, 0, m_parentIndex );
m_curIndex = selected;
m_model->setData( selected, true, Breadcrumb::UserSelectedRole );
emit currentIndexChanged( selected );
}
bool
BreadcrumbButton::hasChildren() const
{
return m_model->rowCount( m_model->index( m_combo->currentIndex(), 0, m_parentIndex ) ) > 0;
}
QModelIndex
BreadcrumbButton::currentIndex() const
{
return m_model->index( m_combo->currentIndex(), 0, m_parentIndex );
}

View File

@ -0,0 +1,69 @@
/* === This file is part of Tomahawk Player - <http://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/>.
*/
#ifndef TOMAHAWK_BREADCRUMBBUTTON_H
#define TOMAHAWK_BREADCRUMBBUTTON_H
#include <QWidget>
#include <QModelIndex>
class ComboBox;
class QPaintEvent;
namespace Tomahawk {
class Breadcrumb;
class BreadcrumbModel;
class BreadcrumbButton : public QWidget
{
Q_OBJECT
public:
explicit BreadcrumbButton( Breadcrumb* parent, QAbstractItemModel* model );
void setParentIndex( const QModelIndex& idx );
// Which index is currently visible. This is the first, default or last selected
// calculated immediately after loading, or what the user has selected if he has made
// a manua;l selection
QModelIndex currentIndex() const;
protected:
virtual void paintEvent( QPaintEvent* );
virtual QSize sizeHint() const;
signals:
// Some combobox value is changed
void currentIndexChanged( const QModelIndex& childSelected );
private slots:
void comboboxActivated( int );
private:
bool hasChildren() const;
Breadcrumb* m_breadcrumb;
QAbstractItemModel* m_model;
QPersistentModelIndex m_parentIndex;
QPersistentModelIndex m_curIndex;
ComboBox* m_combo;
};
}
#endif // TOMAHAWK_BREADCRUMBBUTTON_H

View File

@ -65,17 +65,11 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent )
TomahawkUtils::unmarginLayout( ui->breadCrumbLeft->layout() );
TomahawkUtils::unmarginLayout( ui->verticalLayout->layout() );
//set crumb widgets
SiblingCrumbButtonFactory * crumbFactory = new SiblingCrumbButtonFactory;
m_crumbModelLeft = new QStandardItemModel( this );
ui->breadCrumbLeft->setButtonFactory( crumbFactory );
ui->breadCrumbLeft->setModel( m_crumbModelLeft );
ui->breadCrumbLeft->setRootIcon(QIcon( RESPATH "images/charts.png" ));
ui->breadCrumbLeft->setUseAnimation( true );
ui->breadCrumbLeft->setRootIcon( QPixmap( RESPATH "images/charts.png" ) );
connect( ui->breadCrumbLeft, SIGNAL( currentIndexChanged( QModelIndex ) ), SLOT( leftCrumbIndexChanged(QModelIndex) ) );
connect( ui->breadCrumbLeft, SIGNAL( activateIndex( QModelIndex ) ), SLOT( leftCrumbIndexChanged(QModelIndex) ) );
ui->tracksViewLeft->setFrameShape( QFrame::NoFrame );
ui->tracksViewLeft->setAttribute( Qt::WA_MacShowFocusRect, 0 );
@ -216,9 +210,7 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
}
}
KBreadcrumbSelectionModel *selectionModelLeft = new KBreadcrumbSelectionModel(new QItemSelectionModel(m_crumbModelLeft, this), this);
ui->breadCrumbLeft->setSelectionModel(selectionModelLeft);
//ui->breadCrumbRight->setSelectionModel(selectionModelLeft);
ui->breadCrumbLeft->setModel( m_crumbModelLeft );
break;
}
case InfoSystem::InfoChart:
@ -321,12 +313,12 @@ WhatsHotWidget::leftCrumbIndexChanged( QModelIndex index )
return;
QList<QModelIndex> indexes;
while ( index.parent().isValid() )
{
indexes.prepend(index);
index = index.parent();
}
QList<QModelIndex> indexes;
while ( index.parent().isValid() )
{
indexes.prepend(index);
index = index.parent();
}
const QString chartId = item->data().toString();

View File

@ -12,7 +12,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="HeaderBreadCrumb" name="breadCrumbLeft" native="true"/>
<widget class="Tomahawk::Breadcrumb" name="breadCrumbLeft" native="true"/>
</item>
<item>
<widget class="QStackedWidget" name="stackLeft">
@ -79,9 +79,10 @@
<header>playlist/playlistview.h</header>
</customwidget>
<customwidget>
<class>HeaderBreadCrumb</class>
<class>Tomahawk::Breadcrumb</class>
<extends>QWidget</extends>
<header location="global">widgets/headerbreadcrumb.h</header>
<header>widgets/Breadcrumb.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>