aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKnud Dollereder <knud.dollereder@qt.io>2020-06-09 14:36:40 +0200
committerKnud Dollereder <knud.dollereder@qt.io>2020-06-15 09:35:57 +0000
commitaf9665f7850bc679a9ffbf65b6f25615a6176ab4 (patch)
treed5a17b8b8ebe3bd44dd5a82fce9e92251989f713
parentdb3b60d780ce2d5181837dbcb4ac4626fb23feea (diff)
Fix issues related to curve locking and pinning
- Prevent insertion of keyframes in locked curves. (QDS-2172 means locking, not pinning) - Unselect keyframes when the curve moves into locking state. - Make sure that locked curves are always at the bottom of the z-stack otherwise they might prevent non-locked keyframes from being selected. - Use the selection color as background for the whole row of a treeview-item if it was selected. - Always paint the locked/pinned/unlocked/unpinned icons in the treeview. - Fix wrong mouse-hit-test for the locked/pinned icon hover events. The delegate was sometimes wrongly assuming that the mouse is hovering over a certain icon Task-number: QDS-2172 Change-Id: I6caab3f9e8e61e0dc2738eca113d5e1eec420957 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/curveeditor.qrc2
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/curveeditorstyle.h2
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp3
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.cpp33
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.h6
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp11
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/selectableitem.cpp7
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/treeitemdelegate.cpp113
8 files changed, 104 insertions, 73 deletions
diff --git a/src/plugins/qmldesigner/components/curveeditor/curveeditor.qrc b/src/plugins/qmldesigner/components/curveeditor/curveeditor.qrc
index 2f55372260..606b764936 100644
--- a/src/plugins/qmldesigner/components/curveeditor/curveeditor.qrc
+++ b/src/plugins/qmldesigner/components/curveeditor/curveeditor.qrc
@@ -12,9 +12,9 @@
<file>images/treeview_pin@2x.png</file>
<file>images/treeview_unpin.png</file>
<file>images/treeview_unpin@2x.png</file>
- <file>images/treeview_unlock@2x.png</file>
<file>images/treeview_lock.png</file>
<file>images/treeview_lock@2x.png</file>
<file>images/treeview_unlock.png</file>
+ <file>images/treeview_unlock@2x.png</file>
</qresource>
</RCC>
diff --git a/src/plugins/qmldesigner/components/curveeditor/curveeditorstyle.h b/src/plugins/qmldesigner/components/curveeditor/curveeditorstyle.h
index 038f3a3d0b..54653d3886 100644
--- a/src/plugins/qmldesigner/components/curveeditor/curveeditorstyle.h
+++ b/src/plugins/qmldesigner/components/curveeditor/curveeditorstyle.h
@@ -109,6 +109,8 @@ struct CurveEditorStyle
QBrush backgroundBrush = QBrush(QColor(5, 0, 100));
QBrush backgroundAlternateBrush = QBrush(QColor(0, 0, 50));
QColor fontColor = QColor(200, 200, 200);
+ QColor iconColor = QColor(128, 128, 128);
+ QColor iconHoverColor = QColor(170, 170, 170);
QColor gridColor = QColor(128, 128, 128);
double canvasMargin = 5.0;
int zoomInWidth = 100;
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp
index e9f994214e..9f5ed0b7af 100644
--- a/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp
+++ b/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp
@@ -413,6 +413,9 @@ void CurveItem::connect(GraphicsScene *scene)
void CurveItem::insertKeyframeByTime(double time)
{
+ if (locked())
+ return;
+
AnimationCurve acurve = curve();
acurve.insert(time);
setCurve(acurve);
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.cpp
index 0d516a0ce5..f0a9629528 100644
--- a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.cpp
+++ b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.cpp
@@ -213,7 +213,29 @@ void GraphicsScene::addCurveItem(CurveItem *item)
item->setDirty(false);
item->connect(this);
addItem(item);
- m_curves.push_back(item);
+
+ if (item->locked())
+ m_curves.push_front(item);
+ else
+ m_curves.push_back(item);
+
+ resetZValues();
+}
+
+void GraphicsScene::moveToBottom(CurveItem *item)
+{
+ if (m_curves.removeAll(item) > 0) {
+ m_curves.push_front(item);
+ resetZValues();
+ }
+}
+
+void GraphicsScene::moveToTop(CurveItem *item)
+{
+ if (m_curves.removeAll(item) > 0) {
+ m_curves.push_back(item);
+ resetZValues();
+ }
}
void GraphicsScene::setComponentTransform(const QTransform &transform)
@@ -384,4 +406,13 @@ QRectF GraphicsScene::limits() const
return m_limits;
}
+void GraphicsScene::resetZValues()
+{
+ qreal z = 0.0;
+ for (auto *curve : curves()) {
+ curve->setZValue(z);
+ z += 1.0;
+ }
+}
+
} // End namespace DesignTools.
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.h b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.h
index 3ee50672ba..15433909a0 100644
--- a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.h
+++ b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.h
@@ -91,6 +91,10 @@ public:
void addCurveItem(CurveItem *item);
+ void moveToBottom(CurveItem *item);
+
+ void moveToTop(CurveItem *item);
+
void setComponentTransform(const QTransform &transform);
void keyframeMoved(KeyframeItem *item, const QPointF &direction);
@@ -119,6 +123,8 @@ private:
QRectF limits() const;
+ void resetZValues();
+
QVector<CurveItem *> m_curves;
mutable bool m_dirty;
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp
index e06b140e1a..4fe3ed20d8 100644
--- a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp
+++ b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp
@@ -175,8 +175,15 @@ void GraphicsView::setStyle(const CurveEditorStyle &style)
void GraphicsView::setLocked(PropertyTreeItem *item)
{
- if (CurveItem *curve = m_scene->findCurve(item->id()))
- curve->setLocked(item->locked());
+ if (CurveItem *curve = m_scene->findCurve(item->id())) {
+ if (item->locked()) {
+ curve->setLocked(true);
+ m_scene->moveToBottom(curve);
+ } else {
+ curve->setLocked(false);
+ m_scene->moveToTop(curve);
+ }
+ }
}
void GraphicsView::setZoomX(double zoom, const QPoint &pivot)
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/selectableitem.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/selectableitem.cpp
index 40500427b0..5db5d0c14b 100644
--- a/src/plugins/qmldesigner/components/curveeditor/detail/selectableitem.cpp
+++ b/src/plugins/qmldesigner/components/curveeditor/detail/selectableitem.cpp
@@ -98,6 +98,7 @@ void SelectableItem::lockedCallback()
{
m_preSelected = SelectionMode::Undefined;
m_selected = false;
+ m_active = false;
selectionCallback();
}
@@ -128,11 +129,17 @@ bool SelectableItem::selected() const
void SelectableItem::setActivated(bool active)
{
+ if (locked())
+ return;
+
m_active = active;
}
void SelectableItem::setSelected(bool selected)
{
+ if (locked())
+ return;
+
m_selected = selected;
}
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/treeitemdelegate.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/treeitemdelegate.cpp
index 21633ddce1..2f6a941a20 100644
--- a/src/plugins/qmldesigner/components/curveeditor/detail/treeitemdelegate.cpp
+++ b/src/plugins/qmldesigner/components/curveeditor/detail/treeitemdelegate.cpp
@@ -25,6 +25,7 @@
#include "treeitemdelegate.h"
#include "treeitem.h"
+#include <QApplication>
#include <QEvent>
#include <QMouseEvent>
#include <QPainter>
@@ -41,87 +42,61 @@ QSize TreeItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QMode
return QStyledItemDelegate::sizeHint(option, index);
}
+QRect makeSquare(const QRect &rect)
+{
+ int size = rect.width() > rect.height() ? rect.height() : rect.width();
+ QRect r(QPoint(0, 0), QSize(size, size));
+ r.moveCenter(rect.center());
+ return r;
+}
+
+QPixmap pixmapFromStyle(int column, const CurveEditorStyle &style, const QRect &rect, TreeItem *item, bool underMouse)
+{
+ QColor color = underMouse ? style.iconHoverColor : style.iconColor;
+ if (column == 1) {
+ bool locked = item->locked();
+ if (underMouse)
+ locked = !locked;
+
+ if (locked)
+ return pixmapFromIcon(style.treeItemStyle.lockedIcon, rect.size(), color);
+ else
+ return pixmapFromIcon(style.treeItemStyle.unlockedIcon, rect.size(), color);
+ }
+
+ bool pinned = item->pinned();
+ if (underMouse)
+ pinned = !pinned;
+
+ if (pinned)
+ return pixmapFromIcon(style.treeItemStyle.pinnedIcon, rect.size(), color);
+ else
+ return pixmapFromIcon(style.treeItemStyle.unpinnedIcon, rect.size(), color);
+}
+
void TreeItemDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
if (index.column() == 1 || index.column() == 2) {
-
- int height = option.rect.size().height();
- QRect iconRect(QPoint(0, 0), QSize(height, height));
- iconRect.moveCenter(option.rect.center());
+ QStyleOptionViewItem opt = option;
+ initStyleOption(&opt, index);
auto *treeItem = static_cast<TreeItem *>(index.internalPointer());
- if (option.state & QStyle::State_MouseOver && iconRect.contains(m_mousePos)) {
-
- painter->fillRect(option.rect, option.backgroundBrush);
-
- if (index.column() == 1) {
-
- if (treeItem->locked()) {
-
- QPixmap pixmap = pixmapFromIcon(
- m_style.treeItemStyle.unlockedIcon,
- iconRect.size(),
- m_style.fontColor);
-
- painter->drawPixmap(iconRect, pixmap);
-
- } else {
-
- QPixmap pixmap = pixmapFromIcon(
- m_style.treeItemStyle.lockedIcon,
- iconRect.size(),
- m_style.fontColor);
-
- painter->drawPixmap(iconRect, pixmap);
- }
-
- } else if (index.column() == 2) {
-
- if (treeItem->pinned()) {
-
- QPixmap pixmap = pixmapFromIcon(
- m_style.treeItemStyle.unpinnedIcon,
- iconRect.size(),
- m_style.fontColor);
-
- painter->drawPixmap(iconRect, pixmap);
-
- } else {
-
- QPixmap pixmap = pixmapFromIcon(
- m_style.treeItemStyle.pinnedIcon,
- iconRect.size(),
- m_style.fontColor);
-
- painter->drawPixmap(iconRect, pixmap);
-
- }
- }
-
- } else {
-
- if (treeItem->locked() && index.column() == 1) {
-
- QPixmap pixmap = pixmapFromIcon(
- m_style.treeItemStyle.lockedIcon,
- iconRect.size(),
- m_style.fontColor);
- painter->drawPixmap(iconRect, pixmap);
+ QPoint mousePos = QCursor::pos();
+ mousePos = option.widget->mapFromGlobal(mousePos);
- } else if (treeItem->pinned() && index.column() == 2) {
+ QRect iconRect = makeSquare(option.rect);
+ bool underMouse = option.rect.contains(m_mousePos)
+ && option.state & QStyle::State_MouseOver;
- QPixmap pixmap = pixmapFromIcon(
- m_style.treeItemStyle.pinnedIcon,
- iconRect.size(),
- m_style.fontColor);
+ QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
+ style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
- painter->drawPixmap(iconRect, pixmap);
+ QPixmap pixmap = pixmapFromStyle(index.column(), m_style, iconRect, treeItem, underMouse);
+ painter->drawPixmap(iconRect, pixmap);
- }
- }
} else {
QStyledItemDelegate::paint(painter, option, index);
}