GUI Milestone 5
This commit is contained in:
parent
a369381b6c
commit
79cced017e
6 changed files with 228 additions and 20 deletions
|
|
@ -2,19 +2,41 @@
|
|||
#include "WarpGraphModel.h"
|
||||
|
||||
#include <QtNodes/BasicGraphicsScene>
|
||||
#include <QtNodes/ConnectionStyle>
|
||||
#include <QtNodes/GraphicsView>
|
||||
|
||||
#include <QInputDialog>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QStandardPaths>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
GraphEditorWidget::GraphEditorWidget(warppipe::Client *client,
|
||||
QWidget *parent)
|
||||
: QWidget(parent), m_client(client) {
|
||||
m_layoutPath =
|
||||
QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) +
|
||||
QStringLiteral("/layout.json");
|
||||
|
||||
m_model = new WarpGraphModel(client, this);
|
||||
bool hasLayout = m_model->loadLayout(m_layoutPath);
|
||||
|
||||
m_scene = new QtNodes::BasicGraphicsScene(*m_model, this);
|
||||
|
||||
QtNodes::ConnectionStyle::setConnectionStyle(
|
||||
R"({"ConnectionStyle": {
|
||||
"ConstructionColor": "#b4b4c8",
|
||||
"NormalColor": "#c8c8dc",
|
||||
"SelectedColor": "#ffa500",
|
||||
"SelectedHaloColor": "#ffa50040",
|
||||
"HoveredColor": "#f0c878",
|
||||
"LineWidth": 2.4,
|
||||
"ConstructionLineWidth": 1.8,
|
||||
"PointDiameter": 10.0,
|
||||
"UseDataDefinedColors": false
|
||||
}})");
|
||||
|
||||
m_view = new QtNodes::GraphicsView(m_scene);
|
||||
|
||||
auto *layout = new QVBoxLayout(this);
|
||||
|
|
@ -25,7 +47,20 @@ GraphEditorWidget::GraphEditorWidget(warppipe::Client *client,
|
|||
connect(m_view, &QWidget::customContextMenuRequested, this,
|
||||
&GraphEditorWidget::onContextMenuRequested);
|
||||
|
||||
connect(m_model, &WarpGraphModel::nodePositionUpdated, this,
|
||||
&GraphEditorWidget::scheduleSaveLayout);
|
||||
|
||||
m_saveTimer = new QTimer(this);
|
||||
m_saveTimer->setSingleShot(true);
|
||||
m_saveTimer->setInterval(1000);
|
||||
connect(m_saveTimer, &QTimer::timeout, this, [this]() {
|
||||
m_model->saveLayout(m_layoutPath);
|
||||
});
|
||||
|
||||
m_model->refreshFromClient();
|
||||
if (!hasLayout) {
|
||||
m_model->autoArrange();
|
||||
}
|
||||
|
||||
m_refreshTimer = new QTimer(this);
|
||||
connect(m_refreshTimer, &QTimer::timeout, this,
|
||||
|
|
@ -35,6 +70,25 @@ GraphEditorWidget::GraphEditorWidget(warppipe::Client *client,
|
|||
|
||||
void GraphEditorWidget::onRefreshTimer() { m_model->refreshFromClient(); }
|
||||
|
||||
void GraphEditorWidget::scheduleSaveLayout() {
|
||||
if (!m_saveTimer->isActive()) {
|
||||
m_saveTimer->start();
|
||||
}
|
||||
}
|
||||
|
||||
int GraphEditorWidget::nodeCount() const {
|
||||
return static_cast<int>(m_model->allNodeIds().size());
|
||||
}
|
||||
|
||||
int GraphEditorWidget::linkCount() const {
|
||||
int count = 0;
|
||||
for (auto nodeId : m_model->allNodeIds()) {
|
||||
count += static_cast<int>(
|
||||
m_model->allConnectionIds(nodeId).size());
|
||||
}
|
||||
return count / 2;
|
||||
}
|
||||
|
||||
void GraphEditorWidget::onContextMenuRequested(const QPoint &pos) {
|
||||
QPointF scenePos = m_view->mapToScene(pos);
|
||||
|
||||
|
|
@ -64,17 +118,21 @@ void GraphEditorWidget::onContextMenuRequested(const QPoint &pos) {
|
|||
}
|
||||
|
||||
void GraphEditorWidget::showCanvasContextMenu(const QPoint &screenPos,
|
||||
const QPointF &scenePos) {
|
||||
const QPointF &scenePos) {
|
||||
QMenu menu;
|
||||
QAction *createSink = menu.addAction(QStringLiteral("Create Virtual Sink"));
|
||||
QAction *createSource =
|
||||
menu.addAction(QStringLiteral("Create Virtual Source"));
|
||||
menu.addSeparator();
|
||||
QAction *autoArrange = menu.addAction(QStringLiteral("Auto-Arrange"));
|
||||
|
||||
QAction *chosen = menu.exec(screenPos);
|
||||
if (chosen == createSink) {
|
||||
createVirtualNode(true, scenePos);
|
||||
} else if (chosen == createSource) {
|
||||
createVirtualNode(false, scenePos);
|
||||
} else if (chosen == autoArrange) {
|
||||
m_model->autoArrange();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue