TrackControls.cpp 4.73 KB
Newer Older
1 2 3
/*****************************************************************************
 * TrackControls.cpp: Widget used to configure a track
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
4
 * Copyright (C) 2008-2010 VideoLAN
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * Authors: Ludovic Fauvet <etix@l0cal.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

23
#include "GraphicsTrack.h"
24
#include "EffectStack.h"
25
#include "TrackControls.h"
26
#include "TrackWorkflow.h"
27

28 29
#include "ui_TrackControls.h"

30
#include <QInputDialog>
31
#include <QSettings>
32

33
TrackControls::TrackControls( GraphicsTrack* track, QWidget *parent ) :
34 35 36
    QWidget( parent ),
    m_ui( new Ui::TrackControls ),
    m_track( track )
37
{
38 39 40 41 42 43 44
    QSettings   s( QSettings::UserScope, qApp->organizationName(), "timeline" );
    if ( track->mediaType() == Workflow::VideoTrack &&
         s.contains( "video" + QString::number( track->trackNumber() ) ) )
        m_title = s.value( "video" + QString::number( track->trackNumber() ) ).toString();
    else if ( track->mediaType() == Workflow::AudioTrack &&
                s.contains( "audio" + QString::number( track->trackNumber() ) ) )
        m_title = s.value( "audio" + QString::number( track->trackNumber() ) ).toString();
45

46
    m_ui->setupUi( this );
47 48
    if ( track->mediaType() != Workflow::VideoTrack )
        m_ui->fxButton->hide();
Ludovic Fauvet's avatar
Ludovic Fauvet committed
49
    setTrackDisabled( !m_track->isEnabled() );
50 51
    connect( m_ui->disableButton, SIGNAL( clicked(bool) ),
             this, SLOT( setTrackDisabled(bool) ) );
52 53
    connect( m_ui->trackLabel, SIGNAL( doubleClicked() ),
             this, SLOT( trackNameDoubleClicked() ) );
54
    connect( m_ui->fxButton, SIGNAL( clicked() ), this, SLOT( fxButtonClicked() ) );
55
    updateTextLabels();
56 57 58 59 60 61 62
}

TrackControls::~TrackControls()
{
    delete m_ui;
}

63 64
void
TrackControls::updateTextLabels()
65
{
66
    if ( m_track->mediaType() == Workflow::VideoTrack )
67 68 69 70 71 72
    {
        if ( m_title.isEmpty() == true )
            m_ui->trackLabel->setText( tr( "Video #%1" ).arg( QString::number( m_track->trackNumber() + 1 ) ) );
        else
            m_ui->trackLabel->setText( m_title );
    }
73
    else if ( m_track->mediaType() == Workflow::AudioTrack )
74 75 76 77 78 79
    {
        if ( m_title.isEmpty() )
            m_ui->trackLabel->setText( tr( "Audio #%1" ).arg( QString::number( m_track->trackNumber() + 1 ) ) );
        else
            m_ui->trackLabel->setText( m_title );
    }
80 81
}

82 83
void
TrackControls::changeEvent( QEvent *e )
84 85 86 87 88
{
    QWidget::changeEvent( e );
    switch ( e->type() ) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi( this );
89
        updateTextLabels();
90 91 92 93 94 95
        break;
    default:
        break;
    }
}

96 97
void
TrackControls::setTrackDisabled( bool disable )
98 99 100 101
{
    m_track->setTrackEnabled( !disable );
    if ( !disable )
    {
102
        if ( m_track->mediaType() == Workflow::VideoTrack )
103
            m_ui->disableButton->setIcon( QIcon( ":/images/trackon" ) );
104
        else if ( m_track->mediaType() == Workflow::AudioTrack )
105 106 107 108
            m_ui->disableButton->setIcon( QIcon( ":/images/hpon" ) );
    }
    else
    {
109
        if ( m_track->mediaType() == Workflow::VideoTrack )
110
            m_ui->disableButton->setIcon( QIcon( ":/images/trackoff" ) );
111
        else if ( m_track->mediaType() == Workflow::AudioTrack )
112 113 114
            m_ui->disableButton->setIcon( QIcon( ":/images/hpoff" ) );
    }
}
115 116 117 118 119 120 121

void
TrackControls::trackNameDoubleClicked()
{
    QString     name = QInputDialog::getText( NULL, tr( "Rename track" ),
                                              tr( "Enter the track new name") );
    if ( name.isEmpty() == false )
122 123 124 125 126 127 128 129 130
    {
        QSettings   s( QSettings::UserScope, qApp->organizationName(), "timeline" );
        m_title = name;
        if ( m_track->mediaType() == Workflow::VideoTrack )
            s.setValue("video" + QString::number( m_track->trackNumber() ), name );
        else
            s.setValue("audio" + QString::number( m_track->trackNumber() ), name );
        updateTextLabels();
    }
131
}
132 133 134 135

void
TrackControls::fxButtonClicked()
{
136
    EffectStack *stack = new EffectStack( m_track->trackWorkflow(), this );
137 138
    stack->show();
}