1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 03:10:12 +02:00

Added icons to toolbar, but also a debug commit for a nasty crash.

This commit is contained in:
Teo Mrnjavac
2012-08-14 20:54:38 +02:00
parent eb559dd0a0
commit ef5efacade
7 changed files with 138 additions and 4 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@@ -151,5 +151,6 @@
<file>data/images/subscribe-on.png</file>
<file>data/images/subscribe-off.png</file>
<file>data/images/add-contact.png</file>
<file>data/images/account-none.png</file>
</qresource>
</RCC>

View File

@@ -44,6 +44,8 @@ AccountListWidget::AccountListWidget( AccountModelFactoryProxy* model, QWidget*
void
AccountListWidget::updateEntries( const QModelIndex& topLeft, const QModelIndex& bottomRight )
{
Q_UNUSED( topLeft )
Q_UNUSED( bottomRight )
for ( QHash< QPersistentModelIndex, QList< AccountWidget* > >::iterator it
= m_entries.begin();
it != m_entries.end(); ++it )
@@ -113,6 +115,8 @@ AccountListWidget::removeEntries( const QModelIndex& parent, int start, int end
for ( int j = 0; j < entryAccounts.count(); ++j )
{
AccountWidget *a = entryAccounts.at( j );
qDebug() << "Removing entry " << idx.data( Tomahawk::Accounts::AccountModel::ChildrenOfFactoryRole )
.value< QList< Tomahawk::Accounts::Account* > >().at( j )->accountId();
m_layout->removeWidget( a );
a->deleteLater();
}

View File

@@ -18,6 +18,8 @@
#include "AccountModelFactoryProxy.h"
#include <QDebug>
using namespace Tomahawk;
using namespace Accounts;
@@ -26,6 +28,7 @@ AccountModelFactoryProxy::AccountModelFactoryProxy( QObject* parent )
, m_filterEnabled( false )
, m_filterRowType( AccountModel::TopLevelFactory )
{
setDynamicSortFilter( true );
}
@@ -37,6 +40,9 @@ AccountModelFactoryProxy::filterAcceptsRow( int sourceRow, const QModelIndex& so
const QModelIndex idx = sourceModel()->index( sourceRow, 0, sourceParent );
const Qt::CheckState checkState = static_cast< Qt::CheckState >( idx.data( Qt::CheckStateRole ).value< int >() );
qDebug() << "FILTERING";
qDebug() << "checkState is " << checkState;
if( checkState == Qt::Unchecked ) //if the service is not even enabled
return false;

View File

@@ -32,8 +32,9 @@ AccountsPopupWidget::AccountsPopupWidget( QWidget* parent )
: QWidget( parent )
, m_widget( 0 )
{
setWindowFlags( Qt::FramelessWindowHint );
setWindowFlags( Qt::Popup );
//setWindowFlags( Qt::FramelessWindowHint );
//setWindowFlags( Qt::Popup );
setWindowFlags( Qt::Window );
setAutoFillBackground( false );
setAttribute( Qt::WA_TranslucentBackground, true );

View File

@@ -24,6 +24,9 @@
#include <QLabel>
#include <QListView>
#include <QMouseEvent>
#include <QPainter>
#include <QPaintEvent>
#include <QToolBar>
#include <QVBoxLayout>
AccountsToolButton::AccountsToolButton( QWidget* parent )
@@ -32,6 +35,12 @@ AccountsToolButton::AccountsToolButton( QWidget* parent )
m_popup = new AccountsPopupWidget( this );
m_popup->hide();
QToolBar* toolbar = qobject_cast< QToolBar* >( parent );
if ( toolbar )
setIconSize( toolbar->iconSize() );
else
setIconSize( QSize( 22, 22 ) );
//Set up popup...
QWidget *w = new QWidget( this );
w->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
@@ -76,6 +85,24 @@ AccountsToolButton::AccountsToolButton( QWidget* parent )
wMainLayout->addWidget( view );
view->setAutoFillBackground( false );
view->setAttribute( Qt::WA_TranslucentBackground, true );
connect( m_proxy, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ),
this, SLOT( repaint() ) );
//ToolButton stuff
m_defaultPixmap = QPixmap( RESPATH "images/account-none.png" )
.scaled( iconSize(),
Qt::KeepAspectRatio,
Qt::SmoothTransformation );
connect( m_proxy, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ),
this, SLOT( updateIcons() ) );
connect( m_proxy, SIGNAL( rowsInserted ( QModelIndex, int, int ) ),
this, SLOT( updateIcons() ) );
connect( m_proxy, SIGNAL( rowsRemoved( QModelIndex, int, int ) ),
this, SLOT( updateIcons() ) );
connect( m_proxy, SIGNAL( modelReset() ),
this, SLOT( updateIcons() ) );
}
void
@@ -91,17 +118,107 @@ AccountsToolButton::mousePressEvent( QMouseEvent* event )
QToolButton::mousePressEvent( event );
}
void
AccountsToolButton::paintEvent( QPaintEvent* event )
{
QToolButton::paintEvent( event );
QPainter painter( this );
painter.initFrom( this );
if ( m_proxy->rowCount() == 0 )
{
QRect pixmapRect( QPoint( width() / 2 - iconSize().width() / 2,
height() / 2 - iconSize().height() / 2 ),
iconSize() );
painter.drawPixmap( pixmapRect, m_defaultPixmap );
}
else
{
for ( int i = 0; i < m_factoryPixmaps.count(); ++i )
{
int diff = height() - iconSize().height();
int pixmapRectX = diff / 2
+ i * ( iconSize().width() + diff );
QRect pixmapRect( QPoint( pixmapRectX, height() / 2 - iconSize().height() / 2 ),
iconSize() );
painter.drawPixmap( pixmapRect, m_factoryPixmaps.at( i ) );
}
}
painter.end();
}
void
AccountsToolButton::popupHidden() //SLOT
{
setDown( false );
}
void
AccountsToolButton::updateIcons()
{
m_factoryPixmaps.clear();
for ( int i = 0; i < m_proxy->rowCount(); ++i )
{
QPersistentModelIndex idx( m_proxy->index( i, 0 ) );
const QList< Tomahawk::Accounts::Account* >& children =
idx.data( Tomahawk::Accounts::AccountModel::ChildrenOfFactoryRole )
.value< QList< Tomahawk::Accounts::Account* > >();
int count = children.count();
if ( count == 0 )
continue;
if ( count == 1 )
{
m_factoryPixmaps.append( children.first()->icon()
.scaled( iconSize(),
Qt::KeepAspectRatio,
Qt::SmoothTransformation ) );
}
else //we need to find if at least one of this factory's accounts is connected
{
int connectedAccountIndex = -1;
for ( int j = 0; j < count; ++j )
{
if ( children.at( j )->connectionState() ==
Tomahawk::Accounts::Account::Connected )
{
connectedAccountIndex = j;
break;
}
}
if ( connectedAccountIndex != -1 )
{
m_factoryPixmaps.append( children.at( connectedAccountIndex )->icon()
.scaled( iconSize(),
Qt::KeepAspectRatio,
Qt::SmoothTransformation ) );
}
else
{
m_factoryPixmaps.append( children.first()->icon()
.scaled( iconSize(),
Qt::KeepAspectRatio,
Qt::SmoothTransformation ) );
}
}
}
resize( sizeHint() );
repaint();
}
QSize
AccountsToolButton::sizeHint() const
{
QSize size = QToolButton::sizeHint();
size.rwidth() *= 3;
if ( m_factoryPixmaps.count() == 0 ) //no accounts enabled!
return size;
size.rwidth() *= m_factoryPixmaps.count();
return size;
}

View File

@@ -37,15 +37,20 @@ public:
QSize sizeHint() const;
protected:
void mousePressEvent( QMouseEvent *event );
void mousePressEvent( QMouseEvent* event );
void paintEvent( QPaintEvent* event );
private slots:
void popupHidden();
void updateIcons();
private:
AccountsPopupWidget* m_popup;
Tomahawk::Accounts::AccountModel *m_model;
AccountModelFactoryProxy *m_proxy;
QPixmap m_defaultPixmap;
QList< QPixmap > m_factoryPixmaps;
};
#endif // ACCOUNTSTOOLBUTTON_H