From 0c73c5bb1742629a83176ec0a9be1e5219924552 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Mon, 22 Jun 2009 23:42:15 +0200 Subject: [PATCH] StringPairDrag: added static createMimeData() method Added createMimeData() method to StringPairDrag which creates a proper QMimeData object for StringPairDrag. External code can use it to create a QMimeData object which can be received by users of StringPairDrag. Signed-off-by: Tobias Doerffel --- include/string_pair_drag.h | 7 +++++-- src/gui/string_pair_drag.cpp | 34 ++++++++++++++++++++++------------ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/include/string_pair_drag.h b/include/string_pair_drag.h index 5a3316e6e..0fc88a4f4 100644 --- a/include/string_pair_drag.h +++ b/include/string_pair_drag.h @@ -2,7 +2,7 @@ * string_pair_drag.h - class stringPairDrag which provides general support * for drag'n'drop of string-pairs * - * Copyright (c) 2005-2007 Tobias Doerffel + * Copyright (c) 2005-2009 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -42,6 +42,9 @@ public: const QPixmap & _icon, QWidget * _w ); ~stringPairDrag(); + static QMimeData * createMimeData( const QString & _key, + const QString & _value ); + static bool processDragEnterEvent( QDragEnterEvent * _dee, const QString & _allowed_keys ); static QString decodeKey( QDropEvent * _de ); @@ -49,7 +52,7 @@ public: static const char * mimeType( void ) { - return( "application/x-lmms-stringpair" ); + return "application/x-lmms-stringpair"; } } ; diff --git a/src/gui/string_pair_drag.cpp b/src/gui/string_pair_drag.cpp index 63c4058b0..3a2bdfe58 100644 --- a/src/gui/string_pair_drag.cpp +++ b/src/gui/string_pair_drag.cpp @@ -5,7 +5,7 @@ * for drag'n'drop of string-pairs and which is the base * for all drag'n'drop-actions within LMMS * - * Copyright (c) 2005-2008 Tobias Doerffel + * Copyright (c) 2005-2009 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -52,10 +52,7 @@ stringPairDrag::stringPairDrag( const QString & _key, const QString & _value, { setPixmap( _icon ); } - QString txt = _key + ":" + _value; - QMimeData * m = new QMimeData(); - m->setData( mimeType(), txt.toAscii() ); - setMimeData( m ); + setMimeData( createMimeData( _key, _value ) ); start( Qt::IgnoreAction ); } @@ -75,21 +72,34 @@ stringPairDrag::~stringPairDrag() +QMimeData * stringPairDrag::createMimeData( const QString & _key, + const QString & _value ) +{ + const QString txt = _key + ":" + _value; + QMimeData * m = new QMimeData(); + m->setData( mimeType(), txt.toUtf8() ); + + return m; +} + + + + bool stringPairDrag::processDragEnterEvent( QDragEnterEvent * _dee, const QString & _allowed_keys ) { if( !_dee->mimeData()->hasFormat( mimeType() ) ) { - return( FALSE ); + return false; } QString txt = _dee->mimeData()->data( mimeType() ); if( _allowed_keys.split( ',' ).contains( txt.section( ':', 0, 0 ) ) ) { _dee->acceptProposedAction(); - return( TRUE ); + return true; } _dee->ignore(); - return( FALSE ); + return false; } @@ -97,8 +107,8 @@ bool stringPairDrag::processDragEnterEvent( QDragEnterEvent * _dee, QString stringPairDrag::decodeKey( QDropEvent * _de ) { - return( QString( _de->mimeData()->data( mimeType() - ) ).section( ':', 0, 0 ) ); + return QString( _de->mimeData()-> + data( mimeType() ) ).section( ':', 0, 0 ); } @@ -106,8 +116,8 @@ QString stringPairDrag::decodeKey( QDropEvent * _de ) QString stringPairDrag::decodeValue( QDropEvent * _de ) { - return( QString( _de->mimeData()->data( mimeType() - ) ).section( ':', 1, -1 ) ); + return QString( _de->mimeData()-> + data( mimeType() ) ).section( ':', 1, -1 ); }