Colors and rearrange
This commit is contained in:
parent
8f341f631a
commit
2edd7a366a
4 changed files with 58 additions and 14 deletions
|
|
@ -134,10 +134,7 @@ QVariant WarpGraphModel::nodeData(QtNodes::NodeId nodeId,
|
||||||
if (sizeIt != m_sizes.end()) {
|
if (sizeIt != m_sizes.end()) {
|
||||||
return sizeIt->second;
|
return sizeIt->second;
|
||||||
}
|
}
|
||||||
int maxPorts = static_cast<int>(
|
return estimateNodeSize(data);
|
||||||
std::max(data.inputPorts.size(), data.outputPorts.size()));
|
|
||||||
int height = std::max(80, 50 + maxPorts * 28);
|
|
||||||
return QSize(200, height);
|
|
||||||
}
|
}
|
||||||
case QtNodes::NodeRole::InPortCount:
|
case QtNodes::NodeRole::InPortCount:
|
||||||
return static_cast<unsigned int>(data.inputPorts.size());
|
return static_cast<unsigned int>(data.inputPorts.size());
|
||||||
|
|
@ -354,9 +351,9 @@ void WarpGraphModel::refreshFromClient() {
|
||||||
data.inputPorts = std::move(inputs);
|
data.inputPorts = std::move(inputs);
|
||||||
data.outputPorts = std::move(outputs);
|
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_pwToQt.emplace(nodeInfo.id.value, qtId);
|
||||||
m_positions.emplace(qtId, nextPosition());
|
m_positions.emplace(qtId, nextPosition(nodeIt->second));
|
||||||
|
|
||||||
Q_EMIT nodeCreated(qtId);
|
Q_EMIT nodeCreated(qtId);
|
||||||
}
|
}
|
||||||
|
|
@ -473,17 +470,50 @@ QtNodes::NodeId WarpGraphModel::qtNodeIdForPw(uint32_t pwNodeId) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
QString WarpGraphModel::captionForNode(const warppipe::NodeInfo &info) {
|
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) {
|
if (!info.application_name.empty() && info.application_name != info.name) {
|
||||||
return QString::fromStdString(info.application_name);
|
return QString::fromStdString(info.application_name);
|
||||||
}
|
}
|
||||||
return QString::fromStdString(info.name);
|
return QString::fromStdString(info.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF WarpGraphModel::nextPosition() const {
|
QSize WarpGraphModel::estimateNodeSize(const WarpNodeData &data) {
|
||||||
int count = static_cast<int>(m_nodes.size());
|
int maxPorts = static_cast<int>(
|
||||||
double x = (count % 4) * 280.0;
|
std::max(data.inputPorts.size(), data.outputPorts.size()));
|
||||||
double y = (count / 4) * 200.0;
|
int height = std::max(80, 50 + maxPorts * 28);
|
||||||
return QPointF(x, y);
|
|
||||||
|
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 {
|
bool WarpGraphModel::isGhost(QtNodes::NodeId nodeId) const {
|
||||||
|
|
@ -516,13 +546,17 @@ QVariant WarpGraphModel::styleForNode(WarpNodeType type, bool ghost) {
|
||||||
QColor base;
|
QColor base;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case WarpNodeType::kHardwareSink:
|
case WarpNodeType::kHardwareSink:
|
||||||
case WarpNodeType::kHardwareSource:
|
|
||||||
base = QColor(72, 94, 118);
|
base = QColor(72, 94, 118);
|
||||||
break;
|
break;
|
||||||
|
case WarpNodeType::kHardwareSource:
|
||||||
|
base = QColor(94, 72, 118);
|
||||||
|
break;
|
||||||
case WarpNodeType::kVirtualSink:
|
case WarpNodeType::kVirtualSink:
|
||||||
case WarpNodeType::kVirtualSource:
|
|
||||||
base = QColor(62, 122, 104);
|
base = QColor(62, 122, 104);
|
||||||
break;
|
break;
|
||||||
|
case WarpNodeType::kVirtualSource:
|
||||||
|
base = QColor(62, 104, 122);
|
||||||
|
break;
|
||||||
case WarpNodeType::kApplication:
|
case WarpNodeType::kApplication:
|
||||||
base = QColor(138, 104, 72);
|
base = QColor(138, 104, 72);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,8 @@ private:
|
||||||
static QString captionForNode(const warppipe::NodeInfo &info);
|
static QString captionForNode(const warppipe::NodeInfo &info);
|
||||||
static WarpNodeType classifyNode(const warppipe::NodeInfo &info);
|
static WarpNodeType classifyNode(const warppipe::NodeInfo &info);
|
||||||
static QVariant styleForNode(WarpNodeType type, bool ghost);
|
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;
|
warppipe::Client *m_client = nullptr;
|
||||||
QtNodes::NodeId m_nextNodeId = 1;
|
QtNodes::NodeId m_nextNodeId = 1;
|
||||||
|
|
@ -83,4 +84,11 @@ private:
|
||||||
std::unordered_map<QtNodes::NodeId, QPointF> m_positions;
|
std::unordered_map<QtNodes::NodeId, QPointF> m_positions;
|
||||||
std::unordered_map<QtNodes::NodeId, QSize> m_sizes;
|
std::unordered_map<QtNodes::NodeId, QSize> m_sizes;
|
||||||
std::unordered_set<QtNodes::NodeId> m_ghostNodes;
|
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;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ struct RuleId {
|
||||||
struct NodeInfo {
|
struct NodeInfo {
|
||||||
NodeId id;
|
NodeId id;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
std::string description;
|
||||||
std::string media_class;
|
std::string media_class;
|
||||||
std::string application_name;
|
std::string application_name;
|
||||||
std::string process_binary;
|
std::string process_binary;
|
||||||
|
|
|
||||||
|
|
@ -334,6 +334,7 @@ void Client::Impl::RegistryGlobal(void* data,
|
||||||
NodeInfo info;
|
NodeInfo info;
|
||||||
info.id = NodeId{id};
|
info.id = NodeId{id};
|
||||||
info.name = LookupString(props, PW_KEY_NODE_NAME);
|
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.media_class = LookupString(props, PW_KEY_MEDIA_CLASS);
|
||||||
info.application_name = LookupString(props, PW_KEY_APP_NAME);
|
info.application_name = LookupString(props, PW_KEY_APP_NAME);
|
||||||
info.process_binary = LookupString(props, PW_KEY_APP_PROCESS_BINARY);
|
info.process_binary = LookupString(props, PW_KEY_APP_PROCESS_BINARY);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue