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