summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp
diff options
context:
space:
mode:
authorMahmoud Badri <mahmoud.badri@qt.io>2018-02-22 15:34:20 +0200
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2018-02-28 13:47:13 +0000
commit6741e0b808aef4992c81df1128b8db0f8113f49f (patch)
treee6d96b203c2a2f67ac84d7e038b4c25ed67772dc /src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp
parent26a16b56b39f3904c382c392d7ed958fab73108b (diff)
Implement graphics view based timeline basics
Add rows, reorder rows, keyframes Task-number: QT3DS-927 Change-Id: Iaff7354fd5d5b8feaa86364d1b545a48cc3c0376 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp')
-rw-r--r--src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp144
1 files changed, 144 insertions, 0 deletions
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp
new file mode 100644
index 00000000..ed447bb7
--- /dev/null
+++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp
@@ -0,0 +1,144 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt 3D Studio.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "RowMover.h"
+#include "RowTree.h"
+#include "TimelineConstants.h"
+
+#include <QtGui/qpainter.h>
+#include <QtWidgets/qapplication.h>
+#include <QtWidgets/qgraphicsitem.h>
+
+RowMover::RowMover() : QGraphicsRectItem()
+{
+ setZValue(99);
+ setRect(0, -2, 20, 2);
+}
+
+void RowMover::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ painter->setPen(QPen(QColor(TimelineConstants::ROW_MOVER_COLOR), 4));
+ painter->drawLine(0, -.5, 10, -.5);
+ painter->fillRect(0, -2.5, rect().width() - x(), 2, QColor(TimelineConstants::ROW_MOVER_COLOR));
+}
+
+RowTree *RowMover::insertionParent() const
+{
+ return m_insertionParent;
+}
+
+void RowMover::resetInsertionParent(RowTree *newTarget)
+{
+ if (m_insertionParent != nullptr) {
+ m_insertionParent->setMoveTarget(false);
+ m_insertionParent = nullptr;
+ }
+
+ if (newTarget != nullptr) {
+ m_insertionParent = newTarget;
+ m_insertionParent->setMoveTarget(true);
+ }
+}
+
+int RowMover::sourceIndex() const
+{
+ return m_sourceIndex;
+}
+
+int RowMover::targetIndex() const
+{
+ return m_targetIndex;
+}
+
+bool RowMover::movingDown() const
+{
+ return m_targetIndex >= m_sourceIndex;
+}
+
+RowTree *RowMover::sourceRow() const
+{
+ return m_sourceRow;
+}
+
+bool RowMover::isActive()
+{
+ return m_active;
+}
+
+void RowMover::start(RowTree *row, int index)
+{
+ m_sourceRow = row;
+ m_sourceIndex = index;
+ m_active = true;
+
+ m_sourceRow->setMoveSourceRecursive(true);
+
+ qApp->setOverrideCursor(Qt::ClosedHandCursor);
+}
+
+void RowMover::end()
+{
+ if (m_active) {
+ m_sourceRow->setMoveSourceRecursive(false);
+
+ m_active = false;
+ m_sourceRow = nullptr;
+ m_sourceIndex = -1;
+
+ setVisible(false);
+ resetInsertionParent();
+
+ qApp->changeOverrideCursor(Qt::ArrowCursor);
+ qApp->restoreOverrideCursor();
+ }
+}
+
+
+void RowMover::updateState(int index, int depth, int rawIndex)
+{
+ m_targetIndex = index;
+
+ setPos(20 + depth * 15, (rawIndex + 1) * TimelineConstants::ROW_H);
+ setVisible(true);
+}
+
+// TODO: not used, probably delete
+bool RowMover::isValidMove(int index, RowTree *rowAtIndex)
+{
+ return
+ // not the same row
+ //index != m_currentIndex &&
+
+ // not moving an ancestor into a decendent
+ !rowAtIndex->isDecendentOf(m_sourceRow) &&
+
+ // not at the top of an expanded object with property children
+ (rowAtIndex->childRows().empty()
+ || rowAtIndex->childRows().first()->rowType() != RowType::Property
+ || !rowAtIndex->expanded());
+}