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

add delegate for pending contact requests

This change adds an item delegate used to display every
elements in the pending contact requests list.

The displayed view is consistent with the existing smart
list view. It shows the RingID of the sender and its picture.
This last one is currently the default picture but is expected
to become the one embedded in the payload if any.

Change-Id: Idc7afb5c6bfcda7bce67dfd042a28f9789506815
Reviewed-by: default avatarOlivier Soldano <olivier.soldano@savoirfairelinux.com>
parent 266dd30e
......@@ -74,7 +74,8 @@ SOURCES += main.cpp\
photoboothdialog.cpp \
sendcontactrequestwidget.cpp \
currentaccountwidget.cpp \
contactrequestwidget.cpp
contactrequestwidget.cpp \
contactrequestitemdelegate.cpp
HEADERS += mainwindow.h \
callwidget.h \
......@@ -112,7 +113,8 @@ HEADERS += mainwindow.h \
photoboothdialog.h \
sendcontactrequestwidget.h \
currentaccountwidget.h \
contactrequestwidget.h
contactrequestwidget.h \
contactrequestitemdelegate.h
contains(DEFINES, URI_PROTOCOL) {
HEADERS += shmclient.h
......
......@@ -58,6 +58,7 @@
#include "imdelegate.h"
#include "pixbufmanipulator.h"
#include "settingskey.h"
#include "contactrequestitemdelegate.h"
#include "profilemodel.h"
#include "profile.h"
......@@ -152,6 +153,8 @@ CallWidget::CallWidget(QWidget* parent) :
connect(AccountModel::instance().userSelectionModel(), &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(AccountModel::instance().userSelectionModel()->currentIndex(), QModelIndex());
......
/***************************************************************************
* Copyright (C) 2017 by Savoir-faire Linux *
* Author: Anthony Léonard <anthony.leonard@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 "contactrequestitemdelegate.h"
#include "ringthemeutils.h"
#include "accountmodel.h"
#include "pendingcontactrequestmodel.h"
#include "contactrequest.h"
#include <QPainter>
#include <QApplication>
ContactRequestItemDelegate::ContactRequestItemDelegate(QObject* parent) :
QItemDelegate(parent)
{}
void
ContactRequestItemDelegate::paint(QPainter* painter
, const QStyleOptionViewItem& option
, const QModelIndex& index
) const
{
painter->setRenderHint(QPainter::Antialiasing);
QStyleOptionViewItem opt(option);
// Not having focus removes dotted lines around the item
if (opt.state & QStyle::State_HasFocus)
opt.state ^= QStyle::State_HasFocus;
// First, we draw the control itself
QStyle* style = opt.widget ? opt.widget->style() : QApplication::style();
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, opt.widget);
// Then, we print the text
QFont font(painter->font());
font.setPointSize(10);
font.setBold(true);
painter->setFont(font);
QFontMetrics fontMetrics(font);
QRect rectText(opt.rect);
rectText.setLeft(opt.rect.left() + dxText_);
rectText.setTop(opt.rect.top() + dyText_);
rectText.setBottom(rectText.top() + fontMetrics.height());
QString text(index.data().toString());
text = fontMetrics.elidedText(text, Qt::ElideRight, rectText.width());
QPen pen(painter->pen());
pen.setColor(RingTheme::lightBlack_);
painter->setPen(pen);
painter->drawText(rectText,text);
// Draw a picture
// TODO: Draw the incoming CR picture if part of the payload
QRect rectPic(opt.rect.left() + dxImage_, opt.rect.top() + dyImage_, sizeImage_, sizeImage_);
drawDecoration(painter, opt, rectPic,
QPixmap::fromImage(QImage(":/images/user/btn-default-userpic.svg").scaled(QSize(sizeImage_, sizeImage_),
Qt::KeepAspectRatio,
Qt::SmoothTransformation)));
// Draw separator when item is not selected
if (not (opt.state & QStyle::State_Selected)) {
QRect rect(opt.rect);
pen.setColor(RingTheme::lightGrey_);
painter->setPen(pen);
painter->drawLine(rect.left() + separatorYPadding_, rect.bottom(),
rect.right() - separatorYPadding_,
rect.bottom());
}
}
QSize
ContactRequestItemDelegate::sizeHint(const QStyleOptionViewItem& option
, const QModelIndex& index
) const
{
QSize size = QItemDelegate::sizeHint(option, index);
size.setHeight(cellHeight_);
return size;
}
/***************************************************************************
* Copyright (C) 2017 by Savoir-faire Linux *
* Author: Anthony Léonard <anthony.leonard@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/>. *
***************************************************************************/
#pragma once
#include <QObject>
#include <QItemDelegate>
class ContactRequestItemDelegate : public QItemDelegate
{
public:
ContactRequestItemDelegate(QObject* parent = 0);
protected:
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
private:
constexpr static int cellHeight_ = 60;
constexpr static int sizeImage_ = 48;
constexpr static int dxImage_ = 16;
constexpr static int dyImage_ = 6;
constexpr static int dxText_ = dxImage_ + sizeImage_ + 12;
constexpr static int dyText_ = 13;
constexpr static int separatorYPadding_ = 20;
};
......@@ -111,12 +111,14 @@ QListView#contactReqList
border: none;
}
SmartList::item:selected, QListView#accountView::item:selected, QListView#contactView::item:selected{
SmartList::item:selected, QListView#accountView::item:selected, QListView#contactView::item:selected,
QListView#contactReqList::item:selected{
background-color: rgba(220, 220, 220, 255);
border: none;
}
SmartList::item:hover, QListView#accountView::item:hover, QListView#contactView::item:hover{
SmartList::item:hover, QListView#accountView::item:hover, QListView#contactView::item:hover,
QListView#contactReqList::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