Fixed QZXingTestApp to use QQuickItem instead of QDeclarativeItem. Also removed the file path editing from the QML, it is properly handled by decoding function with the use of QUrl.

This commit is contained in:
favoritas37 2016-01-08 21:49:49 +02:00
parent 6542fb1d6a
commit 89163533d4
5 changed files with 48 additions and 33 deletions

View File

@ -4,34 +4,34 @@
#include <QMimeData>
#include <QDebug>
DropArea::DropArea(QDeclarativeItem *parent) : QDeclarativeItem(parent),
DropArea::DropArea(QQuickItem *parent) : QQuickItem(parent),
m_accepting(true)
{
setAcceptDrops(m_accepting);
setAcceptingDrops(m_accepting);
}
void DropArea::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
event->acceptProposedAction();
setCursor(Qt::DragMoveCursor);
}
//void DropArea::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
//{
// event->acceptProposedAction();
// setCursor(Qt::DragMoveCursor);
//}
void DropArea::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
{
unsetCursor();
}
//void DropArea::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
//{
// unsetCursor();
//}
void DropArea::dropEvent(QGraphicsSceneDragDropEvent *event)
{
qDebug("File!");
QList<QUrl> list = event->mimeData()->urls();
for(int i=0; i<list.size(); i++)
{
QString path = list.at(i).path();
emit fileDroped(path.right(path.size()-1));
}
unsetCursor();
}
//void DropArea::dropEvent(QGraphicsSceneDragDropEvent *event)
//{
// qDebug("File!");
// QList<QUrl> list = event->mimeData()->urls();
// for(int i=0; i<list.size(); i++)
// {
// QString path = list.at(i).path();
// emit fileDroped(path.right(path.size()-1));
// }
// unsetCursor();
//}
void DropArea::setAcceptingDrops(bool accepting)
{
@ -40,6 +40,19 @@ void DropArea::setAcceptingDrops(bool accepting)
m_accepting = accepting;
setAcceptDrops(m_accepting);
setFlag(QQuickItem::ItemAcceptsDrops);
//setAcceptDrops(m_accepting);
emit acceptingDropsChanged();
}
void DropArea::dropEvent(QDropEvent *event)
{
qDebug("File!");
QList<QUrl> list = event->mimeData()->urls();
for(int i=0; i<list.size(); i++)
{
QString path = list.at(i).path();
emit fileDroped(path.right(path.size()-1));
}
unsetCursor();
}

View File

@ -2,19 +2,21 @@
#define DROPAREA_H
#include <qglobal.h>
#include <QDeclarativeItem>
//#include <QDeclarativeItem>
#include <QQuickItem>
/**
An oversimplified prototype Item which accepts any drop that includes
data with mime type of text/plain, and just emits the text.
*/
class DropArea : public QDeclarativeItem
//class DropArea : public QDeclarativeItem
class DropArea : public QQuickItem
{
Q_OBJECT
Q_PROPERTY(bool acceptingDrops READ isAcceptingDrops WRITE setAcceptingDrops NOTIFY acceptingDropsChanged)
public:
DropArea(QDeclarativeItem *parent=0);
DropArea(QQuickItem *parent=0);
bool isAcceptingDrops() const { return m_accepting; }
void setAcceptingDrops(bool accepting);
@ -23,9 +25,10 @@ signals:
void acceptingDropsChanged();
protected:
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
void dropEvent(QGraphicsSceneDragDropEvent *event);
void dropEvent(QDropEvent * event);
// void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
// void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
// void dropEvent(QGraphicsSceneDragDropEvent *event);
private:
bool m_accepting;

View File

@ -2,7 +2,6 @@
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
#include "droparea.h"
#include <QDeclarativeEngine>
#include <QDeclarativeContext>
#include <qdeclarative.h>
@ -10,6 +9,7 @@
#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#endif
#include "droparea.h"
#include <QZXing.h>
@ -30,6 +30,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
QZXing::registerQMLTypes();
QtQuick2ApplicationViewer viewer;
qmlRegisterType<DropArea>("DropArea", 1, 0, "DropArea");
viewer.setMainQmlFile(QStringLiteral("qml/QZXingTestApp/main_QtQuick2.qml"));
#endif
viewer.showExpanded();

View File

@ -1,5 +1,5 @@
// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.0
import QtQuick 2.0
Rectangle {
id: rect

View File

@ -20,8 +20,6 @@ Rectangle {
console.log(drop.urls[0])
var path = drop.urls[0];
path = path.replace("file://","");
decoder.decodeImageFromFile(path)
}
}