diff --git a/RingWinClient.pro b/RingWinClient.pro index 8ab4a34908e454ae4da4bf0342c0b744aa5945d2..d397160bc9465b1d3ea02666835ec1a8a26b4f99 100644 --- a/RingWinClient.pro +++ b/RingWinClient.pro @@ -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 diff --git a/callwidget.cpp b/callwidget.cpp index cb10747f8263e900289537ea6efe180b6927d243..0920293245678d66301f822c8192306dec38d16b 100644 --- a/callwidget.cpp +++ b/callwidget.cpp @@ -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()); diff --git a/contactrequestitemdelegate.cpp b/contactrequestitemdelegate.cpp new file mode 100644 index 0000000000000000000000000000000000000000..15ee10a81cd0dd4bfb11df7b34bb864690c8b7b0 --- /dev/null +++ b/contactrequestitemdelegate.cpp @@ -0,0 +1,101 @@ +/*************************************************************************** + * 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; +} diff --git a/contactrequestitemdelegate.h b/contactrequestitemdelegate.h new file mode 100644 index 0000000000000000000000000000000000000000..2d059e34e1f344c7ff3578a37e3f5ceb08268990 --- /dev/null +++ b/contactrequestitemdelegate.h @@ -0,0 +1,43 @@ +/*************************************************************************** + * 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; +}; diff --git a/stylesheet.css b/stylesheet.css index 9bb04c9f82f9663a5279423550e7b18d7e373eb8..52ff700fecb50e95406abfcf39d968e5be24cf48 100644 --- a/stylesheet.css +++ b/stylesheet.css @@ -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); }