mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Updated QQrDecoder (ZXing + Qt).
Added zoom functionality + autofocus + automatic detection (at the immediate previous version the user had to press a button to initiate decoding). git-svn-id: https://zxing.googlecode.com/svn/trunk@1925 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
f2e3fdc5e3
commit
f0e371d622
|
@ -6,6 +6,10 @@ MyVideoSurface::MyVideoSurface(QWidget* widget, VideoIF* target, QObject* parent
|
||||||
m_targetWidget = widget;
|
m_targetWidget = widget;
|
||||||
m_target = target;
|
m_target = target;
|
||||||
m_imageFormat = QImage::Format_Invalid;
|
m_imageFormat = QImage::Format_Invalid;
|
||||||
|
|
||||||
|
timer = new QTimer(this);
|
||||||
|
connect(timer, SIGNAL(timeout()), this, SLOT(sendImageToDecode()));
|
||||||
|
timer->start(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
MyVideoSurface::~MyVideoSurface()
|
MyVideoSurface::~MyVideoSurface()
|
||||||
|
@ -77,3 +81,20 @@ QList<QVideoFrame::PixelFormat> MyVideoSurface::supportedPixelFormats(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyVideoSurface::sendImageToDecode()
|
||||||
|
{
|
||||||
|
if (m_frame.map(QAbstractVideoBuffer::ReadOnly)) {
|
||||||
|
QImage image(
|
||||||
|
m_frame.bits(),
|
||||||
|
m_frame.width(),
|
||||||
|
m_frame.height(),
|
||||||
|
m_frame.bytesPerLine(),
|
||||||
|
m_imageFormat);
|
||||||
|
|
||||||
|
if (!image.isNull())
|
||||||
|
emit imageCaptured(image);
|
||||||
|
|
||||||
|
m_frame.unmap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ QCameraControllerWidget::QCameraControllerWidget(QWidget *parent) :
|
||||||
m_stackedWidget->addWidget(secondWidget);
|
m_stackedWidget->addWidget(secondWidget);
|
||||||
m_stackedWidget->setCurrentIndex(0);
|
m_stackedWidget->setCurrentIndex(0);
|
||||||
|
|
||||||
hboxl->addWidget(m_stackedWidget);
|
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
QSize iconSize(80, 80);
|
QSize iconSize(80, 80);
|
||||||
|
@ -98,23 +98,24 @@ QCameraControllerWidget::QCameraControllerWidget(QWidget *parent) :
|
||||||
vboxl->setSpacing(0);
|
vboxl->setSpacing(0);
|
||||||
vboxl->setMargin(0);
|
vboxl->setMargin(0);
|
||||||
|
|
||||||
// Exit button
|
zoomIn = new Button(this);
|
||||||
m_exit = new Button(this);
|
QObject::connect(zoomIn, SIGNAL(pressed()), this, SLOT(onZoomIn()));
|
||||||
QObject::connect(m_exit, SIGNAL(pressed()), qApp, SLOT(quit()));
|
QPixmap p = QPixmap(":/icons/zoomIn");
|
||||||
QPixmap p = QPixmap(":/icons/exit.png");
|
zoomIn->setPixmap(p.scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||||
m_exit->setPixmap(p.scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
vboxl->addWidget(zoomIn);
|
||||||
vboxl->addWidget(m_exit);
|
vboxl->setAlignment(zoomIn,Qt::AlignTop | Qt::AlignHCenter);
|
||||||
vboxl->setAlignment(m_exit,Qt::AlignHCenter | Qt::AlignTop);
|
|
||||||
|
|
||||||
// Camera button
|
zoomOut = new Button(this);
|
||||||
m_cameraBtn = new Button(this);
|
QObject::connect(zoomOut, SIGNAL(pressed()), this, SLOT(onZoomOut()));
|
||||||
QObject::connect(m_cameraBtn, SIGNAL(pressed()), this, SLOT(searchAndLock()));
|
p = QPixmap(":/icons/zoomOut");
|
||||||
p = QPixmap(":/icons/camera.png");
|
zoomOut->setPixmap(p.scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||||
m_cameraBtn->setPixmap(p.scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
vboxl->addWidget(zoomOut);
|
||||||
vboxl->addWidget(m_cameraBtn);
|
vboxl->setAlignment(zoomOut, Qt::AlignBottom | Qt::AlignHCenter);
|
||||||
vboxl->setAlignment(m_cameraBtn, Qt::AlignBottom);
|
|
||||||
|
|
||||||
|
//hboxl->addLayout(vboxl);
|
||||||
|
hboxl->addWidget(m_stackedWidget);
|
||||||
hboxl->addLayout(vboxl);
|
hboxl->addLayout(vboxl);
|
||||||
|
|
||||||
setLayout(hboxl);
|
setLayout(hboxl);
|
||||||
|
|
||||||
// Enable camera after 1s, so that the application is started
|
// Enable camera after 1s, so that the application is started
|
||||||
|
@ -139,6 +140,7 @@ void QCameraControllerWidget::enableCamera()
|
||||||
m_camera->setCaptureMode(QCamera::CaptureStillImage);
|
m_camera->setCaptureMode(QCamera::CaptureStillImage);
|
||||||
connect(m_camera, SIGNAL(error(QCamera::Error)), this, SLOT(error(QCamera::Error)));
|
connect(m_camera, SIGNAL(error(QCamera::Error)), this, SLOT(error(QCamera::Error)));
|
||||||
connect(m_camera, SIGNAL(lockStatusChanged(QCamera::LockStatus,QCamera::LockChangeReason)), this, SLOT(lockStatusChanged(QCamera::LockStatus,QCamera::LockChangeReason)));
|
connect(m_camera, SIGNAL(lockStatusChanged(QCamera::LockStatus,QCamera::LockChangeReason)), this, SLOT(lockStatusChanged(QCamera::LockStatus,QCamera::LockChangeReason)));
|
||||||
|
connect(m_camera, SIGNAL(stateChanged( QCamera::State) ), this, SLOT(onStateChanged(QCamera::State)));
|
||||||
|
|
||||||
// Own video output drawing that shows camera view finder pictures
|
// Own video output drawing that shows camera view finder pictures
|
||||||
//! [0]
|
//! [0]
|
||||||
|
@ -146,6 +148,9 @@ void QCameraControllerWidget::enableCamera()
|
||||||
QVideoRendererControl* vrc = ms->requestControl<QVideoRendererControl*>();
|
QVideoRendererControl* vrc = ms->requestControl<QVideoRendererControl*>();
|
||||||
m_myVideoSurface = new MyVideoSurface(this,this,this);
|
m_myVideoSurface = new MyVideoSurface(this,this,this);
|
||||||
vrc->setSurface(m_myVideoSurface);
|
vrc->setSurface(m_myVideoSurface);
|
||||||
|
|
||||||
|
connect(m_myVideoSurface, SIGNAL(imageCaptured(QImage)), this, SLOT(redirectImageSignalFromVideoFinder(QImage)));
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
// Image capturer
|
// Image capturer
|
||||||
m_stillImageCapture = new QCameraImageCapture(m_camera);
|
m_stillImageCapture = new QCameraImageCapture(m_camera);
|
||||||
|
@ -158,6 +163,10 @@ void QCameraControllerWidget::enableCamera()
|
||||||
m_videoWidget->show();
|
m_videoWidget->show();
|
||||||
m_camera->start();
|
m_camera->start();
|
||||||
showViewFinder = true;
|
showViewFinder = true;
|
||||||
|
|
||||||
|
cameraFocus = m_camera->focus();
|
||||||
|
// cameraFocus->setFocusMode(QCameraFocus::ContinuousFocus);
|
||||||
|
// cameraFocus->setFocusPointMode(QCameraFocus::FocusPointAuto);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QCameraControllerWidget::mousePressEvent(QMouseEvent *event)
|
void QCameraControllerWidget::mousePressEvent(QMouseEvent *event)
|
||||||
|
@ -337,18 +346,63 @@ void QCameraControllerWidget::paintEvent(QPaintEvent *event)
|
||||||
// Draw black
|
// Draw black
|
||||||
painter.fillRect(event->rect(), palette().background());
|
painter.fillRect(event->rect(), palette().background());
|
||||||
// Show captured image
|
// Show captured image
|
||||||
if (pictureCaptured) {
|
// if (pictureCaptured) {
|
||||||
// Paint captured image
|
// // Paint captured image
|
||||||
QPoint centerPic((qAbs(r.size().width() - m_capturedImage.size().width())) / 2, (qAbs(
|
// QPoint centerPic((qAbs(r.size().width() - m_capturedImage.size().width())) / 2, (qAbs(
|
||||||
r.size().height() - m_capturedImage.size().height())) / 2);
|
// r.size().height() - m_capturedImage.size().height())) / 2);
|
||||||
|
|
||||||
painter.drawImage(centerPic, m_capturedImage);
|
// painter.drawImage(centerPic, m_capturedImage);
|
||||||
|
|
||||||
// Paint filename
|
// // Paint filename
|
||||||
// painter.drawText(r, Qt::AlignBottom | Qt::AlignCenter, m_imageName);
|
// // painter.drawText(r, Qt::AlignBottom | Qt::AlignCenter, m_imageName);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QCameraControllerWidget::redirectImageSignalFromVideoFinder(QImage image)
|
||||||
|
{
|
||||||
|
emit imageCaptured(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void QCameraControllerWidget::onZoomIn()
|
||||||
|
{
|
||||||
|
qreal optical = cameraFocus->opticalZoom();
|
||||||
|
qreal digital = cameraFocus->digitalZoom();
|
||||||
|
|
||||||
|
if(optical == cameraFocus->maximumOpticalZoom())
|
||||||
|
cameraFocus->zoomTo(optical, digital + 0.1);
|
||||||
|
else
|
||||||
|
cameraFocus->zoomTo(optical + 0.1, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QCameraControllerWidget::onZoomOut()
|
||||||
|
{
|
||||||
|
qreal optical = cameraFocus->opticalZoom();
|
||||||
|
qreal digital = cameraFocus->digitalZoom();
|
||||||
|
|
||||||
|
|
||||||
|
if(optical == cameraFocus->maximumOpticalZoom() && digital != 0.0)
|
||||||
|
{
|
||||||
|
if(digital - 0.1 >= 1)
|
||||||
|
cameraFocus->zoomTo(optical, digital - 0.1);
|
||||||
|
else
|
||||||
|
cameraFocus->zoomTo(optical, 1.0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(optical - 0.1 >= 1)
|
||||||
|
cameraFocus->zoomTo(optical - 0.1, 1.0);
|
||||||
|
else
|
||||||
|
cameraFocus->zoomTo(1.0, 1.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QCameraControllerWidget::onStateChanged(QCamera::State state)
|
||||||
|
{
|
||||||
|
if(state == QCamera::ActiveState)
|
||||||
|
{
|
||||||
|
// cameraFocus->setFocusMode(QCameraFocus::AutoFocus);
|
||||||
|
// cameraFocus->setFocusPointMode(QCameraFocus::FocusPointAuto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
// the Multimedia API is not in the QtMobility namespace "QTM_USE_NAMESPACE"
|
// the Multimedia API is not in the QtMobility namespace "QTM_USE_NAMESPACE"
|
||||||
#include <QCamera>
|
#include <QCamera>
|
||||||
#include <QCameraImageCapture>
|
#include <QCameraImageCapture>
|
||||||
|
#include <QCameraFocus>
|
||||||
|
|
||||||
// QtMobility API
|
// QtMobility API
|
||||||
//#include <QSystemScreenSaver>
|
//#include <QSystemScreenSaver>
|
||||||
|
@ -78,6 +79,11 @@ public slots:
|
||||||
void captureImage();
|
void captureImage();
|
||||||
void onImageCaptured(int id, const QImage &preview);
|
void onImageCaptured(int id, const QImage &preview);
|
||||||
void error(QCamera::Error);
|
void error(QCamera::Error);
|
||||||
|
void redirectImageSignalFromVideoFinder(QImage image);
|
||||||
|
|
||||||
|
void onStateChanged(QCamera::State state) ;
|
||||||
|
void onZoomIn();
|
||||||
|
void onZoomOut();
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -85,13 +91,13 @@ signals:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWidget* m_videoWidget;
|
QWidget* m_videoWidget;
|
||||||
|
QWidget* zoomButtons;
|
||||||
QCamera* m_camera;
|
QCamera* m_camera;
|
||||||
QCameraImageCapture* m_stillImageCapture;
|
QCameraImageCapture* m_stillImageCapture;
|
||||||
|
|
||||||
QStackedWidget* m_stackedWidget;
|
QStackedWidget* m_stackedWidget;
|
||||||
Button* m_exit;
|
Button* zoomIn;
|
||||||
Button* m_cameraBtn;
|
Button* zoomOut;
|
||||||
Button* m_mms;
|
|
||||||
QImage m_capturedImage;
|
QImage m_capturedImage;
|
||||||
QString m_imageName;
|
QString m_imageName;
|
||||||
QString m_focusMessage;
|
QString m_focusMessage;
|
||||||
|
@ -102,7 +108,7 @@ private:
|
||||||
bool pictureCaptured;
|
bool pictureCaptured;
|
||||||
bool showViewFinder;
|
bool showViewFinder;
|
||||||
MyVideoSurface* m_myVideoSurface;
|
MyVideoSurface* m_myVideoSurface;
|
||||||
//QSystemScreenSaver* m_systemScreenSaver;
|
QCameraFocus* cameraFocus;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QCAMERA_H
|
#endif // QCAMERA_H
|
||||||
|
|
|
@ -3,7 +3,7 @@ TARGET = QQrDecoder
|
||||||
QT += core \
|
QT += core \
|
||||||
gui
|
gui
|
||||||
|
|
||||||
VERSION = 1.1.0
|
VERSION = 1.2.0
|
||||||
|
|
||||||
CONFIG += mobility
|
CONFIG += mobility
|
||||||
MOBILITY = multimedia #\
|
MOBILITY = multimedia #\
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 16 KiB |
Binary file not shown.
Before Width: | Height: | Size: 14 KiB |
BIN
symbian/QQrDecoder/icons/zoomIn.png
Normal file
BIN
symbian/QQrDecoder/icons/zoomIn.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.9 KiB |
BIN
symbian/QQrDecoder/icons/zoomOut.png
Normal file
BIN
symbian/QQrDecoder/icons/zoomOut.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.4 KiB |
|
@ -9,6 +9,7 @@
|
||||||
#include <QVideoRendererControl>
|
#include <QVideoRendererControl>
|
||||||
#include <QVideoSurfaceFormat>
|
#include <QVideoSurfaceFormat>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
class VideoIF
|
class VideoIF
|
||||||
{
|
{
|
||||||
|
@ -33,12 +34,19 @@ public:
|
||||||
|
|
||||||
void paint(QPainter*);
|
void paint(QPainter*);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void sendImageToDecode();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void imageCaptured(QImage image);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWidget* m_targetWidget;
|
QWidget* m_targetWidget;
|
||||||
VideoIF* m_target;
|
VideoIF* m_target;
|
||||||
QVideoFrame m_frame;
|
QVideoFrame m_frame;
|
||||||
QImage::Format m_imageFormat;
|
QImage::Format m_imageFormat;
|
||||||
QVideoSurfaceFormat m_videoFormat;
|
QVideoSurfaceFormat m_videoFormat;
|
||||||
|
QTimer* timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MYVIDEOSURFACE_H
|
#endif // MYVIDEOSURFACE_H
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/icons">
|
<qresource prefix="/icons">
|
||||||
<file alias="camera.png">icons/camera.png</file>
|
<file alias="camera">icons/camera.png</file>
|
||||||
<file alias="exit.png">icons/exit.png</file>
|
<file alias="exit">icons/exit.png</file>
|
||||||
|
<file alias="zoomIn">icons/zoomIn.png</file>
|
||||||
|
<file alias="zoomOut">icons/zoomOut.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
Loading…
Reference in a new issue