diff options
author | Pasi Keränen <pasi.keranen@qt.io> | 2019-06-05 13:22:33 +0300 |
---|---|---|
committer | Pasi Keränen <pasi.keranen@qt.io> | 2019-06-10 21:22:35 +0300 |
commit | fa46a1dc716c499b5eefdfd8f0cfcfc8ac303937 (patch) | |
tree | 61f7f6eed72822cf39a52769dfaba24d1bde9522 /src/Authoring/Studio/Palettes/TimelineGraphicsView/ui | |
parent | fe7649841f68c6fe99bf08e477df77770c7dffa0 (diff) |
Switch to qt3dstudio/ogl-runtime submodule
Module config change so that ogl-runtime builds from submodule.
Task-number: QT3DS-3600
Change-Id: Ib22fda6aed1cf9336f15b79256b5f9db8774159f
Reviewed-by: Pasi Keränen <pasi.keranen@qt.io>
Diffstat (limited to 'src/Authoring/Studio/Palettes/TimelineGraphicsView/ui')
32 files changed, 0 insertions, 6191 deletions
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/InteractiveTimelineItem.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/InteractiveTimelineItem.cpp deleted file mode 100644 index efc7a2c1..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/InteractiveTimelineItem.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** 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 "InteractiveTimelineItem.h" - -InteractiveTimelineItem::InteractiveTimelineItem(TimelineItem *parent) : TimelineItem(parent) -{ - setAcceptHoverEvents(true); -} - -void InteractiveTimelineItem::setState(State state) -{ - m_state = state; -} - -int InteractiveTimelineItem::type() const -{ - // Enable the use of qgraphicsitem_cast with this item. - return TypeInteractiveTimelineItem; -} - -void InteractiveTimelineItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event) - if (m_state != Selected) - setState(Hovered); -} - -void InteractiveTimelineItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event) - if (m_state != Selected) - setState(Normal); -} diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/InteractiveTimelineItem.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/InteractiveTimelineItem.h deleted file mode 100644 index a6a5e5ee..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/InteractiveTimelineItem.h +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef INTERACTIVETIMELINEITEM_H -#define INTERACTIVETIMELINEITEM_H - -#include "TimelineItem.h" - -class InteractiveTimelineItem : public TimelineItem { - Q_OBJECT - -public: - enum State { - Pressed, - Hovered, - Selected, - Normal - }; - - explicit InteractiveTimelineItem(TimelineItem *parent = nullptr); - - virtual void setState(State state); - - int type() const override; - -protected: - void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; - void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; - - State m_state = Normal; -}; - -#endif // INTERACTIVETIMELINEITEM_H diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/NavigationBar.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/NavigationBar.cpp deleted file mode 100644 index f41c2952..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/NavigationBar.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/**************************************************************************** -** -** 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 "NavigationBar.h" -#include "NavigationBarItem.h" -#include "TimelineConstants.h" -#include <QtCore/qdebug.h> - -NavigationBar::NavigationBar(QWidget *parent) - : QWidget(parent) -{ - setMaximumHeight(0); - m_layout = new QHBoxLayout(this); - m_layout->setMargin(4); - m_layout->setSpacing(4); - setLayout(m_layout); - // Initialize hide/show animation - m_expandAnimation.setTargetObject(this); - m_expandAnimation.setPropertyName("maximumHeight"); - m_expandAnimation.setDuration(TimelineConstants::EXPAND_ANIMATION_DURATION); -} - -void NavigationBar::updateNavigationItems(IBreadCrumbProvider *inBreadCrumbProvider) -{ - if (!inBreadCrumbProvider) - return; - - m_breadCrumbProvider = inBreadCrumbProvider; - - const IBreadCrumbProvider::TTrailList &trailList = m_breadCrumbProvider->GetTrail(); - int listSize = (int)trailList.size(); - - // Remove "stretch" from end - QLayoutItem *stretch = m_layout->takeAt(m_layout->count() - 1); - if (stretch) - delete stretch; - - // Update current items or create new as needed - for (int i = 0; i < listSize; ++i) { - SBreadCrumb item = trailList.at(i); - NavigationBarItem *barItem = nullptr; - bool newItem = (m_itemAmount <= 0) || (i > m_itemAmount - 1); - if (newItem) { - barItem = new NavigationBarItem(this); - } else { - // Every other item is NavigationBarItem, every other separator - int barItemIndex = i * 2; - barItem = static_cast<NavigationBarItem *>( - m_layout->itemAt(barItemIndex)->widget()); - barItem->setHighlight(false); - } - bool isLastItem = (i == listSize - 1); - barItem->setEnabled(!isLastItem); - barItem->setIndex(i); - barItem->setText(item.m_String); - if (i == 0) - barItem->setIcon(m_breadCrumbProvider->GetRootImage()); - else - barItem->setIcon(m_breadCrumbProvider->GetBreadCrumbImage()); - - if (newItem) { - QObject::connect(barItem, &NavigationBarItem::clicked, - this, &NavigationBar::itemClicked); - if (i != 0) { - // Separator before all items except first - QLabel *separator = new QLabel(this); - separator->setPixmap(m_breadCrumbProvider->GetSeparatorImage()); - m_layout->addWidget(separator); - } - m_layout->addWidget(barItem); - } - } - - // Remove possible extra items, when user navigates back - // First item (scene) is never removed - QLayoutItem *child; - int lastIndex = (listSize <= 1) ? 1 : (listSize * 2) - 1; - while ((child = m_layout->takeAt(lastIndex)) != 0) { - if (child->widget()) - delete child->widget(); - delete child; - } - - // When list contains single item (scene), hide the bar - setBarVisibility(listSize > 1); - - // Stretch at end for proper item sizing - m_layout->addStretch(1); - - m_itemAmount = listSize; -} - -void NavigationBar::itemClicked(int index) -{ - m_breadCrumbProvider->OnBreadCrumbClicked((long)index); -} - -void NavigationBar::setBarVisibility(bool visible) -{ - int endHeight = visible ? TimelineConstants::NAVIGATION_BAR_H : 0; - if (height() != endHeight) { - m_expandAnimation.setEndValue(endHeight); - m_expandAnimation.start(); - } -} diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/NavigationBar.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/NavigationBar.h deleted file mode 100644 index f08e4220..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/NavigationBar.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef NAVIGATIONBAR_H -#define NAVIGATIONBAR_H - -#include <QtCore/qpropertyanimation.h> -#include <QtWidgets/qwidget.h> -#include <QtWidgets/qboxlayout.h> -#include "Bindings/IBreadCrumbProvider.h" - -class NavigationBar : public QWidget -{ - Q_OBJECT -public: - explicit NavigationBar(QWidget *parent = nullptr); - void updateNavigationItems(IBreadCrumbProvider *inBreadCrumbProvider); - -public slots: - void itemClicked(int index); - -private: - void setBarVisibility(bool visible); - IBreadCrumbProvider *m_breadCrumbProvider = nullptr; - QHBoxLayout *m_layout = nullptr; - int m_itemAmount = 0; - QPropertyAnimation m_expandAnimation; -}; - -#endif // NAVIGATIONBAR_H diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/NavigationBarItem.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/NavigationBarItem.cpp deleted file mode 100644 index b9b47642..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/NavigationBarItem.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** 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 "NavigationBarItem.h" -#include "StudioPreferences.h" -#include "ResourceCache.h" - -#include <QtCore/qdebug.h> -#include <QtWidgets/qsizepolicy.h> - -NavigationBarItem::NavigationBarItem(QWidget *parent) - : QWidget(parent) -{ - setHighlight(false); - m_layout.setMargin(0); - m_layout.setSpacing(0); - m_iconLabel.setFixedWidth(20); - m_iconLabel.setStyleSheet("padding: 0 0 0 4;"); - m_textLabel.setStyleSheet("padding: 0 4 0 0;"); - m_textLabel.setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - m_layout.addWidget(&m_iconLabel); - m_layout.addWidget(&m_textLabel); - setLayout(&m_layout); -} - -void NavigationBarItem::setIndex(int index) -{ - m_index = index; -} - -void NavigationBarItem::setIcon(const QPixmap &pixmap) -{ - m_iconLabel.setPixmap(pixmap); -} - -void NavigationBarItem::setText(const QString &text) -{ - QColor textColor = isEnabled() ? CStudioPreferences::GetNormalColor() - : CStudioPreferences::GetInactiveColor(); - const QString fonttemplate = tr("<font color='%1'>%2</font>"); - m_textLabel.setText(fonttemplate.arg(textColor.name(), text)); -} - -void NavigationBarItem::setHighlight(bool highlight) -{ - if (highlight) { - QColor bgColor = CStudioPreferences::GetMouseOverHighlightColor(); - QString bgColorStyle = QStringLiteral("background-color: ") + bgColor.name(); - setStyleSheet(bgColorStyle); - } else { - setStyleSheet("background-color: transparent;"); - } -} - -void NavigationBarItem::mousePressEvent(QMouseEvent *event) -{ - Q_UNUSED(event); - emit clicked(m_index); -} - -void NavigationBarItem::enterEvent(QEvent *event) -{ - Q_UNUSED(event); - if (isEnabled()) - setHighlight(true); -} - -void NavigationBarItem::leaveEvent(QEvent *event) -{ - Q_UNUSED(event); - if (isEnabled()) - setHighlight(false); -} diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/NavigationBarItem.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/NavigationBarItem.h deleted file mode 100644 index 8b1fc3ab..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/NavigationBarItem.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef NAVIGATIONBARITEM_H -#define NAVIGATIONBARITEM_H - -#include <QtGui/qpixmap.h> -#include <QtWidgets/qwidget.h> -#include <QtWidgets/qboxlayout.h> -#include <QtWidgets/qlabel.h> - -class NavigationBarItem : public QWidget -{ - Q_OBJECT -public: - explicit NavigationBarItem(QWidget *parent = nullptr); - - void setIndex(int index); - void setText(const QString &text); - void setIcon(const QPixmap &pixmap); - void setHighlight(bool highlight); - -protected: - void mousePressEvent(QMouseEvent *event) override; - void enterEvent(QEvent *event) override; - void leaveEvent(QEvent *event) override; - -signals: - void clicked(int index); - -private: - int m_index = 0; - QHBoxLayout m_layout; - QLabel m_iconLabel; - QLabel m_textLabel; -}; - -#endif // NAVIGATIONBARITEM_H diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/PlayHead.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/PlayHead.cpp deleted file mode 100644 index 3ddfdcad..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/PlayHead.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** 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 "PlayHead.h" -#include "Ruler.h" -#include "TimelineConstants.h" -#include "StudioPreferences.h" -#include "StudioUtils.h" - -#include <QtGui/qpainter.h> -#include <QtGui/qcursor.h> -#include <QtWidgets/qwidget.h> - -PlayHead::PlayHead(Ruler *ruler) - : QGraphicsRectItem() - , m_ruler(ruler) -{ - setZValue(99); - setRect(-TimelineConstants::PLAYHEAD_W * .5, 0, TimelineConstants::PLAYHEAD_W, 0); -} - -void PlayHead::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - Q_UNUSED(option) - Q_UNUSED(widget) - - bool hiResIcons = StudioUtils::devicePixelRatio(widget->window()->windowHandle()) > 1.0; - static const QPixmap pixHead = QPixmap(":/images/PlaybackHead.png"); - static const QPixmap pixHead2x = QPixmap(":/images/PlaybackHead@2x.png"); - - static const int PLAY_HEAD_H = 999999; // theoretically big enough height - painter->drawPixmap(-TimelineConstants::PLAYHEAD_W * .5, 0, hiResIcons ? pixHead2x : pixHead); - painter->setPen(CStudioPreferences::timelinePlayheadLineColor()); - painter->drawLine(0, 0, 0, PLAY_HEAD_H); -} - -void PlayHead::setHeight(int height) -{ - setRect(rect().x(), rect().y(), rect().width(), height); -} - -void PlayHead::setTime(long time) -{ - if (time < 0) - time = 0; - else if (time > m_ruler->duration()) - time = m_ruler->duration(); - - m_time = time; - updatePosition(); -} - -void PlayHead::setPosition(double posX) -{ - posX = qBound(TimelineConstants::RULER_EDGE_OFFSET, posX, m_ruler->duration() - * TimelineConstants::RULER_MILLI_W * m_ruler->timelineScale() - + TimelineConstants::RULER_EDGE_OFFSET); - - setX(m_ruler->x() + posX); - m_time = (posX - TimelineConstants::RULER_EDGE_OFFSET) - / (TimelineConstants::RULER_MILLI_W * m_ruler->timelineScale()); -} - -void PlayHead::updatePosition() -{ - setX(m_ruler->x() + TimelineConstants::RULER_EDGE_OFFSET - + m_time * TimelineConstants::RULER_MILLI_W * m_ruler->timelineScale()); -} - -long PlayHead::time() const -{ - return m_time; -} - -int PlayHead::type() const -{ - // Enable the use of qgraphicsitem_cast with this item. - return TimelineItem::TypePlayHead; -} diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/PlayHead.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/PlayHead.h deleted file mode 100644 index 395e6317..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/PlayHead.h +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef PLAYHEAD_H -#define PLAYHEAD_H - -#include "TimelineItem.h" - -#include <QtWidgets/qgraphicsitem.h> - -class Ruler; - -class PlayHead : public QGraphicsRectItem -{ - -public: - explicit PlayHead(Ruler *m_ruler); - - void setHeight(int height); - void setPosition(double posX); // set x poisiotn - void updatePosition(); // sync x poisiotn based on time value - void setTime(long time); // set time (sets x based on time (ms) input) - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) override; - long time() const; - int type() const override; - -private: - long m_time = 0; - Ruler *m_ruler; -}; - -#endif // PLAYHEAD_H diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.cpp deleted file mode 100644 index 25b66911..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.cpp +++ /dev/null @@ -1,1035 +0,0 @@ -/**************************************************************************** -** -** 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 "RowTimeline.h" -#include "RowTimelinePropertyGraph.h" -#include "RowTree.h" -#include "RowManager.h" -#include "Ruler.h" -#include "TimelineConstants.h" -#include "Keyframe.h" -#include "KeyframeManager.h" -#include "TimelineGraphicsScene.h" -#include "Bindings/ITimelineItemBinding.h" -#include "Bindings/ITimelineTimebar.h" -#include "Bindings/Qt3DSDMTimelineItemProperty.h" -#include "AppFonts.h" -#include "StudioPreferences.h" -#include "TimelineToolbar.h" -#include "StudioUtils.h" - -#include <QtGui/qpainter.h> -#include <QtGui/qbrush.h> -#include <QtWidgets/qdesktopwidget.h> -#include <QtWidgets/qapplication.h> -#include <QtWidgets/qgraphicssceneevent.h> -#include <QtWidgets/qwidget.h> -#include <QtWidgets/qlabel.h> -#include <QtCore/qdatetime.h> - -RowTimeline::RowTimeline() - : InteractiveTimelineItem() -{ - // 999999: theoretically big enough row width (~ 4.6 hrs of presentation length) - setMinimumWidth(999999); - setMaximumWidth(999999); -} - -RowTimeline::~RowTimeline() -{ - // remove keyframes - if (!m_keyframes.empty()) { - if (m_isProperty) // non-property rows use the same keyframes from property rows. - qDeleteAll(m_keyframes); - - m_keyframes.clear(); - } -} - -void RowTimeline::initialize() -{ - // Called once m_rowTree exists - - m_commentItem = new RowTimelineCommentItem(this); - m_commentItem->setParentRow(m_rowTree); - updateCommentItemPos(); - - TimelineToolbar *toolbar = m_rowTree->m_scene->widgetTimeline()->toolbar(); - connect(toolbar, &TimelineToolbar::showRowTextsToggled, this, [this]() { - updateCommentItem(); - }); - - connect(m_commentItem, &RowTimelineCommentItem::labelChanged, this, - [this](const QString &label) { - // Update label on timeline and on model - ITimelineTimebar *timebar = m_rowTree->m_binding->GetTimelineItem()->GetTimebar(); - timebar->SetTimebarComment(label); - }); - - connect(m_rowTree->m_scene->ruler(), &Ruler::viewportXChanged, this, - &RowTimeline::updateCommentItemPos); -} - -void RowTimeline::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - Q_UNUSED(option) - - bool hiResIcons = StudioUtils::devicePixelRatio(widget->window()->windowHandle()) > 1.0; - - if (!y()) // prevents flickering when the row is just inserted to the layout - return; - - const int currentHeight = size().height() - 1; - - if (isColorProperty() && !m_keyframes.empty()) { - drawColorPropertyGradient(painter, widget->width()); - } else { - // Background - QColor bgColor; - if (m_rowTree->isProperty()) - bgColor = CStudioPreferences::timelineRowColorNormalProp(); - else if (m_state == Selected) - bgColor = CStudioPreferences::timelineRowColorSelected(); - else if (m_state == Hovered && !m_rowTree->m_locked) - bgColor = CStudioPreferences::timelineRowColorOver(); - else - bgColor = CStudioPreferences::timelineRowColorNormal(); - painter->fillRect(0, 0, size().width(), currentHeight, bgColor); - } - - const double edgeOffset = TimelineConstants::RULER_EDGE_OFFSET; - - // Duration. Draw duration bar (for scene/component root) also if it has - // datainput controller - if (m_rowTree->hasDurationBar() || m_controllerDataInput.size()) { - painter->save(); - - // fully outside ancestors' limits, draw fully hashed - if (m_minStartX > m_endX || m_maxEndX < m_startX) { - painter->setBrush(QBrush(CStudioPreferences::timelineRowColorDurationOff1(), - Qt::BDiagPattern)); - painter->setPen(Qt::NoPen); - painter->fillRect(QRect(edgeOffset + m_startX, 0, m_endX - m_startX, currentHeight), - CStudioPreferences::timelineRowColorDurationOff2()); - painter->drawRect(QRect(edgeOffset + m_startX, 0, m_endX - m_startX, currentHeight)); - - painter->setPen(QPen(CStudioPreferences::timelineRowColorDurationEdge(), 2)); - painter->drawLine(edgeOffset + m_startX, 0, edgeOffset + m_startX, currentHeight); - painter->drawLine(edgeOffset + m_endX, 0, edgeOffset + m_endX, currentHeight); - } else { - // draw main duration part - double x = edgeOffset + qMax(m_startX, m_minStartX); - double w = edgeOffset + qMin(m_endX, m_maxEndX) - x; - static const int marginY = 3; - - painter->setPen(Qt::NoPen); - - if (m_controllerDataInput.size()) { - painter->fillRect(QRect(x, 0, w, currentHeight), - CStudioPreferences::dataInputColor()); - } else if (m_rowTree->indexInLayout() != 1) { - painter->fillRect(QRect(x, 0, w, currentHeight), m_barColor); - } - - if (m_state == Selected) { - // draw selection overlay on bar - painter->fillRect(QRect(x, marginY, w, currentHeight - marginY * 2), - CStudioPreferences::timelineRowColorDurationSelected()); - } - - if (m_controllerDataInput.size()) { - static const QPixmap pixDataInput = QPixmap(":/images/Objects-DataInput-White.png"); - static const QPixmap pixDataInput2x - = QPixmap(":/images/Objects-DataInput-White@2x.png"); - static const QFontMetrics fm(painter->font()); - - // need clip region to limit datainput icon visibility to the same rect as we use - // for text - painter->setClipRect(x, 0, w, currentHeight); - painter->setClipping(true); - painter->setPen(QPen(CStudioPreferences::textColor(), 2)); - // +5 added to text location to make margin comparable to other datainput controls - painter->drawText(QRect(x + pixDataInput.width() + 5, 0, w, currentHeight), - m_controllerDataInput, QTextOption(Qt::AlignCenter)); - // place the icon in front of the text - int textwidth = fm.width(m_controllerDataInput); - int iconx = x + (w - textwidth) / 2; - if (iconx < x) - iconx = x; - painter->drawPixmap(iconx, marginY, hiResIcons ? pixDataInput2x : pixDataInput); - painter->setPen(Qt::NoPen); - painter->setClipping(false); - } - - // draw hashed part before - painter->setBrush(QBrush(CStudioPreferences::timelineRowColorDurationOff1(), - Qt::BDiagPattern)); - if (m_startX < m_minStartX) { - painter->setPen(Qt::NoPen); - painter->fillRect(QRect(edgeOffset + m_startX, 0, m_minStartX - m_startX, - currentHeight), - CStudioPreferences::timelineRowColorDurationOff2()); - painter->drawRect(QRect(edgeOffset + m_startX, 0, m_minStartX - m_startX, - currentHeight)); - painter->setPen(CStudioPreferences::timelineRowColorDurationEdge()); - painter->drawLine(edgeOffset + m_minStartX, 0, edgeOffset + m_minStartX, - currentHeight); - } - - // draw hashed part after - if (m_endX > m_maxEndX) { - painter->setPen(Qt::NoPen); - painter->fillRect(QRect(edgeOffset + m_maxEndX, 0, m_endX - m_maxEndX, - currentHeight), - CStudioPreferences::timelineRowColorDurationOff2()); - painter->drawRect(QRect(edgeOffset + m_maxEndX, 0, m_endX - m_maxEndX, - currentHeight)); - painter->setPen(CStudioPreferences::timelineRowColorDurationEdge()); - painter->drawLine(edgeOffset + m_maxEndX, 0, edgeOffset + m_maxEndX, currentHeight); - } - - if (m_rowTree->indexInLayout() != 1) { - painter->setPen(QPen(CStudioPreferences::timelineRowColorDurationEdge(), 2)); - painter->drawLine(edgeOffset + m_startX, 0, edgeOffset + m_startX, currentHeight); - painter->drawLine(edgeOffset + m_endX, 0, edgeOffset + m_endX, currentHeight); - } - } - - painter->restore(); - } - - if (m_propertyGraph) { // Property graph - QRectF graphRect(edgeOffset, 0, widget->width(), currentHeight); - m_propertyGraph->paintGraphs(painter, graphRect); - } - - // Keyframes - const qreal keyFrameH = 16.0; - const qreal keyFrameHalfH = keyFrameH / 2.0; - const qreal keyFrameY = (qMin(currentHeight, TimelineConstants::ROW_H) / 2.0) - keyFrameHalfH; - const qreal hiddenKeyFrameY = keyFrameY + (keyFrameH * 2.0 / 3.0) + 2.0; - const qreal keyFrameOffset = hiResIcons ? 8 : 7.5; - - // Hidden descendant keyframe indicators - if (!m_rowTree->expanded()) { - static const QPixmap pixKeyframeHidden = QPixmap(":/images/keyframe-hidden-normal.png"); - static const QPixmap pixKeyframeHidden2x - = QPixmap(":/images/keyframe-hidden-normal@2x.png"); - QVector<long> childKeyframeTimes; - collectChildKeyframeTimes(childKeyframeTimes); - - const qreal oldOpacity = painter->opacity(); - painter->setOpacity(0.75); - for (const auto time : qAsConst(childKeyframeTimes)) { - const qreal xCoord = edgeOffset + m_rowTree->m_scene->ruler()->timeToDistance(time) - - 2.5; - painter->drawPixmap(QPointF(xCoord, hiddenKeyFrameY), hiResIcons ? pixKeyframeHidden2x - : pixKeyframeHidden); - } - painter->setOpacity(oldOpacity); - } - - if (m_rowTree->hasPropertyChildren()) { // object row keyframes - static const QPixmap pixKeyframeMasterDisabled - = QPixmap(":/images/Keyframe-Master-Disabled.png"); - static const QPixmap pixKeyframeMasterNormal - = QPixmap(":/images/Keyframe-Master-Normal.png"); - static const QPixmap pixKeyframeMasterSelected - = QPixmap(":/images/Keyframe-Master-Selected.png"); - static const QPixmap pixKeyframeMasterDynamicDisabled - = QPixmap(":/images/Keyframe-MasterDynamic-Disabled.png"); - static const QPixmap pixKeyframeMasterDynamicNormal - = QPixmap(":/images/Keyframe-MasterDynamic-Normal.png"); - static const QPixmap pixKeyframeMasterDynamicSelected - = QPixmap(":/images/Keyframe-MasterDynamic-Selected.png"); - static const QPixmap pixKeyframeMasterDisabled2x - = QPixmap(":/images/Keyframe-Master-Disabled@2x.png"); - static const QPixmap pixKeyframeMasterNormal2x - = QPixmap(":/images/Keyframe-Master-Normal@2x.png"); - static const QPixmap pixKeyframeMasterSelected2x - = QPixmap(":/images/Keyframe-Master-Selected@2x.png"); - static const QPixmap pixKeyframeMasterDynamicDisabled2x - = QPixmap(":/images/Keyframe-MasterDynamic-Disabled@2x.png"); - static const QPixmap pixKeyframeMasterDynamicNormal2x - = QPixmap(":/images/Keyframe-MasterDynamic-Normal@2x.png"); - static const QPixmap pixKeyframeMasterDynamicSelected2x - = QPixmap(":/images/Keyframe-MasterDynamic-Selected@2x.png"); - for (auto keyframe : qAsConst(m_keyframes)) { - QPixmap pixmap; - if (m_rowTree->locked()) { - if (keyframe->dynamic) { - pixmap = hiResIcons ? pixKeyframeMasterDynamicDisabled2x - : pixKeyframeMasterDynamicDisabled; - } else { - pixmap = hiResIcons ? pixKeyframeMasterDisabled2x - : pixKeyframeMasterDisabled; - } - } else if (keyframe->selected()) { - if (keyframe->dynamic) { - pixmap = hiResIcons ? pixKeyframeMasterDynamicSelected2x - : pixKeyframeMasterDynamicSelected; - } else { - pixmap = hiResIcons ? pixKeyframeMasterSelected2x - : pixKeyframeMasterSelected; - } - } else { - if (keyframe->dynamic) { - pixmap = hiResIcons ? pixKeyframeMasterDynamicNormal2x - : pixKeyframeMasterDynamicNormal; - } else { - pixmap = hiResIcons ? pixKeyframeMasterNormal2x - : pixKeyframeMasterNormal; - } - } - painter->drawPixmap(QPointF(edgeOffset + m_rowTree->m_scene->ruler() - ->timeToDistance(keyframe->time) - keyFrameOffset, - keyFrameY), pixmap); - - // highlight the pressed keyframe in a multi-selection (the keyframe that is affected - // by snapping, and setting time dialog) - if (m_rowTree->m_scene->keyframeManager()->selectedKeyframes().size() > 1 - && m_rowTree->m_scene->pressedKeyframe() == keyframe) { - painter->setPen(QPen(CStudioPreferences::timelinePressedKeyframeColor(), 1)); - painter->drawArc(edgeOffset + m_rowTree->m_scene->ruler() - ->timeToDistance(keyframe->time) - 4, keyFrameY + 4, 9, 9, 0, - 5760); - } - } - } else if (m_rowTree->isProperty()) { // property row keyframes - static const QPixmap pixKeyframePropertyDisabled - = QPixmap(":/images/Keyframe-Property-Disabled.png"); - static const QPixmap pixKeyframePropertyNormal - = QPixmap(":/images/Keyframe-Property-Normal.png"); - static const QPixmap pixKeyframePropertySelected - = QPixmap(":/images/Keyframe-Property-Selected.png"); - static const QPixmap pixKeyframePropertyDynamicDisabled - = QPixmap(":/images/Keyframe-PropertyDynamic-Disabled.png"); - static const QPixmap pixKeyframePropertyDynamicNormal - = QPixmap(":/images/Keyframe-PropertyDynamic-Normal.png"); - static const QPixmap pixKeyframePropertyDynamicSelected - = QPixmap(":/images/Keyframe-PropertyDynamic-Selected.png"); - static const QPixmap pixKeyframePropertyDisabled2x - = QPixmap(":/images/Keyframe-Property-Disabled@2x.png"); - static const QPixmap pixKeyframePropertyNormal2x - = QPixmap(":/images/Keyframe-Property-Normal@2x.png"); - static const QPixmap pixKeyframePropertySelected2x - = QPixmap(":/images/Keyframe-Property-Selected@2x.png"); - static const QPixmap pixKeyframePropertyDynamicDisabled2x - = QPixmap(":/images/Keyframe-PropertyDynamic-Disabled@2x.png"); - static const QPixmap pixKeyframePropertyDynamicNormal2x - = QPixmap(":/images/Keyframe-PropertyDynamic-Normal@2x.png"); - static const QPixmap pixKeyframePropertyDynamicSelected2x - = QPixmap(":/images/Keyframe-PropertyDynamic-Selected@2x.png"); - for (auto keyframe : qAsConst(m_keyframes)) { - QPixmap pixmap; - if (m_rowTree->locked()) { - if (keyframe->dynamic) { - pixmap = hiResIcons ? pixKeyframePropertyDynamicDisabled2x - : pixKeyframePropertyDynamicDisabled; - - } else { - pixmap = hiResIcons ? pixKeyframePropertyDisabled2x - : pixKeyframePropertyDisabled; - } - } else if (keyframe->selected()) { - if (keyframe->dynamic) { - pixmap = hiResIcons ? pixKeyframePropertyDynamicSelected2x - : pixKeyframePropertyDynamicSelected; - - } else { - pixmap = hiResIcons ? pixKeyframePropertySelected2x - : pixKeyframePropertySelected; - } - } else { - if (keyframe->dynamic) { - pixmap = hiResIcons ? pixKeyframePropertyDynamicNormal2x - : pixKeyframePropertyDynamicNormal; - - } else { - pixmap = hiResIcons ? pixKeyframePropertyNormal2x - : pixKeyframePropertyNormal; - } - } - painter->drawPixmap(QPointF(edgeOffset + m_rowTree->m_scene->ruler() - ->timeToDistance(keyframe->time) - keyFrameOffset, - keyFrameY), pixmap); - } - } -} - -bool RowTimeline::isColorProperty() const -{ - ITimelineItemProperty *propBinding = m_rowTree->propBinding(); - if (propBinding) { - qt3dsdm::TDataTypePair type = propBinding->GetType(); - if (m_rowTree->isProperty() - && type.first == qt3dsdm::DataModelDataType::Float4 - && type.second == qt3dsdm::AdditionalMetaDataType::Color) { - return true; - } - } - return false; -} - -void RowTimeline::drawColorPropertyGradient(QPainter *painter, int width) -{ - // Gradient scaled width, or at least widget width - double minWidth = width; - double timelineScale = m_rowTree->m_scene->ruler()->timelineScale(); - double scaledWidth = width * (timelineScale / 2); - width = qMax(minWidth, scaledWidth); - - ITimelineItemProperty *propBinding = m_rowTree->propBinding(); - QLinearGradient bgGradient(0, 0, width, 0); - - for (auto keyframe : qAsConst(m_keyframes)) { - double xPos = m_rowTree->m_scene->ruler()->timeToDistance(keyframe->time); - double gradPos = xPos / width; - gradPos = qBound(0.0, gradPos, 1.0); - QColor currentColor; - // Get the color at the specified time. - currentColor.setRed(propBinding->GetChannelValueAtTime(0, keyframe->time)); - currentColor.setGreen(propBinding->GetChannelValueAtTime(1, keyframe->time)); - currentColor.setBlue(propBinding->GetChannelValueAtTime(2, keyframe->time)); - bgGradient.setColorAt(gradPos, currentColor); - } - painter->fillRect(TimelineConstants::RULER_EDGE_OFFSET, 0, - width, size().height() - 1, bgGradient); -} - -Keyframe *RowTimeline::getClickedKeyframe(const QPointF &scenePos) -{ - if (rowTree()->locked()) - return nullptr; - - QPointF p = mapFromScene(scenePos.x(), scenePos.y()); - double x; - - QList<Keyframe *> keyframes; - if (m_rowTree->hasPropertyChildren()) { - const auto childProps = m_rowTree->childProps(); - for (auto child : childProps) - keyframes.append(child->rowTimeline()->m_keyframes); - } else { - keyframes = m_keyframes; - } - - for (const auto keyframe : qAsConst(keyframes)) { - x = TimelineConstants::RULER_EDGE_OFFSET - + m_rowTree->m_scene->ruler()->timeToDistance(keyframe->time); - - if (p.x() > x - 5 && p.x() < x + 5 && p.y() > 3 && p.y() < 16) - return keyframe; - } - - return nullptr; -} - -QList<Keyframe *> RowTimeline::getKeyframesInRange(const QRectF &rect) const -{ - double x; - QRectF localRect = mapFromScene(rect).boundingRect(); - - QList<Keyframe *> result; - - static const int KF_CENTER_Y = 10; - for (auto keyframe : qAsConst(m_keyframes)) { - x = TimelineConstants::RULER_EDGE_OFFSET - + m_rowTree->m_scene->ruler()->timeToDistance(keyframe->time); - - if (localRect.left() < x && localRect.right() > x - && localRect.top() < KF_CENTER_Y && localRect.bottom() > KF_CENTER_Y) { - result.append(keyframe); - } - } - - return result; -} - -void RowTimeline::updateDurationFromBinding() -{ - if (m_rowTree->isProperty()) // this method works for main rows only - return; - - ITimelineTimebar *timebar = m_rowTree->m_binding->GetTimelineItem()->GetTimebar(); - clearBoundChildren(); - setStartTime(timebar->GetStartTime()); - setEndTime(timebar->GetEndTime()); -} - -void RowTimeline::updateKeyframesFromBinding(const QList<int> &properties) -{ - if (m_rowTree->isProperty()) // this method works for main rows only - return; - - const auto childProps = m_rowTree->childProps(); - for (auto child : childProps) { - qt3dsdm::Qt3DSDMPropertyHandle propertyHandle = - static_cast<Qt3DSDMTimelineItemProperty *>(child->m_PropBinding) - ->getPropertyHandle(); - if (properties.contains(propertyHandle)) { - m_rowTree->m_scene->keyframeManager()->deleteKeyframes(child->rowTimeline(), false); - - for (int i = 0; i < child->m_PropBinding->GetKeyframeCount(); i++) { - Qt3DSDMTimelineKeyframe *kf = static_cast<Qt3DSDMTimelineKeyframe *> - (child->m_PropBinding->GetKeyframeByIndex(i)); - - Keyframe *kfUI = new Keyframe(kf->GetTime(), child->rowTimeline()); - kfUI->binding = kf; - kfUI->dynamic = kf->IsDynamic(); - kf->setUI(kfUI); - child->rowTimeline()->insertKeyframe(kfUI); - child->parentRow()->rowTimeline()->insertKeyframe(kfUI); - if (kf->IsSelected()) - m_rowTree->m_scene->keyframeManager()->selectKeyframe(kfUI); - } - - if (isVisible()) { - child->rowTimeline()->update(); - } else { - // Find the first visible parent and update that to show hidden keyframes - RowTree *updateRow = m_rowTree->parentRow(); - while (updateRow && !updateRow->isVisible()) - updateRow = updateRow->parentRow(); - if (updateRow) - updateRow->rowTimeline()->update(); - } - } - } - update(); -} - -void RowTimeline::insertKeyframe(Keyframe *keyframe) -{ - if (!m_keyframes.contains(keyframe)) - m_keyframes.append(keyframe); -} - -void RowTimeline::removeKeyframe(Keyframe *keyframe) -{ - m_keyframes.removeAll(keyframe); -} - -void RowTimeline::putSelectedKeyframesOnTop() -{ - if (!m_keyframes.empty()) { - std::partition(m_keyframes.begin(), m_keyframes.end(), [](Keyframe *kf) { - return !kf->selected(); - }); - } - - if (m_rowTree->hasPropertyChildren()) { // has property rows - const auto childProps = m_rowTree->childProps(); - for (auto child : childProps) { - std::partition(child->rowTimeline()->m_keyframes.begin(), - child->rowTimeline()->m_keyframes.end(), [](Keyframe *kf) { - return !kf->selected(); - }); - } - } -} - -void RowTimeline::updateKeyframes() -{ - update(); - - if (m_rowTree->hasPropertyChildren()) { // master keyframes - const auto childProps = m_rowTree->childProps(); - for (const auto child : childProps) - child->rowTimeline()->update(); - } -} - -TimelineControlType RowTimeline::getClickedControl(const QPointF &scenePos) const -{ - if (!m_rowTree->hasDurationBar()) - return TimelineControlType::None; - - if (!m_rowTree->locked()) { - QPointF p = mapFromScene(scenePos.x(), scenePos.y()); - p.setX(p.x() - TimelineConstants::RULER_EDGE_OFFSET); - - const int halfHandle = TimelineConstants::DURATION_HANDLE_W * .5; - // Never choose start handle if end time is zero, as you cannot adjust it in that case - bool startHandle = p.x() > m_startX - halfHandle && p.x() < m_startX + halfHandle - && m_endTime > 0; - bool endHandle = p.x() > m_endX - halfHandle && p.x() < m_endX + halfHandle; - if (startHandle && endHandle) { - // If handles overlap, choose the handle based on the side of the click relative to start - startHandle = p.x() < m_startX; - endHandle = !startHandle; - } - if (startHandle) - return TimelineControlType::StartHandle; - else if (endHandle) - return TimelineControlType::EndHandle; - else if (p.x() > m_startX && p.x() < m_endX && !rowTree()->locked()) - return TimelineControlType::Duration; - } - - return TimelineControlType::None; -} - -void RowTimeline::startDurationMove(double clickX) -{ - // clickX is in ruler coordinate space - m_startDurationMoveStartTime = m_startTime; - m_startDurationMoveOffsetX = clickX - m_startX; -} - -void RowTimeline::updateBoundChildren(bool start) -{ - // Collect all bound children - // Children are considered bound if the start/end time matches the parent time - if (start) - m_boundChildrenStart.clear(); - else - m_boundChildrenEnd.clear(); - if (m_rowTree->hasDurationBar()) { - const auto childRows = m_rowTree->childRows(); - for (auto child : childRows) { - if (child->hasDurationBar() && !child->locked()) { - RowTimeline *rowTimeline = child->rowTimeline(); - if (start && rowTimeline->m_startX == m_startX) { - m_boundChildrenStart.append(rowTimeline); - rowTimeline->updateBoundChildren(start); - } else if (!start && rowTimeline->m_endX == m_endX) { - m_boundChildrenEnd.append(rowTimeline); - rowTimeline->updateBoundChildren(start); - } - } - } - } -} - -void RowTimeline::clearBoundChildren() -{ - m_boundChildrenStart.clear(); - m_boundChildrenEnd.clear(); -} - -// move the duration area (start/end x) -void RowTimeline::moveDurationBy(double dx) -{ - if (m_startX + dx < 0) - dx = -m_startX; - - m_startX += dx; - m_endX += dx; - - if (!m_rowTree->parentRow() || m_rowTree->objectType() == OBJTYPE_LAYER - || m_rowTree->hasComponentAncestor()) { - m_minStartX = m_startX; - m_maxEndX = m_endX; - } - - Ruler *ruler = m_rowTree->m_scene->ruler(); - m_startTime = ruler->distanceToTime(m_startX); - m_endTime = ruler->distanceToTime(m_endX); - - // move keyframes with the row - if (!m_rowTree->isProperty()) { // make sure we don't move the keyframes twice - for (Keyframe *keyframe : qAsConst(m_keyframes)) - keyframe->time += rowTree()->m_scene->ruler()->distanceToTime(dx); - } - - update(); - - if (!m_rowTree->empty()) { - updateChildrenMinStartXRecursive(m_rowTree); - updateChildrenMaxEndXRecursive(m_rowTree); - - for (RowTree *child : qAsConst(m_rowTree->m_childRows)) { - if (!child->locked()) - child->m_rowTimeline->moveDurationBy(dx); - } - } -} - -void RowTimeline::moveDurationTo(double newX) -{ - if (newX < 0) - newX = 0; - - double dx = newX - m_startX; - double durationX = m_endX - m_startX; - - m_startX = newX; - m_endX = m_startX + durationX; - - if (!m_rowTree->parentRow() || m_rowTree->objectType() == OBJTYPE_LAYER - || m_rowTree->hasComponentAncestor()) { - m_minStartX = m_startX; - m_maxEndX = m_endX; - } - - Ruler *ruler = m_rowTree->m_scene->ruler(); - m_startTime = ruler->distanceToTime(m_startX); - m_endTime = ruler->distanceToTime(m_endX); - - // move keyframes with the row - if (!m_rowTree->isProperty()) { // make sure we don't move the keyframes twice - for (Keyframe *keyframe : qAsConst(m_keyframes)) - keyframe->time += ruler->distanceToTime(dx); - } - - update(); - - if (!m_rowTree->empty()) { - updateChildrenMinStartXRecursive(m_rowTree); - updateChildrenMaxEndXRecursive(m_rowTree); - - for (RowTree *child : qAsConst(m_rowTree->m_childRows)) { - if (!child->locked()) - child->m_rowTimeline->moveDurationBy(dx); - } - } -} - -long RowTimeline::getDurationMoveTime() const -{ - return m_startTime - m_startDurationMoveStartTime; -} - -double RowTimeline::getDurationMoveOffsetX() const -{ - return m_startDurationMoveOffsetX; -} - -long RowTimeline::getDuration() const -{ - return m_endTime - m_startTime; -} - -void RowTimeline::collectChildKeyframeTimes(QVector<long> &childKeyframeTimes) -{ - const auto childRows = m_rowTree->childRows(); - for (const auto row : childRows) { - row->rowTimeline()->collectChildKeyframeTimes(childKeyframeTimes); - const auto keyframes = row->rowTimeline()->keyframes(); - for (const auto kf : keyframes) - childKeyframeTimes.append(kf->time); - } -} - -// called after timeline scale is changed to update duration star/end positions -void RowTimeline::updatePosition() -{ - clearBoundChildren(); - setStartTime(m_startTime); - setEndTime(m_endTime); -} - -// Set the position of the start of the row duration -void RowTimeline::setStartX(double startX) -{ - if (startX < 0) - startX = 0; - else if (startX > m_endX) - startX = m_endX; - - m_startX = startX; - m_startTime = m_rowTree->m_scene->ruler()->distanceToTime(startX); - - if (!m_rowTree->parentRow() || m_rowTree->parentRow()->objectType() == OBJTYPE_SCENE - || m_rowTree->hasComponentAncestor()) { - m_minStartX = 0; - } - - updateChildrenStartRecursive(); - updateChildrenMinStartXRecursive(m_rowTree); - update(); -} - -// Set the position of the end of the row duration -void RowTimeline::setEndX(double endX) -{ - if (endX < m_startX) - endX = m_startX; - - m_endX = endX; - m_endTime = m_rowTree->m_scene->ruler()->distanceToTime(endX); - - if (!m_rowTree->parentRow() || m_rowTree->parentRow()->objectType() == OBJTYPE_SCENE - || m_rowTree->hasComponentAncestor()) { - m_maxEndX = 999999; - } - - updateChildrenEndRecursive(); - updateChildrenMaxEndXRecursive(m_rowTree); - update(); -} - -QColor RowTimeline::barColor() const -{ - return m_barColor; -} - -void RowTimeline::setBarColor(const QColor &color) -{ - m_barColor = color; - update(); -} - -void RowTimeline::setControllerText(const QString &controller) -{ - m_controllerDataInput = controller; - update(); -} - -void RowTimeline::updateChildrenStartRecursive() -{ - for (auto child : qAsConst(m_boundChildrenStart)) { - if (!child.isNull()) { - child->m_startX = m_startX; - child->m_startTime = m_startTime; - child->updateChildrenStartRecursive(); - child->update(); - } - } -} - -void RowTimeline::updateChildrenEndRecursive() -{ - for (auto child : qAsConst(m_boundChildrenEnd)) { - if (!child.isNull()) { - child->m_endX = m_endX; - child->m_endTime = m_endTime; - child->updateChildrenEndRecursive(); - child->update(); - } - } -} - -void RowTimeline::updateChildrenMinStartXRecursive(RowTree *rowTree) -{ - if (m_rowTree->objectType() != OBJTYPE_SCENE && !rowTree->empty()) { - const auto childRows = rowTree->childRows(); - bool isComponentChild = m_rowTree->objectType() == OBJTYPE_COMPONENT - || m_rowTree->hasComponentAncestor(); - for (auto child : childRows) { - if (isComponentChild) { - child->rowTimeline()->m_minStartX = 0; - } else { - child->rowTimeline()->m_minStartX = qMax(rowTree->rowTimeline()->m_startX, - rowTree->rowTimeline()->m_minStartX); - } - child->rowTimeline()->update(); - - updateChildrenMinStartXRecursive(child); - } - } -} - -void RowTimeline::updateChildrenMaxEndXRecursive(RowTree *rowTree) -{ - if (m_rowTree->objectType() != OBJTYPE_SCENE && !rowTree->empty()) { - const auto childRows = rowTree->childRows(); - bool isComponentChild = m_rowTree->objectType() == OBJTYPE_COMPONENT - || m_rowTree->hasComponentAncestor(); - for (auto child : childRows) { - if (isComponentChild) { - child->rowTimeline()->m_maxEndX = 999999; - } else { - child->rowTimeline()->m_maxEndX = qMin(rowTree->rowTimeline()->m_endX, - rowTree->rowTimeline()->m_maxEndX); - } - child->rowTimeline()->update(); - - updateChildrenMaxEndXRecursive(child); - } - } -} - -void RowTimeline::updateCommentItem() -{ - if (!m_commentItem) - return; - TimelineToolbar *toolbar = m_rowTree->m_scene->widgetTimeline()->toolbar(); - // Backend allows storing comments for rows with duration bar - bool canHaveComment = m_rowTree->hasDurationBar(); - bool showComments = canHaveComment && toolbar->actionShowRowTexts()->isChecked(); - m_commentItem->setVisible(showComments); - if (showComments && m_rowTree->m_binding) { - ITimelineTimebar *timebar = m_rowTree->m_binding->GetTimelineItem()->GetTimebar(); - m_commentItem->setLabel(timebar->GetTimebarComment()); - } -} - -void RowTimeline::updateCommentItemPos() -{ - if (!m_commentItem) - return; - - Ruler *ruler = m_rowTree->m_scene->ruler(); - m_commentItem->setPos(TimelineConstants::RULER_EDGE_OFFSET + ruler->viewportX(), - -TimelineConstants::ROW_TEXT_OFFSET_Y); -} - -void RowTimeline::setStartTime(long startTime) -{ - m_startTime = startTime; - m_startX = m_rowTree->m_scene->ruler()->timeToDistance(startTime); - - if (!m_rowTree->parentRow() || m_rowTree->parentRow()->objectType() == OBJTYPE_SCENE - || m_rowTree->hasComponentAncestor()) { - m_minStartX = 0; - } - - updateChildrenStartRecursive(); - updateChildrenMinStartXRecursive(m_rowTree); - update(); -} - -void RowTimeline::setEndTime(long endTime) -{ - m_endTime = endTime; - m_endX = m_rowTree->m_scene->ruler()->timeToDistance(endTime); - - if (!m_rowTree->parentRow() || m_rowTree->parentRow()->objectType() == OBJTYPE_SCENE - || m_rowTree->hasComponentAncestor()) { - m_maxEndX = 999999; - } - - updateChildrenEndRecursive(); - updateChildrenMaxEndXRecursive(m_rowTree); - update(); -} - -// duration start x in local space (x=0 at time=0) -double RowTimeline::getStartX() const -{ - return m_startX; -} - -// duration end x in local space -double RowTimeline::getEndX() const -{ - return m_endX; -} - -long RowTimeline::getStartTime() const -{ - return m_startTime; -} - -long RowTimeline::getEndTime() const -{ - return m_endTime; -} - -void RowTimeline::setState(State state) -{ - m_state = state; - m_rowTree->m_state = state; - - update(); - m_rowTree->update(); -} - -void RowTimeline::setRowTree(RowTree *rowTree) -{ - m_rowTree = rowTree; - if (m_rowTree->isProperty()) { - if (m_propertyGraph) - delete m_propertyGraph; - m_propertyGraph = new RowTimelinePropertyGraph(this); - } - initialize(); -} - -RowTree *RowTimeline::rowTree() const -{ - return m_rowTree; -} - -QList<Keyframe *> RowTimeline::keyframes() const -{ - return m_keyframes; -} - -QString RowTimeline::formatTime(long millis) const -{ - static const QString timeTemplate = tr("%1:%2.%3"); - static const QChar fillChar = tr("0").at(0); - - long mins = millis % 3600000 / 60000; - long secs = millis % 60000 / 1000; - long mils = millis % 1000; - - return timeTemplate.arg(mins).arg(secs, 2, 10, fillChar).arg(mils, 3, 10, fillChar); -} - -void RowTimeline::showToolTip(const QPointF &pos) -{ - QLabel *tooltip = m_rowTree->m_scene->timebarTooltip(); - - tooltip->setText(formatTime(m_startTime) + " - " + formatTime(m_endTime) - + " (" + formatTime(m_endTime - m_startTime) + ")"); - - tooltip->adjustSize(); - - QPoint newPos = pos.toPoint() + QPoint(-tooltip->width() / 2, - -tooltip->height() - TimelineConstants::TIMEBAR_TOOLTIP_OFFSET_V); - - // Confine the tooltip to the current screen area to avoid artifacts from different pixel ratios - static const int MARGIN = 5; - const QRect screenGeometry = QApplication::desktop()->screenGeometry( - m_rowTree->m_scene->widgetTimeline()); - int xMin = screenGeometry.x() + MARGIN; - int xMax = screenGeometry.x() + screenGeometry.width() - tooltip->width() - MARGIN; - if (newPos.x() < xMin) - newPos.setX(xMin); - else if (newPos.x() > xMax) - newPos.setX(xMax); - - tooltip->move(newPos); - tooltip->raise(); - tooltip->show(); -} - -RowTimeline *RowTimeline::parentRow() const -{ - if (!m_rowTree->m_parentRow) - return nullptr; - - return m_rowTree->m_parentRow->rowTimeline(); -} - -void RowTimeline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) -{ - InteractiveTimelineItem::hoverLeaveEvent(event); - // Make sure mouse cursor is reseted when moving away from timeline row - m_rowTree->m_scene->resetMouseCursor(); -} - -int RowTimeline::type() const -{ - // Enable the use of qgraphicsitem_cast with this item. - return TypeRowTimeline; -} diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.h deleted file mode 100644 index 00c81696..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.h +++ /dev/null @@ -1,126 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef ROWTIMELINE_H -#define ROWTIMELINE_H - -#include "InteractiveTimelineItem.h" -#include "RowTypes.h" -#include "Bindings/Qt3DSDMTimelineItemProperty.h" -#include <QtCore/qpointer.h> -#include "RowTimelineCommentItem.h" - -class RowTree; -class RowTimelinePropertyGraph; -struct Keyframe; - -class RowTimeline : public InteractiveTimelineItem -{ - Q_OBJECT - -public: - explicit RowTimeline(); - ~RowTimeline(); - - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) override; - void setState(State state) override; - void setRowTree(RowTree *rowTree); - void updatePosition(); - void startDurationMove(double clickX); - void updateBoundChildren(bool start); - void clearBoundChildren(); - void moveDurationBy(double dx); - void moveDurationTo(double newX); - void setStartTime(long startTime); - void setEndTime(long endTime); - void setStartX(double startX); - void setEndX(double endX); - void setBarColor(const QColor &color); - void setControllerText(const QString &controller); - void putSelectedKeyframesOnTop(); - void updateKeyframes(); - void insertKeyframe(Keyframe *keyframe); - void removeKeyframe(Keyframe *keyframe); - void updateKeyframesFromBinding(const QList<int> &properties); - void updateDurationFromBinding(); - TimelineControlType getClickedControl(const QPointF &scenePos) const; - double getStartX() const; - double getEndX() const; - long getStartTime() const; - long getEndTime() const; - long getDurationMoveTime() const; // the time a row duration has moved (to commit to binding) - double getDurationMoveOffsetX() const; - long getDuration() const; - QColor barColor() const; - int type() const override; - RowTimeline *parentRow() const; - RowTree *rowTree() const; - Keyframe *getClickedKeyframe(const QPointF &scenePos); - QList<Keyframe *> getKeyframesInRange(const QRectF &rect) const; - QList<Keyframe *> keyframes() const; - void showToolTip(const QPointF &pos); - -protected: - void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; - -private: - void initialize(); - void updateChildrenStartRecursive(); - void updateChildrenEndRecursive(); - void updateChildrenMinStartXRecursive(RowTree *rowTree); - void updateChildrenMaxEndXRecursive(RowTree *rowTree); - void updateCommentItem(); - void updateCommentItemPos(); - void drawColorPropertyGradient(QPainter *painter, int width); - bool isColorProperty() const; - QString formatTime(long millis) const; - void collectChildKeyframeTimes(QVector<long> &childKeyframeTimes); - - RowTree *m_rowTree; - RowTimelinePropertyGraph *m_propertyGraph = nullptr; - RowTimelineCommentItem *m_commentItem = nullptr; - long m_startTime = 0; - long m_startDurationMoveStartTime = 0; - double m_startDurationMoveOffsetX = 0; - long m_endTime = 0; - double m_startX = 0; - double m_endX = 0; - double m_minStartX = 0; - double m_maxEndX = 0; - bool m_isProperty = false; // used in the destructor - QString m_controllerDataInput; - QList<Keyframe *> m_keyframes; - QColor m_barColor; - QVector<QPointer<RowTimeline>> m_boundChildrenStart; - QVector<QPointer<RowTimeline>> m_boundChildrenEnd; - - friend class RowTree; -}; - -#endif // ROWTIMELINE_H diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineCommentItem.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineCommentItem.cpp deleted file mode 100644 index 1bfb7163..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineCommentItem.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** -** -** 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 "RowTimelineCommentItem.h" -#include "TimelineConstants.h" -#include "TimelineItem.h" -#include "RowTree.h" -#include "StudioPreferences.h" - -#include <QtWidgets/qstyleoption.h> -#include <QtGui/qevent.h> -#include <QtGui/qtextcursor.h> -#include <QtGui/qpainter.h> -#include <QtGui/qtextoption.h> -#include <QtGui/qtextdocument.h> - -static const int MAX_COMMENT_SIZE = 2000; // Should be enough - -RowTimelineCommentItem::RowTimelineCommentItem(QGraphicsItem *parent) - : QGraphicsTextItem(parent) - , m_acceptOnFocusOut(true) -{ - setTextInteractionFlags(Qt::TextEditorInteraction); - setTextWidth(MAX_COMMENT_SIZE); - setDefaultTextColor(CStudioPreferences::textColor()); - setVisible(false); -} - -QString RowTimelineCommentItem::label() const -{ - return m_label; -} - -void RowTimelineCommentItem::setLabel(const QString &label) -{ - setPlainText(label); - if (m_label != label) { - m_label = label; - emit labelChanged(m_label); - } -} - -RowTree *RowTimelineCommentItem::parentRow() const -{ - return m_rowTree; -} - -void RowTimelineCommentItem::setParentRow(RowTree *row) -{ - m_rowTree = row; -} - -int RowTimelineCommentItem::type() const -{ - // Enable the use of qgraphicsitem_cast with this item. - return TimelineItem::TypeRowTimelineCommentItem; -} - -void RowTimelineCommentItem::paint(QPainter *painter, - const QStyleOptionGraphicsItem *option, - QWidget *widget) -{ - // prevents flickering when the row is just inserted to the layout - if (m_rowTree && !m_rowTree->y()) - return; - - // Paint background - QRectF r = boundingRect(); - r.adjust(-TimelineConstants::RULER_EDGE_OFFSET, - TimelineConstants::ROW_TEXT_OFFSET_Y, 0, - TimelineConstants::ROW_TEXT_OFFSET_Y); - painter->fillRect(r, CStudioPreferences::timelineRowCommentBgColor()); - - // Remove the HasFocus style state, to prevent the dotted line from being drawn. - QStyleOptionGraphicsItem *style = const_cast<QStyleOptionGraphicsItem *>(option); - style->state &= ~QStyle::State_HasFocus; - - QGraphicsTextItem::paint(painter, option, widget); -} - -void RowTimelineCommentItem::focusOutEvent(QFocusEvent *event) -{ - if (m_acceptOnFocusOut) - validateLabel(); - else - setPlainText(m_label); - - // Remove possible selection - QTextCursor cursor = textCursor(); - cursor.clearSelection(); - setTextCursor(cursor); - QGraphicsTextItem::focusOutEvent(event); - // Next time default to accepting - m_acceptOnFocusOut = true; -} - -void RowTimelineCommentItem::keyPressEvent(QKeyEvent *event) -{ - int key = event->key(); - if (key == Qt::Key_Return || key == Qt::Key_Enter) { - m_acceptOnFocusOut = true; - clearFocus(); - event->accept(); - return; - } else if (key == Qt::Key_Escape) { - m_acceptOnFocusOut = false; - clearFocus(); - event->accept(); - return; - } - - QGraphicsTextItem::keyPressEvent(event); -} - -QRectF RowTimelineCommentItem::boundingRect() const -{ - return QRectF(0, 0, parentItem()->boundingRect().width(), - TimelineConstants::ROW_H); -} - -void RowTimelineCommentItem::validateLabel() -{ - QString text = toPlainText().trimmed(); - text = text.left(MAX_COMMENT_SIZE); - setLabel(text); -} diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineCommentItem.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineCommentItem.h deleted file mode 100644 index 48c5065f..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineCommentItem.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef ROWTIMELINECOMMENTITEM_H -#define ROWTIMELINECOMMENTITEM_H - -#include "StudioObjectTypes.h" -#include <QtWidgets/qgraphicsitem.h> -#include <QtCore/qstring.h> -#include <QtWidgets/qgraphicssceneevent.h> -#include <QtGui/qevent.h> - -class RowTree; - -class RowTimelineCommentItem : public QGraphicsTextItem -{ - Q_OBJECT -public: - explicit RowTimelineCommentItem(QGraphicsItem *parent = nullptr); - - QString label() const; - void setLabel(const QString &label); - RowTree *parentRow() const; - void setParentRow(RowTree *row); - int type() const override; - -protected: - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; - void focusOutEvent(QFocusEvent *event) override; - void keyPressEvent(QKeyEvent *event) override; - QRectF boundingRect() const override; - -signals: - void labelChanged(const QString label); - -private: - void validateLabel(); - - RowTree *m_rowTree = nullptr; - QString m_label; - bool m_acceptOnFocusOut; - -}; - -#endif // ROWTIMELINECOMMENTITEM_H diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp deleted file mode 100644 index 7861bb19..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp +++ /dev/null @@ -1,275 +0,0 @@ -/**************************************************************************** -** -** 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 "RowTimelineContextMenu.h" -#include "RowTree.h" -#include "Keyframe.h" -#include "KeyframeManager.h" -#include "MainFrm.h" -#include "StudioApp.h" -#include "TimelineControl.h" -#include "Bindings/ITimelineItemBinding.h" -#include "TimelineGraphicsScene.h" -#include "TimelineToolbar.h" - -RowTimelineContextMenu::RowTimelineContextMenu(RowTree *inRowTree, - KeyframeManager *inKeyframeManager, - QGraphicsSceneContextMenuEvent *inEvent, - TimelineControl *timelineControl, - QWidget *parent) - : QMenu(parent) - , m_rowTree(inRowTree) - , m_keyframeManager(inKeyframeManager) - , m_menuEvent(inEvent) - , m_timelineControl(timelineControl) -{ - initialize(); -} - -RowTimelineContextMenu::~RowTimelineContextMenu() -{ -} - -void RowTimelineContextMenu::initialize() -{ - m_insertKeyframeAction = new QAction(tr("Insert Keyframe"), this); - m_insertKeyframeAction->setShortcut(Qt::Key_S); - m_insertKeyframeAction->setShortcutVisibleInContextMenu(true); - connect(m_insertKeyframeAction, &QAction::triggered, this, - &RowTimelineContextMenu::insertKeyframe); - addAction(m_insertKeyframeAction); - - m_cutSelectedKeyframesAction = new QAction(tr("Cut Selected Keyframe"), this); - m_cutSelectedKeyframesAction->setShortcut(QKeySequence(Qt::ControlModifier | Qt::Key_X)); - m_cutSelectedKeyframesAction->setShortcutVisibleInContextMenu(true); - connect(m_cutSelectedKeyframesAction, &QAction::triggered, this, - &RowTimelineContextMenu::cutSelectedKeyframes); - addAction(m_cutSelectedKeyframesAction); - - m_copySelectedKeyframesAction = new QAction(tr("Copy Selected Keyframe"), this); - m_copySelectedKeyframesAction->setShortcut(QKeySequence(Qt::ControlModifier | Qt::Key_C)); - m_copySelectedKeyframesAction->setShortcutVisibleInContextMenu(true); - connect(m_copySelectedKeyframesAction, &QAction::triggered, this, - &RowTimelineContextMenu::copySelectedKeyframes); - addAction(m_copySelectedKeyframesAction); - - m_pasteKeyframesAction = new QAction(tr("Paste Keyframes"), this); - m_pasteKeyframesAction->setShortcut(QKeySequence(Qt::ControlModifier | Qt::Key_V)); - m_pasteKeyframesAction->setShortcutVisibleInContextMenu(true); - connect(m_pasteKeyframesAction, &QAction::triggered, this, - &RowTimelineContextMenu::pasteKeyframes); - addAction(m_pasteKeyframesAction); - - m_deleteSelectedKeyframesAction = new QAction(tr("Delete Selected Keyframe"), this); - m_deleteSelectedKeyframesAction->setShortcut(Qt::Key_Delete); - m_deleteSelectedKeyframesAction->setShortcutVisibleInContextMenu(true); - connect(m_deleteSelectedKeyframesAction, &QAction::triggered, this, - &RowTimelineContextMenu::deleteSelectedKeyframes); - addAction(m_deleteSelectedKeyframesAction); - - m_deleteRowKeyframesAction = new QAction(tr("Delete All Channel Keyframes"), this); - m_deleteRowKeyframesAction->setShortcut( - QKeySequence(Qt::ControlModifier | Qt::AltModifier | Qt::Key_K)); - m_deleteRowKeyframesAction->setShortcutVisibleInContextMenu(true); - connect(m_deleteRowKeyframesAction, &QAction::triggered, this, - &RowTimelineContextMenu::deleteRowKeyframes); - addAction(m_deleteRowKeyframesAction); - - m_keyframe = m_rowTree->rowTimeline()->getClickedKeyframe(m_menuEvent->scenePos()); - bool ctrlPressed = m_menuEvent->modifiers() & Qt::ControlModifier; - if (m_keyframe) { - if (!m_keyframe->selected() && !ctrlPressed) - m_keyframeManager->deselectAllKeyframes(); - - m_keyframeManager->selectKeyframe(m_keyframe); - } else { - m_keyframeManager->deselectAllKeyframes(); - } - - if (m_rowTree->rowTimeline()->keyframes().size()) { - m_hasDynamicKeyframes = m_keyframeManager->hasDynamicKeyframes(m_rowTree); - QString label; - if (m_hasDynamicKeyframes) - label = tr("Make Animations Static"); - else - label = tr("Make Animations Dynamic"); - - m_dynamicKeyframesAction = new QAction(label, this); - connect(m_dynamicKeyframesAction, &QAction::triggered, this, - &RowTimelineContextMenu::toggleDynamicKeyframes); - addAction(m_dynamicKeyframesAction); - } - - addSeparator(); - - if (m_keyframe) { - m_setInterpolationAction = new QAction(tr("Set Interpolation..."), this); - m_setInterpolationAction->setShortcut(Qt::Key_I); - m_setInterpolationAction->setShortcutVisibleInContextMenu(true); - connect(m_setInterpolationAction, &QAction::triggered, this, - &RowTimelineContextMenu::setInterpolation); - addAction(m_setInterpolationAction); - - m_setKeyframeTimeAction = new QAction(tr("Set Keyframe Time..."), this); - connect(m_setKeyframeTimeAction, &QAction::triggered, this, - &RowTimelineContextMenu::setKeyframeTime); - addAction(m_setKeyframeTimeAction); - } else { - m_setTimeBarColorAction = new QAction(tr("Change Time Bar Color..."), this); - connect(m_setTimeBarColorAction, &QAction::triggered, this, - &RowTimelineContextMenu::changeTimeBarColor); - addAction(m_setTimeBarColorAction); - - m_setTimeBarTimeAction = new QAction(tr("Set Time Bar Time..."), this); - m_setTimeBarTimeAction->setShortcut(QKeySequence(Qt::ShiftModifier | Qt::Key_T)); - m_setTimeBarTimeAction->setShortcutVisibleInContextMenu(true); - connect(m_setTimeBarTimeAction, &QAction::triggered, this, - &RowTimelineContextMenu::setTimeBarTime); - addAction(m_setTimeBarTimeAction); - - QAction *showRowTextsAction - = m_rowTree->m_scene->widgetTimeline()->toolbar()->actionShowRowTexts(); - showRowTextsAction->setShortcutVisibleInContextMenu(true); - addAction(showRowTextsAction); - } -} - -void RowTimelineContextMenu::showEvent(QShowEvent *event) -{ - bool propRow = m_rowTree->isProperty(); - bool hasPropRows = m_rowTree->hasPropertyChildren(); - - m_insertKeyframeAction->setEnabled(!m_keyframe && (propRow || hasPropRows)); - m_cutSelectedKeyframesAction->setEnabled(m_keyframeManager->oneMasterRowSelected()); - m_copySelectedKeyframesAction->setEnabled(m_keyframeManager->oneMasterRowSelected()); - m_pasteKeyframesAction->setEnabled(m_keyframeManager->hasCopiedKeyframes()); - m_deleteSelectedKeyframesAction->setEnabled(m_keyframeManager->hasSelectedKeyframes()); - m_deleteRowKeyframesAction->setEnabled(!m_rowTree->rowTimeline()->keyframes().empty()); - if (!m_keyframe) { - m_setTimeBarColorAction->setEnabled(m_rowTree->hasDurationBar()); - m_setTimeBarTimeAction->setEnabled(m_rowTree->hasDurationBar()); - } - - QMenu::showEvent(event); -} - -void RowTimelineContextMenu::insertKeyframe() -{ - RowTree *destinationRowTree = nullptr; - if (m_rowTree->isProperty()) { - // When inserting into a property, insert actually into - // its parent rowtree - destinationRowTree = m_rowTree->parentRow(); - } else { - destinationRowTree = m_rowTree; - } - - destinationRowTree->getBinding()->InsertKeyframe(); -} - -void RowTimelineContextMenu::cutSelectedKeyframes() -{ - m_keyframeManager->copySelectedKeyframes(); - m_keyframeManager->deleteSelectedKeyframes(); -} - -void RowTimelineContextMenu::copySelectedKeyframes() -{ - m_keyframeManager->copySelectedKeyframes(); -} - -void RowTimelineContextMenu::pasteKeyframes() -{ - m_keyframeManager->pasteKeyframes(); -} - -void RowTimelineContextMenu::deleteSelectedKeyframes() -{ - m_keyframeManager->deleteSelectedKeyframes(); -} - -void RowTimelineContextMenu::deleteRowKeyframes() -{ - RowTree *destinationRowTree = nullptr; - if (m_rowTree->isProperty()) { - // Can't delete nicely just from property, so get the actual object row - destinationRowTree = m_rowTree->parentRow(); - } else { - destinationRowTree = m_rowTree; - } - destinationRowTree->getBinding()->DeleteAllChannelKeyframes(); -} - -void RowTimelineContextMenu::setInterpolation() -{ - m_keyframeManager->SetKeyframeInterpolation(); -} - -void RowTimelineContextMenu::setKeyframeTime() -{ - m_keyframeManager->SetKeyframeTime(m_keyframe->time); -} - -void RowTimelineContextMenu::changeTimeBarColor() -{ - g_StudioApp.m_pMainWnd->OnTimelineSetTimeBarColor(); -} - -void RowTimelineContextMenu::setTimeBarTime() -{ - if (m_timelineControl) { - m_timelineControl->setRowTimeline(m_rowTree->rowTimeline()); - m_timelineControl->showDurationEditDialog(); - } -} - -void RowTimelineContextMenu::toggleDynamicKeyframes() -{ - QList<Keyframe *> selectedKeyframes = m_keyframeManager->selectedKeyframes(); - - if (selectedKeyframes.isEmpty()) { - // If property row is clicked, only make that property's first keyframe dynamic. - // Otherwise make all properties' first keyframes dynamic - // Note that it doesn't matter which keyframe we make dynamic, as the dynamic keyframe will - // automatically change to the first one in time order. - QList<Keyframe *> keyframes; - if (m_rowTree->isProperty()) { - keyframes.append(m_rowTree->rowTimeline()->keyframes().first()); - } else { - const auto childProps = m_rowTree->childProps(); - for (const auto prop : childProps) - keyframes.append(prop->rowTimeline()->keyframes().first()); - } - m_keyframeManager->selectKeyframes(keyframes); - } - - m_keyframeManager->SetKeyframesDynamic(!m_hasDynamicKeyframes); - - if (selectedKeyframes.isEmpty()) - m_keyframeManager->deselectAllKeyframes(); -} diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.h deleted file mode 100644 index b8c2f922..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.h +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef ROWTIMELINECONTEXTMENU_H -#define ROWTIMELINECONTEXTMENU_H - -#include <QtWidgets/qmenu.h> -#include <QtWidgets/qaction.h> -#include <QtWidgets/qgraphicssceneevent.h> - -class RowTree; -class KeyframeManager; -class TimelineControl; -struct Keyframe; - -class RowTimelineContextMenu : public QMenu -{ - Q_OBJECT -public: - explicit RowTimelineContextMenu(RowTree *inRowTree, - KeyframeManager *inKeyframeManager, - QGraphicsSceneContextMenuEvent *inEvent, - TimelineControl *timelineControl, - QWidget *parent = nullptr); - virtual ~RowTimelineContextMenu(); - -protected: - void showEvent(QShowEvent *event) override; - -private: - void initialize(); - void insertKeyframe(); - void cutSelectedKeyframes(); - void copySelectedKeyframes(); - void pasteKeyframes(); - void deleteSelectedKeyframes(); - void deleteRowKeyframes(); - void setInterpolation(); - void setKeyframeTime(); - void changeTimeBarColor(); - void setTimeBarTime(); - void toggleDynamicKeyframes(); - - RowTree *m_rowTree = nullptr; - Keyframe *m_keyframe = nullptr; - KeyframeManager *m_keyframeManager = nullptr; - QGraphicsSceneContextMenuEvent *m_menuEvent = nullptr; - QAction *m_insertKeyframeAction = nullptr; - QAction *m_cutSelectedKeyframesAction = nullptr; - QAction *m_copySelectedKeyframesAction = nullptr; - QAction *m_pasteKeyframesAction = nullptr; - QAction *m_deleteSelectedKeyframesAction = nullptr; - QAction *m_deleteRowKeyframesAction = nullptr; - QAction *m_setInterpolationAction = nullptr; - QAction *m_setKeyframeTimeAction = nullptr; - QAction *m_setTimeBarColorAction = nullptr; - QAction *m_setTimeBarTimeAction = nullptr; - QAction *m_dynamicKeyframesAction = nullptr; - TimelineControl *m_timelineControl = nullptr; - bool m_hasDynamicKeyframes = false; -}; - -#endif // ROWTIMELINECONTEXTMENU_H diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp deleted file mode 100644 index 3c82d73b..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** 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 "RowTimelinePropertyGraph.h" -#include "RowTimeline.h" -#include "RowTree.h" -#include "Ruler.h" -#include "TimelineGraphicsScene.h" -#include "Bindings/ITimelineItemProperty.h" - -RowTimelinePropertyGraph::RowTimelinePropertyGraph(QObject *parent) - : QObject(parent) -{ - m_rowTimeline = static_cast<RowTimeline *>(parent); -} - -void RowTimelinePropertyGraph::paintGraphs(QPainter *painter, const QRectF &rect) -{ - m_rect = rect; - m_propBinding = m_rowTimeline->rowTree()->propBinding(); - - // Animate alpha 0..255 while expanding - int alpha = 255 * (m_rect.height() - TimelineConstants::ROW_H) - / (TimelineConstants::ROW_H_EXPANDED - TimelineConstants::ROW_H); - alpha = std::max(0, alpha); - - if (alpha == 0) - return; - - // Available line colors - QColor colors[6] = { QColor(255, 0, 0, alpha), QColor(0, 255, 0, alpha), - QColor(0, 0, 255, alpha), QColor(255, 255, 0, alpha), - QColor(255, 0, 255, alpha), QColor(0, 255, 255, alpha) }; - - long channelCount = m_propBinding->GetChannelCount(); - - // Don't want to overflow the color array - if (channelCount <= 6) { - // For each channel graph it. - for (long i = 0; i < channelCount; ++i) - paintSingleChannel(painter, i, colors[i]); - } -} - -void RowTimelinePropertyGraph::paintSingleChannel(QPainter *painter, long inChannelIndex, - const QColor &inColor) -{ - float maxVal = m_propBinding->GetMaximumValue(); - float minVal = m_propBinding->GetMinimumValue(); - - double timelineScale = m_rowTimeline->rowTree()->m_scene->ruler()->timelineScale(); - - // Step in pixels - int interval = 5; - // Margin at top & bottom of graph - float marginY = 10; - float graphY = m_rect.y() + marginY; - float graphHeight = m_rect.height() - marginY * 2; - - QPainterPath path; - for (int i = 0; i < m_rect.width(); i += interval) { - // Value time in ms - long time = i / (TimelineConstants::RULER_MILLI_W * timelineScale); - float value = m_propBinding->GetChannelValueAtTime(inChannelIndex, time); - float yPos = graphY + (1.0 - (value - minVal) / (maxVal - minVal)) * graphHeight; - - if (i == 0) - path.moveTo(m_rect.x() + i, yPos); - else - path.lineTo(m_rect.x() + i, yPos); - } - - painter->setPen(QPen(inColor, 2)); - painter->drawPath(path); -} diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.h deleted file mode 100644 index 275c24e2..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.h +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef ROWTIMELINEPROPERTYGRAPH_H -#define ROWTIMELINEPROPERTYGRAPH_H - -#include <QtCore/qobject.h> -#include <QtGui/qpainter.h> - -class RowTimeline; -class ITimelineItemProperty; - -class RowTimelinePropertyGraph : public QObject -{ - Q_OBJECT -public: - explicit RowTimelinePropertyGraph(QObject *parent = nullptr); - void paintGraphs(QPainter *painter, const QRectF &rect); - -private: - void paintSingleChannel(QPainter *painter, long inChannelIndex, - const QColor &inColor); - - RowTimeline *m_rowTimeline = nullptr; - ITimelineItemProperty *m_propBinding = nullptr; - QRectF m_rect; -}; - -#endif // ROWTIMELINEPROPERTYGRAPH_H diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.cpp deleted file mode 100644 index e15258cd..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.cpp +++ /dev/null @@ -1,1337 +0,0 @@ -/**************************************************************************** -** -** 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 "RowTree.h" -#include "RowTimeline.h" -#include "RowManager.h" -#include "TimelineConstants.h" -#include "StudioObjectTypes.h" -#include "TimelineGraphicsScene.h" -#include "Bindings/ITimelineItemBinding.h" -#include "Bindings/Qt3DSDMTimelineItemBinding.h" -#include "Qt3DSString.h" -#include "TreeHeader.h" -#include "StudioPreferences.h" -#include "KeyframeManager.h" -#include "StudioApp.h" -#include "MainFrm.h" -#include "Core.h" -#include "Doc.h" -#include "ClientDataModelBridge.h" -#include "Qt3DSDMStudioSystem.h" -#include "Qt3DSDMSlides.h" -#include "StudioUtils.h" -#include "TimelineToolbar.h" - -#include <QtGui/qpainter.h> -#include "QtGui/qtextcursor.h" -#include <QtWidgets/qgraphicslinearlayout.h> -#include <QtWidgets/qgraphicssceneevent.h> - -// object row constructor -RowTree::RowTree(TimelineGraphicsScene *timelineScene, EStudioObjectType objType, - const QString &label) - : m_rowTimeline(new RowTimeline()) - , m_scene(timelineScene) - , m_objectType(objType) - , m_label(label) -{ - CDoc *doc = g_StudioApp.GetCore()->GetDoc(); - m_onMasterSlide = doc->GetStudioSystem()->GetSlideSystem() - ->IsMasterSlide(doc->GetActiveSlide()); - - initialize(); -} - -// property row constructor -RowTree::RowTree(TimelineGraphicsScene *timelineScene, const QString &propType) - : InteractiveTimelineItem() - , m_rowTimeline(new RowTimeline()) - , m_isProperty(true) - , m_scene(timelineScene) - , m_propertyType(propType) - , m_label(propType) -{ - m_rowTimeline->m_isProperty = true; - - initialize(); -} - -RowTree::~RowTree() -{ - delete m_rowTimeline; // this will also delete the keyframes - m_rowTimeline = nullptr; -} - -ITimelineItemBinding *RowTree::getBinding() const -{ - return m_binding; -} - -// object instance handle - qt3dsdm::Qt3DSDMInstanceHandle RowTree::instance() const -{ - if (m_isProperty || !m_binding) - return 0; - - return static_cast<Qt3DSDMTimelineItemBinding *>(m_binding)->GetInstance(); -} - -void RowTree::initialize() -{ - setTimelineRow(m_rowTimeline); - m_rowTimeline->setRowTree(this); - - setMinimumWidth(TimelineConstants::TREE_BOUND_W); - - initializeAnimations(); - - m_labelItem.setParentItem(this); - m_labelItem.setParentRow(this); - m_labelItem.setLabel(m_label); - updateLabelPosition(); - - // Default all rows to collapsed - setRowVisible(false); - m_expandState = ExpandState::HiddenCollapsed; - - connect(&m_labelItem, &RowTreeLabelItem::labelChanged, this, - [this](const QString &label) { - // Update label on timeline and on model - m_label = label; - // TODO: Get rid of CString APIs - auto clabel = Q3DStudio::CString::fromQString(m_label); - m_binding->GetTimelineItem()->SetName(clabel); - }); -} - -void RowTree::initializeAnimations() -{ - // Init left side expand animations - m_expandHeightAnimation = new QPropertyAnimation(this, "maximumSize"); - m_expandHeightAnimation->setDuration(TimelineConstants::EXPAND_ANIMATION_DURATION); - m_expandAnimation.addAnimation(m_expandHeightAnimation); - m_expandOpacityAnimation = new QPropertyAnimation(this, "opacity"); - m_expandOpacityAnimation->setDuration(TimelineConstants::EXPAND_ANIMATION_DURATION / 3); - m_expandAnimation.addAnimation(m_expandOpacityAnimation); - - // Init right side expand animations - m_expandTimelineHeightAnimation = new QPropertyAnimation(m_rowTimeline, "maximumSize"); - m_expandTimelineHeightAnimation->setDuration(TimelineConstants::EXPAND_ANIMATION_DURATION); - m_expandAnimation.addAnimation(m_expandTimelineHeightAnimation); - m_expandTimelineOpacityAnimation = new QPropertyAnimation(m_rowTimeline, "opacity"); - m_expandTimelineOpacityAnimation->setDuration(TimelineConstants::EXPAND_ANIMATION_DURATION / 3); - m_expandAnimation.addAnimation(m_expandTimelineOpacityAnimation); - - connect(&m_expandAnimation, &QAbstractAnimation::stateChanged, - [this](const QAbstractAnimation::State newState) { - if (m_rowTimeline) { - if (newState == QAbstractAnimation::Running) { - setVisible(true); - m_rowTimeline->setVisible(true); - } else if (newState == QAbstractAnimation::Stopped) { - if (this->maximumHeight() == 0) { - setVisible(false); - m_rowTimeline->setVisible(false); - } - } - } - }); -} - -void RowTree::animateExpand(ExpandState state) -{ - int endHeight = 0; // hidden states - float endOpacity = 0; - if (state == ExpandState::Expanded) { - endHeight = m_isPropertyExpanded ? TimelineConstants::ROW_H_EXPANDED - : TimelineConstants::ROW_H; - endOpacity = 1; - } else if (state == ExpandState::Collapsed) { - endHeight = TimelineConstants::ROW_H; - endOpacity = 1; - } - // Changing end values while animation is running does not affect currently running animation, - // so let's make sure the animation is stopped first. - m_expandAnimation.stop(); - - m_expandHeightAnimation->setEndValue(QSizeF(size().width(), endHeight)); - m_expandTimelineHeightAnimation->setEndValue(QSizeF(m_rowTimeline->size().width(), - endHeight)); - m_expandOpacityAnimation->setEndValue(endOpacity); - m_expandTimelineOpacityAnimation->setEndValue(endOpacity); - - m_expandAnimation.start(); -} - -void RowTree::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - Q_UNUSED(option) - Q_UNUSED(widget) - - bool hiResIcons = StudioUtils::devicePixelRatio(widget->window()->windowHandle()) > 1.0; - - if (!y()) // prevents flickering when the row is just inserted to the layout - return; - - static const int ICON_SIZE = 16; - static const int LEFT_DIVIDER = 18; - const int offset = 5 + m_depth * TimelineConstants::ROW_DEPTH_STEP; - const int iconY = (TimelineConstants::ROW_H / 2) - (ICON_SIZE / 2); - - // update button bounds rects - m_rectArrow .setRect(offset, iconY, ICON_SIZE, ICON_SIZE); - m_rectType .setRect(offset + ICON_SIZE, iconY, ICON_SIZE, ICON_SIZE); - m_rectShy .setRect(treeWidth() - 16 * 3.3, iconY, ICON_SIZE, ICON_SIZE); - m_rectVisible.setRect(treeWidth() - 16 * 2.2, iconY, ICON_SIZE, ICON_SIZE); - m_rectLocked .setRect(treeWidth() - 16 * 1.1, iconY, ICON_SIZE, ICON_SIZE); - - // Background - QColor bgColor; - if (m_dndState == DnDState::Source) - bgColor = CStudioPreferences::timelineRowColorDndSource(); - else if (m_dndState == DnDState::SP_TARGET) - bgColor = CStudioPreferences::timelineRowColorDndTargetSP(); - else if (m_isProperty) - bgColor = CStudioPreferences::timelineRowColorNormalProp(); - else if (m_dndHover) - bgColor = CStudioPreferences::timelineRowColorDndTarget(); - else if (m_state == Selected) - bgColor = CStudioPreferences::timelineRowColorSelected(); - else if (m_state == Hovered && !m_locked) - bgColor = CStudioPreferences::timelineRowColorOver(); - else - bgColor = CStudioPreferences::timelineRowColorNormal(); - - painter->fillRect(QRect(0, 0, size().width(), size().height() - 1), bgColor); - - // left divider - painter->setPen(CStudioPreferences::timelineWidgetBgColor()); - painter->drawLine(LEFT_DIVIDER, 0, LEFT_DIVIDER, size().height() - 1); - - // Shy, eye, lock separator - painter->fillRect(QRect(treeWidth() - TimelineConstants::TREE_ICONS_W, - 0, 1, size().height()), - CStudioPreferences::timelineWidgetBgColor()); - - // Shy, eye, lock - static const QPixmap pixEmpty = QPixmap(":/images/Toggle-Empty.png"); - static const QPixmap pixShy = QPixmap(":/images/Toggle-Shy.png"); - static const QPixmap pixHide = QPixmap(":/images/Toggle-HideShow.png"); - static const QPixmap pixHideDisabled = QPixmap(":/images/Toggle-HideShow-disabled.png"); - static const QPixmap pixHideCtrld = QPixmap(":/images/Toggle-HideShowControlled.png"); - static const QPixmap pixLock = QPixmap(":/images/Toggle-Lock.png"); - static const QPixmap pixEmpty2x = QPixmap(":/images/Toggle-Empty@2x.png"); - static const QPixmap pixShy2x = QPixmap(":/images/Toggle-Shy@2x.png"); - static const QPixmap pixHide2x = QPixmap(":/images/Toggle-HideShow@2x.png"); - static const QPixmap pixHideDisabled2x = QPixmap(":/images/Toggle-HideShow-disabled@2x.png"); - static const QPixmap pixHideCtrld2x = QPixmap(":/images/Toggle-HideShowControlled@2x.png"); - static const QPixmap pixLock2x = QPixmap(":/images/Toggle-Lock@2x.png"); - if (hasActionButtons()) { - painter->drawPixmap(m_rectShy, hiResIcons ? (m_shy ? pixShy2x : pixEmpty2x) - : (m_shy ? pixShy : pixEmpty)); - // Eyeball visibility follows the visibility setting for the object even if it has - // datainput controller - // Disable eyeball from master slide - if (m_onMasterSlide) { - painter->drawPixmap(m_rectVisible, hiResIcons ? pixHideDisabled2x - : pixHideDisabled); - } else if (m_visibilityCtrld) { - painter->drawPixmap(m_rectVisible, hiResIcons - ? (m_visible ? pixHideCtrld2x : pixEmpty2x) - : (m_visible ? pixHideCtrld : pixEmpty)); - } else { - painter->drawPixmap(m_rectVisible, hiResIcons - ? (m_visible ? pixHide2x : pixEmpty2x) - : (m_visible ? pixHide : pixEmpty)); - } - painter->drawPixmap(m_rectLocked, hiResIcons ? (m_locked ? pixLock2x : pixEmpty2x) - : (m_locked ? pixLock : pixEmpty)); - } - - static const QPixmap pixInsertLeft = QPixmap(":/images/Insert-Left.png"); - static const QPixmap pixInsertRight = QPixmap(":/images/Insert-Right.png"); - static const QPixmap pixInsertLeft2x = QPixmap(":/images/Insert-Left@2x.png"); - static const QPixmap pixInsertRight2x = QPixmap(":/images/Insert-Right@2x.png"); - if (m_dndState == DnDState::SP_TARGET) { // Candidate target of a subpresentation drop - painter->drawPixmap(19, 2, hiResIcons ? pixInsertLeft2x : pixInsertLeft); - painter->drawPixmap(treeWidth() - TimelineConstants::TREE_ICONS_W - 8, 2, hiResIcons - ? pixInsertRight2x : pixInsertRight); - } else if (m_dndState == DnDState::Parent) { // Candidate parent of a dragged row - painter->setPen(QPen(CStudioPreferences::timelineRowMoverColor(), 1)); - painter->drawRect(QRect(1, 1, treeWidth() - 2, size().height() - 3)); - } - - // Action indicators - static const QPixmap pixMasterAction = QPixmap(":/images/Action-MasterAction.png"); - static const QPixmap pixAction = QPixmap(":/images/Action-Action.png"); - static const QPixmap pixChildMasterAction = QPixmap(":/images/Action-ChildMasterAction.png"); - static const QPixmap pixChildAction = QPixmap(":/images/Action-ChildAction.png"); - static const QPixmap pixCompMasterAction = QPixmap(":/images/Action-ComponentMasterAction.png"); - static const QPixmap pixCompAction = QPixmap(":/images/Action-ComponentAction.png"); - static const QPixmap pixMasterAction2x = QPixmap(":/images/Action-MasterAction@2x.png"); - static const QPixmap pixAction2x = QPixmap(":/images/Action-Action@2x.png"); - static const QPixmap pixChildMasterAction2x - = QPixmap(":/images/Action-ChildMasterAction@2x.png"); - static const QPixmap pixChildAction2x = QPixmap(":/images/Action-ChildAction@2x.png"); - static const QPixmap pixCompMasterAction2x - = QPixmap(":/images/Action-ComponentMasterAction@2x.png"); - static const QPixmap pixCompAction2x = QPixmap(":/images/Action-ComponentAction@2x.png"); - - if (!isProperty()) { - // subpresentation indicators - if (m_hasSubpresentation) { - painter->fillRect(QRect(0, 0, LEFT_DIVIDER, size().height() - 1), - CStudioPreferences::timelineRowSubpColor()); - } else if (!expanded() && m_numDescendantSubpresentations > 0) { - painter->fillRect(QRect(0, 0, LEFT_DIVIDER, size().height() - 1), - CStudioPreferences::timelineRowSubpDescendantColor()); - } - - if (m_actionStates & ActionState::MasterAction) // has master action - painter->drawPixmap(0, 0, hiResIcons ? pixMasterAction2x : pixMasterAction); - else if (m_actionStates & ActionState::Action) // has action - painter->drawPixmap(0, 0, hiResIcons ? pixAction2x : pixAction); - - if (!expanded()) { - if (m_actionStates & ActionState::MasterChildAction) { - // children have master action - painter->drawPixmap(0, 0, hiResIcons ? pixChildMasterAction2x - : pixChildMasterAction); - } else if (m_actionStates & ActionState::ChildAction) { - // children have action - painter->drawPixmap(0, 0, hiResIcons ? pixChildAction2x : pixChildAction); - } - } - - if (m_actionStates & ActionState::MasterComponentAction) // component has master action - painter->drawPixmap(0, 0, hiResIcons ? pixCompMasterAction2x : pixCompMasterAction); - else if (m_actionStates & ActionState::ComponentAction) // component has action - painter->drawPixmap(0, 0, hiResIcons ? pixCompAction2x : pixCompAction); - } - - // variants indicator - if (m_variantsGroups.size() > 0) { - const auto variantsDef = g_StudioApp.GetCore()->getProjectFile().variantsDef(); - for (int i = 0; i < m_variantsGroups.size(); ++i) { - painter->fillRect(QRect(clipX() + 2 + i * 8, 6, 6, 6), - variantsDef[m_variantsGroups[i]].m_color); - painter->setPen(CStudioPreferences::timelineWidgetBgColor()); - painter->drawRect(QRect(clipX() + 2 + i * 8, 6, 6, 6)); - } - } - - // The following items need to be clipped so that they do not draw overlapping shy etc. buttons - - painter->setClipRect(0, 0, clipX(), TimelineConstants::ROW_H); - - // expand/collapse arrow - static const QPixmap pixArrow = QPixmap(":/images/arrow.png"); - static const QPixmap pixArrowDown = QPixmap(":/images/arrow_down.png"); - static const QPixmap pixArrow2x = QPixmap(":/images/arrow@2x.png"); - static const QPixmap pixArrowDown2x = QPixmap(":/images/arrow_down@2x.png"); - if (m_arrowVisible) { - painter->drawPixmap(m_rectArrow, hiResIcons ? (expanded() ? pixArrowDown2x : pixArrow2x) - : (expanded() ? pixArrowDown : pixArrow)); - } - - // Row type icon - static const QPixmap pixSceneNormal = QPixmap(":/images/Objects-Scene-Normal.png"); - static const QPixmap pixLayerNormal = QPixmap(":/images/Objects-Layer-Normal.png"); - static const QPixmap pixObjectNormal = QPixmap(":/images/Objects-Model-Normal.png"); - static const QPixmap pixLightNormal = QPixmap(":/images/Objects-Light-Normal.png"); - static const QPixmap pixCameraNormal = QPixmap(":/images/Objects-Camera-Normal.png"); - static const QPixmap pixTextNormal = QPixmap(":/images/Objects-Text-Normal.png"); - static const QPixmap pixAliasNormal = QPixmap(":/images/Objects-Alias-Normal.png"); - static const QPixmap pixGroupNormal = QPixmap(":/images/Objects-Group-Normal.png"); - static const QPixmap pixComponentNormal = QPixmap(":/images/Objects-Component-Normal.png"); - static const QPixmap pixMaterialNormal = QPixmap(":/images/Objects-Material-Normal.png"); - static const QPixmap pixPropertyNormal = QPixmap(":/images/Objects-Property-Normal.png"); - static const QPixmap pixImageNormal = QPixmap(":/images/Objects-Image-Normal.png"); - static const QPixmap pixBehaviorNormal = QPixmap(":/images/Objects-Behavior-Normal.png"); - static const QPixmap pixEffectNormal= QPixmap(":/images/Objects-Effect-Normal.png"); - static const QPixmap pixSceneNormal2x = QPixmap(":/images/Objects-Scene-Normal@2x.png"); - static const QPixmap pixLayerNormal2x = QPixmap(":/images/Objects-Layer-Normal@2x.png"); - static const QPixmap pixObjectNormal2x = QPixmap(":/images/Objects-Model-Normal@2x.png"); - static const QPixmap pixLightNormal2x = QPixmap(":/images/Objects-Light-Normal@2x.png"); - static const QPixmap pixCameraNormal2x = QPixmap(":/images/Objects-Camera-Normal@2x.png"); - static const QPixmap pixTextNormal2x = QPixmap(":/images/Objects-Text-Normal@2x.png"); - static const QPixmap pixAliasNormal2x = QPixmap(":/images/Objects-Alias-Normal@2x.png"); - static const QPixmap pixGroupNormal2x = QPixmap(":/images/Objects-Group-Normal@2x.png"); - static const QPixmap pixComponentNormal2x = QPixmap(":/images/Objects-Component-Normal@2x.png"); - static const QPixmap pixMaterialNormal2x = QPixmap(":/images/Objects-Material-Normal@2x.png"); - static const QPixmap pixPropertyNormal2x = QPixmap(":/images/Objects-Property-Normal@2x.png"); - static const QPixmap pixImageNormal2x = QPixmap(":/images/Objects-Image-Normal@2x.png"); - static const QPixmap pixBehaviorNormal2x = QPixmap(":/images/Objects-Behavior-Normal@2x.png"); - static const QPixmap pixEffectNormal2x = QPixmap(":/images/Objects-Effect-Normal@2x.png"); - - static const QPixmap pixSceneDisabled = QPixmap(":/images/Objects-Scene-Disabled.png"); - static const QPixmap pixLayerDisabled = QPixmap(":/images/Objects-Layer-Disabled.png"); - static const QPixmap pixObjectDisabled = QPixmap(":/images/Objects-Model-Disabled.png"); - static const QPixmap pixLightDisabled = QPixmap(":/images/Objects-Light-Disabled.png"); - static const QPixmap pixCameraDisabled = QPixmap(":/images/Objects-Camera-Disabled.png"); - static const QPixmap pixTextDisabled = QPixmap(":/images/Objects-Text-Disabled.png"); - static const QPixmap pixAliasDisabled = QPixmap(":/images/Objects-Alias-Disabled.png"); - static const QPixmap pixGroupDisabled = QPixmap(":/images/Objects-Group-Disabled.png"); - static const QPixmap pixComponentDisabled = QPixmap(":/images/Objects-Component-Disabled.png"); - static const QPixmap pixMaterialDisabled = QPixmap(":/images/Objects-Material-Disabled.png"); - static const QPixmap pixPropertyDisabled = QPixmap(":/images/Objects-Property-Disabled.png"); - static const QPixmap pixImageDisabled = QPixmap(":/images/Objects-Image-Disabled.png"); - static const QPixmap pixBehaviorDisabled = QPixmap(":/images/Objects-Behavior-Disabled.png"); - static const QPixmap pixEffectDisabled = QPixmap(":/images/Objects-Effect-Disabled.png"); - static const QPixmap pixSceneDisabled2x = QPixmap(":/images/Objects-Scene-Disabled@2x.png"); - static const QPixmap pixLayerDisabled2x = QPixmap(":/images/Objects-Layer-Disabled@2x.png"); - static const QPixmap pixObjectDisabled2x = QPixmap(":/images/Objects-Model-Disabled@2x.png"); - static const QPixmap pixLightDisabled2x = QPixmap(":/images/Objects-Light-Disabled@2x.png"); - static const QPixmap pixCameraDisabled2x = QPixmap(":/images/Objects-Camera-Disabled@2x.png"); - static const QPixmap pixTextDisabled2x = QPixmap(":/images/Objects-Text-Disabled@2x.png"); - static const QPixmap pixAliasDisabled2x = QPixmap(":/images/Objects-Alias-Disabled@2x.png"); - static const QPixmap pixGroupDisabled2x = QPixmap(":/images/Objects-Group-Disabled@2x.png"); - static const QPixmap pixComponentDisabled2x - = QPixmap(":/images/Objects-Component-Disabled@2x.png"); - static const QPixmap pixMaterialDisabled2x - = QPixmap(":/images/Objects-Material-Disabled@2x.png"); - static const QPixmap pixPropertyDisabled2x - = QPixmap(":/images/Objects-Property-Disabled@2x.png"); - static const QPixmap pixImageDisabled2x = QPixmap(":/images/Objects-Image-Disabled@2x.png"); - static const QPixmap pixBehaviorDisabled2x - = QPixmap(":/images/Objects-Behavior-Disabled@2x.png"); - static const QPixmap pixEffectDisabled2x = QPixmap(":/images/Objects-Effect-Disabled@2x.png"); - - QPixmap pixRowType; - if (m_isProperty) { - pixRowType = hiResIcons ? (m_locked ? pixPropertyDisabled2x : pixPropertyNormal2x) - : (m_locked ? pixPropertyDisabled : pixPropertyNormal); - } else { - switch (m_objectType) { - case OBJTYPE_SCENE: - pixRowType = hiResIcons ? (m_locked ? pixSceneDisabled2x : pixSceneNormal2x) - : (m_locked ? pixSceneDisabled : pixSceneNormal); - break; - case OBJTYPE_LAYER: - pixRowType = hiResIcons ? (m_locked ? pixLayerDisabled2x : pixLayerNormal2x) - : (m_locked ? pixLayerDisabled : pixLayerNormal); - break; - case OBJTYPE_MODEL: - pixRowType = hiResIcons ? (m_locked ? pixObjectDisabled2x : pixObjectNormal2x) - : (m_locked ? pixObjectDisabled : pixObjectNormal); - break; - case OBJTYPE_LIGHT: - pixRowType = hiResIcons ? (m_locked ? pixLightDisabled2x : pixLightNormal2x) - : (m_locked ? pixLightDisabled : pixLightNormal); - break; - case OBJTYPE_CAMERA: - pixRowType = hiResIcons ? (m_locked ? pixCameraDisabled2x : pixCameraNormal2x) - : (m_locked ? pixCameraDisabled : pixCameraNormal); - break; - case OBJTYPE_TEXT: - pixRowType = hiResIcons ? (m_locked ? pixTextDisabled2x : pixTextNormal2x) - : (m_locked ? pixTextDisabled : pixTextNormal); - break; - case OBJTYPE_ALIAS: - pixRowType = hiResIcons ? (m_locked ? pixAliasDisabled2x : pixAliasNormal2x) - : (m_locked ? pixAliasDisabled : pixAliasNormal); - break; - case OBJTYPE_GROUP: - pixRowType = hiResIcons ? (m_locked ? pixGroupDisabled2x : pixGroupNormal2x) - : (m_locked ? pixGroupDisabled : pixGroupNormal); - break; - case OBJTYPE_COMPONENT: - pixRowType = hiResIcons ? (m_locked ? pixComponentDisabled2x : pixComponentNormal2x) - : (m_locked ? pixComponentDisabled : pixComponentNormal); - break; - case OBJTYPE_MATERIAL: - case OBJTYPE_CUSTOMMATERIAL: - case OBJTYPE_REFERENCEDMATERIAL: - pixRowType = hiResIcons ? (m_locked ? pixMaterialDisabled2x : pixMaterialNormal2x) - : (m_locked ? pixMaterialDisabled : pixMaterialNormal); - break; - case OBJTYPE_IMAGE: - pixRowType = hiResIcons ? (m_locked ? pixImageDisabled2x : pixImageNormal2x) - : (m_locked ? pixImageDisabled : pixImageNormal); - break; - case OBJTYPE_BEHAVIOR: - pixRowType = hiResIcons ? (m_locked ? pixBehaviorDisabled2x : pixBehaviorNormal2x) - : (m_locked ? pixBehaviorDisabled : pixBehaviorNormal); - break; - case OBJTYPE_EFFECT: - pixRowType = hiResIcons ? (m_locked ? pixEffectDisabled2x : pixEffectNormal2x) - : (m_locked ? pixEffectDisabled : pixEffectNormal); - break; - default: - break; - } - } - - painter->drawPixmap(m_rectType, pixRowType); -} - -void RowTree::updateVariants(const QStringList &groups) -{ - m_variantsGroups = groups; - update(); -} - -int RowTree::treeWidth() const -{ - return m_scene->treeWidth() - m_scene->getScrollbarOffsets().x(); -} - -void RowTree::setBinding(ITimelineItemBinding *binding) -{ - m_binding = binding; - - // Restore the expansion state of rows - m_expandState = m_scene->expandMap().value(instance(), ExpandState::Unknown); - - if (m_expandState == ExpandState::Unknown) { - // Everything but scene/component is initially collapsed and hidden - if (m_objectType == OBJTYPE_SCENE || m_objectType == OBJTYPE_COMPONENT) - m_expandState = ExpandState::Expanded; - else - m_expandState = ExpandState::HiddenCollapsed; - } - - // Make sure all children of visible expanded parents are shown, and vice versa - if (parentRow()) { - if (parentRow()->expanded()) { - if (m_expandState == ExpandState::HiddenCollapsed) - m_expandState = ExpandState::Collapsed; - else if (m_expandState == ExpandState::HiddenExpanded) - m_expandState = ExpandState::Expanded; - } else { - if (m_expandState == ExpandState::Collapsed) - m_expandState = ExpandState::HiddenCollapsed; - else if (m_expandState == ExpandState::Expanded) - m_expandState = ExpandState::HiddenExpanded; - } - } - - setRowVisible(m_expandState == ExpandState::Collapsed - || m_expandState == ExpandState::Expanded); - - updateFromBinding(); -} - -// x value where label should clip -int RowTree::clipX() const -{ - return treeWidth() - TimelineConstants::TREE_ICONS_W - m_variantsGroups.size() * 8 - 2; -} - -ITimelineItemProperty *RowTree::propBinding() -{ - return m_PropBinding; -} - -void RowTree::setPropBinding(ITimelineItemProperty *binding) -{ - m_PropBinding = binding; - - if (parentRow()->expanded()) - setRowVisible(true); - - // Update label color - m_labelItem.setMaster(m_PropBinding->IsMaster()); -} - -void RowTree::setState(State state) -{ - m_state = state; - m_rowTimeline->m_state = state; - - update(); - m_rowTimeline->update(); -} - -void RowTree::setTimelineRow(RowTimeline *rowTimeline) -{ - m_rowTimeline = rowTimeline; -} - -void RowTree::setParentRow(RowTree *parent) -{ - m_parentRow = parent; -} - -void RowTree::selectLabel() -{ - m_labelItem.setEnabled(true); - m_labelItem.setFocus(); - // Select all text - QTextCursor cursor = m_labelItem.textCursor(); - cursor.select(QTextCursor::Document); - m_labelItem.setTextCursor(cursor); -} - -RowTree *RowTree::parentRow() const -{ - return m_parentRow; -} - -int RowTree::depth() const -{ - return m_depth; -} - -EStudioObjectType RowTree::objectType() const -{ - return m_objectType; -} - -QString RowTree::propertyType() const -{ - return m_propertyType; -} - -int RowTree::type() const -{ - // Enable the use of qgraphicsitem_cast with this item. - return TypeRowTree; -} - -int RowTree::index() const -{ - // first child in a parent has index 0 - return m_index; -} - -int RowTree::indexInLayout() const -{ - // first child (scene) at index 1, tree header at index 0 (invisible rows are also counted) - return m_indexInLayout; -} - -void RowTree::addChild(RowTree *child) -{ - int index = getLastChildIndex(child->isProperty()) + 1; - addChildAt(child, index); -} - -int RowTree::getLastChildIndex(bool isProperty) const -{ - int index = -1; - if (isProperty && !m_childProps.empty()) - index = m_childProps.last()->index(); - else if (!isProperty && !m_childRows.empty()) - index = m_childRows.last()->index(); - - return index; -} - -void RowTree::updateArrowVisibility() -{ - bool oldVisibility = m_arrowVisible; - if (m_childRows.empty() && m_childProps.empty()) { - m_arrowVisible = false; - } else { - if (m_childProps.empty()) { - m_arrowVisible = false; - for (RowTree *row : qAsConst(m_childRows)) { - if (!row->m_filtered) { - m_arrowVisible = true; - break; - } - } - } else { - m_arrowVisible = true; - } - } - if (oldVisibility != m_arrowVisible) - update(); -} - -bool RowTree::isInVariantsFilter() const -{ - const QString filterStr = g_StudioApp.m_pMainWnd->getVariantsFilterStr(); - - if (m_objectType & ~OBJTYPE_IS_VARIANT || filterStr.isEmpty() - || !m_scene->widgetTimeline()->toolbar()->isVariantsFilterOn()) { - return true; - } - - CDoc *doc = g_StudioApp.GetCore()->GetDoc(); - const auto propertySystem = doc->GetStudioSystem()->GetPropertySystem(); - const auto bridge = doc->GetStudioSystem()->GetClientDataModelBridge(); - auto property = bridge->getVariantsProperty(instance()); - - using namespace qt3dsdm; - SValue sValue; - if (propertySystem->GetInstancePropertyValue(instance(), property, sValue)) { - QString propVal = get<TDataStrPtr>(sValue)->toQString(); - const QStringList filterPairs = filterStr.split(QLatin1Char(',')); - QHash<QString, bool> matches; - for (auto &filterPair : filterPairs) { - QString group = filterPair.left(filterPair.indexOf(QLatin1Char(':')) + 1); - if (propVal.contains(group)) { // the layer has 1 or more tags from this filter group - if (propVal.contains(filterPair)) - matches[group] = true; // filter tag exists in the property variant group - else if (!matches.contains(group)) - matches[group] = false; - } - } - - for (auto m : qAsConst(matches)) { - if (!m) - return false; - } - } - - return true; -} - -void RowTree::updateFilter() -{ - auto bridge = g_StudioApp.GetCore()->GetDoc()->GetStudioSystem()->GetClientDataModelBridge(); - if (bridge->isMaterialContainer(instance())) - return; - - bool parentOk = !m_parentRow || m_parentRow->isVisible(); - bool shyOk = !m_shy || !m_scene->treeHeader()->filterShy(); - bool visibleOk = m_visible || !m_scene->treeHeader()->filterHidden(); - bool lockOk = !m_locked || !m_scene->treeHeader()->filterLocked(); - bool expandOk = !expandHidden(); - bool variantsOk = isInVariantsFilter(); - - m_filtered = !(shyOk && visibleOk && lockOk && variantsOk); - const bool visible = parentOk && expandOk && !m_filtered; - setVisible(visible); - m_rowTimeline->setVisible(visible); - for (auto propRow : qAsConst(m_childProps)) { - propRow->setVisible(visible); - propRow->m_rowTimeline->setVisible(visible); - } -} - -int RowTree::getCountDecendentsRecursive() const -{ - int num = m_childProps.count(); - - for (auto child : qAsConst(m_childRows)) { - num++; - num += child->getCountDecendentsRecursive(); - } - - return num; -} - -void RowTree::addChildAt(RowTree *child, int index) -{ - // Mahmoud_TODO: improvement: implement moving the child (instead of remove/add) if it is added - // under the same parent. - - int maxIndex = getLastChildIndex(child->isProperty()) + 1; - - if (index > maxIndex) - index = maxIndex; - - if (child->parentRow() == this && index == child->m_index) // same place - return; - - if (child->parentRow()) - child->parentRow()->removeChild(child); - - child->m_index = index; - - QList<RowTree *> &childRows = child->isProperty() ? m_childProps : m_childRows; - int updateIndexInLayout = child->m_indexInLayout; - child->m_indexInLayout = m_indexInLayout + index + 1; - - if (!child->isProperty()) { - child->m_indexInLayout += m_childProps.count(); - - if (m_childRows.size() >= index) { - for (int i = 0; i < index; ++i) - child->m_indexInLayout += m_childRows.at(i)->getCountDecendentsRecursive(); - } - } - - if (!childRows.contains(child)) - childRows.insert(index, child); - - child->m_parentRow = this; - child->updateDepthRecursive(); - if (!child->isProperty()) { - m_rowTimeline->updateChildrenMinStartXRecursive(this); - m_rowTimeline->updateChildrenMaxEndXRecursive(this); - } - - // update the layout - child->addToLayout(child->m_indexInLayout); - - // update indices - updateIndexInLayout = std::min(updateIndexInLayout, child->m_indexInLayout); - updateIndices(true, child->m_index + 1, updateIndexInLayout, child->isProperty()); - updateArrowVisibility(); -} - -int RowTree::addToLayout(int indexInLayout) -{ - m_scene->layoutTree()->insertItem(indexInLayout, this); - m_scene->layoutTimeline()->insertItem(indexInLayout, rowTimeline()); - - indexInLayout++; - - for (auto p : qAsConst(m_childProps)) - indexInLayout = p->addToLayout(indexInLayout); - - for (auto c : qAsConst(m_childRows)) - indexInLayout = c->addToLayout(indexInLayout); - - return indexInLayout; -} - -RowTree *RowTree::getChildAt(int index) const -{ - if (index < 0 || index > m_childRows.count() - 1) - return nullptr; - - return m_childRows.at(index); -} - -// this does not destroy the row, just remove it from the layout and parenting hierarchy -void RowTree::removeChild(RowTree *child) -{ - if (m_childProps.contains(child) || m_childRows.contains(child)) { // child exists - removeChildFromLayout(child); - - // detach from parent - if (child->isProperty()) - m_childProps.removeAll(child); - else - m_childRows.removeAll(child); - - child->m_depth = -1; - child->m_parentRow = nullptr; - - updateIndices(false, child->m_index, child->m_indexInLayout, child->isProperty()); - updateArrowVisibility(); - } -} - -int RowTree::removeChildFromLayout(RowTree *child) const -{ - int numRemoved = 0; - int deleteIndex = child->m_indexInLayout; - for (;;) { - RowTree *row_i = static_cast<RowTree *>(m_scene->layoutTree()->itemAt(deleteIndex) - ->graphicsItem()); - if (row_i->depth() <= child->depth() && numRemoved > 0) - break; - - m_scene->layoutTree()->removeItem(row_i); - m_scene->layoutTimeline()->removeItem(row_i->rowTimeline()); - numRemoved++; - - if (m_scene->layoutTree()->count() == deleteIndex) // reached end of the list - break; - } - - return numRemoved; -} - -bool RowTree::draggable() const -{ - return !m_locked && !isProperty() - && m_objectType & ~(OBJTYPE_IMAGE | OBJTYPE_SCENE | OBJTYPE_IS_MATERIAL); -} - -void RowTree::updateDepthRecursive() -{ - if (m_parentRow) { - m_depth = m_parentRow->m_depth + 1; - updateLabelPosition(); - - for (auto p : qAsConst(m_childProps)) - p->updateDepthRecursive(); - - for (auto r : qAsConst(m_childRows)) - r->updateDepthRecursive(); - } -} - -// update this parent's children indices after a child row is inserted or removed -void RowTree::updateIndices(bool isInsertion, int index, int indexInLayout, bool isProperty) -{ - // update index - if (isProperty && index < m_childProps.count()) { - for (int i = index; i < m_childProps.count(); i++) - m_childProps.at(i)->m_index += isInsertion ? 1 : -1; - } else if (!isProperty && index < m_childRows.count()) { - for (int i = index; i < m_childRows.count(); i++) - m_childRows.at(i)->m_index += isInsertion ? 1 : -1; - } - - // update indexInLayout - for (int i = indexInLayout; i < m_scene->layoutTree()->count(); ++i) { - RowTree *row_i = static_cast<RowTree *>(m_scene->layoutTree()->itemAt(i)->graphicsItem()); - row_i->m_indexInLayout = i; - } -} - -void RowTree::updateFromBinding() -{ - // update view (shy, visible, locked) - m_shy = m_binding->GetTimelineItem()->IsShy(); - m_visible = m_binding->GetTimelineItem()->IsVisible(); - updateLock(m_binding->GetTimelineItem()->IsLocked()); - m_visibilityCtrld = m_binding->GetTimelineItem()->IsVisibilityControlled(); - - // Update label color - Qt3DSDMTimelineItemBinding *itemBinding = - static_cast<Qt3DSDMTimelineItemBinding *>(m_binding); - m_master = itemBinding->IsMaster(); - m_labelItem.setMaster(m_master); - // Update timeline comments - m_rowTimeline->updateCommentItem(); -} - -void RowTree::updateLabel() -{ - if (m_binding) - m_labelItem.setLabel(m_binding->GetTimelineItem()->GetName().toQString()); -} - -void RowTree::setRowVisible(bool visible) -{ - auto bridge = g_StudioApp.GetCore()->GetDoc()->GetStudioSystem()->GetClientDataModelBridge(); - if (bridge->isMaterialContainer(instance())) - return; - - if (visible) { - setMaximumHeight(TimelineConstants::ROW_H); - setOpacity(1.0); - setVisible(true); - m_rowTimeline->setMaximumHeight(TimelineConstants::ROW_H); - m_rowTimeline->setOpacity(1.0); - m_rowTimeline->setVisible(true); - } else { - setMaximumHeight(0.0); - setOpacity(0.0); - setVisible(false); - m_rowTimeline->setMaximumHeight(0.0); - m_rowTimeline->setOpacity(0.0); - m_rowTimeline->setVisible(false); - } -} - -bool RowTree::hasPropertyChildren() const -{ - return !m_childProps.empty(); -} - -void RowTree::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) -{ - QPointF p = event->pos(); - if (m_rectType.contains(p.x(), p.y()) && !m_locked) - if (m_binding) - m_binding->OpenAssociatedEditor(); -} - -// handle clicked control and return its type -TreeControlType RowTree::getClickedControl(const QPointF &scenePos) -{ - QPointF p = mapFromScene(scenePos.x(), scenePos.y()); - if (m_arrowVisible && m_rectArrow.contains(p.x(), p.y())) { - updateExpandStatus(m_expandState == ExpandState::Expanded ? ExpandState::Collapsed - : ExpandState::Expanded, false); - update(); - return TreeControlType::Arrow; - } - - if (hasActionButtons()) { - if (m_rectShy.contains(p.x(), p.y())) { - toggleShy(); - return TreeControlType::Shy; - } else if (!m_onMasterSlide && m_rectVisible.contains(p.x(), p.y())) { - // Prevent toggling hide on master slide - toggleVisible(); - return TreeControlType::Hide; - } else if (m_rectLocked.contains(p.x(), p.y())) { - toggleLocked(); - return TreeControlType::Lock; - } - } - - return TreeControlType::None; -} - -void RowTree::updateExpandStatus(ExpandState state, bool animate, bool forceChildUpdate) -{ - const bool changed = m_expandState != state; - if (!forceChildUpdate && !changed) - return; - - m_expandState = state; - - if (m_scene->widgetTimeline()->isFullReconstructPending()) - return; - - // Store the expanded state of items so we can restore it on slide change - if (changed && m_binding) - m_scene->expandMap().insert(instance(), m_expandState); - - if (animate) - animateExpand(m_expandState); - - // updateFilter updates the row visibility. It must be called before children are handled - // to ensure parent visibility is up to date. - if (changed) - updateFilter(); - - if (!m_childRows.empty()) { - for (auto child : qAsConst(m_childRows)) { - if (state == ExpandState::Expanded) { - if (child->m_expandState == ExpandState::HiddenExpanded) - child->updateExpandStatus(ExpandState::Expanded); - else if (child->m_expandState == ExpandState::HiddenCollapsed) - child->updateExpandStatus(ExpandState::Collapsed); - } else { - if (child->m_expandState == ExpandState::Expanded) - child->updateExpandStatus(ExpandState::HiddenExpanded); - else if (child->m_expandState == ExpandState::Collapsed) - child->updateExpandStatus(ExpandState::HiddenCollapsed); - } - } - } - - if (!m_childProps.empty()) { - for (auto child : qAsConst(m_childProps)) { - // Properties can never be collapsed - if (state == ExpandState::Expanded) - child->updateExpandStatus(ExpandState::Expanded); - else - child->updateExpandStatus(ExpandState::HiddenExpanded); - } - } -} - -void RowTree::updateLockRecursive(bool state) -{ - updateLock(state); - if (!m_childRows.empty()) { - for (auto child : qAsConst(m_childRows)) - child->updateLockRecursive(m_locked); - } -} - -void RowTree::updateLock(bool state) -{ - m_locked = state; - - m_labelItem.setLocked(m_locked); - update(); - if (!m_childProps.empty()) { - for (auto child : qAsConst(m_childProps)) - child->updateLock(m_locked); - } - if (m_locked) - m_scene->keyframeManager()->deselectRowKeyframes(this); -} - -void RowTree::updateSubpresentations(int updateParentsOnlyVal) -{ - if (updateParentsOnlyVal != 0) { - int n = m_numDescendantSubpresentations; - if (m_hasSubpresentation) - n++; - if (n > 0) { - RowTree *parentRow = m_parentRow; - while (parentRow) { - parentRow->m_numDescendantSubpresentations += n * updateParentsOnlyVal; - parentRow->update(); - parentRow = parentRow->m_parentRow; - } - } - } else { - auto binding = static_cast<Qt3DSDMTimelineItemBinding *>(m_binding); - bool hasSubp = binding->hasSubpresentation(); - - if (m_hasSubpresentation != hasSubp) { - m_hasSubpresentation = hasSubp; - int n = hasSubp ? 1 : -1; - RowTree *parentRow = m_parentRow; - while (parentRow) { - parentRow->m_numDescendantSubpresentations += n; - parentRow->update(); - parentRow = parentRow->m_parentRow; - } - } - } - update(); -} - -void RowTree::updateLabelPosition() -{ - int offset = 5 + m_depth * TimelineConstants::ROW_DEPTH_STEP + 30; - m_labelItem.setPos(offset, -1); -} - -bool RowTree::expanded() const -{ - if (m_isProperty) - return false; - else - return m_expandState == ExpandState::Expanded; -} - -bool RowTree::expandHidden() const -{ - return m_expandState == ExpandState::HiddenExpanded - || m_expandState == ExpandState::HiddenCollapsed; -} - -bool RowTree::isDecendentOf(RowTree *row) const -{ - RowTree *parentRow = m_parentRow; - - while (parentRow) { - if (parentRow == row) - return true; - - parentRow = parentRow->parentRow(); - } - - return false; -} - -void RowTree::setDnDHover(bool val) -{ - m_dndHover = val; - update(); -} - -void RowTree::setDnDState(DnDState state, DnDState onlyIfState, bool recursive) -{ - if (m_dndState == onlyIfState || onlyIfState == DnDState::Any) { - m_dndState = state; - update(); - - if (recursive) { // used by source rows to highlights all of their descendants - for (auto child : qAsConst(m_childProps)) - child->setDnDState(state, onlyIfState, true); - - for (auto child : qAsConst(m_childRows)) - child->setDnDState(state, onlyIfState, true); - } - } -} - -RowTree::DnDState RowTree::getDnDState() const -{ - return m_dndState; -} - -void RowTree::setActionStates(ActionStates states) -{ - if (states != m_actionStates) { - m_actionStates = states; - update(); - } -} - -bool RowTree::isContainer() const -{ - return !m_isProperty && m_objectType & OBJTYPE_IS_CONTAINER; -} - -bool RowTree::isProperty() const -{ - return m_isProperty; -} - -RowTree *RowTree::getPropertyRow(const QString &type) const -{ - for (RowTree *prop : qAsConst(m_childProps)) { - if (prop->label() == type) - return prop; - } - - return nullptr; -} - - -bool RowTree::isPropertyOrMaterial() const -{ - return m_isProperty || m_objectType & (OBJTYPE_IS_MATERIAL | OBJTYPE_IMAGE); -} - -bool RowTree::isComponent() const -{ - return m_objectType == OBJTYPE_COMPONENT; -} - -bool RowTree::isComponentRoot() const -{ - if (m_objectType == OBJTYPE_COMPONENT && m_binding) - return static_cast<Qt3DSDMTimelineItemBinding *>(m_binding)->isRootComponent(); - - return false; -} - -bool RowTree::isMaster() const -{ - return m_master; -} - -bool RowTree::isDefaultMaterial() const -{ - if (m_binding) - return static_cast<Qt3DSDMTimelineItemBinding *>(m_binding)->isDefaultMaterial(); - - return false; -} - -bool RowTree::empty() const -{ - return m_childRows.empty() && m_childProps.empty(); -} - -bool RowTree::selected() const -{ - return m_state == Selected; -} - -QList<RowTree *> RowTree::childRows() const -{ - return m_childRows; -} - -QList<RowTree *> RowTree::childProps() const -{ - return m_childProps; -} - -RowTimeline *RowTree::rowTimeline() const -{ - return m_rowTimeline; -} - -QString RowTree::label() const -{ - return m_label; -} - -void RowTree::toggleShy() -{ - if (hasActionButtons()) { - m_shy = !m_shy; - update(); - m_binding->GetTimelineItem()->SetShy(m_shy); - } -} - -void RowTree::toggleVisible() -{ - if (hasActionButtons()) { - m_visible = !m_visible; - update(); - m_binding->GetTimelineItem()->SetVisible(m_visible); - } -} - -void RowTree::toggleLocked() -{ - if (hasActionButtons()) { - updateLockRecursive(!m_locked); - m_binding->GetTimelineItem()->SetLocked(m_locked); - if (m_locked && selected()) - m_scene->rowManager()->clearSelection(); - } -} - -bool RowTree::shy() const -{ - return m_shy; -} - -bool RowTree::visible() const -{ - return m_visible; -} - -bool RowTree::locked() const -{ - return m_locked; -} - -// Returns true for items with shy/visible/lock buttons -bool RowTree::hasActionButtons() const -{ - return !m_isProperty && m_indexInLayout != 1 - && m_objectType & ~(OBJTYPE_SCENE | OBJTYPE_IS_MATERIAL | OBJTYPE_IMAGE); -} - -bool RowTree::hasComponentAncestor() const -{ - RowTree *parentRow = m_parentRow; - while (parentRow) { - if (parentRow->objectType() == OBJTYPE_COMPONENT) - return true; - parentRow = parentRow->parentRow(); - } - return false; -} - -// Returns true for items with duration bar -bool RowTree::hasDurationBar() const -{ - return hasActionButtons(); // Same at least now -} - -bool RowTree::propertyExpanded() const -{ - return m_isPropertyExpanded; -} - -void RowTree::togglePropertyExpanded() -{ - setPropertyExpanded(!m_isPropertyExpanded); -} - -void RowTree::setPropertyExpanded(bool expand) -{ - m_isPropertyExpanded = expand; - if (m_isPropertyExpanded) - animateExpand(ExpandState::Expanded); - else - animateExpand(ExpandState::Collapsed); -} - -void RowTree::showDataInputSelector(const QString &propertyname, const QPoint &pos) -{ - auto bridge = g_StudioApp.GetCore()->GetDoc()->GetStudioSystem()->GetClientDataModelBridge(); - - // Set the datainput to control property in referenced object if this - // is a referenced material. - auto refInstance = bridge->getMaterialReference(instance()); - - m_scene->handleShowDISelector(propertyname, refInstance.Valid() ? refInstance : instance(), - pos); -} - diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.h deleted file mode 100644 index b028e94d..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.h +++ /dev/null @@ -1,228 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef ROWTREE_H -#define ROWTREE_H - -#include "InteractiveTimelineItem.h" -#include "TimelineConstants.h" -#include "RowTypes.h" -#include "StudioObjectTypes.h" -#include "RowTreeLabelItem.h" -#include "Qt3DSDMHandles.h" - -#include <QtCore/qpropertyanimation.h> -#include <QtCore/qparallelanimationgroup.h> - -class RowTimeline; -class Ruler; -class ITimelineItemBinding; -class TimelineGraphicsScene; -class ITimelineItemProperty; - -class RowTree : public InteractiveTimelineItem -{ - Q_OBJECT - -public: - enum class ExpandState { - Unknown, - Collapsed, - Expanded, - HiddenCollapsed, - HiddenExpanded - }; - - enum class DnDState { - None, - Source, // the row being dragged while DnD-ing - Parent, // parent of the insertion point - SP_TARGET, // drop target for a subpresentation (layer, material or image rows) - Any // accept any state (default value in setDnDState() method) - }; - - enum class ActionState { - None = 0, - Action = 1, - ChildAction = 2, - ComponentAction = 4, - MasterAction = 8, - MasterChildAction = 16, - MasterComponentAction = 32 - }; - Q_DECLARE_FLAGS(ActionStates, ActionState) - - explicit RowTree(TimelineGraphicsScene *timelineScene, - EStudioObjectType objectType = OBJTYPE_UNKNOWN, const QString &label = {}); - // property row constructor - explicit RowTree(TimelineGraphicsScene *timelineScene, const QString &propType); - ~RowTree(); - - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) override; - void setState(State state) override; - void setTimelineRow(RowTimeline *rowTimeline); - void setParentRow(RowTree *parent); - void addChild(RowTree *child); - void addChildAt(RowTree *child, int index); - void removeChild(RowTree *child); - void setDnDState(DnDState state, DnDState onlyIfState = DnDState::Any, bool recursive = false); - void setActionStates(ActionStates states); - void setTreeWidth(double w); - void setBinding(ITimelineItemBinding *binding); - void setPropBinding(ITimelineItemProperty *binding); // for property rows - void selectLabel(); - void togglePropertyExpanded(); - void setPropertyExpanded(bool expand); - void showDataInputSelector(const QString &propertyname, const QPoint &pos); - ITimelineItemProperty *propBinding(); - TreeControlType getClickedControl(const QPointF &scenePos); - bool shy() const; - bool visible() const; - bool locked() const; - bool expanded() const; - bool expandHidden() const; - ExpandState expandState() const { return m_expandState; } - bool isDecendentOf(RowTree *row) const; - bool isContainer() const; - bool isProperty() const; - bool isPropertyOrMaterial() const; - bool isComponent() const; - bool isComponentRoot() const; - bool isMaster() const; - bool isDefaultMaterial() const; - bool hasPropertyChildren() const; - bool empty() const; // has zero child rows (and zero properties) - bool selected() const; - bool draggable() const; - bool hasDurationBar() const; - bool propertyExpanded() const; - int depth() const; - int type() const override; - int index() const; - int indexInLayout() const; - int treeWidth() const; - EStudioObjectType objectType() const; - QString propertyType() const; - RowTree *getChildAt(int index) const; - RowTree *parentRow() const; - RowTree *getPropertyRow(const QString &type) const; - QList<RowTree *> childRows() const; - QList<RowTree *> childProps() const; - RowTimeline *rowTimeline() const; - QString label() const; - void toggleShy(); - void toggleVisible(); - void toggleLocked(); - void updateFromBinding(); - void updateLabel(); - void setRowVisible(bool visible); - void setDnDHover(bool val); - void updateVariants(const QStringList &groups); - DnDState getDnDState() const; - - ITimelineItemBinding *getBinding() const; - void updateExpandStatus(ExpandState state, bool animate = true, bool forceChildUpdate = false); - void updateArrowVisibility(); - void updateFilter(); - void updateLock(bool state); - void updateSubpresentations(int updateParentsOnlyVal = 0); - int clipX() const; - qt3dsdm::Qt3DSDMInstanceHandle instance() const; - -protected: - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override; - -private: - void initialize(); - void initializeAnimations(); - void animateExpand(ExpandState state); - void updateDepthRecursive(); - void updateLockRecursive(bool state); - void updateLabelPosition(); - void updateIndices(bool isInsertion, int startIndex, int startIndexInLayout, bool isProperty); - bool hasActionButtons() const; - bool hasComponentAncestor() const; - bool isInVariantsFilter() const; - int removeChildFromLayout(RowTree *child) const; - int getCountDecendentsRecursive() const; - int addToLayout(int indexInLayout); - int getLastChildIndex(bool isProperty) const; - - RowTree *m_parentRow = nullptr; - RowTimeline *m_rowTimeline = nullptr; - int m_depth = 1; - int m_index = 0; - int m_indexInLayout = 1; - bool m_shy = false; - bool m_visible = true; - bool m_locked = false; - bool m_isProperty = false; - bool m_isPropertyExpanded = false; - bool m_master = false; - bool m_filtered = false; - bool m_arrowVisible = false; - bool m_dndHover = false; - bool m_visibilityCtrld = false; - bool m_onMasterSlide = false; - DnDState m_dndState = DnDState::None; - ActionStates m_actionStates = ActionState::None; - bool m_hasSubpresentation = false; - int m_numDescendantSubpresentations = 0; - ExpandState m_expandState = ExpandState::HiddenCollapsed; - TimelineGraphicsScene *m_scene; - RowTreeLabelItem m_labelItem; - EStudioObjectType m_objectType = OBJTYPE_UNKNOWN; - QString m_propertyType; // for property rows - QString m_label; - QList<RowTree *> m_childRows; - QList<RowTree *> m_childProps; - QStringList m_variantsGroups; - ITimelineItemBinding *m_binding = nullptr; - ITimelineItemProperty *m_PropBinding = nullptr; // for property rows - - QRect m_rectArrow; - QRect m_rectShy; - QRect m_rectVisible; - QRect m_rectLocked; - QRect m_rectType; - - QParallelAnimationGroup m_expandAnimation; - QPropertyAnimation *m_expandHeightAnimation; - QPropertyAnimation *m_expandTimelineHeightAnimation; - QPropertyAnimation *m_expandOpacityAnimation; - QPropertyAnimation *m_expandTimelineOpacityAnimation; - - friend class RowTimeline; - friend class RowTimelinePropertyGraph; - friend class RowTimelineContextMenu; -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(RowTree::ActionStates) - -#endif // ROWTREE_H diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeContextMenu.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeContextMenu.cpp deleted file mode 100644 index ae5c0bbb..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeContextMenu.cpp +++ /dev/null @@ -1,441 +0,0 @@ -/**************************************************************************** -** -** 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 "RowTreeContextMenu.h" -#include "RowTree.h" -#include "StudioClipboard.h" -#include "StudioApp.h" -#include "Doc.h" -#include "Core.h" -#include "Bindings/ITimelineItemBinding.h" -#include "Bindings/Qt3DSDMTimelineItemBinding.h" -#include "ChooseImagePropertyDlg.h" -#include "Qt3DSDMStudioSystem.h" -#include "ClientDataModelBridge.h" -#include "qcursor.h" - -RowTreeContextMenu::RowTreeContextMenu(RowTree *inRowTree, QWidget *parent) - : QMenu(parent) - , m_RowTree(inRowTree) - , m_TimelineItemBinding(inRowTree->getBinding()) -{ - initialize(); -} - -RowTreeContextMenu::~RowTreeContextMenu() -{ -} - -void RowTreeContextMenu::initialize() -{ - CDoc &doc(*g_StudioApp.GetCore()->GetDoc()); - qt3dsdm::Qt3DSDMInstanceHandle instance = m_RowTree->instance(); - - // add sub-presentations submenu - if (m_RowTree->objectType() & (OBJTYPE_LAYER | OBJTYPE_IS_MATERIAL | OBJTYPE_IMAGE)) { - m_subpMenu = addMenu(tr("Set sub-presentation")); - connect(m_subpMenu, &QMenu::triggered, this, &RowTreeContextMenu::addSubPresentation); - - m_subpMenu->addAction(tr("[None]")); - for (auto sp : qAsConst(g_StudioApp.m_subpresentations)) - m_subpMenu->addAction(sp.m_id); - - addSeparator(); - } - - // add datainput controller submenu - if (m_RowTree->objectType() & ~(OBJTYPE_GUIDE | OBJTYPE_EFFECT | OBJTYPE_ALIAS | OBJTYPE_SCENE) - && !m_RowTree->isDefaultMaterial()) { - - m_diMenu = addMenu(tr("Set datainput controller")); - connect(m_diMenu, &QMenu::triggered, this, &RowTreeContextMenu::addDiController); - - QVector<qt3dsdm::Qt3DSDMPropertyHandle> propList; - - // If this is a referenced material instance, we need to get the property list from - // the referenced source, and set datainput control to point to the property - // in the referenced source. - auto refInstance = doc.GetStudioSystem()->GetClientDataModelBridge() - ->getMaterialReference(instance); - propList = doc.GetStudioSystem()->GetPropertySystem() - ->GetControllableProperties(refInstance ? refInstance : instance); - - QMap<int, QAction *> sections; - for (const auto &prop : propList) { - QAction *action - = new QAction(QString::fromStdWString(doc.GetPropertySystem() - ->GetFormalName( - refInstance ? refInstance : instance, - prop).wide_str())); - action->setData(QString::fromStdWString( - doc.GetPropertySystem() - ->GetName(prop).wide_str())); - - auto metadata = doc.GetStudioSystem()->GetActionMetaData()->GetMetaDataPropertyInfo( - doc.GetStudioSystem()->GetActionMetaData()->GetMetaDataProperty( - refInstance ? refInstance : instance, prop)); - - if (sections.contains(metadata->m_CompleteType) ) { - m_diMenu->insertAction(sections[metadata->m_CompleteType], action); - } else { - // Create a QAction for a section so that we can insert properties above it - // to maintain category groupings. Sections are shown as separators in Studio - // style i.e. enum text is not shown. - QAction *section = m_diMenu->addSection(QString(metadata->m_CompleteType)); - sections.insert(metadata->m_CompleteType, section); - m_diMenu->insertAction(section, action); - } - } - } - m_renameAction = new QAction(tr("Rename Object"), this); - connect(m_renameAction, &QAction::triggered, this, &RowTreeContextMenu::renameObject); - addAction(m_renameAction); - - m_duplicateAction = new QAction(tr("Duplicate Object"), this); - m_duplicateAction->setShortcut(QKeySequence(Qt::ControlModifier | Qt::Key_D)); - m_duplicateAction->setShortcutVisibleInContextMenu(true); - connect(m_duplicateAction, &QAction::triggered, - this, &RowTreeContextMenu::duplicateObject); - addAction(m_duplicateAction); - - m_deleteAction = new QAction(tr("Delete Object"), this); - m_deleteAction->setShortcut(Qt::Key_Delete); - m_deleteAction->setShortcutVisibleInContextMenu(true); - connect(m_deleteAction, &QAction::triggered, this, &RowTreeContextMenu::deleteObject); - addAction(m_deleteAction); - - m_groupAction = new QAction(tr("Group Objects"), this); - m_groupAction->setShortcut(QKeySequence(Qt::ControlModifier | Qt::Key_G)); - m_groupAction->setShortcutVisibleInContextMenu(true); - connect(m_groupAction, &QAction::triggered, this, &RowTreeContextMenu::groupObjects); - addAction(m_groupAction); - - addSeparator(); - - m_addLayerAction = new QAction(tr("Add Layer"), this); - m_addLayerAction->setShortcut(QKeySequence(Qt::ControlModifier | Qt::Key_L)); - m_addLayerAction->setShortcutVisibleInContextMenu(true); - connect(m_addLayerAction, &QAction::triggered, this, &RowTreeContextMenu::addLayer); - addAction(m_addLayerAction); - - addSeparator(); - - m_copyAction = new QAction(tr("Copy"), this); - m_copyAction->setShortcut(QKeySequence(Qt::ControlModifier | Qt::Key_C)); - m_copyAction->setShortcutVisibleInContextMenu(true); - connect(m_copyAction, &QAction::triggered, this, &RowTreeContextMenu::copyObject); - addAction(m_copyAction); - - m_pasteAction = new QAction(tr("Paste"), this); - m_pasteAction->setShortcut(QKeySequence(Qt::ControlModifier | Qt::Key_V)); - m_pasteAction->setShortcutVisibleInContextMenu(true); - connect(m_pasteAction, &QAction::triggered, this, &RowTreeContextMenu::pasteObject); - addAction(m_pasteAction); - - m_cutAction = new QAction(tr("Cut"), this); - m_cutAction->setShortcut(QKeySequence(Qt::ControlModifier | Qt::Key_X)); - m_cutAction->setShortcutVisibleInContextMenu(true); - connect(m_cutAction, &QAction::triggered, this, &RowTreeContextMenu::cutObject); - addAction(m_cutAction); - addSeparator(); - - m_makeAction = new QAction(tr("Make Component"), this); - m_makeAction->setShortcut(QKeySequence(Qt::ShiftModifier | Qt::Key_G)); - m_makeAction->setShortcutVisibleInContextMenu(true); - connect(m_makeAction, &QAction::triggered, this, &RowTreeContextMenu::makeComponent); - addAction(m_makeAction); - - if (canInspectComponent()) { - m_inspectAction = new QAction(tr("Edit Component"), this); - m_inspectAction->setShortcut(QKeySequence( - Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_G)); - m_inspectAction->setShortcutVisibleInContextMenu(true); - connect(m_inspectAction, &QAction::triggered, this, &RowTreeContextMenu::inspectComponent); - addAction(m_inspectAction); - } - - if (canMakeAnimatable()) { - m_animAction = new QAction(tr("Make Animatable"), this); - connect(m_animAction, &QAction::triggered, this, &RowTreeContextMenu::makeAnimatable); - addAction(m_animAction); - } - - addSeparator(); - - m_copyPathAction = new QAction(tr("Copy Object Path"), this); - m_copyPathAction->setShortcut(QKeySequence( - Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_C)); - m_copyPathAction->setShortcutVisibleInContextMenu(true); - connect(m_copyPathAction, &QAction::triggered, this, &RowTreeContextMenu::copyObjectPath); - addAction(m_copyPathAction); -} - -void RowTreeContextMenu::showEvent(QShowEvent *event) -{ - if (m_subpMenu) - m_subpMenu->setEnabled(canAddSubPresentation()); - if (m_diMenu) - m_diMenu->setEnabled(true); - m_renameAction->setEnabled(canRenameObject()); - m_duplicateAction->setEnabled(canDuplicateObject()); - m_deleteAction->setEnabled(canDeleteObject()); - m_canGroupObjects = canGroupObjects(); - m_canUngroupObjects = canUngroupObjects(); - m_groupAction->setEnabled(m_canUngroupObjects || m_canGroupObjects); - if (m_canUngroupObjects) - m_groupAction->setText(tr("Ungroup Objects")); - - m_cutAction->setEnabled(canCutObject()); - m_copyAction->setEnabled(canCopyObject()); - m_pasteAction->setEnabled(canPasteObject()); - - m_makeAction->setEnabled(canMakeComponent()); - - m_addLayerAction->setEnabled(canAddLayer()); - - QMenu::showEvent(event); -} - -bool RowTreeContextMenu::canAddSubPresentation() const -{ - return !g_StudioApp.m_subpresentations.empty(); -} - -bool RowTreeContextMenu::canRenameObject() const -{ - return m_TimelineItemBinding->IsValidTransaction( - ITimelineItemBinding::EUserTransaction_Rename); -} - -void RowTreeContextMenu::addSubPresentation(QAction *action) -{ - CDoc &doc(*g_StudioApp.GetCore()->GetDoc()); - auto &bridge(*doc.GetStudioSystem()->GetClientDataModelBridge()); - - qt3dsdm::Qt3DSDMInstanceHandle instance = m_RowTree->instance(); - Q3DStudio::CString presentationId; - if (action->text() != tr("[None]")) - presentationId = Q3DStudio::CString::fromQString(action->text()); - - if (m_RowTree->objectType() == OBJTYPE_LAYER) { - qt3dsdm::Qt3DSDMPropertyHandle propHandle = bridge.GetSourcePathProperty(); - - Q3DStudio::SCOPED_DOCUMENT_EDITOR(doc, tr("Set layer sub-presentation")) - ->SetInstancePropertyValueAsRenderable(instance, propHandle, presentationId); - } else if (m_RowTree->objectType() & OBJTYPE_IS_MATERIAL) { - // if this is a ref material, update the material it references - qt3dsdm::Qt3DSDMInstanceHandle refInstance = bridge.getMaterialReference(instance); - - ChooseImagePropertyDlg dlg(refInstance ? refInstance : instance, refInstance != 0); - if (dlg.exec() == QDialog::Accepted) { - qt3dsdm::Qt3DSDMPropertyHandle propHandle = dlg.getSelectedPropertyHandle(); - if (dlg.detachMaterial()) { - Q3DStudio::ScopedDocumentEditor editor(Q3DStudio::SCOPED_DOCUMENT_EDITOR(doc, - tr("Set material sub-presentation"))); - editor->BeginAggregateOperation(); - editor->SetMaterialType(instance, QStringLiteral("Standard Material")); - editor->setInstanceImagePropertyValue(instance, propHandle, presentationId); - editor->EndAggregateOperation(); - } else { - Q3DStudio::SCOPED_DOCUMENT_EDITOR(doc, tr("Set material sub-presentation")) - ->setInstanceImagePropertyValue(refInstance ? refInstance : instance, propHandle, - presentationId); - } - } - } else if (m_RowTree->objectType() == OBJTYPE_IMAGE) { - qt3dsdm::Qt3DSDMPropertyHandle propHandle = bridge.getSubpresentationProperty(); - - Q3DStudio::SCOPED_DOCUMENT_EDITOR(doc, tr("Set image sub-presentation")) - ->SetInstancePropertyValueAsRenderable(instance, propHandle, presentationId); - } -} - -void RowTreeContextMenu::addDiController(QAction *action) -{ - m_RowTree->showDataInputSelector(action->data().toString(), QCursor::pos()); -} - -void RowTreeContextMenu::renameObject() -{ - m_RowTree->selectLabel(); -} - -bool RowTreeContextMenu::canDuplicateObject() const -{ - return m_TimelineItemBinding->IsValidTransaction( - ITimelineItemBinding::EUserTransaction_Duplicate); -} - -void RowTreeContextMenu::duplicateObject() -{ - m_TimelineItemBinding->PerformTransaction( - ITimelineItemBinding::EUserTransaction_Duplicate); -} - -bool RowTreeContextMenu::canDeleteObject() const -{ - return m_TimelineItemBinding->IsValidTransaction( - ITimelineItemBinding::EUserTransaction_Delete); -} - -bool RowTreeContextMenu::canGroupObjects() const -{ - return m_TimelineItemBinding->IsValidTransaction( - ITimelineItemBinding::EUserTransaction_Group); -} - -bool RowTreeContextMenu::canUngroupObjects() const -{ - return m_TimelineItemBinding->IsValidTransaction( - ITimelineItemBinding::EUserTransaction_Ungroup); -} - -void RowTreeContextMenu::deleteObject() -{ - m_TimelineItemBinding->PerformTransaction( - ITimelineItemBinding::EUserTransaction_Delete); -} - -void RowTreeContextMenu::groupObjects() -{ - if (m_canUngroupObjects) - m_TimelineItemBinding->PerformTransaction(ITimelineItemBinding::EUserTransaction_Ungroup); - else if (m_canGroupObjects) - m_TimelineItemBinding->PerformTransaction(ITimelineItemBinding::EUserTransaction_Group); -} - -bool RowTreeContextMenu::canInspectComponent() const -{ - return m_TimelineItemBinding->IsValidTransaction( - ITimelineItemBinding::EUserTransaction_EditComponent); -} - -/** - * Inspect the State (Component). - * This will make the component the top level item of the timelineview. - */ -void RowTreeContextMenu::inspectComponent() -{ - m_TimelineItemBinding->OpenAssociatedEditor(); -} - -/** - * Checks to see if the object can be wrapped in a component. - * @return true if the object is allowed to be wrapped in a component. - */ -bool RowTreeContextMenu::canMakeComponent() const -{ - return m_TimelineItemBinding->IsValidTransaction( - ITimelineItemBinding::EUserTransaction_MakeComponent); -} - -/** - * Wraps the specified asset hierarchy under a component. - */ -void RowTreeContextMenu::makeComponent() -{ - m_TimelineItemBinding->PerformTransaction( - ITimelineItemBinding::EUserTransaction_MakeComponent); -} - -/** - * Returns true if the object is a referenced material and thus can be made animatable - */ -bool RowTreeContextMenu::canMakeAnimatable() const -{ - return m_TimelineItemBinding->IsValidTransaction( - ITimelineItemBinding::EUserTransaction_MakeAnimatable); -} - -/** - * Makes a referenced material animatable aka changing it to a standard or a custom material - * with the same properties - */ -void RowTreeContextMenu::makeAnimatable() -{ - m_TimelineItemBinding->PerformTransaction( - ITimelineItemBinding::EUserTransaction_MakeAnimatable); -} - -/** - * Get the full Scripting path of the object and copy it to the clipboard. - * This will figure out the proper way to address the object via scripting - * and put that path into the clipboard. - */ -void RowTreeContextMenu::copyObjectPath() -{ - CStudioClipboard::CopyTextToClipboard( - m_TimelineItemBinding->GetObjectPath().toQString()); -} - -bool RowTreeContextMenu::canCopyObject() const -{ - return m_TimelineItemBinding->IsValidTransaction( - ITimelineItemBinding::EUserTransaction_Copy); -} - -void RowTreeContextMenu::copyObject() -{ - m_TimelineItemBinding->PerformTransaction( - ITimelineItemBinding::EUserTransaction_Copy); -} - -bool RowTreeContextMenu::canCutObject() const -{ - return m_TimelineItemBinding->IsValidTransaction( - ITimelineItemBinding::EUserTransaction_Cut); -} - -void RowTreeContextMenu::cutObject() -{ - m_TimelineItemBinding->PerformTransaction( - ITimelineItemBinding::EUserTransaction_Cut); -} - -bool RowTreeContextMenu::canAddLayer() const -{ - return m_TimelineItemBinding->IsValidTransaction( - ITimelineItemBinding::EUserTransaction_AddLayer); -} -void RowTreeContextMenu::addLayer() -{ - m_TimelineItemBinding->PerformTransaction( - ITimelineItemBinding::EUserTransaction_AddLayer); -} - -bool RowTreeContextMenu::canPasteObject() const -{ - return m_TimelineItemBinding->IsValidTransaction( - ITimelineItemBinding::EUserTransaction_Paste); -} - -void RowTreeContextMenu::pasteObject() -{ - m_TimelineItemBinding->PerformTransaction( - ITimelineItemBinding::EUserTransaction_Paste); -} diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeContextMenu.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeContextMenu.h deleted file mode 100644 index 0ef87552..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeContextMenu.h +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef ROWTREECONTEXTMENU_H -#define ROWTREECONTEXTMENU_H - -#include <QtWidgets/qmenu.h> -#include <QtWidgets/qaction.h> - -class ITimelineItemBinding; -class RowTree; - -class RowTreeContextMenu : public QMenu -{ - Q_OBJECT -public: - RowTreeContextMenu(RowTree *inRowTree, - QWidget *parent = nullptr); - virtual ~RowTreeContextMenu(); - -protected: - void showEvent(QShowEvent *event) override; - -private Q_SLOTS: - void addSubPresentation(QAction *action); - void addDiController(QAction *action); - void renameObject(); - void duplicateObject(); - void deleteObject(); - void groupObjects(); - void inspectComponent(); - void makeComponent(); - void makeAnimatable(); - void copyObject(); - void copyObjectPath(); - void pasteObject(); - void cutObject(); - void addLayer(); - -private: - void initialize(); - - bool canAddSubPresentation() const; - bool canRenameObject() const; - bool canDuplicateObject() const; - bool canDeleteObject() const; - bool canGroupObjects() const; - bool canUngroupObjects() const; - bool canInspectComponent() const; - bool canMakeComponent() const; - bool canMakeAnimatable() const; - bool canCopyObject() const; - bool canPasteObject() const; - bool canCutObject() const; - bool canAddLayer() const; - - RowTree *m_RowTree; - ITimelineItemBinding *m_TimelineItemBinding; - QMenu *m_subpMenu = nullptr; // sub-presentation submenu - QMenu *m_diMenu = nullptr; // datainput submenu - QAction *m_renameAction = nullptr; - QAction *m_duplicateAction = nullptr; - QAction *m_deleteAction = nullptr; - QAction *m_groupAction = nullptr; - QAction *m_addLayerAction = nullptr; - QAction *m_inspectAction = nullptr; - QAction *m_makeAction = nullptr; - QAction *m_animAction = nullptr; - QAction *m_copyPathAction = nullptr; - QAction *m_cutAction = nullptr; - QAction *m_copyAction = nullptr; - QAction *m_pasteAction = nullptr; - bool m_canGroupObjects = false; - bool m_canUngroupObjects = false; -}; -#endif // ROWTREECONTEXTMENU_H diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeLabelItem.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeLabelItem.cpp deleted file mode 100644 index 21b57aaa..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeLabelItem.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/**************************************************************************** -** -** 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 "RowTreeLabelItem.h" -#include "TimelineConstants.h" -#include "TimelineItem.h" -#include "RowTree.h" -#include "StudioPreferences.h" - -#include <QtWidgets/qstyleoption.h> -#include <QtGui/qevent.h> -#include <QtGui/qtextcursor.h> - -RowTreeLabelItem::RowTreeLabelItem(QGraphicsItem *parent) - : QGraphicsTextItem(parent) - , m_locked(false) - , m_master(false) - , m_acceptOnFocusOut(true) -{ - setTextInteractionFlags(Qt::TextEditorInteraction); - setEnabled(false); - updateLabelColor(); -} - -QString RowTreeLabelItem::label() const -{ - return m_label; -} - -void RowTreeLabelItem::setLabel(const QString &label) -{ - setPlainText(label); - if (m_label != label) { - m_label = label; - emit labelChanged(m_label); - } -} - -void RowTreeLabelItem::setMaster(bool isMaster) { - if (m_master != isMaster) { - m_master = isMaster; - updateLabelColor(); - } -} - -void RowTreeLabelItem::setLocked(bool isLocked) { - if (m_locked != isLocked) { - m_locked = isLocked; - updateLabelColor(); - } -} - -RowTree *RowTreeLabelItem::parentRow() const -{ - return m_rowTree; -} - -void RowTreeLabelItem::setParentRow(RowTree *row) -{ - m_rowTree = row; -} - -int RowTreeLabelItem::type() const -{ - // Enable the use of qgraphicsitem_cast with this item. - return TimelineItem::TypeRowTreeLabelItem; -} - -void RowTreeLabelItem::paint(QPainter *painter, - const QStyleOptionGraphicsItem *option, - QWidget *widget) -{ - if (!m_rowTree->y()) // prevents flickering when the row is just inserted to the layout - return; - - // Remove the HasFocus style state, to prevent the dotted line from being drawn. - QStyleOptionGraphicsItem *style = const_cast<QStyleOptionGraphicsItem *>(option); - style->state &= ~QStyle::State_HasFocus; - - QGraphicsTextItem::paint(painter, option, widget); -} - -void RowTreeLabelItem::focusOutEvent(QFocusEvent *event) -{ - if (m_acceptOnFocusOut) - validateLabel(); - else - setPlainText(m_label); - - // Remove possible selection and make disabled again - QTextCursor cursor = textCursor(); - cursor.clearSelection(); - setTextCursor(cursor); - setEnabled(false); - QGraphicsTextItem::focusOutEvent(event); - // Next time default to accepting - m_acceptOnFocusOut = true; -} - -void RowTreeLabelItem::keyPressEvent(QKeyEvent *event) -{ - int key = event->key(); - if (key == Qt::Key_Return || key == Qt::Key_Enter) { - m_acceptOnFocusOut = true; - clearFocus(); - event->accept(); - return; - } else if (key == Qt::Key_Escape) { - m_acceptOnFocusOut = false; - clearFocus(); - event->accept(); - return; - } - - QGraphicsTextItem::keyPressEvent(event); -} - -QRectF RowTreeLabelItem::boundingRect() const -{ - if (!m_rowTree) - return QGraphicsTextItem::boundingRect(); - - double w = m_rowTree->clipX() - x(); - // Bounding rect width must be at least 1 - w = std::max(w, 1.0); - return QRectF(0, 0, w, TimelineConstants::ROW_H); -} - -void RowTreeLabelItem::validateLabel() -{ - QString text = toPlainText().trimmed(); - if (text.isEmpty()) { - // Inform label was empty and return previous label - emit labelChanged(""); - setLabel(m_label); - return; - } - - setLabel(text); -} - -void RowTreeLabelItem::updateLabelColor() -{ - if (m_locked) - setDefaultTextColor(CStudioPreferences::GetDisabledTextColor()); - else if (m_master) - setDefaultTextColor(CStudioPreferences::GetMasterColor()); - else - setDefaultTextColor(CStudioPreferences::GetNormalColor()); -} diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeLabelItem.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeLabelItem.h deleted file mode 100644 index edffbef5..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeLabelItem.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef ROWTREELABELITEM_H -#define ROWTREELABELITEM_H - -#include "StudioObjectTypes.h" -#include <QtWidgets/qgraphicsitem.h> -#include <QtCore/qstring.h> -#include <QtWidgets/qgraphicssceneevent.h> -#include <QtGui/qevent.h> - -class RowTree; - -class RowTreeLabelItem : public QGraphicsTextItem -{ - Q_OBJECT -public: - explicit RowTreeLabelItem(QGraphicsItem *parent = nullptr); - - QString label() const; - void setLabel(const QString &label); - void setLocked(bool isLocked); - void setMaster(bool isMaster); - RowTree *parentRow() const; - void setParentRow(RowTree *row); - int type() const; - bool isLocked() const { return m_locked; } - -protected: - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; - void focusOutEvent(QFocusEvent *event) override; - void keyPressEvent(QKeyEvent *event) override; - QRectF boundingRect() const override; - -signals: - void labelChanged(const QString label); - -private: - void validateLabel(); - void updateLabelColor(); - - RowTree *m_rowTree = nullptr; - QString m_label; - bool m_locked; - bool m_master; - bool m_acceptOnFocusOut; - -}; - -#endif // ROWTREELABELITEM_H diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.cpp deleted file mode 100644 index 62c6de01..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.cpp +++ /dev/null @@ -1,219 +0,0 @@ -/**************************************************************************** -** -** 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 "Ruler.h" -#include "TimelineConstants.h" -#include "StudioPreferences.h" - -#include <QtGui/qpainter.h> -#include <QtWidgets/qwidget.h> - -Ruler::Ruler(TimelineItem *parent) : TimelineItem(parent) -{ - setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); -} - -void Ruler::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - Q_UNUSED(option) - - double xStep = TimelineConstants::RULER_SEC_W / TimelineConstants::RULER_SEC_DIV * m_timeScale; - double activeSegmentsWidth = TimelineConstants::RULER_EDGE_OFFSET - + m_duration / 1000.0 * xStep * TimelineConstants::RULER_SEC_DIV; - double totalSegmentsWidth = TimelineConstants::RULER_EDGE_OFFSET - + m_maxDuration / 1000.0 * xStep * TimelineConstants::RULER_SEC_DIV; - - // Ruler painted width to be at least widget width - double minRulerWidth = widget->width(); - double rowXMax = std::max(minRulerWidth, totalSegmentsWidth); - - painter->save(); - painter->setPen(CStudioPreferences::timelineRulerColorDisabled()); - painter->drawLine(TimelineConstants::RULER_EDGE_OFFSET, - TimelineConstants::RULER_BASE_Y, - rowXMax + TimelineConstants::RULER_EDGE_OFFSET, - TimelineConstants::RULER_BASE_Y); - painter->setPen(CStudioPreferences::timelineRulerColor()); - painter->drawLine(TimelineConstants::RULER_EDGE_OFFSET, - TimelineConstants::RULER_BASE_Y, - activeSegmentsWidth, - TimelineConstants::RULER_BASE_Y); - - QFont font = painter->font(); - font.setPointSize(8); - painter->setFont(font); - - const int margin = 50; - const int secDiv = TimelineConstants::RULER_SEC_DIV; - double rowX = 0; - bool useDisabledColor = false; - for (int i = 0; rowX < rowXMax; i++) { - rowX = TimelineConstants::RULER_EDGE_OFFSET + xStep * i; - - // Optimization to skip painting outside the visible area - if (rowX < (m_viewportX - margin) || rowX > (m_viewportX + minRulerWidth + margin)) - continue; - - const int h = i % secDiv == 0 ? TimelineConstants::RULER_DIV_H1 - : i % secDiv == secDiv * 0.5 ? TimelineConstants::RULER_DIV_H2 - : TimelineConstants::RULER_DIV_H3; - - if (!useDisabledColor && rowX > activeSegmentsWidth) { - painter->setPen(CStudioPreferences::timelineRulerColorDisabled()); - useDisabledColor = true; - } - painter->drawLine(QPointF(rowX, TimelineConstants::RULER_BASE_Y - h), - QPointF(rowX, TimelineConstants::RULER_BASE_Y - 1)); - - // See if label should be shown at this tick at this zoom level - bool drawTimestamp = false; - if ((i % (secDiv * 4) == 0) - || (i % (secDiv * 2) == 0 && m_timeScale >= TimelineConstants::RULER_TICK_SCALE1) - || (i % secDiv == 0 && m_timeScale >= TimelineConstants::RULER_TICK_SCALE2) - || (i % secDiv == secDiv * 0.5 - && m_timeScale >= TimelineConstants::RULER_TICK_SCALE3) - || (m_timeScale >= TimelineConstants::RULER_TICK_SCALE4)) { - drawTimestamp = true; - } - - if (drawTimestamp) { - QRectF timestampPos = QRectF(TimelineConstants::RULER_EDGE_OFFSET - + xStep * i - TimelineConstants::RULER_LABEL_W / 2, - 1, TimelineConstants::RULER_LABEL_W, - TimelineConstants::RULER_LABEL_H); - painter->drawText(timestampPos, Qt::AlignCenter, - timestampString(i * 1000 / TimelineConstants::RULER_SEC_DIV)); - } - - } - - painter->restore(); -} - -void Ruler::setTimelineScale(double scl) -{ - m_timeScale = scl; - update(); -} - -// convert distance values to time (milliseconds) -long Ruler::distanceToTime(double distance) const -{ - return distance / (TimelineConstants::RULER_MILLI_W * m_timeScale); -} - -// convert time (milliseconds) values to distance -double Ruler::timeToDistance(long time) const -{ - return time * TimelineConstants::RULER_MILLI_W * m_timeScale; -} - -double Ruler::timelineScale() const -{ - return m_timeScale; -} - -// Returns end of right-most layer/component row. -// Active color of ruler is used up to this point. -// Slide plays up to this point. -long Ruler::duration() const -{ - return m_duration; -} - -// Returns end of right-most row. -// Ruler steps & labels are drawn up to this point. -// Timeline scrollbar allows scrolling up to this point. -long Ruler::maxDuration() const -{ - return m_maxDuration; -} - -void Ruler::setDuration(long duration) -{ - if (m_duration != duration) { - m_duration = duration; - update(); - emit durationChanged(m_duration); - } -} - -void Ruler::setMaxDuration(long maxDuration) -{ - if (m_maxDuration != maxDuration) { - m_maxDuration = maxDuration; - update(); - emit maxDurationChanged(m_maxDuration); - } -} - -void Ruler::setViewportX(int viewportX) -{ - if (m_viewportX != viewportX) { - m_viewportX = viewportX; - emit viewportXChanged(m_viewportX); - update(); - } -} - -int Ruler::viewportX() const -{ - return m_viewportX; -} - -// Returns timestamp in mm:ss.ttt or ss.ttt format -const QString Ruler::timestampString(int timeMs) -{ - static const QString zeroString = tr("0"); - static const QChar fillChar = tr("0").at(0); - static const QString noMinutesTemplate = tr("%1.%2"); - static const QString minutesTemplate = tr("%1:%2.%3"); - - int ms = timeMs % 1000; - int s = timeMs % 60000 / 1000; - int m = timeMs % 3600000 / 60000; - const QString msString = QString::number(ms).rightJustified(3, fillChar); - const QString sString = QString::number(s); - - if (timeMs == 0) { - return zeroString; - } else if (m == 0) { - if (s < 10) - return noMinutesTemplate.arg(sString).arg(msString); - else - return noMinutesTemplate.arg(sString.rightJustified(2, fillChar)).arg(msString); - } else { - return minutesTemplate.arg(m).arg(sString.rightJustified(2, fillChar)).arg(msString); - } -} - -int Ruler::type() const -{ - // Enable the use of qgraphicsitem_cast with this item. - return TypeRuler; -} diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.h deleted file mode 100644 index 005a23c3..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef RULER_H -#define RULER_H - -#include "TimelineItem.h" - -class Ruler : public TimelineItem -{ - Q_OBJECT - -signals: - void rulerClicked(const double &pos); - -public: - explicit Ruler(TimelineItem *parent = nullptr); - - void setTimelineScale(double scl); - long distanceToTime(double distance) const; - double timeToDistance(long time) const; - double timelineScale() const; - long duration() const; - long maxDuration() const; - void setDuration(long duration); - void setMaxDuration(long maxDuration); - void setViewportX(int viewportX); - int viewportX() const; - int type() const override; - -protected: - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) override; - -signals: - void maxDurationChanged(long maxDuration); - void durationChanged(long duration); - void viewportXChanged(int viewportX); - -private: - const QString timestampString(int timeMs); - double m_timeScale = 2; - long m_duration = 0; // milliseconds - long m_maxDuration = 0; // milliseconds - int m_viewportX = 0; -}; - -#endif // RULER_H diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineItem.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineItem.cpp deleted file mode 100644 index 866d8109..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineItem.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** 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 "TimelineItem.h" -#include "TimelineConstants.h" - -#include <QtGui/qpainter.h> - -TimelineItem::TimelineItem(TimelineItem *parent) : QGraphicsWidget(parent) -{ - setPreferredHeight(TimelineConstants::ROW_H_EXPANDED); - setMaximumHeight(TimelineConstants::ROW_H); -} - -int TimelineItem::type() const -{ - // Enable the use of qgraphicsitem_cast with this item. - return TypeTimelineItem; -} diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineItem.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineItem.h deleted file mode 100644 index 71d26c0d..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineItem.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef TIMELINEITEM_H -#define TIMELINEITEM_H - -#include <QtWidgets/qgraphicswidget.h> - -class TimelineItem : public QGraphicsWidget -{ - Q_OBJECT - -public: - explicit TimelineItem(TimelineItem *parent = nullptr); - - enum ItemType { - TypeTimelineItem = UserType + 1, - TypeInteractiveTimelineItem, - TypeTreeHeader, - TypeRowTree, - TypeRowTreeLabelItem, - TypeRowTimeline, - TypeRowTimelineCommentItem, - TypePlayHead, - TypeRuler, - TypeRowMover - }; - - int type() const override; -}; - -#endif // TIMELINEITEM_H diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.cpp deleted file mode 100644 index 05d24fa6..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.cpp +++ /dev/null @@ -1,456 +0,0 @@ -/**************************************************************************** -** -** 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 "TimelineToolbar.h" -#include "StudioApp.h" -#include "Core.h" -#include "Doc.h" -#include "Dispatch.h" -#include "DataInputSelectView.h" -#include "DataInputDlg.h" -#include "Qt3DSDMStudioSystem.h" -#include "StudioPreferences.h" -#include "ClientDataModelBridge.h" -#include "IDocumentEditor.h" -#include "DocumentEditorEnumerations.h" -#include "Dialogs.h" - -#include <QtWidgets/qslider.h> -#include <QtCore/qdatetime.h> -#include <QtCore/qtimer.h> -#include <QtWidgets/qpushbutton.h> -#include <QtWidgets/qshortcut.h> - -TimelineToolbar::TimelineToolbar() : QToolBar() -{ - setContentsMargins(0, 0, 0, 0); - setIconSize(QSize(16, 16)); - - // create icons - static const QIcon iconLayer = QIcon(":/images/Objects-Layer-Normal.png"); - static const QIcon iconDelete = QIcon(":/images/Action-Trash-Normal.png"); - static const QIcon iconFirst = QIcon(":/images/playback_tools_first.png"); - static const QIcon iconLast = QIcon(":/images/playback_tools_last.png"); - static const QIcon iconZoomIn = QIcon(":/images/zoom_in.png"); - static const QIcon iconZoomOut = QIcon(":/images/zoom_out.png"); - m_iconDiActive = QIcon(":/images/Objects-DataInput-Active.png"); - m_iconDiInactive = QIcon(":/images/Objects-DataInput-Inactive.png"); - m_iconStop = QIcon(":/images/playback_tools_stop.png"); - m_iconPlay = QIcon(":/images/playback_tools_play.png"); - - // create actions - QString ctrlKey(QStringLiteral("Ctrl+")); - QString altKey(QStringLiteral("Alt+")); -#ifdef Q_OS_MACOS - ctrlKey = "⌘"; - altKey = "⌥"; -#endif - QString newLayerString = tr("Add New Layer (%1L)").arg(ctrlKey); - m_actionNewLayer = new QAction(iconLayer, newLayerString, this); - QAction *actionFirst = new QAction(iconFirst, tr("Go to Timeline Start"), this); - QAction *actionLast = new QAction(iconLast, tr("Go to Timeline End"), this); - m_actionDataInput = new QAction(m_iconDiInactive, tr("No Controller"), this); - m_actionDeleteRow = new QAction(iconDelete, tr("Delete Selected Object (Del)"), this); - m_actionPlayStop = new QAction(this); - m_timeLabel = new QPushButton(this); - m_diLabel = new QLabel(this); - m_actionZoomIn = new QAction(iconZoomIn, tr("Zoom In"), this); - m_actionZoomOut = new QAction(iconZoomOut, tr("Zoom Out"), this); - - m_scaleSlider = new QSlider(); - m_scaleSlider->setOrientation(Qt::Horizontal); - m_scaleSlider->setFixedWidth(100); - m_scaleSlider->setMinimum(1); - m_scaleSlider->setMaximum(22); - m_scaleSlider->setValue(2); - - m_timeLabel->setObjectName(QLatin1String("timelineButton")); - m_timeLabel->setFlat(true); - m_timeLabel->setMinimumWidth(80); - m_timeLabel->setToolTip(tr("Go To Time (%1%2T)").arg(ctrlKey).arg(altKey)); - - m_diLabel->setText(""); - m_diLabel->setMinimumWidth(100); - m_diLabel->setAlignment(Qt::AlignCenter); - QString styleString = "QLabel { background: transparent; color: " - + QString(CStudioPreferences::dataInputColor().name()) + "; }"; - m_diLabel->setStyleSheet(styleString); - - m_actionShowRowTexts = new QAction(tr("Toggle Timebars Text Visibility"), this); - QIcon rowTextIcon { QPixmap(":/images/timeline_text_hidden.png") }; - rowTextIcon.addPixmap(QPixmap(":/images/timeline_text_shown.png"), QIcon::Normal, QIcon::On); - m_actionShowRowTexts->setIcon(rowTextIcon); - m_actionShowRowTexts->setCheckable(true); - m_actionFilter = new QAction(tr("Filter Timeline Rows Visibility According to Variants Filter"), - this); - m_actionFilter->setCheckable(true); - QIcon filterIcon { QPixmap(":/images/filter.png") }; - filterIcon.addPixmap(QPixmap(":/images/filter-colored.png"), QIcon::Normal, QIcon::On); - m_actionFilter->setIcon(filterIcon); - - updatePlayButtonState(false); - - // connections - connect(m_actionNewLayer, &QAction::triggered, this, &TimelineToolbar::newLayerTriggered); - connect(m_actionDeleteRow, &QAction::triggered, this, &TimelineToolbar::deleteLayerTriggered); - connect(m_timeLabel, &QPushButton::clicked, this, &TimelineToolbar::gotoTimeTriggered); - connect(actionFirst, &QAction::triggered, this, &TimelineToolbar::firstFrameTriggered); - connect(m_actionPlayStop, &QAction::triggered, this, &TimelineToolbar::onPlayButtonClicked); - connect(actionLast, &QAction::triggered, this, &TimelineToolbar::lastFrameTriggered); - connect(m_scaleSlider, &QSlider::valueChanged, this, &TimelineToolbar::onZoomLevelChanged); - connect(m_actionZoomIn, &QAction::triggered, this, &TimelineToolbar::onZoomInButtonClicked); - connect(m_actionZoomOut, &QAction::triggered, this, &TimelineToolbar::onZoomOutButtonClicked); - connect(m_actionDataInput, &QAction::triggered, this, &TimelineToolbar::onDiButtonClicked); - connect(m_actionShowRowTexts, &QAction::toggled, this, &TimelineToolbar::showRowTextsToggled); - connect(m_actionFilter, &QAction::toggled, this, &TimelineToolbar::variantsFilterToggled); - - // add actions - addAction(m_actionNewLayer); - addAction(m_actionDeleteRow); - addAction(m_actionDataInput); - addSpacing(2); - addAction(m_actionShowRowTexts); - addAction(m_actionFilter); - addWidget(m_diLabel); - addSpacing(20); - addWidget(m_timeLabel); - addSpacing(20); - addAction(actionFirst); - addAction(m_actionPlayStop); - addAction(actionLast); - addSpacing(30); - addAction(m_actionZoomOut); - addWidget(m_scaleSlider); - addAction(m_actionZoomIn); - - // add keyboard shortcuts - m_actionZoomOut->setShortcut(Qt::Key_Minus); - m_actionZoomOut->setShortcutContext(Qt::ApplicationShortcut); - m_actionZoomIn->setShortcut(Qt::Key_Plus); - m_actionZoomIn->setShortcutContext(Qt::ApplicationShortcut); - m_actionNewLayer->setShortcut(QKeySequence(Qt::ControlModifier | Qt::Key_L)); - m_actionNewLayer->setShortcutContext(Qt::ApplicationShortcut); - - QShortcut *gotoTimeShortcut = new QShortcut(this); - gotoTimeShortcut->setKey(QKeySequence(Qt::ControlModifier | Qt::AltModifier | Qt::Key_T)); - gotoTimeShortcut->setContext(Qt::ApplicationShortcut); - connect(gotoTimeShortcut, &QShortcut::activated, this, &TimelineToolbar::gotoTimeTriggered); - - m_connectSelectionChange = g_StudioApp.GetCore()->GetDispatch()->ConnectSelectionChange( - std::bind(&TimelineToolbar::onSelectionChange, this, std::placeholders::_1)); - - // make datainput indicator listen to selection dialog choice - const QVector<EDataType> acceptedTypes = { EDataType::DataTypeRangedNumber }; - m_dataInputSelector = new DataInputSelectView(acceptedTypes, this); - g_StudioApp.GetCore()->GetDispatch()->AddDataModelListener(this); - connect(m_dataInputSelector, &DataInputSelectView::dataInputChanged, - this, &TimelineToolbar::onDataInputChange); -} - -TimelineToolbar::~TimelineToolbar() -{ - delete m_dataInputSelector; -} - -void TimelineToolbar::onSelectionChange(Q3DStudio::SSelectedValue inNewSelectable) -{ - qt3dsdm::TInstanceHandleList selectedInstances = inNewSelectable.GetSelectedInstances(); - CDoc *doc = g_StudioApp.GetCore()->GetDoc(); - CClientDataModelBridge *theClientBridge = doc->GetStudioSystem()->GetClientDataModelBridge(); - bool canDelete = false; - for (size_t idx = 0, end = selectedInstances.size(); idx < end; ++idx) { - if (theClientBridge->CanDelete(selectedInstances[idx])) { - canDelete = true; - break; - } - } - - m_actionDeleteRow->setEnabled(canDelete); -} - -// add a spacer widget -void TimelineToolbar::addSpacing(int width) -{ - auto *widget = new QWidget; - widget->setStyleSheet("background:transparent;"); - widget->setFixedWidth(width); - addWidget(widget); -} - -void TimelineToolbar::setTime(long totalMillis) -{ - long mins = totalMillis % 3600000 / 60000; - long secs = totalMillis % 60000 / 1000; - long millis = totalMillis % 1000; - - m_timeLabel->setText(QString::asprintf("%01d:%02d.%03d", mins, secs, millis)); -} - -QString TimelineToolbar::getCurrentController() const -{ - return m_currController; -} - -QAction *TimelineToolbar::actionShowRowTexts() const -{ - return m_actionShowRowTexts; -} - -void TimelineToolbar::setNewLayerEnabled(bool enable) -{ - m_actionNewLayer->setEnabled(enable); -} - -void TimelineToolbar::updatePlayButtonState(bool started) -{ - if (started) { - m_actionPlayStop->setIcon(m_iconStop); - m_actionPlayStop->setText(tr("Stop Playing (Enter)")); - } else { - m_actionPlayStop->setIcon(m_iconPlay); - m_actionPlayStop->setText(tr("Start Playing (Enter)")); - } -} - -void TimelineToolbar::onPlayButtonClicked() -{ - CDoc *doc = g_StudioApp.GetCore()->GetDoc(); - if (doc->IsPlaying()) - emit stopTriggered(); - else - emit playTriggered(); -} - -void TimelineToolbar::onZoomLevelChanged(int scale) -{ - m_actionZoomIn->setEnabled(scale < m_scaleSlider->maximum()); - m_actionZoomOut->setEnabled(scale > m_scaleSlider->minimum()); - - emit timelineScaleChanged(scale); -} - -void TimelineToolbar::onZoomInButtonClicked() -{ - m_scaleSlider->setValue(m_scaleSlider->value() + 1); -} - -void TimelineToolbar::onZoomOutButtonClicked() -{ - m_scaleSlider->setValue(m_scaleSlider->value() - 1); -} - -void TimelineToolbar::onDiButtonClicked() -{ - QWidget *diButton = widgetForAction(m_actionDataInput); - if (diButton) { - QPoint chooserPos = diButton->pos() + QPoint(diButton->size().width(), - diButton->size().height()); - showDataInputChooser(mapToGlobal(chooserPos)); - } -} - -bool TimelineToolbar::isVariantsFilterOn() const -{ - return m_actionFilter->isChecked(); -} - -// Update datainput button state according to this timecontext control state. -void TimelineToolbar::updateDataInputStatus() -{ - CDoc *doc = g_StudioApp.GetCore()->GetDoc(); - qt3dsdm::Qt3DSDMPropertyHandle ctrldProp; - qt3dsdm::Qt3DSDMInstanceHandle timeCtxRoot = doc->GetActiveRootInstance(); - CClientDataModelBridge *theClientBridge = doc->GetStudioSystem()->GetClientDataModelBridge(); - if (theClientBridge->GetObjectType(timeCtxRoot) == EStudioObjectType::OBJTYPE_SCENE) { - ctrldProp = theClientBridge->GetObjectDefinitions().m_Scene.m_ControlledProperty; - } else if (theClientBridge->GetObjectType(timeCtxRoot) == - EStudioObjectType::OBJTYPE_COMPONENT) { - ctrldProp = theClientBridge->GetObjectDefinitions().m_Component.m_ControlledProperty; - } else { - Q_ASSERT(false); - } - - qt3dsdm::SValue controlledPropertyVal; - doc->GetStudioSystem()->GetPropertySystem()->GetInstancePropertyValue( - timeCtxRoot, ctrldProp, controlledPropertyVal); - auto existingCtrl = qt3dsdm::get<QString>(controlledPropertyVal); - - QString newController; - int timelineStrPos = existingCtrl.indexOf("@timeline"); - if (timelineStrPos != -1) { - int ctrStrPos = existingCtrl.lastIndexOf("$", timelineStrPos - 2); - newController = existingCtrl.mid(ctrStrPos + 1, timelineStrPos - ctrStrPos - 2); - } - if (newController != m_currController) { - m_currController = newController; - // Toggle if we changed to a controlled time context, or if icon current state - // differs from the control state of current time context - if (!m_currController.isEmpty()) { - m_actionDataInput->setToolTip( - tr("Timeline Controller:\n%1").arg(m_currController)); - m_actionDataInput->setIcon(m_iconDiActive); - updateTimelineTitleColor(true); - } else { - // TODO actually delete the entire property instead of setting it as empty string - m_actionDataInput->setIcon(m_iconDiInactive); - m_actionDataInput->setToolTip(tr("No Controller")); - updateTimelineTitleColor(false); - } - m_diLabel->setText(m_currController); - emit controllerChanged(m_currController); - if (m_dataInputSelector && m_dataInputSelector->isVisible()) - m_dataInputSelector->setCurrentController(m_currController); - } -} - -void TimelineToolbar::showDataInputChooser(const QPoint &point) -{ - QString currCtr = m_currController.size() ? - m_currController : m_dataInputSelector->getNoneString(); - QVector<QPair<QString, int>> dataInputList; - - for (auto &it : qAsConst(g_StudioApp.m_dataInputDialogItems)) - dataInputList.append({it->name, it->type}); - - m_dataInputSelector->setData(dataInputList, currCtr); - - CDialogs::showWidgetBrowser(this, m_dataInputSelector, point, - CDialogs::WidgetBrowserAlign::ToolButton); -} - -void TimelineToolbar::onDataInputChange(int handle, int instance, const QString &dataInputName) -{ - Q_UNUSED(handle) - Q_UNUSED(instance) - - if (dataInputName == m_currController) - return; - - CDoc *doc = g_StudioApp.GetCore()->GetDoc(); - CClientDataModelBridge *bridge = doc->GetStudioSystem()->GetClientDataModelBridge(); - QString fullTimeControlStr; - - if (dataInputName != m_dataInputSelector->getNoneString()) { - m_actionDataInput->setToolTip(tr("Timeline Controller:\n%1").arg(dataInputName)); - fullTimeControlStr = "$" + dataInputName + " @timeline"; - m_actionDataInput->setIcon(m_iconDiActive); - m_currController = dataInputName; - updateTimelineTitleColor(true); - } else { - m_actionDataInput->setToolTip(tr("No Controller")); - // TODO actually delete the entire property instead of setting it as empty string - m_actionDataInput->setIcon(m_iconDiInactive); - m_currController.clear(); - updateTimelineTitleColor(false); - } - - emit controllerChanged(m_currController); - - // To indicate that this presentation timeline is controlled by data input, - // we set "controlled property" of this time context root (scene or component) - // to contain the name of controller followed by special indicator "@timeline". - // Either replace existing timeline control indicator string or append new one - // but do not touch @slide indicator string as scene can have both - qt3dsdm::Qt3DSDMPropertyHandle ctrldPropertyHandle; - qt3dsdm::Qt3DSDMInstanceHandle timeCtxRoot = doc->GetActiveRootInstance(); - // Time context root is either scene or component - if (bridge->GetObjectType(timeCtxRoot) == EStudioObjectType::OBJTYPE_SCENE) - ctrldPropertyHandle = bridge->GetObjectDefinitions().m_Scene.m_ControlledProperty; - else if (bridge->GetObjectType(timeCtxRoot) == EStudioObjectType::OBJTYPE_COMPONENT) - ctrldPropertyHandle = bridge->GetObjectDefinitions().m_Component.m_ControlledProperty; - else - Q_ASSERT(false); - - qt3dsdm::SValue controlledPropertyVal; - doc->GetStudioSystem()->GetPropertySystem()->GetInstancePropertyValue( - timeCtxRoot, ctrldPropertyHandle, controlledPropertyVal); - - auto existingCtrl = qt3dsdm::get<QString>(controlledPropertyVal); - int slideStrPos = existingCtrl.indexOf("@timeline"); - if (slideStrPos != -1) { - // find the controlling datainput name and build the string to replace - int ctrStrPos = existingCtrl.lastIndexOf("$", slideStrPos - 2); - QString prevCtrler = existingCtrl.mid(ctrStrPos, slideStrPos - ctrStrPos); - existingCtrl.replace(prevCtrler + "@timeline", fullTimeControlStr); - } else { - if (!existingCtrl.isEmpty() && m_currController.size()) - existingCtrl.append(" "); - existingCtrl.append(fullTimeControlStr); - } - - if (existingCtrl.endsWith(" ")) - existingCtrl.chop(1); - - if (existingCtrl.startsWith(" ")) - existingCtrl.remove(0, 1); - - m_diLabel->setText(m_currController); - qt3dsdm::SValue fullCtrlPropVal - = std::make_shared<qt3dsdm::CDataStr>( - Q3DStudio::CString::fromQString(existingCtrl)); - Q3DStudio::SCOPED_DOCUMENT_EDITOR(*doc, QObject::tr("Set Timeline control")) - ->SetInstancePropertyValue(timeCtxRoot, ctrldPropertyHandle, fullCtrlPropVal); -} - -void TimelineToolbar::OnBeginDataModelNotifications() -{ -} - -void TimelineToolbar::OnEndDataModelNotifications() -{ - updateDataInputStatus(); -} - -void TimelineToolbar::OnImmediateRefreshInstanceSingle(qt3dsdm::Qt3DSDMInstanceHandle inInstance) -{ - Q_UNUSED(inInstance) -} - -void TimelineToolbar::OnImmediateRefreshInstanceMultiple(qt3dsdm::Qt3DSDMInstanceHandle *inInstance, - long inInstanceCount) -{ - Q_UNUSED(inInstance) - Q_UNUSED(inInstanceCount) -} - -// Notify the user about control state change also with timeline dock -// title color change. -void TimelineToolbar::updateTimelineTitleColor(bool controlled) -{ - QString styleString; - if (controlled) { - styleString = "QDockWidget#timeline { color: " - + QString(CStudioPreferences::dataInputColor().name()) + "; }"; - } else { - styleString = "QDockWidget#timeline { color: " - + QString(CStudioPreferences::textColor().name()) + "; }"; - } - - QWidget *timelineDock = parentWidget()->parentWidget()->parentWidget(); - timelineDock->setStyleSheet(styleString); -} diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.h deleted file mode 100644 index 53a87b18..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.h +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef TIMELINETOOLBAR_H -#define TIMELINETOOLBAR_H - -#include "SelectedValueImpl.h" -#include "Qt3DSDMSignals.h" -#include "DispatchListeners.h" -#include "Dispatch.h" -#include "DataInputSelectView.h" -#include <QtWidgets/qtoolbar.h> -#include <QtWidgets/qlabel.h> - -QT_FORWARD_DECLARE_CLASS(QAction) -QT_FORWARD_DECLARE_CLASS(QSlider) - -class TimelineToolbar : public QToolBar, - public IDataModelListener -{ - Q_OBJECT - -signals: - void newLayerTriggered(); - void deleteLayerTriggered(); - void gotoTimeTriggered(); - void firstFrameTriggered(); - void stopTriggered(); - void playTriggered(); - void controllerChanged(const QString &controller); - void lastFrameTriggered(); - void timelineScaleChanged(int scale); - void setDurationTriggered(); - void showRowTextsToggled(bool toggled); - void variantsFilterToggled(bool toggled); - -public: - TimelineToolbar(); - virtual ~TimelineToolbar() override; - void setTime(long totalMillis); - QString getCurrentController() const; - void setNewLayerEnabled(bool enable); - QAction *actionShowRowTexts() const; - bool isVariantsFilterOn() const; - - // IDataModelListener - void OnBeginDataModelNotifications() override; - void OnEndDataModelNotifications() override; - void OnImmediateRefreshInstanceSingle(qt3dsdm::Qt3DSDMInstanceHandle inInstance) override; - void OnImmediateRefreshInstanceMultiple(qt3dsdm::Qt3DSDMInstanceHandle *inInstance, - long inInstanceCount) override; - -public Q_SLOTS: - void updatePlayButtonState(bool started); - void onZoomInButtonClicked(); - void onZoomOutButtonClicked(); - -private Q_SLOTS: - void onPlayButtonClicked(); - void onZoomLevelChanged(int scale); - void onDiButtonClicked(); - -private: - void addSpacing(int width); - void onSelectionChange(Q3DStudio::SSelectedValue inNewSelectable); - void onDataInputChange(int handle, int instance, const QString &dataInputName); - void showDataInputChooser(const QPoint &point); - void updateDataInputStatus(); - void updateTimelineTitleColor(bool controlled); - - QPushButton *m_timeLabel = nullptr; - QLabel *m_diLabel = nullptr; - QAction *m_actionDeleteRow = nullptr; - QAction *m_actionPlayStop = nullptr; - QAction *m_actionZoomIn = nullptr; - QAction *m_actionZoomOut = nullptr; - QAction *m_actionDataInput = nullptr; - QAction *m_actionNewLayer = nullptr; - QAction *m_actionShowRowTexts = nullptr; - QAction *m_actionFilter = nullptr; - QSlider *m_scaleSlider = nullptr; - qt3dsdm::TSignalConnectionPtr m_connectSelectionChange; - QIcon m_iconStop; - QIcon m_iconPlay; - QIcon m_iconDiActive; - QIcon m_iconDiInactive; - - QString m_currController; - - DataInputSelectView *m_dataInputSelector; -}; -#endif // TIMELINETOOLBAR_H diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeader.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeader.cpp deleted file mode 100644 index 55e0a8fe..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeader.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/**************************************************************************** -** -** 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 "TreeHeader.h" -#include "StudioPreferences.h" -#include "StudioUtils.h" - -#include <QtGui/qpainter.h> - - -TreeHeader::TreeHeader(TimelineGraphicsScene *timelineScene, TimelineItem *parent) - : TimelineItem(parent) - , m_scene(timelineScene) -{ - setAcceptHoverEvents(true); -} - -void TreeHeader::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget) -{ - Q_UNUSED(option) - Q_UNUSED(widget) - - bool hiResIcons = StudioUtils::devicePixelRatio(widget->window()->windowHandle()) > 1.0; - - double treeWidth = m_scene->treeWidth() - m_scene->getScrollbarOffsets().x(); - 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 pixShy2x = QPixmap(":/images/Toggle-Shy@2x.png"); - static const QPixmap pixVisible = QPixmap(":/images/Toggle-HideShow.png"); - static const QPixmap pixVisible2x = QPixmap(":/images/Toggle-HideShow@2x.png"); - static const QPixmap pixLock = QPixmap(":/images/Toggle-Lock.png"); - static const QPixmap pixLock2x = QPixmap(":/images/Toggle-Lock@2x.png"); - - const QColor selectedColor = CStudioPreferences::timelineFilterButtonSelectedColor(); - const QColor hoveredColor = CStudioPreferences::timelineFilterButtonHoveredColor(); - - if (m_shy) - painter->fillRect(m_rectShy, selectedColor); - - if (m_visible) - painter->fillRect(m_rectVisible, selectedColor); - - if (m_lock) - painter->fillRect(m_rectLock, selectedColor); - - // Paint hovering as semi-transparent overlay - if (m_hoveredItem == TreeControlType::Shy) - painter->fillRect(m_rectShy, hoveredColor); - else if (m_hoveredItem == TreeControlType::Hide) - painter->fillRect(m_rectVisible, hoveredColor); - else if (m_hoveredItem == TreeControlType::Lock) - painter->fillRect(m_rectLock, hoveredColor); - - painter->drawPixmap(m_rectShy , hiResIcons ? pixShy2x : pixShy); - painter->drawPixmap(m_rectVisible , hiResIcons ? pixVisible2x : pixVisible); - painter->drawPixmap(m_rectLock , hiResIcons ? pixLock2x : pixLock); -} - -TreeControlType TreeHeader::handleButtonsClick(const QPointF &scenePos) -{ - QPointF p = mapFromScene(scenePos.x(), scenePos.y()); - - if (m_rectShy.contains(p.x(), p.y())) { - toggleFilterShy(); - return TreeControlType::Shy; - } else if (m_rectVisible.contains(p.x(), p.y())) { - toggleFilterHidden(); - return TreeControlType::Hide; - } else if (m_rectLock.contains(p.x(), p.y())) { - toggleFilterLocked(); - return TreeControlType::Lock; - } - - return TreeControlType::None; -} - -bool TreeHeader::filterShy() const -{ - return m_shy; -} - -bool TreeHeader::filterHidden() const -{ - return m_visible; -} - -bool TreeHeader::filterLocked() const -{ - return m_lock; -} - -int TreeHeader::type() const -{ - // Enable the use of qgraphicsitem_cast with this item. - return TypeTreeHeader; -} - -void TreeHeader::toggleFilterShy() -{ - m_shy = !m_shy; - update(); -} - -void TreeHeader::toggleFilterHidden() -{ - m_visible = !m_visible; - update(); -} - -void TreeHeader::toggleFilterLocked() -{ - m_lock = !m_lock; - update(); -} - -void TreeHeader::hoverMoveEvent(QGraphicsSceneHoverEvent *event) -{ - QPointF p = event->scenePos(); - TreeControlType hoveredItem = TreeControlType::None; - if (m_rectShy.contains(p.x(), p.y())) { - QString action = m_shy ? tr("Show") : tr("Hide"); - setToolTip(tr("%1 shy objects").arg(action)); - hoveredItem = TreeControlType::Shy; - } else if (m_rectVisible.contains(p.x(), p.y())) { - QString action = m_visible ? tr("Show") : tr("Hide"); - setToolTip(tr("%1 inactive objects").arg(action)); - hoveredItem = TreeControlType::Hide; - } else if (m_rectLock.contains(p.x(), p.y())) { - QString action = m_lock ? tr("Show") : tr("Hide"); - setToolTip(tr("%1 locked objects").arg(action)); - hoveredItem = TreeControlType::Lock; - } else { - setToolTip(""); - } - - if (m_hoveredItem != hoveredItem) { - // Update hover status only if it has changed - m_hoveredItem = hoveredItem; - update(); - } -} - -void TreeHeader::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) -{ - m_hoveredItem = TreeControlType::None; - update(); -} diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeader.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeader.h deleted file mode 100644 index 6ebf2bad..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeader.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef TREEHEADER_H -#define TREEHEADER_H - -#include "TimelineItem.h" -#include "TimelineConstants.h" -#include "RowTypes.h" -#include "TimelineGraphicsScene.h" - -class RowTimeline; - -class TreeHeader : public TimelineItem -{ - Q_OBJECT - -public: - explicit TreeHeader(TimelineGraphicsScene *timelineScene, TimelineItem *parent = nullptr); - - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) override; - TreeControlType handleButtonsClick(const QPointF &scenePos); - bool filterShy() const; - bool filterHidden() const; - bool filterLocked() const; - int type() const override; - -protected: - void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override; - void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; - -private: - void toggleFilterShy(); - void toggleFilterHidden(); - void toggleFilterLocked(); - TimelineGraphicsScene *m_scene; - bool m_shy = false; - bool m_visible = false; - bool m_lock = false; - TreeControlType m_hoveredItem = TreeControlType::None; - QRect m_rectShy; - QRect m_rectVisible; - QRect m_rectLock; -}; - -#endif // TREEHEADER_H diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeaderView.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeaderView.cpp deleted file mode 100644 index df784418..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeaderView.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** -** -** 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 "TreeHeaderView.h" - -TreeHeaderView::TreeHeaderView(QWidget *parent) - : QGraphicsView(parent) -{ -} - -void TreeHeaderView::scrollContentsBy(int dx, int dy) -{ - // Overridden to ignore scrolling after initial show related scrolling has been finished - // - // Longer explanation: When RowTreeLabelItem (QGraphicsTextItem) gets focus - // for text editing, it forces views to scroll themselves so that editable - // text item is always visible. But we don't want tree header view to move. - // See QGraphicsTextItemPrivate::textControl() and _q_ensureVisible() - if (m_allowScrolling) - QGraphicsView::scrollContentsBy(dx, dy); -} diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeaderView.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeaderView.h deleted file mode 100644 index 7b648660..00000000 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TreeHeaderView.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef TREEHEADERVIEW_H -#define TREEHEADERVIEW_H - -#include <QtWidgets/qgraphicsview.h> - -class TreeHeaderView : public QGraphicsView -{ - Q_OBJECT -public: - TreeHeaderView(QWidget *parent = nullptr); - - void disableScrolling() { m_allowScrolling = false; } - -protected: - void scrollContentsBy(int dx, int dy) override; - -private: - bool m_allowScrolling = true; -}; - -#endif // TREEHEADERVIEW_H |