diff options
author | Kaj Grönholm <kaj.gronholm@qt.io> | 2018-05-04 09:28:47 +0300 |
---|---|---|
committer | Kaj Grönholm <kaj.gronholm@qt.io> | 2018-05-04 10:20:17 +0000 |
commit | 71389e596f9146fedb6d28459d4b7aa0cbba8e44 (patch) | |
tree | fd00db764f4ea53bc7318ec82eab0fb2a795a114 | |
parent | 8a53e7004fc78a590bb55de30039b06231bfc33f (diff) |
Fix timeline tree items width
Don't store tree width into each row, use one in scene.
Task-number: QT3DS-1546
Change-Id: I9fe06ba309279c3ced78ca3af766d3abb6d47fab
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
6 files changed, 26 insertions, 36 deletions
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp index 7c5ca1f9..43fd6060 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp @@ -108,7 +108,7 @@ TimelineGraphicsScene::TimelineGraphicsScene(TimelineWidget *timelineWidget) m_layoutRoot->addItem(m_layoutTree); m_layoutRoot->addItem(m_layoutTimeline); - m_treeHeader = new TreeHeader; + m_treeHeader = new TreeHeader(this); m_layoutTree->addItem(m_treeHeader); m_layoutTimeline->addItem(m_ruler); @@ -324,17 +324,17 @@ bool TimelineGraphicsScene::validLayerMove(RowTree *rowAtIndex, RowTree *nextRow void TimelineGraphicsScene::updateTreeWidth(double treeWidth) { - m_treeWidth = treeWidth; - - m_treeHeader->setWidth(treeWidth); - - RowTree *row_i; - for (int i = 1; i < m_layoutTree->count(); ++i) { - row_i = static_cast<RowTree *>(m_layoutTree->itemAt(i)->graphicsItem()); - row_i->setTreeWidth(treeWidth); + if (m_treeWidth != treeWidth) { + m_treeWidth = treeWidth; + update(); } } +double TimelineGraphicsScene::treeWidth() const +{ + return m_treeWidth; +} + void TimelineGraphicsScene::setMouseCursor(CMouseCursor::Qt3DSMouseCursor cursor) { if (m_currentCursor != cursor) { diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.h index 55e4db87..155978c9 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.h +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.h @@ -72,6 +72,7 @@ public: QGraphicsLinearLayout *layoutTree() const; QGraphicsLinearLayout *layoutTimeline() const; TreeHeader *treeHeader() const; + double treeWidth() const; void updateTreeWidth(double x); void setMouseCursor(CMouseCursor::Qt3DSMouseCursor cursor); void resetMouseCursor(); diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.cpp index 33885f40..6c0f3696 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.cpp @@ -164,9 +164,9 @@ void RowTree::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q // update button bounds rects m_rectArrow .setRect(offset, iconY, iconSize, iconSize); m_rectType .setRect(offset + iconSize, iconY, iconSize, iconSize); - m_rectShy .setRect(m_treeWidth - 16 * 3.3, iconY, iconSize, iconSize); - m_rectVisible.setRect(m_treeWidth - 16 * 2.2, iconY, iconSize, iconSize); - m_rectLocked .setRect(m_treeWidth - 16 * 1.1, iconY, iconSize, iconSize); + m_rectShy .setRect(treeWidth() - 16 * 3.3, iconY, iconSize, iconSize); + m_rectVisible.setRect(treeWidth() - 16 * 2.2, iconY, iconSize, iconSize); + m_rectLocked .setRect(treeWidth() - 16 * 1.1, iconY, iconSize, iconSize); // Background QColor bgColor; @@ -275,7 +275,7 @@ void RowTree::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q painter->drawPixmap(m_rectType, pixRowType); // Shy, eye, lock separator - painter->fillRect(QRect(m_treeWidth - TimelineConstants::TREE_ICONS_W, + painter->fillRect(QRect(treeWidth() - TimelineConstants::TREE_ICONS_W, 0, 1, size().height()), TimelineConstants::WIDGET_BG_COLOR); @@ -293,7 +293,7 @@ void RowTree::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q // Candidate parent of a dragged row if (m_moveTarget) { painter->setPen(QPen(QColor(TimelineConstants::ROW_MOVER_COLOR), 1)); - painter->drawRect(QRect(1, 1, m_treeWidth - 2, size().height() - 3)); + painter->drawRect(QRect(1, 1, treeWidth() - 2, size().height() - 3)); } // Action indicators @@ -328,13 +328,7 @@ void RowTree::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q int RowTree::treeWidth() const { - return m_treeWidth; -} - -void RowTree::setTreeWidth(double w) -{ - m_treeWidth = w; - update(); + return m_scene->treeWidth(); } void RowTree::setBinding(ITimelineItemBinding *binding) diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.h index 7cd7b979..baa0118f 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.h +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.h @@ -135,7 +135,6 @@ private: int m_depth = 1; int m_index = 0; int m_indexInLayout = 1; - int m_treeWidth = TimelineConstants::TREE_DEFAULT_W; bool m_shy = false; bool m_visible = true; bool m_locked = false; diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeader.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeader.cpp index bd375e2a..79321737 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeader.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeader.cpp @@ -31,7 +31,9 @@ #include <QtGui/qpainter.h> -TreeHeader::TreeHeader(TimelineItem *parent) : TimelineItem(parent) +TreeHeader::TreeHeader(TimelineGraphicsScene *timelineScene, TimelineItem *parent) + : TimelineItem(parent) + , m_scene(timelineScene) { } @@ -42,9 +44,10 @@ void TreeHeader::paint(QPainter *painter, const QStyleOptionGraphicsItem *option Q_UNUSED(option) Q_UNUSED(widget) - m_rectShy .setRect(m_treeWidth - 16 * 3.3, size().height() * .5 - 8, 16, 16); - m_rectVisible.setRect(m_treeWidth - 16 * 2.2, size().height() * .5 - 8, 16, 16); - m_rectLock .setRect(m_treeWidth - 16 * 1.1, size().height() * .5 - 8, 16, 16); + double treeWidth = m_scene->treeWidth(); + m_rectShy .setRect(treeWidth - 16 * 3.3, size().height() * .5 - 8, 16, 16); + m_rectVisible.setRect(treeWidth - 16 * 2.2, size().height() * .5 - 8, 16, 16); + m_rectLock .setRect(treeWidth - 16 * 1.1, size().height() * .5 - 8, 16, 16); static const QPixmap pixShy = QPixmap(":/images/Toggle-Shy.png"); static const QPixmap pixVisible = QPixmap(":/images/Toggle-HideShow.png"); @@ -65,12 +68,6 @@ void TreeHeader::paint(QPainter *painter, const QStyleOptionGraphicsItem *option painter->drawPixmap(m_rectLock , pixLock); } -void TreeHeader::setWidth(double w) -{ - m_treeWidth = w; - update(); -} - TreeControlType TreeHeader::handleButtonsClick(const QPointF &scenePos) { QPointF p = mapFromScene(scenePos.x(), scenePos.y()); diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeader.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeader.h index 88239215..7bd09634 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeader.h +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeader.h @@ -32,6 +32,7 @@ #include "TimelineItem.h" #include "TimelineConstants.h" #include "RowTypes.h" +#include "TimelineGraphicsScene.h" class RowTimeline; @@ -40,24 +41,22 @@ class TreeHeader : public TimelineItem Q_OBJECT public: - explicit TreeHeader(TimelineItem *parent = nullptr); + explicit TreeHeader(TimelineGraphicsScene *timelineScene, TimelineItem *parent = nullptr); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; - void setWidth(double w); TreeControlType handleButtonsClick(const QPointF &scenePos); bool filterShy() const; bool filterHidden() const; bool filterLocked() const; int type() const; - int m_treeWidth = TimelineConstants::TREE_DEFAULT_W; - void toggleFilterShy(); void toggleFilterHidden(); void toggleFilterLocked(); private: + TimelineGraphicsScene *m_scene; bool m_shy = false; bool m_visible = false; bool m_lock = false; |