File indexing completed on 2025-02-23 04:34:23
0001 /** 0002 * \file chaptereditor.cpp 0003 * Editor for chapter frames. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 18 Sep 2015 0008 * 0009 * Copyright (C) 2015-2018 Urs Fleisch 0010 * 0011 * This file is part of Kid3. 0012 * 0013 * Kid3 is free software; you can redistribute it and/or modify 0014 * it under the terms of the GNU General Public License as published by 0015 * the Free Software Foundation; either version 2 of the License, or 0016 * (at your option) any later version. 0017 * 0018 * Kid3 is distributed in the hope that it will be useful, 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0021 * GNU General Public License for more details. 0022 * 0023 * You should have received a copy of the GNU General Public License 0024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0025 */ 0026 0027 #include "chaptereditor.h" 0028 #include <QFormLayout> 0029 #include <QLineEdit> 0030 #include <QTimeEdit> 0031 #include <QTime> 0032 0033 /** 0034 * Constructor. 0035 * 0036 * @param parent parent widget 0037 */ 0038 ChapterEditor::ChapterEditor(QWidget* parent) 0039 : QWidget(parent) 0040 { 0041 setObjectName(QLatin1String("ChapterEditor")); 0042 auto formatLayout = new QFormLayout(this); 0043 formatLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow); 0044 QString timeFormat(QLatin1String("hh:mm:ss.zzz")); 0045 QString inputMask(QLatin1String("HHHHHHHH")); 0046 m_startTimeEdit = new QTimeEdit; 0047 m_startTimeEdit->setDisplayFormat(timeFormat); 0048 m_endTimeEdit = new QTimeEdit; 0049 m_endTimeEdit->setDisplayFormat(timeFormat); 0050 m_startOffsetEdit = new QLineEdit; 0051 m_startOffsetEdit->setInputMask(inputMask); 0052 m_endOffsetEdit = new QLineEdit; 0053 m_endOffsetEdit->setInputMask(inputMask); 0054 formatLayout->addRow(tr("Start time"), m_startTimeEdit); 0055 formatLayout->addRow(tr("End time"), m_endTimeEdit); 0056 formatLayout->addRow(tr("Start offset"), m_startOffsetEdit); 0057 formatLayout->addRow(tr("End offset"), m_endOffsetEdit); 0058 } 0059 0060 /** 0061 * Set start and end time of chapter. 0062 * @param startTimeMs start time in ms 0063 * @param endTimeMs end time in ms 0064 * @param startOffset offset of first byte of chapter in file, 0065 * ignored if all ones 0066 * @param endOffset offset of byte after last chapter byte, 0067 * ignored if all ones 0068 */ 0069 void ChapterEditor::setValues(quint32 startTimeMs, quint32 endTimeMs, 0070 quint32 startOffset, quint32 endOffset) 0071 { 0072 const QTime zeroTime(0, 0); 0073 QTime startTime = zeroTime.addMSecs(startTimeMs); 0074 m_startTimeEdit->setTime(startTime); 0075 QTime endTime = zeroTime.addMSecs(endTimeMs); 0076 m_endTimeEdit->setTime(endTime); 0077 m_startOffsetEdit->setText(QString::number(startOffset, 16).toUpper()); 0078 m_endOffsetEdit->setText(QString::number(endOffset, 16).toUpper()); 0079 } 0080 0081 /** 0082 * Get start and end time of chapter. 0083 * @param startTimeMs the start time in ms is returned here 0084 * @param endTimeMs the end time in ms is returned here 0085 * @param startOffset the offset of the first byte of chapter in file is 0086 * returned here, ignored if all ones 0087 * @param endOffset the offset of the byte after the last chapter byte is 0088 * returned here, ignored if all ones 0089 */ 0090 void ChapterEditor::getValues(quint32& startTimeMs, quint32& endTimeMs, 0091 quint32& startOffset, quint32& endOffset) const 0092 { 0093 const QTime zeroTime(0, 0); 0094 startTimeMs = zeroTime.msecsTo(m_startTimeEdit->time()); 0095 endTimeMs = zeroTime.msecsTo(m_endTimeEdit->time()); 0096 bool ok; 0097 startOffset = m_startOffsetEdit->text().toUInt(&ok, 16); 0098 if (!ok) { 0099 startOffset = 0xffffffff; 0100 } 0101 endOffset = m_endOffsetEdit->text().toUInt(&ok, 16); 0102 if (!ok) { 0103 endOffset = 0xffffffff; 0104 } 0105 }