1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 The Qt Company Ltd. 4 ** Contact: http://www.qt.io/licensing/ 5 ** 6 ** This file is part of the demonstration applications of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:BSD$ 9 ** You may use this file under the terms of the BSD license as follows: 10 ** 11 ** "Redistribution and use in source and binary forms, with or without 12 ** modification, are permitted provided that the following conditions are 13 ** met: 14 ** * Redistributions of source code must retain the above copyright 15 ** notice, this list of conditions and the following disclaimer. 16 ** * Redistributions in binary form must reproduce the above copyright 17 ** notice, this list of conditions and the following disclaimer in 18 ** the documentation and/or other materials provided with the 19 ** distribution. 20 ** * Neither the name of The Qt Company Ltd nor the names of its 21 ** contributors may be used to endorse or promote products derived 22 ** from this software without specific prior written permission. 23 ** 24 ** 25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 ** 37 ** $QT_END_LICENSE$ 38 ** 39 ****************************************************************************/ 40 41 #ifndef QCAMERAEXAMPLE_H 42 #define QCAMERAEXAMPLE_H 43 44 #include <QtGui> 45 46 // Multimedia API in QtMobility API 47 // Unlike the other APIs in Qt Mobility, 48 // the Multimedia API is not in the QtMobility namespace "QTM_USE_NAMESPACE" 49 #include <QCamera> 50 #include <QCameraImageCapture> 51 52 // QtMobility API 53 #include <QSystemScreenSaver> 54 QTM_USE_NAMESPACE 55 56 57 #include <QAbstractVideoSurface> 58 #include <QVideoRendererControl> 59 #include <QVideoSurfaceFormat> 60 61 /***************************************************************************** 62 * MyVideoSurface 63 */ 64 class VideoIF 65 { 66 public: 67 virtual void updateVideo() = 0; 68 }; 69 class MyVideoSurface: public QAbstractVideoSurface 70 { 71 Q_OBJECT 72 73 public: 74 MyVideoSurface(QWidget* widget, VideoIF* target, QObject * parent = 0); 75 ~MyVideoSurface(); 76 77 bool start(const QVideoSurfaceFormat &format); 78 79 bool present(const QVideoFrame &frame); 80 81 QList<QVideoFrame::PixelFormat> supportedPixelFormats( 82 QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const; 83 84 void paint(QPainter*); 85 86 private: 87 QWidget* m_targetWidget; 88 VideoIF* m_target; 89 QVideoFrame m_frame; 90 QImage::Format m_imageFormat; 91 QVideoSurfaceFormat m_videoFormat; 92 }; 93 94 95 96 /***************************************************************************** 97 * CameraExample 98 */ 99 class Message; 100 class ContactsDialog; 101 class Button; 102 class BusinessCardHandling; 103 class CameraExample: public QMainWindow, public VideoIF 104 { 105 Q_OBJECT 106 107 public: 108 CameraExample(QWidget *parent = 0); 109 ~CameraExample(); 110 111 void paintEvent(QPaintEvent*); 112 void mousePressEvent(QMouseEvent *); 113 114 void updateVideo(); 115 116 117 public slots: 118 void enableCamera(); 119 void lockStatusChanged(QCamera::LockStatus status, QCamera::LockChangeReason reason); 120 void searchAndLock(); 121 void captureImage(); 122 void imageCaptured(int id, const QImage &preview); 123 void error(QCamera::Error); 124 125 void openContactsDlg(); 126 void contactSelected(QString phoneNumber); 127 128 void messageStateChanged(int error); 129 void messageReceived(QString phoneNumber, QString filename, QPixmap pixmap); 130 131 void sendMMS(); 132 133 private: 134 QWidget* m_videoWidget; 135 QCamera* m_camera; 136 QCameraImageCapture* m_stillImageCapture; 137 138 QStackedWidget* m_stackedWidget; 139 Button* m_exit; 140 Button* m_cameraBtn; 141 Button* m_mms; 142 QImage m_capturedImage; 143 QString m_imageName; 144 QString m_focusMessage; 145 bool m_focusing; 146 QString m_phoneNumber; 147 148 Message* m_message; 149 QPointer<ContactsDialog> m_contactsDialog; 150 BusinessCardHandling* m_businessCardHandling; 151 bool pictureCaptured; 152 bool showViewFinder; 153 MyVideoSurface* m_myVideoSurface; 154 QSystemScreenSaver* m_systemScreenSaver; 155 }; 156 157 #endif // QCAMERA_H 158