phoneuis/bubblemanager2/bubblecore/src/bubbleparticipantlistitem.cpp
changeset 30 ebdbd102c78a
parent 22 6bb1b21d2484
child 51 f39ed5e045e0
equal deleted inserted replaced
27:2f8f8080a020 30:ebdbd102c78a
    13 *
    13 *
    14 * Description: List item for conference participant list.
    14 * Description: List item for conference participant list.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <QtGui>
    18 #include <QGraphicsLinearLayout>
    19 #include <hbiconitem.h>
    19 #include <hbiconitem.h>
    20 #include <hbframeitem.h>
       
    21 #include <hbtextitem.h>
    20 #include <hbtextitem.h>
    22 #include <hbiconitem.h>
       
    23 #include <hbaction.h>
    21 #include <hbaction.h>
    24 #include <hbpushbutton.h>
    22 #include <hbpushbutton.h>
    25 #include <hblabel.h>
    23 #include <hbstyleloader.h>
       
    24 #include <hbabstractitemview.h>
       
    25 #include <hblistviewitem.h>
    26 
    26 
    27 #include "bubbleparticipantlistitem.h"
    27 #include "bubbleparticipantlistitem.h"
    28 #include "bubbleprimitives.h"
    28 #include "bubblemanagerif.h"
    29 #include "bubblestyleoption.h"
    29 #include "bubbleutils.h"
    30 #include "bubblebuttonstyle.h"
       
    31 
    30 
    32 BubbleParticipantListItem::BubbleParticipantListItem(
    31 BubbleParticipantListItem::BubbleParticipantListItem(
    33     const QString& stylePluginName,
       
    34     BubbleButtonStyle& buttonStyle,
       
    35     QGraphicsItem *parent) :
    32     QGraphicsItem *parent) :
    36     HbListViewItem(parent),
    33     HbAbstractViewItem(parent),
    37     mStylePluginName(stylePluginName),
       
    38     mButtonStyle(buttonStyle),
       
    39     mBackground(0),
       
    40     mText(0),
    34     mText(0),
    41     mStatusIcon(0),
    35     mStatusIcon(0),
    42     mCipheringIcon(0),
    36     mCipheringIcon(0),
    43     mExpandIcon(0),
    37     mExpandIcon(0),
    44     mButton1(0),
    38     mButton1(0),
    45     mButton2(0),
    39     mButton2(0),
    46     mExpanded(false)
    40     mExpanded(false)
    47 {
    41 {
    48     mStylePluginBaseId = style()->registerPlugin(mStylePluginName);
    42     HbStyleLoader::registerFilePath(":/bubbleparticipantlistitem.css");
    49     Q_ASSERT(pluginBaseId()!=-1);
    43     HbStyleLoader::registerFilePath(":/bubbleparticipantlistitem.widgetml");
    50 }
    44 }
    51 
    45 
    52 BubbleParticipantListItem::~BubbleParticipantListItem()
    46 BubbleParticipantListItem::~BubbleParticipantListItem()
    53 {
    47 {
    54     if (prototype()==(HbAbstractViewItem*)this) {
       
    55         style()->unregisterPlugin(mStylePluginName);
       
    56     }
       
    57 }
    48 }
    58 
    49 
    59 HbAbstractViewItem* BubbleParticipantListItem::createItem()
    50 HbAbstractViewItem* BubbleParticipantListItem::createItem()
    60 {
    51 {
    61     return new BubbleParticipantListItem(*this);
    52     return new BubbleParticipantListItem(*this);
    62 }
    53 }
    63 
    54 
    64 void BubbleParticipantListItem::updateChildItems()
    55 void BubbleParticipantListItem::updateChildItems()
    65 {
    56 {
    66     setPluginBaseId(mStylePluginBaseId);
    57     HbAbstractViewItem::updateChildItems();
       
    58 
    67     setFocusPolicy(Qt::ClickFocus); // to enable expanding
    59     setFocusPolicy(Qt::ClickFocus); // to enable expanding
    68 
    60 
    69     // create primitives
    61     // create primitives
    70     if (!mBackground) {
       
    71         mBackground = style()->createPrimitive(
       
    72                 (HbStyle::Primitive)(pluginBaseId()+BP_Bubble_frame), this);
       
    73         if ( mBackground ) {
       
    74             style()->setItemName( mBackground, "background" );
       
    75         }
       
    76     }
       
    77 
       
    78     if (!mText) {
    62     if (!mText) {
    79         mText = style()->createPrimitive(
    63         mText = new HbTextItem(this);
    80                 (HbStyle::Primitive)(pluginBaseId()+BP_Text1_text), this);
    64         style()->setItemName( mText, "text" );
    81         if ( mText ) {
       
    82             style()->setItemName( mText, "text" );
       
    83         }
       
    84     }
    65     }
    85 
    66 
    86     if (!mCipheringIcon) {
    67     if (!mCipheringIcon) {
    87         mCipheringIcon = style()->createPrimitive(
    68         mCipheringIcon = new HbIconItem(this);
    88                 (HbStyle::Primitive)(pluginBaseId()+BP_Ciphering_icon), this);
    69         style()->setItemName( mCipheringIcon, "ciphering" );
    89         if ( mCipheringIcon ) {
       
    90             style()->setItemName( mCipheringIcon, "ciphering" );
       
    91         }
       
    92     }
    70     }
    93 
    71 
    94     if (!mStatusIcon) {
    72     if (!mStatusIcon) {
    95         mStatusIcon = style()->createPrimitive(
    73         mStatusIcon = new HbIconItem(this);
    96                 (HbStyle::Primitive)(pluginBaseId()+BP_CallStatus_icon), this);
    74         style()->setItemName( mStatusIcon, "icon" );
    97         if ( mStatusIcon ) {
       
    98             style()->setItemName( mStatusIcon, "icon" );
       
    99         }
       
   100     }
    75     }
   101 
    76 
   102     if (!mExpandIcon) {
    77     if (!mExpandIcon) {
   103         mExpandIcon = new HbIconItem(this);
    78         mExpandIcon = new HbIconItem(this);
   104         if ( mExpandIcon ) {
    79         style()->setItemName( mExpandIcon, "expand-indi" );
   105             style()->setItemName( mExpandIcon, "expand-indi" );
    80 
       
    81         // for expand/collapse controls
       
    82         if (itemView()) {
       
    83             connect( itemView()->selectionModel(),
       
    84                      SIGNAL(currentChanged(QModelIndex,QModelIndex)),
       
    85                      this,
       
    86                      SLOT(currentIndexChanged(QModelIndex,QModelIndex)) );
   106         }
    87         }
   107     }
    88     }
   108 
    89 
   109     BubbleParticipantListItem* p =
    90     BubbleParticipantListItem* p =
   110             static_cast<BubbleParticipantListItem*>(prototype());
    91             static_cast<BubbleParticipantListItem*>(prototype());
   111 
    92 
   112     if (mExpanded && !mButton1) {
    93     if (mExpanded && !mButton1) {
   113         Q_ASSERT(p->mActions.count()==2);
    94         Q_ASSERT(p->mActions.count()==2);
   114         HbAction* action = p->mActions.at(0);
    95         HbAction* action = p->mActions.at(0);
   115         mButton1 = new HbPushButton(this);
    96         mButton1 = new HbPushButton(this);
   116         mButton1->setStyle(&mButtonStyle);
       
   117         mButton1->setIcon(action->icon());
    97         mButton1->setIcon(action->icon());
   118         style()->setItemName( mButton1, "button-1" );
    98         style()->setItemName( mButton1, "button-1" );
   119         HbTextItem* label = static_cast<HbTextItem*>(
       
   120             mButton1->primitive(HbStyle::P_PushButton_text));
       
   121         if (label) {
       
   122             label->setTextColor( Qt::white );
       
   123         }
       
   124 
    99 
   125         // connect first action
   100         // connect first action
   126         connect(mButton1,
   101         connect(mButton1,
   127                 SIGNAL(clicked()),
   102                 SIGNAL(clicked()),
   128                 action,
   103                 action,
   135 
   110 
   136     if (mExpanded && !mButton2) {
   111     if (mExpanded && !mButton2) {
   137         Q_ASSERT(p->mActions.count()==2);
   112         Q_ASSERT(p->mActions.count()==2);
   138         HbAction* action = p->mActions.at(1);
   113         HbAction* action = p->mActions.at(1);
   139         mButton2 = new HbPushButton(this);
   114         mButton2 = new HbPushButton(this);
   140         mButton2->setStyle(&mButtonStyle);
       
   141         mButton2->setIcon(action->icon());
   115         mButton2->setIcon(action->icon());
   142         style()->setItemName( mButton2, "button-2" );
   116         style()->setItemName( mButton2, "button-2" );
   143         HbTextItem* label = static_cast<HbTextItem*>(
       
   144             mButton2->primitive(HbStyle::P_PushButton_text));
       
   145         if (label) {
       
   146             label->setTextColor( Qt::white );
       
   147         }
       
   148 
   117 
   149         // connect second action
   118         // connect second action
   150         connect(mButton2,
   119         connect(mButton2,
   151                 SIGNAL(clicked()),
   120                 SIGNAL(clicked()),
   152                 action,
   121                 action,
   156     } else {
   125     } else {
   157         delete mButton2;
   126         delete mButton2;
   158         mButton2 = 0;
   127         mButton2 = 0;
   159     }
   128     }
   160 
   129 
   161     // update primitives
       
   162     BubbleStyleOption option;
       
   163     HbWidget::initStyleOption(&option);
       
   164 
       
   165     // check canConvert()
       
   166     option.mCallState = (BubbleManagerIF::PhoneCallState)
       
   167                          modelIndex().data(Qt::DecorationRole).toInt();
       
   168     option.mText1 = modelIndex().data(Qt::DisplayRole).toString();
       
   169     option.mCliLineNumber = 1;
       
   170     bool ciphering = modelIndex().data(Qt::StatusTipRole).toBool();
       
   171     if (!ciphering) {
       
   172         option.mCallFlags = BubbleManagerIF::NoCiphering;
       
   173     }
       
   174 
       
   175     if (mBackground) {
       
   176         style()->updatePrimitive(
       
   177             mBackground,
       
   178             (HbStyle::Primitive)(pluginBaseId()+BP_Bubble_frame),
       
   179             &option);
       
   180     }
       
   181 
       
   182     if (mText) {
   130     if (mText) {
   183         style()->updatePrimitive(
   131         mText->setText(modelIndex().data(Qt::DisplayRole).toString());
   184             mText,
   132     }
   185             (HbStyle::Primitive)(pluginBaseId()+BP_Text1_text),
   133 
   186             &option);
   134     int state = (BubbleManagerIF::PhoneCallState)
   187     }
   135         modelIndex().data(Qt::DecorationRole).toInt();
   188 
   136 
   189     if (mStatusIcon) {
   137     if (mStatusIcon) {
   190         style()->updatePrimitive(
   138         BubbleUtils::setCallStatusIcon(state,0,*mStatusIcon);
   191             mStatusIcon,
       
   192             (HbStyle::Primitive)(pluginBaseId()+BP_CallStatus_icon),
       
   193             &option );
       
   194     }
   139     }
   195 
   140 
   196     if (mCipheringIcon) {
   141     if (mCipheringIcon) {
   197         style()->updatePrimitive(
   142         int flags = !modelIndex().data(Qt::StatusTipRole).toBool() ?
   198             mCipheringIcon,
   143                     BubbleManagerIF::NoCiphering : 0;
   199             (HbStyle::Primitive)(pluginBaseId()+BP_Ciphering_icon),
   144 
   200             &option );
   145         BubbleUtils::setCipheringIcon(state,flags,*mCipheringIcon);
   201     }
   146     }
   202 
   147 
   203     if (mExpandIcon) {
   148     if (mExpandIcon) {
   204         if (mExpanded) {
   149         if (mExpanded) {
       
   150             mExpandIcon->setIcon(HbIcon("qtg_small_collapse"));
       
   151         } else {
   205             mExpandIcon->setIcon(HbIcon("qtg_small_expand"));
   152             mExpandIcon->setIcon(HbIcon("qtg_small_expand"));
   206         } else {
       
   207             mExpandIcon->setIcon(HbIcon("qtg_small_collapse"));
       
   208         }
   153         }
   209     }
   154     }
   210 
   155 
   211     repolish();
   156     repolish();
   212 }
   157 }
   217         setProperty("layoutOption","expanded");
   162         setProperty("layoutOption","expanded");
   218     } else {
   163     } else {
   219         setProperty("layoutOption","collapsed");
   164         setProperty("layoutOption","collapsed");
   220     }
   165     }
   221 
   166 
   222     HbListViewItem::polish(params);
   167     HbAbstractViewItem::polish(params);
   223 }
       
   224 
       
   225 void BubbleParticipantListItem::receivedFocus()
       
   226 {
       
   227     HbListViewItem::receivedFocus();
       
   228     BubbleParticipantListItem* p =
       
   229         static_cast<BubbleParticipantListItem*>(prototype());
       
   230     if ( p->mActions.count() == 2 ) {
       
   231         // supports two buttons layout only
       
   232 
       
   233         setExpanded(true);
       
   234         emit p->selectionChanged(modelIndex().row());
       
   235     }
       
   236 }
       
   237 
       
   238 void BubbleParticipantListItem::lostFocus()
       
   239 {
       
   240     HbListViewItem::lostFocus();
       
   241     setExpanded(false);
       
   242 }
   168 }
   243 
   169 
   244 void BubbleParticipantListItem::setExpanded(bool expanded)
   170 void BubbleParticipantListItem::setExpanded(bool expanded)
   245 {
   171 {
   246     mExpanded = expanded;
   172     mExpanded = expanded;
   256 {
   182 {
   257     mActions.clear();
   183     mActions.clear();
   258     mExpanded = false;
   184     mExpanded = false;
   259 }
   185 }
   260 
   186 
   261 
   187 void BubbleParticipantListItem::currentIndexChanged(
   262 
   188     const QModelIndex &current,
       
   189     const QModelIndex &previous)
       
   190 {
       
   191     Q_UNUSED(previous);
       
   192 
       
   193     if (modelIndex() == current) {
       
   194         if ( !mExpanded ) {
       
   195             setExpanded(true);
       
   196         }
       
   197     } else if (mExpanded) {
       
   198         setExpanded(false);
       
   199     }
       
   200 }
       
   201 
       
   202 int BubbleParticipantListItem::type() const
       
   203 {
       
   204     return HbListViewItem::Type;
       
   205 }
       
   206