phoneuis/bubblemanager2/bubblecore/src/bubblewidgetmanager.cpp
changeset 37 ba76fc04e6c2
child 46 bc5a64e5bc3c
equal deleted inserted replaced
36:2eacb6118286 37:ba76fc04e6c2
       
     1 /*
       
     2 * Copyright (c) 2009 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: Interface to HbDocumentLoader (DocML files).
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QtCore>
       
    19 #include <hbstyle.h>
       
    20 #include <hbdocumentloader.h>
       
    21 #include <hbframeitem.h>
       
    22 #include "bubblewidgetmanager.h"
       
    23 #include "bubblecontainerwidget.h"
       
    24 #include "bubbleimagewidget.h"
       
    25 #include "bubbleheadingwidget.h"
       
    26 #include "bubbleexpandedhandler.h"
       
    27 #include "bubblecollapsedhandler.h"
       
    28 #include "bubbleconferencehandler.h"
       
    29 #include "bubbleparticipantlistitem.h"
       
    30 #include "bubblebutton.h"
       
    31 #include "hbtextitem.h"
       
    32 
       
    33 const char *BUBBLE_DOCUMENT_CONTENT = "content";
       
    34 
       
    35 // document loader
       
    36 class BubbleDocumentLoader : public HbDocumentLoader
       
    37 {
       
    38 public:
       
    39     BubbleDocumentLoader(BubbleImageManager& imageManager);
       
    40     virtual QObject *createObject(const QString& type,
       
    41                                   const QString &name);
       
    42 private:
       
    43     BubbleImageManager& mImageManager;
       
    44 };
       
    45 
       
    46 
       
    47 BubbleWidgetManager::BubbleWidgetManager(
       
    48     BubbleImageManager& imageManager, QObject* parent)
       
    49     : QObject(parent), mImageManager(imageManager),
       
    50       mOrientation(Qt::Vertical)
       
    51 {
       
    52     // .docml mappings
       
    53     mFileNames.insert(SingleCallView,":/xml/bubble_layout_1.docml");
       
    54     mFileNames.insert(TwoCallsView,  ":/xml/bubble_layout_2.docml");
       
    55     mFileNames.insert(ThreeCallsView,":/xml/bubble_layout_3.docml");
       
    56     mFileNames.insert(ConferenceView,":/xml/bubble_layout_4.docml");
       
    57     mFileNames.insert(MutedOverlay,  ":/xml/bubble_layout_5.docml");
       
    58 
       
    59     mOrientationName.insert(Qt::Vertical,   "portrait");
       
    60     mOrientationName.insert(Qt::Horizontal, "landscape");
       
    61 
       
    62     mWidgetPrefix.insert(ExpandedBubble, "eb:");
       
    63     mWidgetPrefix.insert(CollapsedBubble,    "cb:");
       
    64     mWidgetPrefix.insert(CollapsedBubble2,    "cb2:");
       
    65     mContainerName.insert(ExpandedBubble, "expandedBubble");
       
    66     mContainerName.insert(CollapsedBubble,   "collapsedBubble");
       
    67     mContainerName.insert(CollapsedBubble2,   "collapsedBubble2");
       
    68     mWidgetName.insert(Heading,        "bubbleHeading");
       
    69     mWidgetName.insert(Image,          "callImage");
       
    70     mWidgetName.insert(LeftButton,     "leftButton");
       
    71     mWidgetName.insert(CenterButton,   "centerButton");
       
    72     mWidgetName.insert(RightButton,    "rightButton");
       
    73     mWidgetName.insert(ConferenceTimer,"callTimer");
       
    74     mWidgetName.insert(ParticipantList,"participantList");
       
    75     mWidgetName.insert(MutedIcon,      "mutedIcon");
       
    76 }
       
    77 
       
    78 BubbleWidgetManager::~BubbleWidgetManager()
       
    79 {
       
    80     qDeleteAll(mDocumentLoaders);
       
    81     mDocumentLoaders.clear();
       
    82 
       
    83     QList<int> keys = mDocumentHandlers.keys();
       
    84     foreach (int key, keys) {
       
    85         qDeleteAll(*mDocumentHandlers[key]);
       
    86     }
       
    87     qDeleteAll(mDocumentHandlers);
       
    88     mDocumentHandlers.clear();
       
    89 }
       
    90 
       
    91 QGraphicsWidget* BubbleWidgetManager::view(View view)
       
    92 {
       
    93     if (mDocumentContent.contains(view)) {
       
    94         // already loaded
       
    95         return mDocumentContent[view];
       
    96     } else {
       
    97         // load from .docml
       
    98         return loadDocument(view,mOrientation);
       
    99     }
       
   100 }
       
   101 
       
   102 void BubbleWidgetManager::releaseView(View view)
       
   103 {
       
   104     Q_UNUSED(view)
       
   105 }
       
   106 
       
   107 QGraphicsWidget* BubbleWidgetManager::loadDocument(
       
   108     View view,
       
   109     Qt::Orientation orientation)
       
   110 {
       
   111     BubbleDocumentLoader* loader =
       
   112         new BubbleDocumentLoader(mImageManager);
       
   113     bool ok;
       
   114 
       
   115     loader->load(mFileNames[view],&ok);
       
   116     Q_ASSERT(ok);
       
   117     loader->load(mFileNames[view],mOrientationName[orientation],&ok);
       
   118     Q_ASSERT(ok);
       
   119 
       
   120     mDocumentLoaders.insert(view,loader);
       
   121 
       
   122     QGraphicsWidget* widget =
       
   123         mDocumentLoaders[view]->findWidget(BUBBLE_DOCUMENT_CONTENT);
       
   124 
       
   125     Q_ASSERT(widget);
       
   126     widget->setVisible(false);
       
   127     mDocumentContent.insert(view,widget);
       
   128 
       
   129     if (view!=MutedOverlay) {
       
   130         createDocumentHandlers(view);
       
   131     }
       
   132 
       
   133     applyCustomStyles(view);
       
   134 
       
   135     return widget;
       
   136 }
       
   137 
       
   138 void BubbleWidgetManager::applyCustomStyles(View view)
       
   139 {
       
   140     setBackground(widget(view,None,MutedIcon));
       
   141 }
       
   142 
       
   143 void BubbleWidgetManager::setBackground(QGraphicsWidget* widget)
       
   144 {
       
   145     HbWidget* w;
       
   146     w = qobject_cast<HbWidget*>(widget);
       
   147     if (w) {
       
   148         HbFrameItem* item =
       
   149             new HbFrameItem("qtg_fr_popup_trans",HbFrameDrawer::NinePieces);
       
   150         w->setBackgroundItem(item); // takes ownership
       
   151     }
       
   152 }
       
   153 
       
   154 void BubbleWidgetManager::createDocumentHandlers(View view)
       
   155 {
       
   156     Q_ASSERT(mDocumentLoaders.contains(view));
       
   157 
       
   158     QList<BubbleHandler*>* handlers = new QList<BubbleHandler*>;
       
   159 
       
   160     if (mDocumentLoaders[view]->findWidget(mContainerName[ExpandedBubble]) ) {
       
   161         if (view==ConferenceView) {
       
   162             BubbleConferenceHandler* handler =
       
   163                 new BubbleConferenceHandler(*this,view,ExpandedBubble);
       
   164             handlers->append(handler);
       
   165         } else {
       
   166             BubbleExpandedHandler* handler =
       
   167                 new BubbleExpandedHandler(*this,view,ExpandedBubble);
       
   168             handlers->append(handler);
       
   169         }
       
   170     }
       
   171 
       
   172     if (mDocumentLoaders[view]->findWidget(mContainerName[CollapsedBubble]) ) {
       
   173         BubbleCollapsedHandler* handler =
       
   174             new BubbleCollapsedHandler(*this,view,CollapsedBubble);
       
   175         handlers->append(handler);
       
   176     }
       
   177 
       
   178     if (mDocumentLoaders[view]->findWidget(mContainerName[CollapsedBubble2]) ) {
       
   179         BubbleCollapsedHandler* handler =
       
   180             new BubbleCollapsedHandler(*this,view,CollapsedBubble2);
       
   181         handlers->append(handler);
       
   182     }
       
   183 
       
   184 
       
   185     mDocumentHandlers.insert(view,handlers);
       
   186 }
       
   187 
       
   188 QGraphicsWidget* BubbleWidgetManager::container(
       
   189     View view,
       
   190     Container container) const
       
   191 {
       
   192     QGraphicsWidget* w=0;
       
   193 
       
   194     if (mDocumentLoaders.contains(view)) {
       
   195         w = mDocumentLoaders.value(view)->findWidget(
       
   196             mContainerName[container]);
       
   197     }
       
   198 
       
   199     return w;
       
   200 }
       
   201 
       
   202 
       
   203 QGraphicsWidget* BubbleWidgetManager::widget(
       
   204     View view,
       
   205     Container container,
       
   206     Widget widget ) const
       
   207 {
       
   208     QGraphicsWidget* w=0;
       
   209 
       
   210     if (mDocumentLoaders.contains(view)) {
       
   211         QString name;
       
   212         name.append(mWidgetPrefix.value(container));
       
   213         name.append(mWidgetName.value(widget));
       
   214         w = mDocumentLoaders.value(view)->findWidget(name);
       
   215     }
       
   216 
       
   217     return w;
       
   218 }
       
   219 
       
   220 QList<BubbleHandler*>* BubbleWidgetManager::handlers(
       
   221     QGraphicsWidget* widget) const
       
   222 {
       
   223     int doc = mDocumentContent.key(widget);
       
   224     return mDocumentHandlers[doc];
       
   225 }
       
   226 
       
   227 void BubbleWidgetManager::handleOrientationChange(
       
   228     Qt::Orientation orientation)
       
   229 {
       
   230     if (mOrientation!=orientation) {
       
   231         bool ok;
       
   232         QList<int> docs = mDocumentLoaders.keys();
       
   233         foreach (int doc, docs) {
       
   234             mDocumentLoaders[doc]->load(
       
   235                 mFileNames[doc],mOrientationName.value(orientation),&ok);
       
   236             Q_ASSERT(ok);
       
   237         }
       
   238         mOrientation = orientation;
       
   239     }
       
   240 }
       
   241 
       
   242 QGraphicsWidget* BubbleWidgetManager::createParticipantListItem()
       
   243 {
       
   244     return new BubbleParticipantListItem();
       
   245 }
       
   246 
       
   247 // custom widget loading
       
   248 BubbleDocumentLoader::BubbleDocumentLoader(BubbleImageManager& imageManager)
       
   249     : mImageManager(imageManager)
       
   250 {
       
   251 }
       
   252 
       
   253 QObject *BubbleDocumentLoader::createObject(
       
   254     const QString& type,
       
   255     const QString &name)
       
   256 {
       
   257     if ( type == BubbleContainerWidget::staticMetaObject.className() ) {
       
   258         QObject *object = new BubbleContainerWidget();
       
   259         object->setObjectName(name);
       
   260         return object;
       
   261     }
       
   262 
       
   263     if ( type == BubbleImageWidget::staticMetaObject.className() ) {
       
   264         QObject *object = new BubbleImageWidget(mImageManager);
       
   265         object->setObjectName(name);
       
   266         return object;
       
   267     }
       
   268 
       
   269     if ( type == BubbleHeadingWidget::staticMetaObject.className() ) {
       
   270         QObject *object = new BubbleHeadingWidget();
       
   271         object->setObjectName(name);
       
   272         return object;
       
   273     }
       
   274 
       
   275     if ( type == BubbleButton::staticMetaObject.className() ) {
       
   276         QObject *object = new BubbleButton;
       
   277         object->setObjectName(name);
       
   278         return object;
       
   279     }
       
   280 
       
   281     return HbDocumentLoader::createObject(type, name);
       
   282 }
       
   283