ui: only single class expand button next to class name
This change reduces the size of collapsed classes in the GraphView by removing the condensed view of the class access nodes and using a single button next to the class name for collapsing and expanding instead.
This commit is contained in:
@@ -55,6 +55,8 @@ add_files(
|
||||
qt/view/graphElements/QtGraphNode.h
|
||||
qt/view/graphElements/QtGraphNodeAccess.cpp
|
||||
qt/view/graphElements/QtGraphNodeAccess.h
|
||||
qt/view/graphElements/QtGraphNodeExpandToggle.cpp
|
||||
qt/view/graphElements/QtGraphNodeExpandToggle.h
|
||||
|
||||
qt/view/QtCodeView.cpp
|
||||
qt/view/QtCodeView.h
|
||||
|
||||
@@ -20,8 +20,8 @@ QtStraightLineItem::QtStraightLineItem(QGraphicsItem* parent)
|
||||
m_circle->setAcceptHoverEvents(true);
|
||||
|
||||
QFont font;
|
||||
font.setFamily(GraphViewStyle::getFontNameOfNumber().c_str());
|
||||
font.setPixelSize(GraphViewStyle::getFontSizeOfNumber());
|
||||
font.setFamily(GraphViewStyle::getFontNameOfExpandToggleNode().c_str());
|
||||
font.setPixelSize(GraphViewStyle::getFontSizeOfExpandToggleNode());
|
||||
font.setWeight(QFont::Normal);
|
||||
|
||||
m_number = new QGraphicsSimpleTextItem(this);
|
||||
|
||||
@@ -423,14 +423,14 @@ void QtGraphPostprocessor::resizeNodes(std::list<std::shared_ptr<QtGraphNode>>&
|
||||
Vec2i size = (*it)->getSize();
|
||||
|
||||
int newWidth = s_cellSize;
|
||||
while(size.x - newWidth > 0)
|
||||
while(size.x - newWidth > 3)
|
||||
{
|
||||
newWidth += s_cellPadding + s_cellSize;
|
||||
}
|
||||
size.x = newWidth;
|
||||
|
||||
int newHeight = s_cellSize;
|
||||
while(size.y - newHeight > 0)
|
||||
while(size.y - newHeight > 3)
|
||||
{
|
||||
newHeight += s_cellPadding + s_cellSize;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "qt/view/graphElements/QtGraphEdge.h"
|
||||
#include "qt/view/graphElements/QtGraphNode.h"
|
||||
#include "qt/view/graphElements/QtGraphNodeAccess.h"
|
||||
#include "qt/view/graphElements/QtGraphNodeExpandToggle.h"
|
||||
|
||||
QtGraphView::QtGraphView(ViewLayout* viewLayout)
|
||||
: GraphView(viewLayout)
|
||||
@@ -229,13 +230,17 @@ std::shared_ptr<QtGraphNode> QtGraphView::createNodeRecursive(
|
||||
}
|
||||
|
||||
std::shared_ptr<QtGraphNode> newNode;
|
||||
if (node.data)
|
||||
if (node.isGraphNode())
|
||||
{
|
||||
newNode = std::make_shared<QtGraphNode>(node.data);
|
||||
newNode = std::make_shared<QtGraphNode>(node.data, node.childVisible);
|
||||
}
|
||||
else
|
||||
else if (node.isAccessNode())
|
||||
{
|
||||
newNode = std::make_shared<QtGraphNodeAccess>(node.accessType, node.isExpanded(), node.invisibleSubNodeCount);
|
||||
newNode = std::make_shared<QtGraphNodeAccess>(node.accessType);
|
||||
}
|
||||
else if (node.isExpandToggleNode())
|
||||
{
|
||||
newNode = std::make_shared<QtGraphNodeExpandToggle>(node.isExpanded(), node.invisibleSubNodeCount);
|
||||
}
|
||||
|
||||
newNode->setPosition(node.position);
|
||||
@@ -325,7 +330,8 @@ void QtGraphView::compareNodesRecursive(
|
||||
if (((*it)->getTokenId() && (*it)->getTokenId() == (*it2)->getTokenId()) ||
|
||||
((*it)->isAccessNode() && (*it2)->isAccessNode() &&
|
||||
dynamic_cast<QtGraphNodeAccess*>((*it).get())->getAccessType() ==
|
||||
dynamic_cast<QtGraphNodeAccess*>((*it2).get())->getAccessType()))
|
||||
dynamic_cast<QtGraphNodeAccess*>((*it2).get())->getAccessType()) ||
|
||||
((*it)->isExpandToggleNode() && (*it2)->isExpandToggleNode()))
|
||||
{
|
||||
remainingNodes->push_back(std::pair<QtGraphNode*, QtGraphNode*>((*it).get(), (*it2).get()));
|
||||
compareNodesRecursive((*it)->getSubNodes(), (*it2)->getSubNodes(), appearingNodes, vanishingNodes, remainingNodes);
|
||||
|
||||
@@ -45,6 +45,7 @@ QtGraphNode::QtGraphNode()
|
||||
, m_undefinedRect(nullptr)
|
||||
, m_isActive(false)
|
||||
, m_isHovering(false)
|
||||
, m_childVisible(false)
|
||||
{
|
||||
this->setPen(QPen(Qt::transparent));
|
||||
|
||||
@@ -52,11 +53,12 @@ QtGraphNode::QtGraphNode()
|
||||
m_text = new QGraphicsSimpleTextItem(this);
|
||||
}
|
||||
|
||||
QtGraphNode::QtGraphNode(const Node* data)
|
||||
QtGraphNode::QtGraphNode(const Node* data, bool childVisible)
|
||||
: GraphNode(data)
|
||||
, m_undefinedRect(nullptr)
|
||||
, m_isActive(false)
|
||||
, m_isHovering(false)
|
||||
, m_childVisible(childVisible)
|
||||
{
|
||||
this->setPen(QPen(Qt::transparent));
|
||||
|
||||
@@ -87,6 +89,11 @@ bool QtGraphNode::isAccessNode() const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QtGraphNode::isExpandToggleNode() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Vec2i QtGraphNode::getPosition() const
|
||||
{
|
||||
return Vec2i(this->scenePos().x(), this->scenePos().y());
|
||||
@@ -263,7 +270,7 @@ void QtGraphNode::hoverEnter()
|
||||
void QtGraphNode::updateStyle()
|
||||
{
|
||||
GraphViewStyle::NodeStyle style =
|
||||
GraphViewStyle::getStyleForNodeType(m_data->getType(), m_isActive, m_isHovering, m_subNodes.size() > 0);
|
||||
GraphViewStyle::getStyleForNodeType(m_data->getType(), m_isActive, m_isHovering, m_childVisible);
|
||||
setStyle(style);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,13 +32,14 @@ public:
|
||||
static QFont getFontForNodeType(Node::NodeType type);
|
||||
|
||||
QtGraphNode();
|
||||
QtGraphNode(const Node* data);
|
||||
QtGraphNode(const Node* data, bool childVisible);
|
||||
virtual ~QtGraphNode();
|
||||
|
||||
virtual std::string getName() const;
|
||||
void setName(const std::string& name);
|
||||
|
||||
virtual bool isAccessNode() const;
|
||||
virtual bool isExpandToggleNode() const;
|
||||
|
||||
virtual Vec2i getPosition() const;
|
||||
virtual bool setPosition(const Vec2i& position);
|
||||
@@ -106,6 +107,7 @@ private:
|
||||
|
||||
bool m_isActive;
|
||||
bool m_isHovering;
|
||||
bool m_childVisible;
|
||||
};
|
||||
|
||||
#endif // QT_GRAPH_NODE_H
|
||||
|
||||
@@ -4,63 +4,11 @@
|
||||
#include <QFontMetrics>
|
||||
#include <QPen>
|
||||
|
||||
#include "utility/messaging/type/MessageGraphNodeExpand.h"
|
||||
|
||||
#include "component/view/GraphViewStyle.h"
|
||||
#include "qt/graphics/QtRoundedRectItem.h"
|
||||
#include "qt/utility/QtDeviceScaledPixmap.h"
|
||||
|
||||
QtGraphNodeAccess::QtAccessToggle::QtAccessToggle(bool expanded, int invisibleSubNodeCount, QGraphicsItem* parent)
|
||||
: QGraphicsRectItem(parent)
|
||||
{
|
||||
const int iconHeight = 4;
|
||||
m_icon = new QGraphicsPixmapItem(this);
|
||||
|
||||
if (!expanded && !invisibleSubNodeCount)
|
||||
{
|
||||
this->hide();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
QtDeviceScaledPixmap pixmap("data/gui/graph_view/images/arrow.png");
|
||||
pixmap.scaleToHeight(iconHeight);
|
||||
|
||||
if (invisibleSubNodeCount)
|
||||
{
|
||||
QFont font;
|
||||
font.setFamily(GraphViewStyle::getFontNameOfNumber().c_str());
|
||||
font.setPixelSize(GraphViewStyle::getFontSizeOfNumber());
|
||||
font.setWeight(QFont::Normal);
|
||||
|
||||
m_number = new QGraphicsSimpleTextItem(this);
|
||||
m_number->setFont(font);
|
||||
|
||||
QString numberStr = QString::number(invisibleSubNodeCount);
|
||||
m_number->setText(numberStr);
|
||||
m_number->setPos(
|
||||
-QFontMetrics(m_number->font()).width(numberStr) / 2,
|
||||
-iconHeight - QFontMetrics(m_number->font()).height()
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
pixmap.mirror();
|
||||
}
|
||||
|
||||
m_icon->setPixmap(pixmap.pixmap());
|
||||
m_icon->setPos(-pixmap.width() / 2, -iconHeight);
|
||||
}
|
||||
}
|
||||
|
||||
QtGraphNodeAccess::QtAccessToggle::~QtAccessToggle()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QtGraphNodeAccess::QtGraphNodeAccess(
|
||||
TokenComponentAccess::AccessType accessType, bool expanded, int invisibleSubNodeCount
|
||||
)
|
||||
QtGraphNodeAccess::QtGraphNodeAccess(TokenComponentAccess::AccessType accessType)
|
||||
: QtGraphNode()
|
||||
, m_access(accessType)
|
||||
, m_accessIconSize(20)
|
||||
@@ -73,7 +21,6 @@ QtGraphNodeAccess::QtGraphNodeAccess(
|
||||
pixmap.scaleToHeight(m_accessIconSize);
|
||||
|
||||
m_accessIcon = new QGraphicsPixmapItem(pixmap.pixmap(), this);
|
||||
m_accessToggle = new QtAccessToggle(expanded, invisibleSubNodeCount, this);
|
||||
}
|
||||
|
||||
QtGraphNodeAccess::~QtGraphNodeAccess()
|
||||
@@ -90,29 +37,12 @@ TokenComponentAccess::AccessType QtGraphNodeAccess::getAccessType() const
|
||||
return m_access;
|
||||
}
|
||||
|
||||
void QtGraphNodeAccess::setSize(const Vec2i& size)
|
||||
{
|
||||
QtGraphNode::setSize(size);
|
||||
|
||||
m_accessToggle->setPos(m_rect->rect().width() / 2, m_rect->rect().height() - 5);
|
||||
}
|
||||
|
||||
void QtGraphNodeAccess::addSubNode(const std::shared_ptr<QtGraphNode>& node)
|
||||
{
|
||||
QtGraphNode::addSubNode(node);
|
||||
m_text->show();
|
||||
}
|
||||
|
||||
void QtGraphNodeAccess::onClick()
|
||||
{
|
||||
QtGraphNode* parent = getParent();
|
||||
|
||||
if (m_accessToggle->isVisible() && parent && parent->getData())
|
||||
{
|
||||
MessageGraphNodeExpand(parent->getData()->getId(), m_access).dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
void QtGraphNodeAccess::updateStyle()
|
||||
{
|
||||
GraphViewStyle::NodeStyle style = GraphViewStyle::getStyleOfAccessNode();
|
||||
|
||||
@@ -8,27 +8,13 @@ class QtGraphNodeAccess
|
||||
: public QtGraphNode
|
||||
{
|
||||
public:
|
||||
class QtAccessToggle
|
||||
: public QGraphicsRectItem
|
||||
{
|
||||
public:
|
||||
QtAccessToggle(bool expanded, int invisibleSubNodeCount, QGraphicsItem* parent);
|
||||
virtual ~QtAccessToggle();
|
||||
|
||||
private:
|
||||
QGraphicsPixmapItem* m_icon;
|
||||
QGraphicsSimpleTextItem* m_number;
|
||||
};
|
||||
|
||||
QtGraphNodeAccess(TokenComponentAccess::AccessType accessType, bool expanded, int invisibleSubNodeCount);
|
||||
QtGraphNodeAccess(TokenComponentAccess::AccessType accessType);
|
||||
virtual ~QtGraphNodeAccess();
|
||||
|
||||
virtual bool isAccessNode() const;
|
||||
TokenComponentAccess::AccessType getAccessType() const;
|
||||
|
||||
virtual void setSize(const Vec2i& size);
|
||||
virtual void addSubNode(const std::shared_ptr<QtGraphNode>& node);
|
||||
virtual void onClick();
|
||||
|
||||
virtual void updateStyle();
|
||||
|
||||
@@ -39,8 +25,6 @@ private:
|
||||
|
||||
QGraphicsPixmapItem* m_accessIcon;
|
||||
int m_accessIconSize;
|
||||
|
||||
QtAccessToggle* m_accessToggle;
|
||||
};
|
||||
|
||||
#endif // QT_GRAPH_NODE_ACCESS_H
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
#include "qt/view/graphElements/QtGraphNodeExpandToggle.h"
|
||||
|
||||
#include "utility/messaging/type/MessageGraphNodeExpand.h"
|
||||
|
||||
#include "qt/graphics/QtRoundedRectItem.h"
|
||||
#include "qt/utility/QtDeviceScaledPixmap.h"
|
||||
|
||||
QtGraphNodeExpandToggle::QtGraphNodeExpandToggle(bool expanded, int invisibleSubNodeCount)
|
||||
: m_allVisible(invisibleSubNodeCount == 0)
|
||||
{
|
||||
const int iconHeight = 4;
|
||||
m_icon = new QGraphicsPixmapItem(this);
|
||||
|
||||
if (!expanded && !invisibleSubNodeCount)
|
||||
{
|
||||
this->hide();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
QtDeviceScaledPixmap pixmap("data/gui/graph_view/images/arrow.png");
|
||||
pixmap.scaleToHeight(iconHeight);
|
||||
|
||||
if (invisibleSubNodeCount)
|
||||
{
|
||||
QString numberStr = QString::number(invisibleSubNodeCount);
|
||||
m_text->setText(numberStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
pixmap.mirror();
|
||||
}
|
||||
|
||||
m_icon->setPixmap(pixmap.pixmap());
|
||||
}
|
||||
}
|
||||
|
||||
QtGraphNodeExpandToggle::~QtGraphNodeExpandToggle()
|
||||
{
|
||||
}
|
||||
|
||||
bool QtGraphNodeExpandToggle::isExpandToggleNode() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void QtGraphNodeExpandToggle::onClick()
|
||||
{
|
||||
QtGraphNode* parent = getParent();
|
||||
|
||||
if (parent && parent->getData())
|
||||
{
|
||||
MessageGraphNodeExpand(parent->getData()->getId()).dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
void QtGraphNodeExpandToggle::updateStyle()
|
||||
{
|
||||
GraphViewStyle::NodeStyle style = GraphViewStyle::getStyleOfExpandToggleNode();
|
||||
setStyle(style);
|
||||
|
||||
m_text->setPos(
|
||||
(m_rect->rect().width() - QFontMetrics(m_text->font()).width(m_text->text())) / 2,
|
||||
5
|
||||
);
|
||||
|
||||
m_icon->setPos(
|
||||
(m_rect->rect().width() - m_icon->pixmap().width() / QtDeviceScaledPixmap::devicePixelRatio()) / 2,
|
||||
(m_allVisible ? 9 : 14)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef QT_EXPAND_TOGGLE_H
|
||||
#define QT_EXPAND_TOGGLE_H
|
||||
|
||||
#include <QGraphicsItem>
|
||||
|
||||
#include "qt/view/graphElements/QtGraphNode.h"
|
||||
|
||||
class QtGraphNodeExpandToggle
|
||||
: public QtGraphNode
|
||||
{
|
||||
public:
|
||||
QtGraphNodeExpandToggle(bool expanded, int invisibleSubNodeCount);
|
||||
virtual ~QtGraphNodeExpandToggle();
|
||||
|
||||
virtual bool isExpandToggleNode() const;
|
||||
|
||||
virtual void onClick();
|
||||
virtual void updateStyle();
|
||||
|
||||
private:
|
||||
QGraphicsPixmapItem* m_icon;
|
||||
bool m_allVisible;
|
||||
};
|
||||
|
||||
#endif // QT_EXPAND_TOGGLE_H
|
||||
Reference in New Issue
Block a user