mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-02-25 20:33:20 +01:00
* Made QHeaderView behave, mostly.
* Removed online / offline button again.
This commit is contained in:
parent
0934b443f4
commit
6e708cc0c4
@ -13,7 +13,6 @@ using namespace Tomahawk;
|
||||
CollectionView::CollectionView( QWidget* parent )
|
||||
: TrackView( parent )
|
||||
{
|
||||
setGuid( "collectionview" );
|
||||
setProxyModel( new CollectionProxyModel( this ) );
|
||||
|
||||
setSortingEnabled( true );
|
||||
@ -37,6 +36,7 @@ void
|
||||
CollectionView::setModel( TrackModel* model )
|
||||
{
|
||||
TrackView::setModel( model );
|
||||
setGuid( "collectionview" );
|
||||
|
||||
connect( model, SIGNAL( trackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) );
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ using namespace Tomahawk;
|
||||
PlaylistView::PlaylistView( QWidget* parent )
|
||||
: TrackView( parent )
|
||||
{
|
||||
setGuid( "playlistview" );
|
||||
setProxyModel( new PlaylistProxyModel( this ) );
|
||||
|
||||
setContextMenuPolicy( Qt::CustomContextMenu );
|
||||
@ -31,14 +30,16 @@ PlaylistView::~PlaylistView()
|
||||
void
|
||||
PlaylistView::setModel( PlaylistModel* model )
|
||||
{
|
||||
if ( !model->playlist().isNull() )
|
||||
setGuid( QString( "playlistview/%1" ).arg( model->playlist()->guid() ) );
|
||||
|
||||
m_model = model;
|
||||
|
||||
TrackView::setModel( model );
|
||||
setColumnHidden( 5, true ); // Hide age column per default
|
||||
|
||||
if ( !model->playlist().isNull() )
|
||||
setGuid( QString( "playlistview/%1" ).arg( model->playlist()->guid() ) );
|
||||
else
|
||||
setGuid( "playlistview" );
|
||||
|
||||
connect( model, SIGNAL( trackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) );
|
||||
}
|
||||
|
||||
|
@ -14,28 +14,27 @@ TrackHeader::TrackHeader( TrackView* parent )
|
||||
, m_parent( parent )
|
||||
, m_menu( new QMenu( this ) )
|
||||
, m_sigmap( new QSignalMapper( this ) )
|
||||
, m_hiddenWidth( 0 )
|
||||
, m_hiddenPct( 0.0 )
|
||||
, m_init( false )
|
||||
{
|
||||
setStretchLastSection( true );
|
||||
setResizeMode( QHeaderView::Interactive );
|
||||
setMinimumSectionSize( 60 );
|
||||
setDefaultAlignment( Qt::AlignLeft );
|
||||
setMovable( true );
|
||||
setStretchLastSection( true );
|
||||
// setCascadingSectionResizes( true );
|
||||
|
||||
// m_menu->addAction( tr( "Resize columns to fit window" ), this, SLOT( onToggleResizeColumns() ) );
|
||||
// m_menu->addSeparator();
|
||||
|
||||
connect( this, SIGNAL( sectionResized( int, int, int ) ), SLOT( onSectionResized( int, int, int ) ) );
|
||||
// connect( this, SIGNAL( sectionResized( int, int, int ) ), SLOT( onSectionResized( int ) ) );
|
||||
connect( m_sigmap, SIGNAL( mapped( int ) ), SLOT( toggleVisibility( int ) ) );
|
||||
}
|
||||
|
||||
|
||||
TrackHeader::~TrackHeader()
|
||||
{
|
||||
saveColumnsState();
|
||||
qDebug() << "Storing for:" << m_parent->guid();
|
||||
TomahawkSettings::instance()->setPlaylistColumnSizes( m_parent->guid(), saveState() );
|
||||
}
|
||||
|
||||
|
||||
@ -47,75 +46,35 @@ TrackHeader::visibleSectionCount() const
|
||||
|
||||
|
||||
void
|
||||
TrackHeader::onSectionResized( int logicalidx, int oldSize, int newSize )
|
||||
TrackHeader::checkState()
|
||||
{
|
||||
if ( !m_init )
|
||||
if ( !count() || m_init )
|
||||
return;
|
||||
|
||||
int width = m_parent->viewport()->width();
|
||||
for ( int x = 0; x < m_columnWeights.count(); x++ )
|
||||
{
|
||||
if ( sectionSize( x ) )
|
||||
{
|
||||
// not hidden
|
||||
m_columnWeights[x] = (double)sectionSize( x ) / (double)width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TrackHeader::onResized()
|
||||
{
|
||||
if ( !m_init && count() )
|
||||
restoreColumnsState();
|
||||
|
||||
m_init = false;
|
||||
|
||||
int width = m_parent->viewport()->width();
|
||||
for ( int x = 0; x < m_columnWeights.count(); x++ )
|
||||
{
|
||||
if ( sectionSize( x ) )
|
||||
{
|
||||
// not hidden
|
||||
double nw = (double)width * m_columnWeights[x];
|
||||
resizeSection( x, qMax( minimumSectionSize(), int( nw ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "Restoring for:" << m_parent->guid();
|
||||
m_init = true;
|
||||
}
|
||||
QByteArray state = TomahawkSettings::instance()->playlistColumnSizes( m_parent->guid() );
|
||||
|
||||
|
||||
void
|
||||
TrackHeader::restoreColumnsState()
|
||||
{
|
||||
QList<QVariant> list = TomahawkSettings::instance()->playlistColumnSizes( m_parent->guid() );
|
||||
|
||||
if ( list.count() != count() ) // FIXME: const
|
||||
{
|
||||
m_columnWeights << 0.21 << 0.22 << 0.20 << 0.05 << 0.05 << 0.05 << 0.05 << 0.05 << 0.12;
|
||||
}
|
||||
if ( !state.isEmpty() )
|
||||
restoreState( state );
|
||||
else
|
||||
{
|
||||
foreach( const QVariant& v, list )
|
||||
m_columnWeights << v.toDouble();
|
||||
QList< double > m_columnWeights;
|
||||
m_columnWeights << 0.21 << 0.22 << 0.20 << 0.05 << 0.05 << 0.05 << 0.05 << 0.05; // << 0.12;
|
||||
|
||||
for ( int i = 0; i < count(); i++ )
|
||||
{
|
||||
if ( isSectionHidden( i ) )
|
||||
continue;
|
||||
|
||||
double nw = (double)m_parent->width() * m_columnWeights.at( i );
|
||||
qDebug() << "Setting default size:" << i << nw;
|
||||
resizeSection( i, qMax( minimumSectionSize(), int( nw - 0.5 ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TrackHeader::saveColumnsState()
|
||||
{
|
||||
QList<QVariant> wlist;
|
||||
|
||||
foreach( double w, m_columnWeights )
|
||||
wlist << QVariant( w );
|
||||
|
||||
TomahawkSettings::instance()->setPlaylistColumnSizes( m_parent->guid(), wlist );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TrackHeader::addColumnToMenu( int index )
|
||||
{
|
||||
@ -158,6 +117,4 @@ TrackHeader::toggleVisibility( int index )
|
||||
showSection( index );
|
||||
else
|
||||
hideSection( index );
|
||||
|
||||
onResized();
|
||||
}
|
||||
|
@ -19,32 +19,24 @@ public:
|
||||
int visibleSectionCount() const;
|
||||
|
||||
public slots:
|
||||
void onResized();
|
||||
void toggleVisibility( int index );
|
||||
void checkState();
|
||||
|
||||
protected:
|
||||
void contextMenuEvent( QContextMenuEvent* e );
|
||||
|
||||
private slots:
|
||||
void onSectionResized( int logicalIndex, int oldSize, int newSize );
|
||||
|
||||
// void onSectionResized( int index );
|
||||
void onToggleResizeColumns();
|
||||
|
||||
private:
|
||||
void addColumnToMenu( int index );
|
||||
|
||||
void restoreColumnsState();
|
||||
void saveColumnsState();
|
||||
|
||||
TrackView* m_parent;
|
||||
|
||||
QMenu* m_menu;
|
||||
QSignalMapper* m_sigmap;
|
||||
QList<QAction*> m_visActions;
|
||||
|
||||
QList<double> m_columnWeights;
|
||||
int m_hiddenWidth;
|
||||
double m_hiddenPct;
|
||||
bool m_init;
|
||||
};
|
||||
|
||||
|
@ -190,7 +190,7 @@ TrackModel::headerData( int section, Qt::Orientation orientation, int role ) con
|
||||
{
|
||||
QStringList headers;
|
||||
headers << tr( "Artist" ) << tr( "Track" ) << tr( "Album" ) << tr( "Duration" ) << tr( "Bitrate" ) << tr( "Age" ) << tr( "Year" ) << tr( "Size" ) << tr( "Origin" );
|
||||
if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 )
|
||||
if ( role == Qt::DisplayRole && section >= 0 )
|
||||
{
|
||||
return headers.at( section );
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ TrackView::TrackView( QWidget* parent )
|
||||
setRootIsDecorated( false );
|
||||
setUniformRowHeights( true );
|
||||
setMinimumWidth( 300 );
|
||||
setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn );
|
||||
|
||||
setHeader( m_header );
|
||||
|
||||
@ -61,6 +62,13 @@ TrackView::~TrackView()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TrackView::setGuid( const QString& guid )
|
||||
{
|
||||
m_guid = guid;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TrackView::setProxyModel( TrackProxyModel* model )
|
||||
{
|
||||
@ -156,7 +164,7 @@ TrackView::addItemsToQueue()
|
||||
void
|
||||
TrackView::resizeEvent( QResizeEvent* event )
|
||||
{
|
||||
m_header->onResized();
|
||||
m_header->checkState();
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,7 +23,7 @@ public:
|
||||
~TrackView();
|
||||
|
||||
virtual QString guid() const { return m_guid; }
|
||||
virtual void setGuid( const QString& guid ) { m_guid = guid; }
|
||||
virtual void setGuid( const QString& guid );
|
||||
|
||||
virtual void setModel( TrackModel* model );
|
||||
void setProxyModel( TrackProxyModel* model );
|
||||
|
@ -184,17 +184,17 @@ TomahawkSettings::setMainWindowState( const QByteArray& state )
|
||||
}
|
||||
|
||||
|
||||
QList<QVariant>
|
||||
QByteArray
|
||||
TomahawkSettings::playlistColumnSizes( const QString& playlistid ) const
|
||||
{
|
||||
return value( QString( "ui/playlist/%1/columnSizes" ).arg( playlistid ) ).toList();
|
||||
return value( QString( "ui/playlist/%1/columnSizes" ).arg( playlistid ) ).toByteArray();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TomahawkSettings::setPlaylistColumnSizes( const QString& playlistid, const QList<QVariant>& cols )
|
||||
TomahawkSettings::setPlaylistColumnSizes( const QString& playlistid, const QByteArray& state )
|
||||
{
|
||||
setValue( QString( "ui/playlist/%1/columnSizes" ).arg( playlistid ), cols );
|
||||
setValue( QString( "ui/playlist/%1/columnSizes" ).arg( playlistid ), state );
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,8 +32,8 @@ public:
|
||||
void setMainWindowState( const QByteArray& state );
|
||||
|
||||
/// Playlist stuff
|
||||
QList<QVariant> playlistColumnSizes( const QString& playlistid ) const;
|
||||
void setPlaylistColumnSizes( const QString& playlistid, const QList<QVariant>& cols );
|
||||
QByteArray playlistColumnSizes( const QString& playlistid ) const;
|
||||
void setPlaylistColumnSizes( const QString& playlistid, const QByteArray& state );
|
||||
|
||||
QList<Tomahawk::playlist_ptr> recentlyPlayedPlaylists() const;
|
||||
void appendRecentlyPlayedPlaylist( const Tomahawk::playlist_ptr& playlist );
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <QSplitter>
|
||||
#include <QStyleOption>
|
||||
#include <QWidget>
|
||||
|
||||
@ -19,8 +20,12 @@ ProxyStyle::drawControl( ControlElement ce, const QStyleOption* opt, QPainter* p
|
||||
{
|
||||
if ( ce == CE_Splitter )
|
||||
{
|
||||
p->setPen( QColor( 0x8c, 0x8c, 0x8c ) );
|
||||
p->drawLine( opt->rect.topLeft(), opt->rect.bottomRight() );
|
||||
const QSplitter* splitter = qobject_cast< const QSplitter* >( w );
|
||||
if ( !splitter->sizes().contains( 0 ) )
|
||||
{
|
||||
p->setPen( QColor( 0x8c, 0x8c, 0x8c ) );
|
||||
p->drawLine( opt->rect.topLeft(), opt->rect.bottomRight() );
|
||||
}
|
||||
}
|
||||
else
|
||||
QProxyStyle::drawControl( ce, opt, p, w );
|
||||
|
@ -87,22 +87,22 @@ TomahawkWindow::TomahawkWindow( QWidget* parent )
|
||||
sidebar->addWidget( transferView );
|
||||
sidebar->hide( 1, false );
|
||||
|
||||
QWidget* buttonWidget = new QWidget();
|
||||
/* QWidget* buttonWidget = new QWidget();
|
||||
buttonWidget->setLayout( new QVBoxLayout() );
|
||||
m_statusButton = new QPushButton();
|
||||
buttonWidget->layout()->addWidget( m_statusButton );
|
||||
buttonWidget->layout()->addWidget( m_statusButton );*/
|
||||
|
||||
sidebarWidget->layout()->addWidget( sidebar );
|
||||
sidebarWidget->layout()->addWidget( buttonWidget );
|
||||
// sidebarWidget->layout()->addWidget( buttonWidget );
|
||||
|
||||
sidebarWidget->setContentsMargins( 0, 0, 0, 0 );
|
||||
sidebarWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
|
||||
sidebarWidget->layout()->setMargin( 0 );
|
||||
sidebarWidget->layout()->setSpacing( 0 );
|
||||
buttonWidget->setContentsMargins( 0, 0, 0, 0 );
|
||||
/* buttonWidget->setContentsMargins( 0, 0, 0, 0 );
|
||||
buttonWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
|
||||
buttonWidget->layout()->setMargin( 0 );
|
||||
buttonWidget->layout()->setSpacing( 0 );
|
||||
buttonWidget->layout()->setSpacing( 0 );*/
|
||||
|
||||
ui->splitter->addWidget( sidebarWidget );
|
||||
ui->splitter->addWidget( PlaylistManager::instance()->widget() );
|
||||
@ -181,7 +181,7 @@ TomahawkWindow::setupSignals()
|
||||
connect( ui->actionCreate_New_Station, SIGNAL( triggered() ), SLOT( createStation() ));
|
||||
connect( ui->actionAboutTomahawk, SIGNAL( triggered() ), SLOT( showAboutTomahawk() ) );
|
||||
connect( ui->actionExit, SIGNAL( triggered() ), APP, SLOT( quit() ) );
|
||||
connect( m_statusButton, SIGNAL( clicked() ), APP->sipHandler(), SLOT( toggleConnect() ) );
|
||||
// connect( m_statusButton, SIGNAL( clicked() ), APP->sipHandler(), SLOT( toggleConnect() ) );
|
||||
|
||||
// <SipHandler>
|
||||
connect( APP->sipHandler(), SIGNAL( connected() ), SLOT( onSipConnected() ) );
|
||||
@ -392,14 +392,14 @@ TomahawkWindow::onPlaybackLoading( const Tomahawk::result_ptr& result )
|
||||
void
|
||||
TomahawkWindow::onSipConnected()
|
||||
{
|
||||
m_statusButton->setText( tr( "Online" ) );
|
||||
// m_statusButton->setText( tr( "Online" ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TomahawkWindow::onSipDisconnected()
|
||||
{
|
||||
m_statusButton->setText( tr( "Offline" ) );
|
||||
// m_statusButton->setText( tr( "Offline" ) );
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user