ClipProperty.cpp 4.04 KB
Newer Older
1 2 3
/*****************************************************************************
 * ClipProperty.cpp: Handle the clip properties and meta tags edition
 *****************************************************************************
4
 * Copyright (C) 2008-2016 VideoLAN
5
 *
6
 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * 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 25 26
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

27
#include "ClipProperty.h"
28
#include "ui/ClipProperty.h"
29

30 31
#include "Media/Clip.h"
#include "Media/Media.h"
32 33

#include "Gui/media/ClipMetadataDisplayer.h"
34 35

#include <QInputDialog>
36
#include <QPushButton>
37
#include <QRegExp>
38

39
ClipProperty::ClipProperty( Clip* clip, QWidget *parent ) :
40
    QDialog( parent ),
41
    ui( new Ui::ClipProperty ),
42
    m_clip( clip )
43 44 45 46
{
    ui->setupUi(this);
    connect( this, SIGNAL( accepted() ), this, SLOT( deleteLater() ) );
    connect( this, SIGNAL( rejected() ), this, SLOT( deleteLater() ) );
47

48
    setWindowTitle( m_clip->media()->title() + " " + tr( "properties" ) );
49
    //Snapshot
50 51
    QPixmap snapshot( m_clip->media()->snapshot() );
    ui->snapshotLabel->setPixmap( snapshot.scaled( 128, 128, Qt::KeepAspectRatio ) );
52
    //Metatags
53
    const QPushButton* button = ui->buttonBox->button( QDialogButtonBox::Apply );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
54
    Q_ASSERT( button != nullptr);
55 56
    connect( button, SIGNAL( clicked() ), this, SLOT( apply() ) );

57
    m_model = new QStringListModel( m_clip->metaTags(), this );
58
    ui->metaTagsView->setModel( m_model );
59

60
    //Notes:
61
    ui->annotationInput->setPlainText( m_clip->notes() );
62

63 64
    connect( ui->addTagsButton, SIGNAL( clicked() ), this, SLOT( addTagsRequired() ) );
    connect( ui->deleteTagsButton, SIGNAL( clicked() ), this, SLOT( removeTagsRequired() ) );
65

66
    ui->metadataContainer->setWatchedClip( clip );
67 68
}

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

74 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 89
void
ClipProperty::apply()
90
{
91
    m_clip->setNotes( ui->annotationInput->toPlainText() );
92
    m_clip->setMetaTags( m_model->stringList() );
93
}
94

95 96
void
ClipProperty::addTagsRequired()
97 98 99 100 101 102 103
{
    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 )
    {
104
        QStringList         list = m_model->stringList();
105 106
        QRegExp             regexp( "\\s*,\\s*" );
        QStringList         toAdd = newTags.split( regexp, QString::SkipEmptyParts );
107
        list.append( toAdd );
108
        m_model->setStringList( list );
109 110
    }
}
111

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