Fix canvas sizing + scaling
This commit is contained in:
parent
4bae38f994
commit
623305965b
7 changed files with 43 additions and 43 deletions
|
@ -81,8 +81,7 @@ bool CanvasConnection::restoreState(QJsonObject state)
|
||||||
m_destRect = QRectF(rect[0].toDouble(), rect[1].toDouble(),
|
m_destRect = QRectF(rect[0].toDouble(), rect[1].toDouble(),
|
||||||
rect[2].toDouble(), rect[3].toDouble());
|
rect[2].toDouble(), rect[3].toDouble());
|
||||||
|
|
||||||
emit sizeChanged(m_destRect.size());
|
emit geometryChanged();
|
||||||
emit centerChanged(m_destRect.center());
|
|
||||||
emit rootPathChanged();
|
emit rootPathChanged();
|
||||||
emit webSocketUrlChanged();
|
emit webSocketUrlChanged();
|
||||||
|
|
||||||
|
@ -100,13 +99,13 @@ void CanvasConnection::showDebugTree()
|
||||||
qWarning() << Q_FUNC_INFO << "implement me!";
|
qWarning() << Q_FUNC_INFO << "implement me!";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CanvasConnection::setCenter(QPointF c)
|
void CanvasConnection::setOrigin(QPointF c)
|
||||||
{
|
{
|
||||||
if (center() == c)
|
if (m_destRect.topLeft() == c)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_destRect.moveCenter(c);
|
m_destRect.moveTopLeft(c);
|
||||||
emit centerChanged(c);
|
emit geometryChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CanvasConnection::setSize(QSizeF sz)
|
void CanvasConnection::setSize(QSizeF sz)
|
||||||
|
@ -115,7 +114,7 @@ void CanvasConnection::setSize(QSizeF sz)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_destRect.setSize(sz);
|
m_destRect.setSize(sz);
|
||||||
emit sizeChanged(sz);
|
emit geometryChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CanvasConnection::connectWebSocket(QByteArray hostName, int port)
|
void CanvasConnection::connectWebSocket(QByteArray hostName, int port)
|
||||||
|
@ -133,9 +132,9 @@ void CanvasConnection::connectWebSocket(QByteArray hostName, int port)
|
||||||
setStatus(Connecting);
|
setStatus(Connecting);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF CanvasConnection::center() const
|
QPointF CanvasConnection::origin() const
|
||||||
{
|
{
|
||||||
return m_destRect.center();
|
return m_destRect.topLeft();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSizeF CanvasConnection::size() const
|
QSizeF CanvasConnection::size() const
|
||||||
|
|
|
@ -40,8 +40,8 @@ class CanvasConnection : public QObject
|
||||||
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
|
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
|
||||||
|
|
||||||
// QML exposed versions of the destination rect
|
// QML exposed versions of the destination rect
|
||||||
Q_PROPERTY(QPointF center READ center WRITE setCenter NOTIFY centerChanged)
|
Q_PROPERTY(QPointF origin READ origin WRITE setOrigin NOTIFY geometryChanged)
|
||||||
Q_PROPERTY(QSizeF size READ size WRITE setSize NOTIFY sizeChanged)
|
Q_PROPERTY(QSizeF size READ size WRITE setSize NOTIFY geometryChanged)
|
||||||
|
|
||||||
Q_PROPERTY(QUrl webSocketUrl READ webSocketUrl NOTIFY webSocketUrlChanged)
|
Q_PROPERTY(QUrl webSocketUrl READ webSocketUrl NOTIFY webSocketUrlChanged)
|
||||||
Q_PROPERTY(QString rootPath READ rootPath NOTIFY rootPathChanged)
|
Q_PROPERTY(QString rootPath READ rootPath NOTIFY rootPathChanged)
|
||||||
|
@ -71,7 +71,7 @@ public:
|
||||||
bool restoreState(QJsonObject state);
|
bool restoreState(QJsonObject state);
|
||||||
|
|
||||||
void connectWebSocket(QByteArray hostName, int port);
|
void connectWebSocket(QByteArray hostName, int port);
|
||||||
QPointF center() const;
|
QPointF origin() const;
|
||||||
|
|
||||||
QSizeF size() const;
|
QSizeF size() const;
|
||||||
|
|
||||||
|
@ -97,16 +97,14 @@ public Q_SLOTS:
|
||||||
// not on iOS / Android - requires widgets
|
// not on iOS / Android - requires widgets
|
||||||
void showDebugTree();
|
void showDebugTree();
|
||||||
|
|
||||||
void setCenter(QPointF center);
|
void setOrigin(QPointF center);
|
||||||
|
|
||||||
void setSize(QSizeF size);
|
void setSize(QSizeF size);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void statusChanged(Status status);
|
void statusChanged(Status status);
|
||||||
|
|
||||||
void centerChanged(QPointF center);
|
void geometryChanged();
|
||||||
|
|
||||||
void sizeChanged(QSizeF size);
|
|
||||||
|
|
||||||
void rootPathChanged();
|
void rootPathChanged();
|
||||||
|
|
||||||
|
|
|
@ -123,16 +123,12 @@ void CanvasDisplay::onCanvasSizeChanged()
|
||||||
{
|
{
|
||||||
m_sourceSize = QSizeF(m_connection->propertyRoot()->value("size", 400).toDouble(),
|
m_sourceSize = QSizeF(m_connection->propertyRoot()->value("size", 400).toDouble(),
|
||||||
m_connection->propertyRoot()->value("size[1]", 400).toDouble());
|
m_connection->propertyRoot()->value("size[1]", 400).toDouble());
|
||||||
|
|
||||||
recomputeScaling();
|
recomputeScaling();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CanvasDisplay::recomputeScaling()
|
void CanvasDisplay::recomputeScaling()
|
||||||
{
|
{
|
||||||
double xScaleFactor = width() / m_sourceSize.width();
|
const double xScaleFactor = width() / m_sourceSize.width();
|
||||||
double yScaleFactor = height() / m_sourceSize.height();
|
const double yScaleFactor = height() / m_sourceSize.height();
|
||||||
|
setScale(std::min(xScaleFactor, yScaleFactor));
|
||||||
double finalScaleFactor = std::min(xScaleFactor, yScaleFactor);
|
|
||||||
|
|
||||||
setScale(finalScaleFactor);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,8 +93,7 @@ void FGCanvasGroup::doPolish()
|
||||||
if (_zIndicesDirty) {
|
if (_zIndicesDirty) {
|
||||||
std::sort(_children.begin(), _children.end(), ChildOrderingFunction());
|
std::sort(_children.begin(), _children.end(), ChildOrderingFunction());
|
||||||
_zIndicesDirty = false;
|
_zIndicesDirty = false;
|
||||||
|
resetChildQuickItemZValues();
|
||||||
qWarning() << Q_FUNC_INFO << "adjust z order of quick items";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FGCanvasElement* element : _children) {
|
for (FGCanvasElement* element : _children) {
|
||||||
|
@ -102,9 +101,20 @@ void FGCanvasGroup::doPolish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FGCanvasGroup::resetChildQuickItemZValues()
|
||||||
|
{
|
||||||
|
int counter = 0;
|
||||||
|
for (auto e : _children) {
|
||||||
|
auto qq = e->quickItem();
|
||||||
|
if (qq) {
|
||||||
|
qq->setZ(counter++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool FGCanvasGroup::onChildAdded(LocalProp *prop)
|
bool FGCanvasGroup::onChildAdded(LocalProp *prop)
|
||||||
{
|
{
|
||||||
const bool isRootGroup = (parent() == nullptr);
|
const bool isRootGroup = (_parent == nullptr);
|
||||||
int newChildCount = 0;
|
int newChildCount = 0;
|
||||||
|
|
||||||
if (FGCanvasElement::onChildAdded(prop)) {
|
if (FGCanvasElement::onChildAdded(prop)) {
|
||||||
|
|
|
@ -42,6 +42,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
void markCachedSymbolDirty();
|
void markCachedSymbolDirty();
|
||||||
int indexOfChildWithProp(LocalProp *prop) const;
|
int indexOfChildWithProp(LocalProp *prop) const;
|
||||||
|
void resetChildQuickItemZValues();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable FGCanvasElementVec _children;
|
mutable FGCanvasElementVec _children;
|
||||||
|
|
|
@ -37,7 +37,7 @@ FGQCanvasImage::FGQCanvasImage(FGCanvasGroup* pr, LocalProp* prop) :
|
||||||
|
|
||||||
void FGQCanvasImage::setEngine(QQmlEngine *engine)
|
void FGQCanvasImage::setEngine(QQmlEngine *engine)
|
||||||
{
|
{
|
||||||
static_imageComponent = new QQmlComponent(engine, QUrl("image.qml"));
|
static_imageComponent = new QQmlComponent(engine, QUrl("qrc:///qml/image.qml"));
|
||||||
if (!static_imageComponent || !static_imageComponent->errors().empty()) {
|
if (!static_imageComponent || !static_imageComponent->errors().empty()) {
|
||||||
qWarning() << static_imageComponent->errorString();
|
qWarning() << static_imageComponent->errorString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,23 +6,21 @@ Item {
|
||||||
property bool showDecorations: true
|
property bool showDecorations: true
|
||||||
property alias canvas: canvasDisplay.canvas
|
property alias canvas: canvasDisplay.canvas
|
||||||
|
|
||||||
readonly property var centerPoint: Qt.point(width / 2, height / 2)
|
//clip: true;
|
||||||
|
|
||||||
clip: true;
|
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
if (canvas) {
|
if (canvas) {
|
||||||
width = canvas.size.width
|
width = canvas.size.width
|
||||||
height = canvas.size.height
|
height = canvas.size.height
|
||||||
x = canvas.center.x - (width / 2)
|
x = canvas.origin.x
|
||||||
y = canvas.center.y - (height / 2)
|
y = canvas.origin.y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveGeometry()
|
function saveGeometry()
|
||||||
{
|
{
|
||||||
canvas.center = Qt.point(x + (width / 2), y + (height / 2))
|
canvas.origin = Qt.point(x, y )
|
||||||
canvas.size = Qt.size(root.width / 2, root.height / 2);
|
canvas.size = Qt.size(root.width, root.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
FG.CanvasDisplay {
|
FG.CanvasDisplay {
|
||||||
|
@ -33,9 +31,8 @@ Item {
|
||||||
if (canvas) {
|
if (canvas) {
|
||||||
root.width = canvas.size.width
|
root.width = canvas.size.width
|
||||||
root.height = canvas.size.height
|
root.height = canvas.size.height
|
||||||
|
root.x = canvas.origin.x
|
||||||
root.x = canvas.center.x - (root.width / 2)
|
root.y = canvas.origin.y
|
||||||
root.y = canvas.center.y - (root.height / 2)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,13 +70,11 @@ Item {
|
||||||
|
|
||||||
onPositionChanged: {
|
onPositionChanged: {
|
||||||
var rootPos = mapToItem(root, mouse.x, mouse.y);
|
var rootPos = mapToItem(root, mouse.x, mouse.y);
|
||||||
var rootDiff = Qt.point(rootPos.x - root.centerPoint.x,
|
// var rootDiff = Qt.point(rootPos.x - root.x,
|
||||||
rootPos.y - root.centerPoint.y);
|
// rootPos.y - root.y);
|
||||||
|
|
||||||
root.width = rootDiff.x * 2;
|
root.width = rootPos.x;
|
||||||
root.height = rootDiff.y * 2;
|
root.height = rootPos.y;
|
||||||
root.x = canvas.center.x - (root.width / 2)
|
|
||||||
root.y = canvas.center.y - (root.height / 2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onReleased: {
|
onReleased: {
|
||||||
|
@ -104,6 +99,7 @@ Item {
|
||||||
case FG.CanvasConnection.NotConnected: return "Not connected";
|
case FG.CanvasConnection.NotConnected: return "Not connected";
|
||||||
case FG.CanvasConnection.Connecting: return "Connecting";
|
case FG.CanvasConnection.Connecting: return "Connecting";
|
||||||
case FG.CanvasConnection.Connected: return "Connected";
|
case FG.CanvasConnection.Connected: return "Connected";
|
||||||
|
case FG.CanvasConnection.Closed: return "Closed";
|
||||||
case FG.CanvasConnection.Reconnecting: return "Re-connecting";
|
case FG.CanvasConnection.Reconnecting: return "Re-connecting";
|
||||||
case FG.CanvasConnection.Error: return "Error";
|
case FG.CanvasConnection.Error: return "Error";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue