Remove old FGQCanvas files
This commit is contained in:
parent
a184f532ce
commit
3c1cb67a27
9 changed files with 0 additions and 779 deletions
|
@ -1,71 +0,0 @@
|
||||||
//
|
|
||||||
// Copyright (C) 2017 James Turner zakalawe@mac.com
|
|
||||||
//
|
|
||||||
// This program is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation; either version 2 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful, but
|
|
||||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
|
|
||||||
#include "fgcanvaswidget.h"
|
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QPainter>
|
|
||||||
|
|
||||||
#include "localprop.h"
|
|
||||||
#include "fgcanvasgroup.h"
|
|
||||||
#include "fgcanvaspaintcontext.h"
|
|
||||||
|
|
||||||
FGCanvasWidget::FGCanvasWidget(QWidget *parent) :
|
|
||||||
QWidget(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void FGCanvasWidget::setRootProperty(LocalProp* root)
|
|
||||||
{
|
|
||||||
_canvasRoot = root;
|
|
||||||
_rootElement = new FGCanvasGroup(nullptr, root);
|
|
||||||
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
FGCanvasGroup *FGCanvasWidget::rootElement()
|
|
||||||
{
|
|
||||||
return _rootElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FGCanvasWidget::paintEvent(QPaintEvent *pe)
|
|
||||||
{
|
|
||||||
if (!_rootElement) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QPainter painter(this);
|
|
||||||
painter.fillRect(rect(), Qt::black);
|
|
||||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
|
||||||
|
|
||||||
QSizeF sz(_canvasRoot->value("size[0]", 512).toInt(),
|
|
||||||
_canvasRoot->value("size[1]", 512).toInt());
|
|
||||||
|
|
||||||
|
|
||||||
// set scaling by canvas size
|
|
||||||
|
|
||||||
const double verticalScaling = height() / sz.height();
|
|
||||||
const double horizontalScaling = width() / sz.width();
|
|
||||||
const double usedScale = std::min(verticalScaling, horizontalScaling);
|
|
||||||
|
|
||||||
painter.scale(usedScale, usedScale);
|
|
||||||
|
|
||||||
// captures the view scaling
|
|
||||||
FGCanvasPaintContext context(&painter);
|
|
||||||
_rootElement->paint(&context);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,47 +0,0 @@
|
||||||
//
|
|
||||||
// Copyright (C) 2017 James Turner zakalawe@mac.com
|
|
||||||
//
|
|
||||||
// This program is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation; either version 2 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful, but
|
|
||||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
|
|
||||||
#ifndef FGCANVASWIDGET_H
|
|
||||||
#define FGCANVASWIDGET_H
|
|
||||||
|
|
||||||
#include <QWidget>
|
|
||||||
#include "localprop.h"
|
|
||||||
|
|
||||||
class FGCanvasGroup;
|
|
||||||
|
|
||||||
class FGCanvasWidget : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit FGCanvasWidget(QWidget *parent = 0);
|
|
||||||
|
|
||||||
void setRootProperty(LocalProp *root);
|
|
||||||
|
|
||||||
FGCanvasGroup* rootElement();
|
|
||||||
signals:
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void paintEvent(QPaintEvent* pe);
|
|
||||||
|
|
||||||
private:
|
|
||||||
LocalProp* _canvasRoot = nullptr;
|
|
||||||
FGCanvasGroup* _rootElement = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // FGCANVASWIDGET_H
|
|
|
@ -7,7 +7,5 @@
|
||||||
<file>qml/CanvasFrame.qml</file>
|
<file>qml/CanvasFrame.qml</file>
|
||||||
<file>qml/BrowsePanel.qml</file>
|
<file>qml/BrowsePanel.qml</file>
|
||||||
<file>qml/LoadSavePanel.qml</file>
|
<file>qml/LoadSavePanel.qml</file>
|
||||||
<file>qml/image.qml</file>
|
|
||||||
<file>qml/text.qml</file>
|
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
import QtQuick 2.0
|
|
||||||
import FlightGear 1.0
|
|
||||||
|
|
||||||
CanvasItem {
|
|
||||||
implicitHeight: img.implicitHeight
|
|
||||||
implicitWidth: img.implicitWidth
|
|
||||||
|
|
||||||
property alias source: img.source
|
|
||||||
|
|
||||||
Image {
|
|
||||||
id: img
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,81 +0,0 @@
|
||||||
import QtQuick 2.0
|
|
||||||
import FlightGear 1.0
|
|
||||||
|
|
||||||
CanvasItem {
|
|
||||||
id: root
|
|
||||||
// implicitHeight: text.implicitHeight
|
|
||||||
// implicitWidth: text.implicitWidth
|
|
||||||
|
|
||||||
property alias text: text.text
|
|
||||||
property alias fontPixelSize: text.font.pixelSize
|
|
||||||
property alias fontFamily: text.font.family
|
|
||||||
property alias color: text.color
|
|
||||||
|
|
||||||
property string canvasAlignment: "center"
|
|
||||||
|
|
||||||
property string __canvasVAlign: "center"
|
|
||||||
property string __canvasHAlign: "center"
|
|
||||||
|
|
||||||
onCanvasAlignmentChanged: {
|
|
||||||
if (canvasAlignment == "center") {
|
|
||||||
__canvasVAlign = __canvasVAlign = "center";
|
|
||||||
} else {
|
|
||||||
var pieces = canvasAlignment.split("-");
|
|
||||||
__canvasHAlign = pieces[0]
|
|
||||||
__canvasVAlign = pieces[1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Text {
|
|
||||||
id: text
|
|
||||||
}
|
|
||||||
|
|
||||||
Binding {
|
|
||||||
when: __canvasHAlign == "left"
|
|
||||||
target: text
|
|
||||||
property: "anchors.left"
|
|
||||||
value: root.left
|
|
||||||
}
|
|
||||||
|
|
||||||
Binding {
|
|
||||||
when: __canvasHAlign == "right"
|
|
||||||
target: text
|
|
||||||
property: "anchors.right"
|
|
||||||
value: root.left
|
|
||||||
}
|
|
||||||
|
|
||||||
Binding {
|
|
||||||
when: __canvasHAlign == "center"
|
|
||||||
target: text
|
|
||||||
property: "anchors.horizontalCenter"
|
|
||||||
value: root.left
|
|
||||||
}
|
|
||||||
|
|
||||||
Binding {
|
|
||||||
when: __canvasVAlign == "top"
|
|
||||||
target: text
|
|
||||||
property: "anchors.top"
|
|
||||||
value: root.top
|
|
||||||
}
|
|
||||||
|
|
||||||
Binding {
|
|
||||||
when: __canvasVAlign == "bottom"
|
|
||||||
target: text
|
|
||||||
property: "anchors.bottom"
|
|
||||||
value: root.top
|
|
||||||
}
|
|
||||||
|
|
||||||
Binding {
|
|
||||||
when: __canvasVAlign == "center"
|
|
||||||
target: text
|
|
||||||
property: "anchors.verticalCenter"
|
|
||||||
value: root.top
|
|
||||||
}
|
|
||||||
|
|
||||||
Binding {
|
|
||||||
when: __canvasVAlign == "baseline"
|
|
||||||
target: text
|
|
||||||
property: "anchors.baseline"
|
|
||||||
value: root.top
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
import QtQuick 2.0
|
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
color: "black"
|
|
||||||
}
|
|
|
@ -1,343 +0,0 @@
|
||||||
//
|
|
||||||
// Copyright (C) 2017 James Turner zakalawe@mac.com
|
|
||||||
//
|
|
||||||
// This program is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation; either version 2 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful, but
|
|
||||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
|
|
||||||
#include "temporarywidget.h"
|
|
||||||
#include "ui_temporarywidget.h"
|
|
||||||
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QJsonValue>
|
|
||||||
#include <QSettings>
|
|
||||||
#include <QItemSelectionModel>
|
|
||||||
#include <QNetworkRequest>
|
|
||||||
#include <QNetworkAccessManager>
|
|
||||||
#include <QNetworkReply>
|
|
||||||
#include <QQuickItem>
|
|
||||||
#include <QAction>
|
|
||||||
#include <QFileDialog>
|
|
||||||
|
|
||||||
#include "fgqcanvasfontcache.h"
|
|
||||||
#include "fgqcanvasimageloader.h"
|
|
||||||
#include "canvastreemodel.h"
|
|
||||||
#include "localprop.h"
|
|
||||||
#include "elementdatamodel.h"
|
|
||||||
#include "fgcanvastext.h"
|
|
||||||
|
|
||||||
TemporaryWidget::TemporaryWidget(QWidget *parent) :
|
|
||||||
QWidget(parent),
|
|
||||||
ui(new Ui::TemporaryWidget)
|
|
||||||
{
|
|
||||||
ui->setupUi(this);
|
|
||||||
connect(ui->connectButton, &QPushButton::clicked, this, &TemporaryWidget::onConnect);
|
|
||||||
restoreSettings();
|
|
||||||
|
|
||||||
ui->quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
|
||||||
ui->quickWidget->setSource(QUrl("root.qml"));
|
|
||||||
|
|
||||||
connect(ui->canvasSelectCombo, SIGNAL(activated(int)),
|
|
||||||
this, SLOT(onCanvasSelected(int)));
|
|
||||||
ui->canvasSelectCombo->hide();
|
|
||||||
|
|
||||||
QAction* saveTreeAction = new QAction("Save", this);
|
|
||||||
saveTreeAction->setShortcut(Qt::CTRL | Qt::Key_S);
|
|
||||||
connect(saveTreeAction, &QAction::triggered, this, &TemporaryWidget::onSave);
|
|
||||||
addAction(saveTreeAction);
|
|
||||||
|
|
||||||
QAction* openSnapshotAction = new QAction("Open snapshot", this);
|
|
||||||
openSnapshotAction->setShortcut(Qt::CTRL | Qt::Key_O);
|
|
||||||
connect(openSnapshotAction, &QAction::triggered, this, &TemporaryWidget::onLoadSnapshot);
|
|
||||||
addAction(openSnapshotAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
TemporaryWidget::~TemporaryWidget()
|
|
||||||
{
|
|
||||||
disconnect(&m_webSocket, &QWebSocket::disconnected, this, &TemporaryWidget::onSocketClosed);
|
|
||||||
m_webSocket.close();
|
|
||||||
delete ui;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TemporaryWidget::setNetworkAccess(QNetworkAccessManager *dl)
|
|
||||||
{
|
|
||||||
m_netAccess = dl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TemporaryWidget::onConnect()
|
|
||||||
{
|
|
||||||
QUrl queryUrl;
|
|
||||||
queryUrl.setScheme("http");
|
|
||||||
queryUrl.setHost(ui->hostName->text());
|
|
||||||
queryUrl.setPort(ui->portEdit->text().toInt());
|
|
||||||
queryUrl.setPath("/json/canvas/by-index");
|
|
||||||
queryUrl.setQuery("d=2");
|
|
||||||
|
|
||||||
QNetworkReply* reply = m_netAccess->get(QNetworkRequest(queryUrl));
|
|
||||||
connect(reply, &QNetworkReply::finished, this, &TemporaryWidget::onFinishedGetCanvasList);
|
|
||||||
|
|
||||||
ui->connectButton->setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject jsonPropNodeFindChild(QJsonObject obj, QByteArray name)
|
|
||||||
{
|
|
||||||
Q_FOREACH (QJsonValue v, obj.value("children").toArray()) {
|
|
||||||
QJsonObject vo = v.toObject();
|
|
||||||
if (vo.value("name").toString() == name) {
|
|
||||||
return vo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return QJsonObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TemporaryWidget::onFinishedGetCanvasList()
|
|
||||||
{
|
|
||||||
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
|
|
||||||
reply->deleteLater();
|
|
||||||
ui->connectButton->setEnabled(true);
|
|
||||||
|
|
||||||
if (reply->error() != QNetworkReply::NoError) {
|
|
||||||
qWarning() << "failed to get canvases";
|
|
||||||
// reset some state
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ui->connectButton->hide();
|
|
||||||
ui->canvasSelectCombo->show();
|
|
||||||
|
|
||||||
QJsonDocument json = QJsonDocument::fromJson(reply->readAll());
|
|
||||||
|
|
||||||
ui->canvasSelectCombo->clear();
|
|
||||||
QJsonArray canvasArray = json.object().value("children").toArray();
|
|
||||||
Q_FOREACH (QJsonValue canvasValue, canvasArray) {
|
|
||||||
QJsonObject canvas = canvasValue.toObject();
|
|
||||||
QString canvasName = jsonPropNodeFindChild(canvas, "name").value("value").toString();
|
|
||||||
QString propPath = canvas.value("path").toString();
|
|
||||||
ui->canvasSelectCombo->addItem(canvasName, propPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TemporaryWidget::onSave()
|
|
||||||
{
|
|
||||||
qDebug() << "should save";
|
|
||||||
if (!m_localPropertyRoot) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString path = QFileDialog::getSaveFileName(this, tr("Choose name to save"));
|
|
||||||
if (path.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile f(path);
|
|
||||||
f.open(QIODevice::ReadWrite);
|
|
||||||
|
|
||||||
{
|
|
||||||
QDataStream ds(&f);
|
|
||||||
m_localPropertyRoot->saveToStream(ds);
|
|
||||||
}
|
|
||||||
|
|
||||||
f.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TemporaryWidget::onLoadSnapshot()
|
|
||||||
{
|
|
||||||
qDebug() << "should load";
|
|
||||||
|
|
||||||
QString path = QFileDialog::getOpenFileName(this, tr("Select a saved snapshot"));
|
|
||||||
if (path.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile f(path);
|
|
||||||
f.open(QIODevice::ReadOnly);
|
|
||||||
|
|
||||||
{
|
|
||||||
QDataStream ds(&f);
|
|
||||||
m_localPropertyRoot = LocalProp::restoreFromStream(ds, nullptr);
|
|
||||||
|
|
||||||
createdRootProperty();
|
|
||||||
|
|
||||||
m_localPropertyRoot->recursiveNotifyRestored();
|
|
||||||
|
|
||||||
// this is needed for either QtQuick or QPainter drawing
|
|
||||||
ui->canvas->rootElement()->update();
|
|
||||||
|
|
||||||
// this is the widget re-draw request (QtQuick draws all the time)
|
|
||||||
ui->canvas->update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TemporaryWidget::createdRootProperty()
|
|
||||||
{
|
|
||||||
ui->canvas->setRootProperty(m_localPropertyRoot);
|
|
||||||
ui->stack->setCurrentIndex(1);
|
|
||||||
|
|
||||||
ui->canvas->rootElement()->createQuickItem(ui->quickWidget->rootObject());
|
|
||||||
|
|
||||||
m_canvasModel = new CanvasTreeModel(ui->canvas->rootElement());
|
|
||||||
ui->treeView->setModel(m_canvasModel);
|
|
||||||
|
|
||||||
m_elementModel = new ElementDataModel(this);
|
|
||||||
ui->elementData->setModel(m_elementModel);
|
|
||||||
|
|
||||||
connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, &TemporaryWidget::onTreeCurrentChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TemporaryWidget::onWebSocketConnected()
|
|
||||||
{
|
|
||||||
connect(&m_webSocket, &QWebSocket::textMessageReceived,
|
|
||||||
this, &TemporaryWidget::onTextMessageReceived);
|
|
||||||
|
|
||||||
m_localPropertyRoot = new LocalProp(nullptr, NameIndexTuple(""));
|
|
||||||
|
|
||||||
createdRootProperty();
|
|
||||||
|
|
||||||
FGQCanvasFontCache::instance()->setHost(ui->hostName->text(),
|
|
||||||
ui->portEdit->text().toInt());
|
|
||||||
FGQCanvasImageLoader::instance()->setHost(ui->hostName->text(),
|
|
||||||
ui->portEdit->text().toInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
void TemporaryWidget::onCanvasSelected(int index)
|
|
||||||
{
|
|
||||||
QString path = ui->canvasSelectCombo->itemData(index).toString();
|
|
||||||
|
|
||||||
QUrl wsUrl;
|
|
||||||
wsUrl.setScheme("ws");
|
|
||||||
wsUrl.setHost(ui->hostName->text());
|
|
||||||
wsUrl.setPort(ui->portEdit->text().toInt());
|
|
||||||
wsUrl.setPath("/PropertyTreeMirror" + path);
|
|
||||||
m_rootPropertyPath = path.toUtf8();
|
|
||||||
|
|
||||||
connect(&m_webSocket, &QWebSocket::connected, this, &TemporaryWidget::onWebSocketConnected);
|
|
||||||
connect(&m_webSocket, &QWebSocket::disconnected, this, &TemporaryWidget::onSocketClosed);
|
|
||||||
|
|
||||||
saveSettings();
|
|
||||||
|
|
||||||
qDebug() << "starting connection to:" << wsUrl;
|
|
||||||
m_webSocket.open(wsUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TemporaryWidget::onTextMessageReceived(QString message)
|
|
||||||
{
|
|
||||||
QJsonDocument json = QJsonDocument::fromJson(message.toUtf8());
|
|
||||||
if (json.isObject()) {
|
|
||||||
// process new nodes
|
|
||||||
QJsonArray created = json.object().value("created").toArray();
|
|
||||||
Q_FOREACH (QJsonValue v, created) {
|
|
||||||
QJsonObject newProp = v.toObject();
|
|
||||||
|
|
||||||
QByteArray nodePath = newProp.value("path").toString().toUtf8();
|
|
||||||
if (nodePath.indexOf(m_rootPropertyPath) != 0) {
|
|
||||||
qWarning() << "not a property path we are mirroring:" << nodePath;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray localPath = nodePath.mid(m_rootPropertyPath.size() + 1);
|
|
||||||
LocalProp* newNode = propertyFromPath(localPath);
|
|
||||||
newNode->setPosition(newProp.value("position").toInt());
|
|
||||||
// store in the global dict
|
|
||||||
unsigned int propId = newProp.value("id").toInt();
|
|
||||||
if (idPropertyDict.contains(propId)) {
|
|
||||||
qWarning() << "duplicate add of:" << nodePath << "old is" << idPropertyDict.value(propId)->path();
|
|
||||||
} else {
|
|
||||||
idPropertyDict.insert(propId, newNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set initial value
|
|
||||||
newNode->processChange(newProp.value("value"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// process removes
|
|
||||||
QJsonArray removed = json.object().value("removed").toArray();
|
|
||||||
Q_FOREACH (QJsonValue v, removed) {
|
|
||||||
unsigned int propId = v.toInt();
|
|
||||||
if (idPropertyDict.contains(propId)) {
|
|
||||||
LocalProp* prop = idPropertyDict.value(propId);
|
|
||||||
idPropertyDict.remove(propId);
|
|
||||||
prop->parent()->removeChild(prop);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// process changes
|
|
||||||
QJsonArray changed = json.object().value("changed").toArray();
|
|
||||||
|
|
||||||
Q_FOREACH (QJsonValue v, changed) {
|
|
||||||
QJsonArray change = v.toArray();
|
|
||||||
if (change.size() != 2) {
|
|
||||||
qWarning() << "malformed change notification";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int propId = change.at(0).toInt();
|
|
||||||
if (!idPropertyDict.contains(propId)) {
|
|
||||||
qWarning() << "ignoring unknown prop ID " << propId;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalProp* lp = idPropertyDict.value(propId);
|
|
||||||
lp->processChange(change.at(1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ui->canvas->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TemporaryWidget::onSocketClosed()
|
|
||||||
{
|
|
||||||
qDebug() << "saw web-socket closed";
|
|
||||||
delete m_localPropertyRoot;
|
|
||||||
m_localPropertyRoot = nullptr;
|
|
||||||
idPropertyDict.clear();
|
|
||||||
|
|
||||||
ui->stack->setCurrentIndex(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TemporaryWidget::onTreeCurrentChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
|
||||||
{
|
|
||||||
FGCanvasElement* prev = m_canvasModel->elementFromIndex(previous);
|
|
||||||
if (prev) {
|
|
||||||
prev->setHighlighted(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
FGCanvasElement* e = m_canvasModel->elementFromIndex(current);
|
|
||||||
m_elementModel->setElement(e);
|
|
||||||
if (e) {
|
|
||||||
e->setHighlighted(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TemporaryWidget::saveSettings()
|
|
||||||
{
|
|
||||||
QSettings settings;
|
|
||||||
settings.setValue("ws-host", ui->hostName->text());
|
|
||||||
settings.setValue("ws-port", ui->portEdit->text());
|
|
||||||
//settings.setValue("prop-path", ui->propertyPath->text());
|
|
||||||
}
|
|
||||||
|
|
||||||
void TemporaryWidget::restoreSettings()
|
|
||||||
{
|
|
||||||
QSettings settings;
|
|
||||||
ui->hostName->setText(settings.value("ws-host").toString());
|
|
||||||
ui->portEdit->setText(settings.value("ws-port").toString());
|
|
||||||
// ui->propertyPath->setText(settings.value("prop-path").toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalProp *TemporaryWidget::propertyFromPath(QByteArray path) const
|
|
||||||
{
|
|
||||||
return m_localPropertyRoot->getOrCreateWithPath(path);
|
|
||||||
}
|
|
|
@ -1,77 +0,0 @@
|
||||||
//
|
|
||||||
// Copyright (C) 2017 James Turner zakalawe@mac.com
|
|
||||||
//
|
|
||||||
// This program is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation; either version 2 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful, but
|
|
||||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
|
|
||||||
#ifndef TEMPORARYWIDGET_H
|
|
||||||
#define TEMPORARYWIDGET_H
|
|
||||||
|
|
||||||
#include <QWidget>
|
|
||||||
#include <QtWebSockets/QWebSocket>
|
|
||||||
#include <QAction>
|
|
||||||
|
|
||||||
namespace Ui {
|
|
||||||
class TemporaryWidget;
|
|
||||||
}
|
|
||||||
|
|
||||||
class LocalProp;
|
|
||||||
class CanvasTreeModel;
|
|
||||||
class ElementDataModel;
|
|
||||||
class QNetworkAccessManager;
|
|
||||||
|
|
||||||
class TemporaryWidget : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit TemporaryWidget(QWidget *parent = 0);
|
|
||||||
~TemporaryWidget();
|
|
||||||
|
|
||||||
void setNetworkAccess(QNetworkAccessManager* dl);
|
|
||||||
private Q_SLOTS:
|
|
||||||
void onConnect();
|
|
||||||
|
|
||||||
void onWebSocketConnected();
|
|
||||||
void onTextMessageReceived(QString message);
|
|
||||||
|
|
||||||
void onSocketClosed();
|
|
||||||
|
|
||||||
void onTreeCurrentChanged(const QModelIndex &previous, const QModelIndex ¤t);
|
|
||||||
void onCanvasSelected(int index);
|
|
||||||
|
|
||||||
void onFinishedGetCanvasList();
|
|
||||||
|
|
||||||
void onSave();
|
|
||||||
void onLoadSnapshot();
|
|
||||||
private:
|
|
||||||
void saveSettings();
|
|
||||||
void restoreSettings();
|
|
||||||
|
|
||||||
LocalProp* propertyFromPath(QByteArray path) const;
|
|
||||||
|
|
||||||
void createdRootProperty();
|
|
||||||
|
|
||||||
QNetworkAccessManager* m_netAccess;
|
|
||||||
QWebSocket m_webSocket;
|
|
||||||
Ui::TemporaryWidget *ui;
|
|
||||||
QByteArray m_rootPropertyPath;
|
|
||||||
|
|
||||||
LocalProp* m_localPropertyRoot = nullptr;
|
|
||||||
QHash<int, LocalProp*> idPropertyDict;
|
|
||||||
CanvasTreeModel* m_canvasModel;
|
|
||||||
ElementDataModel* m_elementModel;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // TEMPORARYWIDGET_H
|
|
|
@ -1,139 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>TemporaryWidget</class>
|
|
||||||
<widget class="QWidget" name="TemporaryWidget">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>983</width>
|
|
||||||
<height>864</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle">
|
|
||||||
<string>TemporaryWidget</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QTabWidget" name="stack">
|
|
||||||
<property name="currentIndex">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<widget class="QWidget" name="stackPage1">
|
|
||||||
<attribute name="title">
|
|
||||||
<string>Connect</string>
|
|
||||||
</attribute>
|
|
||||||
<layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0,0,1" columnstretch="1,0">
|
|
||||||
<item row="5" column="0" colspan="2">
|
|
||||||
<widget class="QWidget" name="widget" native="true">
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>10</width>
|
|
||||||
<height>100</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
|
||||||
<property name="leftMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="topMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
|
||||||
<widget class="QSplitter" name="splitter">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<widget class="QTreeView" name="treeView"/>
|
|
||||||
<widget class="QTableView" name="elementData"/>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QLabel" name="label">
|
|
||||||
<property name="text">
|
|
||||||
<string>Enter FlightGear host-name and port</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QLineEdit" name="portEdit"/>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLineEdit" name="hostName"/>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="0">
|
|
||||||
<widget class="QLabel" name="selectCanvasLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Select canvas:</string>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QPushButton" name="connectButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>Connect</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="1">
|
|
||||||
<widget class="QComboBox" name="canvasSelectCombo"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<widget class="QWidget" name="stackPage2">
|
|
||||||
<attribute name="title">
|
|
||||||
<string>Canvas</string>
|
|
||||||
</attribute>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
|
||||||
<item>
|
|
||||||
<widget class="FGCanvasWidget" name="canvas" native="true"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<widget class="QWidget" name="tab">
|
|
||||||
<attribute name="title">
|
|
||||||
<string>Quick</string>
|
|
||||||
</attribute>
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QQuickWidget" name="quickWidget">
|
|
||||||
<property name="resizeMode">
|
|
||||||
<enum>QQuickWidget::SizeRootObjectToView</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>QQuickWidget</class>
|
|
||||||
<extends>QWidget</extends>
|
|
||||||
<header>QtQuickWidgets/QQuickWidget</header>
|
|
||||||
</customwidget>
|
|
||||||
<customwidget>
|
|
||||||
<class>FGCanvasWidget</class>
|
|
||||||
<extends>QWidget</extends>
|
|
||||||
<header>fgcanvaswidget.h</header>
|
|
||||||
<container>1</container>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<resources/>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
Loading…
Add table
Reference in a new issue