ImageDropWidget.cpp
Go to the documentation of this file.
00001 /*
00002  * ImageDropWidget.cpp
00003  *
00004  *  Created on: Dec 22, 2014
00005  *      Author: mathieu
00006  */
00007 
00008 #include <ImageDropWidget.h>
00009 #include <find_object/Settings.h>
00010 #include <QtGui/QDragEnterEvent>
00011 #include <QtCore/QRegExp>
00012 #include <QtCore/QUrl>
00013 
00014 namespace find_object {
00015 
00016 ImageDropWidget::ImageDropWidget(QWidget *parent, Qt::WindowFlags flags) :
00017                 QWidget(parent, flags)
00018 {
00019         setAcceptDrops(true);
00020 }
00021 
00022 ImageDropWidget::~ImageDropWidget()
00023 {
00024 }
00025 
00026 void ImageDropWidget::dragEnterEvent(QDragEnterEvent *event)
00027 {
00028         if (event->mimeData()->hasUrls())
00029         {
00030                 event->acceptProposedAction();
00031         }
00032 }
00033 
00034 void ImageDropWidget::dropEvent(QDropEvent *event)
00035 {
00036         QStringList fileNames;
00037 
00038         QStringList extensions = Settings::getGeneral_imageFormats().split(" ");
00039 
00040         QList<QUrl> urls = event->mimeData()->urls();
00041         for(int i=0; i<urls.size(); ++i)
00042         {
00043                 QString path = urls.at(i).toLocalFile();
00044                 for(int j=0; j<extensions.size(); ++j)
00045                 {
00046                         QRegExp reg(extensions[j]);
00047                         reg.setPatternSyntax(QRegExp::Wildcard);
00048                         if(reg.exactMatch(path))
00049                         {
00050                                 fileNames.push_back(path);
00051                                 break;
00052                         }
00053                 }
00054         }
00055 
00056         if(fileNames.size())
00057         {
00058                 Q_EMIT imagesReceived(fileNames);
00059         }
00060 
00061         event->acceptProposedAction();
00062 }
00063 
00064 }
00065 


find_object_2d
Author(s): Mathieu Labbe
autogenerated on Thu Feb 11 2016 22:57:56