mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-21 13:49:04 -04:00
added column to show distribution data and moved ReputationItemDelegate to GxsIdDetails
This commit is contained in:
parent
873c0e60df
commit
d423745064
5 changed files with 80 additions and 53 deletions
|
@ -130,42 +130,6 @@ class TreeWidgetItem : public QTreeWidgetItem {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// This class allows to draw the item in the share flags column using an appropriate size
|
|
||||||
|
|
||||||
class ReputationItemDelegate: public QStyledItemDelegate
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ReputationItemDelegate() {}
|
|
||||||
|
|
||||||
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
Q_ASSERT(index.isValid());
|
|
||||||
|
|
||||||
QStyleOptionViewItemV4 opt = option;
|
|
||||||
initStyleOption(&opt, index);
|
|
||||||
// disable default icon
|
|
||||||
opt.icon = QIcon();
|
|
||||||
// draw default item
|
|
||||||
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter, 0);
|
|
||||||
|
|
||||||
const QRect r = option.rect;
|
|
||||||
|
|
||||||
// get pixmap
|
|
||||||
unsigned int icon_index = qvariant_cast<unsigned int>(index.data(Qt::DecorationRole));
|
|
||||||
|
|
||||||
if(icon_index > 4)
|
|
||||||
return ;
|
|
||||||
|
|
||||||
QIcon icon = GxsIdDetails::getReputationIcon(RsReputations::ReputationLevel(icon_index));
|
|
||||||
|
|
||||||
QPixmap pix = icon.pixmap(r.size());
|
|
||||||
|
|
||||||
// draw pixmap at center of item
|
|
||||||
const QPoint p = QPoint((r.width() - pix.width())/2, (r.height() - pix.height())/2);
|
|
||||||
painter->drawPixmap(r.topLeft() + p, pix);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Constructor */
|
/** Constructor */
|
||||||
IdDialog::IdDialog(QWidget *parent) :
|
IdDialog::IdDialog(QWidget *parent) :
|
||||||
RsGxsUpdateBroadcastPage(rsIdentity, parent),
|
RsGxsUpdateBroadcastPage(rsIdentity, parent),
|
||||||
|
@ -360,7 +324,7 @@ IdDialog::IdDialog(QWidget *parent) :
|
||||||
ui->idTreeWidget->setColumnWidth(RSID_COL_IDTYPE, 18 * fontWidth);
|
ui->idTreeWidget->setColumnWidth(RSID_COL_IDTYPE, 18 * fontWidth);
|
||||||
ui->idTreeWidget->setColumnWidth(RSID_COL_VOTES, 7 * fontWidth);
|
ui->idTreeWidget->setColumnWidth(RSID_COL_VOTES, 7 * fontWidth);
|
||||||
|
|
||||||
ui->idTreeWidget->setItemDelegateForColumn(RSID_COL_VOTES,new ReputationItemDelegate()) ;
|
ui->idTreeWidget->setItemDelegateForColumn(RSID_COL_VOTES,new ReputationItemDelegate(RsReputations::ReputationLevel(0xff))) ;
|
||||||
|
|
||||||
//QHeaderView_setSectionResizeMode(ui->idTreeWidget->header(), QHeaderView::ResizeToContents);
|
//QHeaderView_setSectionResizeMode(ui->idTreeWidget->header(), QHeaderView::ResizeToContents);
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
#define REPUTATION_NEUTRAL_ICON ":/icons/bullet_grey_128.png"
|
#define REPUTATION_NEUTRAL_ICON ":/icons/bullet_grey_128.png"
|
||||||
#define REPUTATION_REMOTELY_NEGATIVE_ICON ":/icons/yellow_biohazard64.png"
|
#define REPUTATION_REMOTELY_NEGATIVE_ICON ":/icons/yellow_biohazard64.png"
|
||||||
#define REPUTATION_LOCALLY_NEGATIVE_ICON ":/icons/red_biohazard64.png"
|
#define REPUTATION_LOCALLY_NEGATIVE_ICON ":/icons/red_biohazard64.png"
|
||||||
|
#define REPUTATION_VOID ":/icons/void_128.png"
|
||||||
|
|
||||||
#define TIMER_INTERVAL 500
|
#define TIMER_INTERVAL 500
|
||||||
#define MAX_ATTEMPTS 10
|
#define MAX_ATTEMPTS 10
|
||||||
|
@ -66,6 +67,35 @@ const int kRecognTagType_Dev_Translator = 3;
|
||||||
const int kRecognTagType_Dev_Patcher = 4;
|
const int kRecognTagType_Dev_Patcher = 4;
|
||||||
const int kRecognTagType_Dev_Developer = 5;
|
const int kRecognTagType_Dev_Developer = 5;
|
||||||
|
|
||||||
|
|
||||||
|
void ReputationItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
Q_ASSERT(index.isValid());
|
||||||
|
|
||||||
|
QStyleOptionViewItemV4 opt = option;
|
||||||
|
initStyleOption(&opt, index);
|
||||||
|
// disable default icon
|
||||||
|
opt.icon = QIcon();
|
||||||
|
// draw default item
|
||||||
|
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter, 0);
|
||||||
|
|
||||||
|
const QRect r = option.rect;
|
||||||
|
|
||||||
|
// get pixmap
|
||||||
|
unsigned int icon_index = qvariant_cast<unsigned int>(index.data(Qt::DecorationRole));
|
||||||
|
|
||||||
|
if(icon_index > mMaxLevelToDisplay)
|
||||||
|
return ;
|
||||||
|
|
||||||
|
QIcon icon = GxsIdDetails::getReputationIcon(RsReputations::ReputationLevel(icon_index),0xff);
|
||||||
|
|
||||||
|
QPixmap pix = icon.pixmap(r.size());
|
||||||
|
|
||||||
|
// draw pixmap at center of item
|
||||||
|
const QPoint p = QPoint((r.width() - pix.width())/2, (r.height() - pix.height())/2);
|
||||||
|
painter->drawPixmap(r.topLeft() + p, pix);
|
||||||
|
}
|
||||||
|
|
||||||
/* The global object */
|
/* The global object */
|
||||||
GxsIdDetails *GxsIdDetails::mInstance = NULL ;
|
GxsIdDetails *GxsIdDetails::mInstance = NULL ;
|
||||||
|
|
||||||
|
@ -964,8 +994,11 @@ QString nickname ;
|
||||||
return comment;
|
return comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon GxsIdDetails::getReputationIcon(RsReputations::ReputationLevel icon_index)
|
QIcon GxsIdDetails::getReputationIcon(RsReputations::ReputationLevel icon_index,uint32_t min_reputation)
|
||||||
{
|
{
|
||||||
|
if(icon_index >= min_reputation)
|
||||||
|
return QIcon(REPUTATION_VOID);
|
||||||
|
|
||||||
switch(icon_index)
|
switch(icon_index)
|
||||||
{
|
{
|
||||||
case RsReputations::REPUTATION_LOCALLY_NEGATIVE: return QIcon(REPUTATION_LOCALLY_NEGATIVE_ICON) ; break ;
|
case RsReputations::REPUTATION_LOCALLY_NEGATIVE: return QIcon(REPUTATION_LOCALLY_NEGATIVE_ICON) ; break ;
|
||||||
|
@ -979,7 +1012,7 @@ QIcon GxsIdDetails::getReputationIcon(RsReputations::ReputationLevel icon_index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GxsIdDetails::getIcons(const RsIdentityDetails &details, QList<QIcon> &icons,uint32_t icon_types)
|
void GxsIdDetails::getIcons(const RsIdentityDetails &details, QList<QIcon> &icons,uint32_t icon_types,uint32_t minimal_required_reputation)
|
||||||
{
|
{
|
||||||
QPixmap pix ;
|
QPixmap pix ;
|
||||||
|
|
||||||
|
@ -990,9 +1023,8 @@ void GxsIdDetails::getIcons(const RsIdentityDetails &details, QList<QIcon> &icon
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(icon_types & ICON_TYPE_REPUTATION)
|
if(icon_types & ICON_TYPE_REPUTATION)
|
||||||
icons.push_back(getReputationIcon(details.mReputation.mOverallReputationLevel)) ;
|
icons.push_back(getReputationIcon(details.mReputation.mOverallReputationLevel,minimal_required_reputation)) ;
|
||||||
|
|
||||||
if(icon_types & ICON_TYPE_AVATAR)
|
if(icon_types & ICON_TYPE_AVATAR)
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
#include <retroshare/rsidentity.h>
|
#include <retroshare/rsidentity.h>
|
||||||
|
|
||||||
|
@ -45,6 +46,21 @@ enum GxsIdDetailsType
|
||||||
|
|
||||||
typedef void (*GxsIdDetailsCallbackFunction)(GxsIdDetailsType type, const RsIdentityDetails &details, QObject *object, const QVariant &data);
|
typedef void (*GxsIdDetailsCallbackFunction)(GxsIdDetailsType type, const RsIdentityDetails &details, QObject *object, const QVariant &data);
|
||||||
|
|
||||||
|
// This class allows to draw the item in a reputation column using an appropriate size. The max_level_to_display parameter allows to replace
|
||||||
|
// the icon by an empty icon when needed. This allows to keep the focus on the critical icons only.
|
||||||
|
|
||||||
|
class ReputationItemDelegate: public QStyledItemDelegate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ReputationItemDelegate(RsReputations::ReputationLevel max_level_to_display) : mMaxLevelToDisplay(max_level_to_display) {}
|
||||||
|
|
||||||
|
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32_t mMaxLevelToDisplay ;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class GxsIdDetails : public QObject
|
class GxsIdDetails : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -67,7 +83,13 @@ public:
|
||||||
|
|
||||||
static QString getName(const RsIdentityDetails &details);
|
static QString getName(const RsIdentityDetails &details);
|
||||||
static QString getComment(const RsIdentityDetails &details);
|
static QString getComment(const RsIdentityDetails &details);
|
||||||
static void getIcons(const RsIdentityDetails &details, QList<QIcon> &icons,uint32_t icon_types=ICON_TYPE_ALL);
|
|
||||||
|
/*!
|
||||||
|
* \brief getIcons
|
||||||
|
* Returns the list of icons to display along with the ID name. The types of icons to show is a compound of the ICON_TYPE_* flags.
|
||||||
|
* If reputation is needed and exceeds the minimal reputation, an empty/void icon is showsn . This allow to only show reputation for IDs for which a problem exists.
|
||||||
|
*/
|
||||||
|
static void getIcons(const RsIdentityDetails &details, QList<QIcon> &icons, uint32_t icon_types=ICON_TYPE_ALL, uint32_t minimal_required_reputation=0xff);
|
||||||
|
|
||||||
static QString getEmptyIdText();
|
static QString getEmptyIdText();
|
||||||
static QString getLoadingText(const RsGxsId &id);
|
static QString getLoadingText(const RsGxsId &id);
|
||||||
|
@ -76,7 +98,7 @@ public:
|
||||||
static QString getNameForType(GxsIdDetailsType type, const RsIdentityDetails &details);
|
static QString getNameForType(GxsIdDetailsType type, const RsIdentityDetails &details);
|
||||||
|
|
||||||
static QIcon getLoadingIcon(const RsGxsId &id);
|
static QIcon getLoadingIcon(const RsGxsId &id);
|
||||||
static QIcon getReputationIcon(RsReputations::ReputationLevel icon_index);
|
static QIcon getReputationIcon(RsReputations::ReputationLevel icon_index, uint32_t min_reputation);
|
||||||
|
|
||||||
static void GenerateCombinedPixmap(QPixmap &pixmap, const QList<QIcon> &icons, int iconSize);
|
static void GenerateCombinedPixmap(QPixmap &pixmap, const QList<QIcon> &icons, int iconSize);
|
||||||
|
|
||||||
|
|
|
@ -67,13 +67,14 @@
|
||||||
#define VIEW_FLAT 2
|
#define VIEW_FLAT 2
|
||||||
|
|
||||||
/* Thread constants */
|
/* Thread constants */
|
||||||
#define COLUMN_THREAD_COUNT 6
|
|
||||||
#define COLUMN_THREAD_TITLE 0
|
#define COLUMN_THREAD_TITLE 0
|
||||||
#define COLUMN_THREAD_READ 1
|
#define COLUMN_THREAD_READ 1
|
||||||
#define COLUMN_THREAD_DATE 2
|
#define COLUMN_THREAD_DATE 2
|
||||||
#define COLUMN_THREAD_AUTHOR 3
|
#define COLUMN_THREAD_DISTRIBUTION 3
|
||||||
#define COLUMN_THREAD_SIGNED 4
|
#define COLUMN_THREAD_AUTHOR 4
|
||||||
#define COLUMN_THREAD_CONTENT 5
|
#define COLUMN_THREAD_SIGNED 5
|
||||||
|
#define COLUMN_THREAD_CONTENT 6
|
||||||
|
#define COLUMN_THREAD_COUNT 7
|
||||||
|
|
||||||
#define COLUMN_THREAD_DATA 0 // column for storing the userdata like msgid and parentid
|
#define COLUMN_THREAD_DATA 0 // column for storing the userdata like msgid and parentid
|
||||||
|
|
||||||
|
@ -137,6 +138,8 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
|
||||||
mThreadCompareRole = new RSTreeWidgetItemCompareRole;
|
mThreadCompareRole = new RSTreeWidgetItemCompareRole;
|
||||||
mThreadCompareRole->setRole(COLUMN_THREAD_DATE, ROLE_THREAD_SORT);
|
mThreadCompareRole->setRole(COLUMN_THREAD_DATE, ROLE_THREAD_SORT);
|
||||||
|
|
||||||
|
ui->threadTreeWidget->setItemDelegateForColumn(COLUMN_THREAD_DISTRIBUTION,new ReputationItemDelegate(RsReputations::REPUTATION_NEUTRAL)) ;
|
||||||
|
|
||||||
connect(ui->threadTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(threadListCustomPopupMenu(QPoint)));
|
connect(ui->threadTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(threadListCustomPopupMenu(QPoint)));
|
||||||
connect(ui->postText, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTextBrowser(QPoint)));
|
connect(ui->postText, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTextBrowser(QPoint)));
|
||||||
|
|
||||||
|
@ -1000,7 +1003,7 @@ QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForum
|
||||||
|
|
||||||
bool redacted = (reputation_level == RsReputations::REPUTATION_LOCALLY_NEGATIVE) ;
|
bool redacted = (reputation_level == RsReputations::REPUTATION_LOCALLY_NEGATIVE) ;
|
||||||
|
|
||||||
GxsIdRSTreeWidgetItem *item = new GxsIdRSTreeWidgetItem(mThreadCompareRole,GxsIdDetails::ICON_TYPE_REPUTATION | GxsIdDetails::ICON_TYPE_AVATAR );
|
GxsIdRSTreeWidgetItem *item = new GxsIdRSTreeWidgetItem(mThreadCompareRole,GxsIdDetails::ICON_TYPE_AVATAR );
|
||||||
item->moveToThread(ui->threadTreeWidget->thread());
|
item->moveToThread(ui->threadTreeWidget->thread());
|
||||||
|
|
||||||
if(redacted)
|
if(redacted)
|
||||||
|
@ -1008,6 +1011,7 @@ QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForum
|
||||||
else
|
else
|
||||||
item->setText(COLUMN_THREAD_TITLE, QString::fromUtf8(msg.mMeta.mMsgName.c_str()));
|
item->setText(COLUMN_THREAD_TITLE, QString::fromUtf8(msg.mMeta.mMsgName.c_str()));
|
||||||
|
|
||||||
|
item->setData(COLUMN_THREAD_DISTRIBUTION,Qt::DecorationRole, reputation_level) ;
|
||||||
|
|
||||||
//msg.mMeta.mChildTs Was not updated when received new child
|
//msg.mMeta.mChildTs Was not updated when received new child
|
||||||
// so do it here.
|
// so do it here.
|
||||||
|
@ -1096,7 +1100,7 @@ QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForum
|
||||||
|
|
||||||
QTreeWidgetItem *GxsForumThreadWidget::generateMissingItem(const RsGxsMessageId &msgId)
|
QTreeWidgetItem *GxsForumThreadWidget::generateMissingItem(const RsGxsMessageId &msgId)
|
||||||
{
|
{
|
||||||
GxsIdRSTreeWidgetItem *item = new GxsIdRSTreeWidgetItem(mThreadCompareRole,GxsIdDetails::ICON_TYPE_REPUTATION | GxsIdDetails::ICON_TYPE_AVATAR);
|
GxsIdRSTreeWidgetItem *item = new GxsIdRSTreeWidgetItem(mThreadCompareRole,GxsIdDetails::ICON_TYPE_AVATAR);
|
||||||
|
|
||||||
item->setText(COLUMN_THREAD_TITLE, tr("[ ... Missing Message ... ]"));
|
item->setText(COLUMN_THREAD_TITLE, tr("[ ... Missing Message ... ]"));
|
||||||
item->setData(COLUMN_THREAD_DATA, ROLE_THREAD_MSGID, QString::fromStdString(msgId.toStdString()));
|
item->setData(COLUMN_THREAD_DATA, ROLE_THREAD_MSGID, QString::fromStdString(msgId.toStdString()));
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>851</width>
|
<width>1217</width>
|
||||||
<height>721</height>
|
<height>721</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
@ -238,6 +238,11 @@
|
||||||
<string>Date</string>
|
<string>Date</string>
|
||||||
</property>
|
</property>
|
||||||
</column>
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Distribution</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
<column>
|
<column>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Author</string>
|
<string>Author</string>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue