Commit 7a8517d2 authored by Edric Milaret's avatar Edric Milaret

use the selection model from the recent model

Change-Id: I3b371a53f193944eccc349b5d0c42ef13dc41270
Tuleap: #148
parent a20501fd
...@@ -95,15 +95,6 @@ CallWidget::CallWidget(QWidget* parent) : ...@@ -95,15 +95,6 @@ CallWidget::CallWidget(QWidget* parent) :
RecentModel::instance().peopleProxy()->setFilterRole(static_cast<int>(Ring::Role::Name)); RecentModel::instance().peopleProxy()->setFilterRole(static_cast<int>(Ring::Role::Name));
RecentModel::instance().peopleProxy()->setFilterCaseSensitivity(Qt::CaseInsensitive); RecentModel::instance().peopleProxy()->setFilterCaseSensitivity(Qt::CaseInsensitive);
ui->smartList->setModel(RecentModel::instance().peopleProxy()); ui->smartList->setModel(RecentModel::instance().peopleProxy());
connect(ui->smartList->selectionModel(),
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this,
SLOT(smartListSelectionChanged(QItemSelection,QItemSelection)));
connect(ui->smartList, &QTreeView::entered, this, &CallWidget::on_entered);
smartListDelegate_ = new SmartListDelegate();
ui->smartList->setSmartListItemDelegate(smartListDelegate_);
PersonModel::instance(). PersonModel::instance().
addCollection<WindowsContactBackend>(LoadOptions::FORCE_ENABLED); addCollection<WindowsContactBackend>(LoadOptions::FORCE_ENABLED);
...@@ -129,6 +120,11 @@ CallWidget::CallWidget(QWidget* parent) : ...@@ -129,6 +120,11 @@ CallWidget::CallWidget(QWidget* parent) :
ui->historyList->setExpanded(idx, true); ui->historyList->setExpanded(idx, true);
}); });
connect(ui->smartList, &QTreeView::entered, this, &CallWidget::on_entered);
smartListDelegate_ = new SmartListDelegate();
ui->smartList->setSmartListItemDelegate(smartListDelegate_);
ui->historyList->setContextMenuPolicy(Qt::CustomContextMenu); ui->historyList->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->historyList, &QListView::customContextMenuRequested, [=](const QPoint& pos){ connect(ui->historyList, &QListView::customContextMenuRequested, [=](const QPoint& pos){
if (ui->historyList->currentIndex().parent().isValid()) { if (ui->historyList->currentIndex().parent().isValid()) {
...@@ -160,6 +156,21 @@ CallWidget::CallWidget(QWidget* parent) : ...@@ -160,6 +156,21 @@ CallWidget::CallWidget(QWidget* parent) :
setupOutOfCallIM(); setupOutOfCallIM();
setupSmartListMenu(); setupSmartListMenu();
connect(RecentModel::instance().selectionModel(),
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this,
SLOT(smartListSelectionChanged(QItemSelection,QItemSelection)));
connect(RecentModel::instance().selectionModel(), &QItemSelectionModel::selectionChanged, [=](const QItemSelection &selected, const QItemSelection &deselected) {
Q_UNUSED(deselected)
if (selected.size()) {
auto idx = selected.indexes().first();
auto realIdx = RecentModel::instance().peopleProxy()->mapFromSource(idx);
ui->smartList->selectionModel()->setCurrentIndex(realIdx, QItemSelectionModel::ClearAndSelect);
} else
ui->smartList->clearSelection();
});
} catch (const std::exception& e) { } catch (const std::exception& e) {
qDebug() << "INIT ERROR" << e.what(); qDebug() << "INIT ERROR" << e.what();
} }
...@@ -173,6 +184,7 @@ CallWidget::~CallWidget() ...@@ -173,6 +184,7 @@ CallWidget::~CallWidget()
delete imDelegate_; delete imDelegate_;
delete welcomePageAnim_; delete welcomePageAnim_;
delete messagingPageAnim_; delete messagingPageAnim_;
delete smartListDelegate_;
} }
void void
...@@ -371,12 +383,7 @@ CallWidget::callStateChanged(Call* call, Call::State previousState) ...@@ -371,12 +383,7 @@ CallWidget::callStateChanged(Call* call, Call::State previousState)
setActualCall(nullptr); setActualCall(nullptr);
ui->instantMessagingWidget->setMediaText(nullptr); ui->instantMessagingWidget->setMediaText(nullptr);
ui->stackedWidget->setCurrentWidget(ui->welcomePage); ui->stackedWidget->setCurrentWidget(ui->welcomePage);
//TODO : Link this so that recentModel get selected correctly RecentModel::instance().selectionModel()->clear();
// auto onHoldCall = callModel_->getActiveCalls().first();
// if (onHoldCall != nullptr && onHoldCall->state() == Call::State::HOLD) {
// setActualCall(onHoldCall);
// onHoldCall->performAction(Call::Action::HOLD);
// }
} else if (call->state() == Call::State::CURRENT) { } else if (call->state() == Call::State::CURRENT) {
ui->instantMessagingWidget->setMediaText(actualCall_); ui->instantMessagingWidget->setMediaText(actualCall_);
ui->stackedWidget->setCurrentWidget(ui->videoPage); ui->stackedWidget->setCurrentWidget(ui->videoPage);
...@@ -483,15 +490,17 @@ CallWidget::smartListSelectionChanged(const QItemSelection& newSel, const QItemS ...@@ -483,15 +490,17 @@ CallWidget::smartListSelectionChanged(const QItemSelection& newSel, const QItemS
if (not newIdx.isValid()) if (not newIdx.isValid())
return; return;
auto nodeIdx = RecentModel::instance().peopleProxy()->mapToSource(newIdx); auto newIdxCall = RecentModel::instance().getActiveCall(newIdx);
auto newIdxCall = RecentModel::instance().getActiveCall(nodeIdx);
if (newIdxCall && newIdxCall != actualCall_) { if (newIdxCall && newIdxCall != actualCall_) {
setActualCall(newIdxCall); setActualCall(newIdxCall);
ui->stackedWidget->setCurrentWidget(ui->videoPage); if (newIdxCall->state() == Call::State::INCOMING
&& !newIdxCall->account()->isAutoAnswer())
ui->stackedWidget->setCurrentWidget(ui->callInvitePage);
else
ui->stackedWidget->setCurrentWidget(ui->videoPage);
} else if (newIdxCall == nullptr){ } else if (newIdxCall == nullptr){
setActualCall(nullptr); setActualCall(nullptr);
showIMOutOfCall(); showIMOutOfCall(newIdx);
} else { } else {
setActualCall(nullptr); setActualCall(nullptr);
ui->stackedWidget->setCurrentWidget(ui->welcomePage); ui->stackedWidget->setCurrentWidget(ui->welcomePage);
...@@ -552,16 +561,10 @@ CallWidget::on_btnvideo_clicked() ...@@ -552,16 +561,10 @@ CallWidget::on_btnvideo_clicked()
} }
void void
CallWidget::showIMOutOfCall() CallWidget::showIMOutOfCall(const QModelIndex& nodeIdx)
{ {
if (not highLightedIndex_.isValid())
return;
ui->smartList->selectionModel()->select(highLightedIndex_, QItemSelectionModel::ClearAndSelect);
ui->contactMethodComboBox->clear(); ui->contactMethodComboBox->clear();
auto nodeIdx = RecentModel::instance().peopleProxy()->mapToSource(highLightedIndex_);
ui->imNameLabel->setText(QString(tr("Conversation with %1", "%1 is the contact name")) ui->imNameLabel->setText(QString(tr("Conversation with %1", "%1 is the contact name"))
.arg(nodeIdx.data(static_cast<int>(Ring::Role::Name)).toString())); .arg(nodeIdx.data(static_cast<int>(Ring::Role::Name)).toString()));
auto cmVector = RecentModel::instance().getContactMethods(nodeIdx); auto cmVector = RecentModel::instance().getContactMethods(nodeIdx);
...@@ -647,6 +650,7 @@ CallWidget::on_ringContactLineEdit_textChanged(const QString& text) ...@@ -647,6 +650,7 @@ CallWidget::on_ringContactLineEdit_textChanged(const QString& text)
void void
CallWidget::on_imBackButton_clicked() CallWidget::on_imBackButton_clicked()
{ {
RecentModel::instance().selectionModel()->clear();
slideToLeft(welcomePageAnim_, ui->welcomePage); slideToLeft(welcomePageAnim_, ui->welcomePage);
} }
...@@ -671,3 +675,11 @@ CallWidget::slideToRight(QPropertyAnimation* anim, QWidget* widget) ...@@ -671,3 +675,11 @@ CallWidget::slideToRight(QPropertyAnimation* anim, QWidget* widget)
anim->setEasingCurve(QEasingCurve::OutQuad); anim->setEasingCurve(QEasingCurve::OutQuad);
anim->start(); anim->start();
} }
void
CallWidget::on_smartList_clicked(const QModelIndex& index)
{
RecentModel::instance().selectionModel()->setCurrentIndex(
RecentModel::instance().peopleProxy()->mapToSource(index),
QItemSelectionModel::ClearAndSelect);
}
...@@ -63,7 +63,7 @@ public slots: ...@@ -63,7 +63,7 @@ public slots:
void on_ringContactLineEdit_returnPressed(); void on_ringContactLineEdit_returnPressed();
void on_btnCall_clicked(); void on_btnCall_clicked();
void on_btnvideo_clicked(); void on_btnvideo_clicked();
void showIMOutOfCall(); void showIMOutOfCall(const QModelIndex& newIdx);
inline void on_entered(const QModelIndex& i){highLightedIndex_ = i;}; inline void on_entered(const QModelIndex& i){highLightedIndex_ = i;};
//UI SLOTS //UI SLOTS
...@@ -79,6 +79,7 @@ private slots: ...@@ -79,6 +79,7 @@ private slots:
void on_contactMethodComboBox_currentIndexChanged(const QString& number); void on_contactMethodComboBox_currentIndexChanged(const QString& number);
void on_ringContactLineEdit_textChanged(const QString& text); void on_ringContactLineEdit_textChanged(const QString& text);
void on_imBackButton_clicked(); void on_imBackButton_clicked();
void on_smartList_clicked(const QModelIndex &index);
private slots: private slots:
void callIncoming(Call* call); void callIncoming(Call* call);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment