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 "splitsubtitledialog.h"
0011 #include "helpers/commondefs.h"
0012 #include "videoplayer/videoplayer.h"
0013 #include "widgets/timeedit.h"
0014 
0015 #include <QLabel>
0016 #include <QGroupBox>
0017 #include <QCheckBox>
0018 #include <QGridLayout>
0019 #include <QIcon>
0020 #include <QPushButton>
0021 
0022 #include <KLocalizedString>
0023 
0024 using namespace SubtitleComposer;
0025 
0026 SplitSubtitleDialog::SplitSubtitleDialog(QWidget *parent) :
0027     ActionDialog(i18n("Split Subtitle"), parent)
0028 {
0029     QGroupBox *settingsGroupBox = createGroupBox(i18nc("@title:group", "Settings"));
0030 
0031     m_splitTimeFromVideoButton = new QPushButton(settingsGroupBox);
0032     m_splitTimeFromVideoButton->setIcon(QIcon::fromTheme(QStringLiteral("time_from_video")));
0033     int buttonSize = m_splitTimeFromVideoButton->sizeHint().height();
0034     m_splitTimeFromVideoButton->setFixedSize(buttonSize, buttonSize);
0035     m_splitTimeFromVideoButton->setToolTip(i18n("Set from video length"));
0036 
0037     m_splitTimeEdit = new TimeEdit(settingsGroupBox);
0038 
0039     QLabel *splitTimeLabel = new QLabel(settingsGroupBox);
0040     splitTimeLabel->setText(i18n("Split time:"));
0041     splitTimeLabel->setBuddy(m_splitTimeEdit);
0042 
0043     m_shiftNewSubtitleCheckBox = new QCheckBox(settingsGroupBox);
0044     m_shiftNewSubtitleCheckBox->setText(i18n("Shift new part backwards after split"));
0045     m_shiftNewSubtitleCheckBox->setChecked(true);
0046 
0047     QHBoxLayout *splitTimeLayout = new QHBoxLayout();
0048     splitTimeLayout->addWidget(m_splitTimeFromVideoButton);
0049     splitTimeLayout->addWidget(m_splitTimeEdit);
0050 
0051     QGridLayout *settingsLayout = createLayout(settingsGroupBox);
0052     settingsLayout->addWidget(splitTimeLabel, 0, 0, Qt::AlignRight | Qt::AlignVCenter);
0053     settingsLayout->addLayout(splitTimeLayout, 0, 1);
0054     settingsLayout->addWidget(m_shiftNewSubtitleCheckBox, 1, 0, 1, 2);
0055 
0056     connect(m_splitTimeFromVideoButton, &QAbstractButton::clicked, this, &SplitSubtitleDialog::setSplitTimeFromVideo);
0057 }
0058 
0059 void
0060 SplitSubtitleDialog::setSplitTimeFromVideo()
0061 {
0062     m_splitTimeEdit->setValue(static_cast<int>(VideoPlayer::instance()->duration() * 1000 + 0.5));
0063 }
0064 
0065 Time
0066 SplitSubtitleDialog::splitTime() const
0067 {
0068     return m_splitTimeEdit->value();
0069 }
0070 
0071 bool
0072 SplitSubtitleDialog::shiftNewSubtitle() const
0073 {
0074     return m_shiftNewSubtitleCheckBox->isChecked();
0075 }
0076 
0077 void
0078 SplitSubtitleDialog::show()
0079 {
0080     m_splitTimeFromVideoButton->setEnabled(VideoPlayer::instance()->state() > VideoPlayer::Opening);
0081     if(m_splitTimeFromVideoButton->isEnabled())
0082         setSplitTimeFromVideo();
0083 
0084     ActionDialog::show();
0085 }
0086 
0087