Commit 6b5ad3e2 authored by Andreas Traczyk's avatar Andreas Traczyk

callwidget: fix handling of smartlist for calls

Change-Id: If360b3f73a22f8cdfc140f1be2716390bfb9ccb0
parent 3fc824d7
This diff is collapsed.
......@@ -133,8 +133,7 @@ private:
void setConversationFilter(lrc::api::profile::Type filter);
void updateConversationsFilterWidget();
void updateComboBox();
const std::string& selectedAccountId();
const std::string& selectedConvUid();
void connectAccount(const std::string& accId);
QMenu* menu_;
......@@ -166,5 +165,6 @@ private:
QMetaObject::Connection smartlistSelectionConnection_;
QMetaObject::Connection interactionRemovedConnection_;
QMetaObject::Connection contactAddedConnection_;
QMetaObject::Connection callStatusChangedConnection_;
};
......@@ -381,6 +381,12 @@
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<attribute name="headerDefaultSectionSize">
<number>0</number>
</attribute>
<attribute name="headerMinimumSectionSize">
<number>0</number>
</attribute>
</widget>
</item>
</layout>
......
......@@ -62,9 +62,15 @@ ConversationItemDelegate::paint(QPainter* painter
// menu is open
auto rowHighlight = highlightMap_.find(index.row());
if (selected) {
painter->fillRect(option.rect, RingTheme::smartlistSelection_);
painter->fillRect(option.rect, RingTheme::smartlistSelection_);
} else if (rowHighlight != highlightMap_.end() && (*rowHighlight).second) {
painter->fillRect(option.rect, RingTheme::smartlistHighlight_);
painter->fillRect(option.rect, RingTheme::smartlistHighlight_);
}
auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)).value<QString>().toStdString();
auto conversation = Utils::getConversationFromUid(convUid, *LRCInstance::getCurrentConversationModel());
if (LRCInstance::getCurrentCallModel()->hasCall(conversation->callId)) {
auto color = QColor(RingTheme::blue_.lighter(180)); color.setAlpha(128);
painter->fillRect(option.rect, color);
}
QRect &rect = opt.rect;
......
......@@ -30,17 +30,19 @@
// Client
#include "pixbufmanipulator.h"
#include "utils.h"
#include "lrcinstance.h"
SmartListModel::SmartListModel(const lrc::api::account::Info &acc, QObject *parent)
SmartListModel::SmartListModel(const std::string& accId, QObject *parent)
: QAbstractItemModel(parent),
acc_(acc)
accId_(accId)
{
}
int SmartListModel::rowCount(const QModelIndex &parent) const
{
if (!parent.isValid()) {
return acc_.conversationModel->allFilteredConversations().size();
auto& accInfo = LRCInstance::accountModel().getAccountInfo(accId_);
return accInfo.conversationModel->allFilteredConversations().size();
}
return 0; // A valid QModelIndex returns 0 as no entry has sub-elements
}
......@@ -57,32 +59,33 @@ QVariant SmartListModel::data(const QModelIndex &index, int role) const
return QVariant();
}
const auto& item = acc_.conversationModel->filteredConversation(index.row());
auto& accInfo = LRCInstance::accountModel().getAccountInfo(accId_);
const auto& item = accInfo.conversationModel->filteredConversation(index.row());
if (item.participants.size() > 0) {
try {
switch (role) {
case Role::Picture:
case Qt::DecorationRole:
return GlobalInstances::pixmapManipulator().decorationRole(item, acc_);
return GlobalInstances::pixmapManipulator().decorationRole(item, accInfo);
case Role::DisplayName:
case Qt::DisplayRole:
{
auto& contact = acc_.contactModel->getContact(item.participants[0]);
auto& contact = accInfo.contactModel->getContact(item.participants[0]);
return QVariant(QString::fromStdString(Utils::bestNameForContact(contact)));
}
case Role::DisplayID:
{
auto& contact = acc_.contactModel->getContact(item.participants[0]);
auto& contact = accInfo.contactModel->getContact(item.participants[0]);
return QVariant(QString::fromStdString(Utils::bestIdForContact(contact)));
}
case Role::Presence:
{
auto& contact = acc_.contactModel->getContact(item.participants[0]);
auto& contact = accInfo.contactModel->getContact(item.participants[0]);
return QVariant(contact.isPresent);
}
case Role::URI:
{
auto& contact = acc_.contactModel->getContact(item.participants[0]);
auto& contact = accInfo.contactModel->getContact(item.participants[0]);
return QVariant(QString::fromStdString(contact.profileInfo.uri));
}
case Role::UnreadMessagesCount:
......@@ -98,7 +101,7 @@ QVariant SmartListModel::data(const QModelIndex &index, int role) const
return QVariant(Utils::toUnderlyingValue(item.interactions.at(item.lastMessageUid).type));
case Role::ContactType:
{
auto& contact = acc_.contactModel->getContact(item.participants[0]);
auto& contact = accInfo.contactModel->getContact(item.participants[0]);
return QVariant(Utils::toUnderlyingValue(contact.profileInfo.type));
}
case Role::UID:
......@@ -144,3 +147,9 @@ Qt::ItemFlags SmartListModel::flags(const QModelIndex &index) const
}
return flags;
}
void
SmartListModel::setAccount(const std::string& accId)
{
accId_ = accId;
}
......@@ -51,7 +51,7 @@ public:
ContextMenuOpen
};
explicit SmartListModel(const lrc::api::account::Info& acc, QObject *parent = 0);
explicit SmartListModel(const std::string& accId, QObject *parent = 0);
// QAbstractItemModel
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
......@@ -61,9 +61,11 @@ public:
QModelIndex parent(const QModelIndex &child) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
void setAccount(const std::string& accId);
// hack for context menu highlight retention
bool isContextMenuOpen{ false };
private:
const AccountInfo& acc_;
std::string accId_;
};
......@@ -42,6 +42,7 @@
#include "pixbufmanipulator.h"
#include "globalsystemtray.h"
#include "lrcinstance.h"
bool
Utils::CreateStartupLink()
......@@ -428,4 +429,18 @@ Utils::generateTintedPixmap(const QString& filename, QColor color)
}
}
return QPixmap::fromImage(tmpImage);
}
std::string
Utils::getConversationFromCallId(const std::string& callId)
{
auto convModel = LRCInstance::getCurrentConversationModel();
auto conversations = convModel->allFilteredConversations();
std::string convUid;
for (auto conversation : conversations) {
if (conversation.callId == callId) {
return conversation.uid;
}
}
return "";
}
\ No newline at end of file
......@@ -78,6 +78,7 @@ namespace Utils
QImage conversationPhoto(const std::string& convUid, const lrc::api::account::Info& accountInfo);
QByteArray QByteArrayFromFile(const QString& filename);
QPixmap generateTintedPixmap(const QString& filename, QColor color);
std::string getConversationFromCallId(const std::string& callId);
template<typename E>
constexpr inline typename std::enable_if< std::is_enum<E>::value,
......
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