forked from qt-creator/qt-creator
QmlDesigner: Fix Components lib wrong scrolling after drag-n-drop
Change-Id: Ibd3f3c155496443eac0accf468280a15cad51351 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -235,7 +235,7 @@ Item {
|
||||
id: verticalScrollView
|
||||
anchors.fill: parent
|
||||
clip: true
|
||||
interactive: !itemContextMenu.opened && !moduleContextMenu.opened
|
||||
interactive: !itemContextMenu.opened && !moduleContextMenu.opened && !rootView.isDragging
|
||||
|
||||
onContentHeightChanged: {
|
||||
var maxPosition = Math.max(contentHeight - verticalScrollView.height, 0)
|
||||
@@ -352,7 +352,7 @@ Item {
|
||||
width: 270
|
||||
height: parent.height
|
||||
clip: true
|
||||
interactive: !itemContextMenu.opened && !moduleContextMenu.opened
|
||||
interactive: !itemContextMenu.opened && !moduleContextMenu.opened && !rootView.isDragging
|
||||
|
||||
onContentHeightChanged: {
|
||||
var maxPosition = Math.max(contentHeight - horizontalScrollView.height, 0)
|
||||
@@ -457,6 +457,8 @@ Item {
|
||||
id: itemScrollView
|
||||
width: itemsView.width - 275
|
||||
height: itemsView.height
|
||||
interactive: !itemContextMenu.opened && !moduleContextMenu.opened && !rootView.isDragging
|
||||
|
||||
onContentHeightChanged: {
|
||||
var maxPosition = Math.max(contentHeight - itemScrollView.height, 0)
|
||||
if (contentY > maxPosition)
|
||||
|
||||
@@ -105,6 +105,10 @@ bool ItemLibraryWidget::eventFilter(QObject *obj, QEvent *event)
|
||||
m_itemToDrag = {};
|
||||
}
|
||||
}
|
||||
} else if (event->type() == QMouseEvent::MouseButtonRelease) {
|
||||
m_itemToDrag = {};
|
||||
|
||||
setIsDragging(false);
|
||||
}
|
||||
|
||||
return QObject::eventFilter(obj, event);
|
||||
@@ -366,12 +370,21 @@ void ItemLibraryWidget::handlePriorityImportsChanged()
|
||||
}
|
||||
}
|
||||
|
||||
void ItemLibraryWidget::setIsDragging(bool val)
|
||||
{
|
||||
if (m_isDragging != val) {
|
||||
m_isDragging = val;
|
||||
emit isDraggingChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void ItemLibraryWidget::startDragAndDrop(const QVariant &itemLibEntry, const QPointF &mousePos)
|
||||
{
|
||||
// Actual drag is created after mouse has moved to avoid a QDrag bug that causes drag to stay
|
||||
// active (and blocks mouse release) if mouse is released at the same spot of the drag start.
|
||||
m_itemToDrag = itemLibEntry;
|
||||
m_dragStartPoint = mousePos.toPoint();
|
||||
setIsDragging(true);
|
||||
}
|
||||
|
||||
bool ItemLibraryWidget::subCompEditMode() const
|
||||
|
||||
@@ -44,6 +44,9 @@ class ItemLibraryWidget : public QFrame
|
||||
public:
|
||||
Q_PROPERTY(bool subCompEditMode READ subCompEditMode NOTIFY subCompEditModeChanged)
|
||||
|
||||
// Needed for a workaround for a bug where after drag-n-dropping an item, the ScrollView scrolls to a random position
|
||||
Q_PROPERTY(bool isDragging MEMBER m_isDragging NOTIFY isDraggingChanged)
|
||||
|
||||
ItemLibraryWidget(AsynchronousImageCache &imageCache);
|
||||
~ItemLibraryWidget();
|
||||
|
||||
@@ -76,6 +79,7 @@ public:
|
||||
signals:
|
||||
void itemActivated(const QString &itemName);
|
||||
void subCompEditModeChanged();
|
||||
void isDraggingChanged();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
@@ -86,6 +90,8 @@ private:
|
||||
|
||||
void updateSearch();
|
||||
void handlePriorityImportsChanged();
|
||||
void setIsDragging(bool val);
|
||||
|
||||
static QString getDependencyImport(const Import &import);
|
||||
|
||||
QTimer m_compressionTimer;
|
||||
@@ -107,6 +113,7 @@ private:
|
||||
QString m_filterText;
|
||||
QPoint m_dragStartPoint;
|
||||
bool m_subCompEditMode = false;
|
||||
bool m_isDragging = false;
|
||||
|
||||
inline static int HORIZONTAL_LAYOUT_WIDTH_LIMIT = 600;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user