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>
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"
35 #include "MainWindow.h"
38 stringPairDrag::stringPairDrag( const QString
& _key
, const QString
& _value
,
39 const QPixmap
& _icon
, QWidget
* _w
) :
42 if( _icon
.isNull() && _w
)
44 setPixmap( QPixmap::grabWidget( _w
).scaled(
47 Qt::SmoothTransformation
) );
53 QString txt
= _key
+ ":" + _value
;
54 QMimeData
* m
= new QMimeData();
55 m
->setData( mimeType(), txt
.toAscii() );
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() ) )
83 QString txt
= _dee
->mimeData()->data( mimeType() );
84 if( _allowed_keys
.split( ',' ).contains( txt
.section( ':', 0, 0 ) ) )
86 _dee
->acceptProposedAction();
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 ) );