summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMahmoud Badri <mahmoud.badri@qt.io>2018-06-07 11:44:51 +0300
committerMahmoud Badri <mahmoud.badri@qt.io>2018-06-07 10:09:08 +0000
commitab754c656ec67aaa3684476d438ca5e869c62219 (patch)
tree8f5b0ced6cc1643f4cf99d94df40bea1158c077f
parent103309d9c7ab10fc1b48723c2a2f4721ef91c973 (diff)
Fix some property graph expansion issues
Fixed the following 2 issues which happen when one or more property rows graphs are expanded: - selecting keyframes by selection rectangle - tree rows context menu targeting the correct row Also got rid of the correctIndex() method (and some related methods) which caused some limitations. Task-number: QT3DS-1892 Change-Id: I64b817d54da4a471c0ada8e74a13b61b44f5820f Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Kaj Grönholm <kaj.gronholm@qt.io> Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
-rw-r--r--src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.cpp29
-rw-r--r--src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.cpp55
-rw-r--r--src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.h6
-rw-r--r--src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp28
-rw-r--r--src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.h1
-rw-r--r--src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp6
-rw-r--r--src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.cpp14
-rw-r--r--src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.h6
8 files changed, 42 insertions, 103 deletions
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.cpp
index 570c3981..cab31750 100644
--- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.cpp
+++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.cpp
@@ -167,26 +167,19 @@ void KeyframeManager::selectKeyframesInRect(const QRectF &rect)
{
deselectAllKeyframes();
- int idx1 = (rect.top() + 4) / TimelineConstants::ROW_H;
- int idx2 = (rect.bottom() - 4) / TimelineConstants::ROW_H;
-
- m_scene->rowManager()->clampIndex(idx1);
- m_scene->rowManager()->clampIndex(idx2);
-
- for (int i = idx1; i <= idx2; ++i) {
- RowTimeline *rowTimeline = m_scene->rowManager()->rowTimelineAt(i);
-
- if (rowTimeline) {
- const auto keyframes = rowTimeline->getKeyframesInRange(rect.left(), rect.right());
- for (auto keyframe : keyframes) {
- if (!m_selectedKeyframes.contains(keyframe)) {
- m_selectedKeyframes.append(keyframe);
-
- if (!m_selectedKeyframesMasterRows.contains(keyframe->rowMaster))
- m_selectedKeyframesMasterRows.append(keyframe->rowMaster);
- }
+ RowTree *row = m_scene->rowManager()->getRowAtPos(QPointF(0, rect.top()));
+ while (row && row->y() < rect.bottom()) {
+ const auto keyframes = row->rowTimeline()->getKeyframesInRange(rect);
+ for (auto keyframe : keyframes) {
+ if (!m_selectedKeyframes.contains(keyframe)) {
+ m_selectedKeyframes.append(keyframe);
+
+ if (!m_selectedKeyframesMasterRows.contains(keyframe->rowMaster))
+ m_selectedKeyframesMasterRows.append(keyframe->rowMaster);
}
}
+
+ row = m_scene->rowManager()->getRowAtPos(QPointF(0, row->y() + row->size().height()));
}
for (auto keyframe : qAsConst(m_selectedKeyframes))
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.cpp
index 479fed20..026e31cc 100644
--- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.cpp
+++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.cpp
@@ -174,22 +174,16 @@ RowTree *RowManager::createRow(EStudioObjectType rowType, RowTree *parentRow, co
return nullptr;
}
-RowTree *RowManager::rowAt(int idx)
+RowTree *RowManager::getRowAtPos(const QPointF &scenePos) const
{
- correctIndex(idx);
+ QList<QGraphicsItem *> items = m_scene->items(scenePos);
- if (idx != -1)
- return static_cast<RowTree *>(m_layoutTree->itemAt(idx)->graphicsItem());
-
- return nullptr;
-}
-
-RowTimeline *RowManager::rowTimelineAt(int idx)
-{
- correctIndex(idx);
-
- if (idx != -1)
- return static_cast<RowTimeline *>(m_layoutTimeline->itemAt(idx)->graphicsItem());
+ int index = 0;
+ while (index < items.size()) {
+ QGraphicsItem *item = items.at(index++);
+ if (item->type() == TimelineItem::TypeRowTree)
+ return static_cast<RowTree *>(item);
+ }
return nullptr;
}
@@ -436,39 +430,6 @@ int RowManager::getLastChildIndex(RowTree *row, int index)
return -1;
}
-void RowManager::clampIndex(int &idx)
-{
- if (idx < 1)
- idx = 1;
- else if (idx > m_layoutTree->count() - 1)
- idx = m_layoutTree->count() - 1;
-}
-
-// Index within rows indices bounds
-bool RowManager::validIndex(int idx) const
-{
- return idx > 0 && idx < m_layoutTree->count();
-}
-
-// Adjust index to point to the correct row taking into consideration collaped rows
-void RowManager::correctIndex(int &idx)
-{
- if (!validIndex(idx)) {
- idx = -1;
- return;
- }
-
- // adjust for collapsed and filtered items (invisible)
- for (int i = 1; i <= idx; ++i) {
- if (!m_layoutTimeline->itemAt(i)->graphicsItem()->isVisible()) {
- if (++idx > m_layoutTimeline->count() - 1) {
- idx = -1;
- return;
- }
- }
- }
-}
-
void RowManager::collapseAllPropertyRows()
{
for (int i = 0; i < m_layoutTree->count(); ++i) {
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.h
index e39bafa8..21b8417e 100644
--- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.h
+++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.h
@@ -47,8 +47,6 @@ public:
RowManager(TimelineGraphicsScene *scene, QGraphicsLinearLayout *layoutLabels,
QGraphicsLinearLayout *layoutTimeline);
- void clampIndex(int &idx);
- void correctIndex(int &idx);
void selectRow(RowTree *row, bool multiSelect = false);
void setRowSelection(RowTree *row, bool selected);
void deleteRow(RowTree *row);
@@ -67,15 +65,13 @@ public:
RowTree *createRow(EStudioObjectType rowType, RowTree *parentRow = nullptr,
const QString &label = QString(), const QString &propType = QString(),
int index = -1);
- RowTree *rowAt(int idx);
+ RowTree *getRowAtPos(const QPointF &scenePos) const;
RowTree *selectedRow() const;
bool isRowSelected(RowTree *row) const;
QVector<RowTree *> selectedRows() const;
- RowTimeline *rowTimelineAt(int idx);
private:
int getLastChildIndex(RowTree *row, int index = -1);
- bool validIndex(int idx) const;
void deleteRowRecursive(RowTree *row);
void updateRowFilterRecursive(RowTree *row);
void createRowsFromBindingRecursive(ITimelineItemBinding *binding,
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp
index 44c01622..65be2cdd 100644
--- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp
+++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp
@@ -156,20 +156,6 @@ void RowMover::updateState(int depth, double y)
setVisible(true);
}
-RowTree *RowMover::getRowAtPos(const QPointF &scenePos)
-{
- QList<QGraphicsItem *> items = m_scene->items(scenePos);
-
- int index = 0;
- while (index < items.size()) {
- QGraphicsItem *item = items.at(index++);
- if (item->type() == TimelineItem::TypeRowTree)
- return static_cast<RowTree *>(item);
- }
-
- return nullptr;
-}
-
bool RowMover::isNextSiblingRow(RowTree *rowMain, RowTree *rowSibling) const
{
// order matters, rowSibling is below rowMain
@@ -208,8 +194,10 @@ void RowMover::updateTargetRow(const QPointF &scenePos, EStudioObjectType rowTyp
theRowType = m_sourceRows[0]->rowType();
// row will be inserted just below rowInsert1 and just above rowInsert2 (if it exists)
- RowTree *rowInsert1 = getRowAtPos(scenePos + QPointF(0, TimelineConstants::ROW_H * -.5));
- RowTree *rowInsert2 = getRowAtPos(scenePos + QPointF(0, TimelineConstants::ROW_H * .5));
+ RowTree *rowInsert1 = m_scene->rowManager()
+ ->getRowAtPos(scenePos + QPointF(0, TimelineConstants::ROW_H * -.5));
+ RowTree *rowInsert2 = m_scene->rowManager()
+ ->getRowAtPos(scenePos + QPointF(0, TimelineConstants::ROW_H * .5));
bool valid = rowInsert1 && theRowType != OBJTYPE_MATERIAL
&& theRowType != OBJTYPE_CUSTOMMATERIAL;
@@ -219,10 +207,12 @@ void RowMover::updateTargetRow(const QPointF &scenePos, EStudioObjectType rowTyp
// after the property
if (rowInsert1->isProperty()) {
rowInsert1 = rowInsert1->parentRow()->childProps().last();
- rowInsert2 = getRowAtPos(QPointF(0, rowInsert1->y() + TimelineConstants::ROW_H));
+ rowInsert2 = m_scene->rowManager()
+ ->getRowAtPos(QPointF(0, rowInsert1->y() + TimelineConstants::ROW_H));
} else if (rowInsert1->hasPropertyChildren() && rowInsert1->expanded()) {
rowInsert1 = rowInsert1->childProps().last();
- rowInsert2 = getRowAtPos(QPointF(0, rowInsert1->y() + TimelineConstants::ROW_H));
+ rowInsert2 = m_scene->rowManager()
+ ->getRowAtPos(QPointF(0, rowInsert1->y() + TimelineConstants::ROW_H));
}
// calc insertion depth
@@ -320,7 +310,7 @@ void RowMover::updateTargetRow(const QPointF &scenePos, EStudioObjectType rowTyp
valid = false;
}
if (valid) {
- updateState(depth, rowInsert1->y() + TimelineConstants::ROW_H);
+ updateState(depth, rowInsert1->y() + rowInsert1->size().height());
// auto expand
if (!rowInsert1->locked() && !rowInsert1->expanded() && rowInsert1->isContainer()
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.h
index b2d3f058..1250739d 100644
--- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.h
+++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.h
@@ -58,7 +58,6 @@ public:
private:
void updateState(int depth, double y);
void resetInsertionParent(RowTree *newParent = nullptr);
- RowTree *getRowAtPos(const QPointF &scenePos);
bool isSourceRowsDescendant(RowTree *row) const;
bool sourceRowsHasMaster() const;
bool isNextSiblingRow(RowTree *r1, RowTree *r2) const;
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp
index de682be3..4436f517 100644
--- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp
+++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp
@@ -444,7 +444,6 @@ void TimelineGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
m_rowMover->start(m_rowManager->selectedRows());
}
if (m_rowMover->isActive()) {
- // collapse all properties so correctIndex() counts correctly
m_rowManager->collapseAllPropertyRows();
m_rowMover->updateTargetRow(event->scenePos());
updateAutoScrolling(event->scenePos().y());
@@ -702,10 +701,9 @@ void TimelineGraphicsScene::keyReleaseEvent(QKeyEvent *keyEvent)
void TimelineGraphicsScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
- int index = event->scenePos().y() / TimelineConstants::ROW_H;
- RowTree *row = m_rowManager->rowAt(index);
+ RowTree *row = m_rowManager->getRowAtPos(event->scenePos());
- if (row == nullptr || m_widgetTimeline->isFullReconstructPending() || m_dragging
+ if (!row || m_widgetTimeline->isFullReconstructPending() || m_dragging
|| m_startRowMoverOnNextDrag) {
return;
}
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.cpp
index e768283d..be65b80b 100644
--- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.cpp
+++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.cpp
@@ -285,19 +285,21 @@ Keyframe *RowTimeline::getClickedKeyframe(const QPointF &scenePos)
return nullptr;
}
-QList<Keyframe *> RowTimeline::getKeyframesInRange(double left, double right)
+QList<Keyframe *> RowTimeline::getKeyframesInRange(const QRectF &rect) const
{
double x;
- double x1 = mapFromScene(left, 0).x();
- double x2 = mapFromScene(right, 0).x();
+ QRectF localRect = mapFromScene(rect).boundingRect();
QList<Keyframe *> result;
+ static const int KF_CENTER_Y = 10;
for (auto keyframe : qAsConst(m_keyframes)) {
x = timeToX(keyframe->time);
- if (x1 < x && x2 > x)
+ if (localRect.left() < x && localRect.right() > x
+ && localRect.top() < KF_CENTER_Y && localRect.bottom() > KF_CENTER_Y) {
result.append(keyframe);
+ }
}
return result;
@@ -508,14 +510,14 @@ double RowTimeline::getDurationMoveOffsetX() const
}
// convert time values to x
-double RowTimeline::timeToX(double time)
+double RowTimeline::timeToX(double time) const
{
return TimelineConstants::RULER_EDGE_OFFSET + time * TimelineConstants::RULER_SEC_W
* rowTree()->m_scene->ruler()->timelineScale();
}
// convert x values to time
-double RowTimeline::xToTime(double xPos)
+double RowTimeline::xToTime(double xPos) const
{
return (xPos - TimelineConstants::RULER_EDGE_OFFSET)
/ (TimelineConstants::RULER_SEC_W * rowTree()->m_scene->ruler()->timelineScale());
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.h
index 831c02e0..c0a9a0c1 100644
--- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.h
+++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.h
@@ -76,7 +76,7 @@ public:
RowTimeline *parentRow() const;
RowTree *rowTree() const;
Keyframe *getClickedKeyframe(const QPointF &scenePos);
- QList<Keyframe *> getKeyframesInRange(double left, double right);
+ QList<Keyframe *> getKeyframesInRange(const QRectF &rect) const;
QList<Keyframe *> keyframes() const;
void showToolTip(const QPointF &pos);
@@ -90,8 +90,8 @@ private:
void updateChildrenMaxEndXRecursive(RowTree *rowTree);
void drawColorPropertyGradient(QPainter *painter, int width);
bool isColorProperty() const;
- double timeToX(double time);
- double xToTime(double xPos);
+ double timeToX(double time) const;
+ double xToTime(double xPos) const;
RowTree *m_rowTree;
RowTimelinePropertyGraph *m_propertyGraph = nullptr;