phoneuis/bubblemanager2/bubblestyle/src/bubblestyleplugin.cpp
changeset 30 ebdbd102c78a
parent 27 2f8f8080a020
child 32 14cdbae33453
child 36 2eacb6118286
equal deleted inserted replaced
27:2f8f8080a020 30:ebdbd102c78a
     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:  Bubble style plugin.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "bubblestyleplugin.h"
       
    19 #include "bubblestyleoption.h"
       
    20 #include "bubbleprimitives.h"
       
    21 #include "bubbleanimiconitem.h"
       
    22 
       
    23 #include <hbstyle.h>
       
    24 #include <hbiconitem.h>
       
    25 #include <hbtextitem.h>
       
    26 #include <hbframeitem.h>
       
    27 #include <hbframedrawer.h>
       
    28 #include <hbfontspec.h>
       
    29 #include <hbdeviceprofile.h>
       
    30 #include <hbcolorscheme.h>
       
    31 #include <hbstringutil.h>
       
    32 
       
    33 static const int BUBBLE_ICON_ANIM_INTERVAL = 500; // ms
       
    34 
       
    35 BubbleStylePlugin::BubbleStylePlugin()
       
    36 {
       
    37     mCliFont = new HbFontSpec(HbFontSpec::Primary);
       
    38     mTextFont = new HbFontSpec(HbFontSpec::Secondary);
       
    39     mTimerFont = new HbFontSpec(HbFontSpec::Secondary);
       
    40 
       
    41     HbDeviceProfile profile;
       
    42     mCliFont->setTextHeight(4*HbDeviceProfile::current().unitValue());
       
    43     mTextFont->setTextHeight(4*HbDeviceProfile::current().unitValue());
       
    44     mTimerFont->setTextHeight(4*HbDeviceProfile::current().unitValue());
       
    45 }
       
    46 
       
    47 BubbleStylePlugin::~BubbleStylePlugin()
       
    48 {
       
    49     delete mCliFont;
       
    50     delete mTextFont;
       
    51     delete mTimerFont;
       
    52 }
       
    53 
       
    54 int BubbleStylePlugin::primitiveCount() const
       
    55 {
       
    56     return BP_Bubble_primitive_count;
       
    57 }
       
    58 
       
    59 QGraphicsItem* BubbleStylePlugin::createPrimitive(
       
    60     HbStyle::Primitive primitive, 
       
    61     QGraphicsItem *parent) const
       
    62 {
       
    63     QGraphicsItem* item = 0;
       
    64     
       
    65     switch(primitive) {
       
    66     case BP_Bubble_frame: {
       
    67         HbFrameItem* frame = new HbFrameItem(parent);
       
    68         frame->setZValue(-1.0);
       
    69         HbFrameDrawer *drawer = new HbFrameDrawer();
       
    70         frame->setFrameDrawer( drawer ); // takes ownership
       
    71         item = frame;
       
    72         }
       
    73         break;
       
    74     case BP_Text1_text:
       
    75     case BP_Text2_text:
       
    76     case BP_Text3_text: {
       
    77         HbTextItem* text = new HbTextItem(parent);
       
    78         item = text;
       
    79         }
       
    80         break;    
       
    81     case BP_CallStatus_icon: {
       
    82         BubbleAnimIconItem* anim =
       
    83             new BubbleAnimIconItem(BUBBLE_ICON_ANIM_INTERVAL,parent);
       
    84         item = anim;
       
    85         }
       
    86         break;
       
    87     case BP_NumberType_icon: {
       
    88         HbIconItem* icon = new HbIconItem(parent);
       
    89         item = icon;
       
    90         }
       
    91         break;
       
    92     case BP_Ciphering_icon: {
       
    93         HbIconItem* icon = new HbIconItem(parent);
       
    94         item = icon;
       
    95         }
       
    96         break;
       
    97     case BP_DefaultAvatar_icon: {
       
    98         HbIconItem* icon = new HbIconItem(parent);
       
    99         item = icon;
       
   100         }
       
   101     default:
       
   102         break;
       
   103     } // switch
       
   104 
       
   105     return item;    
       
   106 }
       
   107 
       
   108 void BubbleStylePlugin::updatePrimitive(
       
   109     QGraphicsItem *item,
       
   110     HbStyle::Primitive primitive, 
       
   111     const QStyleOption *option ) const
       
   112 {
       
   113 #ifndef Q_OS_SYMBIAN
       
   114     // qtcast didn't work with mingw
       
   115     const BubbleStyleOption *opt = static_cast<const BubbleStyleOption*>(option);
       
   116 #else
       
   117     const BubbleStyleOption *opt = qstyleoption_cast<const BubbleStyleOption*>(option);
       
   118 #endif
       
   119     if ( !opt ) {
       
   120         return;
       
   121     }    
       
   122     
       
   123     switch(primitive) {
       
   124     case BP_Bubble_frame: {
       
   125         HbFrameItem *frame = static_cast<HbFrameItem*>(item);
       
   126         frame->frameDrawer().setFrameType( HbFrameDrawer::NinePieces );
       
   127         frame->frameDrawer().setFrameGraphicsName("qtg_fr_list_normal");
       
   128         }
       
   129         break;                
       
   130 
       
   131     case BP_Text1_text: {
       
   132         HbTextItem* textItem = static_cast<HbTextItem*>(item);
       
   133         setText(textItem, opt->mText1, opt->mText1Clip);
       
   134         setFont(textItem, primitive, opt);
       
   135         }
       
   136         break;    
       
   137     
       
   138     case BP_Text2_text: {
       
   139         HbTextItem* textItem = static_cast<HbTextItem*>(item);
       
   140         setText(textItem, opt->mText2, opt->mText2Clip);
       
   141         setFont(textItem, primitive, opt);
       
   142         }
       
   143         break;    
       
   144 
       
   145     case BP_Text3_text: {
       
   146         HbTextItem* textItem = static_cast<HbTextItem*>(item);
       
   147         setText(textItem, opt->mText3, opt->mText3Clip);
       
   148         setFont(textItem, primitive, opt);
       
   149         }
       
   150         break;    
       
   151     
       
   152     case BP_CallStatus_icon: {
       
   153         setCallStatusIcons(static_cast<BubbleAnimIconItem*>(item), opt);
       
   154         }
       
   155         break;
       
   156     
       
   157     case BP_NumberType_icon: {
       
   158         HbIconItem* icon = static_cast<HbIconItem*>(item);
       
   159         if ( (( opt->mCallState == BubbleManagerIF::Incoming ) ||
       
   160               ( opt->mCallState == BubbleManagerIF::Waiting )) &&
       
   161              ( opt->mCallFlags & BubbleManagerIF::Diverted ) ) {
       
   162             icon->setIconName(":/qgn_indi_call_diverted.svg");
       
   163             setIconColor(icon);
       
   164             icon->show();
       
   165             } else {
       
   166             icon->setIconName(QString());
       
   167             icon->hide();
       
   168             }
       
   169         }
       
   170         break;
       
   171 
       
   172     case BP_Ciphering_icon: {
       
   173         HbIconItem* icon = static_cast<HbIconItem*>(item);
       
   174         if ( opt->mCallFlags & BubbleManagerIF::NoCiphering ) {
       
   175             icon->setIconName("qtg_mono_ciphering_off");
       
   176             setIconColor(icon);
       
   177             icon->show();
       
   178             } else {
       
   179             icon->setIconName(QString());
       
   180             icon->hide();
       
   181             }
       
   182         }
       
   183         break;
       
   184 
       
   185     case BP_DefaultAvatar_icon: {
       
   186         HbIconItem* icon = static_cast<HbIconItem*>(item);
       
   187         icon->setIconName("qtg_large_avatar");
       
   188         icon->setAspectRatioMode(Qt::KeepAspectRatioByExpanding);
       
   189         icon->setAlignment(Qt::AlignCenter);
       
   190         }
       
   191 
       
   192     default:
       
   193         break;
       
   194     } // switch
       
   195 }
       
   196 
       
   197 void BubbleStylePlugin::setText(
       
   198     HbTextItem* item,
       
   199     const QString& text,
       
   200     Qt::TextElideMode clip) const
       
   201 {
       
   202     if (clip == Qt::ElideLeft) {
       
   203         // convert phonenumber to phone ui language
       
   204         QString converted = HbStringUtil::convertDigits(text);
       
   205         item->setText(converted);
       
   206     } else {
       
   207         item->setText( text );
       
   208     }
       
   209     item->setElideMode( clip );
       
   210 }
       
   211 
       
   212 void BubbleStylePlugin::setFont(
       
   213     HbTextItem* item,
       
   214     int primitive,
       
   215     const BubbleStyleOption *option) const
       
   216 {
       
   217     int primitiveLineNumber = 0;
       
   218     if (primitive==BP_Text1_text) {
       
   219         primitiveLineNumber = 1;
       
   220     } else if (primitive==BP_Text2_text) {
       
   221         primitiveLineNumber = 2;
       
   222     } else if (primitive==BP_Text3_text) {
       
   223         primitiveLineNumber = 3;
       
   224     }
       
   225 
       
   226     QFont font = mTextFont->font();
       
   227     if (primitiveLineNumber==option->mCliLineNumber) {
       
   228         font = mCliFont->font();
       
   229     } else if (primitiveLineNumber==option->mTimerLineNumber) {
       
   230         font = mTimerFont->font();
       
   231     }
       
   232 
       
   233     item->setFont(font);
       
   234 
       
   235     // set color (to be done via css when possible)
       
   236     QColor color;
       
   237     color = HbColorScheme::color("list_item_title_normal");
       
   238     if (color.isValid()) {
       
   239         item->setTextColor(color);
       
   240     } else {
       
   241         item->setTextColor(Qt::black);
       
   242     }
       
   243 }
       
   244 
       
   245 void BubbleStylePlugin::setIconColor(HbIconItem* icon) const
       
   246 {
       
   247     // to be done via css when possible
       
   248     QColor color;
       
   249     color = HbColorScheme::color("list_item_title_normal");
       
   250     if (color.isValid()) {
       
   251         icon->setColor(color);
       
   252     }
       
   253 }
       
   254 
       
   255 QString BubbleStylePlugin::layoutPath() const
       
   256 {
       
   257    QString path(":/");
       
   258    return path;
       
   259 }
       
   260 
       
   261 void BubbleStylePlugin::setCallStatusIcons(BubbleAnimIconItem* anim, const BubbleStyleOption *opt) const
       
   262 {
       
   263     anim->reset();
       
   264     switch(opt->mCallState) {
       
   265     case BubbleManagerIF::Incoming:
       
   266     case BubbleManagerIF::Alerting:
       
   267     case BubbleManagerIF::Waiting:
       
   268         if ( opt->mCallFlags & BubbleManagerIF::VoIPCall ) {
       
   269             anim->appendIcon("qtg_large_voip_call_active");
       
   270             anim->appendIcon("qtg_large_voip_call_waiting");
       
   271         } else if ( opt->mCallFlags & BubbleManagerIF::Video ) {
       
   272             anim->appendIcon("qtg_large_video_call_active");
       
   273             anim->appendIcon("qtg_large_video_call_waiting");
       
   274         } else {
       
   275             anim->appendIcon("qtg_large_active_call");
       
   276             anim->appendIcon("qtg_large_waiting_call");
       
   277         }
       
   278         break;
       
   279     case BubbleManagerIF::Outgoing:
       
   280     case BubbleManagerIF::Active:
       
   281         if ( opt->mCallFlags & BubbleManagerIF::VoIPCall ) {
       
   282             anim->appendIcon("qtg_large_voip_call_active");
       
   283         } else if ( opt->mCallFlags & BubbleManagerIF::Video ) {
       
   284             anim->appendIcon("qtg_large_video_call_active");
       
   285         } else {
       
   286             anim->appendIcon("qtg_large_active_call");
       
   287         }            
       
   288         break;
       
   289     case BubbleManagerIF::OnHold:
       
   290         if ( opt->mCallFlags & BubbleManagerIF::VoIPCall ) {
       
   291             anim->appendIcon("qtg_large_voip_call_waiting");
       
   292         } else if ( opt->mCallFlags & BubbleManagerIF::Video ) {
       
   293             anim->appendIcon("qtg_large_video_call_waiting");
       
   294         } else {
       
   295             anim->appendIcon("qtg_large_waiting_call");
       
   296         }                      
       
   297         break;
       
   298     case BubbleManagerIF::Disconnected:
       
   299     case BubbleManagerIF::AlertToDisconnected:
       
   300         if ( opt->mCallFlags & BubbleManagerIF::VoIPCall ) {
       
   301             anim->appendIcon("qtg_large_end_call");
       
   302         } else if ( opt->mCallFlags & BubbleManagerIF::Video ) {
       
   303             anim->appendIcon("qtg_large_end_call");
       
   304         } else {
       
   305             anim->appendIcon("qtg_large_end_call");
       
   306         }           
       
   307         break;
       
   308     default:
       
   309         break;
       
   310     }
       
   311     
       
   312 }
       
   313 
       
   314 Q_EXPORT_PLUGIN2(bubblestyleplugin, BubbleStylePlugin)