PageRenderTime 352ms CodeModel.GetById 100ms app.highlight 170ms RepoModel.GetById 72ms app.codeStats 1ms

/src/libtomahawk/playlist/dynamic/widgets/DynamicSetupWidget.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 164 lines | 110 code | 35 blank | 19 comment | 9 complexity | 1866e6a449742075476f6a4020598bc5 MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
  4 *   Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.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 "DynamicSetupWidget.h"
 21
 22#include "ReadOrWriteWidget.h"
 23#include "playlist/dynamic/DynamicPlaylist.h"
 24#include "playlist/dynamic/GeneratorFactory.h"
 25#include "DynamicWidget.h"
 26#include "Source.h"
 27
 28#include <QHBoxLayout>
 29#include <QComboBox>
 30#include <QLabel>
 31#include <QPushButton>
 32#include <QSpinBox>
 33#include <QPropertyAnimation>
 34#include <QPaintEvent>
 35#include <QPainter>
 36
 37#include "utils/Logger.h"
 38
 39using namespace Tomahawk;
 40
 41
 42DynamicSetupWidget::DynamicSetupWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget* parent )
 43    : QWidget( parent )
 44    , m_playlist( playlist )
 45    , m_headerText( 0 )
 46    , m_layout( new QHBoxLayout )
 47    , m_generatorCombo( 0 )
 48    , m_logo( 0 )
 49    , m_generateButton( 0 )
 50    , m_genNumber( 0 )
 51{
 52    setContentsMargins( 0, 0, 0, 0 );
 53    m_headerText = new QLabel( tr( "Type:" ), this );
 54    m_layout->addWidget( m_headerText );
 55
 56    QComboBox * genCombo = new QComboBox( this );
 57    foreach( const QString& type, GeneratorFactory::types() )
 58        genCombo->addItem( type );
 59    m_generatorCombo = new ReadOrWriteWidget( genCombo, m_playlist->author()->isLocal(), this );
 60    m_generatorCombo->setLabel( playlist->generator()->type().replace( 0, 1, playlist->generator()->type().at( 0 ).toUpper() ) );
 61
 62    m_layout->addWidget( m_generatorCombo );
 63    // TODO until there are more... no point in choices
 64    m_headerText->hide();
 65    m_generatorCombo->hide();
 66
 67    m_generateButton = new QPushButton( tr( "Generate" ), this );
 68    m_generateButton->setAttribute( Qt::WA_LayoutUsesWidgetRect );
 69    connect( m_generateButton, SIGNAL( clicked( bool ) ), this, SLOT( generatePressed( bool ) ) );
 70    if( m_playlist->mode() == OnDemand )
 71        m_generateButton->hide();
 72    else
 73        m_layout->addWidget( m_generateButton );
 74
 75    m_genNumber = new QSpinBox( this );
 76    m_genNumber->setValue( 15 );
 77    m_genNumber->setMinimum( 0 );
 78    if( m_playlist->mode() == OnDemand )
 79        m_genNumber->hide();
 80    else
 81        m_layout->addWidget( m_genNumber );
 82
 83    if( m_playlist->mode() == Static )
 84        m_layout->addSpacing( 30 );
 85
 86    m_logo = new QLabel( this );
 87    if( !m_playlist->generator()->logo().isNull() ) {
 88        QPixmap p = m_playlist->generator()->logo().scaledToHeight( 22, Qt::SmoothTransformation );
 89        m_logo->setPixmap( p );
 90    }
 91    m_layout->addWidget(m_logo);
 92
 93    setLayout( m_layout );
 94
 95    m_fadeAnim = new QPropertyAnimation( this, "opacity" );
 96    m_fadeAnim->setDuration( 250 );
 97    m_fadeAnim->setStartValue( 0.00 );
 98    m_fadeAnim->setEndValue( .70 );
 99
100    setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
101    resize( QWidget::sizeHint() );
102}
103
104
105DynamicSetupWidget::~DynamicSetupWidget()
106{
107
108}
109
110
111void
112DynamicSetupWidget::setPlaylist( const Tomahawk::dynplaylist_ptr& playlist )
113{
114    Q_UNUSED( playlist );
115}
116
117
118void
119DynamicSetupWidget::fadeIn()
120{
121    m_fadeAnim->setDirection( QAbstractAnimation::Forward );
122    m_fadeAnim->start();
123
124    show();
125}
126
127
128void
129DynamicSetupWidget::fadeOut()
130{
131    m_fadeAnim->setDirection( QAbstractAnimation::Backward );
132    m_fadeAnim->start();
133
134}
135
136
137void
138DynamicSetupWidget::generatePressed( bool )
139{
140    emit generatePressed( m_genNumber->value() );
141}
142
143void
144DynamicSetupWidget::setOpacity( qreal opacity )
145{
146    m_opacity = opacity;
147
148    if( m_opacity == 0 )
149        hide();
150    repaint();
151}
152
153
154void
155DynamicSetupWidget::paintEvent( QPaintEvent* e )
156{
157    QPainter p( this );
158    QRect r = contentsRect();
159    QPalette pal = palette();
160
161    DynamicWidget::paintRoundedFilledRect( p, pal, r, m_opacity );
162
163    QWidget::paintEvent( e );
164}