From 89163533d46809f81638e3bf56724106dd2eba22 Mon Sep 17 00:00:00 2001 From: favoritas37 Date: Fri, 8 Jan 2016 21:49:49 +0200 Subject: [PATCH] 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. --- examples/QZXingDragNDropTest/droparea.cpp | 59 +++++++++++-------- examples/QZXingDragNDropTest/droparea.h | 15 +++-- examples/QZXingDragNDropTest/main.cpp | 3 +- .../qml/QZXingTestApp/ToggleButton.qml | 2 +- .../qml/QZXingTestApp/main_QtQuick2.qml | 2 - 5 files changed, 48 insertions(+), 33 deletions(-) diff --git a/examples/QZXingDragNDropTest/droparea.cpp b/examples/QZXingDragNDropTest/droparea.cpp index 2940898..8a338f0 100644 --- a/examples/QZXingDragNDropTest/droparea.cpp +++ b/examples/QZXingDragNDropTest/droparea.cpp @@ -4,34 +4,34 @@ #include #include -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 list = event->mimeData()->urls(); - for(int i=0; i list = event->mimeData()->urls(); +// for(int i=0; i list = event->mimeData()->urls(); + for(int i=0; i -#include +//#include +#include /** 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; diff --git a/examples/QZXingDragNDropTest/main.cpp b/examples/QZXingDragNDropTest/main.cpp index 8cbc46f..c27b8ce 100644 --- a/examples/QZXingDragNDropTest/main.cpp +++ b/examples/QZXingDragNDropTest/main.cpp @@ -2,7 +2,6 @@ #if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #include #include "qmlapplicationviewer.h" -#include "droparea.h" #include #include #include @@ -10,6 +9,7 @@ #include #include "qtquick2applicationviewer.h" #endif +#include "droparea.h" #include @@ -30,6 +30,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) QZXing::registerQMLTypes(); QtQuick2ApplicationViewer viewer; + qmlRegisterType("DropArea", 1, 0, "DropArea"); viewer.setMainQmlFile(QStringLiteral("qml/QZXingTestApp/main_QtQuick2.qml")); #endif viewer.showExpanded(); diff --git a/examples/QZXingDragNDropTest/qml/QZXingTestApp/ToggleButton.qml b/examples/QZXingDragNDropTest/qml/QZXingTestApp/ToggleButton.qml index 081700a..6d8d076 100644 --- a/examples/QZXingDragNDropTest/qml/QZXingTestApp/ToggleButton.qml +++ b/examples/QZXingDragNDropTest/qml/QZXingTestApp/ToggleButton.qml @@ -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 diff --git a/examples/QZXingDragNDropTest/qml/QZXingTestApp/main_QtQuick2.qml b/examples/QZXingDragNDropTest/qml/QZXingTestApp/main_QtQuick2.qml index 65b96bd..3fff763 100644 --- a/examples/QZXingDragNDropTest/qml/QZXingTestApp/main_QtQuick2.qml +++ b/examples/QZXingDragNDropTest/qml/QZXingTestApp/main_QtQuick2.qml @@ -20,8 +20,6 @@ Rectangle { console.log(drop.urls[0]) var path = drop.urls[0]; - path = path.replace("file://",""); - decoder.decodeImageFromFile(path) } }