File indexing completed on 2024-12-22 04:40:07
0001 /* 0002 SPDX-FileCopyrightText: 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar> 0003 SPDX-FileCopyrightText: 2010-2022 Mladen Milinkovic <max@smoothware.net> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "config.h" 0009 0010 #include "joinsubtitlesdialog.h" 0011 #include "helpers/commondefs.h" 0012 #include "videoplayer/videoplayer.h" 0013 #include "widgets/timeedit.h" 0014 0015 #include <QIcon> 0016 #include <QGridLayout> 0017 #include <QGroupBox> 0018 #include <QCheckBox> 0019 #include <QPushButton> 0020 0021 using namespace SubtitleComposer; 0022 0023 JoinSubtitlesDialog::JoinSubtitlesDialog(QWidget *parent) : 0024 SelectableSubtitleDialog(i18n("Join Subtitles"), parent) 0025 { 0026 createSubtitleGroupBox(); 0027 0028 m_shiftSubtitleCheckBox = new QCheckBox(m_subtitleGroupBox); 0029 m_shiftSubtitleCheckBox->setText(i18n("Shift subtitle forwards before append")); 0030 m_shiftSubtitleCheckBox->setChecked(true); 0031 0032 m_shiftTimeFromVideoButton = new QPushButton(m_subtitleGroupBox); 0033 m_shiftTimeFromVideoButton->setIcon(QIcon::fromTheme(QStringLiteral("time_from_video"))); 0034 int buttonSize = m_shiftTimeFromVideoButton->sizeHint().height(); 0035 m_shiftTimeFromVideoButton->setFixedSize(buttonSize, buttonSize); 0036 m_shiftTimeFromVideoButton->setToolTip(i18n("Set from video length")); 0037 0038 m_shiftTimeEdit = new TimeEdit(m_subtitleGroupBox); 0039 0040 connect(m_shiftTimeFromVideoButton, &QAbstractButton::clicked, this, &JoinSubtitlesDialog::setShiftTimeFromVideo); 0041 connect(m_shiftSubtitleCheckBox, &QAbstractButton::toggled, m_shiftTimeFromVideoButton, &QWidget::setEnabled); 0042 connect(m_shiftSubtitleCheckBox, &QAbstractButton::toggled, m_shiftTimeEdit, &QWidget::setEnabled); 0043 0044 createTargetsGroupBox(); 0045 createTextTargetsButtonGroup(); 0046 0047 QHBoxLayout *shiftTimeLayout = new QHBoxLayout(); 0048 shiftTimeLayout->addStretch(); 0049 shiftTimeLayout->addWidget(m_shiftTimeFromVideoButton); 0050 shiftTimeLayout->addWidget(m_shiftTimeEdit); 0051 0052 m_subtitleLayout->addWidget(m_shiftSubtitleCheckBox, 2, 0, 1, 2); 0053 m_subtitleLayout->addLayout(shiftTimeLayout, 2, 2); 0054 } 0055 0056 void 0057 JoinSubtitlesDialog::setShiftTimeFromVideo() 0058 { 0059 m_shiftTimeEdit->setValue((int)(VideoPlayer::instance()->duration() * 1000 + 0.5)); 0060 } 0061 0062 Time 0063 JoinSubtitlesDialog::shiftTime() const 0064 { 0065 return m_shiftSubtitleCheckBox->isChecked() ? m_shiftTimeEdit->value() : 0; 0066 } 0067 0068 void 0069 JoinSubtitlesDialog::show() 0070 { 0071 m_shiftTimeFromVideoButton->setEnabled(VideoPlayer::instance()->state() > VideoPlayer::Opening); 0072 if(m_shiftTimeFromVideoButton->isEnabled()) 0073 setShiftTimeFromVideo(); 0074 0075 SelectableSubtitleDialog::show(); 0076 } 0077 0078