improved naming, icons and tooltip for GxsIds

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7532 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-09-13 14:07:59 +00:00
parent ab1b930852
commit e2a8ed46f2
9 changed files with 108 additions and 107 deletions

View File

@ -6,6 +6,7 @@
#include <QGraphicsItem>
#include <QGraphicsSceneMouseEvent>
#include "gui/gxs/GxsIdDetails.h"
#include "IdentityItem.h"
#include "CircleItem.h"
@ -90,7 +91,7 @@ void CircleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
uint32_t i=0 ;
for(std::set<RsGxsId>::const_iterator it(_circle_details.mUnknownPeers.begin());it!= _circle_details.mUnknownPeers.end();++it)
{
painter->drawImage(QPoint(CRC_SIZE*cos(_angles[i]) -(int)IMG_SIZE/2, CRC_SIZE*sin(_angles[i]) -(int)IMG_SIZE/2), IdentityItem::makeDefaultIcon(RsGxsGroupId(*it))) ;
painter->drawImage(QPoint(CRC_SIZE*cos(_angles[i]) -(int)IMG_SIZE/2, CRC_SIZE*sin(_angles[i]) -(int)IMG_SIZE/2), GxsIdDetails::makeDefaultIcon(*it)) ;
++i ;
}

View File

@ -10,6 +10,7 @@
#include <QGraphicsSceneMouseEvent>
#include <gui/chat/ChatDialog.h>
#include <gui/gxs/GxsIdDetails.h>
#include "IdentityItem.h"
#define IMAGE_MAKEFRIEND ""
@ -61,70 +62,6 @@ QRectF IdentityItem::boundingRect() const
return QRectF(-(int)IMG_SIZE/2-10, -(int)IMG_SIZE/2-10, (int)IMG_SIZE+20,(int)IMG_SIZE+35) ;
}
QImage IdentityItem::makeDefaultIcon(const RsGxsGroupId& id)
{
int S = 128 ;
QImage pix(S,S,QImage::Format_RGB32) ;
uint64_t n = reinterpret_cast<const uint64_t*>(id.toByteArray())[0] ;
uint8_t a[8] ;
for(int i=0;i<8;++i)
{
a[i] = n&0xff ;
n >>= 8 ;
}
QColor val[16] = {
QColor::fromRgb( 255, 110, 180),
QColor::fromRgb( 238, 92, 66),
QColor::fromRgb( 255, 127, 36),
QColor::fromRgb( 255, 193, 193),
QColor::fromRgb( 127, 255, 212),
QColor::fromRgb( 0, 255, 255),
QColor::fromRgb( 224, 255, 255),
QColor::fromRgb( 199, 21, 133),
QColor::fromRgb( 50, 205, 50),
QColor::fromRgb( 107, 142, 35),
QColor::fromRgb( 30, 144, 255),
QColor::fromRgb( 95, 158, 160),
QColor::fromRgb( 143, 188, 143),
QColor::fromRgb( 233, 150, 122),
QColor::fromRgb( 151, 255, 255),
QColor::fromRgb( 162, 205, 90),
};
int c1 = (a[0]^a[1]) & 0xf ;
int c2 = (a[1]^a[2]) & 0xf ;
int c3 = (a[2]^a[3]) & 0xf ;
int c4 = (a[3]^a[4]) & 0xf ;
for(int i=0;i<S/2;++i)
for(int j=0;j<S/2;++j)
{
float res1 = 0.0f ;
float res2 = 0.0f ;
float f = 1.70;
for(int k1=0;k1<4;++k1)
for(int k2=0;k2<4;++k2)
{
res1 += cos( (2*M_PI*i/(float)S) * k1 * f) * (a[k1 ] & 0xf) + sin( (2*M_PI*j/(float)S) * k2 * f) * (a[k2 ] >> 4) + sin( (2*M_PI*i/(float)S) * k1 * f) * cos( (2*M_PI*j/(float)S) * k2 * f) * (a[k1+k2] >> 4) ;
res2 += cos( (2*M_PI*i/(float)S) * k2 * f) * (a[k1+2] & 0xf) + sin( (2*M_PI*j/(float)S) * k1 * f) * (a[k2+1] >> 4) + sin( (2*M_PI*i/(float)S) * k2 * f) * cos( (2*M_PI*j/(float)S) * k1 * f) * (a[k1^k2] >> 4) ;
}
uint32_t q = 0 ;
if(res1 >= 0.0f) q += val[c1].rgb() ; else q += val[c2].rgb() ;
if(res2 >= 0.0f) q += val[c3].rgb() ; else q += val[c4].rgb() ;
pix.setPixel( i, j, q) ;
pix.setPixel( S-1-i, j, q) ;
pix.setPixel( S-1-i, S-1-j, q) ;
pix.setPixel( i, S-1-j, q) ;
}
return pix.scaled(IMG_SIZE,IMG_SIZE,Qt::KeepAspectRatio,Qt::SmoothTransformation) ;
}
void IdentityItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
{
static QColor type_color[4] = { QColor(Qt::yellow), QColor(Qt::green), QColor(Qt::cyan), QColor(Qt::black) } ;
@ -146,7 +83,7 @@ void IdentityItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
painter->setPen(QPen(Qt::black, 0));
painter->drawRoundedRect(QRectF(-(int)IMG_SIZE/2-10, -(int)IMG_SIZE/2-10, 20+IMG_SIZE, 20+IMG_SIZE),20,15) ;
painter->drawImage(QPoint(-(int)IMG_SIZE/2, -(int)IMG_SIZE/2), makeDefaultIcon(_group_info.mMeta.mGroupId)) ;
painter->drawImage(QPoint(-(int)IMG_SIZE/2, -(int)IMG_SIZE/2), GxsIdDetails::makeDefaultIcon(RsGxsId(_group_info.mMeta.mGroupId))) ;
std::string desc_string = _group_info.mMeta.mGroupName ;

View File

@ -16,8 +16,6 @@ class IdentityItem: public QObject, public QGraphicsItem
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) ;
static QImage makeDefaultIcon(const RsGxsGroupId& id) ;
static const int IMG_SIZE = 64;
static IdentityItem *_selected_node ;

