/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. #include "DynamicSetupWidget.h"
  20. #include "ReadOrWriteWidget.h"
  21. #include "playlist/dynamic/DynamicPlaylist.h"
  22. #include "playlist/dynamic/GeneratorFactory.h"
  23. #include "DynamicWidget.h"
  24. #include "Source.h"
  25. #include <QHBoxLayout>
  26. #include <QComboBox>
  27. #include <QLabel>
  28. #include <QPushButton>
  29. #include <QSpinBox>
  30. #include <QPropertyAnimation>
  31. #include <QPaintEvent>
  32. #include <QPainter>
  33. #include "utils/Logger.h"
  34. using namespace Tomahawk;
  35. DynamicSetupWidget::DynamicSetupWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget* parent )
  36. : QWidget( parent )
  37. , m_playlist( playlist )
  38. , m_headerText( 0 )
  39. , m_layout( new QHBoxLayout )
  40. , m_generatorCombo( 0 )
  41. , m_logo( 0 )
  42. , m_generateButton( 0 )
  43. , m_genNumber( 0 )
  44. {
  45. setContentsMargins( 0, 0, 0, 0 );
  46. m_headerText = new QLabel( tr( "Type:" ), this );
  47. m_layout->addWidget( m_headerText );
  48. QComboBox * genCombo = new QComboBox( this );
  49. foreach( const QString& type, GeneratorFactory::types() )
  50. genCombo->addItem( type );
  51. m_generatorCombo = new ReadOrWriteWidget( genCombo, m_playlist->author()->isLocal(), this );
  52. m_generatorCombo->setLabel( playlist->generator()->type().replace( 0, 1, playlist->generator()->type().at( 0 ).toUpper() ) );
  53. m_layout->addWidget( m_generatorCombo );
  54. // TODO until there are more... no point in choices
  55. m_headerText->hide();
  56. m_generatorCombo->hide();
  57. m_generateButton = new QPushButton( tr( "Generate" ), this );
  58. m_generateButton->setAttribute( Qt::WA_LayoutUsesWidgetRect );
  59. connect( m_generateButton, SIGNAL( clicked( bool ) ), this, SLOT( generatePressed( bool ) ) );
  60. if( m_playlist->mode() == OnDemand )
  61. m_generateButton->hide();
  62. else
  63. m_layout->addWidget( m_generateButton );
  64. m_genNumber = new QSpinBox( this );
  65. m_genNumber->setValue( 15 );
  66. m_genNumber->setMinimum( 0 );
  67. if( m_playlist->mode() == OnDemand )
  68. m_genNumber->hide();
  69. else
  70. m_layout->addWidget( m_genNumber );
  71. if( m_playlist->mode() == Static )
  72. m_layout->addSpacing( 30 );
  73. m_logo = new QLabel( this );
  74. if( !m_playlist->generator()->logo().isNull() ) {
  75. QPixmap p = m_playlist->generator()->logo().scaledToHeight( 22, Qt::SmoothTransformation );
  76. m_logo->setPixmap( p );
  77. }
  78. m_layout->addWidget(m_logo);
  79. setLayout( m_layout );
  80. m_fadeAnim = new QPropertyAnimation( this, "opacity" );
  81. m_fadeAnim->setDuration( 250 );
  82. m_fadeAnim->setStartValue( 0.00 );
  83. m_fadeAnim->setEndValue( .70 );
  84. setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
  85. resize( QWidget::sizeHint() );
  86. }
  87. DynamicSetupWidget::~DynamicSetupWidget()
  88. {
  89. }
  90. void
  91. DynamicSetupWidget::setPlaylist( const Tomahawk::dynplaylist_ptr& playlist )
  92. {
  93. Q_UNUSED( playlist );
  94. }
  95. void
  96. DynamicSetupWidget::fadeIn()
  97. {
  98. m_fadeAnim->setDirection( QAbstractAnimation::Forward );
  99. m_fadeAnim->start();
  100. show();
  101. }
  102. void
  103. DynamicSetupWidget::fadeOut()
  104. {
  105. m_fadeAnim->setDirection( QAbstractAnimation::Backward );
  106. m_fadeAnim->start();
  107. }
  108. void
  109. DynamicSetupWidget::generatePressed( bool )
  110. {
  111. emit generatePressed( m_genNumber->value() );
  112. }
  113. void
  114. DynamicSetupWidget::setOpacity( qreal opacity )
  115. {
  116. m_opacity = opacity;
  117. if( m_opacity == 0 )
  118. hide();
  119. repaint();
  120. }
  121. void
  122. DynamicSetupWidget::paintEvent( QPaintEvent* e )
  123. {
  124. QPainter p( this );
  125. QRect r = contentsRect();
  126. QPalette pal = palette();
  127. DynamicWidget::paintRoundedFilledRect( p, pal, r, m_opacity );
  128. QWidget::paintEvent( e );
  129. }