blob: 14a89df3f6b11a7cec8d7f5dc0ff8aa0e702926d [file] [log] [blame]
Yingdi Yu9e0dc292013-10-10 11:39:45 -07001/* -*- 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 Yudef90612013-10-09 22:34:42 -070011#include "contactpanel.h"
12#include "ui_contactpanel.h"
13
Yingdi Yu01a942b2013-10-10 15:00:58 -070014
15#include <QStringList>
16#include <QItemSelectionModel>
17#include <QModelIndex>
18
Yingdi Yudef90612013-10-09 22:34:42 -070019ContactPanel::ContactPanel(QWidget *parent) :
20 QDialog(parent),
Yingdi Yu01a942b2013-10-10 15:00:58 -070021 ui(new Ui::ContactPanel),
22 m_contactListModel(new QStringListModel)
Yingdi Yudef90612013-10-09 22:34:42 -070023{
24 ui->setupUi(this);
Yingdi Yu01a942b2013-10-10 15:00:58 -070025
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 Yudef90612013-10-09 22:34:42 -070035}
36
37ContactPanel::~ContactPanel()
38{
39 delete ui;
Yingdi Yu01a942b2013-10-10 15:00:58 -070040 delete m_contactListModel;
Yingdi Yudef90612013-10-09 22:34:42 -070041}
Yingdi Yu9e0dc292013-10-10 11:39:45 -070042
Yingdi Yu01a942b2013-10-10 15:00:58 -070043void
44ContactPanel::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 Yu9e0dc292013-10-10 11:39:45 -070051
52#if WAF
53#include "contactpanel.moc"
54#include "contactpanel.cpp.moc"
55#endif