1 /* This file is part of the KDE project 2 SPDX-FileCopyrightText: 2010 Jean-Baptiste Mardelle <jb@kdenlive.org> 3 4 SPDX-License-Identifier: LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 5 */ 6 7 #ifndef TIMECODEDISPLAY_H 8 #define TIMECODEDISPLAY_H 9 10 #include "gentime.h" 11 #include "timecode.h" 12 13 #include <QAbstractSpinBox> 14 15 /** @class MyValidator 16 @brief \@todo Describe class MyValidator 17 @todo Describe class MyValidator 18 */ 19 class MyValidator : public QValidator 20 { 21 public: 22 explicit MyValidator(QObject *parent = nullptr); 23 void fixup(QString &str) const override; 24 QValidator::State validate(QString &str, int &pos) const override; 25 }; 26 27 /** 28 * @class TimecodeDisplay 29 * @brief A widget for inserting a timecode value. 30 * @author Jean-Baptiste Mardelle 31 * 32 * TimecodeDisplay can be used to insert either frames 33 * or a timecode in the format HH:MM:SS:FF 34 */ 35 class TimecodeDisplay : public QAbstractSpinBox 36 { 37 Q_OBJECT 38 39 public: 40 /** @brief Constructor for the widget, sets value to 0. 41 * @param t Timecode object used to setup correct input (frames or HH:MM:SS:FF) 42 * @param parent parent Widget */ 43 explicit TimecodeDisplay(const Timecode &t, QWidget *parent = nullptr); 44 45 /** @brief Returns the minimum value, which can be entered. 46 * default is 0 */ 47 int minimum() const; 48 49 /** @brief Returns the maximum value, which can be entered. 50 * default is no maximum (-1) */ 51 int maximum() const; 52 53 /** @brief Sets the minimum maximum value that can be entered. 54 * @param min the minimum value 55 * @param max the maximum value */ 56 void setRange(int min, int max); 57 58 /** @brief Returns the current input in frames. */ 59 int getValue() const; 60 61 /** @brief Returns the current input as a GenTime object. */ 62 GenTime gentime() const; 63 64 /** @brief Returns the widget's timecode object. */ 65 Timecode timecode() const; 66 67 /** @brief Sets value's format to frames or HH:MM:SS:FF according to @param frametimecode. 68 * @param frametimecode true = frames, false = HH:MM:SS:FF 69 * @param init true = force the change, false = update only if the frametimecode param changed */ 70 void setTimeCodeFormat(bool frametimecode, bool init = false); 71 72 /** @brief Sets timecode for current project. 73 * @param t the new timecode */ 74 void updateTimeCode(const Timecode &t); 75 76 void stepBy(int steps) override; 77 78 const QString displayText() const; 79 80 /** @brief Sets an offset for timecode display only, Used to show recording time instead of absolute timecode 81 * @param offset the offset in msecs */ 82 void setOffset(int offset); 83 84 /** @brief Select all timecode text */ 85 void selectAll(); 86 87 private: 88 /** timecode for widget */ 89 Timecode m_timecode; 90 /** Should we display the timecode in frames or in format hh:mm:ss:ff */ 91 bool m_frametimecode; 92 int m_minimum; 93 int m_maximum; 94 int m_value; 95 int m_offset; 96 97 public slots: 98 /** @brief Sets the value. 99 * @param value the new value 100 * The value actually set is forced to be within the legal range: minimum <= value <= maximum */ 101 void setValue(int value); 102 void setValue(const QString &value); 103 void setValue(const GenTime &value); 104 105 /** @brief Sets value's format according to Kdenlive's settings. 106 * @param t (optional, if already existing) Timecode object to use */ 107 void slotUpdateTimeCodeFormat(); 108 109 private slots: 110 void slotEditingFinished(); 111 112 signals: 113 void timeCodeEditingFinished(int value = -1); 114 void timeCodeUpdated(); 115 116 protected: 117 void keyPressEvent(QKeyEvent *e) override; 118 void mouseReleaseEvent(QMouseEvent *) override; 119 void wheelEvent(QWheelEvent *e) override; 120 void enterEvent(QEvent *e) override; 121 void leaveEvent(QEvent *e) override; 122 QAbstractSpinBox::StepEnabled stepEnabled() const override; 123 }; 124 125 #endif 126