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_target = target;
|
||||
m_imageFormat = QImage::Format_Invalid;
|
||||
|
||||
timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(sendImageToDecode()));
|
||||
timer->start(500);
|
||||
}
|
||||
|
||||
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->setCurrentIndex(0);
|
||||
|
||||
hboxl->addWidget(m_stackedWidget);
|
||||
|
||||
|
||||
// Buttons
|
||||
QSize iconSize(80, 80);
|
||||
|
@ -98,23 +98,24 @@ QCameraControllerWidget::QCameraControllerWidget(QWidget *parent) :
|
|||
vboxl->setSpacing(0);
|
||||
vboxl->setMargin(0);
|
||||
|
||||
// Exit button
|
||||
m_exit = new Button(this);
|
||||
QObject::connect(m_exit, SIGNAL(pressed()), qApp, SLOT(quit()));
|
||||
QPixmap p = QPixmap(":/icons/exit.png");
|
||||
m_exit->setPixmap(p.scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
vboxl->addWidget(m_exit);
|
||||
vboxl->setAlignment(m_exit,Qt::AlignHCenter | Qt::AlignTop);
|
||||
zoomIn = new Button(this);
|
||||
QObject::connect(zoomIn, SIGNAL(pressed()), this, SLOT(onZoomIn()));
|
||||
QPixmap p = QPixmap(":/icons/zoomIn");
|
||||
zoomIn->setPixmap(p.scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
vboxl->addWidget(zoomIn);
|
||||
vboxl->setAlignment(zoomIn,Qt::AlignTop | Qt::AlignHCenter);
|
||||
|
||||
// Camera button
|
||||
m_cameraBtn = new Button(this);
|
||||
QObject::connect(m_cameraBtn, SIGNAL(pressed()), this, SLOT(searchAndLock()));
|
||||
p = QPixmap(":/icons/camera.png");
|
||||
m_cameraBtn->setPixmap(p.scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
vboxl->addWidget(m_cameraBtn);
|
||||
vboxl->setAlignment(m_cameraBtn, Qt::AlignBottom);
|
||||
zoomOut = new Button(this);
|
||||
QObject::connect(zoomOut, SIGNAL(pressed()), this, SLOT(onZoomOut()));
|
||||
p = QPixmap(":/icons/zoomOut");
|
||||
zoomOut->setPixmap(p.scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
vboxl->addWidget(zoomOut);
|
||||
vboxl->setAlignment(zoomOut, Qt::AlignBottom | Qt::AlignHCenter);
|
||||
|
||||
//hboxl->addLayout(vboxl);
|
||||
hboxl->addWidget(m_stackedWidget);
|
||||
hboxl->addLayout(vboxl);
|
||||
|
||||
setLayout(hboxl);
|
||||
|
||||
// Enable camera after 1s, so that the application is started
|
||||
|
@ -139,6 +140,7 @@ void QCameraControllerWidget::enableCamera()
|
|||
m_camera->setCaptureMode(QCamera::CaptureStillImage);
|
||||
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(stateChanged( QCamera::State) ), this, SLOT(onStateChanged(QCamera::State)));
|
||||
|
||||
// Own video output drawing that shows camera view finder pictures
|
||||
//! [0]
|
||||
|
@ -146,6 +148,9 @@ void QCameraControllerWidget::enableCamera()
|
|||
QVideoRendererControl* vrc = ms->requestControl<QVideoRendererControl*>();
|
||||
m_myVideoSurface = new MyVideoSurface(this,this,this);
|
||||
vrc->setSurface(m_myVideoSurface);
|
||||
|
||||
connect(m_myVideoSurface, SIGNAL(imageCaptured(QImage)), this, SLOT(redirectImageSignalFromVideoFinder(QImage)));
|
||||
|
||||
//! [0]
|
||||
// Image capturer
|
||||
m_stillImageCapture = new QCameraImageCapture(m_camera);
|
||||
|
@ -158,6 +163,10 @@ void QCameraControllerWidget::enableCamera()
|
|||
m_videoWidget->show();
|
||||
m_camera->start();
|
||||
showViewFinder = true;
|
||||
|
||||
cameraFocus = m_camera->focus();
|
||||
// cameraFocus->setFocusMode(QCameraFocus::ContinuousFocus);
|
||||
// cameraFocus->setFocusPointMode(QCameraFocus::FocusPointAuto);
|
||||
}
|
||||
|
||||
void QCameraControllerWidget::mousePressEvent(QMouseEvent *event)
|
||||
|
@ -337,18 +346,63 @@ void QCameraControllerWidget::paintEvent(QPaintEvent *event)
|
|||
// Draw black
|
||||
painter.fillRect(event->rect(), palette().background());
|
||||
// Show captured image
|
||||
if (pictureCaptured) {
|
||||
// Paint captured image
|
||||
QPoint centerPic((qAbs(r.size().width() - m_capturedImage.size().width())) / 2, (qAbs(
|
||||
r.size().height() - m_capturedImage.size().height())) / 2);
|
||||
// if (pictureCaptured) {
|
||||
// // Paint captured image
|
||||
// QPoint centerPic((qAbs(r.size().width() - m_capturedImage.size().width())) / 2, (qAbs(
|
||||
// r.size().height() - m_capturedImage.size().height())) / 2);
|
||||
|
||||
painter.drawImage(centerPic, m_capturedImage);
|
||||
// painter.drawImage(centerPic, m_capturedImage);
|
||||
|
||||
// Paint filename
|
||||
// painter.drawText(r, Qt::AlignBottom | Qt::AlignCenter, m_imageName);
|
||||
// // Paint filename
|
||||
// // 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"
|
||||
#include <QCamera>
|
||||
#include <QCameraImageCapture>
|
||||
#include <QCameraFocus>
|
||||
|
||||
// QtMobility API
|
||||
//#include <QSystemScreenSaver>
|
||||
|
@ -78,6 +79,11 @@ public slots:
|
|||
void captureImage();
|
||||
void onImageCaptured(int id, const QImage &preview);
|
||||
void error(QCamera::Error);
|
||||
void redirectImageSignalFromVideoFinder(QImage image);
|
||||
|
||||
void onStateChanged(QCamera::State state) ;
|
||||
void onZoomIn();
|
||||
void onZoomOut();
|
||||
|
||||
|
||||
signals:
|
||||
|
@ -85,13 +91,13 @@ signals:
|
|||
|
||||
private:
|
||||
QWidget* m_videoWidget;
|
||||
QWidget* zoomButtons;
|
||||
QCamera* m_camera;
|
||||
QCameraImageCapture* m_stillImageCapture;
|
||||
|
||||
QStackedWidget* m_stackedWidget;
|
||||
Button* m_exit;
|
||||
Button* m_cameraBtn;
|
||||
Button* m_mms;
|
||||
Button* zoomIn;
|
||||
Button* zoomOut;
|
||||
QImage m_capturedImage;
|
||||
QString m_imageName;
|
||||
QString m_focusMessage;
|
||||
|
@ -102,7 +108,7 @@ private:
|
|||
bool pictureCaptured;
|
||||
bool showViewFinder;
|
||||
MyVideoSurface* m_myVideoSurface;
|
||||
//QSystemScreenSaver* m_systemScreenSaver;
|
||||
QCameraFocus* cameraFocus;
|
||||
};
|
||||
|
||||
#endif // QCAMERA_H
|
||||
|
|
|
@ -3,7 +3,7 @@ TARGET = QQrDecoder
|
|||
QT += core \
|
||||
gui
|
||||
|
||||
VERSION = 1.1.0
|
||||
VERSION = 1.2.0
|
||||
|
||||
CONFIG += mobility
|
||||
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 <QVideoSurfaceFormat>
|
||||
#include <QPainter>
|
||||
#include <QTimer>
|
||||
|
||||
class VideoIF
|
||||
{
|
||||
|
@ -33,12 +34,19 @@ public:
|
|||
|
||||
void paint(QPainter*);
|
||||
|
||||
public slots:
|
||||
void sendImageToDecode();
|
||||
|
||||
signals:
|
||||
void imageCaptured(QImage image);
|
||||
|
||||
private:
|
||||
QWidget* m_targetWidget;
|
||||
VideoIF* m_target;
|
||||
QVideoFrame m_frame;
|
||||
QImage::Format m_imageFormat;
|
||||
QVideoSurfaceFormat m_videoFormat;
|
||||
QTimer* timer;
|
||||
};
|
||||
|
||||
#endif // MYVIDEOSURFACE_H
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<RCC>
|
||||
<qresource prefix="/icons">
|
||||
<file alias="camera.png">icons/camera.png</file>
|
||||
<file alias="exit.png">icons/exit.png</file>
|
||||
<file alias="camera">icons/camera.png</file>
|
||||
<file alias="exit">icons/exit.png</file>
|
||||
<file alias="zoomIn">icons/zoomIn.png</file>
|
||||
<file alias="zoomOut">icons/zoomOut.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
Loading…
Reference in a new issue