QSapecNG
 All Classes Functions Enumerations Properties
extendedmdiarea.h
00001 /*
00002     QSapecNG - Qt based SapecNG GUI front-end
00003     Copyright (C) 2009, Michele Caini
00004 
00005     This program is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation, either version 3 of the License, or
00008     (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, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 
00020 #ifndef EXTENDEDMDIAREA_H
00021 #define EXTENDEDMDIAREA_H
00022 
00023 
00024 #include <QtGui/QMdiArea>
00025 
00026 #include <QtGui/QDragEnterEvent>
00027 #include <QtGui/QDropEvent>
00028 #include <QtCore/QMimeData>
00029 
00030 #include <QtCore/QList>
00031 #include <QtCore/QFile>
00032 #include <QtCore/QUrl>
00033 
00034 
00035 namespace qsapecng
00036 {
00037 
00038 
00039 
00040 class ExtendedMdiArea: public QMdiArea
00041 {
00042 
00043   Q_OBJECT
00044 
00045 public:
00046   ExtendedMdiArea(QWidget* parent = 0): QMdiArea(parent)
00047     { setAcceptDrops(true); }
00048 
00049 signals:
00050   void dropFileEvent(const QString& fileName);
00051 
00052 protected:
00053   void dragEnterEvent(QDragEnterEvent* event)
00054   {
00055     if(event->mimeData()->hasUrls())
00056       event->accept();
00057   }
00058 
00059 
00060   void dropEvent(QDropEvent* event)
00061   {
00062     if(event->mimeData()->hasUrls()
00063         && event->proposedAction() == Qt::CopyAction)
00064     {
00065       QList<QUrl> urls = event->mimeData()->urls();
00066       foreach(QUrl url, urls) {
00067         QString file = url.toLocalFile();
00068         if(QFile::exists(file))
00069           emit dropFileEvent(file);
00070       }
00071 
00072       event->acceptProposedAction();
00073     }
00074   }
00075 
00076 };
00077 
00078 
00079 
00080 }
00081 
00082 
00083 #endif // EXTENDEDMDIAREA_H
 All Classes Functions Enumerations Properties