File indexing completed on 2024-12-22 04:40:07
0001 /* 0002 SPDX-FileCopyrightText: 2023 Mladen Milinkovic <max@smoothware.net> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #include "subtitleclassdialog.h" 0007 #include "ui_subtitleclassdialog.h" 0008 0009 #include <QComboBox> 0010 #include <QDialogButtonBox> 0011 #include <QLayout> 0012 #include <QLineEdit> 0013 #include <QPushButton> 0014 #include <QVBoxLayout> 0015 0016 0017 using namespace SubtitleComposer; 0018 0019 0020 SubtitleClassDialog::SubtitleClassDialog(QWidget *parent, Qt::WindowFlags flags) 0021 : QDialog(parent, flags), 0022 ui(new Ui::SubtitleClassDialog) 0023 { 0024 ui->setupUi(this); 0025 0026 connect(ui->classList, &QComboBox::currentTextChanged, this, [&](){ emit currentClassChanged(currentClass()); }); 0027 connect(this, &QDialog::accepted, this, [&](){ emit classSelected(currentClass()); }); 0028 } 0029 0030 SubtitleClassDialog::SubtitleClassDialog(const QString &initial, QWidget *parent, Qt::WindowFlags flags) 0031 : SubtitleClassDialog(parent, flags) 0032 { 0033 QSignalBlocker sb(this); 0034 setCurrentClass(initial); 0035 } 0036 0037 SubtitleClassDialog::~SubtitleClassDialog() 0038 { 0039 delete ui; 0040 } 0041 0042 void 0043 SubtitleClassDialog::setCurrentClass(const QString &cssClass) 0044 { 0045 ui->classList->setCurrentText(cssClass); 0046 } 0047 0048 QString 0049 SubtitleClassDialog::currentClass() const 0050 { 0051 return ui->classList->currentText(); 0052 } 0053 0054 QString 0055 SubtitleClassDialog::getClass(const QStringList &classes, const QString &initial, QWidget *parent, const QString &title) 0056 { 0057 SubtitleClassDialog dlg(parent); 0058 if(!title.isEmpty()) 0059 dlg.setWindowTitle(title); 0060 dlg.ui->classList->addItems(classes); 0061 dlg.setCurrentClass(initial); 0062 return dlg.exec() == QDialog::Accepted ? dlg.selectedClass() : QString(); 0063 }