From 6c534360f15aedfcd69fcffa3452142ba33e57a7 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 6 Aug 2019 19:41:18 +0200 Subject: [PATCH] fixed coloring in FriendListModel --- retroshare-gui/src/gui/common/FriendList.cpp | 1 + .../src/gui/common/FriendListModel.cpp | 25 ++++++++++++++--- .../src/gui/common/FriendListModel.h | 13 +++++---- retroshare-gui/src/gui/common/NewFriendList.h | 28 ++++++++----------- .../src/gui/qss/stylesheet/qss.default | 2 +- 5 files changed, 42 insertions(+), 27 deletions(-) diff --git a/retroshare-gui/src/gui/common/FriendList.cpp b/retroshare-gui/src/gui/common/FriendList.cpp index 30603e9dc..4feaf0158 100644 --- a/retroshare-gui/src/gui/common/FriendList.cpp +++ b/retroshare-gui/src/gui/common/FriendList.cpp @@ -1014,6 +1014,7 @@ void FriendList::insertPeers() if (rsState == 0) { sslFont.setBold(true); sslColor = mTextColorStatus[RS_STATUS_ONLINE]; + } else { sslFont = StatusDefs::font(rsState); sslColor = mTextColorStatus[rsState]; diff --git a/retroshare-gui/src/gui/common/FriendListModel.cpp b/retroshare-gui/src/gui/common/FriendListModel.cpp index 2b8491a55..465c9e9b0 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.cpp +++ b/retroshare-gui/src/gui/common/FriendListModel.cpp @@ -364,8 +364,9 @@ QVariant RsFriendListModel::data(const QModelIndex &index, int role) const switch(role) { - case Qt::DisplayRole: return displayRole(entry,index.column()) ; - case Qt::FontRole: return fontRole(entry,index.column()) ; + case Qt::DisplayRole: return displayRole(entry,index.column()) ; + case Qt::FontRole: return fontRole(entry,index.column()) ; + case Qt::TextColorRole: return textColorRole(entry,index.column()) ; default: return QVariant(); } @@ -381,7 +382,6 @@ QVariant RsFriendListModel::data(const QModelIndex &index, int role) const // case Qt::DecorationRole: return decorationRole(fmpe,index.column()) ; // case Qt::ToolTipRole: return toolTipRole (fmpe,index.column()) ; // case Qt::UserRole: return userRole (fmpe,index.column()) ; -// case Qt::TextColorRole: return textColorRole (fmpe,index.column()) ; // case Qt::BackgroundRole: return backgroundRole(fmpe,index.column()) ; // // case FilterRole: return filterRole (fmpe,index.column()) ; @@ -395,7 +395,14 @@ QVariant RsFriendListModel::data(const QModelIndex &index, int role) const QVariant RsFriendListModel::textColorRole(const EntryIndex& fmpe,int column) const { - return QVariant(); + switch(fmpe.type) + { + case ENTRY_TYPE_GROUP: return QVariant(QBrush(mTextColorGroup)); +#warning CODE NEEDED HERE! + case ENTRY_TYPE_NODE: return QVariant(QBrush(mTextColorStatus[getPeerStatus(fmpe)])); + default: + return QVariant(); + } } QVariant RsFriendListModel::statusRole(const EntryIndex& fmpe,int column) const @@ -690,6 +697,16 @@ const RsFriendListModel::RsNodeDetails *RsFriendListModel::getNodeInfo(const Ent return &node.node_info; } +uint32_t RsFriendListModel::getPeerStatus(const EntryIndex& e) const +{ + const RsNodeDetails *noded = getNodeInfo(e) ; + StatusInfo info; + + if(!noded || !rsStatus->getStatus(noded->id,info)) + return RS_STATUS_OFFLINE; + + return info.status; +} QVariant RsFriendListModel::userRole(const EntryIndex& fmpe,int col) const { diff --git a/retroshare-gui/src/gui/common/FriendListModel.h b/retroshare-gui/src/gui/common/FriendListModel.h index c79f1b379..d73852450 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.h +++ b/retroshare-gui/src/gui/common/FriendListModel.h @@ -23,15 +23,10 @@ #include #include +#include "retroshare/rsstatus.h" #include "retroshare/rsmsgs.h" #include "retroshare/rspeers.h" -// This class holds the actual hierarchy of posts, represented by identifiers -// It is responsible for auto-updating when necessary and holds a mutex to allow the Model to -// safely access the data. - -// The model contains a post in place 0 that is the parent of all posts. - typedef uint32_t ForumModelIndex; // This class is the item model used by Qt to display the information @@ -148,11 +143,17 @@ public: void clear() ; + /* Color definitions (for standard see qss.default) */ + QColor mTextColorGroup; + QColor mTextColorStatus[RS_STATUS_COUNT]; + private: const RsGroupInfo *getGroupInfo (const EntryIndex&) const; const RsProfileDetails *getProfileInfo(const EntryIndex&) const; const RsNodeDetails *getNodeInfo (const EntryIndex&) const; + uint32_t getPeerStatus(const EntryIndex& e) const; + QVariant sizeHintRole (int col) const; QVariant displayRole (const EntryIndex &e, int col) const; diff --git a/retroshare-gui/src/gui/common/NewFriendList.h b/retroshare-gui/src/gui/common/NewFriendList.h index 6d5ae939b..185882d34 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.h +++ b/retroshare-gui/src/gui/common/NewFriendList.h @@ -64,19 +64,19 @@ public: void sortByColumn(int column, Qt::SortOrder sortOrder); bool isSortByState(); - QColor textColorGroup() const { return mTextColorGroup; } - QColor textColorStatusOffline() const { return mTextColorStatus[RS_STATUS_OFFLINE]; } - QColor textColorStatusAway() const { return mTextColorStatus[RS_STATUS_AWAY]; } - QColor textColorStatusBusy() const { return mTextColorStatus[RS_STATUS_BUSY]; } - QColor textColorStatusOnline() const { return mTextColorStatus[RS_STATUS_ONLINE]; } - QColor textColorStatusInactive() const { return mTextColorStatus[RS_STATUS_INACTIVE]; } + QColor textColorGroup() const { return mModel->mTextColorGroup; } + QColor textColorStatusOffline() const { return mModel->mTextColorStatus[RS_STATUS_OFFLINE ]; } + QColor textColorStatusAway() const { return mModel->mTextColorStatus[RS_STATUS_AWAY ]; } + QColor textColorStatusBusy() const { return mModel->mTextColorStatus[RS_STATUS_BUSY ]; } + QColor textColorStatusOnline() const { return mModel->mTextColorStatus[RS_STATUS_ONLINE ]; } + QColor textColorStatusInactive() const { return mModel->mTextColorStatus[RS_STATUS_INACTIVE]; } - void setTextColorGroup(QColor color) { mTextColorGroup = color; } - void setTextColorStatusOffline(QColor color) { mTextColorStatus[RS_STATUS_OFFLINE] = color; } - void setTextColorStatusAway(QColor color) { mTextColorStatus[RS_STATUS_AWAY] = color; } - void setTextColorStatusBusy(QColor color) { mTextColorStatus[RS_STATUS_BUSY] = color; } - void setTextColorStatusOnline(QColor color) { mTextColorStatus[RS_STATUS_ONLINE] = color; } - void setTextColorStatusInactive(QColor color) { mTextColorStatus[RS_STATUS_INACTIVE] = color; } + void setTextColorGroup(QColor color) { mModel->mTextColorGroup = color; } + void setTextColorStatusOffline(QColor color) { mModel->mTextColorStatus[RS_STATUS_OFFLINE ] = color; } + void setTextColorStatusAway(QColor color) { mModel->mTextColorStatus[RS_STATUS_AWAY ] = color; } + void setTextColorStatusBusy(QColor color) { mModel->mTextColorStatus[RS_STATUS_BUSY ] = color; } + void setTextColorStatusOnline(QColor color) { mModel->mTextColorStatus[RS_STATUS_ONLINE ] = color; } + void setTextColorStatusInactive(QColor color) { mModel->mTextColorStatus[RS_STATUS_INACTIVE] = color; } public slots: void filterItems(const QString &text); @@ -116,10 +116,6 @@ private: std::set openGroups; std::set openPeers; - /* Color definitions (for standard see qss.default) */ - QColor mTextColorGroup; - QColor mTextColorStatus[RS_STATUS_COUNT]; - bool getOrCreateGroup(const std::string& name, uint flag, RsNodeGroupId& id); bool getGroupIdByName(const std::string& name, RsNodeGroupId& id); diff --git a/retroshare-gui/src/gui/qss/stylesheet/qss.default b/retroshare-gui/src/gui/qss/stylesheet/qss.default index 3c33a202e..66422a25f 100644 --- a/retroshare-gui/src/gui/qss/stylesheet/qss.default +++ b/retroshare-gui/src/gui/qss/stylesheet/qss.default @@ -156,7 +156,7 @@ MessagesDialog qproperty-textColorInbox: rgb(49, 106, 197); } -FriendList +NewFriendList { qproperty-textColorStatusOffline: black; qproperty-textColorStatusAway: gray;