mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-17 13:24:15 -05:00
cleaned the network graph a little bit. Removed text, updated bounding boxes, removed background
This commit is contained in:
parent
b3625448e9
commit
c428739abd
@ -43,7 +43,7 @@ NetworkView::NetworkView(QWidget *parent)
|
|||||||
|
|
||||||
mScene = new QGraphicsScene();
|
mScene = new QGraphicsScene();
|
||||||
mScene->setItemIndexMethod(QGraphicsScene::NoIndex);
|
mScene->setItemIndexMethod(QGraphicsScene::NoIndex);
|
||||||
mScene->setSceneRect(-200, -200, 1200, 1200);
|
mScene->setSceneRect(0, 0, ui.graphicsView->width(), ui.graphicsView->height());
|
||||||
|
|
||||||
ui.graphicsView->setScene(mScene);
|
ui.graphicsView->setScene(mScene);
|
||||||
ui.graphicsView->setEdgeLength(ui.edgeLengthSB->value()) ;
|
ui.graphicsView->setEdgeLength(ui.edgeLengthSB->value()) ;
|
||||||
|
@ -127,7 +127,8 @@ GraphWidget::GraphWidget(QWidget *)
|
|||||||
// scene->setItemIndexMethod(QGraphicsScene::NoIndex);
|
// scene->setItemIndexMethod(QGraphicsScene::NoIndex);
|
||||||
// scene->clear() ;
|
// scene->clear() ;
|
||||||
// setScene(scene);
|
// setScene(scene);
|
||||||
// scene->setSceneRect(0, 0, 500, 500);
|
|
||||||
|
// scene()->setSceneRect(0, 0, width(), height());
|
||||||
|
|
||||||
setCacheMode(CacheBackground);
|
setCacheMode(CacheBackground);
|
||||||
setViewportUpdateMode(BoundingRectViewportUpdate);
|
setViewportUpdateMode(BoundingRectViewportUpdate);
|
||||||
@ -154,7 +155,8 @@ void GraphWidget::clearGraph()
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
scene()->clear();
|
scene()->clear();
|
||||||
scene()->setSceneRect(-200, -200, 1000, 1000);
|
scene()->setSceneRect(0, 0, width(), height());
|
||||||
|
|
||||||
_edges.clear();
|
_edges.clear();
|
||||||
_nodes.clear();
|
_nodes.clear();
|
||||||
_friction_factor = 1.0f ;
|
_friction_factor = 1.0f ;
|
||||||
@ -391,9 +393,11 @@ void GraphWidget::setEdgeLength(uint32_t l)
|
|||||||
|
|
||||||
void GraphWidget::setNameSearch(QString s)
|
void GraphWidget::setNameSearch(QString s)
|
||||||
{
|
{
|
||||||
|
float f = QFontMetrics(font()).height()/16.0 ;
|
||||||
|
|
||||||
if (s.length() == 0){
|
if (s.length() == 0){
|
||||||
for(uint32_t i=0;i<_nodes.size();++i)
|
for(uint32_t i=0;i<_nodes.size();++i)
|
||||||
_nodes[i]->setNodeDrawSize(20);
|
_nodes[i]->setNodeDrawSize(20 * f);
|
||||||
forceRedraw();
|
forceRedraw();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -405,10 +409,10 @@ void GraphWidget::setNameSearch(QString s)
|
|||||||
|
|
||||||
if (ns.find(qs) != std::string::npos) {
|
if (ns.find(qs) != std::string::npos) {
|
||||||
//std::cout << "found!" << '\n';
|
//std::cout << "found!" << '\n';
|
||||||
ni->setNodeDrawSize(22);
|
ni->setNodeDrawSize(22 * f);
|
||||||
//std::cout << ni->getNodeDrawSize() << '\n';
|
//std::cout << ni->getNodeDrawSize() << '\n';
|
||||||
} else {
|
} else {
|
||||||
ni->setNodeDrawSize(12);
|
ni->setNodeDrawSize(12 * f);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -420,47 +424,53 @@ void GraphWidget::forceRedraw()
|
|||||||
for(uint32_t i=0;i<_nodes.size();++i)
|
for(uint32_t i=0;i<_nodes.size();++i)
|
||||||
_nodes[i]->update(_nodes[i]->boundingRect()) ;
|
_nodes[i]->update(_nodes[i]->boundingRect()) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GraphWidget::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
scene()->setSceneRect(QRectF(QPointF(0,0),event->size()));
|
||||||
|
}
|
||||||
|
|
||||||
void GraphWidget::wheelEvent(QWheelEvent *event)
|
void GraphWidget::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
scaleView(pow((double)2, -event->delta() / 240.0));
|
scaleView(pow((double)2, -event->delta() / 240.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect)
|
//void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect)
|
||||||
{
|
//{
|
||||||
Q_UNUSED(rect);
|
// Q_UNUSED(rect);
|
||||||
|
//
|
||||||
// Shadow
|
// // Shadow
|
||||||
QRectF sceneRect = this->sceneRect();
|
// QRectF sceneRect = this->sceneRect();
|
||||||
QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height());
|
// QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height());
|
||||||
QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5);
|
// QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5);
|
||||||
if (rightShadow.intersects(rect) || rightShadow.contains(rect))
|
// if (rightShadow.intersects(rect) || rightShadow.contains(rect))
|
||||||
painter->fillRect(rightShadow, Qt::darkGray);
|
// painter->fillRect(rightShadow, Qt::darkGray);
|
||||||
if (bottomShadow.intersects(rect) || bottomShadow.contains(rect))
|
// if (bottomShadow.intersects(rect) || bottomShadow.contains(rect))
|
||||||
painter->fillRect(bottomShadow, Qt::darkGray);
|
// painter->fillRect(bottomShadow, Qt::darkGray);
|
||||||
|
//
|
||||||
// Fill
|
// // Fill
|
||||||
QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
|
// QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
|
||||||
gradient.setColorAt(0, Qt::white);
|
// gradient.setColorAt(0, Qt::white);
|
||||||
gradient.setColorAt(1, Qt::lightGray);
|
// gradient.setColorAt(1, Qt::lightGray);
|
||||||
painter->fillRect(rect.intersected(sceneRect), gradient);
|
// painter->fillRect(rect.intersected(sceneRect), gradient);
|
||||||
painter->setBrush(Qt::NoBrush);
|
// painter->setBrush(Qt::NoBrush);
|
||||||
painter->drawRect(sceneRect);
|
// painter->drawRect(sceneRect);
|
||||||
|
//
|
||||||
// Text
|
// // Text
|
||||||
QRectF textRect(sceneRect.left() + 4, sceneRect.top() + 4,
|
// QRectF textRect(sceneRect.left() + 4, sceneRect.top() + 4,
|
||||||
sceneRect.width() - 4, sceneRect.height() - 4);
|
// sceneRect.width() - 4, sceneRect.height() - 4);
|
||||||
QString message(tr("Click and drag the nodes around, and zoom with the mouse "
|
// QString message(tr("Click and drag the nodes around, and zoom with the mouse "
|
||||||
"wheel or the '+' and '-' keys"));
|
// "wheel or the '+' and '-' keys"));
|
||||||
|
//
|
||||||
QFont font = painter->font();
|
// QFont font = painter->font();
|
||||||
font.setBold(true);
|
// font.setBold(true);
|
||||||
font.setPointSize(14);
|
// font.setPointSize(14);
|
||||||
painter->setFont(font);
|
// painter->setFont(font);
|
||||||
painter->setPen(Qt::lightGray);
|
// painter->setPen(Qt::lightGray);
|
||||||
painter->drawText(textRect.translated(2, 2), message);
|
// painter->drawText(textRect.translated(2, 2), message);
|
||||||
painter->setPen(Qt::black);
|
// painter->setPen(Qt::black);
|
||||||
painter->drawText(textRect, message);
|
// painter->drawText(textRect, message);
|
||||||
}
|
//}
|
||||||
|
|
||||||
void GraphWidget::scaleView(qreal scaleFactor)
|
void GraphWidget::scaleView(qreal scaleFactor)
|
||||||
{
|
{
|
||||||
|
@ -91,10 +91,11 @@ public:
|
|||||||
|
|
||||||
void forceRedraw() ;
|
void forceRedraw() ;
|
||||||
protected:
|
protected:
|
||||||
void keyPressEvent(QKeyEvent *event);
|
virtual void keyPressEvent(QKeyEvent *event);
|
||||||
void timerEvent(QTimerEvent *event);
|
virtual void timerEvent(QTimerEvent *event);
|
||||||
void wheelEvent(QWheelEvent *event);
|
virtual void wheelEvent(QWheelEvent *event);
|
||||||
void drawBackground(QPainter *painter, const QRectF &rect);
|
virtual void resizeEvent(QResizeEvent *event);
|
||||||
|
//void drawBackground(QPainter *painter, const QRectF &rect);
|
||||||
|
|
||||||
void scaleView(qreal scaleFactor);
|
void scaleView(qreal scaleFactor);
|
||||||
|
|
||||||
|
@ -205,8 +205,8 @@ void Node::calculateForces(const double *map,int width,int height,int W,int H,fl
|
|||||||
|
|
||||||
QRectF sceneRect = scene()->sceneRect();
|
QRectF sceneRect = scene()->sceneRect();
|
||||||
newPos = pos() + QPointF(_speedx, _speedy) / friction_factor;
|
newPos = pos() + QPointF(_speedx, _speedy) / friction_factor;
|
||||||
newPos.setX(qMin(qMax(newPos.x(), sceneRect.left() + 10), sceneRect.right() - 10));
|
newPos.setX(qMin(qMax(newPos.x(), sceneRect.left()), sceneRect.right()));
|
||||||
newPos.setY(qMin(qMax(newPos.y(), sceneRect.top() + 10), sceneRect.bottom() - 10));
|
newPos.setY(qMin(qMax(newPos.y(), sceneRect.top()) , sceneRect.bottom()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Node::advance()
|
bool Node::advance()
|
||||||
@ -222,20 +222,22 @@ bool Node::advance()
|
|||||||
|
|
||||||
QRectF Node::boundingRect() const
|
QRectF Node::boundingRect() const
|
||||||
{
|
{
|
||||||
qreal adjust = 2;
|
float m = QFontMetricsF(graph->font()).height();
|
||||||
|
float f = m/16.0;
|
||||||
|
qreal adjust = 2*f;
|
||||||
/* add in the size of the text */
|
/* add in the size of the text */
|
||||||
qreal realwidth = 40;
|
qreal realwidth = 40*f;
|
||||||
|
|
||||||
if (mDeterminedBB)
|
if (mDeterminedBB)
|
||||||
{
|
{
|
||||||
realwidth = mBBWidth + adjust;
|
realwidth = mBBWidth + adjust;
|
||||||
}
|
}
|
||||||
if (realwidth < 23 + adjust)
|
if (realwidth < 23*f + adjust)
|
||||||
{
|
{
|
||||||
realwidth = 23 + adjust;
|
realwidth = 23*f + adjust;
|
||||||
}
|
}
|
||||||
|
|
||||||
return QRectF(-10 - adjust, -10 - adjust,
|
return QRectF(-10*f - adjust, -10*f - adjust, realwidth, 23*f + adjust);
|
||||||
realwidth, 23 + adjust);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPainterPath Node::shape() const
|
QPainterPath Node::shape() const
|
||||||
@ -314,12 +316,17 @@ void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid
|
|||||||
painter->setBrush(gradient);
|
painter->setBrush(gradient);
|
||||||
painter->setPen(QPen(Qt::black, 0));
|
painter->setPen(QPen(Qt::black, 0));
|
||||||
painter->drawEllipse(-mNodeDrawSize2, -mNodeDrawSize2, mNodeDrawSize, mNodeDrawSize);
|
painter->drawEllipse(-mNodeDrawSize2, -mNodeDrawSize2, mNodeDrawSize, mNodeDrawSize);
|
||||||
painter->drawText(-10, 0, QString::fromUtf8(_desc_string.c_str()));
|
|
||||||
|
QString txt = QString::fromUtf8(_desc_string.c_str());
|
||||||
|
float m = QFontMetricsF(graph->font()).height();
|
||||||
|
float f = m/16.0;
|
||||||
|
|
||||||
|
painter->drawText(-10, 5*f, txt) ;
|
||||||
|
|
||||||
if (!mDeterminedBB)
|
if (!mDeterminedBB)
|
||||||
{
|
{
|
||||||
QRect textBox = painter->boundingRect(-10, 0, 400, 20, 0, QString::fromUtf8(_desc_string.c_str()));
|
QRect textBox = painter->boundingRect(-10, 5*f, QFontMetricsF(graph->font()).width(txt), 1.5*m, Qt::AlignVCenter, QString::fromUtf8(_desc_string.c_str()));
|
||||||
mBBWidth = textBox.width();
|
mBBWidth = textBox.width()+40*f;
|
||||||
mDeterminedBB = true;
|
mDeterminedBB = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user