UNNAMED_READER/corelibrary
dropObserver.cpp
Go to the documentation of this file.00001 /*************************************************************************** 00002 * Copyright (C) 2006 by Stefan Kebekus <kebekus@kde.org> * 00003 * * 00004 * This program is free software; you can redistribute it and/or modify * 00005 * it under the terms of the GNU General Public License as published by * 00006 * the Free Software Foundation; either version 2 of the License, or * 00007 * (at your option) any later version. * 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 * 00012 * GNU General Public License for more details. * 00013 * * 00014 * You should have received a copy of the GNU General Public License * 00015 * along with this program; if not, write to the * 00016 * Free Software Foundation, Inc., * 00017 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00018 ***************************************************************************/ 00019 00020 00021 #include <config.h> 00022 00023 #include "dropObserver.h" 00024 #include "fileFormats.h" 00025 #include "UNNAMED_READER_debug.h" 00026 00027 #include <kurl.h> 00028 #include <QDropEvent> 00029 #include <QMetaObject> 00030 #include <QWidget> 00031 00032 00033 #define UNNAMED_READER_DEBUG 0 00034 00035 00036 namespace UNNAMED_READER { 00037 00038 00039 dropObserver::dropObserver(QWidget *myWdg) 00040 { 00041 kDebug(UNNAMED_READER_DEBUG, shell) << "dropObserver::dropObserver(..)" << endl; 00042 00043 // Accept drops 00044 myWdg->setAcceptDrops(true); 00045 00046 myWidget = myWdg; 00047 } 00048 00049 00050 void dropObserver::dragEnterEvent(QDragEnterEvent* event) 00051 { 00052 kDebug(UNNAMED_READER_DEBUG, shell) << "dropObserver::dragEnterEvent(...)" << endl; 00053 00054 if (!event->mimeData()->hasUrls()) 00055 return; 00056 00057 // Go through the list of URLs and check if one of them looks like a 00058 // URL that we would accept (we accept all non-local URLs) 00059 QList<QUrl> list = event->mimeData()->urls(); 00060 for(int i=0; i<list.count(); i++) { 00061 if (!fileFormats::UrlQuickCheckForSupportedFormat(list.at(i))) 00062 continue; 00063 00064 event->setDropAction(Qt::CopyAction); 00065 event->accept(); 00066 return; 00067 }// Go through the list of files 00068 00069 return; 00070 } 00071 00072 00073 void dropObserver::dropEvent(QDropEvent* event) 00074 { 00075 kDebug(UNNAMED_READER_DEBUG, shell) << "dropObserver::dropEvent(...)" << endl; 00076 00077 if (!event->mimeData()->hasUrls()) 00078 return; 00079 00080 // Go through the list of URLs and check if one of them looks like a 00081 // URL that we would accept (we accept all non-local URLs) 00082 QList<QUrl> list = event->mimeData()->urls(); 00083 for(int i=0; i<list.count(); i++) { 00084 if (!fileFormats::UrlQuickCheckForSupportedFormat(list.at(i))) 00085 continue; 00086 00087 // Check if this object is child of a mainWindow. Store the 00088 // mainWindow in the mainWin pointer 00089 QObject *ptr=myWidget; 00090 while((ptr!=0) && (!ptr->inherits("UNNAMED_READER::mainWindow"))) 00091 ptr = ptr->parent(); 00092 if (ptr == 0) 00093 return; 00094 00095 QMetaObject::invokeMethod(ptr, "openUrl", Q_ARG(KUrl, (KUrl)list.at(i))); 00096 return; 00097 }// Go through the list of files 00098 00099 return; 00100 } 00101 00102 00103 } // namespace UNNAMED_READER 00104
KDE 4.2 API Reference