/src/PipelineStatusView.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 117 lines · 73 code · 26 blank · 18 comment · 5 complexity · 771026afccee6cee44a39dd18eddc694 MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4. * Copyright 2011, Leo Franchi <lfranchi@kde.org>
  5. *
  6. * Tomahawk is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Tomahawk is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "JobStatusView.h"
  20. #include <QHeaderView>
  21. #include <QVBoxLayout>
  22. #include "libtomahawk/pipeline.h"
  23. #include "utils/logger.h"
  24. using namespace Tomahawk;
  25. JobStatusView::JobStatusView( AnimatedSplitter* parent )
  26. : AnimatedWidget( parent )
  27. , m_parent( parent )
  28. {
  29. setHiddenSize( QSize( 0, 0 ) );
  30. setLayout( new QVBoxLayout() );
  31. m_tree = new QTreeWidget( this );
  32. layout()->setMargin( 0 );
  33. layout()->addWidget( m_tree );
  34. QStringList headers;
  35. headers << tr( "Searching For" ) << tr( "Pending" );
  36. m_tree->setHeaderLabels( headers );
  37. m_tree->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
  38. m_tree->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Ignored );
  39. m_tree->setColumnCount( 2 );
  40. m_tree->setColumnWidth( 0, 200 );
  41. m_tree->setColumnWidth( 1, 50 );
  42. m_tree->header()->setStretchLastSection( true );
  43. m_tree->setRootIsDecorated( false );
  44. m_tree->setFrameShape( QFrame::NoFrame );
  45. m_tree->setAttribute( Qt::WA_MacShowFocusRect, 0 );
  46. new QTreeWidgetItem( m_tree );
  47. connect( Pipeline::instance(), SIGNAL( resolving( Tomahawk::query_ptr ) ), SLOT( onPipelineUpdate( Tomahawk::query_ptr ) ) );
  48. connect( Pipeline::instance(), SIGNAL( idle() ), SLOT( onPipelineUpdate() ) );
  49. #ifndef Q_WS_WIN
  50. QFont f = font();
  51. f.setPointSize( f.pointSize() - 1 );
  52. setFont( f );
  53. #endif
  54. #ifdef Q_WS_MAC
  55. f.setPointSize( f.pointSize() - 2 );
  56. setFont( f );
  57. #endif
  58. onPipelineUpdate();
  59. }
  60. void
  61. JobStatusView::onPipelineUpdate( const query_ptr& query )
  62. {
  63. QTreeWidgetItem* ti = m_tree->invisibleRootItem()->child( 0 );
  64. if ( Pipeline::instance()->activeQueryCount() && !query.isNull() )
  65. {
  66. ti->setText( 0, QString( "%1 - %2" ).arg( query->artist() ).arg( query->track() ) );
  67. ti->setText( 1, QString( "%1" ).arg( Pipeline::instance()->activeQueryCount() + Pipeline::instance()->pendingQueryCount() ) );
  68. if ( isHidden() )
  69. emit showWidget();
  70. }
  71. else
  72. {
  73. ti->setText( 0, tr( "Idle" ) );
  74. ti->setText( 1, QString( "None" ) );
  75. if ( !isHidden() )
  76. emit hideWidget();
  77. }
  78. }
  79. QSize
  80. JobStatusView::sizeHint() const
  81. {
  82. unsigned int y = 0;
  83. y += m_tree->header()->height();
  84. y += m_tree->contentsMargins().top() + m_tree->contentsMargins().bottom();
  85. if ( m_tree->invisibleRootItem()->childCount() )
  86. {
  87. unsigned int rowheight = m_tree->sizeHintForRow( 0 );
  88. y += rowheight * m_tree->invisibleRootItem()->childCount() + 2;
  89. }
  90. return QSize( 0, y );
  91. }