1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cxecameradevicedesktop.h" |
|
19 |
|
20 #include <QTimer> |
|
21 #include <QDir> |
|
22 #include "cxutils.h" |
|
23 |
|
24 |
|
25 /*! |
|
26 * Constructor |
|
27 */ |
|
28 CxeCameraDeviceDesktop::CxeCameraDeviceDesktop() : |
|
29 mSwitchPictureTimer(0), |
|
30 mPictureIndex(0) |
|
31 { |
|
32 CX_DEBUG_ENTER_FUNCTION(); |
|
33 loadPictures(); |
|
34 setupTimer(); |
|
35 CX_DEBUG_EXIT_FUNCTION(); |
|
36 } |
|
37 |
|
38 /*! |
|
39 * Destructor |
|
40 */ |
|
41 CxeCameraDeviceDesktop::~CxeCameraDeviceDesktop() |
|
42 { |
|
43 CX_DEBUG_ENTER_FUNCTION(); |
|
44 mSwitchPictureTimer->stop(); |
|
45 delete mSwitchPictureTimer; |
|
46 CX_DEBUG_EXIT_FUNCTION(); |
|
47 } |
|
48 |
|
49 /*! |
|
50 * Start the camera device |
|
51 */ |
|
52 void CxeCameraDeviceDesktop::start() |
|
53 { |
|
54 CX_DEBUG_ENTER_FUNCTION(); |
|
55 if (!mSwitchPictureTimer->isActive()) { |
|
56 mSwitchPictureTimer->start(); |
|
57 CX_DEBUG_EXIT_FUNCTION(); |
|
58 } |
|
59 } |
|
60 |
|
61 /*! |
|
62 * Stop the camera device |
|
63 */ |
|
64 void CxeCameraDeviceDesktop::stop() |
|
65 { |
|
66 CX_DEBUG_ENTER_FUNCTION(); |
|
67 mSwitchPictureTimer->stop(); |
|
68 CX_DEBUG_EXIT_FUNCTION(); |
|
69 } |
|
70 |
|
71 /*! |
|
72 * Get current picture |
|
73 * @ Return current picture |
|
74 */ |
|
75 const QPixmap &CxeCameraDeviceDesktop::currentSnaphot() |
|
76 { |
|
77 return mPictureList.at(mPictureIndex); |
|
78 } |
|
79 |
|
80 /*! |
|
81 * Handle timeout |
|
82 */ |
|
83 void CxeCameraDeviceDesktop::handleTimeout() |
|
84 { |
|
85 CX_DEBUG_ENTER_FUNCTION(); |
|
86 mPictureIndex++; |
|
87 |
|
88 if (mPictureIndex >= mPictureList.count()) { |
|
89 mPictureIndex = 0; |
|
90 } |
|
91 |
|
92 emit imageChanged(mPictureList.at(mPictureIndex)); |
|
93 CX_DEBUG_EXIT_FUNCTION(); |
|
94 } |
|
95 |
|
96 /*! |
|
97 * Load pictures |
|
98 */ |
|
99 void CxeCameraDeviceDesktop::loadPictures() |
|
100 { |
|
101 CX_DEBUG_ENTER_FUNCTION(); |
|
102 QDir currentDir(".","*.jpg"); |
|
103 |
|
104 if (!currentDir.count()) { |
|
105 mPictureList.append(QPixmap(360, 640)); |
|
106 return; |
|
107 } |
|
108 |
|
109 foreach (QString entry, currentDir.entryList()){ |
|
110 mPictureList.append(QPixmap(entry).scaledToHeight(360)); |
|
111 } |
|
112 CX_DEBUG_EXIT_FUNCTION(); |
|
113 } |
|
114 |
|
115 /*! |
|
116 * Create timer |
|
117 */ |
|
118 void CxeCameraDeviceDesktop::setupTimer() |
|
119 { |
|
120 CX_DEBUG_ENTER_FUNCTION(); |
|
121 mSwitchPictureTimer = new QTimer(this); |
|
122 mSwitchPictureTimer->setInterval(500); |
|
123 mSwitchPictureTimer->setSingleShot(false); |
|
124 connect(mSwitchPictureTimer, SIGNAL(timeout()), this, SLOT(handleTimeout())); |
|
125 CX_DEBUG_EXIT_FUNCTION(); |
|
126 } |
|