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 "TranscodingPropertySliderWidget.h" 0018 0019 #include "core/support/Debug.h" 0020 0021 #include "KLocalizedString" 0022 0023 #include <QHBoxLayout> 0024 0025 namespace Transcoding 0026 { 0027 0028 PropertySliderWidget::PropertySliderWidget( const Property &property, QWidget * parent ) 0029 : QWidget( parent ) 0030 , m_property( property ) 0031 { 0032 m_name = property.name(); 0033 0034 m_mainLabel = new QLabel( m_property.prettyName(), this ); 0035 m_mainLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ); 0036 0037 QBoxLayout *mainLayout = new QVBoxLayout( this ); 0038 QBoxLayout *secondaryTopLayout = new QHBoxLayout; 0039 QBoxLayout *secondaryBotLayout = new QHBoxLayout; 0040 mainLayout->addWidget( m_mainLabel ); 0041 mainLayout->addLayout( secondaryTopLayout ); 0042 mainLayout->addLayout( secondaryBotLayout ); 0043 secondaryTopLayout->addSpacing( 5 ); 0044 0045 m_mainEdit = new QSlider( this ); 0046 m_mainEdit->setOrientation( Qt::Horizontal ); 0047 m_mainEdit->setRange( m_property.min(), m_property.max() ); 0048 0049 m_mainEdit->setValue( m_property.defaultValue().toInt() ); 0050 m_mainEdit->setTickPosition( QSlider::TicksBelow ); 0051 m_mainEdit->setTickInterval( 1 ); 0052 m_mainEdit->setPageStep( 2 ); 0053 m_mainEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ); 0054 secondaryTopLayout->addWidget( m_mainEdit, 3 ); 0055 0056 secondaryTopLayout->addSpacing( 5 ); 0057 0058 QLabel *leftLabel = new QLabel( m_property.endLabels().at( 0 ), this ); 0059 secondaryBotLayout->addWidget( leftLabel, 1 ); 0060 0061 m_midLabel = new QLabel( QString::number( m_mainEdit->value() ), this ); 0062 { 0063 QFont font = m_midLabel->font(); 0064 font.setBold( true ); 0065 m_midLabel->setFont( font ); 0066 } 0067 connect( m_mainEdit, &QSlider::valueChanged, 0068 this, &PropertySliderWidget::onSliderChanged ); 0069 0070 QLabel *rightLabel = new QLabel( m_property.endLabels().at( 1 ), this ); 0071 rightLabel->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); 0072 secondaryBotLayout->addWidget( rightLabel, 1 ); 0073 0074 mainLayout->addWidget( m_midLabel ); 0075 0076 onSliderChanged( m_property.defaultValue().toInt() ); 0077 0078 QString description = m_property.description(); 0079 m_mainEdit->setToolTip( description ); 0080 m_mainLabel->setToolTip( description ); 0081 m_mainEdit->setWhatsThis( description ); 0082 m_mainLabel->setWhatsThis( description ); 0083 0084 m_mainLabel->setBuddy( m_mainEdit ); 0085 m_midLabel->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter ); 0086 } 0087 0088 void 0089 PropertySliderWidget::onSliderChanged( int value ) //SLOT 0090 { 0091 QString newText; 0092 if( !m_property.valueLabels().isEmpty() && 0093 m_property.valueLabels().size() == qAbs( m_property.max() - m_property.min() ) + 1 ) 0094 newText = m_property.valueLabels().at( value - qMin( m_property.min(), m_property.max() ) ); 0095 else 0096 newText = QString::number( value ); 0097 0098 if( value == m_property.defaultValue().toInt() ) 0099 newText += i18n( " (recommended)" ); 0100 0101 m_midLabel->setText( newText ); 0102 } 0103 0104 QVariant 0105 PropertySliderWidget::value() const 0106 { 0107 return m_mainEdit->value(); 0108 } 0109 0110 } //namespace Transcoding