kivio

kivio_spawner_drag.cpp

00001 /*
00002  * Kivio - Visual Modelling and Flowcharting
00003  * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 #include "kivio_spawner_drag.h"
00020 
00021 #include "kivio_stencil_spawner.h"
00022 #include "kivio_stencil_spawner_info.h"
00023 #include "kivio_stencil_spawner_set.h"
00024 #include "kivio_icon_view.h"
00025 
00026 #include <kdebug.h>
00027 
00028 KivioSpawnerDrag::KivioSpawnerDrag( KivioIconView *view, QWidget *parent, const char *name )
00029     : QIconDrag( parent, name )
00030 {
00031     m_pView = view;
00032 }
00033 
00034 KivioSpawnerDrag::~KivioSpawnerDrag()
00035 {
00036     m_pView->clearCurrentDrag();
00037     kdDebug(43000) << "KivioSpawnerDrag - this destroyed" << endl;
00038 }
00039 
00040 const char *KivioSpawnerDrag::format( int i ) const
00041 {
00042     if( i==0 )
00043         return "application/x-qiconlist";
00044     else if( i==1 )
00045         return "kivio/stencilSpawner";
00046     else
00047         return 0L;
00048 }
00049 
00050 QByteArray KivioSpawnerDrag::encodedData( const char *mime ) const
00051 {
00052     QByteArray a;
00053 
00054     if( QString(mime) == "application/x-qiconlist" )
00055     {
00056         a = QIconDrag::encodedData(mime);
00057     }
00058     else if( QString(mime) == "kivio/stencilSpawner" )
00059     {
00060         QString s = m_spawners.join("\r\n");
00061         a.resize(s.length());
00062         memcpy( a.data(), s.latin1(), s.length() );
00063     }
00064 
00065     return a;
00066 }
00067 
00068 bool KivioSpawnerDrag::canDecode( QMimeSource *e )
00069 {
00070     return e->provides( "application/x-qiconlist" ) ||
00071            e->provides( "kivio/stencilSpawner" );
00072 }
00073 
00074 void KivioSpawnerDrag::append( const QIconDragItem &item, const QRect &pr,
00075             const QRect &tr, KivioStencilSpawner &spawner )
00076 {
00077     QIconDrag::append( item, pr, tr );
00078 
00079     QString full = spawner.set()->dir() + "/" + spawner.info()->title();
00080     
00081     kdDebug(43000) << "KivioSpawnerDrag::append() - Adding " << full << endl;
00082 
00083     m_spawners << full;
00084 }
KDE Home | KDE Accessibility Home | Description of Access Keys