mirror of https://github.com/status-im/qzxing.git
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:
parent
6542fb1d6a
commit
89163533d4
|
@ -4,24 +4,48 @@
|
|||
#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)
|
||||
//void DropArea::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
|
||||
//{
|
||||
// event->acceptProposedAction();
|
||||
// setCursor(Qt::DragMoveCursor);
|
||||
//}
|
||||
|
||||
//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::setAcceptingDrops(bool accepting)
|
||||
{
|
||||
event->acceptProposedAction();
|
||||
setCursor(Qt::DragMoveCursor);
|
||||
if (accepting == m_accepting)
|
||||
return;
|
||||
|
||||
m_accepting = accepting;
|
||||
|
||||
setFlag(QQuickItem::ItemAcceptsDrops);
|
||||
//setAcceptDrops(m_accepting);
|
||||
emit acceptingDropsChanged();
|
||||
}
|
||||
|
||||
void DropArea::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
|
||||
{
|
||||
unsetCursor();
|
||||
}
|
||||
|
||||
void DropArea::dropEvent(QGraphicsSceneDragDropEvent *event)
|
||||
void DropArea::dropEvent(QDropEvent *event)
|
||||
{
|
||||
qDebug("File!");
|
||||
QList<QUrl> list = event->mimeData()->urls();
|
||||
|
@ -32,14 +56,3 @@ void DropArea::dropEvent(QGraphicsSceneDragDropEvent *event)
|
|||
}
|
||||
unsetCursor();
|
||||
}
|
||||
|
||||
void DropArea::setAcceptingDrops(bool accepting)
|
||||
{
|
||||
if (accepting == m_accepting)
|
||||
return;
|
||||
|
||||
m_accepting = accepting;
|
||||
|
||||
setAcceptDrops(m_accepting);
|
||||
emit acceptingDropsChanged();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -20,8 +20,6 @@ Rectangle {
|
|||
console.log(drop.urls[0])
|
||||
|
||||
var path = drop.urls[0];
|
||||
path = path.replace("file://","");
|
||||
|
||||
decoder.decodeImageFromFile(path)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue