ClipProperty.cpp 4.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*****************************************************************************
 * ClipProperty.cpp: Handle the clip properties and meta tags edition
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
 * Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
 *
 * 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 24
#include <QtDebug>
#include <QTime>
25
#include <QPushButton>
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
26
#include <QInputDialog>
27

28 29
#include "ClipProperty.h"
#include "ui_ClipProperty.h"
30

31
ClipProperty::ClipProperty( Clip* clip, QWidget *parent ) :
32
    QDialog( parent ),
33
    ui( new Ui::ClipProperty ),
34
    m_clip( clip )
35 36
{
    QTime   duration;
37
    duration = duration.addSecs( m_clip->getLengthSecond() );
38 39 40 41

    ui->setupUi(this);
    connect( this, SIGNAL( accepted() ), this, SLOT( deleteLater() ) );
    connect( this, SIGNAL( rejected() ), this, SLOT( deleteLater() ) );
42
    //Duration
43
    ui->durationValueLabel->setText( duration.toString( "hh:mm:ss" ) );
44
    //Filename || title
45
    ui->nameValueLabel->setText( m_clip->getParent()->getFileInfo()->fileName() );
46 47
    setWindowTitle( m_clip->getParent()->getFileInfo()->fileName() + " " + tr( "properties" ) );
    //Resolution
48 49
    ui->resolutionValueLabel->setText( QString::number( m_clip->getParent()->getWidth() )
                                       + " x " + QString::number( m_clip->getParent()->getHeight() ) );
50
    //FPS
51
    ui->fpsValueLabel->setText( QString::number( m_clip->getParent()->getFps() ) );
52
    //Snapshot
53
    ui->snapshotLabel->setPixmap( m_clip->getParent()->getSnapshot().scaled( 128, 128, Qt::KeepAspectRatio ) );
54

55
    //Metatags
56 57 58 59
    const QPushButton* button = ui->buttonBox->button( QDialogButtonBox::Apply );
    Q_ASSERT( button != NULL);
    connect( button, SIGNAL( clicked() ), this, SLOT( apply() ) );

60 61
    m_model = new QStringListModel( m_clip->getMetaTags(), this );
    ui->metaTagsView->setModel( m_model );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
62

63 64 65
    //Notes:
    ui->annotationInput->setPlainText( m_clip->getNotes() );

66 67
    connect( ui->addTagsButton, SIGNAL( clicked() ), this, SLOT( addTagsRequired() ) );
    connect( ui->deleteTagsButton, SIGNAL( clicked() ), this, SLOT( removeTagsRequired() ) );
68 69
}

70
ClipProperty::~ClipProperty()
71 72 73 74
{
    delete ui;
}

75
void ClipProperty::changeEvent( QEvent *e )
76 77 78 79 80 81 82 83 84 85 86
{
    QDialog::changeEvent( e );
    switch ( e->type() )
    {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}
87

88
void    ClipProperty::apply()
89
{
90
    m_clip->setNotes( ui->annotationInput->toPlainText() );
91
    m_clip->setMetaTags( m_model->stringList() );
92
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
93

94
void    ClipProperty::addTagsRequired()
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
95 96 97 98 99 100 101
{
    bool                ok;
    QString             newTags = QInputDialog::getText( this, tr( "New tags edition" ),
                                            tr( "Enter tags (you can enter multiple tags, separated by a comma)" ),
                                            QLineEdit::Normal, "", &ok );
    if ( ok == true && newTags.length() > 0 )
    {
102
        QStringList         list = m_model->stringList();
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
103 104
        QStringList         toAdd = newTags.split( ",", QString::SkipEmptyParts );
        list.append( toAdd );
105
        m_model->setStringList( list );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
106 107
    }
}
108

109
void    ClipProperty::removeTagsRequired()
110 111 112
{
    QItemSelectionModel*    selected = ui->metaTagsView->selectionModel();
    QModelIndexList         listSelected = selected->selectedIndexes();
113
    QStringList             list = m_model->stringList();
114 115
    while ( listSelected.empty() == false )
    {
116
        QVariant    elem = m_model->data( listSelected.first(), Qt::DisplayRole );
117 118 119
        list.removeOne( elem.toString() );
        listSelected.removeFirst();
    }
120
    m_model->setStringList( list );
121
}