Renamed all automation related files and classes to match new coding style
[lmms.git] / src / gui / string_pair_drag.cpp
blob611421e99e94d88ea4e9f8e1cd0c69b44f59a4e5
1 /*
2 * string_pair_drag.cpp - class stringPairDrag which provides general support
3 * for drag'n'drop of string-pairs and which is the base
4 * for all drag'n'drop-actions within LMMS
6 * Copyright (c) 2005-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
7 *
8 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public
21 * License along with this program (see COPYING); if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301 USA.
28 #include <QtCore/QMimeData>
29 #include <QtGui/QDragEnterEvent>
30 #include <QtGui/QDropEvent>
33 #include "string_pair_drag.h"
34 #include "engine.h"
35 #include "MainWindow.h"
38 stringPairDrag::stringPairDrag( const QString & _key, const QString & _value,
39 const QPixmap & _icon, QWidget * _w ) :
40 QDrag( _w )
42 if( _icon.isNull() && _w )
44 setPixmap( QPixmap::grabWidget( _w ).scaled(
45 64, 64,
46 Qt::KeepAspectRatio,
47 Qt::SmoothTransformation ) );
49 else
51 setPixmap( _icon );
53 QString txt = _key + ":" + _value;
54 QMimeData * m = new QMimeData();
55 m->setData( mimeType(), txt.toAscii() );
56 setMimeData( m );
57 start( Qt::IgnoreAction );
63 stringPairDrag::~stringPairDrag()
65 // during a drag, we might have lost key-press-events, so reset
66 // modifiers of main-win
67 if( engine::mainWindow() )
69 engine::mainWindow()->clearKeyModifiers();
76 bool stringPairDrag::processDragEnterEvent( QDragEnterEvent * _dee,
77 const QString & _allowed_keys )
79 if( !_dee->mimeData()->hasFormat( mimeType() ) )
81 return( FALSE );
83 QString txt = _dee->mimeData()->data( mimeType() );
84 if( _allowed_keys.split( ',' ).contains( txt.section( ':', 0, 0 ) ) )
86 _dee->acceptProposedAction();
87 return( TRUE );
89 _dee->ignore();
90 return( FALSE );
96 QString stringPairDrag::decodeKey( QDropEvent * _de )
98 return( QString( _de->mimeData()->data( mimeType()
99 ) ).section( ':', 0, 0 ) );
105 QString stringPairDrag::decodeValue( QDropEvent * _de )
107 return( QString( _de->mimeData()->data( mimeType()
108 ) ).section( ':', 1, -1 ) );