Yingdi Yu | 9e0dc29 | 2013-10-10 11:39:45 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013, Regents of the University of California |
| 4 | * Yingdi Yu |
| 5 | * |
| 6 | * BSD license, See the LICENSE file for more information |
| 7 | * |
| 8 | * Author: Yingdi Yu <yingdi@cs.ucla.edu> |
| 9 | */ |
| 10 | |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 11 | #include "contactpanel.h" |
| 12 | #include "ui_contactpanel.h" |
| 13 | |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame^] | 14 | |
| 15 | #include <QStringList> |
| 16 | #include <QItemSelectionModel> |
| 17 | #include <QModelIndex> |
| 18 | |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 19 | ContactPanel::ContactPanel(QWidget *parent) : |
| 20 | QDialog(parent), |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame^] | 21 | ui(new Ui::ContactPanel), |
| 22 | m_contactListModel(new QStringListModel) |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 23 | { |
| 24 | ui->setupUi(this); |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame^] | 25 | |
| 26 | QStringList contactNameList; |
| 27 | contactNameList << "Alex" << "Wentao" << "Yingdi"; |
| 28 | |
| 29 | m_contactListModel->setStringList(contactNameList); |
| 30 | ui->ContactList->setModel(m_contactListModel); |
| 31 | |
| 32 | QItemSelectionModel* selectionModel = ui->ContactList->selectionModel(); |
| 33 | connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), |
| 34 | this, SLOT(updateSelection(const QItemSelection &, const QItemSelection &))); |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | ContactPanel::~ContactPanel() |
| 38 | { |
| 39 | delete ui; |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame^] | 40 | delete m_contactListModel; |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 41 | } |
Yingdi Yu | 9e0dc29 | 2013-10-10 11:39:45 -0700 | [diff] [blame] | 42 | |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame^] | 43 | void |
| 44 | ContactPanel::updateSelection(const QItemSelection &selected, |
| 45 | const QItemSelection &deselected) |
| 46 | { |
| 47 | QModelIndexList items = selected.indexes(); |
| 48 | QString text = m_contactListModel->data(items.first(), Qt::DisplayRole).toString(); |
| 49 | ui->NameData->setText(text); |
| 50 | } |
Yingdi Yu | 9e0dc29 | 2013-10-10 11:39:45 -0700 | [diff] [blame] | 51 | |
| 52 | #if WAF |
| 53 | #include "contactpanel.moc" |
| 54 | #include "contactpanel.cpp.moc" |
| 55 | #endif |