camerauis/cameraxui/cxui/src/cxuiview.cpp
changeset 39 c5025ea871a1
child 36 b12f3922a74f
equal deleted inserted replaced
38:0f0b4c1d7744 39:c5025ea871a1
       
     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 <hbtoolbar.h>
       
    21 #include <hbnotificationdialog.h>
       
    22 #include <hbframeitem.h>
       
    23 #include "cxuiview.h"
       
    24 #include "cxutils.h"
       
    25 #include "cxeengine.h"
       
    26 #include "cxuidocumentloader.h"
       
    27 #include "cxuicapturekeyhandler.h"
       
    28 #include "cxecameradevicecontrol.h"
       
    29 #include "cxevideocapturecontrol.h"
       
    30 #include "cxuizoomslider.h"
       
    31 #include "cxezoomcontrol.h"
       
    32 
       
    33 // CONSTANTS
       
    34 const QString PhotosAppExe = "photos.exe";
       
    35 const QString VideosAppExe = "videoplayer.exe";
       
    36 
       
    37 /*!
       
    38 * Constructor
       
    39 */
       
    40 CxuiView::CxuiView(QGraphicsItem *parent) :
       
    41         HbView(parent),
       
    42         mMainWindow(NULL),
       
    43         mEngine(NULL),
       
    44         mDocumentLoader(NULL),
       
    45         mSlider(NULL),
       
    46         mToolbar(NULL),
       
    47         mIndicators(NULL),
       
    48         mHideControlsTimeout(this)
       
    49 {
       
    50     CX_DEBUG_IN_FUNCTION();
       
    51 }
       
    52 
       
    53 /*!
       
    54 * Destructor
       
    55 */
       
    56 CxuiView::~CxuiView()
       
    57 {
       
    58     CX_DEBUG_IN_FUNCTION();
       
    59 }
       
    60 
       
    61 /*!
       
    62 * CxuiView::construct
       
    63 */
       
    64 void CxuiView::construct(HbMainWindow *mainWindow, CxeEngine *engine,
       
    65                          CxuiDocumentLoader *documentLoader,
       
    66                          CxuiCaptureKeyHandler * keyHandler)
       
    67 {
       
    68     CX_DEBUG_ENTER_FUNCTION();
       
    69 
       
    70     //Minimum requirements to construct the view
       
    71     CX_ASSERT_ALWAYS(mainWindow);
       
    72     CX_ASSERT_ALWAYS(engine);
       
    73     CX_ASSERT_ALWAYS(documentLoader);
       
    74 
       
    75     mMainWindow = mainWindow;
       
    76     mDocumentLoader = documentLoader;
       
    77     mCaptureKeyHandler = keyHandler;
       
    78     mEngine = engine;
       
    79 
       
    80     // adjust the timer, and connect it to correct slot
       
    81     connect(&mHideControlsTimeout, SIGNAL(timeout()), this, SLOT(hideControls()));
       
    82     mHideControlsTimeout.setSingleShot(true);
       
    83     mHideControlsTimeout.setInterval(CXUI_HIDE_CONTROLS_TIMEOUT);
       
    84 }
       
    85 
       
    86 /*!
       
    87 * CxuiView::updateOrientation
       
    88 */
       
    89 void CxuiView::updateOrientation(Qt::Orientation orientation)
       
    90 {
       
    91     CX_DEBUG_ENTER_FUNCTION();
       
    92 
       
    93     hideControls();
       
    94     mMainWindow->setOrientation(orientation);
       
    95 
       
    96     if (mToolbar) {
       
    97         if (orientation == Qt::Horizontal) {
       
    98             mToolbar->setOrientation(Qt::Vertical);
       
    99         } else {
       
   100             mToolbar->setOrientation(Qt::Horizontal);
       
   101         }
       
   102     }
       
   103 
       
   104     CX_DEBUG_EXIT_FUNCTION();
       
   105 }
       
   106 
       
   107 /*!
       
   108 * Allow showing UI controls?
       
   109 * Default behaviour is that controls can be shown at any time.
       
   110 */
       
   111 bool CxuiView::allowShowControls() const
       
   112 {
       
   113     return true;
       
   114 }
       
   115 
       
   116 /*!
       
   117 * Toggle visibility of UI controls.
       
   118 */
       
   119 void CxuiView::toggleControls()
       
   120 {
       
   121     CX_DEBUG_ENTER_FUNCTION();
       
   122 
       
   123     if (mControlsVisible) {
       
   124         hideControls();
       
   125     } else {
       
   126         showControls();
       
   127     }
       
   128 
       
   129     CX_DEBUG_EXIT_FUNCTION();
       
   130 }
       
   131 
       
   132 /*!
       
   133 * CxuiView::launchNotSupportedNotification
       
   134 * Show "not supported" notification.
       
   135 */
       
   136 void CxuiView::launchNotSupportedNotification()
       
   137 {
       
   138     CX_DEBUG_ENTER_FUNCTION();
       
   139     HbNotificationDialog::launchDialog("Notification", "Not supported yet");
       
   140     CX_DEBUG_EXIT_FUNCTION();
       
   141 }
       
   142 
       
   143 /*!
       
   144  * CxuiView::launchScenesView
       
   145  */
       
   146 void CxuiView::launchScenesView()
       
   147 {
       
   148     CX_DEBUG_ENTER_FUNCTION();
       
   149     hideControls();
       
   150     emit showScenesView();
       
   151     CX_DEBUG_EXIT_FUNCTION();
       
   152 }
       
   153 
       
   154 /*!
       
   155  * CxuiView::launchPhotosApp
       
   156  */
       
   157 void CxuiView::launchPhotosApp()
       
   158 {
       
   159     QProcess::startDetached(PhotosAppExe);
       
   160 }
       
   161 
       
   162 /*!
       
   163  * CxuiView::launchVideosApp
       
   164  * Launching Videos application as a separate process
       
   165  */
       
   166 void CxuiView::launchVideosApp()
       
   167 {
       
   168     //Releasing cameda device in order to free
       
   169     //graphical memory
       
   170     releaseCamera();
       
   171     QProcess::startDetached(VideosAppExe);
       
   172 }
       
   173 
       
   174 /*!
       
   175  * Releasing camera hw
       
   176  */
       
   177 void CxuiView::releaseCamera()
       
   178 {
       
   179     CX_DEBUG_ENTER_FUNCTION();
       
   180     mEngine->cameraDeviceControl().release();
       
   181     CX_DEBUG_EXIT_FUNCTION();
       
   182 }
       
   183 
       
   184 /*!
       
   185  * CxuiView::hideControls
       
   186  */
       
   187 void CxuiView::hideControls()
       
   188 {
       
   189     CX_DEBUG_ENTER_FUNCTION();
       
   190 
       
   191     if (mHideControlsTimeout.isActive()) {
       
   192         mHideControlsTimeout.stop();
       
   193     }
       
   194 
       
   195     // Hide title bar and status bar.
       
   196     //!@todo: View flags property is missing from HbView, so can't set these in DocML.
       
   197     HbView::HbViewFlags flags(HbView::ViewTitleBarTransparent
       
   198                             | HbView::ViewTitleBarFloating
       
   199                             | HbView::ViewTitleBarHidden
       
   200                             | HbView::ViewStatusBarTransparent
       
   201                             | HbView::ViewStatusBarFloating
       
   202                             | HbView::ViewStatusBarHidden);
       
   203     setViewFlags(flags);
       
   204     //!@todo: Once the flags are defined in DocML, we can just use these convenience functions
       
   205     //        to hide the title bar and status bar here.
       
   206     //setTitleBarVisible(false);
       
   207     //setStatusBarVisible(false);
       
   208 
       
   209     hideZoom();
       
   210 
       
   211     hideToolbar();
       
   212 
       
   213     // show indicators when controls are hidden
       
   214     showIndicators();
       
   215 
       
   216     mControlsVisible = false;
       
   217 
       
   218     // give the keyboard focus back to the view
       
   219     // for the view to receive key events
       
   220     setFocus();
       
   221 
       
   222     CX_DEBUG_EXIT_FUNCTION();
       
   223 }
       
   224 
       
   225 /*!
       
   226  * CxuiView::showControls
       
   227  */
       
   228 void CxuiView::showControls()
       
   229 {
       
   230     if (allowShowControls()) {
       
   231         // show toolbar
       
   232         showToolbar();
       
   233 
       
   234         // show zoom
       
   235         showZoom();
       
   236 
       
   237         // show title bar and status bar
       
   238         setTitleBarVisible(true);
       
   239         setStatusBarVisible(true);
       
   240 
       
   241         // hide indicators when controls are shown
       
   242         hideIndicators();
       
   243 
       
   244         mHideControlsTimeout.start();
       
   245         mControlsVisible = true;
       
   246     }
       
   247 }
       
   248 
       
   249 /*!
       
   250  * CxuiView::hideToolbar
       
   251  */
       
   252 void CxuiView::hideToolbar()
       
   253 {
       
   254     CX_DEBUG_ENTER_FUNCTION();
       
   255     if (mToolbar) {
       
   256         mToolbar->hide();
       
   257     }
       
   258     CX_DEBUG_EXIT_FUNCTION();
       
   259 }
       
   260 
       
   261 /*!
       
   262  * CxuiView::showToolbar
       
   263  */
       
   264 void CxuiView::showToolbar()
       
   265 {
       
   266     CX_DEBUG_ENTER_FUNCTION();
       
   267     if (mToolbar) {
       
   268         mToolbar->show();
       
   269     }
       
   270     CX_DEBUG_EXIT_FUNCTION();
       
   271 }
       
   272 
       
   273 /*!
       
   274  * CxuiView::hideIndicators
       
   275  */
       
   276 void CxuiView::hideIndicators()
       
   277 {
       
   278     if (mIndicators) {
       
   279         mIndicators->hide();
       
   280     }
       
   281 }
       
   282 
       
   283 /*!
       
   284  * CxuiView::showIndicators
       
   285  */
       
   286 void CxuiView::showIndicators()
       
   287 {
       
   288     if (mIndicators) {
       
   289         mIndicators->show();
       
   290     }
       
   291 }
       
   292 
       
   293 /*!
       
   294  * CxuiView::hideZoom
       
   295  */
       
   296 void CxuiView::hideZoom()
       
   297 {
       
   298     if (mSlider) {
       
   299         mSlider->hide();
       
   300     }
       
   301     mZoomVisible = false;
       
   302 }
       
   303 
       
   304 /*!
       
   305  * CxuiView::showZoom
       
   306  */
       
   307 void CxuiView::showZoom()
       
   308 {
       
   309     CX_DEBUG_ENTER_FUNCTION();
       
   310     if (mSlider) {
       
   311 
       
   312         // if maxVal has not been set yet, ask for new parameters from engine
       
   313         if (mSlider->maximum() <= 0) {
       
   314 
       
   315             // get the zoom range
       
   316             int min = mEngine->zoomControl().min();
       
   317             int max = mEngine->zoomControl().max();
       
   318 
       
   319             // only change values if they are acceptable and have changed
       
   320             if ((max - min > 0) && ((mSlider->maximum() != max) || (mSlider->minimum() != min))) {
       
   321                 mSlider->setRange(min, max);
       
   322             }
       
   323         }
       
   324 
       
   325         // show zoom only if the slider has acceptable value
       
   326         if (mSlider->maximum() > 0) {
       
   327             mSlider->show();
       
   328         }
       
   329     }
       
   330 
       
   331     mZoomVisible = true;
       
   332     CX_DEBUG_EXIT_FUNCTION();
       
   333 }
       
   334 
       
   335 /*!
       
   336 * Function can be used to create a graphics item and setting it as a background
       
   337 * item for HbWidget. graphicName refers to system wide graphic name. Given graphic
       
   338 * can consist of one, three or nine pieces. Nine piece graphics are used by default.
       
   339 * See HbFrameDrawer documentation for graphic naming.
       
   340 */
       
   341 void CxuiView::createWidgetBackgroundGraphic(HbWidget *widget,
       
   342                                                        const QString &graphicName,
       
   343                                                        HbFrameDrawer::FrameType frameType)
       
   344 {
       
   345     if (widget) {
       
   346         HbFrameDrawer *drawer = new HbFrameDrawer(graphicName, frameType);
       
   347 
       
   348         if (drawer) {
       
   349             HbFrameItem *backgroundItem = new HbFrameItem(drawer, widget);
       
   350             if (backgroundItem) {
       
   351                 // set item to fill the whole widget
       
   352                 backgroundItem->setGeometry(QRectF(QPointF(0, 0), widget->size()));
       
   353                 backgroundItem->setZValue(0);
       
   354                 widget->setBackgroundItem(backgroundItem);
       
   355             }
       
   356         }
       
   357     }
       
   358 }
       
   359 
       
   360 // End of file