mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-17 13:24:15 -05:00
added item for circles. Does not show up yet because of a grou retrieval problem
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7332 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
d7b7e4d976
commit
0290143da3
144
retroshare-gui/src/gui/People/CircleItem.cpp
Normal file
144
retroshare-gui/src/gui/People/CircleItem.cpp
Normal file
@ -0,0 +1,144 @@
|
||||
#include <math.h>
|
||||
|
||||
#include <QPainter>
|
||||
#include <QMenu>
|
||||
#include <QStyle>
|
||||
#include <QGraphicsItem>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
|
||||
#include "CircleItem.h"
|
||||
|
||||
#define IMAGE_MAKEFRIEND ""
|
||||
|
||||
CircleItem *CircleItem::_selected_node = NULL ;
|
||||
|
||||
CircleItem::CircleItem(const RsGroupMetaData& group_info)
|
||||
: _group_info(group_info)
|
||||
{
|
||||
std::cerr << "Created group item for id=" <<group_info.mGroupId << std::endl;
|
||||
|
||||
// setFlag(ItemIsMovable);
|
||||
setAcceptHoverEvents(true) ;
|
||||
#if QT_VERSION >= 0x040600
|
||||
setFlag(ItemSendsGeometryChanges);
|
||||
#endif
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
_selected = false ;
|
||||
|
||||
mDeterminedBB = false ;
|
||||
mBBWidth = 40 ;
|
||||
}
|
||||
|
||||
void CircleItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e)
|
||||
{
|
||||
std::cerr << "Object was entered!" << std::endl;
|
||||
_selected = true ;
|
||||
_selected_node = this ;
|
||||
|
||||
emit itemChanged() ;
|
||||
update() ;
|
||||
}
|
||||
void CircleItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *e)
|
||||
{
|
||||
std::cerr << "Object was left!" << std::endl;
|
||||
_selected = false ;
|
||||
_selected_node = NULL ;
|
||||
|
||||
emit itemChanged() ;
|
||||
update() ;
|
||||
}
|
||||
|
||||
|
||||
QRectF CircleItem::boundingRect() const
|
||||
{
|
||||
static const bool mDeterminedBB = false ;
|
||||
static const int mBBWidth = 40 ;
|
||||
|
||||
return QRectF(-(int)IMG_SIZE/2-10, -(int)IMG_SIZE/2-10, (int)IMG_SIZE+20,(int)IMG_SIZE+35) ;
|
||||
}
|
||||
|
||||
void CircleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
|
||||
{
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(Qt::lightGray);
|
||||
painter->drawEllipse(-7, -7, 20, 20);
|
||||
|
||||
QRadialGradient gradient(-10, -IMG_SIZE/3.0, IMG_SIZE*1.5);
|
||||
gradient.setColorAt(0.0f,Qt::lightGray) ;
|
||||
gradient.setColorAt(1.0f,Qt::darkGray) ;
|
||||
painter->setBrush(gradient);
|
||||
|
||||
if(_selected)
|
||||
painter->setOpacity(0.7) ;
|
||||
else
|
||||
painter->setOpacity(1.0) ;
|
||||
|
||||
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->drawRect(-(int)IMG_SIZE/2, -(int)IMG_SIZE/2, IMG_SIZE, IMG_SIZE);
|
||||
//std::string desc_string = _group_info.mMeta.mGroupId.toStdString() ;
|
||||
|
||||
std::string desc_string = _group_info.mGroupName ;
|
||||
|
||||
painter->drawText(-8*desc_string.size()/2, IMG_SIZE/2+24, QString::fromUtf8(desc_string.c_str()));
|
||||
|
||||
if (!mDeterminedBB)
|
||||
{
|
||||
QRect textBox = painter->boundingRect(-10, 0, 400, 20, 0, QString::fromUtf8(desc_string.c_str()));
|
||||
mBBWidth = textBox.width();
|
||||
mDeterminedBB = true;
|
||||
}
|
||||
}
|
||||
|
||||
QVariant CircleItem::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
// switch (change) {
|
||||
// case ItemPositionHasChanged:
|
||||
// foreach (Edge *edge, edgeList)
|
||||
// edge->adjust();
|
||||
// graph->itemMoved();
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// };
|
||||
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
void CircleItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if(event->button() == Qt::LeftButton)
|
||||
{
|
||||
//_selected_node = this ;
|
||||
//graph->forceRedraw() ;
|
||||
}
|
||||
|
||||
update();
|
||||
QGraphicsItem::mousePressEvent(event);
|
||||
}
|
||||
void CircleItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
||||
{
|
||||
QMenu contextMnu ;
|
||||
|
||||
//if(_type == GraphWidget::ELASTIC_NODE_TYPE_FRIEND)
|
||||
// contextMnu.addAction(QIcon(IMAGE_DENIED), QObject::tr( "Deny friend" ), this, SLOT(denyFriend()) );
|
||||
//else if(_type != GraphWidget::ELASTIC_NODE_TYPE_OWN)
|
||||
// contextMnu.addAction(QIcon(IMAGE_MAKEFRIEND), QObject::tr( "Make friend" ), this, SLOT(makeFriend()) );
|
||||
|
||||
contextMnu.addAction(QIcon(IMAGE_MAKEFRIEND), QObject::tr( "Group details" ), this, SLOT(peerDetails()) );
|
||||
|
||||
contextMnu.exec(event->screenPos());
|
||||
}
|
||||
|
||||
void CircleItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
//_selected_node = NULL ;
|
||||
//graph->forceRedraw() ;
|
||||
|
||||
update();
|
||||
QGraphicsItem::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
|
43
retroshare-gui/src/gui/People/CircleItem.h
Normal file
43
retroshare-gui/src/gui/People/CircleItem.h
Normal file
@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <QGraphicsItem>
|
||||
|
||||
#include <retroshare/rsidentity.h>
|
||||
|
||||
class CircleItem: public QObject, public QGraphicsItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CircleItem(const RsGroupMetaData& gxs_group_info) ;
|
||||
|
||||
QRectF boundingRect() const ;
|
||||
//QPainterPath shape() const ;
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) ;
|
||||
|
||||
//static QImage makeDefaultIcon(const RsGxsGroupId& id) ;
|
||||
|
||||
static const int IMG_SIZE = 64;
|
||||
static CircleItem *_selected_node ;
|
||||
|
||||
const RsGroupMetaData& groupInfo() const { return _group_info ; }
|
||||
signals:
|
||||
void itemChanged() ;
|
||||
|
||||
private:
|
||||
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *e);
|
||||
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *e);
|
||||
virtual QVariant itemChange(GraphicsItemChange change,const QVariant& value) ;
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *) ;
|
||||
|
||||
RsGroupMetaData _group_info ;
|
||||
|
||||
bool mDeterminedBB;
|
||||
bool mBBWidth;
|
||||
bool _selected ;
|
||||
};
|
||||
|
@ -6,16 +6,18 @@
|
||||
#include "gui/common/UIStateHelper.h"
|
||||
#include <retroshare/rsidentity.h>
|
||||
#include <retroshare/rspeers.h>
|
||||
#include <retroshare/rsgxscircles.h>
|
||||
|
||||
#include "GroupListView.h"
|
||||
#include "IdentityItem.h"
|
||||
#include "CircleItem.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
const uint32_t GroupListView::GLVIEW_IDLIST = 0x0001 ;
|
||||
const uint32_t GroupListView::GLVIEW_IDDETAILS = 0x0002 ;
|
||||
const uint32_t GroupListView::GLVIEW_REFRESH = 0x0003 ;
|
||||
const uint32_t GroupListView::GLVIEW_REPLIST = 0x0004 ;
|
||||
const uint32_t GroupListView::GLVIEW_CIRCLES = 0x0004 ;
|
||||
|
||||
GroupListView::GroupListView(QWidget *)
|
||||
: timerId(0), mIsFrozen(false)
|
||||
@ -69,6 +71,7 @@ void GroupListView::keyPressEvent(QKeyEvent *event)
|
||||
break;
|
||||
case Qt::Key_Space:
|
||||
case Qt::Key_Enter:requestIdList() ;
|
||||
requestCirclesList() ;
|
||||
break;
|
||||
default:
|
||||
QGraphicsView::keyPressEvent(event);
|
||||
@ -124,13 +127,15 @@ void GroupListView::insertIdList(uint32_t token)
|
||||
std::cerr << std::endl;
|
||||
|
||||
mStateHelper->setLoading(GLVIEW_IDDETAILS, false);
|
||||
mStateHelper->setLoading(GLVIEW_REPLIST, false);
|
||||
mStateHelper->setLoading(GLVIEW_CIRCLES, false);
|
||||
|
||||
mStateHelper->setActive(GLVIEW_IDLIST, false);
|
||||
mStateHelper->setActive(GLVIEW_IDDETAILS, false);
|
||||
mStateHelper->setActive(GLVIEW_REPLIST, false);
|
||||
mStateHelper->setActive(GLVIEW_CIRCLES, false);
|
||||
|
||||
mStateHelper->clear(GLVIEW_IDLIST);
|
||||
mStateHelper->clear(GLVIEW_IDDETAILS);
|
||||
mStateHelper->clear(GLVIEW_REPLIST);
|
||||
mStateHelper->clear(GLVIEW_CIRCLES);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -145,7 +150,7 @@ void GroupListView::insertIdList(uint32_t token)
|
||||
for (vit = datavector.begin(); vit != datavector.end(); ++vit)
|
||||
if(_identity_items.find((*vit).mMeta.mGroupId) == _identity_items.end())
|
||||
{
|
||||
std::cerr << "Loading data vector identity ID = " << (*vit).mMeta.mGroupId << std::endl;
|
||||
std::cerr << "Loading data vector identity ID = " << (*vit).mMeta.mGroupId << ", i="<< i << std::endl;
|
||||
|
||||
IdentityItem *new_item = new IdentityItem(*vit) ;
|
||||
_identity_items[(*vit).mMeta.mGroupId] = new_item ;
|
||||
@ -165,6 +170,70 @@ void GroupListView::insertIdList(uint32_t token)
|
||||
// fix up buttons.
|
||||
// updateSelection();
|
||||
}
|
||||
void GroupListView::insertCircles(uint32_t token)
|
||||
{
|
||||
mStateHelper->setLoading(GLVIEW_CIRCLES, false);
|
||||
|
||||
std::cerr << "CirclesDialog::loadGroupMeta()" << std::endl;
|
||||
|
||||
std::list<RsGroupMetaData> groupInfo;
|
||||
std::list<RsGroupMetaData>::iterator vit;
|
||||
|
||||
if (!rsGxsCircles->getGroupSummary(token,groupInfo))
|
||||
{
|
||||
std::cerr << "CirclesDialog::loadGroupMeta() Error getting GroupMeta";
|
||||
std::cerr << std::endl;
|
||||
mStateHelper->setActive(GLVIEW_CIRCLES, false);
|
||||
return;
|
||||
}
|
||||
|
||||
mStateHelper->setActive(GLVIEW_CIRCLES, true);
|
||||
|
||||
/* add the top level item */
|
||||
int i=0;
|
||||
|
||||
for(vit = groupInfo.begin(); vit != groupInfo.end(); vit++)
|
||||
{
|
||||
/* Add Widget, and request Pages */
|
||||
std::cerr << "CirclesDialog::loadGroupMeta() GroupId: " << vit->mGroupId;
|
||||
std::cerr << " Group: " << vit->mGroupName;
|
||||
std::cerr << std::endl;
|
||||
|
||||
CircleItem *gitem = new CircleItem( *vit ) ;
|
||||
|
||||
_circles_items[(*vit).mGroupId] = gitem ;
|
||||
|
||||
gitem->setPos(150+IdentityItem::IMG_SIZE/2,(40+IdentityItem::IMG_SIZE)*(i+0.5)) ;
|
||||
|
||||
QObject::connect(gitem,SIGNAL(itemChanged()),this,SLOT(forceRedraw())) ;
|
||||
|
||||
scene()->addItem(gitem) ;
|
||||
++i ;
|
||||
|
||||
//groupItem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, QString::fromUtf8(vit->mGroupName.c_str()));
|
||||
//groupItem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPID, QString::fromStdString(vit->mGroupId.toStdString()));
|
||||
|
||||
//if (vit->mCircleType == GXS_CIRCLE_TYPE_LOCAL)
|
||||
//{
|
||||
// personalCirclesItem->addChild(groupItem);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// if (vit->mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN)
|
||||
// {
|
||||
// externalAdminCirclesItem->addChild(groupItem);
|
||||
// }
|
||||
// else if (vit->mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED)
|
||||
// {
|
||||
// externalSubCirclesItem->addChild(groupItem);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// externalOtherCirclesItem->addChild(groupItem);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
void GroupListView::requestIdList()
|
||||
{
|
||||
@ -186,7 +255,25 @@ void GroupListView::requestIdList()
|
||||
|
||||
mIdQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, GLVIEW_IDLIST);
|
||||
}
|
||||
void GroupListView::requestCirclesList()
|
||||
{
|
||||
std::cerr << "Requesting Circles list..." << std::endl;
|
||||
|
||||
if (!mIdQueue)
|
||||
return;
|
||||
|
||||
mStateHelper->setLoading(GLVIEW_CIRCLES, true);
|
||||
//mStateHelper->setLoading(GLVIEW_IDDETAILS, true);
|
||||
//mStateHelper->setLoading(GLVIEW_REPLIST, true);
|
||||
|
||||
mIdQueue->cancelActiveRequestTokens(GLVIEW_CIRCLES);
|
||||
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
|
||||
|
||||
uint32_t token;
|
||||
mIdQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, GLVIEW_CIRCLES);
|
||||
}
|
||||
void GroupListView::forceRedraw()
|
||||
{
|
||||
std::cerr << "force redraw" << std::endl;
|
||||
@ -214,8 +301,8 @@ void GroupListView::loadRequest(const TokenQueue * /*queue*/, const TokenRequest
|
||||
//insertIdDetails(req.mToken);
|
||||
break;
|
||||
|
||||
case GLVIEW_REPLIST:
|
||||
//insertRepList(req.mToken);
|
||||
case GLVIEW_CIRCLES:
|
||||
insertCircles(req.mToken);
|
||||
break;
|
||||
|
||||
case GLVIEW_REFRESH:
|
||||
@ -286,9 +373,9 @@ void GroupListView::drawBackground(QPainter *painter, const QRectF &rect)
|
||||
+QString::fromStdString(group_info.mPgpId.toStdString())
|
||||
+")"):tr("Anonymous") ;
|
||||
|
||||
painter->drawText(sceneRect.translated(IdentityItem::IMG_SIZE*2.5,line_height*n++), QString("Name\t: ")+QString::fromStdString(group_info.mMeta.mGroupName ));
|
||||
painter->drawText(sceneRect.translated(IdentityItem::IMG_SIZE*2.5,line_height*n++), QString("Id \t: ")+QString::fromStdString(group_info.mMeta.mGroupId.toStdString() ));
|
||||
painter->drawText(sceneRect.translated(IdentityItem::IMG_SIZE*2.5,line_height*n++), QString("Type\t: ")+typestring );
|
||||
painter->drawText(sceneRect.translated(IdentityItem::IMG_SIZE*2.5,line_height*n++), QString("Name : ")+QString::fromStdString(group_info.mMeta.mGroupName ));
|
||||
painter->drawText(sceneRect.translated(IdentityItem::IMG_SIZE*2.5+31,line_height*n++), QString("Id : ")+QString::fromStdString(group_info.mMeta.mGroupId.toStdString() ));
|
||||
painter->drawText(sceneRect.translated(IdentityItem::IMG_SIZE*2.5+10,line_height*n++), QString("Type : ")+typestring );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
class UIStateHelper;
|
||||
class IdentityItem ;
|
||||
class CircleItem ;
|
||||
|
||||
class GroupListView : public QGraphicsView, public TokenResponse
|
||||
{
|
||||
@ -19,7 +20,7 @@ class GroupListView : public QGraphicsView, public TokenResponse
|
||||
public:
|
||||
static const uint32_t GLVIEW_IDLIST ;
|
||||
static const uint32_t GLVIEW_IDDETAILS ;
|
||||
static const uint32_t GLVIEW_REPLIST ;
|
||||
static const uint32_t GLVIEW_CIRCLES ;
|
||||
static const uint32_t GLVIEW_REFRESH ;
|
||||
|
||||
GroupListView(QWidget * = NULL);
|
||||
@ -35,8 +36,12 @@ public:
|
||||
uint32_t edgeLength() const { return _edge_length ; }
|
||||
|
||||
void loadRequest(const TokenQueue * /*queue*/, const TokenRequest &req) ;
|
||||
|
||||
void requestIdList() ;
|
||||
void requestCirclesList() ;
|
||||
|
||||
void insertIdList(uint32_t token) ;
|
||||
void insertCircles(uint32_t token) ;
|
||||
|
||||
protected slots:
|
||||
void forceRedraw() ;
|
||||
@ -70,5 +75,6 @@ private:
|
||||
UIStateHelper *mStateHelper;
|
||||
|
||||
std::map<RsGxsGroupId,IdentityItem *> _identity_items ;
|
||||
std::map<RsGxsGroupId,CircleItem *> _circles_items ;
|
||||
};
|
||||
|
||||
|
@ -163,6 +163,7 @@ void PeopleDialog::updateDisplay(bool /*complete*/)
|
||||
{
|
||||
/* Update identity list */
|
||||
circles_view->requestIdList();
|
||||
circles_view->requestCirclesList();
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -1075,11 +1075,13 @@ thewire {
|
||||
|
||||
HEADERS += gui/People/PeopleDialog.h
|
||||
HEADERS += gui/People/IdentityItem.h
|
||||
HEADERS += gui/People/CircleItem.h
|
||||
HEADERS += gui/People/GroupListView.h
|
||||
FORMS += gui/People/PeopleDialog.ui
|
||||
SOURCES += gui/People/PeopleDialog.cpp
|
||||
SOURCES += gui/People/GroupListView.cpp
|
||||
SOURCES += gui/People/IdentityItem.cpp
|
||||
SOURCES += gui/People/CircleItem.cpp
|
||||
|
||||
identities {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user