using GxsIdRSTreeWidgetItem to display circle members

This commit is contained in:
csoler 2020-02-11 22:14:55 +01:00
parent 4c54d9d633
commit dc0b8c491c
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
5 changed files with 51 additions and 32 deletions

View File

@ -37,6 +37,7 @@
#include "gui/common/UIStateHelper.h"
#include "gui/common/UserNotify.h"
#include "gui/gxs/GxsIdDetails.h"
#include "gui/gxs/GxsIdTreeWidgetItem.h"
//#include "gui/gxs/RsGxsUpdateBroadcastBase.h"
#include "gui/msgs/MessageComposer.h"
#include "gui/settings/rsharesettings.h"
@ -767,13 +768,13 @@ void IdDialog::loadCircles(const std::list<RsGroupMetaData>& groupInfo)
#ifdef ID_DEBUG
std::cerr << "invited: " << invited << ", subscription: " << subscrb ;
#endif
QTreeWidgetItem *subitem = NULL ;
GxsIdRSTreeWidgetItem *subitem = NULL ;
// see if the item already exists
for(uint32_t k=0; k < (uint32_t)item->childCount(); ++k)
if(item->child(k)->data(CIRCLEGROUP_CIRCLE_COL_GROUPID,Qt::UserRole).toString().toStdString() == it->first.toStdString())
{
subitem = item->child(k);
subitem = dynamic_cast<GxsIdRSTreeWidgetItem*>(item->child(k));
#ifdef ID_DEBUG
std::cerr << " found existing sub item." << std::endl;
#endif
@ -802,20 +803,22 @@ void IdDialog::loadCircles(const std::list<RsGroupMetaData>& groupInfo)
#ifdef ID_DEBUG
std::cerr << " no existing sub item. Creating new one." << std::endl;
#endif
subitem = new QTreeWidgetItem(item);
subitem = new GxsIdRSTreeWidgetItem(NULL,GxsIdDetails::ICON_TYPE_AVATAR,false);
subitem->setId(it->first,CIRCLEGROUP_CIRCLE_COL_GROUPNAME,true);
RsIdentityDetails idd ;
bool has_id = rsIdentity->getIdDetails(it->first,idd) ;
QPixmap pixmap ;
// QPixmap pixmap ;
if(idd.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idd.mAvatar.mData, idd.mAvatar.mSize, pixmap,GxsIdDetails::SMALL))
pixmap = GxsIdDetails::makeDefaultIcon(it->first,GxsIdDetails::SMALL) ;
// if(idd.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idd.mAvatar.mData, idd.mAvatar.mSize, pixmap,GxsIdDetails::SMALL))
// pixmap = GxsIdDetails::makeDefaultIcon(it->first,GxsIdDetails::SMALL) ;
if(has_id)
subitem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, QString::fromUtf8(idd.mNickname.c_str())) ;
else
subitem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, tr("Unknown ID:")+QString::fromStdString(it->first.toStdString())) ;
// if(has_id)
// subitem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, QString::fromUtf8(idd.mNickname.c_str())) ;
// else
// subitem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, tr("Unknown ID:")+QString::fromStdString(it->first.toStdString())) ;
QString tooltip ;
tooltip += tr("Identity ID: ")+QString::fromStdString(it->first.toStdString()) ;
@ -836,7 +839,7 @@ void IdDialog::loadCircles(const std::list<RsGroupMetaData>& groupInfo)
subitem->setData(CIRCLEGROUP_CIRCLE_COL_GROUPFLAGS, Qt::UserRole, QVariant(it->second)) ;
subitem->setData(CIRCLEGROUP_CIRCLE_COL_GROUPID, Qt::UserRole, QString::fromStdString(it->first.toStdString())) ;
subitem->setIcon(RSID_COL_NICKNAME, QIcon(pixmap));
//subitem->setIcon(RSID_COL_NICKNAME, QIcon(pixmap));
item->addChild(subitem) ;
}
@ -1565,7 +1568,9 @@ bool IdDialog::fillIdListItem(const RsGxsIdGroup& data, QTreeWidgetItem *&item,
return false;
if (!item)
{
item = new TreeWidgetItem();
}
item->setText(RSID_COL_NICKNAME, QString::fromUtf8(data.mMeta.mGroupName.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE));
@ -1747,6 +1752,10 @@ void IdDialog::loadIdentities(const std::map<RsGxsGroupId,RsGxsIdGroup>& ids_set
else
allItem->addChild(item);
}
GxsIdLabel *label = new GxsIdLabel();
label->setId(RsGxsId(data.mMeta.mGroupId)) ;
ui->treeWidget_membership->setItemWidget(item,0,label) ;
}
/* count items */

