Colors and rearrange

This commit is contained in:
Joey Yakimowich-Payne 2026-01-29 22:22:47 -07:00
commit 2edd7a366a
4 changed files with 58 additions and 14 deletions

View file

@ -134,10 +134,7 @@ QVariant WarpGraphModel::nodeData(QtNodes::NodeId nodeId,
if (sizeIt != m_sizes.end()) {
return sizeIt->second;
}
int maxPorts = static_cast<int>(
std::max(data.inputPorts.size(), data.outputPorts.size()));
int height = std::max(80, 50 + maxPorts * 28);
return QSize(200, height);
return estimateNodeSize(data);
}
case QtNodes::NodeRole::InPortCount:
return static_cast<unsigned int>(data.inputPorts.size());
@ -354,9 +351,9 @@ void WarpGraphModel::refreshFromClient() {
data.inputPorts = std::move(inputs);
data.outputPorts = std::move(outputs);
m_nodes.emplace(qtId, std::move(data));
auto [nodeIt, _] = m_nodes.emplace(qtId, std::move(data));
m_pwToQt.emplace(nodeInfo.id.value, qtId);
m_positions.emplace(qtId, nextPosition());
m_positions.emplace(qtId, nextPosition(nodeIt->second));
Q_EMIT nodeCreated(qtId);
}
@ -473,17 +470,50 @@ QtNodes::NodeId WarpGraphModel::qtNodeIdForPw(uint32_t pwNodeId) const {
}
QString WarpGraphModel::captionForNode(const warppipe::NodeInfo &info) {
if (!info.description.empty()) {
return QString::fromStdString(info.description);
}
if (!info.application_name.empty() && info.application_name != info.name) {
return QString::fromStdString(info.application_name);
}
return QString::fromStdString(info.name);
}
QPointF WarpGraphModel::nextPosition() const {
int count = static_cast<int>(m_nodes.size());
double x = (count % 4) * 280.0;
double y = (count / 4) * 200.0;
return QPointF(x, y);
QSize WarpGraphModel::estimateNodeSize(const WarpNodeData &data) {
int maxPorts = static_cast<int>(
std::max(data.inputPorts.size(), data.outputPorts.size()));
int height = std::max(80, 50 + maxPorts * 28);
QString caption = captionForNode(data.info);
int captionWidth = caption.length() * 8 + 40;
int maxInputLen = 0;
int maxOutputLen = 0;
for (const auto &p : data.inputPorts)
maxInputLen = std::max(maxInputLen, static_cast<int>(p.name.length()));
for (const auto &p : data.outputPorts)
maxOutputLen = std::max(maxOutputLen, static_cast<int>(p.name.length()));
int portWidth = (maxInputLen + maxOutputLen) * 7 + 60;
int width = std::max(180, std::max(captionWidth, portWidth));
return QSize(width, height);
}
QPointF WarpGraphModel::nextPosition(const WarpNodeData &data) {
QSize size = estimateNodeSize(data);
double nodeW = size.width();
double nodeH = size.height();
if (m_nextX + nodeW > kMaxRowWidth && m_nextX > 0) {
m_nextX = 0.0;
m_nextY += m_rowMaxHeight + kVerticalGap;
m_rowMaxHeight = 0.0;
}
QPointF pos(m_nextX, m_nextY);
m_nextX += nodeW + kHorizontalGap;
m_rowMaxHeight = std::max(m_rowMaxHeight, nodeH);
return pos;
}
bool WarpGraphModel::isGhost(QtNodes::NodeId nodeId) const {
@ -516,13 +546,17 @@ QVariant WarpGraphModel::styleForNode(WarpNodeType type, bool ghost) {
QColor base;
switch (type) {
case WarpNodeType::kHardwareSink:
case WarpNodeType::kHardwareSource:
base = QColor(72, 94, 118);
break;
case WarpNodeType::kHardwareSource:
base = QColor(94, 72, 118);
break;
case WarpNodeType::kVirtualSink:
case WarpNodeType::kVirtualSource:
base = QColor(62, 122, 104);
break;
case WarpNodeType::kVirtualSource:
base = QColor(62, 104, 122);
break;
case WarpNodeType::kApplication:
base = QColor(138, 104, 72);
break;

View file

@ -69,7 +69,8 @@ private:
static QString captionForNode(const warppipe::NodeInfo &info);
static WarpNodeType classifyNode(const warppipe::NodeInfo &info);
static QVariant styleForNode(WarpNodeType type, bool ghost);
QPointF nextPosition() const;
QPointF nextPosition(const WarpNodeData &data);
static QSize estimateNodeSize(const WarpNodeData &data);
warppipe::Client *m_client = nullptr;
QtNodes::NodeId m_nextNodeId = 1;
@ -83,4 +84,11 @@ private:
std::unordered_map<QtNodes::NodeId, QPointF> m_positions;
std::unordered_map<QtNodes::NodeId, QSize> m_sizes;
std::unordered_set<QtNodes::NodeId> m_ghostNodes;
static constexpr double kHorizontalGap = 40.0;
static constexpr double kVerticalGap = 30.0;
static constexpr double kMaxRowWidth = 1400.0;
double m_nextX = 0.0;
double m_nextY = 0.0;
double m_rowMaxHeight = 0.0;
};

View file

@ -89,6 +89,7 @@ struct RuleId {
struct NodeInfo {
NodeId id;
std::string name;
std::string description;
std::string media_class;
std::string application_name;
std::string process_binary;

View file

@ -334,6 +334,7 @@ void Client::Impl::RegistryGlobal(void* data,
NodeInfo info;
info.id = NodeId{id};
info.name = LookupString(props, PW_KEY_NODE_NAME);
info.description = LookupString(props, PW_KEY_NODE_DESCRIPTION);
info.media_class = LookupString(props, PW_KEY_MEDIA_CLASS);
info.application_name = LookupString(props, PW_KEY_APP_NAME);
info.process_binary = LookupString(props, PW_KEY_APP_PROCESS_BINARY);