phoneuis/bubblemanager2/bubblecore/src/bubbleparticipantlistitem.cpp
branchGCC_SURGE
changeset 51 f39ed5e045e0
parent 30 ebdbd102c78a
parent 46 bc5a64e5bc3c
equal deleted inserted replaced
40:bab96b7ed1a4 51:f39ed5e045e0
    14 * Description: List item for conference participant list.
    14 * Description: List item for conference participant list.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <QGraphicsLinearLayout>
    18 #include <QGraphicsLinearLayout>
    19 #include <hbiconitem.h>
    19 #include <QTimer>
    20 #include <hbtextitem.h>
       
    21 #include <hbaction.h>
    20 #include <hbaction.h>
    22 #include <hbpushbutton.h>
    21 #include <hbpushbutton.h>
       
    22 #include <hbgroupbox.h>
    23 #include <hbstyleloader.h>
    23 #include <hbstyleloader.h>
    24 #include <hbabstractitemview.h>
    24 #include <hbabstractitemview.h>
    25 #include <hblistviewitem.h>
    25 #include <hblistviewitem.h>
    26 
    26 
    27 #include "bubbleparticipantlistitem.h"
    27 #include "bubbleparticipantlistitem.h"
    28 #include "bubblemanagerif.h"
    28 #include "bubblemanagerif.h"
    29 #include "bubbleutils.h"
    29 #include "bubbleutils.h"
    30 
    30 
       
    31 // helper class to wrap buttons for group box
       
    32 class BubbleParticipantListButtons : public HbWidget
       
    33 {
       
    34     Q_OBJECT
       
    35 
       
    36 public:
       
    37     BubbleParticipantListButtons(QGraphicsItem *parent = 0);
       
    38     ~BubbleParticipantListButtons();
       
    39 
       
    40     HbPushButton* mButton1;
       
    41     HbPushButton* mButton2;
       
    42 };
       
    43 
       
    44 BubbleParticipantListButtons::BubbleParticipantListButtons(
       
    45     QGraphicsItem *parent) : HbWidget(parent)
       
    46 {
       
    47     HbStyleLoader::registerFilePath(
       
    48         QLatin1String(":/bubbleparticipantlistbuttons.css"));
       
    49     HbStyleLoader::registerFilePath(
       
    50         QLatin1String(":/bubbleparticipantlistbuttons.widgetml"));
       
    51 
       
    52     mButton1 = new HbPushButton(this);
       
    53     style()->setItemName( mButton1, QLatin1String("button-1"));
       
    54     mButton2 = new HbPushButton(this);
       
    55     style()->setItemName( mButton2, QLatin1String("button-2"));
       
    56 }
       
    57 
       
    58 BubbleParticipantListButtons::~BubbleParticipantListButtons()
       
    59 {
       
    60 }
       
    61 
    31 BubbleParticipantListItem::BubbleParticipantListItem(
    62 BubbleParticipantListItem::BubbleParticipantListItem(
    32     QGraphicsItem *parent) :
    63     QGraphicsItem *parent) :
    33     HbAbstractViewItem(parent),
    64     HbAbstractViewItem(parent),
    34     mText(0),
    65     mGroupBox(0)
    35     mStatusIcon(0),
       
    36     mCipheringIcon(0),
       
    37     mExpandIcon(0),
       
    38     mButton1(0),
       
    39     mButton2(0),
       
    40     mExpanded(false)
       
    41 {
    66 {
    42     HbStyleLoader::registerFilePath(":/bubbleparticipantlistitem.css");
    67     HbStyleLoader::registerFilePath(
    43     HbStyleLoader::registerFilePath(":/bubbleparticipantlistitem.widgetml");
    68         QLatin1String(":/bubbleparticipantlistitem.css"));
       
    69     HbStyleLoader::registerFilePath(
       
    70         QLatin1String(":/bubbleparticipantlistitem.widgetml"));
    44 }
    71 }
    45 
    72 
    46 BubbleParticipantListItem::~BubbleParticipantListItem()
    73 BubbleParticipantListItem::~BubbleParticipantListItem()
    47 {
    74 {
    48 }
    75 }
    54 
    81 
    55 void BubbleParticipantListItem::updateChildItems()
    82 void BubbleParticipantListItem::updateChildItems()
    56 {
    83 {
    57     HbAbstractViewItem::updateChildItems();
    84     HbAbstractViewItem::updateChildItems();
    58 
    85 
    59     setFocusPolicy(Qt::ClickFocus); // to enable expanding
    86     // create controls
       
    87     if (!mGroupBox) {
       
    88         mGroupBox = new HbGroupBox(this);
       
    89         style()->setItemName( mGroupBox, QLatin1String("group-box" ));
    60 
    90 
    61     // create primitives
    91         // create buttons for actions (same for all items)
    62     if (!mText) {
    92         BubbleParticipantListItem* p =
    63         mText = new HbTextItem(this);
    93                 static_cast<BubbleParticipantListItem*>(prototype());
    64         style()->setItemName( mText, "text" );
       
    65     }
       
    66 
    94 
    67     if (!mCipheringIcon) {
    95         if (p->mActions.count()==2) {
    68         mCipheringIcon = new HbIconItem(this);
    96             BubbleParticipantListButtons* content =
    69         style()->setItemName( mCipheringIcon, "ciphering" );
    97                     new BubbleParticipantListButtons();
    70     }
       
    71 
    98 
    72     if (!mStatusIcon) {
    99             // button 1
    73         mStatusIcon = new HbIconItem(this);
   100             HbAction* action1 = p->mActions.at(0);
    74         style()->setItemName( mStatusIcon, "icon" );
   101             content->mButton1->setIcon(action1->icon());
    75     }
   102             connect(content->mButton1,
       
   103                     SIGNAL(clicked()),
       
   104                     action1,
       
   105                     SLOT(trigger()),
       
   106                     Qt::QueuedConnection);
    76 
   107 
    77     if (!mExpandIcon) {
   108             // button 2
    78         mExpandIcon = new HbIconItem(this);
   109             HbAction* action2 = p->mActions.at(1);
    79         style()->setItemName( mExpandIcon, "expand-indi" );
   110             content->mButton2->setIcon(action2->icon());
       
   111             connect(content->mButton2,
       
   112                     SIGNAL(clicked()),
       
   113                     action2,
       
   114                     SLOT(trigger()),
       
   115                     Qt::QueuedConnection);
    80 
   116 
    81         // for expand/collapse controls
   117             mGroupBox->setHeading(QLatin1String(" "));
    82         if (itemView()) {
   118             mGroupBox->setContentWidget(content);
    83             connect( itemView()->selectionModel(),
   119             mGroupBox->setCollapsed(true);
    84                      SIGNAL(currentChanged(QModelIndex,QModelIndex)),
   120 
    85                      this,
   121             // for scrolling to selected item
    86                      SLOT(currentIndexChanged(QModelIndex,QModelIndex)) );
   122             connect(mGroupBox,SIGNAL(toggled(bool)),
       
   123                     this,SLOT(handleItemStateChange(bool)));
       
   124 
       
   125             // for expand/collapse controls
       
   126             if (itemView()) {
       
   127                 connect( itemView()->selectionModel(),
       
   128                          SIGNAL(currentChanged(QModelIndex,QModelIndex)),
       
   129                          this,
       
   130                          SLOT(currentIndexChanged(QModelIndex,QModelIndex)) );
       
   131             }
       
   132         } else {
       
   133             mGroupBox->setCollapsable(false);
    87         }
   134         }
    88     }
   135     }
    89 
   136 
    90     BubbleParticipantListItem* p =
   137     // update group box title (CLI name)
    91             static_cast<BubbleParticipantListItem*>(prototype());
   138     mGroupBox->setHeading(modelIndex().data(Qt::DisplayRole).toString());
    92 
       
    93     if (mExpanded && !mButton1) {
       
    94         Q_ASSERT(p->mActions.count()==2);
       
    95         HbAction* action = p->mActions.at(0);
       
    96         mButton1 = new HbPushButton(this);
       
    97         mButton1->setIcon(action->icon());
       
    98         style()->setItemName( mButton1, "button-1" );
       
    99 
       
   100         // connect first action
       
   101         connect(mButton1,
       
   102                 SIGNAL(clicked()),
       
   103                 action,
       
   104                 SLOT(trigger()),
       
   105                 Qt::QueuedConnection);
       
   106     } else {
       
   107         delete mButton1;
       
   108         mButton1 = 0;
       
   109     }
       
   110 
       
   111     if (mExpanded && !mButton2) {
       
   112         Q_ASSERT(p->mActions.count()==2);
       
   113         HbAction* action = p->mActions.at(1);
       
   114         mButton2 = new HbPushButton(this);
       
   115         mButton2->setIcon(action->icon());
       
   116         style()->setItemName( mButton2, "button-2" );
       
   117 
       
   118         // connect second action
       
   119         connect(mButton2,
       
   120                 SIGNAL(clicked()),
       
   121                 action,
       
   122                 SLOT(trigger()),
       
   123                 Qt::QueuedConnection );
       
   124 
       
   125     } else {
       
   126         delete mButton2;
       
   127         mButton2 = 0;
       
   128     }
       
   129 
       
   130     if (mText) {
       
   131         mText->setText(modelIndex().data(Qt::DisplayRole).toString());
       
   132     }
       
   133 
       
   134     int state = (BubbleManagerIF::PhoneCallState)
       
   135         modelIndex().data(Qt::DecorationRole).toInt();
       
   136 
       
   137     if (mStatusIcon) {
       
   138         BubbleUtils::setCallStatusIcon(state,0,*mStatusIcon);
       
   139     }
       
   140 
       
   141     if (mCipheringIcon) {
       
   142         int flags = !modelIndex().data(Qt::StatusTipRole).toBool() ?
       
   143                     BubbleManagerIF::NoCiphering : 0;
       
   144 
       
   145         BubbleUtils::setCipheringIcon(state,flags,*mCipheringIcon);
       
   146     }
       
   147 
       
   148     if (mExpandIcon) {
       
   149         if (mExpanded) {
       
   150             mExpandIcon->setIcon(HbIcon("qtg_small_collapse"));
       
   151         } else {
       
   152             mExpandIcon->setIcon(HbIcon("qtg_small_expand"));
       
   153         }
       
   154     }
       
   155 
       
   156     repolish();
       
   157 }
   139 }
   158 
   140 
   159 void BubbleParticipantListItem::polish(HbStyleParameters& params)
   141 void BubbleParticipantListItem::polish(HbStyleParameters& params)
   160 {
   142 {
   161     if (mExpanded) {
       
   162         setProperty("layoutOption","expanded");
       
   163     } else {
       
   164         setProperty("layoutOption","collapsed");
       
   165     }
       
   166 
       
   167     HbAbstractViewItem::polish(params);
   143     HbAbstractViewItem::polish(params);
   168 }
       
   169 
       
   170 void BubbleParticipantListItem::setExpanded(bool expanded)
       
   171 {
       
   172     mExpanded = expanded;
       
   173     updateChildItems();
       
   174 }
   144 }
   175 
   145 
   176 void BubbleParticipantListItem::addAction(HbAction* action)
   146 void BubbleParticipantListItem::addAction(HbAction* action)
   177 {
   147 {
   178     mActions.append(action);
   148     mActions.append(action);
   179 }
   149 }
   180 
   150 
   181 void BubbleParticipantListItem::clearActions()
   151 void BubbleParticipantListItem::clearActions()
   182 {
   152 {
   183     mActions.clear();
   153     mActions.clear();
   184     mExpanded = false;
       
   185 }
   154 }
   186 
   155 
   187 void BubbleParticipantListItem::currentIndexChanged(
   156 void BubbleParticipantListItem::currentIndexChanged(
   188     const QModelIndex &current,
   157     const QModelIndex &current,
   189     const QModelIndex &previous)
   158     const QModelIndex &previous)
   190 {
   159 {
   191     Q_UNUSED(previous);
   160     Q_UNUSED(previous);
   192 
   161 
   193     if (modelIndex() == current) {
   162     if ((modelIndex()!=current) && !mGroupBox->isCollapsed()) {
   194         if ( !mExpanded ) {
   163         // change state asynchronously
   195             setExpanded(true);
   164         QTimer::singleShot(100,this,SLOT(setCollapsed()));
   196         }
       
   197     } else if (mExpanded) {
       
   198         setExpanded(false);
       
   199     }
   165     }
   200 }
   166 }
   201 
   167 
   202 int BubbleParticipantListItem::type() const
   168 void BubbleParticipantListItem::setCollapsed()
   203 {
   169 {
   204     return HbListViewItem::Type;
   170     mGroupBox->setCollapsed(true);
   205 }
   171 }
   206 
   172 
       
   173 void BubbleParticipantListItem::handleItemStateChange(bool collapsed)
       
   174 {
       
   175     if (!collapsed) {
       
   176         itemView()->scrollTo(
       
   177             modelIndex(),
       
   178             HbAbstractItemView::EnsureVisible);
       
   179     }
       
   180 }
       
   181 
       
   182 #include "bubbleparticipantlistitem.moc"
       
   183