camerauis/cameraxui/cxui/src/cxuiview.cpp
branchRCL_3
changeset 24 bac7acad7cb3
parent 23 61bc0f252b2b
child 25 2c87b2808fd7
equal deleted inserted replaced
23:61bc0f252b2b 24:bac7acad7cb3
     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 <QGraphicsItem>
       
    19 #include <QProcess>
       
    20 #include <QGraphicsSceneEvent>
       
    21 #include <hbtoolbar.h>
       
    22 #include <hbnotificationdialog.h>
       
    23 #include <hbframeitem.h>
       
    24 #include <hbeffect.h>
       
    25 #include "cxuiview.h"
       
    26 #include "cxutils.h"
       
    27 #include "cxeengine.h"
       
    28 #include "cxuidocumentloader.h"
       
    29 #include "cxuicapturekeyhandler.h"
       
    30 #include "cxecameradevicecontrol.h"
       
    31 #include "cxevideocapturecontrol.h"
       
    32 #include "cxuizoomslider.h"
       
    33 #include "cxezoomcontrol.h"
       
    34 
       
    35 // CONSTANTS
       
    36 const QString PhotosAppExe = "photos.exe";
       
    37 const QString VideosAppExe = "videoplayer.exe";
       
    38 
       
    39 /*!
       
    40 * Constructor
       
    41 */
       
    42 CxuiView::CxuiView(QGraphicsItem *parent) :
       
    43         HbView(parent),
       
    44         mMainWindow(NULL),
       
    45         mEngine(NULL),
       
    46         mDocumentLoader(NULL),
       
    47         mSlider(NULL),
       
    48         mToolbar(NULL),
       
    49         mIndicators(NULL),
       
    50         mHideControlsTimeout(this),
       
    51         mControlsFeedback(HbFeedback::BasicItem)
       
    52 {
       
    53     CX_DEBUG_IN_FUNCTION();
       
    54 }
       
    55 
       
    56 /*!
       
    57 * Destructor
       
    58 */
       
    59 CxuiView::~CxuiView()
       
    60 {
       
    61     CX_DEBUG_IN_FUNCTION();
       
    62 }
       
    63 
       
    64 /*!
       
    65 * CxuiView::construct
       
    66 */
       
    67 void CxuiView::construct(HbMainWindow *mainWindow, CxeEngine *engine,
       
    68                          CxuiDocumentLoader *documentLoader,
       
    69                          CxuiCaptureKeyHandler * keyHandler,
       
    70                          HbActivityManager *activityManager)
       
    71 {
       
    72     CX_DEBUG_ENTER_FUNCTION();
       
    73 
       
    74     //Minimum requirements to construct the view
       
    75     CX_ASSERT_ALWAYS(mainWindow);
       
    76     CX_ASSERT_ALWAYS(engine);
       
    77     CX_ASSERT_ALWAYS(documentLoader);
       
    78     CX_ASSERT_ALWAYS(activityManager);
       
    79 
       
    80     mMainWindow = mainWindow;
       
    81     mDocumentLoader = documentLoader;
       
    82     mCaptureKeyHandler = keyHandler;
       
    83     mEngine = engine;
       
    84     mActivityManager = activityManager;
       
    85 
       
    86     // adjust the timer, and connect it to correct slot
       
    87     connect(&mHideControlsTimeout, SIGNAL(timeout()), this, SLOT(hideControls()));
       
    88     mHideControlsTimeout.setSingleShot(true);
       
    89     mHideControlsTimeout.setInterval(CXUI_HIDE_CONTROLS_TIMEOUT);
       
    90     
       
    91     HbEffect::add("zoombar", "camera_zoom_appear", "zoom_appear");
       
    92     HbEffect::add("zoombar", "camera_zoom_disappear", "zoom_disappear");
       
    93     
       
    94     mControlsFeedback.setOwningWindow(mMainWindow);
       
    95     CX_DEBUG_EXIT_FUNCTION();
       
    96 }
       
    97 
       
    98 /*!
       
    99 * Is standby mode supported / needed by this view.
       
   100 * Default implementation returns false.
       
   101 * Inherited classes need to re-implement this if standby mode is needed.
       
   102 * @return True if standby mode is supported, false otherwise.
       
   103 */
       
   104 bool CxuiView::isStandbyModeSupported() const
       
   105 {
       
   106     return false;
       
   107 }
       
   108 
       
   109 
       
   110 /*!
       
   111 * CxuiView::updateOrientation
       
   112 */
       
   113 void CxuiView::updateOrientation(Qt::Orientation orientation)
       
   114 {
       
   115     CX_DEBUG_ENTER_FUNCTION();
       
   116 
       
   117     hideControls();
       
   118     mMainWindow->setOrientation(orientation);
       
   119 
       
   120     if (mToolbar) {
       
   121         if (orientation == Qt::Horizontal) {
       
   122             mToolbar->setOrientation(Qt::Vertical);
       
   123         } else {
       
   124             mToolbar->setOrientation(Qt::Horizontal);
       
   125         }
       
   126     }
       
   127 
       
   128     CX_DEBUG_EXIT_FUNCTION();
       
   129 }
       
   130 
       
   131 
       
   132 /*!
       
   133  * Restore view state from activity. Default implementation does nothing.
       
   134  */
       
   135 void CxuiView::restoreActivity(const QString &activityId, const QVariant &data)
       
   136 {
       
   137     Q_UNUSED(activityId);
       
   138     Q_UNUSED(data);
       
   139 }
       
   140 
       
   141 /*!
       
   142  * Save view state to activity. Default implementation does nothing.
       
   143  */
       
   144 void CxuiView::saveActivity()
       
   145 {
       
   146 
       
   147 }
       
   148 
       
   149 /*!
       
   150  * Clear activity from activity manager. Default implementation does nothing.
       
   151  */
       
   152 void CxuiView::clearActivity()
       
   153 {
       
   154 
       
   155 }
       
   156 
       
   157 /*!
       
   158 * Allow showing UI controls?
       
   159 * Default behaviour is that controls can be shown at any time.
       
   160 */
       
   161 bool CxuiView::allowShowControls() const
       
   162 {
       
   163     return true;
       
   164 }
       
   165 
       
   166 /*!
       
   167  * Play feedback when touching view outside of any widget?
       
   168  * Default behaviour is that feedback is always played.
       
   169  */
       
   170 bool CxuiView::isFeedbackEnabled() const
       
   171 {
       
   172     return true;
       
   173 }
       
   174 
       
   175 /*!
       
   176 * Toggle visibility of UI controls.
       
   177 */
       
   178 void CxuiView::toggleControls()
       
   179 {
       
   180     CX_DEBUG_ENTER_FUNCTION();
       
   181 
       
   182     if (mControlsVisible) {
       
   183         hideControls();
       
   184     } else {
       
   185         showControls();
       
   186     }
       
   187 
       
   188     CX_DEBUG_EXIT_FUNCTION();
       
   189 }
       
   190 
       
   191 /*!
       
   192 * Slot for entering standby mode.
       
   193 * By default, release camera.
       
   194 */
       
   195 void CxuiView::enterStandby()
       
   196 {
       
   197     CX_DEBUG_IN_FUNCTION();
       
   198     releaseCamera();
       
   199     CX_DEBUG_IN_FUNCTION();
       
   200 }
       
   201 
       
   202 /*!
       
   203 * Slot for exiting standby mode.
       
   204 * By default, no action needed.
       
   205 */
       
   206 void CxuiView::exitStandby()
       
   207 {
       
   208     CX_DEBUG_IN_FUNCTION();
       
   209 }
       
   210 
       
   211 /*!
       
   212 * CxuiView::launchNotSupportedNotification
       
   213 * Show "not supported" notification.
       
   214 */
       
   215 void CxuiView::launchNotSupportedNotification()
       
   216 {
       
   217     CX_DEBUG_ENTER_FUNCTION();
       
   218     HbNotificationDialog::launchDialog("Notification", "Not supported yet");
       
   219     CX_DEBUG_EXIT_FUNCTION();
       
   220 }
       
   221 
       
   222 /*!
       
   223  * CxuiView::launchScenesView
       
   224  */
       
   225 void CxuiView::launchScenesView()
       
   226 {
       
   227     CX_DEBUG_ENTER_FUNCTION();
       
   228     hideControls();
       
   229     emit showScenesView();
       
   230     CX_DEBUG_EXIT_FUNCTION();
       
   231 }
       
   232 
       
   233 /*!
       
   234  * CxuiView::launchPhotosApp
       
   235  */
       
   236 void CxuiView::launchPhotosApp()
       
   237 {
       
   238     // Release camera device in order to free resources for Photos application
       
   239     releaseCamera();
       
   240     QProcess::startDetached(PhotosAppExe);
       
   241 }
       
   242 
       
   243 /*!
       
   244  * CxuiView::launchVideosApp
       
   245  * Launching Videos application as a separate process
       
   246  */
       
   247 void CxuiView::launchVideosApp()
       
   248 {
       
   249     // Release camera device in order to free resources for Videos application
       
   250     releaseCamera();
       
   251     QProcess::startDetached(VideosAppExe);
       
   252 }
       
   253 
       
   254 /*!
       
   255  * Releasing camera hw
       
   256  */
       
   257 void CxuiView::releaseCamera()
       
   258 {
       
   259     CX_DEBUG_ENTER_FUNCTION();
       
   260     mEngine->cameraDeviceControl().release();
       
   261     CX_DEBUG_EXIT_FUNCTION();
       
   262 }
       
   263 
       
   264 /*!
       
   265  * CxuiView::hideControls
       
   266  */
       
   267 void CxuiView::hideControls()
       
   268 {
       
   269     CX_DEBUG_ENTER_FUNCTION();
       
   270 
       
   271     if (mHideControlsTimeout.isActive()) {
       
   272         mHideControlsTimeout.stop();
       
   273     }
       
   274 
       
   275     setTitleBarVisible(false);
       
   276     setStatusBarVisible(false);
       
   277 
       
   278     hideZoom();
       
   279 
       
   280     hideToolbar();
       
   281 
       
   282     // show indicators when controls are hidden
       
   283     showIndicators();
       
   284 
       
   285     mControlsVisible = false;
       
   286 
       
   287     // give the keyboard focus back to the view
       
   288     // for the view to receive key events
       
   289     setFocus();
       
   290 
       
   291     CX_DEBUG_EXIT_FUNCTION();
       
   292 }
       
   293 
       
   294 /*!
       
   295  * CxuiView::showControls
       
   296  */
       
   297 void CxuiView::showControls()
       
   298 {
       
   299     if (allowShowControls()) {
       
   300         // show toolbar
       
   301         showToolbar();
       
   302 
       
   303         // show zoom
       
   304         showZoom();
       
   305 
       
   306         // show title bar and status bar
       
   307         setTitleBarVisible(true);
       
   308         setStatusBarVisible(true);
       
   309 
       
   310         // hide indicators when controls are shown
       
   311         hideIndicators();
       
   312 
       
   313         mHideControlsTimeout.start();
       
   314         mControlsVisible = true;
       
   315     }
       
   316 }
       
   317 
       
   318 /*!
       
   319  * CxuiView::hideToolbar
       
   320  */
       
   321 void CxuiView::hideToolbar()
       
   322 {
       
   323     CX_DEBUG_ENTER_FUNCTION();
       
   324     if (mToolbar) {
       
   325         mToolbar->hide();
       
   326     }
       
   327     CX_DEBUG_EXIT_FUNCTION();
       
   328 }
       
   329 
       
   330 /*!
       
   331  * CxuiView::showToolbar
       
   332  */
       
   333 void CxuiView::showToolbar()
       
   334 {
       
   335     CX_DEBUG_ENTER_FUNCTION();
       
   336     if (mToolbar) {
       
   337         mToolbar->show();
       
   338     }
       
   339     CX_DEBUG_EXIT_FUNCTION();
       
   340 }
       
   341 
       
   342 /*!
       
   343  * CxuiView::hideIndicators
       
   344  */
       
   345 void CxuiView::hideIndicators()
       
   346 {
       
   347     if (mIndicators) {
       
   348         mIndicators->hide();
       
   349     }
       
   350 }
       
   351 
       
   352 /*!
       
   353  * CxuiView::showIndicators
       
   354  */
       
   355 void CxuiView::showIndicators()
       
   356 {
       
   357     if (mIndicators) {
       
   358         mIndicators->show();
       
   359     }
       
   360 }
       
   361 
       
   362 /*!
       
   363  * CxuiView::hideZoom
       
   364  */
       
   365 void CxuiView::hideZoom()
       
   366 {
       
   367     if (mSlider) {
       
   368         // Hiding of the slider will be done after effect has finished
       
   369         HbEffect::start(mSlider, "zoombar", "zoom_disappear", this, "zoomDisappearEffectFinished");
       
   370     }
       
   371     mZoomVisible = false;
       
   372 }
       
   373 
       
   374 /*!
       
   375  * CxuiView::showZoom
       
   376  */
       
   377 void CxuiView::showZoom()
       
   378 {
       
   379     CX_DEBUG_ENTER_FUNCTION();
       
   380     if (mSlider) {
       
   381 
       
   382         // if maxVal has not been set yet, ask for new parameters from engine
       
   383         if (mSlider->maximum() <= 0) {
       
   384 
       
   385             // get the zoom range
       
   386             int min = mEngine->zoomControl().min();
       
   387             int max = mEngine->zoomControl().max();
       
   388 
       
   389             // only change values if they are acceptable and have changed
       
   390             if ((max - min > 0) && ((mSlider->maximum() != max) || (mSlider->minimum() != min))) {
       
   391                 mSlider->setRange(min, max);
       
   392             }
       
   393         }
       
   394 
       
   395         // show zoom only if the slider has acceptable value
       
   396         if (mSlider->maximum() > 0) {
       
   397             mSlider->show();
       
   398         }
       
   399         HbEffect::start(mSlider, "zoombar", "zoom_appear");
       
   400     }
       
   401 
       
   402     mZoomVisible = true;
       
   403     CX_DEBUG_EXIT_FUNCTION();
       
   404 }
       
   405 
       
   406 /*!
       
   407 * Function can be used to create a graphics item and setting it as a background
       
   408 * item for HbWidget. graphicName refers to system wide graphic name. Given graphic
       
   409 * can consist of one, three or nine pieces. Nine piece graphics are used by default.
       
   410 * See HbFrameDrawer documentation for graphic naming.
       
   411 */
       
   412 void CxuiView::createWidgetBackgroundGraphic(HbWidget *widget,
       
   413                                                        const QString &graphicName,
       
   414                                                        HbFrameDrawer::FrameType frameType)
       
   415 {
       
   416     if (widget) {
       
   417         HbFrameDrawer *drawer = new HbFrameDrawer(graphicName, frameType);
       
   418 
       
   419         if (drawer) {
       
   420             HbFrameItem *backgroundItem = new HbFrameItem(drawer, widget);
       
   421             if (backgroundItem) {
       
   422                 // set item to fill the whole widget
       
   423                 backgroundItem->setGeometry(QRectF(QPointF(0, 0), widget->size()));
       
   424                 backgroundItem->setZValue(0);
       
   425                 widget->setBackgroundItem(backgroundItem);
       
   426             }
       
   427         }
       
   428     }
       
   429 }
       
   430 
       
   431 /*!
       
   432  * Handle mouse press events on this view. Needed to implement toggling of
       
   433  * controls and playing feedback.
       
   434  * \param event event to be handled
       
   435  */
       
   436 void CxuiView::mousePressEvent(QGraphicsSceneMouseEvent *event)
       
   437 {
       
   438     //! @todo temporary workaround for title bar mouse event handling bug
       
   439     if (event->type() == QEvent::GraphicsSceneMousePress && event->scenePos().y() > 70 &&
       
   440         isFeedbackEnabled()) {
       
   441         mControlsFeedback.setModalities(HbFeedback::All);
       
   442         mControlsFeedback.play();
       
   443         event->accept();
       
   444     }
       
   445 }
       
   446 
       
   447 /*!
       
   448  * Handle mouse release events on this view. Needed to implement toggling of
       
   449  * controls and playing feedback.
       
   450  * \param event to be handled
       
   451  */
       
   452 void CxuiView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
       
   453 {
       
   454     //! @todo temporary workaround for title bar mouse event handling bug
       
   455     if (event->type() == QEvent::GraphicsSceneMouseRelease && event->scenePos().y() > 70 &&
       
   456         isFeedbackEnabled()) {        
       
   457         mControlsFeedback.setModalities(HbFeedback::Tactile);
       
   458         mControlsFeedback.play();
       
   459         toggleControls();
       
   460         event->accept();
       
   461     }
       
   462 }
       
   463 
       
   464 void CxuiView::zoomDisappearEffectFinished(const HbEffect::EffectStatus &status) {
       
   465     if (mSlider) {
       
   466         mSlider->hide();
       
   467     }
       
   468 }
       
   469 
       
   470 void CxuiView::zoomAppearEffectFinished(const HbEffect::EffectStatus &status) {
       
   471 }
       
   472 
       
   473 // End of file