TracksScene.cpp 4.41 KB
Newer Older
1 2 3
/*****************************************************************************
 * TracksScene.cpp: QGraphicsScene that contains the tracks
 *****************************************************************************
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 23
 *
 * 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.
 *****************************************************************************/

#include "TracksScene.h"
24

25
#include "Commands.h"
26 27
#include "ClipHelper.h"
#include "EffectHelper.h"
28
#include "GraphicsAudioItem.h"
29 30
#include "GraphicsMovieItem.h"
#include "GraphicsTrack.h"
31
#include "SettingsManager.h"
32
#include "Timeline.h"
33
#include "TrackWorkflow.h"
34
#include "UndoStack.h"
35

36 37 38
#include <QMessageBox>
#include <QKeyEvent>
#include <QGraphicsSceneContextMenuEvent>
39
#include <QPushButton>
40

41
TracksScene::TracksScene( QObject* parent ) : QGraphicsScene( parent )
42 43
{
}
44

45 46
void
TracksScene::keyPressEvent( QKeyEvent* keyEvent )
47 48 49 50 51 52 53 54 55 56
{
    TracksView* tv = Timeline::getInstance()->tracksView();
    if ( !tv ) return;

    if ( keyEvent->modifiers() == Qt::NoModifier &&
         keyEvent->key() == Qt::Key_Delete &&
         selectedItems().size() >= 1 )
    {
        // Items deletion
        keyEvent->accept();
57 58 59 60 61 62
        askRemoveSelectedItems();
    }

    QGraphicsScene::keyPressEvent( keyEvent );
}

63 64
void
TracksScene::contextMenuEvent( QGraphicsSceneContextMenuEvent* event )
65 66 67 68 69 70 71 72
{
    QGraphicsScene::contextMenuEvent( event );
    if ( event->isAccepted() )
        return; // Event handled by an item in the scene.

    //TODO Event not handled, create and show a menu here.
}

73 74
void
TracksScene::askRemoveSelectedItems()
75 76
{
    TracksView* tv = Timeline::getInstance()->tracksView();
77

78 79 80 81
    if ( !tv )
        return;
    if ( tv->currentAction() != TracksView::None )
        return ;
82

83 84 85 86 87 88 89 90
    if ( VLMC_GET_BOOL( "general/ConfirmDeletion" ) == true )
    {
        QString message;
        if ( selectedItems().size() == 1 )
            message = tr("Confirm the deletion of the region?");
        else
            message = tr("Confirm the deletion of those regions?");

91 92 93 94 95 96 97 98 99 100 101 102 103
        QMessageBox msgBox;
        msgBox.setText( message );
        msgBox.addButton( tr( "Yes" ), QMessageBox::YesRole );
        QAbstractButton     *always = msgBox.addButton( tr( "Yes, don't ask me again" ),
                                                        QMessageBox::YesRole );
        QAbstractButton     *no = msgBox.addButton( tr( "No" ), QMessageBox::NoRole );
        msgBox.exec();
        QAbstractButton*    clicked = msgBox.clickedButton();

        if ( clicked == no )
            return ;
        if ( clicked == always )
        {
104 105
            SettingsManager::getInstance()->setValue( "general/ConfirmDeletion",
                                                       false, SettingsManager::Vlmc );
106
        }
107
    }
108

109
    UndoStack::getInstance()->beginMacro( "Remove clip(s)" );
110

111 112 113
    QList<QGraphicsItem*> items = selectedItems();
    for (int i = 0; i < items.size(); ++i )
    {
114 115 116
        AbstractGraphicsItem* item = dynamic_cast<AbstractGraphicsItem*>( items.at(i) );
        if ( !item )
            return;
117 118 119 120 121 122

        /*FIXME: When undo-ing linked items no longer remain linked*/
        AbstractGraphicsItem* linked_item = item->groupItem();
        if (linked_item != NULL)
            items.append(linked_item);

123 124 125 126 127 128 129 130 131
        ClipHelper  *ch = qobject_cast<ClipHelper*>( item->helper() );
        if ( ch != NULL )
        {
            Commands::trigger( new Commands::Clip::Remove( ch, item->track()->trackWorkflow() ) );
        }
        else
        {
            EffectHelper    *eh = qobject_cast<EffectHelper*>( item->helper() );
            Q_ASSERT( eh != NULL );
132
            Commands::trigger( new Commands::Effect::Remove( eh, eh->target() ) );
133
        }
134 135
    }

136
    UndoStack::getInstance()->endMacro();
137
}