File indexing completed on 2024-05-05 04:49:24
0001 /**************************************************************************************** 0002 * Copyright (c) 2010 Téo Mrnjavac <teo@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #include "TranscodingOptionsStackedWidget.h" 0018 0019 #include "core/support/Debug.h" 0020 #include "core/transcoding/TranscodingProperty.h" 0021 #include "core/transcoding/TranscodingController.h" 0022 0023 #include <QIcon> 0024 #include <KLocalizedString> 0025 0026 #include <QHBoxLayout> 0027 #include <QLabel> 0028 #include <QSpinBox> 0029 0030 namespace Transcoding 0031 { 0032 0033 OptionsStackedWidget::OptionsStackedWidget( QWidget *parent ) 0034 : QStackedWidget( parent ) 0035 { 0036 initWelcomePage(); 0037 foreach( const Encoder &encoder, Amarok::Components::transcodingController()->availableEncoders() ) 0038 { 0039 Format *format = Amarok::Components::transcodingController()->format( encoder ); 0040 m_pagesMap.insert( encoder, initCodecPage( format ) ); 0041 } 0042 } 0043 0044 void 0045 OptionsStackedWidget::initWelcomePage() 0046 { 0047 QWidget *welcomeWidget = new QWidget( this ); 0048 QVBoxLayout *vbl = new QVBoxLayout( welcomeWidget ); 0049 vbl->addStretch(); 0050 QHBoxLayout *hbl = new QHBoxLayout( welcomeWidget ); 0051 vbl->addLayout( hbl ); 0052 hbl->addStretch(); 0053 QLabel *arrow = new QLabel( welcomeWidget ); 0054 arrow->setPixmap( QIcon::fromTheme( QStringLiteral("arrow-left") ).pixmap( 16, 16 ) ); 0055 QLabel *message = new QLabel( i18n( 0056 "In order to configure the parameters of the transcoding operation, please " 0057 "pick an encoder from the list." ), this ); 0058 message->setWordWrap( true ); 0059 hbl->addWidget( arrow ); 0060 hbl->addWidget( message ); 0061 hbl->addStretch(); 0062 vbl->addStretch(); 0063 0064 insertWidget( 0, welcomeWidget ); 0065 } 0066 0067 int 0068 OptionsStackedWidget::initCodecPage( Format *format ) 0069 { 0070 m_propertyWidgetsMap.insert( format->encoder(), QList< PropertyWidget * >() ); 0071 0072 QWidget *codecWidget = new QWidget( this ); 0073 0074 QVBoxLayout *mainLayout = new QVBoxLayout( codecWidget ); 0075 mainLayout->addStretch( 1 ); 0076 0077 foreach( Property property, format->propertyList() ) 0078 { 0079 PropertyWidget *propertyWidget = PropertyWidget::create( property, codecWidget ); 0080 mainLayout->addWidget( propertyWidget->widget() ); 0081 m_propertyWidgetsMap[ format->encoder() ].append( propertyWidget ); 0082 debug() << "Created config widget for " << format->prettyName() 0083 << ", element " << property.name(); 0084 } 0085 0086 return addWidget( codecWidget ); 0087 } 0088 0089 const Configuration 0090 OptionsStackedWidget::configuration( const Configuration::TrackSelection trackSelection ) const 0091 { 0092 Encoder encoder = m_pagesMap.key( currentIndex() ); 0093 Configuration configuration = Configuration( encoder, trackSelection ); 0094 0095 foreach( PropertyWidget *propertyWidget, m_propertyWidgetsMap.value( encoder ) ) 0096 { 0097 configuration.addProperty( propertyWidget->name(), propertyWidget->value() ); 0098 } 0099 0100 return configuration; 0101 } 0102 0103 void 0104 OptionsStackedWidget::switchPage( Encoder encoder) 0105 { 0106 setCurrentIndex( m_pagesMap.value( encoder ) ); 0107 Q_EMIT formatChanged( encoder ); 0108 } 0109 0110 } //namespace Transcoding