camerauis/cameraxui/cxui/src/cxuifullscreenpopup.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 <QGraphicsScene>
       
    19 #include <QGraphicsRectItem>
       
    20 #include <QGraphicsAnchorLayout>
       
    21 #include <HbLabel>
       
    22 #include <HbPushButton>
       
    23 #include <HbInstantFeedback>
       
    24 #include "cxutils.h"
       
    25 #include "cxuienums.h"
       
    26 #include "cxuiview.h"
       
    27 #include "cxuidocumentloader.h"
       
    28 #include "cxuifullscreenpopup.h"
       
    29 
       
    30 /*!
       
    31 * Constructor.
       
    32 */
       
    33 CxuiFullScreenPopup::CxuiFullScreenPopupLoader::CxuiFullScreenPopupLoader()
       
    34     : HbDocumentLoader()
       
    35 {
       
    36 }
       
    37 
       
    38 /*!
       
    39 * Create object from DocML.
       
    40 * Custom type of object created when object name matches the full screen dialog one.
       
    41 * Other items are propagated to HbDocumentLoader for standard handling.
       
    42 * @param type Object type (class name)
       
    43 * @param name Object name, name of the item in DocML.
       
    44 */
       
    45 QObject *CxuiFullScreenPopup::CxuiFullScreenPopupLoader::createObject(const QString& type, const QString &name)
       
    46 {
       
    47     CX_DEBUG_ENTER_FUNCTION();
       
    48     QObject *object = NULL;
       
    49 
       
    50     // HbWidget as type in DocML to support UI layout tool.
       
    51     if (type == "HbWidget") {
       
    52         if (name == CxUiLayout::FULL_SCREEN_POPUP) {
       
    53             object = new CxuiFullScreenPopup();
       
    54         }
       
    55     }
       
    56 
       
    57     if (object) {
       
    58         object->setObjectName(name);
       
    59     } else {
       
    60         object = HbDocumentLoader::createObject(type, name);
       
    61     }
       
    62 
       
    63     CX_DEBUG_EXIT_FUNCTION();
       
    64     return object;
       
    65 }
       
    66 
       
    67 /*!
       
    68 * Load a full screen popup from DocML and set given message and action text to it.
       
    69 * @param scene Graphics scene where to insert the popup.
       
    70 * @param message Popup message text.
       
    71 * @param action Popup action button text.
       
    72 */
       
    73 CxuiFullScreenPopup *CxuiFullScreenPopup::create(QGraphicsScene *scene,
       
    74                                                  const QString &message,
       
    75                                                  const QString &action)
       
    76 {
       
    77     CX_DEBUG_ENTER_FUNCTION();
       
    78 
       
    79     bool ok(true);
       
    80 
       
    81     // Load popup structure from DocML.
       
    82     CxuiFullScreenPopupLoader *loader = new CxuiFullScreenPopupLoader();
       
    83     loader->load(CxUiLayout::FULL_SCREEN_POPUP_XML, &ok);
       
    84     CX_ASSERT_ALWAYS(ok);
       
    85 
       
    86     // Popup container widget.
       
    87     CxuiFullScreenPopup *popup = qobject_cast<CxuiFullScreenPopup *>(loader->findWidget(CxUiLayout::FULL_SCREEN_POPUP));
       
    88     CX_ASSERT_ALWAYS(popup);
       
    89     // Popup needs scene to move in front of all widgets.
       
    90     popup->setScene(scene);
       
    91     // Add background graphic for popup.
       
    92     QGraphicsRectItem *bg = new QGraphicsRectItem(popup);
       
    93     bg->setRect(popup->geometry());
       
    94     bg->setBrush(Qt::black);
       
    95     popup->setBackgroundItem(bg);
       
    96 
       
    97     // Popup text.
       
    98     //!@todo: Move text color definition to DocML once supported there.
       
    99     HbLabel *text = qobject_cast<HbLabel*>(loader->findWidget(CxUiLayout::FULL_SCREEN_POPUP_TEXT));
       
   100     CX_ASSERT_ALWAYS(text);
       
   101     text->setPlainText(message);
       
   102     text->setTextColor(Qt::white);
       
   103 
       
   104     // Action button.
       
   105     // Hidden if empty text given.
       
   106     HbPushButton *button = qobject_cast<HbPushButton*>(loader->findWidget(CxUiLayout::FULL_SCREEN_POPUP_BUTTON));
       
   107     CX_ASSERT_ALWAYS(button);
       
   108     if (action.isEmpty()) {
       
   109         CX_DEBUG(("CxuiFullScreenPopup - no button text given, hiding button.."));
       
   110         button->setVisible(false);
       
   111     } else {
       
   112         button->setText(action);
       
   113     }
       
   114 
       
   115     delete loader;
       
   116     loader = NULL;
       
   117 
       
   118     CX_DEBUG_EXIT_FUNCTION();
       
   119     return popup;
       
   120 }
       
   121 
       
   122 /*!
       
   123 * Popup destructor.
       
   124 */
       
   125 CxuiFullScreenPopup::~CxuiFullScreenPopup()
       
   126 {
       
   127     CX_DEBUG_ENTER_FUNCTION();
       
   128     hide();
       
   129     CX_DEBUG_EXIT_FUNCTION();
       
   130 }
       
   131 
       
   132 /*!
       
   133 * Handle mouse press event.
       
   134 */
       
   135 void CxuiFullScreenPopup::handleMousePress()
       
   136 {
       
   137     CX_DEBUG_ENTER_FUNCTION();
       
   138     // Give standard feedback.
       
   139     HbInstantFeedback feedback(HbFeedback::BasicItem);
       
   140     feedback.setModalities(HbFeedback::All);
       
   141     feedback.play();
       
   142     CX_DEBUG_EXIT_FUNCTION();
       
   143 }
       
   144 
       
   145 /*!
       
   146 * Handle mouse release event.
       
   147 */
       
   148 void CxuiFullScreenPopup::handleMouseRelease()
       
   149 {
       
   150     CX_DEBUG_ENTER_FUNCTION();
       
   151     //!@todo: sound disabling doesn't work in orbit yet so don't do feedback on release
       
   152     // needs to be enabled when orbit support is done
       
   153     // Give tactile feedback but no sound feedback on mouse release.
       
   154     /*
       
   155     HbInstantFeedback feedback(HbFeedback::BasicItem);
       
   156     feedback.setModalities(HbFeedback::Tactile);
       
   157     feedback.play();
       
   158     CX_DEBUG_EXIT_FUNCTION();
       
   159     */
       
   160 }
       
   161 
       
   162 /*!
       
   163 * Show the popup.
       
   164 * Checks current top most item in the scene and adds this popup in front of it.
       
   165 * Input to below widgets is blocked.
       
   166 */
       
   167 void CxuiFullScreenPopup::show()
       
   168 {
       
   169     CX_DEBUG_ENTER_FUNCTION();
       
   170 
       
   171     CX_ASSERT_ALWAYS(mScene);
       
   172 
       
   173     if (!mPopupShown) {
       
   174         mPopupShown = true;
       
   175         // Store current top item z value.
       
   176         qreal topZ(topZValue());
       
   177         // Add popup widget to scene to actually get it visible.
       
   178         mScene->addItem(this);
       
   179         // Make sure popup is just above the top item.
       
   180         setZValue(topZ + 1);
       
   181 
       
   182         // Block input to other widgets below the popup.
       
   183         setWindowFlags(Qt::Dialog);
       
   184         setPanelModality(QGraphicsItem::PanelModal);
       
   185 
       
   186         // Show popup.
       
   187         HbWidget::show();
       
   188     }
       
   189     CX_DEBUG_EXIT_FUNCTION();
       
   190 }
       
   191 
       
   192 /*!
       
   193 * Hide the popup.
       
   194 */
       
   195 void CxuiFullScreenPopup::hide()
       
   196 {
       
   197     CX_DEBUG_ENTER_FUNCTION();
       
   198 
       
   199     if (mPopupShown) {
       
   200         HbWidget::hide();
       
   201         // Double check non-nullness.
       
   202         if (mScene) {
       
   203             mScene->removeItem(this);
       
   204         }
       
   205         mPopupShown = false;
       
   206     }
       
   207     CX_DEBUG_EXIT_FUNCTION();
       
   208 }
       
   209 
       
   210 /*!
       
   211 * Get the z value of top item in scene.
       
   212 * @return Top (max) z value.
       
   213 */
       
   214 qreal CxuiFullScreenPopup::topZValue() const
       
   215 {
       
   216     CX_DEBUG_ENTER_FUNCTION();
       
   217 
       
   218     qreal z(0);
       
   219     if (mScene) {
       
   220         const QList<QGraphicsItem *> itemList(mScene->items(Qt::DescendingOrder));
       
   221         foreach (QGraphicsItem *item, itemList) {
       
   222             // Max of z values.
       
   223             z = (item && item->zValue() > z) ? item->zValue() : z;
       
   224 #ifdef CX_DEBUG
       
   225             const QGraphicsObject *gObject(item->toGraphicsObject());
       
   226             CX_DEBUG(("Item of class [%s] z value [%s]",
       
   227                       gObject ? gObject->metaObject()->className() : qPrintable(QString("QGraphicsItem")),
       
   228                       qPrintable(QString::number(item->zValue()))));
       
   229 #endif // CX_DEBUG
       
   230         }
       
   231     } else {
       
   232         CX_DEBUG(("[WARNING] No scene found, returning zero"));
       
   233     }
       
   234     CX_DEBUG_EXIT_FUNCTION();
       
   235     return z;
       
   236 }
       
   237 
       
   238 /*!
       
   239 * Store the scene in which this popup is to be shown.
       
   240 */
       
   241 void CxuiFullScreenPopup::setScene(QGraphicsScene *scene)
       
   242 {
       
   243     mScene = scene;
       
   244 }
       
   245 
       
   246 /*!
       
   247 * Popup (private) constructor.
       
   248 */
       
   249 CxuiFullScreenPopup::CxuiFullScreenPopup()
       
   250     : mScene(NULL),
       
   251       mPopupShown(false)
       
   252 {
       
   253     CX_DEBUG_IN_FUNCTION();
       
   254 }
       
   255 
       
   256 // end of file