InstrumentView: added generic DnD support, renamed/splitted files

Added generic drag'n'drop support for all instrument views. All
resources supported by the according instrument now can be dropped
onto instrument view without any extra code in actual instrument.

Additionally renamed some files and classes related to InstrumentView
class to match new style.

Signed-off-by: Tobias Doerffel <tobias.doerffel@gmail.com>
This commit is contained in:
Tobias Doerffel
2009-06-30 01:19:48 +02:00
parent 65668f9489
commit f943df139e
35 changed files with 251 additions and 380 deletions

View File

@@ -1,9 +1,7 @@
#ifndef SINGLE_SOURCE_COMPILE
/*
* instrument.cpp - base-class for all instrument-plugins (synths, samplers etc)
*
* Copyright (c) 2005-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2005-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -26,9 +24,8 @@
#include "instrument.h"
#include "instrument_view.h"
#include "instrument_track.h"
#include "dummy_instrument.h"
#include "DummyInstrument.h"
#include "note_play_handle.h"
#include "embed.h"
@@ -66,7 +63,7 @@ void instrument::deleteNotePluginData( notePlayHandle * )
f_cnt_t instrument::beatLen( notePlayHandle * ) const
{
return( 0 );
return 0;
}
@@ -81,12 +78,12 @@ instrument * instrument::instantiate( const QString & _plugin_name,
if( dynamic_cast<instrument *>( p ) != NULL )
{
// everything ok, so return pointer
return( dynamic_cast<instrument *>( p ) );
return dynamic_cast<instrument *>( p );
}
// not quite... so delete plugin and return dummy instrument
delete p;
return( new dummyInstrument( _instrument_track ) );
return new DummyInstrument( _instrument_track );
}
@@ -94,7 +91,7 @@ instrument * instrument::instantiate( const QString & _plugin_name,
bool instrument::isFromTrack( const track * _track ) const
{
return( m_instrumentTrack == _track );
return m_instrumentTrack == _track;
}
@@ -129,52 +126,3 @@ QString instrument::fullDisplayName( void ) const
}
instrumentView::instrumentView( instrument * _instrument, QWidget * _parent ) :
pluginView( _instrument, _parent )
{
setModel( _instrument );
setFixedSize( 250, 250 );
setAttribute( Qt::WA_DeleteOnClose, TRUE );
}
instrumentView::~instrumentView()
{
if( getInstrumentTrackWindow() )
{
getInstrumentTrackWindow()->m_instrumentView = NULL;
}
}
void instrumentView::setModel( ::model * _model, bool )
{
if( dynamic_cast<instrument *>( _model ) != NULL )
{
modelView::setModel( _model );
getInstrumentTrackWindow()->setWindowIcon(
model()->getDescriptor()->logo->pixmap() );
connect( model(), SIGNAL( destroyed( QObject * ) ),
this, SLOT( close() ) );
}
}
instrumentTrackWindow * instrumentView::getInstrumentTrackWindow( void )
{
return( dynamic_cast<instrumentTrackWindow *>(
parentWidget()->parentWidget() ) );
}
#endif

116
src/gui/InstrumentView.cpp Normal file
View File

@@ -0,0 +1,116 @@
/*
* InstrumentView.cpp - base-class for views of all instruments
*
* Copyright (c) 2008-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* 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 (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include "InstrumentView.h"
#include "embed.h"
#include "instrument.h"
#include "instrument_track.h"
#include "ResourceDB.h"
#include "string_pair_drag.h"
#include "UnifiedResourceProvider.h"
InstrumentView::InstrumentView( instrument * _instrument, QWidget * _parent ) :
pluginView( _instrument, _parent )
{
setModel( _instrument );
setFixedSize( 250, 250 );
setAttribute( Qt::WA_DeleteOnClose, true );
setAcceptDrops( true );
}
InstrumentView::~InstrumentView()
{
if( getInstrumentTrackWindow() )
{
getInstrumentTrackWindow()->m_instrumentView = NULL;
}
}
void InstrumentView::setModel( ::model * _model, bool )
{
if( dynamic_cast<instrument *>( _model ) != NULL )
{
modelView::setModel( _model );
getInstrumentTrackWindow()->setWindowIcon(
model()->getDescriptor()->logo->pixmap() );
connect( model(), SIGNAL( destroyed( QObject * ) ),
this, SLOT( close() ) );
}
}
instrumentTrackWindow * InstrumentView::getInstrumentTrackWindow( void )
{
return dynamic_cast<instrumentTrackWindow *>(
parentWidget()->parentWidget() );
}
void InstrumentView::dragEnterEvent( QDragEnterEvent * _dee )
{
if( stringPairDrag::decodeKey( _dee ) == ResourceItem::mimeKey() )
{
const ResourceItem * item =
engine::resourceProvider()->database()->
itemByHash( stringPairDrag::decodeValue( _dee ) );
if( item &&
model()->getDescriptor()->supportsFileType(
item->nameExtension() ) )
{
_dee->acceptProposedAction();
}
}
}
void InstrumentView::dropEvent( QDropEvent * _de )
{
if( stringPairDrag::decodeKey( _de ) == ResourceItem::mimeKey() )
{
const ResourceItem * item =
engine::resourceProvider()->database()->
itemByHash( stringPairDrag::decodeValue( _de ) );
model()->loadResource( item );
_de->accept();
}
}