src/hbinput/inputwidgets/hbinputcheckboxlist.cpp
branchGCC_SURGE
changeset 15 f378acbc9cfb
parent 7 923ff622b8b9
child 21 4633027730f5
equal deleted inserted replaced
9:730c025d4b77 15:f378acbc9cfb
    20 **
    20 **
    21 ** If you have questions regarding the use of this file, please contact
    21 ** If you have questions regarding the use of this file, please contact
    22 ** Nokia at developer.feedback@nokia.com.
    22 ** Nokia at developer.feedback@nokia.com.
    23 **
    23 **
    24 ****************************************************************************/
    24 ****************************************************************************/
       
    25 #include "hbinputcheckboxlist_p.h"
    25 
    26 
    26 #include <hblistwidget.h>
    27 #include <hblistwidget.h>
    27 #include <hblistwidgetitem.h>
    28 #include <hblistwidgetitem.h>
    28 #include <hbdataformmodelitem.h>
    29 #include <hbdataformmodelitem.h>
    29 #include <hbdataformmodel.h>
    30 #include <hbdataformmodel.h>
    30 
    31 #include "hbwidget_p.h"
    31 #include "hbinputcheckboxlist_p.h"
       
    32 
    32 
    33 /// @cond
    33 /// @cond
    34 
    34 
    35 class HbInputCheckBoxListPrivate
    35 class HbInputCheckBoxListPrivate
    36 {
    36 {
    42 
    42 
    43 /*!
    43 /*!
    44 Constructs checkbox list
    44 Constructs checkbox list
    45 */
    45 */
    46 HbInputCheckBoxList::HbInputCheckBoxList(QGraphicsItem *parent)
    46 HbInputCheckBoxList::HbInputCheckBoxList(QGraphicsItem *parent)
    47  : HbDataFormViewItem(parent), d_ptr(new HbInputCheckBoxListPrivate())
    47     : HbDataFormViewItem(parent), d_ptr(new HbInputCheckBoxListPrivate())
    48 {
    48 {
    49 }
    49 }
    50 
    50 
    51 /*!
    51 /*!
    52 Destructs checkbox list
    52 Destructs checkbox list
    57 }
    57 }
    58 
    58 
    59 /*!
    59 /*!
    60 Returns a new copy of this object
    60 Returns a new copy of this object
    61 */
    61 */
    62 HbAbstractViewItem* HbInputCheckBoxList::createItem()
    62 HbAbstractViewItem *HbInputCheckBoxList::createItem()
    63 {
    63 {
    64     return new HbInputCheckBoxList(*this);
    64     return new HbInputCheckBoxList(*this);
    65 }
    65 }
    66 
    66 
    67 /*!
    67 /*!
    68 \reimp
    68 \reimp
    69 Returns true if \a model index is supported, otherwise returns false.
    69 Returns true if \a index is supported, otherwise returns false.
    70  */
    70  */
    71 bool HbInputCheckBoxList::canSetModelIndex(const QModelIndex &index) const
    71 bool HbInputCheckBoxList::canSetModelIndex(const QModelIndex &index) const
    72 {
    72 {
    73     HbDataFormModelItem::DataItemType itemType = 
    73     HbDataFormModelItem::DataItemType itemType =
    74         static_cast<HbDataFormModelItem::DataItemType>(index.data(HbDataFormModelItem::ItemTypeRole).toInt());
    74         static_cast<HbDataFormModelItem::DataItemType>(index.data(HbDataFormModelItem::ItemTypeRole).toInt());
    75 
    75 
    76     if(itemType == HbDataFormModelItem::CustomItemBase) {
    76     if (itemType == HbDataFormModelItem::CustomItemBase) {
    77         return true;
    77         return true;
    78     } else {
    78     } else {
    79         return false;
    79         return false;
    80     }
    80     }
    81 }
    81 }
    85 */
    85 */
    86 void HbInputCheckBoxList::itemActivated(const QModelIndex &index)
    86 void HbInputCheckBoxList::itemActivated(const QModelIndex &index)
    87 {
    87 {
    88     Q_D(HbInputCheckBoxList);
    88     Q_D(HbInputCheckBoxList);
    89     QModelIndex itemIndex = modelIndex();
    89     QModelIndex itemIndex = modelIndex();
    90     HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem*>(
    90     HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem *>(
    91         static_cast<HbDataFormModel*>(itemView()->model())->itemFromIndex(itemIndex));
    91                                          static_cast<HbDataFormModel *>(itemView()->model())->itemFromIndex(itemIndex));
    92 
    92 
    93     QList<QVariant> selectedValues = modelItem->contentWidgetData(QString("selectedItems")).toList();
    93     QList<QVariant> selectedValues = modelItem->contentWidgetData(QString("selectedItems")).toList();
    94     selectedValues.replace(index.row(), !selectedValues.at(index.row()).toBool());
    94     selectedValues.replace(index.row(), !selectedValues.at(index.row()).toBool());
    95     modelItem->setContentWidgetData(QString("selectedItems"), selectedValues);
    95     modelItem->setContentWidgetData(QString("selectedItems"), selectedValues);
    96 
    96 
    98     if (selectedValues.at(index.row()).toBool()) {
    98     if (selectedValues.at(index.row()).toBool()) {
    99         d->mListWidget->setCurrentIndex(viewItem->modelIndex(), QItemSelectionModel::Select);
    99         d->mListWidget->setCurrentIndex(viewItem->modelIndex(), QItemSelectionModel::Select);
   100     } else {
   100     } else {
   101         d->mListWidget->setCurrentIndex(viewItem->modelIndex(), QItemSelectionModel::Deselect);
   101         d->mListWidget->setCurrentIndex(viewItem->modelIndex(), QItemSelectionModel::Deselect);
   102     }
   102     }
   103  }
   103 }
   104 
   104 
   105 /*!
   105 /*!
   106 Creates a widget for showing checkbox list
   106 Creates a widget for showing checkbox list
   107 */
   107 */
   108 HbWidget* HbInputCheckBoxList::createCustomWidget()
   108 HbWidget *HbInputCheckBoxList::createCustomWidget()
   109 {
   109 {
   110     Q_D(HbInputCheckBoxList);
   110     Q_D(HbInputCheckBoxList);
   111 
   111 
   112     QModelIndex itemIndex = modelIndex();
   112     QModelIndex itemIndex = modelIndex();
   113     HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem*>(
   113     HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem *>(
   114         static_cast<HbDataFormModel*>(itemView()->model())->itemFromIndex(itemIndex));
   114                                          static_cast<HbDataFormModel *>(itemView()->model())->itemFromIndex(itemIndex));
   115 
   115 
   116     d->mListWidget = new HbListWidget();
   116     d->mListWidget = new HbListWidget();
   117     d->mListWidget->setSelectionMode(HbAbstractItemView::MultiSelection);
   117     d->mListWidget->setSelectionMode(HbAbstractItemView::MultiSelection);
   118     d->mListWidget->contentWidget()->setContentsMargins(10, 10, 10, 10);
   118     d->mListWidget->contentWidget()->setContentsMargins(10, 10, 10, 10);
   119     d->mListWidget->setBackgroundItem(HbStyle::P_DataItem_background);
       
   120     
   119     
       
   120     // get listwidget's widget private ptr
       
   121     HbWidgetPrivate *priv = static_cast<HbWidgetPrivate*>(HbWidgetBasePrivate::d_ptr(d->mListWidget));
       
   122     priv->setBackgroundItem(HbStyle::P_DataItem_background);
       
   123     d->mListWidget->setScrollDirections(0);
       
   124 
   121     QStringList items = modelItem->contentWidgetData(QString("items")).toStringList();
   125     QStringList items = modelItem->contentWidgetData(QString("items")).toStringList();
   122     foreach(QString itemName, items) {
   126     foreach(const QString &itemName, items) {
   123         HbListWidgetItem *item = new HbListWidgetItem();
   127         HbListWidgetItem *item = new HbListWidgetItem();
   124         item->setData(QVariant(itemName), Qt::DisplayRole);
   128         item->setData(QVariant(itemName), Qt::DisplayRole);
   125         d->mListWidget->addItem(item);
   129         d->mListWidget->addItem(item);
   126     }
   130     }
   127 
   131 
   136     QString objectName = modelItem->contentWidgetData(QString("objectName")).toString();
   140     QString objectName = modelItem->contentWidgetData(QString("objectName")).toString();
   137     d->mListWidget->setObjectName(objectName);
   141     d->mListWidget->setObjectName(objectName);
   138 
   142 
   139     connect(d->mListWidget, SIGNAL(activated(const QModelIndex &)), this, SLOT(itemActivated(const QModelIndex &)));
   143     connect(d->mListWidget, SIGNAL(activated(const QModelIndex &)), this, SLOT(itemActivated(const QModelIndex &)));
   140 
   144 
   141     return d->mListWidget;    
   145     return d->mListWidget;
   142 }
   146 }
   143 
   147 
   144 /*!
   148 /*!
   145 Copy constructor for private use.
   149 Copy constructor for private use.
   146 */
   150 */
   147 HbInputCheckBoxList::HbInputCheckBoxList(const HbInputCheckBoxList &other)
   151 HbInputCheckBoxList::HbInputCheckBoxList(const HbInputCheckBoxList &other)
   148  : HbDataFormViewItem(other), d_ptr(new HbInputCheckBoxListPrivate())
   152     : HbDataFormViewItem(other), d_ptr(new HbInputCheckBoxListPrivate())
   149 {
   153 {
   150 }
   154 }
   151 
   155 
   152 // End of file
   156 // End of file