File indexing completed on 2023-12-03 04:55:10
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2010 Jean-Baptiste Mardelle <jb@kdenlive.org> 0003 0004 SPDX-License-Identifier: LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #pragma once 0008 0009 #include "utils/gentime.h" 0010 #include "utils/timecode.h" 0011 0012 #include <QAbstractSpinBox> 0013 0014 /** @class TimecodeValidator 0015 @brief Input validator for TimecodeDisplay 0016 */ 0017 class TimecodeValidator : public QValidator 0018 { 0019 public: 0020 explicit TimecodeValidator(QObject *parent = nullptr); 0021 void fixup(QString &str) const override; 0022 QValidator::State validate(QString &str, int &pos) const override; 0023 }; 0024 0025 /** 0026 * @class TimecodeDisplay 0027 * @brief A widget for inserting a timecode value. 0028 * @author Jean-Baptiste Mardelle 0029 * 0030 * TimecodeDisplay can be used to insert either frames 0031 * or a timecode in the format HH:MM:SS:FF 0032 */ 0033 class TimecodeDisplay : public QAbstractSpinBox 0034 { 0035 Q_OBJECT 0036 0037 public: 0038 /** @brief Constructor for the widget. 0039 * This is the constructor used for Qt Designer 0040 * @param parent parent Widget 0041 * @param autoAdjust @default true if true, the timecode will be set and adjusted according to pCore's timecode */ 0042 explicit TimecodeDisplay(QWidget *parent = nullptr, bool autoAdjust = true); 0043 0044 /** @brief Constructor for the widget. Beware, this constructor does not automatically adjust its fps! 0045 * @param parent parent Widget 0046 * @param t Timecode object used to setup correct input (frames or HH:MM:SS:FF) */ 0047 explicit TimecodeDisplay(QWidget *parent, const Timecode &t); 0048 0049 /** @brief Returns the minimum value, which can be entered. 0050 * default is 0 */ 0051 int minimum() const; 0052 0053 /** @brief Returns the maximum value, which can be entered. 0054 * default is no maximum (-1) */ 0055 int maximum() const; 0056 0057 /** @brief Sets the minimum maximum value that can be entered. 0058 * @param min the minimum value 0059 * @param max the maximum value */ 0060 void setRange(int min, int max); 0061 0062 /** @brief Returns the current input in frames. */ 0063 int getValue() const; 0064 0065 /** @brief Returns the current input as a GenTime object. */ 0066 GenTime gentime() const; 0067 0068 /** @brief Returns the widget's timecode object. */ 0069 Timecode timecode() const; 0070 0071 /** @brief Setup the timecode in case you are using this widget with QtDesigner. */ 0072 void setTimecode(const Timecode &t); 0073 0074 /** @brief Sets value's format to frames or HH:MM:SS:FF according to @param frametimecode. 0075 * @param frametimecode true = frames, false = HH:MM:SS:FF 0076 * @param init true = force the change, false = update only if the frametimecode param changed */ 0077 void setTimeCodeFormat(bool frametimecode, bool init = false); 0078 0079 /** @brief Sets timecode for current project. 0080 * @param t the new timecode */ 0081 void updateTimeCode(const Timecode &t); 0082 0083 void stepBy(int steps) override; 0084 0085 const QString displayText() const; 0086 0087 /** @brief Sets an offset for timecode display only, Used to show recording time instead of absolute timecode 0088 * @param offset the offset in msecs */ 0089 void setOffset(int offset); 0090 0091 /** @brief Select all timecode text */ 0092 void selectAll(); 0093 0094 private: 0095 /** timecode for widget */ 0096 Timecode m_timecode; 0097 /** Should we display the timecode in frames or in format hh:mm:ss:ff */ 0098 bool m_frametimecode; 0099 int m_minimum; 0100 int m_maximum; 0101 int m_value; 0102 int m_offset; 0103 0104 public Q_SLOTS: 0105 /** @brief Sets the value. 0106 * @param value the new value 0107 * The value actually set is forced to be within the legal range: minimum <= value <= maximum */ 0108 void setValue(int value); 0109 void setValue(const QString &value); 0110 void setValue(const GenTime &value); 0111 0112 private Q_SLOTS: 0113 void slotEditingFinished(); 0114 /** @brief Refresh timecode to match project.*/ 0115 void refreshTimeCode(); 0116 0117 Q_SIGNALS: 0118 void timeCodeEditingFinished(int value = -1); 0119 void timeCodeUpdated(); 0120 0121 protected: 0122 void keyPressEvent(QKeyEvent *e) override; 0123 void mouseReleaseEvent(QMouseEvent *) override; 0124 void wheelEvent(QWheelEvent *e) override; 0125 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 0126 void enterEvent(QEnterEvent *e) override; 0127 #else 0128 void enterEvent(QEvent *e) override; 0129 #endif 0130 void leaveEvent(QEvent *e) override; 0131 QAbstractSpinBox::StepEnabled stepEnabled() const override; 0132 };