ImageDropWidget.cpp
Go to the documentation of this file.
1 /*
2  * ImageDropWidget.cpp
3  *
4  * Created on: Dec 22, 2014
5  * Author: mathieu
6  */
7 
8 #include <ImageDropWidget.h>
9 #include <find_object/Settings.h>
10 #include <QtGui/QDragEnterEvent>
11 #include <QtCore/QRegExp>
12 #include <QtCore/QUrl>
13 #include <QMimeData>
14 
15 namespace find_object {
16 
17 ImageDropWidget::ImageDropWidget(QWidget *parent, Qt::WindowFlags flags) :
18  QWidget(parent, flags)
19 {
20  setAcceptDrops(true);
21 }
22 
24 {
25 }
26 
27 void ImageDropWidget::dragEnterEvent(QDragEnterEvent *event)
28 {
29  if (event->mimeData()->hasUrls())
30  {
31  event->acceptProposedAction();
32  }
33 }
34 
35 void ImageDropWidget::dropEvent(QDropEvent *event)
36 {
37  QStringList fileNames;
38 
39  QStringList extensions = Settings::getGeneral_imageFormats().split(" ");
40 
41  QList<QUrl> urls = event->mimeData()->urls();
42  for(int i=0; i<urls.size(); ++i)
43  {
44  QString path = urls.at(i).toLocalFile();
45  for(int j=0; j<extensions.size(); ++j)
46  {
47  QRegExp reg(extensions[j]);
48  reg.setPatternSyntax(QRegExp::Wildcard);
49  if(reg.exactMatch(path))
50  {
51  fileNames.push_back(path);
52  break;
53  }
54  }
55  }
56 
57  if(fileNames.size())
58  {
59  Q_EMIT imagesReceived(fileNames);
60  }
61 
62  event->acceptProposedAction();
63 }
64 
65 }
66 
ImageDropWidget(QWidget *parent=0, Qt::WindowFlags flags=0)
virtual void dragEnterEvent(QDragEnterEvent *event)
void imagesReceived(const QStringList &)
virtual void dropEvent(QDropEvent *event)


find_object_2d
Author(s): Mathieu Labbe
autogenerated on Mon Jun 10 2019 13:21:31