From 56b6b0cb5a05c8fe2a2c37d2f53c7c667826f9e6 Mon Sep 17 00:00:00 2001 From: defnax Date: Mon, 24 Jun 2024 23:36:45 +0200 Subject: [PATCH] Added optional display status icon from friendslist context menu --- .../src/gui/common/FriendListModel.cpp | 48 +++++++++++++++++-- .../src/gui/common/FriendListModel.h | 5 ++ .../src/gui/common/NewFriendList.cpp | 13 +++++ retroshare-gui/src/gui/common/NewFriendList.h | 1 + .../src/gui/common/NewFriendList.ui | 8 ++++ 5 files changed, 70 insertions(+), 5 deletions(-) diff --git a/retroshare-gui/src/gui/common/FriendListModel.cpp b/retroshare-gui/src/gui/common/FriendListModel.cpp index d4c5e74b6..da2addfcc 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.cpp +++ b/retroshare-gui/src/gui/common/FriendListModel.cpp @@ -65,7 +65,7 @@ static const uint32_t NODE_DETAILS_UPDATE_DELAY = 5; // update each node every 5 RsFriendListModel::RsFriendListModel(QObject *parent) : QAbstractItemModel(parent) - , mDisplayGroups(true), mDisplayStatusString(true) + , mDisplayGroups(true), mDisplayStatusString(true), mDisplayStatusIcon (false) , mLastInternalDataUpdate(0), mLastNodeUpdate(0) { mFilterStrings.clear(); @@ -141,6 +141,24 @@ template<> bool RsFriendListModel::convertInternalIdToIndex<8>(quintptr ref,Entr return true; } +static QIcon createAvatar(const QPixmap &avatar, const QPixmap &overlay) +{ + int avatarWidth = avatar.width(); + int avatarHeight = avatar.height(); + + QPixmap pixmap(avatar); + + int overlaySize = (avatarWidth > avatarHeight) ? (avatarWidth/2.5) : (avatarHeight/2.5); + int overlayX = avatarWidth - overlaySize; + int overlayY = avatarHeight - overlaySize; + + QPainter painter(&pixmap); + painter.drawPixmap(overlayX, overlayY, overlaySize, overlaySize, overlay); + + QIcon icon; + icon.addPixmap(pixmap); + return icon; +} void RsFriendListModel::setDisplayStatusString(bool b) { @@ -148,6 +166,12 @@ void RsFriendListModel::setDisplayStatusString(bool b) postMods(); } +void RsFriendListModel::setDisplayStatusIcon(bool b) +{ + mDisplayStatusIcon = b; + postMods(); +} + void RsFriendListModel::setDisplayGroups(bool b) { mDisplayGroups = b; @@ -908,14 +932,23 @@ QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) cons if(!isProfileExpanded(entry)) { QPixmap sslAvatar = FilesDefs::getPixmapFromQtResourcePath(AVATAR_DEFAULT_IMAGE); + QPixmap sslOverlayIcon; + sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(onlineRole(entry,col).toInt())); + 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)); + if (mDisplayStatusIcon) + return QVariant(QIcon(createAvatar(sslAvatar, sslOverlayIcon))); + else + return QVariant(QIcon(sslAvatar)); - return QVariant(QIcon(sslAvatar)); + if (mDisplayStatusIcon) + return QVariant(QIcon(createAvatar(sslAvatar, sslOverlayIcon))); + else + return QVariant(QIcon(sslAvatar)); } return QVariant(); @@ -929,9 +962,14 @@ QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) cons return QVariant(); QPixmap sslAvatar; - AvatarDefs::getAvatarFromSslId(RsPeerId(hn->node_info.id.toStdString()), sslAvatar); + QPixmap sslOverlayIcon; + sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(statusRole(entry,col).toInt())); - return QVariant(QIcon(sslAvatar)); + AvatarDefs::getAvatarFromSslId(RsPeerId(hn->node_info.id.toStdString()), sslAvatar); + if (mDisplayStatusIcon) + return QVariant(QIcon(createAvatar(sslAvatar, sslOverlayIcon))); + else + return QVariant(QIcon(sslAvatar)); } default: return QVariant(); } diff --git a/retroshare-gui/src/gui/common/FriendListModel.h b/retroshare-gui/src/gui/common/FriendListModel.h index 646159377..ea4137085 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.h +++ b/retroshare-gui/src/gui/common/FriendListModel.h @@ -129,6 +129,10 @@ public: void setDisplayStatusString(bool b); bool getDisplayStatusString() const { return mDisplayStatusString; } + void setDisplayStatusIcon(bool b); + bool getDisplayStatusIcon() const { return mDisplayStatusIcon; } + + EntryType getType(const QModelIndex&) const; @@ -224,6 +228,7 @@ private: bool mDisplayGroups ; bool mDisplayStatusString ; + bool mDisplayStatusIcon ; rstime_t mLastInternalDataUpdate; rstime_t mLastNodeUpdate;; diff --git a/retroshare-gui/src/gui/common/NewFriendList.cpp b/retroshare-gui/src/gui/common/NewFriendList.cpp index bd6faec41..838e6ed40 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.cpp +++ b/retroshare-gui/src/gui/common/NewFriendList.cpp @@ -261,6 +261,7 @@ NewFriendList::NewFriendList(QWidget */*parent*/) : /* RsAutoUpdatePage(5000,par connect(ui->actionShowOfflineFriends, SIGNAL(triggered(bool)), this, SLOT(setShowUnconnected(bool))); connect(ui->actionShowState, SIGNAL(triggered(bool)), this, SLOT(setShowState(bool)) ); + connect(ui->actionShowStateIcon, SIGNAL(triggered(bool)), this, SLOT(setShowStateIcon(bool)) ); connect(ui->actionShowGroups, SIGNAL(triggered(bool)), this, SLOT(setShowGroups(bool)) ); connect(ui->actionExportFriendlist, SIGNAL(triggered()) , this, SLOT(exportFriendlistClicked())); connect(ui->actionImportFriendlist, SIGNAL(triggered()) , this, SLOT(importFriendlistClicked())); @@ -341,10 +342,12 @@ void NewFriendList::headerContextMenuRequested(QPoint /*p*/) displayMenu.addAction(ui->actionShowOfflineFriends); displayMenu.addAction(ui->actionShowState); + displayMenu.addAction(ui->actionShowStateIcon); displayMenu.addAction(ui->actionShowGroups); ui->actionShowOfflineFriends->setChecked(mProxyModel->showOfflineNodes()); ui->actionShowState->setChecked(mModel->getDisplayStatusString()); + ui->actionShowStateIcon->setChecked(mModel->getDisplayStatusIcon()); ui->actionShowGroups->setChecked(mModel->getDisplayGroups()); QHeaderView *header = ui->peerTreeWidget->header(); @@ -505,6 +508,8 @@ void NewFriendList::processSettings(bool load) mModel->setDisplayStatusString(Settings->value("showState", mModel->getDisplayStatusString()).toBool()); mModel->setDisplayGroups(Settings->value("showGroups", mModel->getDisplayGroups()).toBool()); + mModel->setDisplayStatusIcon(Settings->value("showStateIcon", mModel->getDisplayStatusIcon()).toBool()); + setColumnVisible(RsFriendListModel::COLUMN_THREAD_IP,Settings->value("showIP", isColumnVisible(RsFriendListModel::COLUMN_THREAD_IP)).toBool()); setColumnVisible(RsFriendListModel::COLUMN_THREAD_ID,Settings->value("showID", isColumnVisible(RsFriendListModel::COLUMN_THREAD_ID)).toBool()); @@ -528,6 +533,8 @@ void NewFriendList::processSettings(bool load) Settings->setValue("hideUnconnected", !mProxyModel->showOfflineNodes()); Settings->setValue("showState", mModel->getDisplayStatusString()); Settings->setValue("showGroups", mModel->getDisplayGroups()); + Settings->setValue("showStateIcon", mModel->getDisplayStatusIcon()); + Settings->setValue("showIP",isColumnVisible(RsFriendListModel::COLUMN_THREAD_IP)); Settings->setValue("showID",isColumnVisible(RsFriendListModel::COLUMN_THREAD_ID)); @@ -1643,6 +1650,12 @@ void NewFriendList::setShowState(bool show) processSettings(false); } +void NewFriendList::setShowStateIcon(bool show) +{ + applyWhileKeepingTree([show,this]() { mModel->setDisplayStatusIcon(show) ; }); + processSettings(false); +} + void NewFriendList::setShowGroups(bool show) { applyWhileKeepingTree([show,this]() { mModel->setDisplayGroups(show) ; }); diff --git a/retroshare-gui/src/gui/common/NewFriendList.h b/retroshare-gui/src/gui/common/NewFriendList.h index 2b5cd1738..7424bcfcf 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.h +++ b/retroshare-gui/src/gui/common/NewFriendList.h @@ -87,6 +87,7 @@ public slots: void setShowGroups(bool show); void setShowUnconnected(bool hidden); void setShowState(bool show); + void setShowStateIcon(bool show); void headerContextMenuRequested(QPoint); void exportFriendlistClicked(); diff --git a/retroshare-gui/src/gui/common/NewFriendList.ui b/retroshare-gui/src/gui/common/NewFriendList.ui index 20ae02eb2..3ed98fe6b 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.ui +++ b/retroshare-gui/src/gui/common/NewFriendList.ui @@ -124,6 +124,14 @@ import your friendlist including groups + + + true + + + Show status icon + +