Added DragNDrop images directly in objects or scene zones.
git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@415 620bd6b2-0a58-f614-fd9a-1bd335dccda9
This commit is contained in:
parent
807c8b5b43
commit
a96ea6c4f5
@ -86,7 +86,9 @@ private Q_SLOTS:
|
||||
void loadObjects();
|
||||
bool saveObjects();
|
||||
void addObjectFromScene();
|
||||
void addObjectsFromFiles(const QStringList & fileNames);
|
||||
void addObjectsFromFiles();
|
||||
void loadSceneFromFile(const QStringList & fileNames);
|
||||
void loadSceneFromFile();
|
||||
void setupCameraFromVideoFile();
|
||||
void setupCameraFromImagesDirectory();
|
||||
|
||||
@ -12,6 +12,7 @@ SET(headers_ui
|
||||
./ParametersToolBox.h
|
||||
./AboutDialog.h
|
||||
./RectItem.h
|
||||
./ImageDropWidget.h
|
||||
./rtabmap/PdfPlot.h
|
||||
./utilite/UPlot.h
|
||||
)
|
||||
@ -47,6 +48,7 @@ SET(SRC_FILES
|
||||
./ParametersToolBox.cpp
|
||||
./Settings.cpp
|
||||
./ObjWidget.cpp
|
||||
./ImageDropWidget.cpp
|
||||
./FindObject.cpp
|
||||
./AboutDialog.cpp
|
||||
./TcpServer.cpp
|
||||
|
||||
65
src/ImageDropWidget.cpp
Normal file
65
src/ImageDropWidget.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* ImageDropWidget.cpp
|
||||
*
|
||||
* Created on: Dec 22, 2014
|
||||
* Author: mathieu
|
||||
*/
|
||||
|
||||
#include <ImageDropWidget.h>
|
||||
#include <find_object/Settings.h>
|
||||
#include <QtGui/QDragEnterEvent>
|
||||
#include <QtCore/QRegExp>
|
||||
#include <QtCore/QUrl>
|
||||
|
||||
namespace find_object {
|
||||
|
||||
ImageDropWidget::ImageDropWidget(QWidget *parent, Qt::WindowFlags flags) :
|
||||
QWidget(parent, flags)
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
}
|
||||
|
||||
ImageDropWidget::~ImageDropWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void ImageDropWidget::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasUrls())
|
||||
{
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
||||
void ImageDropWidget::dropEvent(QDropEvent *event)
|
||||
{
|
||||
QStringList fileNames;
|
||||
|
||||
QStringList extensions = Settings::getGeneral_imageFormats().split(" ");
|
||||
|
||||
QList<QUrl> urls = event->mimeData()->urls();
|
||||
for(int i=0; i<urls.size(); ++i)
|
||||
{
|
||||
QString path = urls.at(i).toLocalFile();
|
||||
for(int j=0; j<extensions.size(); ++j)
|
||||
{
|
||||
QRegExp reg(extensions[j]);
|
||||
reg.setPatternSyntax(QRegExp::Wildcard);
|
||||
if(reg.exactMatch(path))
|
||||
{
|
||||
fileNames.push_back(path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(fileNames.size())
|
||||
{
|
||||
Q_EMIT imagesReceived(fileNames);
|
||||
}
|
||||
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
34
src/ImageDropWidget.h
Normal file
34
src/ImageDropWidget.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* ImageDropWidget.h
|
||||
*
|
||||
* Created on: Dec 22, 2014
|
||||
* Author: mathieu
|
||||
*/
|
||||
|
||||
#ifndef IMAGEDROPWIDGET_H_
|
||||
#define IMAGEDROPWIDGET_H_
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
|
||||
namespace find_object {
|
||||
|
||||
class ImageDropWidget : public QWidget {
|
||||
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
ImageDropWidget(QWidget *parent = 0, Qt::WindowFlags flags = 0);
|
||||
virtual ~ImageDropWidget();
|
||||
|
||||
Q_SIGNALS:
|
||||
void imagesReceived(const QStringList &);
|
||||
|
||||
|
||||
protected:
|
||||
virtual void dragEnterEvent(QDragEnterEvent *event);
|
||||
virtual void dropEvent(QDropEvent *event);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* IMAGEDROPWIDGET_H_ */
|
||||
@ -246,6 +246,10 @@ MainWindow::MainWindow(FindObject * findObject, Camera * camera, QWidget * paren
|
||||
// Set 1 msec to see state on the status bar.
|
||||
QTimer::singleShot(1, this, SLOT(startProcessing()));
|
||||
}
|
||||
|
||||
//Setup drag and drop images
|
||||
connect(ui_->imageDrop_objects, SIGNAL(imagesReceived(const QStringList &)), this, SLOT(addObjectsFromFiles(const QStringList &)));
|
||||
connect(ui_->imageDrop_scene, SIGNAL(imagesReceived(const QStringList &)), this, SLOT(loadSceneFromFile(const QStringList &)));
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@ -570,9 +574,8 @@ void MainWindow::addObjectFromScene()
|
||||
delete dialog;
|
||||
}
|
||||
|
||||
void MainWindow::addObjectsFromFiles()
|
||||
void MainWindow::addObjectsFromFiles(const QStringList & fileNames)
|
||||
{
|
||||
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Add objects..."), Settings::workingDirectory(), tr("Image Files (%1)").arg(Settings::getGeneral_imageFormats()));
|
||||
if(fileNames.size())
|
||||
{
|
||||
for(int i=0; i<fileNames.size(); ++i)
|
||||
@ -584,6 +587,11 @@ void MainWindow::addObjectsFromFiles()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::addObjectsFromFiles()
|
||||
{
|
||||
addObjectsFromFiles(QFileDialog::getOpenFileNames(this, tr("Add objects..."), Settings::workingDirectory(), tr("Image Files (%1)").arg(Settings::getGeneral_imageFormats())));
|
||||
}
|
||||
|
||||
bool MainWindow::addObjectFromFile(const QString & filePath)
|
||||
{
|
||||
const ObjSignature * s = findObject_->addObject(filePath);
|
||||
@ -602,6 +610,20 @@ bool MainWindow::addObjectFromFile(const QString & filePath)
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::loadSceneFromFile(const QStringList & fileNames)
|
||||
{
|
||||
//take the first
|
||||
if(fileNames.size())
|
||||
{
|
||||
cv::Mat img = cv::imread(fileNames.first().toStdString().c_str());
|
||||
if(!img.empty())
|
||||
{
|
||||
this->update(img);
|
||||
ui_->label_timeRefreshRate->setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::loadSceneFromFile()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Load scene..."), Settings::workingDirectory(), tr("Image Files (%1)").arg(Settings::getGeneral_imageFormats()));
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>826</width>
|
||||
<width>881</width>
|
||||
<height>523</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -18,6 +18,15 @@
|
||||
<normaloff>:/images/resources/Find-Object.png</normaloff>:/images/resources/Find-Object.png</iconset>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_8">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="find_object::ImageDropWidget" name="imageDrop_scene" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1,0">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
@ -194,13 +203,16 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>826</width>
|
||||
<height>25</height>
|
||||
<width>881</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
@ -255,7 +267,7 @@
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>360</width>
|
||||
<height>156</height>
|
||||
<height>168</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="floating">
|
||||
@ -285,8 +297,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>360</width>
|
||||
<height>73</height>
|
||||
<width>348</width>
|
||||
<height>76</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
@ -309,8 +321,8 @@
|
||||
<widget class="QDockWidget" name="dockWidget_objects">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>138</height>
|
||||
<width>208</width>
|
||||
<height>196</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -321,6 +333,12 @@
|
||||
</attribute>
|
||||
<widget class="QWidget" name="dockWidgetContents_2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="find_object::ImageDropWidget" name="imageDrop_objects" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
@ -343,8 +361,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>198</width>
|
||||
<height>393</height>
|
||||
<width>206</width>
|
||||
<height>396</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_objects">
|
||||
@ -408,6 +426,12 @@
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder></zorder>
|
||||
<zorder>verticalSpacer</zorder>
|
||||
<zorder>objects_area</zorder>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QDockWidget" name="dockWidget_plot">
|
||||
@ -825,6 +849,12 @@
|
||||
<header>utilite/UPlot.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>find_object::ImageDropWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>ImageDropWidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../resources.qrc"/>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user