File indexing completed on 2024-05-05 04:51:40

0001 /*
0002     SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "k3baudiodatasourceeditwidget.h"
0007 #include "k3baudioeditorwidget.h"
0008 #include "k3bmsfedit.h"
0009 
0010 #include "k3baudiodatasource.h"
0011 
0012 #include <KLocalizedString>
0013 
0014 #include <QLayout>
0015 #include <QLabel>
0016 #include <QToolTip>
0017 #include <QGridLayout>
0018 
0019 
0020 K3b::AudioDataSourceEditWidget::AudioDataSourceEditWidget( QWidget* parent )
0021     : QWidget( parent ),
0022       m_source(0)
0023 {
0024     m_editor = new K3b::AudioEditorWidget( this );
0025     m_editStartOffset = new K3b::MsfEdit( this );
0026     m_editEndOffset = new K3b::MsfEdit( this );
0027 
0028     QLabel* startLabel = new QLabel( i18n("Start Offset:"), this );
0029     QLabel* endLabel = new QLabel( i18n("End Offset:"), this );
0030     endLabel->setAlignment( Qt::AlignRight );
0031 
0032     QGridLayout* grid = new QGridLayout( this );
0033     grid->setContentsMargins( 0, 0, 0, 0 );
0034 
0035     grid->addWidget( startLabel, 0, 0 );
0036     grid->addWidget( m_editStartOffset, 1, 0 );
0037     grid->addWidget( m_editor, 0, 1, 2, 1 );
0038     grid->addWidget( endLabel, 0, 2 );
0039     grid->addWidget( m_editEndOffset, 1, 2 );
0040     grid->setColumnStretch( 1, 1 );
0041 
0042     // setup connections between the msfedits and the editor
0043     connect( m_editor, SIGNAL(rangeChanged(int,K3b::Msf,K3b::Msf)),
0044              this, SLOT(slotRangeModified(int,K3b::Msf,K3b::Msf)) );
0045 
0046     connect( m_editStartOffset, SIGNAL(valueChanged(K3b::Msf)),
0047              this, SLOT(slotStartOffsetEdited(K3b::Msf)) );
0048 
0049     connect( m_editEndOffset, SIGNAL(valueChanged(K3b::Msf)),
0050              this, SLOT(slotEndOffsetEdited(K3b::Msf)) );
0051 
0052     m_editor->setToolTip( i18n("Drag the edges of the highlighted area to define the portion of the "
0053                                "audio source you want to include in the Audio CD track. "
0054                                "You can also use the input windows to fine-tune your selection.") );
0055 }
0056 
0057 
0058 K3b::AudioDataSourceEditWidget::~AudioDataSourceEditWidget()
0059 {
0060 }
0061 
0062 
0063 K3b::Msf K3b::AudioDataSourceEditWidget::startOffset() const
0064 {
0065     return m_editor->rangeStart( m_rangeId );
0066 }
0067 
0068 
0069 K3b::Msf K3b::AudioDataSourceEditWidget::endOffset() const
0070 {
0071     return m_editor->rangeEnd( m_rangeId );
0072 }
0073 
0074 
0075 void K3b::AudioDataSourceEditWidget::loadSource( K3b::AudioDataSource* source )
0076 {
0077     m_source = source;
0078 
0079     // remove old range
0080     m_editor->removeRange( m_rangeId );
0081 
0082     // and add the proper new range
0083     // the source's end offset points after the last sector while
0084     // the editor widget returns the last used sector
0085     m_editor->setLength( source->originalLength() );
0086     m_rangeId = m_editor->addRange( source->startOffset(),
0087                                     source->endOffset() == 0
0088                                     ? source->originalLength()-1
0089                                     : source->endOffset()-1,
0090                                     false,
0091                                     false,
0092                                     i18n("Used part of the audio source"),
0093                                     palette().highlight() );
0094 
0095     m_editStartOffset->setMaximum( source->originalLength() );
0096     m_editEndOffset->setMaximum( source->originalLength() );
0097 
0098     m_editStartOffset->setValue( startOffset() );
0099     m_editEndOffset->setValue( endOffset() );
0100 }
0101 
0102 
0103 void K3b::AudioDataSourceEditWidget::saveSource()
0104 {
0105     if( m_source ) {
0106         m_source->setStartOffset( startOffset() );
0107         // the source's end offset points after the last sector while
0108         // the editor widget returns the last used sector
0109         m_source->setEndOffset( endOffset()+1 );
0110     }
0111 }
0112 
0113 
0114 void K3b::AudioDataSourceEditWidget::setStartOffset( const K3b::Msf& msf )
0115 {
0116     if( m_source ) {
0117         m_editor->modifyRange( m_rangeId,
0118                                msf,
0119                                endOffset() );
0120     }
0121 }
0122 
0123 
0124 void K3b::AudioDataSourceEditWidget::setEndOffset( const K3b::Msf& msf )
0125 {
0126     if( m_source ) {
0127         m_editor->modifyRange( m_rangeId,
0128                                startOffset(),
0129                                msf );
0130     }
0131 }
0132 
0133 
0134 void K3b::AudioDataSourceEditWidget::slotRangeModified( int, const K3b::Msf& start, const K3b::Msf& end )
0135 {
0136     m_editStartOffset->setValue( start );
0137     m_editEndOffset->setValue( end );
0138 }
0139 
0140 void K3b::AudioDataSourceEditWidget::slotStartOffsetEdited( const K3b::Msf& msf )
0141 {
0142     if( m_source ) {
0143         m_editor->modifyRange( m_rangeId, msf, endOffset() );
0144     }
0145 }
0146 
0147 
0148 void K3b::AudioDataSourceEditWidget::slotEndOffsetEdited( const K3b::Msf& msf )
0149 {
0150     if( m_source ) {
0151         m_editor->modifyRange( m_rangeId, startOffset(), msf );
0152     }
0153 }
0154 
0155 #include "moc_k3baudiodatasourceeditwidget.cpp"