File indexing completed on 2024-06-09 04:52:58

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 "changeframeratedialog.h"
0009 
0010 #include <QLabel>
0011 #include <KLineEdit>
0012 #include <QGroupBox>
0013 #include <QGridLayout>
0014 
0015 #include <KMessageBox>
0016 #include <KComboBox>
0017 #include <KLocalizedString>
0018 
0019 using namespace SubtitleComposer;
0020 
0021 ChangeFrameRateDialog::ChangeFrameRateDialog(double fromFramesPerSecond, QWidget *parent) :
0022     ActionDialog(i18n("Change Frame Rate"), parent)
0023 {
0024     QGroupBox *settingsGroupBox = createGroupBox(i18nc("@title:group", "Settings"));
0025 
0026     m_fromFramesPerSecondComboBox = new KComboBox(false, settingsGroupBox);
0027     m_fromFramesPerSecondComboBox->setEditable(true);
0028     m_fromFramesPerSecondComboBox->addItems(QStringLiteral("15 20 23.976 24 25 29.970 30").split(' '));
0029     m_fromFramesPerSecondComboBox->setCurrentIndex(2);
0030     setFromFramesPerSecond(fromFramesPerSecond);
0031 
0032     QLabel *fromFramesPerSecondLabel = new QLabel(settingsGroupBox);
0033     fromFramesPerSecondLabel->setText(i18n("Current frame rate:"));
0034     fromFramesPerSecondLabel->setBuddy(m_fromFramesPerSecondComboBox);
0035 
0036     m_toFramesPerSecondComboBox = new KComboBox(false, settingsGroupBox);
0037     m_toFramesPerSecondComboBox->setEditable(true);
0038     m_toFramesPerSecondComboBox->addItems(QStringLiteral("15 20 23.976 24 25 29.970 30").split(' '));
0039     m_toFramesPerSecondComboBox->setCurrentIndex(2);
0040 
0041     QLabel *toFramesPerSecondLabel = new QLabel(settingsGroupBox);
0042     toFramesPerSecondLabel->setText(i18n("New frame rate:"));
0043     toFramesPerSecondLabel->setBuddy(m_toFramesPerSecondComboBox);
0044 
0045     connect(m_fromFramesPerSecondComboBox, &QComboBox::editTextChanged, this, &ChangeFrameRateDialog::onTextChanged);
0046     connect(m_toFramesPerSecondComboBox, &QComboBox::editTextChanged, this, &ChangeFrameRateDialog::onTextChanged);
0047 
0048     QGridLayout *settingsLayout = createLayout(settingsGroupBox);
0049     settingsLayout->addWidget(fromFramesPerSecondLabel, 0, 0, Qt::AlignRight | Qt::AlignVCenter);
0050     settingsLayout->addWidget(m_fromFramesPerSecondComboBox, 0, 1);
0051     settingsLayout->addWidget(toFramesPerSecondLabel, 1, 0, Qt::AlignRight | Qt::AlignVCenter);
0052     settingsLayout->addWidget(m_toFramesPerSecondComboBox, 1, 1);
0053 
0054     setMinimumWidth(sizeHint().width() + 25);
0055 }
0056 
0057 double
0058 ChangeFrameRateDialog::fromFramesPerSecond() const
0059 {
0060     return m_fromFramesPerSecondComboBox->lineEdit()->text().toDouble();
0061 }
0062 
0063 void
0064 ChangeFrameRateDialog::setFromFramesPerSecond(double framesPerSecond)
0065 {
0066     m_fromFramesPerSecondComboBox->lineEdit()->setText(QString::number(framesPerSecond, 'f', 3));
0067 }
0068 
0069 double
0070 ChangeFrameRateDialog::toFramesPerSecond() const
0071 {
0072     return m_toFramesPerSecondComboBox->lineEdit()->text().toDouble();
0073 }
0074 
0075 void
0076 ChangeFrameRateDialog::setNewFramesPerSecond(double framesPerSecond)
0077 {
0078     m_toFramesPerSecondComboBox->lineEdit()->setText(QString::number(framesPerSecond, 'f', 3));
0079 }
0080 
0081 void
0082 ChangeFrameRateDialog::onTextChanged()
0083 {
0084     bool applyButtonEnabled;
0085     m_fromFramesPerSecondComboBox->lineEdit()->text().toDouble(&applyButtonEnabled);
0086     if(applyButtonEnabled)
0087         m_toFramesPerSecondComboBox->lineEdit()->text().toDouble(&applyButtonEnabled);
0088 
0089     m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(applyButtonEnabled);
0090 }
0091 
0092