Commit 6936119a authored by Olivier SOLDANO's avatar Olivier SOLDANO Committed by Anthony Léonard

separate contact request list in dedicated widget

this patch will facilitate the future work on contact requests.
It will also alleviate callwidget code.

Change-Id: I9ec0220d5c37d960822170e30ab95bf306a7bf5e
Reviewed-by: default avatarAnthony Léonard <anthony.leonard@savoirfairelinux.com>
parent 57442b22
......@@ -76,7 +76,8 @@ SOURCES += main.cpp\
currentaccountwidget.cpp \
contactrequestwidget.cpp \
contactrequestitemdelegate.cpp \
quickactcontactrequestwidget.cpp
quickactcontactrequestwidget.cpp \
contactrequestlistwidget.cpp
HEADERS += mainwindow.h \
callwidget.h \
......@@ -116,7 +117,8 @@ HEADERS += mainwindow.h \
currentaccountwidget.h \
contactrequestwidget.h \
contactrequestitemdelegate.h \
quickactcontactrequestwidget.h
quickactcontactrequestwidget.h \
contactrequestlistwidget.h
contains(DEFINES, URI_PROTOCOL) {
HEADERS += shmclient.h
......
......@@ -33,6 +33,7 @@
#undef ERROR
#undef interface
//LRC
#include "audio/settings.h"
#include "accountmodel.h"
#include "personmodel.h"
......@@ -48,7 +49,12 @@
#include "globalinstances.h"
#include <availableaccountmodel.h>
#include "pendingcontactrequestmodel.h"
#include "profilemodel.h"
#include "profile.h"
#include "peerprofilecollection.h"
#include "localprofilecollection.h"
//Client
#include "wizarddialog.h"
#include "windowscontactbackend.h"
#include "contactpicker.h"
......@@ -60,10 +66,6 @@
#include "settingskey.h"
#include "contactrequestitemdelegate.h"
#include "profilemodel.h"
#include "profile.h"
#include "peerprofilecollection.h"
#include "localprofilecollection.h"
CallWidget::CallWidget(QWidget* parent) :
NavWidget(parent),
......@@ -114,6 +116,8 @@ CallWidget::CallWidget(QWidget* parent) :
smartListDelegate_ = new SmartListDelegate();
ui->smartList->setSmartListItemDelegate(smartListDelegate_);
ui->contactRequestList->setItemDelegate(new ContactRequestItemDelegate());
findRingAccount();
setupOutOfCallIM();
setupSmartListMenu();
......@@ -153,8 +157,6 @@ CallWidget::CallWidget(QWidget* parent) :
connect(AvailableAccountModel::instance().selectionModel(), &QItemSelectionModel::currentChanged,
this, &CallWidget::selectedAccountChanged);
ui->contactReqList->setItemDelegate(new ContactRequestItemDelegate());
// It needs to be called manually once to initialize the ui with the account selected at start.
// The second argument (previous) is set to an invalid QModelIndex as it is the first selection.
selectedAccountChanged(AvailableAccountModel::instance().selectionModel()->currentIndex(), QModelIndex());
......@@ -701,12 +703,12 @@ CallWidget::selectedAccountChanged(const QModelIndex &current, const QModelIndex
// Then, we update the pending CR list with those from the newly selected account
if (disconnect(crListSelectionConnection_)) {
// The selection model must be deleted by the application (see QT doc).
QItemSelectionModel* sMod = ui->contactReqList->selectionModel();
QItemSelectionModel* sMod = ui->contactRequestList->selectionModel();
delete sMod;
}
ui->contactReqList->setModel(ac->pendingContactRequestModel());
crListSelectionConnection_ = connect(ui->contactReqList->selectionModel(), &QItemSelectionModel::currentChanged,
ui->contactRequestList->setItemModel(ac->pendingContactRequestModel());
crListSelectionConnection_ = connect(ui->contactRequestList->selectionModel(), &QItemSelectionModel::currentChanged,
this, &CallWidget::contactReqListCurrentChanged);
// Smartlist filter is refreshed to filter out CMs not linked to the new selected account
......@@ -910,7 +912,7 @@ CallWidget::on_sendCRBackButton_clicked()
void
CallWidget::on_pendingCRBackButton_clicked()
{
ui->contactReqList->selectionModel()->clear();
ui->contactRequestList->selectionModel()->clear();
slidePage(ui->welcomePage);
}
......
......@@ -343,6 +343,9 @@
<property name="headerHidden">
<bool>true</bool>
</property>
<attribute name="headerMinimumSectionSize">
<number>0</number>
</attribute>
</widget>
</item>
</layout>
......@@ -368,7 +371,20 @@
<number>0</number>
</property>
<item>
<widget class="QListView" name="contactReqList"/>
<widget class="ContactRequestListWidget" name="contactRequestList">
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<attribute name="headerMinimumSectionSize">
<number>0</number>
</attribute>
</widget>
</item>
</layout>
</widget>
......@@ -1794,6 +1810,11 @@
<header>contactrequestwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ContactRequestListWidget</class>
<extends>QTreeView</extends>
<header>contactrequestlistwidget.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="ressources.qrc"/>
......
/**************************************************************************
* Copyright (C) 2015-2017 by Savoir-faire Linux *
* Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com> *
* Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#include "contactrequestlistwidget.h"
//LRC
#include "contactrequest.h"
#include "pendingcontactrequestmodel.h"
#include "itemdataroles.h"
//CLIENT
#include "quickactcontactrequestwidget.h"
#include <QScrollBar>
#include <QAbstractItemView>
#include <QEvent>
ContactRequestListWidget::ContactRequestListWidget(QWidget *parent) :
QTreeView(parent)
{
// for hover detection
setMouseTracking(true);
//connects the entered signal to the creation and display of hovering widget
connect(this, &QAbstractItemView::entered, [this](const QModelIndex & index) {
//get current hovered row quick action widget
auto widget = indexWidget(index);
//build and add hovering quick action widget to row and display, if already built just display
if (!widget) {
QuickActContactRequestWidget* quickBtns = new QuickActContactRequestWidget();
setIndexWidget(index, quickBtns);
connect(quickBtns, &QuickActContactRequestWidget::quickValidCRBtnClicked,
this,
[=](){ model()->data(index, static_cast<int>(Ring::Role::Object)).value<ContactRequest*>()->accept(); });
connect(quickBtns, &QuickActContactRequestWidget::quickMuteCRBtnClicked,
this,
[=](){ model()->data(index, static_cast<int>(Ring::Role::Object)).value<ContactRequest*>()->discard(); });
connect(quickBtns, &QuickActContactRequestWidget::quickBanCRBtnClicked,
this,
[=](){ model()->data(index, static_cast<int>(Ring::Role::Object)).value<ContactRequest*>()->block(); });
}
else if (index.isValid()){
indexWidget(index)->setVisible(true);
}
//hide previously shown hover widget (if any)
if(hoveredCRIndex_.isValid() and indexWidget(hoveredCRIndex_))
indexWidget(hoveredCRIndex_)->setVisible(false);
//update current hovered index
hoveredCRIndex_ = index;
});
}
ContactRequestListWidget::~ContactRequestListWidget()
{
}
void
ContactRequestListWidget::setItemModel(QAbstractItemModel *model)
{
setModel(model);
// Hide unused columns
for(int column = 1; column < model->columnCount(); column++){
hideColumn(column);
}
}
void
ContactRequestListWidget::enterEvent(QEvent* event)
{
Q_UNUSED(event);
verticalScrollBar()->show();
}
void
ContactRequestListWidget::leaveEvent(QEvent* event)
{
Q_UNUSED(event);
hoveredCRIndex_ = QModelIndex();
verticalScrollBar()->hide();
}
bool
ContactRequestListWidget::eventFilter(QObject* watched, QEvent* event)
{
if (qobject_cast<QScrollBar*>(watched) && event->type() == QEvent::Enter) {
hoveredCRIndex_ = QModelIndex();
return true;
}
return QObject::eventFilter(watched, event);
}
void
ContactRequestListWidget::drawRow(QPainter* painter,
const QStyleOptionViewItem& option, const QModelIndex& index) const
{
if(index == hoveredCRIndex_ && indexWidget(hoveredCRIndex_))
indexWidget(index)->setVisible(true);
else if(indexWidget(index))
indexWidget(index)->setVisible(false);
QTreeView::drawRow(painter, option, index);
}
/**************************************************************************
* Copyright (C) 2015-2017 by Savoir-faire Linux *
* Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com> *
* Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#ifndef CONTACTREQUESTLISTWIDGET_H
#define CONTACTREQUESTLISTWIDGET_H
#include <QTreeView>
class ContactRequestListWidget : public QTreeView
{
Q_OBJECT
public:
explicit ContactRequestListWidget(QWidget *parent = 0);
~ContactRequestListWidget();
void setItemModel(QAbstractItemModel *model);
private:
QModelIndex hoveredCRIndex_;
protected:
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
bool eventFilter(QObject *watched, QEvent *event);
void drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
#endif // CONTACTREQUESTLISTWIDGET_H
......@@ -54,7 +54,7 @@ QScrollBar::handle:vertical, QScrollBar::handle:horizontal{
background: rgb(255, 255, 255);
}
SmartList{
SmartList, ContactRequestListWidget{
background-color: white;
border: none;
}
......@@ -106,19 +106,14 @@ QListView#cipherListView::item:disabled
background-color: transparent;
}
QListView#contactReqList
{
border: none;
}
SmartList::item:selected, QListView#accountView::item:selected, QListView#contactView::item:selected,
QListView#contactReqList::item:selected{
QTreeView#contactRequestList::item:selected{
background-color: rgba(220, 220, 220, 255);
border: none;
}
SmartList::item:hover, QListView#accountView::item:hover, QListView#contactView::item:hover,
QListView#contactReqList::item:hover{
QTreeView#contactRequestList::item:hover{
background-color: rgba(242, 242, 242, 255);
}
......
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