Commit b8b13ba8 authored by Andreas Traczyk's avatar Andreas Traczyk

refactor: implement new lrc api

- use new lrc models for
 - smartlist
 - conversation view
 - account selector

Change-Id: I0a009d4e9be6f84100f49ba176d853e05364c351
parent ce4309cd
......@@ -41,7 +41,7 @@ isEmpty(QMAKE_LRELEASE) {
}
SOURCES += main.cpp\
mainwindow.cpp \
mainwindow.cpp \
callwidget.cpp \
configurationwidget.cpp \
navwidget.cpp \
......@@ -59,13 +59,11 @@ SOURCES += main.cpp\
videooverlay.cpp \
imdelegate.cpp \
contactpicker.cpp \
contactmethodpicker.cpp \
globalsystemtray.cpp \
smartlistdelegate.cpp \
conversationitemdelegate.cpp \
conversationsfilterwidget.cpp \
callutilsdialog.cpp \
combar.cpp \
idlabel.cpp \
smartlist.cpp \
ringcontactlineedit.cpp \
pixbufmanipulator.cpp \
qualitydialog.cpp \
......@@ -74,13 +72,16 @@ SOURCES += main.cpp\
sendcontactrequestwidget.cpp \
currentaccountwidget.cpp \
contactrequestwidget.cpp \
contactrequestitemdelegate.cpp \
quickactcontactrequestwidget.cpp \
contactrequestlistwidget.cpp \
smartlistselectorbuttonnotifier.cpp \
deleteaccountdialog.cpp \
bannedcontactswidget.cpp \
photoboothwidget.cpp \
deletecontactdialog.cpp
smartlistmodel.cpp \
smartlistview.cpp \
accountitemdelegate.cpp \
accountlistmodel.cpp \
messagemodel.cpp \
invitebuttonswidget.cpp
HEADERS += mainwindow.h \
callwidget.h \
......@@ -100,14 +101,12 @@ HEADERS += mainwindow.h \
videooverlay.h \
imdelegate.h \
contactpicker.h \
contactmethodpicker.h \
settingskey.h \
globalsystemtray.h \
smartlistdelegate.h \
conversationitemdelegate.h \
conversationsfilterwidget.h \
callutilsdialog.h \
combar.h \
idlabel.h \
smartlist.h \
ringcontactlineedit.h \
pixbufmanipulator.h \
qualitydialog.h \
......@@ -117,14 +116,17 @@ HEADERS += mainwindow.h \
sendcontactrequestwidget.h \
currentaccountwidget.h \
contactrequestwidget.h \
contactrequestitemdelegate.h \
quickactcontactrequestwidget.h \
contactrequestlistwidget.h \
smartlistselectorbuttonnotifier.h \
deleteaccountdialog.h \
bannedcontactswidget.h \
photoboothwidget.h \
deletecontactdialog.h \
lrcinstance.h
lrcinstance.h \
smartlistmodel.h \
smartlistview.h \
accountitemdelegate.h \
accountlistmodel.h \
messagemodel.h \
invitebuttonswidget.h
contains(DEFINES, URI_PROTOCOL) {
HEADERS += shmclient.h
......@@ -141,20 +143,17 @@ FORMS += mainwindow.ui \
videoview.ui \
videooverlay.ui \
contactpicker.ui \
contactmethodpicker.ui \
callutilsdialog.ui \
combar.ui \
qualitydialog.ui \
ringbutton.ui \
photoboothdialog.ui \
sendcontactrequestwidget.ui \
currentaccountwidget.ui \
contactrequestwidget.ui \
quickactcontactrequestwidget.ui \
deleteaccountdialog.ui \
bannedcontactswidget.ui \
photoboothwidget.ui \
deletecontactdialog.ui
invitebuttonswidget.ui
win32: LIBS += -lole32 -luuid -lshlwapi -lgdi32
LIBS += -lqrencode
......
/***************************************************************************
* Copyright (C) 2015-2017 by Savoir-faire Linux *
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
* Copyright (C) 2018 by Savoir-faire Linux *
* Author: Andreas Traczyk <andreas.traczyk@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 *
......@@ -16,43 +16,35 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#include "smartlistdelegate.h"
#include "accountitemdelegate.h"
#include <QApplication>
#include <QSortFilterProxyModel>
#include <QPainter>
#include <QTextDocument>
#include <QPixmap>
#include <QDebug>
// LRC
#include "itemdataroles.h"
#include "person.h"
#include "recentmodel.h"
#include "call.h"
// Client
#include "combar.h"
#include "utils.h"
#include "accountlistmodel.h"
#include "ringthemeutils.h"
#include <ciso646>
#undef REGISTERED
SmartListDelegate::SmartListDelegate(QObject* parent) :
QItemDelegate(parent)
AccountItemDelegate::AccountItemDelegate(QObject *parent)
: QItemDelegate(parent)
{
}
void
SmartListDelegate::paint(QPainter* painter
, const QStyleOptionViewItem& option
, const QModelIndex& index
) const
AccountItemDelegate::paint(QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
QStyleOptionViewItem opt(option);
painter->setRenderHint(QPainter::Antialiasing);
// Not having focus removes dotted lines around the item
if (opt.state & QStyle::State_HasFocus)
opt.state ^= QStyle::State_HasFocus;
if (opt.state & QStyle::State_HasFocus) {
opt.state.setFlag(QStyle::State_HasFocus, false);
}
// First, we draw the control itself
QStyle* style = opt.widget ? opt.widget->style() : QApplication::style();
......@@ -71,147 +63,77 @@ SmartListDelegate::paint(QPainter* painter
QRect &rect = opt.rect;
// Avatar drawing
opt.decorationSize = QSize(sizeImage_, sizeImage_);
opt.decorationSize = QSize(avatarSize_, avatarSize_);
opt.decorationPosition = QStyleOptionViewItem::Left;
opt.decorationAlignment = Qt::AlignCenter;
QRect rectAvatar(16 + rect.left(), rect.top() + dy_, sizeImage_, sizeImage_);
QRect rectAvatar(dy_ + rect.left(), rect.top() + dy_, avatarSize_, avatarSize_);
drawDecoration(painter, opt, rectAvatar,
QPixmap::fromImage(index.data(Qt::DecorationRole).value<QImage>())
.scaled(sizeImage_, sizeImage_, Qt::KeepAspectRatio, Qt::SmoothTransformation));
QPixmap::fromImage(index.data(AccountListModel::Role::Picture).value<QImage>())
.scaled(avatarSize_, avatarSize_, Qt::KeepAspectRatio, Qt::SmoothTransformation));
QFont font(painter->font());
// If there's unread messages, a message count is displayed
if (auto messageCount = index.data(static_cast<int>(Ring::Role::UnreadTextMessageCount)).toInt()) {
font.setPointSize(8);
QFontMetrics textFontMetrics(font);
// If there is more than 10 unread messages, "10+" is displayed
QString messageCountText = (messageCount >= 10)? "9+" : QString::number(messageCount);
// This QRect is the bounding one containing the message count to be displayed
QRect pastilleRect = textFontMetrics.boundingRect(QRect(rectAvatar.left() - (2 * sizeImage_)/9,
rectAvatar.bottom() - sizeImage_/3 - textFontMetrics.height(), sizeImage_, textFontMetrics.height()),
Qt::AlignVCenter | Qt::AlignLeft, messageCountText);
// This one is larger than pastilleRect and is used to prepare the red background
QRect bubbleRect(pastilleRect.left() - 3, pastilleRect.top(),
pastilleRect.width() + 6, pastilleRect.height() + 1);
// The background is displayed
QPainterPath path;
path.addRoundedRect(bubbleRect, 3, 3);
QPen pen(RingTheme::red_, 5);
painter->setOpacity(0.9);
painter->setPen(pen);
painter->fillPath(path, RingTheme::red_);
// Then the message count
painter->setPen(Qt::white);
painter->setOpacity(1);
painter->setFont(font);
painter->drawText(pastilleRect, Qt::AlignCenter, messageCountText);
}
// Presence indicator
QPainterPath outerCircle, innerCircle;
QPointF center(rectAvatar.right() - sizeImage_/6, (rectAvatar.bottom() - sizeImage_/6) + 1);
qreal outerCRadius = sizeImage_ / 6, innerCRadius = outerCRadius * 0.75;
QPointF center(rectAvatar.right() - avatarSize_ / 6, (rectAvatar.bottom() - avatarSize_ / 6) + 1);
qreal outerCRadius = avatarSize_ / 6, innerCRadius = outerCRadius * 0.75;
outerCircle.addEllipse(center, outerCRadius, outerCRadius);
innerCircle.addEllipse(center, innerCRadius, innerCRadius);
if (index.data(static_cast<int>(Ring::Role::IsPresent)).value<bool>()) {
auto status = index.data(static_cast<int>(AccountListModel::Role::Status)).value<int>();
auto isPresent = Utils::toEnum<lrc::api::account::Status>(status) == lrc::api::account::Status::REGISTERED;
if (isPresent) {
painter->fillPath(outerCircle, Qt::white);
painter->fillPath(innerCircle, RingTheme::green_);
painter->fillPath(innerCircle, RingTheme::presenceGreen_);
}
font.setPointSize(fontSize_);
QPen pen(painter->pen());
if (index.column() != 0) {
if (selected) {
opt.state ^= QStyle::State_Selected;
}
QItemDelegate::paint(painter, opt, index);
return;
}
painter->setPen(pen);
QRect rectTexts(16 + rect.left() + dx_ + sizeImage_,
QRect rectTexts(dx_ + rect.left() + dx_ + avatarSize_,
rect.top(),
rect.width(),
rect.height() / 2);
// The name is displayed at the avatar's right
QVariant name = index.data(static_cast<int>(Ring::Role::Name));
QVariant name = index.data(static_cast<int>(AccountListModel::Role::Alias));
if (name.isValid())
{
font.setItalic(false);
font.setBold(true);
pen.setColor(RingTheme::lightBlack_);
painter->setPen(pen);
font.setBold(true);
painter->setFont(font);
QFontMetrics fontMetrics(font);
QString nameStr = fontMetrics.elidedText(name.toString(), Qt::ElideRight
, rectTexts.width()- sizeImage_ - effectiveComBarSize_ - dx_);
QString nameStr = fontMetrics.elidedText(name.value<QString>(), Qt::ElideRight,
rectTexts.width() - avatarSize_ - dx_);
painter->drawText(rectTexts, Qt::AlignVCenter | Qt::AlignLeft, nameStr);
}
// Display the ID under the name
QString idStr = index.data(static_cast<int>(Ring::Role::Number)).value<QString>();
if (idStr != name.toString()){
QString idStr = index.data(static_cast<int>(AccountListModel::Role::Username)).value<QString>();
if (idStr != name.toString()) {
font.setItalic(false);
font.setBold(false);
pen.setColor(RingTheme::grey_);
painter->setPen(pen);
font.setItalic(true);
font.setBold(false);
painter->setFont(font);
QFontMetrics fontMetrics(font);
if (!idStr.isNull()){
idStr = fontMetrics.elidedText(idStr, Qt::ElideRight, rectTexts.width()- sizeImage_ - effectiveComBarSize_ - dx_);
painter->drawText(QRect(16 + rect.left() + dx_ + sizeImage_,
rect.top() + rect.height()/7,
rect.width(),
rect.height()/2),
if (!idStr.isNull()) {
idStr = fontMetrics.elidedText(idStr, Qt::ElideRight,
rectTexts.width() - avatarSize_ - dx_ * 2);
painter->drawText(QRect(dx_ + rect.left() + dx_ + avatarSize_,
rect.top() + dy_ * 3,
rect.width(),
rect.height() / 2),
Qt::AlignBottom | Qt::AlignLeft, idStr);
} else {
qDebug() << "This is not a Person";
}
}
// Finally, either last interaction date or call state is displayed
QVariant state = index.data(static_cast<int>(Ring::Role::FormattedState));
pen.setColor(RingTheme::grey_);
painter->setPen(pen);
font.setItalic(false);
font.setBold(false);
painter->setFont(font);
rectTexts.moveTop(cellHeight_/2);
if (state.isValid() && RecentModel::instance().getActiveCall(RecentModel::instance().peopleProxy()->mapToSource(index)))
{
painter->drawText(QRect(16 + rect.left() + dx_ + sizeImage_,
rect.top() + rect.height()/2,
rect.width(),
rect.height()/2),
Qt::AlignLeft | Qt::AlignVCenter, state.toString());
}
else
{
QVariant lastUsed = index.data(static_cast<int>(Ring::Role::FormattedLastUsed));
if (lastUsed.isValid())
{
painter->drawText(QRect(16 + rect.left() + dx_ + sizeImage_,
rect.top() + rect.height()/2,
rect.width(),
rect.height()/2),
Qt::AlignLeft | Qt::AlignVCenter, lastUsed.toString());
}
}
}
QSize
SmartListDelegate::sizeHint(const QStyleOptionViewItem& option
, const QModelIndex& index
) const
QSize AccountItemDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
{
QSize size = QItemDelegate::sizeHint(option, index);
size.setHeight(cellHeight_);
......
/***************************************************************************
* Copyright (C) 2015-2017 by Savoir-faire Linux *
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
* Copyright (C) 2018 by Savoir-faire Linux *
* Author: Andreas Traczyk <andreas.traczyk@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 *
......@@ -15,29 +15,26 @@
* 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 <QPainter>
#include <QItemDelegate>
class QPainter;
class SmartListDelegate : public QItemDelegate
class AccountItemDelegate : public QItemDelegate
{
Q_OBJECT
public:
explicit SmartListDelegate(QObject* parent = 0);
explicit AccountItemDelegate(QObject *parent = nullptr);
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 sizeImage_ = 48;
constexpr static int cellHeight_ = 60;
constexpr static int fontSize_ = 10;
const QFont font_ = QFont("Arial", fontSize_);
constexpr static int dy_ = 6;
constexpr static int dx_ = 12;
constexpr static int fontSize_ = 10;
constexpr static int effectiveComBarSize_ = 48;
constexpr static int avatarSize_ = 36;
constexpr static int cellHeight_ = 48;
};
/***************************************************************************
* Copyright (C) 2018 by Savoir-faire Linux *
* Author: Andreas Traczyk <andreas.traczyk@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 "accountlistmodel.h"
// Qt
#include <QDateTime>
// LRC
#include "globalinstances.h"
// Client
#include "pixbufmanipulator.h"
#include "lrcinstance.h"
#include "utils.h"
AccountListModel::AccountListModel(QObject *parent)
: QAbstractItemModel(parent)
{
}
int AccountListModel::rowCount(const QModelIndex &parent) const
{
if (!parent.isValid()) {
return LRCInstance::accountModel().getAccountList().size(); // count
}
return 0; // A valid QModelIndex returns 0 as no entry has sub-elements
}
int AccountListModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 1;
}
QVariant AccountListModel::data(const QModelIndex &index, int role) const
{
auto accountList = LRCInstance::accountModel().getAccountList();
if (!index.isValid() || accountList.size() == 0) {
return QVariant();
}
auto& accountInfo = LRCInstance::accountModel().getAccountInfo(accountList.at(index.row()));
switch (role) {
case Role::Alias:
case Qt::DisplayRole:
return QVariant(QString::fromStdString(accountInfo.profileInfo.alias));
case Role::Username:
return QVariant(QString::fromStdString(accountInfo.profileInfo.uri));
case Role::Type:
return QVariant(Utils::toUnderlyingValue<lrc::api::profile::Type>(accountInfo.profileInfo.type));
case Role::Status:
return QVariant(Utils::toUnderlyingValue<lrc::api::account::Status>(accountInfo.status));
case Role::Picture:
case Qt::DecorationRole:
return PixbufManipulator::accountPhoto(accountInfo);
case Role::ID:
return QVariant(QString::fromStdString(accountInfo.id));
}
return QVariant();
}
QModelIndex AccountListModel::index(int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(parent);
if (column != 0) {
return QModelIndex();
}
if (row >= 0 && row < rowCount()) {
return createIndex(row, column);
}
return QModelIndex();
}
QModelIndex AccountListModel::parent(const QModelIndex &child) const
{
Q_UNUSED(child);
return QModelIndex();
}
Qt::ItemFlags AccountListModel::flags(const QModelIndex &index) const
{
auto flags = QAbstractItemModel::flags(index) | Qt::ItemNeverHasChildren | Qt::ItemIsSelectable;
if (!index.isValid()) {
return QAbstractItemModel::flags(index);
}
return flags;
}
/**************************************************************************
* 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/>. *
**************************************************************************/
/***************************************************************************
* Copyright (C) 2018 by Savoir-faire Linux *
* Author: Andreas Traczyk <andreas.traczyk@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
#ifndef CONTACTREQUESTLISTWIDGET_H
#define CONTACTREQUESTLISTWIDGET_H
// Qt include
#include <QAbstractItemModel>
#include <QTreeView>
// LRC
#include "api/account.h"
#include "api/conversation.h"
#include "api/contact.h"
class ContactRequestListWidget : public QTreeView
class AccountListModel : public QAbstractItemModel
{
Q_OBJECT
public:
explicit ContactRequestListWidget(QWidget *parent = 0);
~ContactRequestListWidget();
void setItemModel(QAbstractItemModel *model);
enum Role {
Alias = Qt::UserRole + 1,
Username,
Picture,
Type,
Status,
ID
};
private:
QModelIndex hoveredCRIndex_;
explicit AccountListModel(QObject *parent = 0);
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;
// QAbstractItemModel
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &child) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
};
#endif // CONTACTREQUESTLISTWIDGET_H
......@@ -34,7 +34,7 @@ CallUtilsDialog::CallUtilsDialog(QWidget* parent) :
QDialog(parent),
ui(new Ui::CallUtilsDialog),
confMode_(false),