File indexing completed on 2024-06-16 04:16:17
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Dmitrii Utkin <loentar@gmail.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-only 0005 */ 0006 0007 #include "recorder_profile_settings.h" 0008 #include "recorder_export_config.h" 0009 #include "ui_recorder_profile_settings.h" 0010 0011 #include <klocalizedstring.h> 0012 #include <kstandardguiitem.h> 0013 #include <kis_icon_utils.h> 0014 0015 namespace 0016 { 0017 enum ArgumentsPageIndex 0018 { 0019 PageEdit, 0020 PagePreview 0021 }; 0022 } 0023 0024 0025 RecorderProfileSettings::RecorderProfileSettings(QWidget *parent) 0026 : QDialog(parent) 0027 , ui(new Ui::RecorderProfileSettings) 0028 { 0029 ui->setupUi(this); 0030 0031 KGuiItem::assign(ui->buttonBox->button(QDialogButtonBox::Ok), KStandardGuiItem::ok()); 0032 KGuiItem::assign(ui->buttonBox->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel()); 0033 0034 ui->buttonPresetRevert->setIcon(KisIconUtils::loadIcon("edit-undo")); 0035 ui->stackedWidget->setCurrentIndex(ArgumentsPageIndex::PageEdit); 0036 0037 connect(ui->labelSupportedVariables, SIGNAL(linkActivated(QString)), this, SLOT(onLinkActivated(QString))); 0038 connect(ui->checkPreview, SIGNAL(toggled(bool)), this, SLOT(onPreviewToggled(bool))); 0039 } 0040 0041 RecorderProfileSettings::~RecorderProfileSettings() 0042 { 0043 delete ui; 0044 } 0045 0046 bool RecorderProfileSettings::editProfile(RecorderProfile *profile, const RecorderProfile &defaultProfile) 0047 { 0048 fillProfile(*profile); 0049 0050 disconnect(ui->buttonPresetRevert); 0051 connect(ui->buttonPresetRevert, &QPushButton::clicked, [&] { fillProfile(defaultProfile); }); 0052 0053 if (exec() != QDialog::Accepted) 0054 return false; 0055 0056 profile->name = ui->editProfileName->text(); 0057 profile->extension = ui->editFileExtension->text(); 0058 profile->arguments = ui->editFfmpegArguments->toPlainText(); 0059 0060 return true; 0061 } 0062 0063 void RecorderProfileSettings::setPreview(const QString &preview) 0064 { 0065 ui->editPreview->setPlainText(preview); 0066 } 0067 0068 void RecorderProfileSettings::onInputChanged() 0069 { 0070 const QString &name = ui->editProfileName->text(); 0071 const QString &extension = ui->editFileExtension->text(); 0072 const QString &arguments = ui->editFfmpegArguments->toPlainText(); 0073 0074 bool isValid = (!name.isEmpty()) && (!extension.isEmpty()) && (!arguments.isEmpty()); 0075 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(isValid); 0076 } 0077 0078 void RecorderProfileSettings::onLinkActivated(const QString &link) 0079 { 0080 ui->editFfmpegArguments->insertPlainText(link); 0081 ui->editFfmpegArguments->setFocus(); 0082 } 0083 0084 void RecorderProfileSettings::onPreviewToggled(bool checked) 0085 { 0086 if (checked) 0087 emit requestPreview(ui->editFfmpegArguments->toPlainText()); 0088 0089 ui->stackedWidget->setCurrentIndex(checked ? ArgumentsPageIndex::PagePreview : ArgumentsPageIndex::PageEdit); 0090 } 0091 0092 void RecorderProfileSettings::fillProfile(const RecorderProfile &profile) 0093 { 0094 ui->editProfileName->setText(profile.name); 0095 ui->editFileExtension->setText(profile.extension); 0096 ui->editFfmpegArguments->setPlainText(profile.arguments); 0097 }