phoneuis/bubblemanager2/bubblecore/src/bubblewidgetmanager.cpp
changeset 30 ebdbd102c78a
parent 27 2f8f8080a020
child 51 f39ed5e045e0
equal deleted inserted replaced
27:2f8f8080a020 30:ebdbd102c78a
    25 #include "bubbleheadingwidget.h"
    25 #include "bubbleheadingwidget.h"
    26 #include "bubbleexpandedhandler.h"
    26 #include "bubbleexpandedhandler.h"
    27 #include "bubblecollapsedhandler.h"
    27 #include "bubblecollapsedhandler.h"
    28 #include "bubbleconferencehandler.h"
    28 #include "bubbleconferencehandler.h"
    29 #include "bubbleparticipantlistitem.h"
    29 #include "bubbleparticipantlistitem.h"
    30 #include "bubblebuttonstyle.h"
    30 #include "bubblebutton.h"
    31 #include "hbpushbutton.h"
       
    32 #include "hbtextitem.h"
    31 #include "hbtextitem.h"
    33 
    32 
    34 const char *BUBBLE_DOCUMENT_CONTENT = "content";
    33 const char *BUBBLE_DOCUMENT_CONTENT = "content";
    35 
    34 
    36 // document loader
    35 // document loader
    37 class BubbleDocumentLoader : public HbDocumentLoader
    36 class BubbleDocumentLoader : public HbDocumentLoader
    38 {
    37 {
    39 public:
    38 public:
    40     BubbleDocumentLoader(BubbleImageManager& imageManager,
    39     BubbleDocumentLoader(BubbleImageManager& imageManager);
    41                          const QString& stylePluginName);
       
    42     virtual QObject *createObject(const QString& type,
    40     virtual QObject *createObject(const QString& type,
    43                                   const QString &name);
    41                                   const QString &name);
    44 private:
    42 private:
    45     BubbleImageManager& mImageManager;
    43     BubbleImageManager& mImageManager;
    46     QString mStylePluginName;    
       
    47 };
    44 };
    48 
    45 
    49 
    46 
    50 BubbleWidgetManager::BubbleWidgetManager(
    47 BubbleWidgetManager::BubbleWidgetManager(
    51     BubbleImageManager& imageManager, int style, QObject* parent)
    48     BubbleImageManager& imageManager, QObject* parent)
    52     : QObject(parent), mImageManager(imageManager), mStyleBaseId(style),
    49     : QObject(parent), mImageManager(imageManager),
    53       mOrientation(Qt::Vertical)
    50       mOrientation(Qt::Vertical)
    54 {
    51 {
    55     // .docml mappings
    52     // .docml mappings
    56     mFileNames.insert(SingleCallView,":/xml/bubble_layout_1.docml");
    53     mFileNames.insert(SingleCallView,":/xml/bubble_layout_1.docml");
    57     mFileNames.insert(TwoCallsView,  ":/xml/bubble_layout_2.docml");
    54     mFileNames.insert(TwoCallsView,  ":/xml/bubble_layout_2.docml");
    74     mWidgetName.insert(CenterButton,   "centerButton");
    71     mWidgetName.insert(CenterButton,   "centerButton");
    75     mWidgetName.insert(RightButton,    "rightButton");
    72     mWidgetName.insert(RightButton,    "rightButton");
    76     mWidgetName.insert(ConferenceTimer,"callTimer");
    73     mWidgetName.insert(ConferenceTimer,"callTimer");
    77     mWidgetName.insert(ParticipantList,"participantList");
    74     mWidgetName.insert(ParticipantList,"participantList");
    78     mWidgetName.insert(MutedIcon,      "mutedIcon");
    75     mWidgetName.insert(MutedIcon,      "mutedIcon");
    79 
       
    80     mButtonStyle.insert(LeftButton, new BubbleButtonStyle());
       
    81     mButtonStyle.insert(CenterButton, new BubbleButtonStyle());
       
    82     mButtonStyle.insert(RightButton, new BubbleButtonStyle());
       
    83     mButtonStyle.insert(ParticipantListButton, new BubbleButtonStyle()); // not needed??
       
    84 }
    76 }
    85 
    77 
    86 BubbleWidgetManager::~BubbleWidgetManager()
    78 BubbleWidgetManager::~BubbleWidgetManager()
    87 {
    79 {
    88     qDeleteAll(mDocumentLoaders);
    80     qDeleteAll(mDocumentLoaders);
    92     foreach (int key, keys) {
    84     foreach (int key, keys) {
    93         qDeleteAll(*mDocumentHandlers[key]);
    85         qDeleteAll(*mDocumentHandlers[key]);
    94     }
    86     }
    95     qDeleteAll(mDocumentHandlers);
    87     qDeleteAll(mDocumentHandlers);
    96     mDocumentHandlers.clear();
    88     mDocumentHandlers.clear();
    97 
       
    98     qDeleteAll(mButtonStyle);
       
    99 }
    89 }
   100 
    90 
   101 QGraphicsWidget* BubbleWidgetManager::view(View view)
    91 QGraphicsWidget* BubbleWidgetManager::view(View view)
   102 {
    92 {
   103     if (mDocumentContent.contains(view)) {
    93     if (mDocumentContent.contains(view)) {
   117 QGraphicsWidget* BubbleWidgetManager::loadDocument(
   107 QGraphicsWidget* BubbleWidgetManager::loadDocument(
   118     View view,
   108     View view,
   119     Qt::Orientation orientation)
   109     Qt::Orientation orientation)
   120 {
   110 {
   121     BubbleDocumentLoader* loader =
   111     BubbleDocumentLoader* loader =
   122         new BubbleDocumentLoader(mImageManager,mStylePluginName);
   112         new BubbleDocumentLoader(mImageManager);
   123     bool ok;
   113     bool ok;
   124 
   114 
   125     loader->load(mFileNames[view],&ok);
   115     loader->load(mFileNames[view],&ok);
   126     Q_ASSERT(ok);
   116     Q_ASSERT(ok);
   127     loader->load(mFileNames[view],mOrientationName[orientation],&ok);
   117     loader->load(mFileNames[view],mOrientationName[orientation],&ok);
   134 
   124 
   135     Q_ASSERT(widget);
   125     Q_ASSERT(widget);
   136     widget->setVisible(false);
   126     widget->setVisible(false);
   137     mDocumentContent.insert(view,widget);
   127     mDocumentContent.insert(view,widget);
   138 
   128 
   139     applyCustomStyles(view);
       
   140 
       
   141     if (view!=MutedOverlay) {
   129     if (view!=MutedOverlay) {
   142         createDocumentHandlers(view);
   130         createDocumentHandlers(view);
   143     }
   131     }
   144 
   132 
       
   133     applyCustomStyles(view);
       
   134 
   145     return widget;
   135     return widget;
   146 }
   136 }
   147 
   137 
   148 void BubbleWidgetManager::applyCustomStyles(View view)
   138 void BubbleWidgetManager::applyCustomStyles(View view)
   149 {
   139 {
   150     setButtonStyle(LeftButton, widget(view,ExpandedBubble,LeftButton));
       
   151     setButtonStyle(CenterButton, widget(view,ExpandedBubble,CenterButton));
       
   152     setButtonStyle(RightButton, widget(view,ExpandedBubble,RightButton));
       
   153 
       
   154     setBackground(widget(view,None,MutedIcon));
   140     setBackground(widget(view,None,MutedIcon));
   155 }
       
   156 
       
   157 void BubbleWidgetManager::setButtonStyle(Widget widget, QGraphicsWidget* button)
       
   158 {
       
   159     HbPushButton* b;
       
   160     b = qobject_cast<HbPushButton*>(button);
       
   161     if (b) {
       
   162         Q_ASSERT(mButtonStyle.contains(widget));
       
   163         b->setStyle(mButtonStyle.value(widget));
       
   164     }
       
   165 }
   141 }
   166 
   142 
   167 void BubbleWidgetManager::setBackground(QGraphicsWidget* widget)
   143 void BubbleWidgetManager::setBackground(QGraphicsWidget* widget)
   168 {
   144 {
   169     HbWidget* w;
   145     HbWidget* w;
   263     }
   239     }
   264 }
   240 }
   265 
   241 
   266 QGraphicsWidget* BubbleWidgetManager::createParticipantListItem()
   242 QGraphicsWidget* BubbleWidgetManager::createParticipantListItem()
   267 {
   243 {
   268     return new BubbleParticipantListItem(mStylePluginName,
   244     return new BubbleParticipantListItem();
   269                                          *mButtonStyle.value(ParticipantListButton));
       
   270 }
       
   271 
       
   272 void BubbleWidgetManager::setStylePluginName(const QString& name)
       
   273 {
       
   274     mStylePluginName = name;
       
   275 }
   245 }
   276 
   246 
   277 // custom widget loading
   247 // custom widget loading
   278 BubbleDocumentLoader::BubbleDocumentLoader(
   248 BubbleDocumentLoader::BubbleDocumentLoader(BubbleImageManager& imageManager)
   279       BubbleImageManager& imageManager, const QString& stylePluginName)
   249     : mImageManager(imageManager)
   280     : mImageManager(imageManager), mStylePluginName(stylePluginName)
       
   281 {
   250 {
   282 }
   251 }
   283 
   252 
   284 QObject *BubbleDocumentLoader::createObject(
   253 QObject *BubbleDocumentLoader::createObject(
   285     const QString& type,
   254     const QString& type,
   286     const QString &name)
   255     const QString &name)
   287 {
   256 {
   288     if ( type == BubbleContainerWidget::staticMetaObject.className() ) {
   257     if ( type == BubbleContainerWidget::staticMetaObject.className() ) {
   289         QObject *object = new BubbleContainerWidget(mStylePluginName);
   258         QObject *object = new BubbleContainerWidget();
   290         object->setObjectName(name);
   259         object->setObjectName(name);
   291         return object;
   260         return object;
   292     }
   261     }
   293 
   262 
   294     if ( type == BubbleImageWidget::staticMetaObject.className() ) {
   263     if ( type == BubbleImageWidget::staticMetaObject.className() ) {
   295         QObject *object = new BubbleImageWidget(
   264         QObject *object = new BubbleImageWidget(mImageManager);
   296             mStylePluginName, mImageManager);
       
   297         object->setObjectName(name);
   265         object->setObjectName(name);
   298         return object;
   266         return object;
   299     }
   267     }
   300 
   268 
   301     if ( type == BubbleHeadingWidget::staticMetaObject.className() ) {
   269     if ( type == BubbleHeadingWidget::staticMetaObject.className() ) {
   302         QObject *object = new BubbleHeadingWidget(mStylePluginName);
   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;
   303         object->setObjectName(name);
   277         object->setObjectName(name);
   304         return object;
   278         return object;
   305     }
   279     }
   306 
   280 
   307     return HbDocumentLoader::createObject(type, name);
   281     return HbDocumentLoader::createObject(type, name);