mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-15 18:09:32 -04:00
Added in Icons to GxsIDs.
Can support: - "Unique" Icon based of GxsID. - Icon indicating PGP/Anon. - Icons for RecognTags. Needs more work to Make Unique Icons look good. and Add Icon sets. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7084 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
731d28bd41
commit
a4f0221d89
10 changed files with 567 additions and 145 deletions
|
@ -22,6 +22,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "GxsIdChooser.h"
|
#include "GxsIdChooser.h"
|
||||||
|
#include "GxsIdDetails.h"
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
@ -63,41 +64,18 @@ bool GxsIdChooser::MakeIdDesc(const RsGxsId &id, QString &desc)
|
||||||
{
|
{
|
||||||
RsIdentityDetails details;
|
RsIdentityDetails details;
|
||||||
|
|
||||||
bool found = rsIdentity->getIdDetails(id, details);
|
std::list<QIcon> icons;
|
||||||
if (found)
|
if (!GxsIdDetails::MakeIdDesc(id, false, desc, icons))
|
||||||
{
|
{
|
||||||
desc = QString::fromUtf8(details.mNickname.c_str());
|
if (mTimerCount > MAX_TRY)
|
||||||
|
|
||||||
std::list<RsRecognTag>::iterator it;
|
|
||||||
for(it = details.mRecognTags.begin(); it != details.mRecognTags.end(); it++)
|
|
||||||
{
|
{
|
||||||
desc += " (";
|
|
||||||
desc += QString::number(it->tag_class);
|
|
||||||
desc += ":";
|
|
||||||
desc += QString::number(it->tag_type);
|
|
||||||
desc += ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (details.mPgpLinked)
|
|
||||||
{
|
|
||||||
desc += " (PGP) [";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
desc += " (Anon) [";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (mTimerCount <= MAX_TRY) {
|
|
||||||
desc = QString("%1 ... [").arg(tr("Loading"));
|
|
||||||
} else {
|
|
||||||
desc = QString("%1 ... [").arg(tr("Not found"));
|
desc = QString("%1 ... [").arg(tr("Not found"));
|
||||||
|
desc += QString::fromStdString(id.substr(0,5));
|
||||||
|
desc += "...]";
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
desc += QString::fromStdString(id.substr(0,5));
|
|
||||||
desc += "...]";
|
|
||||||
|
|
||||||
return found;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GxsIdChooser::addPrivateId(const RsGxsId &gxsId, bool replace)
|
void GxsIdChooser::addPrivateId(const RsGxsId &gxsId, bool replace)
|
||||||
|
|
216
retroshare-gui/src/gui/gxs/GxsIdDetails.cpp
Normal file
216
retroshare-gui/src/gui/gxs/GxsIdDetails.cpp
Normal file
|
@ -0,0 +1,216 @@
|
||||||
|
/*
|
||||||
|
* Retroshare Gxs Support
|
||||||
|
*
|
||||||
|
* Copyright 2012-2013 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2.1 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "GxsIdDetails.h"
|
||||||
|
|
||||||
|
#include <retroshare/rspeers.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
|
||||||
|
/* Images for tag icons */
|
||||||
|
#define IMAGE_LOADING ":/images/folder-draft.png"
|
||||||
|
#define IMAGE_PGPKNOWN ":/images/vote_up.png"
|
||||||
|
#define IMAGE_PGPUNKNOWN ":/images/vote_up.png"
|
||||||
|
#define IMAGE_ANON ":/images/vote_down.png"
|
||||||
|
|
||||||
|
#define IMAGE_DEV_AMBASSADOR ":/images/vote_down.png"
|
||||||
|
#define IMAGE_DEV_CONTRIBUTOR ":/images/vote_down.png"
|
||||||
|
#define IMAGE_DEV_TRANSLATOR ":/images/vote_down.png"
|
||||||
|
#define IMAGE_DEV_PATCHER ":/images/vote_down.png"
|
||||||
|
#define IMAGE_DEV_DEVELOPER ":/images/vote_down.png"
|
||||||
|
|
||||||
|
static const int IconSize = 20;
|
||||||
|
|
||||||
|
const int kRecognTagClass_DEVELOPMENT = 1;
|
||||||
|
|
||||||
|
const int kRecognTagType_Dev_Ambassador = 1;
|
||||||
|
const int kRecognTagType_Dev_Contributor = 2;
|
||||||
|
const int kRecognTagType_Dev_Translator = 3;
|
||||||
|
const int kRecognTagType_Dev_Patcher = 4;
|
||||||
|
const int kRecognTagType_Dev_Developer = 5;
|
||||||
|
|
||||||
|
|
||||||
|
static bool findTagIcon(int tag_class, int tag_type, QIcon &icon)
|
||||||
|
{
|
||||||
|
switch(tag_class)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case 0:
|
||||||
|
icon = QIcon(IMAGE_DEV_AMBASSADOR);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
icon = QIcon(IMAGE_DEV_CONTRIBUTOR);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool CreateIdIcon(const std::string &id, QIcon &idIcon)
|
||||||
|
{
|
||||||
|
QPixmap image(IconSize, IconSize);
|
||||||
|
QPainter painter(&image);
|
||||||
|
|
||||||
|
painter.fillRect(0, 0, IconSize, IconSize, Qt::black);
|
||||||
|
|
||||||
|
int len = id.length();
|
||||||
|
for(int i = 0; i + 1 < len; i += 2)
|
||||||
|
{
|
||||||
|
char hex1 = id[i];
|
||||||
|
char hex2 = id[i+1];
|
||||||
|
int x = (hex1 >= 'a') ? (hex1 - 'a' + 10) : (hex1 - '0');
|
||||||
|
int y = (hex2 >= 'a') ? (hex2 - 'a' + 10) : (hex2 - '0');
|
||||||
|
painter.fillRect(x, y, x+1, y+1, Qt::green);
|
||||||
|
}
|
||||||
|
idIcon = QIcon(image);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool GxsIdDetails::MakeIdDesc(const RsGxsId &id, bool doIcons, QString &str, std::list<QIcon> &icons)
|
||||||
|
{
|
||||||
|
RsIdentityDetails details;
|
||||||
|
|
||||||
|
if (!rsIdentity->getIdDetails(id, details))
|
||||||
|
{
|
||||||
|
std::cerr << "GxsIdTreeWidget::MakeIdDesc() FAILED TO GET ID";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
str = QObject::tr("Loading... ") + QString::fromStdString(id.substr(0,5));
|
||||||
|
|
||||||
|
if (!doIcons)
|
||||||
|
{
|
||||||
|
QIcon baseIcon = QIcon(IMAGE_LOADING);
|
||||||
|
icons.push_back(baseIcon);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
str = QString::fromUtf8(details.mNickname.c_str());
|
||||||
|
|
||||||
|
std::list<RsRecognTag>::iterator it;
|
||||||
|
for(it = details.mRecognTags.begin(); it != details.mRecognTags.end(); it++)
|
||||||
|
{
|
||||||
|
str += " (";
|
||||||
|
str += QString::number(it->tag_class);
|
||||||
|
str += ":";
|
||||||
|
str += QString::number(it->tag_type);
|
||||||
|
str += ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool addCode = true;
|
||||||
|
if (details.mPgpLinked)
|
||||||
|
{
|
||||||
|
str += " (PGP) [";
|
||||||
|
if (details.mPgpKnown)
|
||||||
|
{
|
||||||
|
/* look up real name */
|
||||||
|
std::string authorName = rsPeers->getPeerName(details.mPgpId);
|
||||||
|
str += QString::fromUtf8(authorName.c_str());
|
||||||
|
str += "]";
|
||||||
|
|
||||||
|
addCode = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
str += " (Anon) [";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addCode)
|
||||||
|
{
|
||||||
|
str += QString::fromStdString(id.substr(0,5));
|
||||||
|
str += "...]";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!doIcons)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QIcon idIcon;
|
||||||
|
CreateIdIcon(id, idIcon);
|
||||||
|
icons.push_back(idIcon);
|
||||||
|
|
||||||
|
// ICON Logic.
|
||||||
|
QIcon baseIcon;
|
||||||
|
if (details.mPgpLinked)
|
||||||
|
{
|
||||||
|
if (details.mPgpKnown)
|
||||||
|
{
|
||||||
|
baseIcon = QIcon(IMAGE_PGPKNOWN);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
baseIcon = QIcon(IMAGE_PGPUNKNOWN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
baseIcon = QIcon(IMAGE_ANON);
|
||||||
|
}
|
||||||
|
|
||||||
|
icons.push_back(baseIcon);
|
||||||
|
// Add In RecognTags Icons.
|
||||||
|
for(it = details.mRecognTags.begin(); it != details.mRecognTags.end(); it++)
|
||||||
|
{
|
||||||
|
QIcon tagIcon;
|
||||||
|
if (findTagIcon(it->tag_class, it->tag_type, tagIcon))
|
||||||
|
{
|
||||||
|
icons.push_back(tagIcon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
icons.push_back(QIcon(IMAGE_ANON));
|
||||||
|
icons.push_back(QIcon(IMAGE_ANON));
|
||||||
|
icons.push_back(QIcon(IMAGE_ANON));
|
||||||
|
|
||||||
|
std::cerr << "GxsIdTreeWidget::MakeIdDesc() ID Ok";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GxsIdDetails::GenerateCombinedIcon(QIcon &outIcon, std::list<QIcon> &icons)
|
||||||
|
{
|
||||||
|
int count = icons.size();
|
||||||
|
QPixmap image(IconSize * count, IconSize);
|
||||||
|
QPainter painter(&image);
|
||||||
|
|
||||||
|
painter.fillRect(0, 0, IconSize * count, IconSize, Qt::transparent);
|
||||||
|
std::list<QIcon>::iterator it;
|
||||||
|
int i = 0;
|
||||||
|
for(it = icons.begin(); it != icons.end(); it++, i++)
|
||||||
|
{
|
||||||
|
it->paint(&painter, IconSize * i, 0, IconSize, IconSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
outIcon = QIcon(image);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
42
retroshare-gui/src/gui/gxs/GxsIdDetails.h
Normal file
42
retroshare-gui/src/gui/gxs/GxsIdDetails.h
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* Retroshare Gxs Support
|
||||||
|
*
|
||||||
|
* Copyright 2012-2013 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2.1 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _GXS_ID_DETAILS_H
|
||||||
|
#define _GXS_ID_DETAILS_H
|
||||||
|
|
||||||
|
#include <QIcon>
|
||||||
|
#include <QString>
|
||||||
|
#include <retroshare/rsidentity.h>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
namespace GxsIdDetails
|
||||||
|
{
|
||||||
|
|
||||||
|
bool MakeIdDesc(const RsGxsId &id, bool doIcons,
|
||||||
|
QString &desc, std::list<QIcon> &icons);
|
||||||
|
|
||||||
|
bool GenerateCombinedIcon(QIcon &outIcon, std::list<QIcon> &icons);
|
||||||
|
|
||||||
|
} // namespace GxsIdDetails.
|
||||||
|
|
||||||
|
#endif
|
|
@ -22,6 +22,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "GxsIdLabel.h"
|
#include "GxsIdLabel.h"
|
||||||
|
#include "GxsIdDetails.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
@ -59,56 +60,6 @@ bool GxsIdLabel::getId(RsGxsId &id)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool MakeIdDesc(const RsGxsId &id, QString &str)
|
|
||||||
{
|
|
||||||
RsIdentityDetails details;
|
|
||||||
|
|
||||||
if (!rsIdentity->getIdDetails(id, details))
|
|
||||||
{
|
|
||||||
str = "Loading... " + QString::fromStdString(id.substr(0,5));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
str = QString::fromUtf8(details.mNickname.c_str());
|
|
||||||
|
|
||||||
std::list<RsRecognTag>::iterator it;
|
|
||||||
for(it = details.mRecognTags.begin(); it != details.mRecognTags.end(); it++)
|
|
||||||
{
|
|
||||||
str += " (";
|
|
||||||
str += QString::number(it->tag_class);
|
|
||||||
str += ":";
|
|
||||||
str += QString::number(it->tag_type);
|
|
||||||
str += ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool addCode = true;
|
|
||||||
if (details.mPgpLinked)
|
|
||||||
{
|
|
||||||
str += " (PGP) [";
|
|
||||||
if (details.mPgpKnown)
|
|
||||||
{
|
|
||||||
/* look up real name */
|
|
||||||
std::string authorName = rsPeers->getPeerName(details.mPgpId);
|
|
||||||
str += QString::fromUtf8(authorName.c_str());
|
|
||||||
str += "]";
|
|
||||||
|
|
||||||
addCode = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
str += " (Anon) [";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (addCode)
|
|
||||||
{
|
|
||||||
str += QString::fromStdString(id.substr(0,5));
|
|
||||||
str += "...]";
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define MAX_ATTEMPTS 3
|
#define MAX_ATTEMPTS 3
|
||||||
|
|
||||||
void GxsIdLabel::loadId()
|
void GxsIdLabel::loadId()
|
||||||
|
@ -117,7 +68,8 @@ void GxsIdLabel::loadId()
|
||||||
|
|
||||||
/* try and get details - if not there ... set callback */
|
/* try and get details - if not there ... set callback */
|
||||||
QString desc;
|
QString desc;
|
||||||
bool loaded = MakeIdDesc(mId, desc);
|
std::list<QIcon> icons;
|
||||||
|
bool loaded = GxsIdDetails::MakeIdDesc(mId, false, desc, icons);
|
||||||
|
|
||||||
setText(desc);
|
setText(desc);
|
||||||
|
|
||||||
|
|
173
retroshare-gui/src/gui/gxs/GxsIdTreeWidget.cpp
Normal file
173
retroshare-gui/src/gui/gxs/GxsIdTreeWidget.cpp
Normal file
|
@ -0,0 +1,173 @@
|
||||||
|
/*
|
||||||
|
* Retroshare Gxs Support
|
||||||
|
*
|
||||||
|
* Copyright 2012-2013 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2.1 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "GxsIdTreeWidget.h"
|
||||||
|
#include "GxsIdDetails.h"
|
||||||
|
|
||||||
|
#include <retroshare/rspeers.h>
|
||||||
|
#include <retroshare/rsidentity.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
static void paintGxsId( QPainter * painter,
|
||||||
|
const QStyleOptionViewItem & option /*, const QRect &rect */, const RsGxsId &id )
|
||||||
|
{
|
||||||
|
QString desc;
|
||||||
|
std::list<QIcon> icons;
|
||||||
|
if (!GxsIdDetails::MakeIdDesc(id, true, desc, icons))
|
||||||
|
{
|
||||||
|
/* flag for reloading */
|
||||||
|
}
|
||||||
|
|
||||||
|
const QRect &rect = option.rect;
|
||||||
|
int x = rect.left();
|
||||||
|
int y = rect.top();
|
||||||
|
int height = rect.height();
|
||||||
|
int width = rect.width();
|
||||||
|
|
||||||
|
|
||||||
|
std::list<QIcon>::iterator it;
|
||||||
|
const int IconSize = 15;
|
||||||
|
int i = 0;
|
||||||
|
for(it = icons.begin(); it != icons.end(); it++, i++)
|
||||||
|
{
|
||||||
|
it->paint(painter, x, y, IconSize, IconSize);
|
||||||
|
x += IconSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define DELTA_X 4
|
||||||
|
QRect textRect = rect.adjusted(DELTA_X + IconSize * i, 0, 0, 0);
|
||||||
|
painter->drawText(textRect, 0, desc, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GxsIdItemDelegate::GxsIdItemDelegate(GxsIdTreeWidget *tree, int col, QObject *parent)
|
||||||
|
:QStyledItemDelegate(parent), mTree(tree), mGxsIdColumn(col)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GxsIdItemDelegate::paint( QPainter * painter,
|
||||||
|
const QStyleOptionViewItem & option, const QModelIndex & index ) const
|
||||||
|
{
|
||||||
|
std::cerr << "GxsIdItemDelegate::paint()";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
RsGxsId id = mTree->ItemTextFromIndex(index, mGxsIdColumn).toStdString();
|
||||||
|
paintGxsId(painter, option, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize GxsIdItemDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
|
||||||
|
{
|
||||||
|
std::cerr << "GxsIdItemDelegate::sizeHint()";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
return QStyledItemDelegate::sizeHint(option, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************/
|
||||||
|
|
||||||
|
GxsIdRSItemDelegate::GxsIdRSItemDelegate(GxsIdRSTreeWidget *tree, int col, QObject *parent)
|
||||||
|
:QStyledItemDelegate(parent), mTree(tree), mGxsIdColumn(col)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GxsIdRSItemDelegate::paint( QPainter * painter,
|
||||||
|
const QStyleOptionViewItem & option, const QModelIndex & index ) const
|
||||||
|
{
|
||||||
|
std::cerr << "GxsIdRSItemDelegate::paint()";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
RsGxsId id = mTree->ItemTextFromIndex(index, mGxsIdColumn).toStdString();
|
||||||
|
paintGxsId(painter, option, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize GxsIdRSItemDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
|
||||||
|
{
|
||||||
|
std::cerr << "GxsIdRSItemDelegate::sizeHint()";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
return QStyledItemDelegate::sizeHint(option, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************/
|
||||||
|
|
||||||
|
GxsIdTreeWidget::GxsIdTreeWidget(QWidget *parent)
|
||||||
|
:QTreeWidget(parent), mIdDelegate(NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GxsIdTreeWidget::setGxsIdColumn(int col)
|
||||||
|
{
|
||||||
|
mIdDelegate = new GxsIdItemDelegate(this, col, this);
|
||||||
|
setItemDelegateForColumn(col, mIdDelegate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString GxsIdTreeWidget::ItemTextFromIndex(const QModelIndex & index, int column ) const
|
||||||
|
{
|
||||||
|
// get real item.
|
||||||
|
QTreeWidgetItem *item = itemFromIndex(index);
|
||||||
|
if (!item)
|
||||||
|
{
|
||||||
|
std::cerr << "GxsIdTreeWidget::ItemTextFromIndex() Invalid Item";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
QString text;
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
return item->text(column);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GxsIdRSTreeWidget::GxsIdRSTreeWidget(QWidget *parent)
|
||||||
|
:RSTreeWidget(parent), mIdDelegate(NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GxsIdRSTreeWidget::setGxsIdColumn(int col)
|
||||||
|
{
|
||||||
|
mIdDelegate = new GxsIdRSItemDelegate(this, col, this);
|
||||||
|
setItemDelegateForColumn(col, mIdDelegate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString GxsIdRSTreeWidget::ItemTextFromIndex(const QModelIndex & index, int column ) const
|
||||||
|
{
|
||||||
|
// get real item.
|
||||||
|
QTreeWidgetItem *item = itemFromIndex(index);
|
||||||
|
if (!item)
|
||||||
|
{
|
||||||
|
std::cerr << "GxsIdTreeWidget::ItemTextFromIndex() Invalid Item";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
QString text;
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
return item->text(column);
|
||||||
|
}
|
||||||
|
|
96
retroshare-gui/src/gui/gxs/GxsIdTreeWidget.h
Normal file
96
retroshare-gui/src/gui/gxs/GxsIdTreeWidget.h
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
/*
|
||||||
|
* Retroshare Gxs Support
|
||||||
|
*
|
||||||
|
* Copyright 2012-2013 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2.1 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _GXS_ID_TREEWIDGET_H
|
||||||
|
#define _GXS_ID_TREEWIDGET_H
|
||||||
|
|
||||||
|
#include <QTreeWidget>
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
|
#include "gui/common/RSTreeWidget.h"
|
||||||
|
|
||||||
|
/*****
|
||||||
|
* To draw multiple fancy Icons, and refresh IDs properly we need
|
||||||
|
* to overload QTreeWidget, and provide a QItemDelegate to draw stuff.
|
||||||
|
*
|
||||||
|
* The ItemDelegate
|
||||||
|
*
|
||||||
|
****/
|
||||||
|
|
||||||
|
class GxsIdTreeWidget;
|
||||||
|
class GxsIdRSTreeWidget;
|
||||||
|
|
||||||
|
class GxsIdItemDelegate : public QStyledItemDelegate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GxsIdItemDelegate(GxsIdTreeWidget *tree, int gxsIdColumn, QObject *parent = 0);
|
||||||
|
virtual void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||||
|
virtual QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
GxsIdTreeWidget *mTree;
|
||||||
|
int mGxsIdColumn;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class GxsIdRSItemDelegate : public QStyledItemDelegate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GxsIdRSItemDelegate(GxsIdRSTreeWidget *tree, int gxsIdColumn, QObject *parent = 0);
|
||||||
|
virtual void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||||
|
virtual QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
GxsIdRSTreeWidget *mTree;
|
||||||
|
int mGxsIdColumn;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class GxsIdTreeWidget : public QTreeWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GxsIdTreeWidget(QWidget *parent = NULL);
|
||||||
|
virtual ~GxsIdTreeWidget() { return; }
|
||||||
|
|
||||||
|
void setGxsIdColumn(int col);
|
||||||
|
QString ItemTextFromIndex(const QModelIndex & index, int column ) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
GxsIdItemDelegate *mIdDelegate;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class GxsIdRSTreeWidget : public RSTreeWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GxsIdRSTreeWidget(QWidget *parent = NULL);
|
||||||
|
virtual ~GxsIdRSTreeWidget() { return; }
|
||||||
|
|
||||||
|
void setGxsIdColumn(int col);
|
||||||
|
QString ItemTextFromIndex(const QModelIndex & index, int column ) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
GxsIdRSItemDelegate *mIdDelegate;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -22,6 +22,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "GxsIdTreeWidgetItem.h"
|
#include "GxsIdTreeWidgetItem.h"
|
||||||
|
#include "GxsIdDetails.h"
|
||||||
|
|
||||||
#include "rshare.h"
|
#include "rshare.h"
|
||||||
|
|
||||||
#include <retroshare/rspeers.h>
|
#include <retroshare/rspeers.h>
|
||||||
|
@ -30,63 +32,6 @@
|
||||||
|
|
||||||
#define MAX_ATTEMPTS 5
|
#define MAX_ATTEMPTS 5
|
||||||
|
|
||||||
static bool MakeIdDesc(const RsGxsId &id, QString &str)
|
|
||||||
{
|
|
||||||
RsIdentityDetails details;
|
|
||||||
|
|
||||||
if (!rsIdentity->getIdDetails(id, details))
|
|
||||||
{
|
|
||||||
std::cerr << "GxsIdRSTreeWidgetItem::MakeIdDesc() FAILED TO GET ID";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
str = "Loading... " + QString::fromStdString(id.substr(0,5));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
str = QString::fromUtf8(details.mNickname.c_str());
|
|
||||||
|
|
||||||
std::list<RsRecognTag>::iterator it;
|
|
||||||
for(it = details.mRecognTags.begin(); it != details.mRecognTags.end(); it++)
|
|
||||||
{
|
|
||||||
str += " (";
|
|
||||||
str += QString::number(it->tag_class);
|
|
||||||
str += ":";
|
|
||||||
str += QString::number(it->tag_type);
|
|
||||||
str += ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool addCode = true;
|
|
||||||
if (details.mPgpLinked)
|
|
||||||
{
|
|
||||||
str += " (PGP) [";
|
|
||||||
if (details.mPgpKnown)
|
|
||||||
{
|
|
||||||
/* look up real name */
|
|
||||||
std::string authorName = rsPeers->getPeerName(details.mPgpId);
|
|
||||||
str += QString::fromUtf8(authorName.c_str());
|
|
||||||
str += "]";
|
|
||||||
|
|
||||||
addCode = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
str += " (Anon) [";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (addCode)
|
|
||||||
{
|
|
||||||
str += QString::fromStdString(id.substr(0,5));
|
|
||||||
str += "...]";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cerr << "GxsIdRSTreeWidgetItem::MakeIdDesc() ID Ok";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Constructor */
|
/** Constructor */
|
||||||
GxsIdRSTreeWidgetItem::GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidget *parent)
|
GxsIdRSTreeWidgetItem::GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidget *parent)
|
||||||
: QObject(NULL), RSTreeWidgetItem(compareRole, parent), mCount(0), mColumn(0)
|
: QObject(NULL), RSTreeWidgetItem(compareRole, parent), mCount(0), mColumn(0)
|
||||||
|
@ -138,7 +83,14 @@ void GxsIdRSTreeWidgetItem::loadId()
|
||||||
|
|
||||||
/* try and get details - if not there ... set callback */
|
/* try and get details - if not there ... set callback */
|
||||||
QString desc;
|
QString desc;
|
||||||
bool loaded = MakeIdDesc(mId, desc);
|
std::list<QIcon> icons;
|
||||||
|
bool loaded = GxsIdDetails::MakeIdDesc(mId, true, desc, icons);
|
||||||
|
QIcon combinedIcon;
|
||||||
|
if (!icons.empty())
|
||||||
|
{
|
||||||
|
GxsIdDetails::GenerateCombinedIcon(combinedIcon, icons);
|
||||||
|
setIcon(mColumn, combinedIcon);
|
||||||
|
}
|
||||||
|
|
||||||
setText(mColumn, desc);
|
setText(mColumn, desc);
|
||||||
|
|
||||||
|
@ -210,8 +162,15 @@ void GxsIdTreeWidgetItem::loadId()
|
||||||
|
|
||||||
/* try and get details - if not there ... set callback */
|
/* try and get details - if not there ... set callback */
|
||||||
QString desc;
|
QString desc;
|
||||||
bool loaded = MakeIdDesc(mId, desc);
|
std::list<QIcon> icons;
|
||||||
|
bool loaded = GxsIdDetails::MakeIdDesc(mId, true, desc, icons);
|
||||||
|
QIcon combinedIcon;
|
||||||
|
if (!icons.empty())
|
||||||
|
{
|
||||||
|
GxsIdDetails::GenerateCombinedIcon(combinedIcon, icons);
|
||||||
|
setIcon(mColumn, combinedIcon);
|
||||||
|
}
|
||||||
|
|
||||||
setText(mColumn, desc);
|
setText(mColumn, desc);
|
||||||
|
|
||||||
if (loaded)
|
if (loaded)
|
||||||
|
|
|
@ -193,6 +193,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const std::string &forumId, QWidget *
|
||||||
// mTimer->start();
|
// mTimer->start();
|
||||||
|
|
||||||
mFillThread = NULL;
|
mFillThread = NULL;
|
||||||
|
ui->threadTreeWidget->setGxsIdColumn(COLUMN_THREAD_AUTHOR);
|
||||||
|
|
||||||
setForumId(forumId);
|
setForumId(forumId);
|
||||||
|
|
||||||
|
@ -803,7 +804,8 @@ QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForum
|
||||||
item->setText(COLUMN_THREAD_DATE, text);
|
item->setText(COLUMN_THREAD_DATE, text);
|
||||||
item->setData(COLUMN_THREAD_DATE, ROLE_THREAD_SORT, sort);
|
item->setData(COLUMN_THREAD_DATE, ROLE_THREAD_SORT, sort);
|
||||||
|
|
||||||
item->setId(msg.mMeta.mAuthorId, COLUMN_THREAD_AUTHOR);
|
item->setText(COLUMN_THREAD_AUTHOR, QString::fromStdString(msg.mMeta.mAuthorId));
|
||||||
|
//item->setId(msg.mMeta.mAuthorId, COLUMN_THREAD_AUTHOR);
|
||||||
//#TODO
|
//#TODO
|
||||||
#if 0
|
#if 0
|
||||||
text = QString::fromUtf8(authorName.c_str());
|
text = QString::fromUtf8(authorName.c_str());
|
||||||
|
|
|
@ -153,7 +153,7 @@
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="RSTreeWidget" name="threadTreeWidget">
|
<widget class="GxsIdRSTreeWidget" name="threadTreeWidget">
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
<pointsize>9</pointsize>
|
<pointsize>9</pointsize>
|
||||||
|
@ -519,9 +519,9 @@
|
||||||
<header location="global">gui/common/LineEditClear.h</header>
|
<header location="global">gui/common/LineEditClear.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>RSTreeWidget</class>
|
<class>GxsIdRSTreeWidget</class>
|
||||||
<extends>QTreeWidget</extends>
|
<extends>QTreeWidget</extends>
|
||||||
<header>gui/common/RSTreeWidget.h</header>
|
<header>gui/gxs/GxsIdTreeWidget.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
|
@ -1175,10 +1175,12 @@ gxsgui {
|
||||||
|
|
||||||
HEADERS += gui/gxs/GxsGroupDialog.h \
|
HEADERS += gui/gxs/GxsGroupDialog.h \
|
||||||
gui/gxs/WikiGroupDialog.h \
|
gui/gxs/WikiGroupDialog.h \
|
||||||
|
gui/gxs/GxsIdDetails.h \
|
||||||
gui/gxs/GxsIdChooser.h \
|
gui/gxs/GxsIdChooser.h \
|
||||||
gui/gxs/GxsIdLabel.h \
|
gui/gxs/GxsIdLabel.h \
|
||||||
gui/gxs/GxsCircleChooser.h \
|
gui/gxs/GxsCircleChooser.h \
|
||||||
gui/gxs/GxsCircleLabel.h \
|
gui/gxs/GxsCircleLabel.h \
|
||||||
|
gui/gxs/GxsIdTreeWidget.h \
|
||||||
gui/gxs/GxsIdTreeWidgetItem.h \
|
gui/gxs/GxsIdTreeWidgetItem.h \
|
||||||
gui/gxs/GxsCommentTreeWidget.h \
|
gui/gxs/GxsCommentTreeWidget.h \
|
||||||
gui/gxs/GxsCommentContainer.h \
|
gui/gxs/GxsCommentContainer.h \
|
||||||
|
@ -1203,10 +1205,12 @@ gxsgui {
|
||||||
|
|
||||||
SOURCES += gui/gxs/GxsGroupDialog.cpp \
|
SOURCES += gui/gxs/GxsGroupDialog.cpp \
|
||||||
gui/gxs/WikiGroupDialog.cpp \
|
gui/gxs/WikiGroupDialog.cpp \
|
||||||
|
gui/gxs/GxsIdDetails.cpp \
|
||||||
gui/gxs/GxsIdChooser.cpp \
|
gui/gxs/GxsIdChooser.cpp \
|
||||||
gui/gxs/GxsIdLabel.cpp \
|
gui/gxs/GxsIdLabel.cpp \
|
||||||
gui/gxs/GxsCircleChooser.cpp \
|
gui/gxs/GxsCircleChooser.cpp \
|
||||||
gui/gxs/GxsCircleLabel.cpp \
|
gui/gxs/GxsCircleLabel.cpp \
|
||||||
|
gui/gxs/GxsIdTreeWidget.cpp \
|
||||||
gui/gxs/GxsIdTreeWidgetItem.cpp \
|
gui/gxs/GxsIdTreeWidgetItem.cpp \
|
||||||
gui/gxs/GxsCommentTreeWidget.cpp \
|
gui/gxs/GxsCommentTreeWidget.cpp \
|
||||||
gui/gxs/GxsCommentContainer.cpp \
|
gui/gxs/GxsCommentContainer.cpp \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue