# kdecore Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kmultipledrag.cpp

    00001 /* This file is part of the KDE project
    00002    Copyright (C) 2001 David Faure <faure@kde.org>
    00003
    00004    This program is free software; you can redistribute it and/or
    00005    modify it under the terms of the GNU Library General Public
    00006    License as published by the Free Software Foundation; either
    00007    version 2 of the License.
    00008
    00009    This program is distributed in the hope that it will be useful,
    00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012    Library General Public License for more details.
    00013
    00014    You should have received a copy of the GNU Library General Public License
    00015    along with this program; see the file COPYING.  If not, write to
    00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00017    Boston, MA 02111-1307, USA.
    00018 */
    00019
    00020 #include "kmultipledrag.h"
    00021 #include "kdebug.h"
    00022
    00023 #ifndef QT_NO_DRAGANDDROP
    00024
    00025 KMultipleDrag::KMultipleDrag( QWidget *dragSource, const char *name )
    00026     : QDragObject( dragSource, name )
    00027 {
    00028     m_dragObjects.setAutoDelete( true );
    00029 }
    00030
    00031 void KMultipleDrag::addDragObject( QDragObject *dragObject )
    00032 {
    00033     //kdDebug() << "KMultipleDrag::addDragObject" << endl;
    00034     m_dragObjects.append( dragObject );
    00035     // We need to find out how many formats this dragObject supports
    00036     int i = 0;
    00037     while ( dragObject->format( i ) )
    00038         ++i;
    00039     m_numberFormats.append( i ); // e.g. if it supports two formats, 0 and 1, store 2.
    00040 }
    00041
    00042 QByteArray KMultipleDrag::encodedData( const char *mime ) const
    00043 {
    00044     //kdDebug() << "KMultipleDrag::encodedData " << mime << endl;
    00045     // Iterate over the drag objects, and find the format in the right one
    00046     QPtrListIterator<QDragObject> it( m_dragObjects );
    00047     for ( ; it.current(); ++it )
    00048     {
    00049         for ( int i = 0; it.current()->format( i ); ++i )
    00050         {
    00051             if ( ::qstrcmp( it.current()->format( i ), mime ) == 0 )
    00052                 return it.current()->encodedData( mime );
    00053         }
    00054     }
    00055     return QByteArray();
    00056 }
    00057
    00058 const char* KMultipleDrag::format( int i ) const
    00059 {
    00060     //kdDebug() << "KMultipleDrag::format " << i << endl;
    00061     // example: m_numberFormats: 1, 4
    00062     //          m_dragObjects: storeddrag, textdrag
    00063     // i=0 -> storeddrag->format( 0 )
    00064     // i=1 -> textdrag->format( 0 )
    00065     // i=2 -> textdrag->format( 1 )
    00066     // etc.
    00067     QValueList<int>::ConstIterator nit = m_numberFormats.begin();
    00068     QValueList<int>::ConstIterator nend = m_numberFormats.end();
    00069     QPtrListIterator<QDragObject> it( m_dragObjects );
    00070     for ( ; nit != nend && i >= *nit ; ++nit, ++it )
    00071         i -= *nit;
    00072     if ( it.current() )
    00073         return it.current()->format( i );
    00074     return 0;
    00075 }
    00076
    00077 void KMultipleDrag::virtual_hook( int, void* )
    00078 { /*BASE::virtual_hook( id, data );*/ }
    00079
    00080 #include "kmultipledrag.moc"
    00081
    00082 #endif

This file is part of the documentation for kdecore Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:18:09 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003