From 81e9cd1c5111ddbe0909db060c1ea07a931c4dc4 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 4 Sep 2019 21:35:17 +0200 Subject: [PATCH] show best icon for not expanded profiles in friend list --- retroshare-gui/src/gui/common/AvatarDefs.cpp | 17 ++-- retroshare-gui/src/gui/common/AvatarDefs.h | 6 +- .../src/gui/common/FriendListModel.cpp | 94 ++++++++++++++++++- .../src/gui/common/FriendListModel.h | 8 ++ .../src/gui/common/NewFriendList.cpp | 12 +++ retroshare-gui/src/gui/common/NewFriendList.h | 2 + 6 files changed, 126 insertions(+), 13 deletions(-) diff --git a/retroshare-gui/src/gui/common/AvatarDefs.cpp b/retroshare-gui/src/gui/common/AvatarDefs.cpp index a3b6c3b54..0332f50d0 100644 --- a/retroshare-gui/src/gui/common/AvatarDefs.cpp +++ b/retroshare-gui/src/gui/common/AvatarDefs.cpp @@ -45,7 +45,7 @@ void AvatarDefs::getOwnAvatar(QPixmap &avatar, const QString& defaultImage) free(data); } -void AvatarDefs::getAvatarFromSslId(const RsPeerId& sslId, QPixmap &avatar, const QString& defaultImage) +bool AvatarDefs::getAvatarFromSslId(const RsPeerId& sslId, QPixmap &avatar, const QString& defaultImage) { unsigned char *data = NULL; int size = 0; @@ -54,15 +54,16 @@ void AvatarDefs::getAvatarFromSslId(const RsPeerId& sslId, QPixmap &avatar, cons rsMsgs->getAvatarData(RsPeerId(sslId), data, size); if (size == 0) { avatar = QPixmap(defaultImage); - return; + return false; } /* load image */ GxsIdDetails::loadPixmapFromData(data, size, avatar, GxsIdDetails::LARGE) ; free(data); + return true; } -void AvatarDefs::getAvatarFromGxsId(const RsGxsId& gxsId, QPixmap &avatar, const QString& defaultImage) +bool AvatarDefs::getAvatarFromGxsId(const RsGxsId& gxsId, QPixmap &avatar, const QString& defaultImage) { //int size = 0; @@ -72,16 +73,18 @@ void AvatarDefs::getAvatarFromGxsId(const RsGxsId& gxsId, QPixmap &avatar, const if(!rsIdentity->getIdDetails(gxsId, details)) { avatar = QPixmap(defaultImage); - return ; + return false; } /* load image */ if(details.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(details.mAvatar.mData, details.mAvatar.mSize, avatar,GxsIdDetails::LARGE)) avatar = GxsIdDetails::makeDefaultIcon(gxsId,GxsIdDetails::LARGE); + + return true; } -void AvatarDefs::getAvatarFromGpgId(const RsPgpId& gpgId, QPixmap &avatar, const QString& defaultImage) +bool AvatarDefs::getAvatarFromGpgId(const RsPgpId& gpgId, QPixmap &avatar, const QString& defaultImage) { unsigned char *data = NULL; int size = 0; @@ -105,11 +108,13 @@ void AvatarDefs::getAvatarFromGpgId(const RsPgpId& gpgId, QPixmap &avatar, const if (size == 0) { avatar = QPixmap(defaultImage); - return; + return false; } /* load image */ GxsIdDetails::loadPixmapFromData(data, size, avatar); free(data); + + return true; } diff --git a/retroshare-gui/src/gui/common/AvatarDefs.h b/retroshare-gui/src/gui/common/AvatarDefs.h index b084b8be3..b32d58c36 100644 --- a/retroshare-gui/src/gui/common/AvatarDefs.h +++ b/retroshare-gui/src/gui/common/AvatarDefs.h @@ -35,9 +35,9 @@ class AvatarDefs public: static void getOwnAvatar(QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE); - static void getAvatarFromSslId(const RsPeerId& sslId, QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE); - static void getAvatarFromGpgId(const RsPgpId & gpgId, QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE); - static void getAvatarFromGxsId(const RsGxsId & gxsId, QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE); + static bool getAvatarFromSslId(const RsPeerId& sslId, QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE); + static bool getAvatarFromGpgId(const RsPgpId & gpgId, QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE); + static bool getAvatarFromGxsId(const RsGxsId & gxsId, QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE); }; #endif diff --git a/retroshare-gui/src/gui/common/FriendListModel.cpp b/retroshare-gui/src/gui/common/FriendListModel.cpp index 4216394e8..919998f14 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.cpp +++ b/retroshare-gui/src/gui/common/FriendListModel.cpp @@ -491,16 +491,19 @@ QVariant RsFriendListModel::sizeHintRole(const EntryIndex& e,int col) const if(e.type == ENTRY_TYPE_NODE) y_factor *= 3.0; + if((e.type == ENTRY_TYPE_PROFILE) && !isProfileExpanded(e)) + y_factor *= 3.0; + if(e.type == ENTRY_TYPE_GROUP) y_factor = std::max(y_factor, 24.0f / 14.0f ); // allows to fit the 24 pixels icon for groups in the line switch(col) { default: - case COLUMN_THREAD_NAME: return QVariant( QSize(x_factor * 170, y_factor*14*1.2f )); - case COLUMN_THREAD_IP: return QVariant( QSize(x_factor * 75 , y_factor*14*1.2f )); - case COLUMN_THREAD_ID: return QVariant( QSize(x_factor * 75 , y_factor*14*1.2f )); - case COLUMN_THREAD_LAST_CONTACT: return QVariant( QSize(x_factor * 75 , y_factor*14*1.2f )); + case COLUMN_THREAD_NAME: return QVariant( QSize(x_factor * 170, y_factor*14*1.1f )); + case COLUMN_THREAD_IP: return QVariant( QSize(x_factor * 75 , y_factor*14*1.1f )); + case COLUMN_THREAD_ID: return QVariant( QSize(x_factor * 75 , y_factor*14*1.1f )); + case COLUMN_THREAD_LAST_CONTACT: return QVariant( QSize(x_factor * 75 , y_factor*14*1.1f )); } } @@ -812,6 +815,24 @@ QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) cons { case ENTRY_TYPE_GROUP: return QVariant(QIcon(IMAGE_GROUP24)); + case ENTRY_TYPE_PROFILE: + { + if(!isProfileExpanded(entry)) + { + QPixmap sslAvatar; + + const HierarchicalProfileInformation *hn = getProfileInfo(entry); + + for(uint32_t i=0;ichild_node_indices.size();++i) + if(AvatarDefs::getAvatarFromSslId(RsPeerId(mLocations[hn->child_node_indices[i]].node_info.id.toStdString()), sslAvatar)) + return QVariant(QIcon(sslAvatar)); + + return QVariant(QIcon(sslAvatar)); + } + + return QVariant(); + } + case ENTRY_TYPE_NODE: { const HierarchicalNodeInformation *hn = getNodeInfo(entry); @@ -1131,4 +1152,69 @@ QModelIndex RsFriendListModel::getIndexOfGroup(const RsNodeGroupId& mid) const return QModelIndex(); } +void RsFriendListModel::collapseItem(const QModelIndex& index) +{ + if(getType(index) != ENTRY_TYPE_PROFILE) + return; + + EntryIndex entry; + + if(!convertInternalIdToIndex(index.internalId(),entry)) + return; + + const HierarchicalProfileInformation *hp = getProfileInfo(entry); + const HierarchicalGroupInformation *hg = getGroupInfo(entry); + + std::string s ; + + if(hg) s += hg->group_info.id.toStdString() ; + if(hp) s += hp->profile_info.gpg_id.toStdString(); + + if(!s.empty()) + mExpandedProfiles.erase(s); + + // apparently we cannot be subtle here. + emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mTopLevel.size()-1,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL)); +} + +void RsFriendListModel::expandItem(const QModelIndex& index) +{ + if(getType(index) != ENTRY_TYPE_PROFILE) + return; + + EntryIndex entry; + + if(!convertInternalIdToIndex(index.internalId(),entry)) + return; + + const HierarchicalProfileInformation *hp = getProfileInfo(entry); + const HierarchicalGroupInformation *hg = getGroupInfo(entry); + + std::string s ; + + if(hg) s += hg->group_info.id.toStdString() ; + if(hp) s += hp->profile_info.gpg_id.toStdString(); + + if(!s.empty()) + mExpandedProfiles.insert(s); + + // apparently we cannot be subtle here. + emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mTopLevel.size()-1,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL)); +} + +bool RsFriendListModel::isProfileExpanded(const EntryIndex& e) const +{ + if(e.type != ENTRY_TYPE_PROFILE) + return false; + + const HierarchicalProfileInformation *hp = getProfileInfo(e); + const HierarchicalGroupInformation *hg = getGroupInfo(e); + + std::string s ; + + if(hg) s += hg->group_info.id.toStdString() ; + if(hp) s += hp->profile_info.gpg_id.toStdString(); + + return mExpandedProfiles.find(s) != mExpandedProfiles.end(); +} diff --git a/retroshare-gui/src/gui/common/FriendListModel.h b/retroshare-gui/src/gui/common/FriendListModel.h index ac8247286..9ff26391e 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.h +++ b/retroshare-gui/src/gui/common/FriendListModel.h @@ -129,6 +129,9 @@ public: void setFilter(FilterType filter_type, const QStringList& strings) ; + void expandItem(const QModelIndex&) ; + void collapseItem(const QModelIndex&) ; + // Overloaded methods from QAbstractItemModel int rowCount(const QModelIndex& parent = QModelIndex()) const override; @@ -153,6 +156,7 @@ private: const HierarchicalProfileInformation *getProfileInfo(const EntryIndex&)const; const HierarchicalNodeInformation *getNodeInfo(const EntryIndex&) const; + bool isProfileExpanded(const EntryIndex& e) const; void checkNode(HierarchicalNodeInformation& node); bool getPeerOnlineStatus(const EntryIndex& e) const; std::map::const_iterator checkProfileIndex(const RsPgpId& pgp_id, @@ -223,5 +227,9 @@ private: // group it belows to. std::vector mTopLevel; + + // keeps track of expanded/collapsed items, so as to only show icon for collapsed profiles + + std::set mExpandedProfiles; }; diff --git a/retroshare-gui/src/gui/common/NewFriendList.cpp b/retroshare-gui/src/gui/common/NewFriendList.cpp index a9baca5fd..600dead7f 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.cpp +++ b/retroshare-gui/src/gui/common/NewFriendList.cpp @@ -211,6 +211,9 @@ NewFriendList::NewFriendList(QWidget *parent) : /* RsAutoUpdatePage(5000,parent) h->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->peerTreeWidget->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumn(int,Qt::SortOrder))); + + connect(ui->peerTreeWidget, SIGNAL(expanded(const QModelIndex&)), this, SLOT(itemExpanded(const QModelIndex&))); + connect(ui->peerTreeWidget, SIGNAL(collapsed(const QModelIndex&)), this, SLOT(itemCollapsed(const QModelIndex&))); connect(mActionSortByState, SIGNAL(toggled(bool)), this, SLOT(toggleSortByState(bool))); connect(ui->peerTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(peerTreeWidgetCustomPopupMenu())); @@ -241,6 +244,15 @@ NewFriendList::~NewFriendList() delete ui; } +void NewFriendList::itemExpanded(const QModelIndex& index) +{ + mModel->expandItem(mProxyModel->mapToSource(index)); +} +void NewFriendList::itemCollapsed(const QModelIndex& index) +{ + mModel->collapseItem(mProxyModel->mapToSource(index)); +} + void NewFriendList::sortColumn(int col,Qt::SortOrder so) { std::set expanded_indexes; diff --git a/retroshare-gui/src/gui/common/NewFriendList.h b/retroshare-gui/src/gui/common/NewFriendList.h index 9faff0b83..17214093d 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.h +++ b/retroshare-gui/src/gui/common/NewFriendList.h @@ -90,6 +90,8 @@ public slots: private slots: void sortColumn(int col,Qt::SortOrder so); + void itemExpanded(const QModelIndex&); + void itemCollapsed(const QModelIndex&); protected: void changeEvent(QEvent *e);