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