Files
Sourcetrail/src/lib_gui/qt/view/graphElements/QtGraphNodeExpandToggle.cpp
T
malte_langkabel 054b8fab17 logic: reduce access to filesystem while indexing
* use canonical filepath cache in cxx indexer
* made constructors of FilePath explicit
* use FilePath at more places instead of string
* forward declares FilePath wherever possible
2017-05-04 10:55:16 +02:00

93 lines
2.4 KiB
C++

#include "qt/view/graphElements/QtGraphNodeExpandToggle.h"
#include <QFontMetrics>
#include "utility/logging/logging.h"
#include "utility/messaging/type/MessageGraphNodeExpand.h"
#include "utility/ResourcePaths.h"
#include "qt/graphics/QtRoundedRectItem.h"
#include "qt/utility/QtDeviceScaledPixmap.h"
#include "qt/utility/utilityQt.h"
#include "qt/view/graphElements/QtGraphNodeData.h"
QtGraphNodeExpandToggle::QtGraphNodeExpandToggle(bool expanded, int invisibleSubNodeCount)
: m_invisibleSubNodeCount(invisibleSubNodeCount)
, m_expanded(expanded)
{
if (!expanded && !invisibleSubNodeCount)
{
LOG_ERROR("ExpandToggle shouldn't be visible");
return;
}
const int iconHeight = 4;
m_icon = new QGraphicsPixmapItem(this);
m_icon->setTransformationMode(Qt::SmoothTransformation);
m_icon->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
QtDeviceScaledPixmap pixmap((ResourcePaths::getGuiPath().str() + "graph_view/images/arrow.png").c_str());
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->getTokenId())
{
MessageGraphNodeExpand(parent->getTokenId(), !m_expanded).dispatch();
}
}
void QtGraphNodeExpandToggle::updateStyle()
{
if (!m_icon)
{
return;
}
GraphViewStyle::NodeStyle style = GraphViewStyle::getStyleOfExpandToggleNode();
setStyle(style);
float textX = (m_rect->rect().width() / 2) - (QFontMetrics(m_text->font()).width(m_text->text()) / 2);
float textY = m_rect->rect().height() / 2 - QFontMetrics(m_text->font()).height() / 1.8f;
// move the text to the nearest integer x pos, instead of the next lower int pos
// improves results on windows systems
if (textX - (float)((int)textX) >= 0.5f)
{
textX += 0.5f;
}
m_text->setPos(textX, textY);
m_icon->setPos(
(m_rect->rect().width() - m_icon->pixmap().width() / QtDeviceScaledPixmap::devicePixelRatio()) / 2,
(m_invisibleSubNodeCount == 0 ? m_rect->rect().height() / 2 - 2 : m_rect->rect().height() - 7)
);
m_icon->setPixmap(utility::colorizePixmap(m_icon->pixmap(), style.color.icon.c_str()));
}