View File

@ -118,7 +118,8 @@ void GxsIdChooser::loadIds(uint32_t chooserFlags, RsGxsId defId)
bool GxsIdChooser::makeIdDesc(const RsGxsId &gxsId, QString &desc)
{
std::list<QIcon> icons;
if (!GxsIdDetails::MakeIdDesc(gxsId, false, desc, icons)) {
QString comment ;
if (!GxsIdDetails::MakeIdDesc(gxsId, false, desc, icons,comment)) {
if (mTimerCount > MAX_TRY) {
desc = QString("%1 ... [").arg(tr("Not found"));
desc += QString::fromStdString(gxsId.toStdString().substr(0,5));

View File

@ -21,12 +21,14 @@
*
*/
#include <math.h>
#include "GxsIdDetails.h"
#include <retroshare/rspeers.h>
#include <iostream>
#include <QPainter>
#include <QIcon>
#include <QObject>
@ -68,6 +70,69 @@ static bool findTagIcon(int tag_class, int tag_type, QIcon &icon)
return true;
}
QImage GxsIdDetails::makeDefaultIcon(const RsGxsId& id)
{
int S = 128 ;
QImage pix(S,S,QImage::Format_RGB32) ;
uint64_t n = reinterpret_cast<const uint64_t*>(id.toByteArray())[0] ;
uint8_t a[8] ;
for(int i=0;i<8;++i)
{
a[i] = n&0xff ;
n >>= 8 ;
}
QColor val[16] = {
QColor::fromRgb( 255, 110, 180),
QColor::fromRgb( 238, 92, 66),
QColor::fromRgb( 255, 127, 36),
QColor::fromRgb( 255, 193, 193),
QColor::fromRgb( 127, 255, 212),
QColor::fromRgb( 0, 255, 255),
QColor::fromRgb( 224, 255, 255),
QColor::fromRgb( 199, 21, 133),
QColor::fromRgb( 50, 205, 50),
QColor::fromRgb( 107, 142, 35),
QColor::fromRgb( 30, 144, 255),
QColor::fromRgb( 95, 158, 160),
QColor::fromRgb( 143, 188, 143),
QColor::fromRgb( 233, 150, 122),
QColor::fromRgb( 151, 255, 255),
QColor::fromRgb( 162, 205, 90),
};
int c1 = (a[0]^a[1]) & 0xf ;
int c2 = (a[1]^a[2]) & 0xf ;
int c3 = (a[2]^a[3]) & 0xf ;
int c4 = (a[3]^a[4]) & 0xf ;
for(int i=0;i<S/2;++i)
for(int j=0;j<S/2;++j)
{
float res1 = 0.0f ;
float res2 = 0.0f ;
float f = 1.70;
for(int k1=0;k1<4;++k1)
for(int k2=0;k2<4;++k2)
{
res1 += cos( (2*M_PI*i/(float)S) * k1 * f) * (a[k1 ] & 0xf) + sin( (2*M_PI*j/(float)S) * k2 * f) * (a[k2 ] >> 4) + sin( (2*M_PI*i/(float)S) * k1 * f) * cos( (2*M_PI*j/(float)S) * k2 * f) * (a[k1+k2] >> 4) ;
res2 += cos( (2*M_PI*i/(float)S) * k2 * f) * (a[k1+2] & 0xf) + sin( (2*M_PI*j/(float)S) * k1 * f) * (a[k2+1] >> 4) + sin( (2*M_PI*i/(float)S) * k2 * f) * cos( (2*M_PI*j/(float)S) * k1 * f) * (a[k1^k2] >> 4) ;
}
uint32_t q = 0 ;
if(res1 >= 0.0f) q += val[c1].rgb() ; else q += val[c2].rgb() ;
if(res2 >= 0.0f) q += val[c3].rgb() ; else q += val[c4].rgb() ;
pix.setPixel( i, j, q) ;
pix.setPixel( S-1-i, j, q) ;
pix.setPixel( S-1-i, S-1-j, q) ;
pix.setPixel( i, S-1-j, q) ;
}
return pix.scaled(64,64,Qt::KeepAspectRatio,Qt::SmoothTransformation) ;
}
static bool CreateIdIcon(const RsGxsId &id, QIcon &idIcon)
{
@ -88,8 +153,7 @@ static bool CreateIdIcon(const RsGxsId &id, QIcon &idIcon)
return true;
}
bool GxsIdDetails::MakeIdDesc(const RsGxsId &id, bool doIcons, QString &str, std::list<QIcon> &icons)
bool GxsIdDetails::MakeIdDesc(const RsGxsId &id, bool doIcons, QString &str, std::list<QIcon> &icons,QString& comment)
{
RsIdentityDetails details;
@ -121,39 +185,34 @@ bool GxsIdDetails::MakeIdDesc(const RsGxsId &id, bool doIcons, QString &str, std
str += ")";
}
comment += "Identity name: " + QString::fromUtf8(details.mNickname.c_str()) + "\n";
comment += "Identity Id : " + QString::fromStdString(id.toStdString()) + "\n";
bool addCode = true;
if (details.mPgpLinked)
{
str += " (PGP) [";
comment += "Authentication: signed by " ;
if (details.mPgpKnown)
{
/* look up real name */
std::string authorName = rsPeers->getGPGName(details.mPgpId);
str += QString::fromUtf8(authorName.c_str());
str += "]";
addCode = false;
comment += QString::fromUtf8(authorName.c_str());
}
comment += " [";
comment += QString::fromStdString(details.mPgpId.toStdString()) ;
comment += "]";
}
else
{
str += " (Anon) [";
}
if (addCode)
{
str += QString::fromStdString(id.toStdString().substr(0,5));
str += "...]";
}
comment += "Authentication: anonymous" ;
if (!doIcons)
{
return true;
}
QIcon idIcon;
CreateIdIcon(id, idIcon);
QPixmap pix ;
pix.convertFromImage( makeDefaultIcon(id) );
QIcon idIcon( pix ) ;
//CreateIdIcon(id, idIcon);
icons.push_back(idIcon);
// ICON Logic.
@ -161,18 +220,12 @@ bool GxsIdDetails::MakeIdDesc(const RsGxsId &id, bool doIcons, QString &str, std
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.
@ -185,11 +238,13 @@ bool GxsIdDetails::MakeIdDesc(const RsGxsId &id, bool doIcons, QString &str, std
}
}
icons.push_back(QIcon(IMAGE_ANON));
icons.push_back(QIcon(IMAGE_ANON));
icons.push_back(QIcon(IMAGE_ANON));
// Cyril: I disabled these three which I believe to have been put for testing purposes.
//
// 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 << "GxsIdTreeWidget::MakeIdDesc() ID Ok. Comment: " << comment.toStdString() ;
std::cerr << std::endl;
return true;

View File

@ -33,10 +33,12 @@ namespace GxsIdDetails
{
bool MakeIdDesc(const RsGxsId &id, bool doIcons,
QString &desc, std::list<QIcon> &icons);
QString &desc, std::list<QIcon> &icons,QString& comment);
bool GenerateCombinedIcon(QIcon &outIcon, std::list<QIcon> &icons);
QImage makeDefaultIcon(const RsGxsId& id);
} // namespace GxsIdDetails.
#endif

View File

@ -68,10 +68,12 @@ void GxsIdLabel::loadId()
/* try and get details - if not there ... set callback */
QString desc;
QString comment ;
std::list<QIcon> icons;
bool loaded = GxsIdDetails::MakeIdDesc(mId, false, desc, icons);
bool loaded = GxsIdDetails::MakeIdDesc(mId, false, desc, icons,comment);
setText(desc);
setToolTip(comment);
if (loaded)
{

View File

@ -35,8 +35,9 @@ static void paintGxsId( QPainter * painter,
const QStyleOptionViewItem & option /*, const QRect &rect */, const RsGxsId &id )
{
QString desc;
QString comment;
std::list<QIcon> icons;
if (!GxsIdDetails::MakeIdDesc(id, true, desc, icons))
if (!GxsIdDetails::MakeIdDesc(id, true, desc, icons,comment))
{
/* flag for reloading */
}

View File

@ -82,15 +82,17 @@ void GxsIdRSTreeWidgetItem::loadId()
mCount++;
/* try and get details - if not there ... set callback */
QString desc;
QString desc;
QString comment ;
std::list<QIcon> icons;
bool loaded = GxsIdDetails::MakeIdDesc(mId, true, desc, icons);
bool loaded = GxsIdDetails::MakeIdDesc(mId, true, desc, icons,comment);
QIcon combinedIcon;
if (!icons.empty())
{
GxsIdDetails::GenerateCombinedIcon(combinedIcon, icons);
setIcon(mColumn, combinedIcon);
}
}
setToolTip(mColumn,comment) ;
setText(mColumn, desc);
@ -162,8 +164,9 @@ void GxsIdTreeWidgetItem::loadId()
/* try and get details - if not there ... set callback */
QString desc;
QString comment;
std::list<QIcon> icons;
bool loaded = GxsIdDetails::MakeIdDesc(mId, true, desc, icons);
bool loaded = GxsIdDetails::MakeIdDesc(mId, true, desc, icons,comment);
QIcon combinedIcon;
if (!icons.empty())
{
@ -172,6 +175,7 @@ void GxsIdTreeWidgetItem::loadId()
}
setText(mColumn, desc);
setToolTip(mColumn, comment);
if (loaded)
{