PageRenderTime 83ms CodeModel.GetById 40ms app.highlight 13ms RepoModel.GetById 28ms app.codeStats 0ms

/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
 20#include "JobStatusView.h"
 21
 22#include <QHeaderView>
 23#include <QVBoxLayout>
 24
 25#include "libtomahawk/pipeline.h"
 26
 27#include "utils/logger.h"
 28
 29using namespace Tomahawk;
 30
 31
 32JobStatusView::JobStatusView( AnimatedSplitter* parent )
 33    : AnimatedWidget( parent )
 34    , m_parent( parent )
 35{
 36    setHiddenSize( QSize( 0, 0 ) );
 37    setLayout( new QVBoxLayout() );
 38    m_tree = new QTreeWidget( this );
 39
 40    layout()->setMargin( 0 );
 41    layout()->addWidget( m_tree );
 42
 43    QStringList headers;
 44    headers << tr( "Searching For" ) << tr( "Pending" );
 45    m_tree->setHeaderLabels( headers );
 46
 47    m_tree->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
 48    m_tree->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Ignored );
 49    m_tree->setColumnCount( 2 );
 50    m_tree->setColumnWidth( 0, 200 );
 51    m_tree->setColumnWidth( 1, 50 );
 52
 53    m_tree->header()->setStretchLastSection( true );
 54    m_tree->setRootIsDecorated( false );
 55
 56    m_tree->setFrameShape( QFrame::NoFrame );
 57    m_tree->setAttribute( Qt::WA_MacShowFocusRect, 0 );
 58
 59    new QTreeWidgetItem( m_tree );
 60
 61    connect( Pipeline::instance(), SIGNAL( resolving( Tomahawk::query_ptr ) ), SLOT( onPipelineUpdate( Tomahawk::query_ptr ) ) );
 62    connect( Pipeline::instance(), SIGNAL( idle() ), SLOT( onPipelineUpdate() ) );
 63
 64#ifndef Q_WS_WIN
 65    QFont f = font();
 66    f.setPointSize( f.pointSize() - 1 );
 67    setFont( f );
 68#endif
 69
 70#ifdef Q_WS_MAC
 71    f.setPointSize( f.pointSize() - 2 );
 72    setFont( f );
 73#endif
 74
 75    onPipelineUpdate();
 76}
 77
 78
 79void
 80JobStatusView::onPipelineUpdate( const query_ptr& query )
 81{
 82    QTreeWidgetItem* ti = m_tree->invisibleRootItem()->child( 0 );
 83
 84    if ( Pipeline::instance()->activeQueryCount() && !query.isNull() )
 85    {
 86        ti->setText( 0, QString( "%1 - %2" ).arg( query->artist() ).arg( query->track() ) );
 87        ti->setText( 1, QString( "%1" ).arg( Pipeline::instance()->activeQueryCount() + Pipeline::instance()->pendingQueryCount() ) );
 88
 89        if ( isHidden() )
 90            emit showWidget();
 91    }
 92    else
 93    {
 94        ti->setText( 0, tr( "Idle" ) );
 95        ti->setText( 1, QString( "None" ) );
 96
 97        if ( !isHidden() )
 98            emit hideWidget();
 99    }
100}
101
102
103QSize
104JobStatusView::sizeHint() const
105{
106    unsigned int y = 0;
107    y += m_tree->header()->height();
108    y += m_tree->contentsMargins().top() + m_tree->contentsMargins().bottom();
109
110    if ( m_tree->invisibleRootItem()->childCount() )
111    {
112        unsigned int rowheight = m_tree->sizeHintForRow( 0 );
113        y += rowheight * m_tree->invisibleRootItem()->childCount() + 2;
114    }
115
116    return QSize( 0, y );
117}