diff options
19 files changed, 1395 insertions, 1093 deletions
diff --git a/src/Authoring/Studio/Application/DurationEditDlg.cpp b/src/Authoring/Studio/Application/DurationEditDlg.cpp new file mode 100644 index 00000000..42be267a --- /dev/null +++ b/src/Authoring/Studio/Application/DurationEditDlg.cpp @@ -0,0 +1,342 @@ +/**************************************************************************** +** +** Copyright (C) 2002 NVIDIA Corporation. +** 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 "ui_DurationEditDlg.h" +#include "DurationEditDlg.h" +#include "IDoc.h" +#include "Bindings/ITimelineKeyframesManager.h" + +//============================================================================= +/** + * Constructor + */ +CDurationEditDlg::CDurationEditDlg(QWidget *pParent) + : QDialog(pParent) + , m_ui(new Ui::DurationEditDlg) + , m_Doc(nullptr) + , m_KeyframesManager(nullptr) + , m_Callback(nullptr) + , m_MaxTime(0) + , m_MaxTimeDisplay(0) + , m_MinTimeDisplay(0) + , m_InitialTimeStart(0) + , m_InitialTimeEnd(0) + , m_minStart(-1) + , m_secStart(-1) + , m_minEnd(-1) + , m_secEnd(-1) +{ + m_ui->setupUi(this); + setAutoFillBackground(true); + + QIntValidator *minValidator = new QIntValidator(this); + minValidator->setRange(0, 9999); + m_ui->lineEditMinutes->setValidator(minValidator); + m_ui->lineEditEndMinutes->setValidator(minValidator); + QIntValidator *secValidator = new QIntValidator(this); + secValidator->setRange(0, 59); + m_ui->lineEditSeconds->setValidator(secValidator); + m_ui->lineEditEndSeconds->setValidator(secValidator); + QIntValidator *msecValidator = new QIntValidator(this); + msecValidator->setRange(0, 999); + m_ui->lineEditMilliseconds->setValidator(msecValidator); + m_ui->lineEditEndMilliseconds->setValidator(msecValidator); + + connect(m_ui->lineEditMinutes, &QLineEdit::textEdited, + this, &CDurationEditDlg::onStartTimeChanged); + connect(m_ui->lineEditSeconds, &QLineEdit::textEdited, + this, &CDurationEditDlg::onStartTimeChanged); + connect(m_ui->lineEditMilliseconds, &QLineEdit::textEdited, + this, &CDurationEditDlg::onStartTimeChanged); + + connect(m_ui->lineEditEndMinutes, &QLineEdit::textEdited, + this, &CDurationEditDlg::onEndTimeChanged); + connect(m_ui->lineEditEndSeconds, &QLineEdit::textEdited, + this, &CDurationEditDlg::onEndTimeChanged); + connect(m_ui->lineEditEndMilliseconds, &QLineEdit::textEdited, + this, &CDurationEditDlg::onEndTimeChanged); +} + +CDurationEditDlg::~CDurationEditDlg() +{ + delete m_ui; +} + +void CDurationEditDlg::setKeyframesManager(ITimelineKeyframesManager *inKeyframesManager) +{ + m_KeyframesManager = inKeyframesManager; +} + +//============================================================================= +/** + * showDialog: Initializes and shows the Duration Edit Dialog Box. + * @param startTime is the initial start time, which will be shown when the time edit + * dialog box pops up + * @param endTime is the initial end time, which will be shown when the time edit + * dialog box pops up + * @param inDoc this can be nullptr where its not applicable + * @param inCallback is the target object for the callbacks + */ +void CDurationEditDlg::showDialog(long startTime, long endTime, IDoc *inDoc, + ITimeChangeCallback *inCallback) +{ + m_InitialTimeStart = startTime; + m_InitialTimeEnd = endTime; + m_Doc = inDoc; + m_Callback = inCallback; + + m_MinTimeDisplay = 0; + // if it is a Timebar, this will be adjusted, else this should be initialized to some value at + // least, for OverflowHandling to work correctly + m_MaxTimeDisplay = LONG_MAX; + + // 9999:59:999 converted to milliseconds + m_MaxTime = timeConversion(9999, CONVERT_MIN_TO_MSEC) + + timeConversion(59, CONVERT_SEC_TO_MSEC) + 999; + + // Set initial values to dialog + formatTime(m_InitialTimeStart, true); + formatTime(m_InitialTimeEnd, false); + + // Present the dialog + exec(); +} + +void CDurationEditDlg::formatTime(long inTime, bool startTime) +{ + long theTime = inTime; + long min = 0; + long sec = 0; + long msec = 0; + + // Translates the m_initialTime (in milliseconds) into Minutes, Seconds and Milliseconds + if (inTime != 0) { + min = timeConversion(theTime, CONVERT_MSEC_TO_MIN); + theTime = theTime - timeConversion(min, CONVERT_MIN_TO_MSEC); + sec = timeConversion(theTime, CONVERT_MSEC_TO_SEC); + theTime = theTime - timeConversion(sec, CONVERT_SEC_TO_MSEC); + msec = theTime; + } + + if (startTime) { + m_ui->lineEditMinutes->setText(QString::number(min)); + m_ui->lineEditSeconds->setText(QString::number(sec)); + m_ui->lineEditMilliseconds->setText(QString::number(msec)); + + // Select the biggest non-zero unit + if (min > 0) { + m_ui->lineEditMinutes->setFocus(); + m_ui->lineEditMinutes->selectAll(); + } else if (sec > 0) { + m_ui->lineEditSeconds->setFocus(); + m_ui->lineEditSeconds->selectAll(); + } else { + m_ui->lineEditMilliseconds->setFocus(); + m_ui->lineEditMilliseconds->selectAll(); + } + } else { + m_ui->lineEditEndMinutes->setText(QString::number(min)); + m_ui->lineEditEndSeconds->setText(QString::number(sec)); + m_ui->lineEditEndMilliseconds->setText(QString::number(msec)); + } +} + +void CDurationEditDlg::showEvent(QShowEvent *ev) +{ + QDialog::showEvent(ev); +} + +void CDurationEditDlg::accept() +{ + m_Callback->Commit(); + QDialog::accept(); +} + +void CDurationEditDlg::reject() +{ + m_Callback->Rollback(); + QDialog::reject(); +} + +long CDurationEditDlg::numberOfDigits(long number) +{ + long theNumberOfDigits = 0; + for (long theNumber = number; theNumber >= 1; theNumber = theNumber / 10) + theNumberOfDigits++; + return theNumberOfDigits; +} + +//============================================================================== +/** + * timeConversion: Converts inTime to the format specified by inFlags. + * For example: + * inTime = 5 sec inFlags = CONVERT_SEC_TO_MSEC + * The method will convert 5 sec into 5000 msec and + * returns the result. + * @param inTime stores the time to be converted. + * inOperationCode determines the type of time conversion to be done on the + * inTime. + * @return theResult stores the result of the time conversion. + */ +long CDurationEditDlg::timeConversion(long inTime, long inOperationCode) +{ + long theResult = 0; + switch (inOperationCode) { + case CONVERT_MIN_TO_MSEC: + theResult = inTime * 60 * 1000; + break; + case CONVERT_SEC_TO_MSEC: + theResult = inTime * 1000; + break; + case CONVERT_MSEC_TO_MIN: + theResult = inTime / (60 * 1000); + break; + case CONVERT_MSEC_TO_SEC: + theResult = inTime / 1000; + break; + } + return theResult; +} + +//============================================================================== +/** + * timeConversion: Takes in the time in mins:secs:msec and convert it to + * the corresponding time in msec. + * @param inMin stores the minutes to be converted. + * inSec stores the seconds to be converted. + * inMsec stores the milliseconds to be converted. + * inOperationCode determines the type of time conversion to be done on the + * inMin, inSec and inMsec. + * @return theResult stores the result of the time conversion. + */ +long CDurationEditDlg::timeConversion(long inMin, long inSec, long inMsec, long inOperationCode) +{ + long theResult = 0; + switch (inOperationCode) { + case CONVERT_TIME_TO_MSEC: + theResult = timeConversion(inMin, CONVERT_MIN_TO_MSEC) + + timeConversion(inSec, CONVERT_SEC_TO_MSEC) + inMsec; + break; + } + return theResult; +} + +//============================================================================== +/** + * timeConversion: Takes in the time in milliseconds and converts them + * to min : sec : msec. + * @param inTotalTime stores the total time in msec. + * ioMin stores the mins result of the time conversion + * ioSec stores the secs result of the time conversion + * ioMsec stores the msecs result of the time conversion + * inOperationCode determines the type of time conversion to be done on the + * inTotalTime. + */ +void CDurationEditDlg::timeConversion(long inTotalTime, long *ioMin, long *ioSec, long *ioMsec, + long inOperationCode) +{ + switch (inOperationCode) { + case CONVERT_MSEC_TO_MIN_SEC_MSEC: + *ioMin = timeConversion(inTotalTime, CONVERT_MSEC_TO_MIN); + *ioSec = inTotalTime - timeConversion(*ioMin, CONVERT_MIN_TO_MSEC); + *ioSec = timeConversion(*ioSec, CONVERT_MSEC_TO_SEC); + *ioMsec = inTotalTime - timeConversion(*ioMin, CONVERT_MIN_TO_MSEC) + - timeConversion(*ioSec, CONVERT_SEC_TO_MSEC); + break; + } +} + +void CDurationEditDlg::updateObjectTime(long inTime, bool startTime) +{ + if (m_Callback) { + if (startTime) + m_Callback->ChangeStartTime(inTime); // Update Start Time + else + m_Callback->ChangeEndTime(inTime); // Update End Time + } +} + +void CDurationEditDlg::onStartTimeChanged() +{ + // Making sure that the start time is not greater than the end time, when + // the user modifies the start time of the timebar + m_MaxTimeDisplay = m_InitialTimeEnd; // the initial end time + m_MinTimeDisplay = 0; + + long min = m_ui->lineEditMinutes->text().toInt(); + long sec = m_ui->lineEditSeconds->text().toInt(); + long msec = m_ui->lineEditMilliseconds->text().toInt(); + + long theGoToTime = timeConversion(min, CONVERT_MIN_TO_MSEC) + + timeConversion(sec, CONVERT_SEC_TO_MSEC) + msec; + + // Go to the time specified in the start time edit display + updateObjectTime(theGoToTime, true); + + // If max number of digits reached in a number field, select the next + if (m_minStart != min && numberOfDigits(min) == 4) { + m_ui->lineEditSeconds->setFocus(); + m_ui->lineEditSeconds->selectAll(); + } else if (m_secStart != sec && numberOfDigits(sec) == 2) { + m_ui->lineEditMilliseconds->setFocus(); + m_ui->lineEditMilliseconds->selectAll(); + } + + m_minStart = min; + m_secStart = sec; +} + +void CDurationEditDlg::onEndTimeChanged() +{ + // Let the end time of the time bar go as far as possible + m_MaxTimeDisplay = m_MaxTime; + m_MinTimeDisplay = m_InitialTimeStart; // the initial start time + + long min = m_ui->lineEditEndMinutes->text().toInt(); + long sec = m_ui->lineEditEndSeconds->text().toInt(); + long msec = m_ui->lineEditEndMilliseconds->text().toInt(); + + long theGoToTime = timeConversion(min, CONVERT_MIN_TO_MSEC) + + timeConversion(sec, CONVERT_SEC_TO_MSEC) + msec; + + // Go to the time specified in the end time edit display + updateObjectTime(theGoToTime, false); + + // If max number of digits reached in a number field, select the next + if (m_minEnd != min && numberOfDigits(min) == 4) { + m_ui->lineEditEndSeconds->setFocus(); + m_ui->lineEditEndSeconds->selectAll(); + } else if (m_secEnd != sec && numberOfDigits(sec) == 2) { + m_ui->lineEditEndMilliseconds->setFocus(); + m_ui->lineEditEndMilliseconds->selectAll(); + } + + m_minEnd = min; + m_secEnd = sec; +} diff --git a/src/Authoring/Studio/Application/DurationEditDlg.h b/src/Authoring/Studio/Application/DurationEditDlg.h new file mode 100644 index 00000000..2dec58ba --- /dev/null +++ b/src/Authoring/Studio/Application/DurationEditDlg.h @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2002 NVIDIA Corporation. +** 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 DURATION_EDIT_DIALOG_H +#define DURATION_EDIT_DIALOG_H + +#include <QtWidgets/qdialog.h> + +class CTimebarControl; +class IDoc; +class ITimelineKeyframesManager; + +enum ETimeFormat { MSEC, SEC_MSEC, MIN_SEC_MSEC }; + +enum ETimeConversionOperation { + CONVERT_MIN_TO_MSEC, + CONVERT_SEC_TO_MSEC, + CONVERT_MSEC_TO_MIN, + CONVERT_MSEC_TO_SEC, + CONVERT_TIME_TO_MSEC, + CONVERT_MSEC_TO_MIN_SEC_MSEC +}; + +class ITimeChangeCallback +{ +public: + virtual ~ITimeChangeCallback() {} + virtual void ChangeStartTime(long) = 0; + virtual void ChangeEndTime(long) = 0; + virtual void Commit() = 0; + virtual void Rollback() = 0; +}; + +#ifdef QT_NAMESPACE +using namespace QT_NAMESPACE; +#endif + +QT_BEGIN_NAMESPACE +namespace Ui { +class DurationEditDlg; +} +QT_END_NAMESPACE + +class CDurationEditDlg : public QDialog +{ + Q_OBJECT + +public: + CDurationEditDlg(QWidget *pParent = nullptr); // standard constructor + virtual ~CDurationEditDlg(); + void setKeyframesManager(ITimelineKeyframesManager *inKeyframeManager); + void showDialog(long startTime, long endTime, IDoc *inDoc, + ITimeChangeCallback *inCallback = nullptr); + +public Q_SLOTS: + void accept() override; + void reject() override; + +protected: + void showEvent(QShowEvent *) override; + + void onStartTimeChanged(); + void onEndTimeChanged(); + + void formatTime(long inTime, bool startTime); + long numberOfDigits(long number); + long timeConversion(long inTime, long inOperationCode); + long timeConversion(long inMin, long inSec, long inMsec, long inOperationCode); + void timeConversion(long inTotalTime, long *ioMin, long *ioSec, long *ioMsec, + long inOperationCode); + void updateObjectTime(long inTime, bool startTime); + +protected: + Ui::DurationEditDlg *m_ui; + IDoc *m_Doc; + ITimelineKeyframesManager *m_KeyframesManager; + ITimeChangeCallback *m_Callback; + long m_MaxTime; + long m_MaxTimeDisplay; + long m_MinTimeDisplay; + long m_InitialTimeStart; + long m_InitialTimeEnd; + int m_minStart; + int m_secStart; + int m_minEnd; + int m_secEnd; +}; +#endif // DURATION_EDIT_DIALOG_H diff --git a/src/Authoring/Studio/Application/DurationEditDlg.ui b/src/Authoring/Studio/Application/DurationEditDlg.ui new file mode 100644 index 00000000..e05ab95c --- /dev/null +++ b/src/Authoring/Studio/Application/DurationEditDlg.ui @@ -0,0 +1,275 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>DurationEditDlg</class> + <widget class="QDialog" name="DurationEditDlg"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>300</width> + <height>137</height> + </rect> + </property> + <property name="windowTitle"> + <string>Set Timebar Start / End Time</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="labelStartTime"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>120</width> + <height>30</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>150</width> + <height>16777215</height> + </size> + </property> + <property name="text"> + <string>Start time</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lineEditMinutes"/> + </item> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>:</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lineEditSeconds"/> + </item> + <item> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>.</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lineEditMilliseconds"/> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_4"> + <item> + <widget class="QLabel" name="labelEndTime"> + <property name="minimumSize"> + <size> + <width>120</width> + <height>30</height> + </size> + </property> + <property name="text"> + <string>End time</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lineEditEndMinutes"/> + </item> + <item> + <widget class="QLabel" name="label_7"> + <property name="text"> + <string>:</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lineEditEndSeconds"/> + </item> + <item> + <widget class="QLabel" name="label_8"> + <property name="text"> + <string>.</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lineEditEndMilliseconds"/> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Maximum</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>120</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="LabelM"> + <property name="minimumSize"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>16777215</width> + <height>20</height> + </size> + </property> + <property name="text"> + <string>min</string> + </property> + <property name="alignment"> + <set>Qt::AlignHCenter|Qt::AlignTop</set> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="labelS"> + <property name="minimumSize"> + <size> + <width>40</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>16777215</width> + <height>20</height> + </size> + </property> + <property name="text"> + <string>sec</string> + </property> + <property name="alignment"> + <set>Qt::AlignHCenter|Qt::AlignTop</set> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="labelMs"> + <property name="minimumSize"> + <size> + <width>40</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>16777215</width> + <height>20</height> + </size> + </property> + <property name="text"> + <string>ms</string> + </property> + <property name="alignment"> + <set>Qt::AlignHCenter|Qt::AlignTop</set> + </property> + </widget> + </item> + </layout> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Maximum</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>10</height> + </size> + </property> + </spacer> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <spacer name="horizontalSpacer_4"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>DurationEditDlg</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>DurationEditDlg</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/src/Authoring/Studio/Application/TimeEditDlg.cpp b/src/Authoring/Studio/Application/TimeEditDlg.cpp new file mode 100644 index 00000000..8426dfd7 --- /dev/null +++ b/src/Authoring/Studio/Application/TimeEditDlg.cpp @@ -0,0 +1,303 @@ +/**************************************************************************** +** +** Copyright (C) 2002 NVIDIA Corporation. +** 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 "ui_TimeEditDlg.h" +#include "TimeEditDlg.h" +#include "IDoc.h" +#include "Bindings/ITimelineKeyframesManager.h" + +CTimeEditDlg::CTimeEditDlg(QWidget *pParent) + : QDialog(pParent) + , m_ui(new Ui::TimeEditDlg) + , m_Doc(nullptr) + , m_KeyframesManager(nullptr) + , m_InitialTime(0) + , m_ObjectAssociation(0) + , m_OffsetFromInitialTime(0) + , m_min(-1) + , m_sec(-1) +{ + m_ui->setupUi(this); + setAutoFillBackground(true); + + QIntValidator *minValidator = new QIntValidator(this); + minValidator->setRange(0, 9999); + m_ui->lineEditMinutes->setValidator(minValidator); + QIntValidator *secValidator = new QIntValidator(this); + secValidator->setRange(0, 59); + m_ui->lineEditSeconds->setValidator(secValidator); + QIntValidator *msecValidator = new QIntValidator(this); + msecValidator->setRange(0, 999); + m_ui->lineEditMilliseconds->setValidator(msecValidator); + + connect(m_ui->lineEditMinutes, &QLineEdit::textEdited, this, &CTimeEditDlg::onTimeChanged); + connect(m_ui->lineEditSeconds, &QLineEdit::textEdited, this, &CTimeEditDlg::onTimeChanged); + connect(m_ui->lineEditMilliseconds, &QLineEdit::textEdited, this, &CTimeEditDlg::onTimeChanged); +} + +CTimeEditDlg::~CTimeEditDlg() +{ + delete m_ui; +} + +void CTimeEditDlg::setKeyframesManager(ITimelineKeyframesManager *inKeyframesManager) +{ + m_KeyframesManager = inKeyframesManager; +} + +//============================================================================= +/** + * showDialog: Initializes and shows the Time Edit Dialog Box. + * @param inTime is the initial time, which will be shown when the time edit + * dialog box pops up + * @param inDoc this can be nullptr where its not applicable + * @param inObjectAssociation is the identifier for that identifies the object + * associated with the time edit dialog + * (e.g. playhead, keyframe) + */ +void CTimeEditDlg::showDialog(long inTime, IDoc *inDoc, long inObjectAssociation) +{ + m_InitialTime = inTime; + m_ObjectAssociation = inObjectAssociation; + m_Doc = inDoc; + + // Set initial values to dialog + formatTime(m_InitialTime); + + exec(); +} + +void CTimeEditDlg::formatTime(long inTime) +{ + long theTime = inTime; + long min = 0; + long sec = 0; + long msec = 0; + + // Translates the m_initialTime (in milliseconds) into Minutes, Seconds and Milliseconds + if (inTime != 0) { + min = timeConversion(theTime, CONVERT_MSEC_TO_MIN); + theTime = theTime - timeConversion(min, CONVERT_MIN_TO_MSEC); + sec = timeConversion(theTime, CONVERT_MSEC_TO_SEC); + theTime = theTime - timeConversion(sec, CONVERT_SEC_TO_MSEC); + msec = theTime; + } + m_ui->lineEditMinutes->setText(QString::number(min)); + m_ui->lineEditSeconds->setText(QString::number(sec)); + m_ui->lineEditMilliseconds->setText(QString::number(msec)); + + // Select the biggest non-zero unit + if (min > 0) { + m_ui->lineEditMinutes->setFocus(); + m_ui->lineEditMinutes->selectAll(); + } else if (sec > 0) { + m_ui->lineEditSeconds->setFocus(); + m_ui->lineEditSeconds->selectAll(); + } else { + m_ui->lineEditMilliseconds->setFocus(); + m_ui->lineEditMilliseconds->selectAll(); + } +} + +void CTimeEditDlg::showEvent(QShowEvent *ev) +{ + onInitDialog(); + QDialog::showEvent(ev); +} + +void CTimeEditDlg::onInitDialog() +{ + QString title; + // Display the window captions for the correct object type + switch (m_ObjectAssociation) { + case PLAYHEAD: + title = QObject::tr("Go To Time"); + break; + case ASSETKEYFRAME: + title = QObject::tr("Set Keyframe Time"); + break; + } + setWindowTitle(title); + m_ui->labelTitle->setText(title); +} + +void CTimeEditDlg::accept() +{ + // Only commit here, cos dup keyframes will be deleted. + if (m_ObjectAssociation == ASSETKEYFRAME && m_Doc && m_KeyframesManager) + m_KeyframesManager->CommitChangedKeyframes(); + + QDialog::accept(); +} + +void CTimeEditDlg::reject() +{ + // Only commit here, cos dup keyframes will be deleted. + if (m_ObjectAssociation == ASSETKEYFRAME && m_Doc && m_KeyframesManager) + m_KeyframesManager->RollbackChangedKeyframes(); + QDialog::reject(); +} + +int CTimeEditDlg::numberOfDigits(long number) +{ + long theNumberOfDigits = 0; + for (long theNumber = number; theNumber >= 1; theNumber = theNumber / 10) + theNumberOfDigits++; + return theNumberOfDigits; +} + +//============================================================================== +/** + * timeConversion: Converts inTime to the format specified by inFlags. + * For example: + * inTime = 5 sec inFlags = CONVERT_SEC_TO_MSEC + * The method will convert 5 sec into 5000 msec and + * returns the result. + * @param inTime stores the time to be converted. + * inOperationCode determines the type of time conversion to be done on the + * inTime. + * @return theResult stores the result of the time conversion. + */ +long CTimeEditDlg::timeConversion(long inTime, long inOperationCode) +{ + long theResult = 0; + switch (inOperationCode) { + case CONVERT_MIN_TO_MSEC: + theResult = inTime * 60 * 1000; + break; + case CONVERT_SEC_TO_MSEC: + theResult = inTime * 1000; + break; + case CONVERT_MSEC_TO_MIN: + theResult = inTime / (60 * 1000); + break; + case CONVERT_MSEC_TO_SEC: + theResult = inTime / 1000; + break; + } + return theResult; +} + +//============================================================================== +/** + * timeConversion: Takes in the time in mins:secs:msec and convert it to + * the corresponding time in msec. + * @param inMin stores the minutes to be converted. + * inSec stores the seconds to be converted. + * inMsec stores the milliseconds to be converted. + * inOperationCode determines the type of time conversion to be done on the + * inMin, inSec and inMsec. + * @return theResult stores the result of the time conversion. + */ +long CTimeEditDlg::timeConversion(long inMin, long inSec, long inMsec, long inOperationCode) +{ + long theResult = 0; + switch (inOperationCode) { + case CONVERT_TIME_TO_MSEC: + theResult = timeConversion(inMin, CONVERT_MIN_TO_MSEC) + + timeConversion(inSec, CONVERT_SEC_TO_MSEC) + inMsec; + break; + } + return theResult; +} + +//============================================================================== +/** + * timeConversion: Takes in the time in milliseconds and converts them + * to min : sec : msec. + * @param inTotalTime stores the total time in msec. + * ioMin stores the mins result of the time conversion + * ioSec stores the secs result of the time conversion + * ioMsec stores the msecs result of the time conversion + * inOperationCode determines the type of time conversion to be done on the + * inTotalTime. + */ +void CTimeEditDlg::timeConversion(long inTotalTime, long *ioMin, long *ioSec, long *ioMsec, + long inOperationCode) +{ + switch (inOperationCode) { + case CONVERT_MSEC_TO_MIN_SEC_MSEC: + *ioMin = timeConversion(inTotalTime, CONVERT_MSEC_TO_MIN); + *ioSec = inTotalTime - timeConversion(*ioMin, CONVERT_MIN_TO_MSEC); + *ioSec = timeConversion(*ioSec, CONVERT_MSEC_TO_SEC); + *ioMsec = inTotalTime - timeConversion(*ioMin, CONVERT_MIN_TO_MSEC) + - timeConversion(*ioSec, CONVERT_SEC_TO_MSEC); + break; + } +} + +//============================================================================== +/** + * updateObjectTime: It updates the playhead or keyframe time according + * to the time displayed in the time edit dialogue. + * @param inTime is the time that will be updated. + */ +void CTimeEditDlg::updateObjectTime(long inTime) +{ + long theDiff = 0; + switch (m_ObjectAssociation) { + case PLAYHEAD: // Update the playhead time + if (m_Doc) + m_Doc->NotifyTimeChanged(inTime); + break; + case ASSETKEYFRAME: // Update the keyframe time + if (m_Doc) { + theDiff = inTime - m_OffsetFromInitialTime - m_InitialTime; + m_OffsetFromInitialTime = m_OffsetFromInitialTime + theDiff; + if (theDiff != 0 && m_KeyframesManager) + m_KeyframesManager->OffsetSelectedKeyframes(theDiff); + } + break; + } +} + +void CTimeEditDlg::onTimeChanged() +{ + long min = m_ui->lineEditMinutes->text().toInt(); + long sec = m_ui->lineEditSeconds->text().toInt(); + long msec = m_ui->lineEditMilliseconds->text().toInt(); + + long theGoToTime = timeConversion(min, CONVERT_MIN_TO_MSEC) + + timeConversion(sec, CONVERT_SEC_TO_MSEC) + msec; + + // Go to the time specified in the time edit display + updateObjectTime(theGoToTime); + + // If max number of digits reached in a number field, select the next + if (m_min != min && numberOfDigits(min) == 4) { + m_ui->lineEditSeconds->setFocus(); + m_ui->lineEditSeconds->selectAll(); + } else if (m_sec != sec && numberOfDigits(sec) == 2) { + m_ui->lineEditMilliseconds->setFocus(); + m_ui->lineEditMilliseconds->selectAll(); + } + + m_min = min; + m_sec = sec; +} diff --git a/src/Authoring/Studio/Application/TimeEditDlg.h b/src/Authoring/Studio/Application/TimeEditDlg.h new file mode 100644 index 00000000..9a58bf13 --- /dev/null +++ b/src/Authoring/Studio/Application/TimeEditDlg.h @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2002 NVIDIA Corporation. +** 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 TIME_EDIT_DIALOG_H +#define TIME_EDIT_DIALOG_H + +#include <QtWidgets/qdialog.h> + +class CTimebarControl; +class IDoc; +class ITimelineKeyframesManager; + +enum ETimeFormat { MSEC, SEC_MSEC, MIN_SEC_MSEC }; + +enum ETimeConversionOperation { + CONVERT_MIN_TO_MSEC, + CONVERT_SEC_TO_MSEC, + CONVERT_MSEC_TO_MIN, + CONVERT_MSEC_TO_SEC, + CONVERT_TIME_TO_MSEC, + CONVERT_MSEC_TO_MIN_SEC_MSEC +}; + +enum EObjectAssociation { + PLAYHEAD, + ASSETKEYFRAME +}; + +#ifdef QT_NAMESPACE +using namespace QT_NAMESPACE; +#endif + +QT_BEGIN_NAMESPACE +namespace Ui { + class TimeEditDlg; +} +QT_END_NAMESPACE + +class CTimeEditDlg : public QDialog +{ + Q_OBJECT + +public: + CTimeEditDlg(QWidget *pParent = nullptr); // standard constructor + virtual ~CTimeEditDlg(); + void setKeyframesManager(ITimelineKeyframesManager *inKeyframeManager); + void showDialog(long inTime, IDoc *inDoc, long inObjectAssociation); + +public Q_SLOTS: + void accept() override; + void reject() override; + +protected: + void showEvent(QShowEvent *) override; + + void onInitDialog(); + void onTimeChanged(); + + void formatTime(long inTime); + int numberOfDigits(long number); + long timeConversion(long inTime, long inOperationCode); + long timeConversion(long inMin, long inSec, long inMsec, long inOperationCode); + void timeConversion(long inTotalTime, long *ioMin, long *ioSec, long *ioMsec, + long inOperationCode); + void updateObjectTime(long inTime); + +protected: + Ui::TimeEditDlg *m_ui; + IDoc *m_Doc; + ITimelineKeyframesManager *m_KeyframesManager; + long m_InitialTime; + long m_ObjectAssociation; + long m_OffsetFromInitialTime; + int m_min; + int m_sec; +}; +#endif // TIME_EDIT_DIALOG_H diff --git a/src/Authoring/Studio/Application/TimeEditDlg.ui b/src/Authoring/Studio/Application/TimeEditDlg.ui new file mode 100644 index 00000000..cdf51245 --- /dev/null +++ b/src/Authoring/Studio/Application/TimeEditDlg.ui @@ -0,0 +1,235 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>TimeEditDlg</class> + <widget class="QDialog" name="TimeEditDlg"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>300</width> + <height>106</height> + </rect> + </property> + <property name="windowTitle"> + <string>Set Keyframe Time</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="labelTitle"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>120</width> + <height>30</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>150</width> + <height>16777215</height> + </size> + </property> + <property name="text"> + <string>Set keyframe time</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lineEditMinutes"/> + </item> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>:</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lineEditSeconds"/> + </item> + <item> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>.</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lineEditMilliseconds"/> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Maximum</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>120</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="label_5"> + <property name="minimumSize"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>16777215</width> + <height>20</height> + </size> + </property> + <property name="text"> + <string>min</string> + </property> + <property name="alignment"> + <set>Qt::AlignHCenter|Qt::AlignTop</set> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_4"> + <property name="minimumSize"> + <size> + <width>40</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>16777215</width> + <height>20</height> + </size> + </property> + <property name="text"> + <string>sec</string> + </property> + <property name="alignment"> + <set>Qt::AlignHCenter|Qt::AlignTop</set> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label"> + <property name="minimumSize"> + <size> + <width>40</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>16777215</width> + <height>20</height> + </size> + </property> + <property name="text"> + <string>ms</string> + </property> + <property name="alignment"> + <set>Qt::AlignHCenter|Qt::AlignTop</set> + </property> + </widget> + </item> + </layout> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Maximum</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>10</height> + </size> + </property> + </spacer> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <spacer name="horizontalSpacer_4"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>TimeEditDlg</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>TimeEditDlg</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/src/Authoring/Studio/Controls/TimeEdit.cpp b/src/Authoring/Studio/Controls/TimeEdit.cpp index 3859721f..5e44ed1f 100644 --- a/src/Authoring/Studio/Controls/TimeEdit.cpp +++ b/src/Authoring/Studio/Controls/TimeEdit.cpp @@ -71,7 +71,7 @@ bool CTimeEdit::OnMouseDown(CPt inPoint, Qt::KeyboardModifiers inFlags) Q_UNUSED(inFlags); CTimeEditDlg theTimeEditDlg; - theTimeEditDlg.ShowDialog(m_Time, 0, m_Doc, PLAYHEAD); + theTimeEditDlg.showDialog(m_Time, m_Doc, PLAYHEAD); return true; } diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/KeyframesManager.cpp b/src/Authoring/Studio/Palettes/Timeline/Bindings/KeyframesManager.cpp index d9c12072..d83c0a5f 100644 --- a/src/Authoring/Studio/Palettes/Timeline/Bindings/KeyframesManager.cpp +++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/KeyframesManager.cpp @@ -299,8 +299,8 @@ void CKeyframesManager::SetChangedKeyframes() void CKeyframesManager::SetKeyframeTime(long inTime) { CTimeEditDlg theTimeEditDlg; - theTimeEditDlg.SetKeyframesManager(this); - theTimeEditDlg.ShowDialog(inTime, 0, g_StudioApp.GetCore()->GetDoc(), ASSETKEYFRAME); + theTimeEditDlg.setKeyframesManager(this); + theTimeEditDlg.showDialog(inTime, g_StudioApp.GetCore()->GetDoc(), ASSETKEYFRAME); } void CKeyframesManager::SetKeyframeDynamic(Qt3DSDMTimelineKeyframe *inKeyframe, bool inDynamic) diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.cpp b/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.cpp index 578b2bb6..612dd32c 100644 --- a/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.cpp +++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.cpp @@ -773,8 +773,8 @@ void Qt3DSDMTimelineItemBinding::CommitChangedKeyframes() void Qt3DSDMTimelineItemBinding::OnEditKeyframeTime(long inCurrentTime, long inObjectAssociation) { CTimeEditDlg theTimeEditDlg; - theTimeEditDlg.SetKeyframesManager(m_TransMgr->GetKeyframesManager()); - theTimeEditDlg.ShowDialog(inCurrentTime, 0, g_StudioApp.GetCore()->GetDoc(), + theTimeEditDlg.setKeyframesManager(m_TransMgr->GetKeyframesManager()); + theTimeEditDlg.showDialog(inCurrentTime, g_StudioApp.GetCore()->GetDoc(), inObjectAssociation); } diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemProperty.cpp b/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemProperty.cpp index a7fc4c53..07e2ac46 100644 --- a/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemProperty.cpp +++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemProperty.cpp @@ -398,8 +398,8 @@ void Qt3DSDMTimelineItemProperty::OnEditKeyframeTime(long inCurrentTime, long in { (void)inObjectAssociation; CTimeEditDlg theTimeEditDlg; - theTimeEditDlg.SetKeyframesManager(m_TransMgr->GetKeyframesManager()); - theTimeEditDlg.ShowDialog(inCurrentTime, 0, g_StudioApp.GetCore()->GetDoc(), ASSETKEYFRAME); + theTimeEditDlg.setKeyframesManager(m_TransMgr->GetKeyframesManager()); + theTimeEditDlg.showDialog(inCurrentTime, g_StudioApp.GetCore()->GetDoc(), ASSETKEYFRAME); } void Qt3DSDMTimelineItemProperty::SelectKeyframes(bool inSelected, long inTime /*= -1 */) diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineTimebar.cpp b/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineTimebar.cpp index 6f18bfce..1e793e56 100644 --- a/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineTimebar.cpp +++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineTimebar.cpp @@ -44,7 +44,7 @@ #include "Doc.h" #include "Dispatch.h" #include "Core.h" -#include "TimeEditDlg.h" +#include "DurationEditDlg.h" #include "IDocumentEditor.h" #include "BaseStateRow.h" #include "BaseTimebarlessRow.h" @@ -257,7 +257,7 @@ void Qt3DSDMTimelineTimebar::SetTimebarTime(ITimeChangeCallback *inCallback /*= { long theStartTime = GetStartTime(); long theEndTime = GetEndTime(); - CTimeEditDlg theTimeEditDlg; - theTimeEditDlg.ShowDialog(theStartTime, theEndTime, m_TimelineTranslationManager->GetDoc(), - TIMEBAR, inCallback); + CDurationEditDlg theDurationEditDlg; + theDurationEditDlg.showDialog(theStartTime, theEndTime, m_TimelineTranslationManager->GetDoc(), + inCallback); } diff --git a/src/Authoring/Studio/Palettes/Timeline/Playhead.cpp b/src/Authoring/Studio/Palettes/Timeline/Playhead.cpp index c010a854..be59530d 100644 --- a/src/Authoring/Studio/Palettes/Timeline/Playhead.cpp +++ b/src/Authoring/Studio/Palettes/Timeline/Playhead.cpp @@ -135,7 +135,7 @@ bool CPlayhead::OnMouseDoubleClick(CPt inPoint, Qt::KeyboardModifiers inFlags) Q_UNUSED(inFlags); CTimeEditDlg theTimeEditDlg; - theTimeEditDlg.ShowDialog(GetCurrentTime(), 0, m_Doc, PLAYHEAD); + theTimeEditDlg.showDialog(GetCurrentTime(), m_Doc, PLAYHEAD); return true; } diff --git a/src/Authoring/Studio/Palettes/Timeline/TimebarControl.cpp b/src/Authoring/Studio/Palettes/Timeline/TimebarControl.cpp index d1421d95..0e5186f7 100644 --- a/src/Authoring/Studio/Palettes/Timeline/TimebarControl.cpp +++ b/src/Authoring/Studio/Palettes/Timeline/TimebarControl.cpp @@ -370,9 +370,9 @@ bool CTimebarControl::OnMouseDoubleClick(CPt inPoint, Qt::KeyboardModifiers inFl { if (!CControl::OnMouseDoubleClick(inPoint, inFlags) && !m_TimelineItemBinding->IsLockedEnabled()) { - CTimeEditDlg theTimeEditDlg; - theTimeEditDlg.ShowDialog(m_StartTime, m_EndTime, g_StudioApp.GetCore()->GetDoc(), TIMEBAR, - this); + CDurationEditDlg theDurationEditDlg; + theDurationEditDlg.showDialog(m_StartTime, m_EndTime, g_StudioApp.GetCore()->GetDoc(), + this); } return true; diff --git a/src/Authoring/Studio/Palettes/Timeline/TimebarControl.h b/src/Authoring/Studio/Palettes/Timeline/TimebarControl.h index ec37d134..2d6e709d 100644 --- a/src/Authoring/Studio/Palettes/Timeline/TimebarControl.h +++ b/src/Authoring/Studio/Palettes/Timeline/TimebarControl.h @@ -36,7 +36,7 @@ #include "Snapper.h" #include "CommentEdit.h" #include "TimebarTip.h" -#include "TimeEditDlg.h" +#include "DurationEditDlg.h" #include "KeyframeContextMenu.h" class CStateTimebarRow; diff --git a/src/Authoring/Studio/Qt3DStudio.pro b/src/Authoring/Studio/Qt3DStudio.pro index a9db16d8..f3c3b379 100644 --- a/src/Authoring/Studio/Qt3DStudio.pro +++ b/src/Authoring/Studio/Qt3DStudio.pro @@ -146,7 +146,8 @@ HEADERS += \ Controls/TreeItem.h FORMS += \ - _Win/UI/timeeditdlg.ui \ + Application/TimeEditDlg.ui \ + Application/DurationEditDlg.ui \ _Win/UI/StudioAppPrefsPage.ui \ _Win/UI/StudioPreferencesPropSheet.ui \ _Win/UI/StudioProjectSettingsPage.ui \ @@ -192,7 +193,8 @@ SOURCES += \ _Win/UI/StudioAppPrefsPage.cpp \ _Win/UI/StudioPreferencesPropSheet.cpp \ _Win/UI/StudioProjectSettingsPage.cpp \ - _Win/UI/TimeEditDlg.cpp \ + Application/TimeEditDlg.cpp \ + Application/DurationEditDlg.cpp \ _Win/UI/TimeLineToolbar.cpp \ _Win/Utils/MouseCursor.cpp \ _Win/Workspace/Dialogs.cpp \ @@ -368,7 +370,8 @@ SOURCES += \ Application/DataInputListDlg.cpp HEADERS += \ - _Win/UI/TimeEditDlg.h \ + Application/TimeEditDlg.h \ + Application/DurationEditDlg.h \ _Win/UI/TimeLineToolbar.h \ _Win/Application/StudioApp.h \ Controls/TextEditContextMenu.h \ diff --git a/src/Authoring/Studio/_Win/UI/TimeEditDlg.cpp b/src/Authoring/Studio/_Win/UI/TimeEditDlg.cpp deleted file mode 100644 index dfeddcd3..00000000 --- a/src/Authoring/Studio/_Win/UI/TimeEditDlg.cpp +++ /dev/null @@ -1,519 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2002 NVIDIA Corporation. -** Copyright (C) 2017 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$ -** -****************************************************************************/ - -//============================================================================= -// Prefix -//============================================================================= - -#include "ui_timeeditdlg.h" - -#include "stdafx.h" -#include "StudioPreferences.h" - -//============================================================================== -// Includes -//============================================================================== - -#include "TimeEditDlg.h" -#include "IDoc.h" -#include "Bindings/ITimelineKeyframesManager.h" - -#include <QtGui/qfont.h> -#include <QtGui/qpalette.h> - -//============================================================================= -/** - * Constructor - */ -CTimeEditDlg::CTimeEditDlg(QWidget *pParent) - : QDialog(pParent) - , m_MaxTime(0) - , m_MaxTimeDisplay(0) - , m_MinTimeDisplay(0) - , m_InitialTime1(0) - , m_InitialTime2(0) - , m_MinOffset(0) - , m_SecOffset(0) - , m_MSecOffset(0) - , m_MinMinorOffset(0) - , m_SecMinorOffset(0) - , m_MSecMinorOffset(0) - , m_CursorPosition(0) - , m_TimeFormat(0) - , m_PreviousFormat(0) - , m_TimeInMins(0.0f) - , m_NumberOfDigitsDrop(0) - , m_ColonPosition1(0) - , m_ColonPosition2(0) - , m_ObjectAssociation(0) - , m_OffsetFromInitialTime(0) - , m_Time1(0) - , m_Time2(0) - , m_Doc(nullptr) - , m_KeyframesManager(nullptr) - , m_Callback(nullptr) - , m_ui(new Ui::TimeEditDlg) -{ - m_ui->setupUi(this); - setAutoFillBackground(true); - - connect(m_ui->startTimeEdit, &QDateTimeEdit::timeChanged, - this, &CTimeEditDlg::OnEnChangeTimeEdit1); - connect(m_ui->endTimeEdit, &QDateTimeEdit::timeChanged, - this, &CTimeEditDlg::OnEnChangeTimeEdit2); -} - -//============================================================================= -/** - * Destructor - */ -CTimeEditDlg::~CTimeEditDlg() -{ - delete m_ui; -} - -void CTimeEditDlg::SetKeyframesManager(ITimelineKeyframesManager *inKeyframesManager) -{ - m_KeyframesManager = inKeyframesManager; -} - -//============================================================================= -/** - * InitData: Initializes the Time Edit Dialog Box. - * @param inTime1 is the intial start time, which will be shown when the time edit - * dialog box pops up - * @param inTime2 is the intial end time, which will be shown when the time edit - * dialog box pops up - * @param inDoc this can be nullptr where its not applicable - * @param inObjectAssociation is the identifier for that identifies the object - * associated with the time edit dialog - *(e.g. - * playhead, keyframe, timebar) - */ -void CTimeEditDlg::ShowDialog(long inTime1, long inTime2, IDoc *inDoc, long inObjectAssociation, - ITimeChangeCallback *inCallback /*= nullptr*/) -{ - m_InitialTime1 = inTime1; - m_InitialTime2 = inTime2; - m_ObjectAssociation = inObjectAssociation; - m_Doc = inDoc; - m_Callback = inCallback; - - m_OffsetFromInitialTime = 0; - m_NumberOfDigitsDrop = 0; - m_MinTimeDisplay = 0; - // if it is a Timebar, this will be adjusted, else this should be initialized to some value at - // least, for OverflowHandling to work correctly - m_MaxTimeDisplay = LONG_MAX; - - // 9999:59:999 converted to milliseconds - m_MaxTime = - TimeConversion(9999, CONVERT_MIN_TO_MSEC) + TimeConversion(59, - CONVERT_SEC_TO_MSEC) + 999; - - m_TimeDisplay2 = FormatTime(m_InitialTime2); - // In cases Keyframes, where its only one set of time, do m_InitialTime1 later so that - // m_Min, etc. values are initializd to the valid values. - m_TimeDisplay1 = FormatTime(m_InitialTime1); - - // Present the dialog - exec(); -} - -//============================================================================== -/** - * FormatTime: Called to break up a given time in milliseconds into min:sec:msec - * store it in a string. The string is formatted in 99:59:999 form. - * @param inTime stores the time in milliseconds, which will be converted - * and stored in ioTimeString in 99:59:999 format. - * @return ioTimeString stores the result of the FormatTime method. - */ -QString CTimeEditDlg::FormatTime(long inTime) -{ - long theTime = inTime; - long hour = 0; - long min = 0; - long sec = 0; - long msec = 0; - // Translates the m_InitialTime1 (in milliseconds) into Minutes, Seconds and Milliseconds - if (inTime != 0) { - min = TimeConversion(theTime, CONVERT_MSEC_TO_MIN); - hour = min / 60; - theTime = theTime - TimeConversion(min, CONVERT_MIN_TO_MSEC); - min -= hour * 60; - sec = TimeConversion(theTime, CONVERT_MSEC_TO_SEC); - theTime = theTime - TimeConversion(sec, CONVERT_SEC_TO_MSEC); - msec = theTime; - } - return QString::asprintf("%02d:%02d:%02d:%03d", hour, min, sec, msec); -} - -//============================================================================== -/** - * OnInitDialog: Handle the WM_INITDIALOG message. - * @param None - * @return Returns TRUE always. - */ -void CTimeEditDlg::showEvent(QShowEvent *ev) -{ - OnInitDialog(); - QDialog::showEvent(ev); -} - - -void CTimeEditDlg::OnInitDialog() -{ - // Hide the window items associated with end time. - if (m_ObjectAssociation != TIMEBAR) - HideUnnecessaryFields(); - m_ui->startTimeEdit->setTime(QTime::fromString(m_TimeDisplay1, "hh:mm:ss:zzz")); - // Display the window captions for the correct object type - switch (m_ObjectAssociation) { - case PLAYHEAD: - setWindowTitle(QObject::tr("Go To Time")); - break; - case ASSETKEYFRAME: - setWindowTitle(QObject::tr("Set Keyframe Time")); - break; - case TIMEBAR: - // m_TimeEditBoxNumber is a flag that switches the output between - // the first and second text box. - // When m_TimeEditBoxNumber = EDITBOX1, we are writing to the first text box - // (the one that appears on top). - // When it is EDITBOX2, the SetTimeEdit will write to the second text box. - setWindowTitle(QObject::tr("Set Timebar Start/End Time")); - m_ui->endTimeEdit->setTime(QTime::fromString(m_TimeDisplay2, "hh:mm:ss:zzz")); - break; - } -} -//============================================================================== -/** - * accept: Upon clicking ok, the dialog will be exited - */ -void CTimeEditDlg::accept() -{ - // Only commit here, cos dup keyframes will be deleted. - if (m_ObjectAssociation == ASSETKEYFRAME && m_Doc && m_KeyframesManager) - m_KeyframesManager->CommitChangedKeyframes(); - else if (m_ObjectAssociation == TIMEBAR) - m_Callback->Commit(); - - QDialog::accept(); -} - -//============================================================================== -/** - * reject: Upon clicking Cancel, revert to the initial time. - */ -void CTimeEditDlg::reject() -{ - // Only commit here, cos dup keyframes will be deleted. - if (m_ObjectAssociation == ASSETKEYFRAME && m_Doc && m_KeyframesManager) - m_KeyframesManager->RollbackChangedKeyframes(); - else if (m_ObjectAssociation == TIMEBAR) - m_Callback->Rollback(); - QDialog::reject(); -} - -//============================================================================== -/** - * CountDigits: Counts the number of digits in a given number - * @param inNumber is the number that is used to count the number of digits - * @return the number of digits - */ -long CTimeEditDlg::CountDigits(long inNumber) -{ - long theNumberOfDigits = 0; - for (long theNumber = inNumber; theNumber >= 1; theNumber = theNumber / 10) - theNumberOfDigits++; - return theNumberOfDigits; -} - - -//============================================================================== -/** - * TimeOverflowUnderflow: Checks if inMin, inSec or inMSec has exceeded the overflow/ - * underflow limit. It will correct the time if it - *overflow/ - * underflow. - * @param inMin stores the min segment of the time - * @param inSec stores the sec segment of the time - * @param inMSec stores the msec segment of the time - * @param inTimeLimit stores the time limit before the overflow/underflow occurs - * @param inOverflowOrUnderflow is set to true if we are checking for overflow else - * we are checking for underflow - * @returns true if overflow/underflow occurs, otherwise returns false. - */ -bool CTimeEditDlg::TimeOverflowUnderflow(long *inMin, long *inSec, long *inMSec, long inTimeLimit, - bool inOverflowOrUnderflow) -{ - // The codes below translates inTimeLimit into theLimitMin:theLimitSec:theLimitMsec - bool theLimitExceeds = false; - long theLimitMin; - long theLimitSec; - long theLimitMsec; - TimeConversion(inTimeLimit, &theLimitMin, &theLimitSec, &theLimitMsec, - CONVERT_MSEC_TO_MIN_SEC_MSEC); - // Handle time overflow/underflow - if ((*inMin > theLimitMin && inOverflowOrUnderflow) - || (*inMin < theLimitMin && inOverflowOrUnderflow == false)) { - // Minutes exceeds limit - // Set all time segments to the limit - *inMin = theLimitMin; - *inSec = theLimitSec; - *inMSec = theLimitMsec; - theLimitExceeds = true; - } else if (*inMin == theLimitMin) { - if ((*inSec > theLimitSec && inOverflowOrUnderflow) - || (*inSec < theLimitSec && inOverflowOrUnderflow == false)) { - // Seconds exceeds limit - // Set the Sec and Msec segments to the limit - *inSec = theLimitSec; - *inMSec = theLimitMsec; - theLimitExceeds = true; - } else if (*inSec == theLimitSec) { - if ((*inMSec > theLimitMsec && inOverflowOrUnderflow) - || (*inMSec < theLimitMsec - && inOverflowOrUnderflow == false)) { - // Milliseconds exceeds limit - // Msec segments to the limit - *inMSec = theLimitMsec; - theLimitExceeds = true; - } - } - } - return theLimitExceeds; -} - -//============================================================================== -/** - * TimeConversion: Converts inTime to the format specified by inFlags. - * For example: - * inTime = 5 sec inFlags = CONVERT_SEC_TO_MSEC - * The method will convert 5 sec into 5000 msec and - *returns - * the result. - * @param inTime stores the time to be converted. - * inOperationCode determines the type of time conversion to be done on the - * inTime. - * @return theResult stores the result of the time conversion. - */ -long CTimeEditDlg::TimeConversion(long inTime, long inOperationCode) -{ - long theResult = 0; - switch (inOperationCode) { - case CONVERT_MIN_TO_MSEC: - theResult = inTime * 60 * 1000; - break; - case CONVERT_SEC_TO_MSEC: - theResult = inTime * 1000; - break; - case CONVERT_MSEC_TO_MIN: - theResult = inTime / (60 * 1000); - break; - case CONVERT_MSEC_TO_SEC: - theResult = inTime / 1000; - break; - } - return theResult; -} - -//============================================================================== -/** - * TimeConversion: Takes in the time in mins:secs:msec and convert it to - * the corresponding time in msec. - * @param inMin stores the minutes to be converted. - * inSec stores the seconds to be converted. - * inMsec stores the milliseconds to be converted. - * inOperationCode determines the type of time conversion to be done on the - * inMin, inSec and inMsec. - * @return theResult stores the result of the time conversion. - */ -long CTimeEditDlg::TimeConversion(long inMin, long inSec, long inMsec, long inOperationCode) -{ - long theResult = 0; - switch (inOperationCode) { - case CONVERT_TIME_TO_MSEC: - theResult = TimeConversion(inMin, CONVERT_MIN_TO_MSEC) - + TimeConversion(inSec, CONVERT_SEC_TO_MSEC) + inMsec; - break; - } - return theResult; -} - -//============================================================================== -/** - * TimeConversion: Takes in the time in milliseconds and converts them - * to min : sec : msec. - * @param inTotalTime stores the total time in msec. - * ioMin stores the mins result of the time conversion - * ioSec stores the secs result of the time conversion - * ioMsec stores the msecs result of the time conversion - * inOperationCode determines the type of time conversion to be done on the - * inTotalTime. - * @return NONE - */ -void CTimeEditDlg::TimeConversion(long inTotalTime, long *ioMin, long *ioSec, long *ioMsec, - long inOperationCode) -{ - switch (inOperationCode) { - case CONVERT_MSEC_TO_MIN_SEC_MSEC: - *ioMin = TimeConversion(inTotalTime, CONVERT_MSEC_TO_MIN); - *ioSec = inTotalTime - TimeConversion(*ioMin, CONVERT_MIN_TO_MSEC); - *ioSec = TimeConversion(*ioSec, CONVERT_MSEC_TO_SEC); - *ioMsec = inTotalTime - TimeConversion(*ioMin, CONVERT_MIN_TO_MSEC) - - TimeConversion(*ioSec, CONVERT_SEC_TO_MSEC); - break; - } -} -//============================================================================== -/** - * UpdateObjectTime: It updates the playhead, keyframe or timebar time according - * to the time displayed in the time edit dialogue. - * @param inTime is the time that will be updated. - * @param startTime if true, updates the start time on the object, otherwise the end time - * @return NONE - */ -void CTimeEditDlg::UpdateObjectTime(long inTime, bool startTime) -{ - long theDiff = 0; - switch (m_ObjectAssociation) { - case PLAYHEAD: // Update the playhead time - if (m_Doc) { - m_Doc->NotifyTimeChanged(inTime); - m_Doc->NotifyTimeChanged(inTime); - } - break; - case ASSETKEYFRAME: // Update the keyframe time - if (m_Doc) { - theDiff = inTime - m_OffsetFromInitialTime - m_InitialTime1; - m_OffsetFromInitialTime = m_OffsetFromInitialTime + theDiff; - if (theDiff != 0 && m_KeyframesManager) { - m_KeyframesManager->OffsetSelectedKeyframes(theDiff); - } - } - break; - case TIMEBAR: // Update the timebar start/end time - if (m_Callback) { - if (startTime) // Update Start Time - m_Callback->ChangeStartTime(inTime); - else // Update End Time - m_Callback->ChangeEndTime(inTime); - } - break; - } -} - -//============================================================================== -/** The codes methods below are provides platform independent wrappers for - * User Interface. - */ -//============================================================================== - -/** - * OnEnChangeTimeEdit: Event triggered when the text in the 1st time edit box has - * been changed. - * @param NONE - * @return NONE - */ -void CTimeEditDlg::OnEnChangeTimeEdit1() -{ - // Making sure that the start time is not greater than the end time, when - // the user modifies the start time of the timebar - if (m_ObjectAssociation == TIMEBAR) - m_MaxTimeDisplay = m_InitialTime2; // the initial end time - m_MinTimeDisplay = 0; - - const auto time = m_ui->startTimeEdit->time(); - long min = time.minute() + time.hour() * 60; - long sec = time.second(); - long msec = time.msec(); - TimeOverflowUnderflow(&min, &sec, &sec, m_MaxTimeDisplay, true); - TimeOverflowUnderflow(&min, &sec, &msec, m_MinTimeDisplay, false); - if (min != time.minute() || sec != time.second() || - msec != time.msec()) { - m_ui->startTimeEdit->setTime(QTime(0, min, sec, msec)); - } - m_ui->startTimeMin->setText(QString::number(min)); - m_ui->startTimeSec->setText(QString::number(sec)); - m_ui->startTimeMsec->setText(QString::number(msec)); - - long theGoToTime = TimeConversion(min, CONVERT_MIN_TO_MSEC) - + TimeConversion(sec, CONVERT_SEC_TO_MSEC) + msec; - // Go to the time specified in the time edit display - UpdateObjectTime(theGoToTime, true /*start time*/); -} - -//============================================================================== -/** - * OnEnChangeTimeEdit2: Event triggered when the text in the 2nd time edit box has - * been changed. - * @param NONE - * @return NONE - */ -void CTimeEditDlg::OnEnChangeTimeEdit2() -{ - // Let the end time of the time bar go as far as possible - if (m_ObjectAssociation == TIMEBAR) { - m_MaxTimeDisplay = m_MaxTime; - m_MinTimeDisplay = m_InitialTime1; // the initial start time - } - const auto time = m_ui->endTimeEdit->time(); - long min = time.minute() + time.hour() * 60; - long sec = time.second(); - long msec = time.msec(); - TimeOverflowUnderflow(&min, &sec, &sec, m_MaxTimeDisplay, true); - TimeOverflowUnderflow(&min, &sec, &msec, m_MinTimeDisplay, false); - if (min != time.minute() || sec != time.second() || - msec != time.msec()) { - m_ui->endTimeEdit->setTime(QTime(0, min, sec, msec)); - } - m_ui->endTimeMin->setText(QString::number(min)); - m_ui->endTimeSec->setText(QString::number(sec)); - m_ui->endTimeMsec->setText(QString::number(msec)); - - long theGoToTime = TimeConversion(min, CONVERT_MIN_TO_MSEC) - + TimeConversion(sec, CONVERT_SEC_TO_MSEC) + msec; - // Go to the time specified in the time edit display - UpdateObjectTime(theGoToTime, false /*end time*/); -} - - -//============================================================================== -/** - * HideUnnecessaryFields: Hides unused dialog items - * @param NONE - * @return NONE - */ -void CTimeEditDlg::HideUnnecessaryFields() -{ - m_ui->endTimeGroup->hide(); - m_ui->startTimeLabel->hide(); -} - diff --git a/src/Authoring/Studio/_Win/UI/TimeEditDlg.h b/src/Authoring/Studio/_Win/UI/TimeEditDlg.h deleted file mode 100644 index cbbcbafb..00000000 --- a/src/Authoring/Studio/_Win/UI/TimeEditDlg.h +++ /dev/null @@ -1,190 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2002 NVIDIA Corporation. -** Copyright (C) 2017 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$ -** -****************************************************************************/ - -//============================================================================== -// Prefix -//============================================================================== - -#ifndef INCLUDED_TIME_EDIT_DIALOG_H -#define INCLUDED_TIME_EDIT_DIALOG_H 1 - -//============================================================================== -// Includes -//============================================================================== -#include "Dialogs.h" -#include <QtWidgets/qdialog.h> -#include <QtWidgets/qdatetimeedit.h> - -//============================================================================== -// Forwards -//============================================================================== -class CTimebarControl; -class IDoc; -class ITimelineKeyframesManager; - -//============================================================================== -// Defines -//============================================================================== - -enum ECursorPosition { MIN_POSITION, SEC_POSITION, MSEC_POSITION }; - -enum ETimeFormat { MSEC, SEC_MSEC, MIN_SEC_MSEC }; - -enum ETimeConversionOperation { - CONVERT_MIN_TO_MSEC, - CONVERT_SEC_TO_MSEC, - CONVERT_MSEC_TO_MIN, - CONVERT_MSEC_TO_SEC, - CONVERT_TIME_TO_MSEC, - CONVERT_MSEC_TO_MIN_SEC_MSEC -}; - -enum ETimeEditBoxNumber { EDITBOX1, EDITBOX2 }; - -enum EObjectAssociation { - PLAYHEAD, - ASSETKEYFRAME, - TIMEBAR, -}; - -class ITimeChangeCallback -{ -public: - virtual ~ITimeChangeCallback() {} - virtual void ChangeStartTime(long) = 0; - virtual void ChangeEndTime(long) = 0; - virtual void Commit() = 0; - virtual void Rollback() = 0; -}; - -#ifdef QT_NAMESPACE -using namespace QT_NAMESPACE; -#endif - -QT_BEGIN_NAMESPACE -namespace Ui { - class TimeEditDlg; -} -QT_END_NAMESPACE - -// This class workaround the problem of QDateTimeEdit overwriting the selected section -// See https://bugreports.qt.io/browse/QTBUG-34759 -class CDateTimeEdit : public QDateTimeEdit -{ - Q_OBJECT -public: - using QDateTimeEdit::QDateTimeEdit; - -protected: - void focusInEvent(QFocusEvent *event) { - QDateTimeEdit::focusInEvent(event); - setSelectedSection(QDateTimeEdit::SecondSection); - } -}; - -//============================================================================== -/** - * CTimeEditDlg: It is a dialog box that allows user to specify the time that - * he/she wishes to go to. This dialog box can be activated by - * pressing Control G or clicking on the time edit box in the - * timeline. - */ -//============================================================================== -class CTimeEditDlg : public QDialog -{ - Q_OBJECT - -public: - CTimeEditDlg(QWidget *pParent = nullptr); // standard constructor - virtual ~CTimeEditDlg(); - void SetKeyframesManager(ITimelineKeyframesManager *inKeyframeManager); - void ShowDialog(long inTime1, long inTime2, IDoc *inDoc, long inObjectAssociation, - ITimeChangeCallback *inCallback = nullptr); - -public Q_SLOTS: - void accept() override; - void reject() override; - -protected: - void showEvent(QShowEvent *) override; - - // Generated message map functions - void OnInitDialog(); - void OnEnChangeTimeEdit1(); - void OnEnChangeTimeEdit2(); - - QString FormatTime(long inTime); - long CountDigits(long inNumber); - long TimeConversion(long inTime, long inOperationCode); - long TimeConversion(long inMin, long inSec, long inMsec, long inOperationCode); - void TimeConversion(long inTotalTime, long *ioMin, long *ioSec, long *ioMsec, - long inOperationCode); - void UpdateObjectTime(long inTime, bool startTime); - bool TimeOverflow(long *inMin, long *inSec, long *inMSec, long inTimeLimit); - bool TimeOverflowUnderflow(long *inMin, long *inSec, long *inMSec, long inTimeLimit, - bool inOverflowOrUnderflow); - void HideUnnecessaryFields(); - -protected: - QString m_MinString; - QString m_SecString; - QString m_MSecString; - QString m_TimeDisplay1; - QString m_TimeDisplay2; - long m_MaxTime; - long m_MaxTimeDisplay; - long m_MinTimeDisplay; - long m_InitialTime1; - long m_InitialTime2; - long m_MinOffset; - long m_SecOffset; - long m_MSecOffset; - long m_MinMinorOffset; - long m_SecMinorOffset; - long m_MSecMinorOffset; - long m_CursorPosition; - long m_TimeFormat; - long m_PreviousFormat; - double m_TimeInMins; - long m_NumberOfDigitsDrop; - long m_ColonPosition1; - long m_ColonPosition2; - long m_ObjectAssociation; - long m_OffsetFromInitialTime; - QString m_DTime; - QString m_DTimeDisplay; - long m_Time1; - long m_Time2; - IDoc *m_Doc; - ITimelineKeyframesManager *m_KeyframesManager; - - ITimeChangeCallback *m_Callback; - Ui::TimeEditDlg *m_ui; -}; -#endif // INCLUDED_TIME_EDIT_DIALOG_H diff --git a/src/Authoring/Studio/_Win/UI/TimeLineToolbar.cpp b/src/Authoring/Studio/_Win/UI/TimeLineToolbar.cpp index 3143f492..a679e9dc 100644 --- a/src/Authoring/Studio/_Win/UI/TimeLineToolbar.cpp +++ b/src/Authoring/Studio/_Win/UI/TimeLineToolbar.cpp @@ -67,7 +67,7 @@ TimeLineToolbar::TimeLineToolbar(CMainFrame *mainFrame, const QSize &preferredSi connect(m_ui->timeButton, &QPushButton::clicked, [this, doc](){ CTimeEditDlg timeEditDlg; - timeEditDlg.ShowDialog(doc->GetCurrentViewTime(), 0, doc, PLAYHEAD); + timeEditDlg.showDialog(doc->GetCurrentViewTime(), doc, PLAYHEAD); }); connect(m_ui->deleteObject, &QPushButton::clicked, diff --git a/src/Authoring/Studio/_Win/UI/timeeditdlg.ui b/src/Authoring/Studio/_Win/UI/timeeditdlg.ui deleted file mode 100644 index f46cb1a2..00000000 --- a/src/Authoring/Studio/_Win/UI/timeeditdlg.ui +++ /dev/null @@ -1,364 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>TimeEditDlg</class> - <widget class="QDialog" name="TimeEditDlg"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>371</width> - <height>274</height> - </rect> - </property> - <property name="windowTitle"> - <string>Go To Time</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <item> - <spacer name="verticalSpacer_2"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QWidget" name="startTimeGroup" native="true"> - <layout class="QGridLayout" name="gridLayout_3"> - <item row="2" column="0"> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="CDateTimeEdit" name="startTimeEdit"> - <property name="currentSection"> - <enum>QDateTimeEdit::SecondSection</enum> - </property> - <property name="displayFormat"> - <string>hh:mm:ss:zzz</string> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Fixed</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <layout class="QGridLayout" name="gridLayout"> - <item row="1" column="1"> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>:</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="startTimeMin"> - <property name="text"> - <string>00</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QLabel" name="label_8"> - <property name="text"> - <string>:</string> - </property> - </widget> - </item> - <item row="0" column="2"> - <widget class="QLabel" name="label_7"> - <property name="text"> - <string>sec</string> - </property> - </widget> - </item> - <item row="1" column="2"> - <widget class="QLabel" name="startTimeSec"> - <property name="text"> - <string>00</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="label"> - <property name="text"> - <string>min</string> - </property> - </widget> - </item> - <item row="1" column="4"> - <widget class="QLabel" name="startTimeMsec"> - <property name="text"> - <string>000</string> - </property> - </widget> - </item> - <item row="1" column="3"> - <widget class="QLabel" name="label_5"> - <property name="text"> - <string>:</string> - </property> - </widget> - </item> - </layout> - </item> - <item> - <spacer name="horizontalSpacer_2"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Expanding</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="startTimeLabel"> - <property name="text"> - <string>Start Time</string> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QWidget" name="endTimeGroup" native="true"> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QLabel" name="endTimeLabel"> - <property name="text"> - <string>End Time</string> - </property> - </widget> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <item> - <widget class="CDateTimeEdit" name="endTimeEdit"> - <property name="currentSection"> - <enum>QDateTimeEdit::SecondSection</enum> - </property> - <property name="displayFormat"> - <string>hh:mm:ss:zzz</string> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer_6"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Fixed</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <layout class="QGridLayout" name="gridLayout_2"> - <item row="1" column="1"> - <widget class="QLabel" name="label_9"> - <property name="text"> - <string>:</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="endTimeMin"> - <property name="text"> - <string>00</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QLabel" name="label_11"> - <property name="text"> - <string>:</string> - </property> - </widget> - </item> - <item row="0" column="2"> - <widget class="QLabel" name="label_12"> - <property name="text"> - <string>sec</string> - </property> - </widget> - </item> - <item row="1" column="2"> - <widget class="QLabel" name="endTimeSec"> - <property name="text"> - <string>00</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="label_14"> - <property name="text"> - <string>min</string> - </property> - </widget> - </item> - <item row="1" column="4"> - <widget class="QLabel" name="endTimeMsec"> - <property name="text"> - <string>000</string> - </property> - </widget> - </item> - <item row="1" column="3"> - <widget class="QLabel" name="label_16"> - <property name="text"> - <string>:</string> - </property> - </widget> - </item> - </layout> - </item> - <item> - <spacer name="horizontalSpacer_7"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Expanding</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - </layout> - </widget> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> - <spacer name="horizontalSpacer_4"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </widget> - <customwidgets> - <customwidget> - <class>CDateTimeEdit</class> - <extends>QTimeEdit</extends> - <header>TimeEditDlg.h</header> - </customwidget> - </customwidgets> - <resources/> - <connections> - <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> - <receiver>TimeEditDlg</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>248</x> - <y>254</y> - </hint> - <hint type="destinationlabel"> - <x>157</x> - <y>274</y> - </hint> - </hints> - </connection> - <connection> - <sender>buttonBox</sender> - <signal>rejected()</signal> - <receiver>TimeEditDlg</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>316</x> - <y>260</y> - </hint> - <hint type="destinationlabel"> - <x>286</x> - <y>274</y> - </hint> - </hints> - </connection> - </connections> -</ui> |