View File

@ -22,35 +22,38 @@
#include "GxsIdDetails.h"
/** Constructor */
GxsIdLabel::GxsIdLabel(QWidget *parent)
: QLabel(parent)
GxsIdLabel::GxsIdLabel(bool show_tooltip,QWidget *parent)
: QLabel(parent),mShowTooltip(show_tooltip)
{
}
static void fillLabelCallback(GxsIdDetailsType type, const RsIdentityDetails &details, QObject *object, const QVariant &/*data*/)
{
QLabel *label = dynamic_cast<QLabel*>(object);
GxsIdLabel *label = dynamic_cast<GxsIdLabel*>(object);
if (!label) {
return;
}
label->setText(GxsIdDetails::getNameForType(type, details));
QString toolTip;
if(label->showTooltip())
{
QString toolTip;
switch (type) {
case GXS_ID_DETAILS_TYPE_EMPTY:
case GXS_ID_DETAILS_TYPE_LOADING:
case GXS_ID_DETAILS_TYPE_FAILED:
case GXS_ID_DETAILS_TYPE_BANNED:
break;
switch (type) {
case GXS_ID_DETAILS_TYPE_EMPTY:
case GXS_ID_DETAILS_TYPE_LOADING:
case GXS_ID_DETAILS_TYPE_FAILED:
case GXS_ID_DETAILS_TYPE_BANNED:
break;
case GXS_ID_DETAILS_TYPE_DONE:
toolTip = GxsIdDetails::getComment(details);
break;
case GXS_ID_DETAILS_TYPE_DONE:
toolTip = GxsIdDetails::getComment(details);
break;
}
label->setToolTip(toolTip);
}
label->setToolTip(toolTip);
}
void GxsIdLabel::setId(const RsGxsId &id)

View File

@ -29,13 +29,16 @@ class GxsIdLabel : public QLabel
Q_OBJECT
public:
GxsIdLabel(QWidget *parent = NULL);
GxsIdLabel(bool show_tooltip=true,QWidget *parent = NULL);
void setId(const RsGxsId &id);
bool getId(RsGxsId &id);
bool showTooltip() const { return mShowTooltip; }
private:
RsGxsId mId;
bool mShowTooltip;
};
#endif

View File

@ -26,8 +26,8 @@
#define BANNED_IMAGE ":/icons/yellow_biohazard64.png"
/** Constructor */
GxsIdRSTreeWidgetItem::GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, uint32_t icon_mask,QTreeWidget *parent)
: QObject(NULL), RSTreeWidgetItem(compareRole, parent), mColumn(0), mIconTypeMask(icon_mask)
GxsIdRSTreeWidgetItem::GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, uint32_t icon_mask,bool auto_tooltip,QTreeWidget *parent)
: QObject(NULL), RSTreeWidgetItem(compareRole, parent), mColumn(0), mIconTypeMask(icon_mask),mAutoTooltip(auto_tooltip)
{
init();
}
@ -72,7 +72,9 @@ static void fillGxsIdRSTreeWidgetItemCallback(GxsIdDetailsType type, const RsIde
}
int column = item->idColumn();
item->setToolTip(column, GxsIdDetails::getComment(details));
if(item->autoTooltip())
item->setToolTip(column, GxsIdDetails::getComment(details));
item->setText(column, GxsIdDetails::getNameForType(type, details));
item->setData(column, Qt::UserRole, QString::fromStdString(details.mId.toStdString()));

View File

@ -41,7 +41,7 @@ class GxsIdRSTreeWidgetItem : public QObject, public RSTreeWidgetItem
Q_OBJECT
public:
GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, uint32_t icon_mask,QTreeWidget *parent = NULL);
GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, uint32_t icon_mask,bool auto_tooltip=true,QTreeWidget *parent = NULL);
void setId(const RsGxsId &id, int column, bool retryWhenFailed);
bool getId(RsGxsId &id);
@ -57,6 +57,7 @@ public:
void setBannedState(bool b) { mBannedState = b; } // does not actually change the state, but used instead by callbacks to leave a trace
void updateBannedState() ; // checks reputation, and update is needed
bool autoTooltip() const { return mAutoTooltip; }
private slots:
void startProcess();
@ -66,8 +67,9 @@ private:
RsGxsId mId;
int mColumn;
bool mIdFound;
bool mBannedState ;
bool mBannedState ;
bool mRetryWhenFailed;
bool mAutoTooltip;
RsReputationLevel mReputationLevel;
uint32_t mIconTypeMask;
RsGxsImage mAvatar;