Commit 5ceb1d24 authored by DonLakeFlyer's avatar DonLakeFlyer

Fix drag visual glitches

parent 09bde0c7
......@@ -29,6 +29,8 @@ Rectangle {
property var itemCoordinate ///< Coordinate we are updating during drag
signal clicked
signal dragStart
signal dragStop
property bool _preventCoordinateBindingLoop: false
......@@ -37,6 +39,7 @@ Rectangle {
property real _touchHeight: Math.max(itemIndicator.height, ScreenTools.minTouchPixels)
property real _touchMarginHorizontal: _mobile ? (_touchWidth - itemIndicator.width) / 2 : 0
property real _touchMarginVertical: _mobile ? (_touchHeight - itemIndicator.height) / 2 : 0
property bool _dragStartSignalled: false
onXChanged: liveDrag()
onYChanged: liveDrag()
......@@ -65,13 +68,18 @@ Rectangle {
preventStealing: true
onClicked: itemDragger.clicked()
}
Item {
id: fakeItemIndicator
Item {
id: anchorPoint
property bool dragActive: drag.active
onDragActiveChanged: {
if (dragActive) {
if (!_dragStartSignalled) {
_dragStartSignalled = true
dragStart()
}
} else {
_dragStartSignalled = false
dragStop()
}
}
}
}
......@@ -22,6 +22,7 @@ QGCMapPolygon::QGCMapPolygon(QObject* newCoordParent, QObject* parent)
: QObject(parent)
, _newCoordParent(newCoordParent)
, _dirty(false)
, _centerDrag(false)
, _ignoreCenterUpdates(false)
{
connect(&_polygonModel, &QmlObjectListModel::dirtyChanged, this, &QGCMapPolygon::_polygonModelDirtyChanged);
......@@ -53,7 +54,10 @@ void QGCMapPolygon::clear(void)
void QGCMapPolygon::adjustVertex(int vertexIndex, const QGeoCoordinate coordinate)
{
_polygonPath[vertexIndex] = QVariant::fromValue(coordinate);
emit pathChanged();
if (!_centerDrag) {
// When dragging center we don't signal path changed until add vertices are updated
emit pathChanged();
}
_polygonModel.value<QGCQGeoCoordinate*>(vertexIndex)->setCoordinate(coordinate);
......@@ -278,7 +282,22 @@ void QGCMapPolygon::setCenter(QGeoCoordinate newCenter)
adjustVertex(i, newVertex);
}
if (_centerDrag) {
// When center dragging signals are delayed until all vertices are updated
emit pathChanged();
}
_ignoreCenterUpdates = false;
_updateCenter();
_center = newCenter;
emit centerChanged(newCenter);
}
}
void QGCMapPolygon::setCenterDrag(bool centerDrag)
{
if (centerDrag != _centerDrag) {
_centerDrag = centerDrag;
emit centerDragChanged(centerDrag);
}
}
......@@ -26,11 +26,12 @@ class QGCMapPolygon : public QObject
public:
QGCMapPolygon(QObject* newCoordParent, QObject* parent = NULL);
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(QVariantList path READ path NOTIFY pathChanged)
Q_PROPERTY(QmlObjectListModel* pathModel READ qmlPathModel CONSTANT)
Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged)
Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter NOTIFY centerChanged)
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(QVariantList path READ path NOTIFY pathChanged)
Q_PROPERTY(QmlObjectListModel* pathModel READ qmlPathModel CONSTANT)
Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged)
Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter NOTIFY centerChanged)
Q_PROPERTY(bool centerDrag READ centerDrag WRITE setCenterDrag NOTIFY centerDragChanged)
Q_INVOKABLE void clear(void);
Q_INVOKABLE void appendVertex(const QGeoCoordinate& coordinate);
......@@ -63,28 +64,30 @@ public:
// Property methods
int count (void) const { return _polygonPath.count(); }
bool dirty (void) const { return _dirty; }
void setDirty(bool dirty);
QGeoCoordinate center (void) const { return _center; }
int count (void) const { return _polygonPath.count(); }
bool dirty (void) const { return _dirty; }
void setDirty (bool dirty);
QGeoCoordinate center (void) const { return _center; }
bool centerDrag (void) const { return _centerDrag; }
QVariantList path (void) const { return _polygonPath; }
QmlObjectListModel* qmlPathModel(void) { return &_polygonModel; }
QmlObjectListModel& pathModel (void) { return _polygonModel; }
void setPath(const QList<QGeoCoordinate>& path);
void setPath(const QVariantList& path);
void setCenter(QGeoCoordinate newCenter);
void setPath (const QList<QGeoCoordinate>& path);
void setPath (const QVariantList& path);
void setCenter (QGeoCoordinate newCenter);
void setCenterDrag (bool centerDrag);
static const char* jsonPolygonKey;
signals:
void countChanged (int count);
void pathChanged (void);
void dirtyChanged (bool dirty);
void cleared (void);
void centerChanged (QGeoCoordinate center);
void countChanged (int count);
void pathChanged (void);
void dirtyChanged (bool dirty);
void cleared (void);
void centerChanged (QGeoCoordinate center);
void centerDragChanged (bool centerDrag);
private slots:
void _polygonModelCountChanged(int count);
......@@ -101,6 +104,7 @@ private:
QmlObjectListModel _polygonModel;
bool _dirty;
QGeoCoordinate _center;
bool _centerDrag;
bool _ignoreCenterUpdates;
};
......
......@@ -222,7 +222,9 @@ Item {
id: centerDragAreaComponent
MissionItemIndicatorDrag {
onItemCoordinateChanged: mapPolygon.center = itemCoordinate
onItemCoordinateChanged: mapPolygon.center = itemCoordinate
onDragStart: mapPolygon.centerDrag = true
onDragStop: mapPolygon.centerDrag = false
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment