File indexing completed on 2024-12-22 04:40:06

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 "actiondialog.h"
0009 
0010 #include <QGroupBox>
0011 #include <QGridLayout>
0012 
0013 using namespace SubtitleComposer;
0014 
0015 ActionDialog::ActionDialog(const QString &title, QWidget *parent)
0016     : QDialog(parent)
0017 {
0018     setWindowTitle(title);
0019 
0020     m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0021     connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
0022     connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
0023 
0024     m_mainWidget = new QWidget(this);
0025     m_mainLayout = new QVBoxLayout(m_mainWidget);
0026 
0027     QVBoxLayout *layout = new QVBoxLayout(this);
0028     layout->setAlignment(Qt::AlignTop);
0029 
0030     layout->addWidget(m_mainWidget);
0031     layout->addWidget(m_buttonBox);
0032 }
0033 
0034 int
0035 ActionDialog::exec()
0036 {
0037     // attempt at showing the full action name on the title...
0038     // it would work better if we could get the fontMetrics used by kwin
0039 //  int minWidth = fontMetrics().width( windowTitle() ) + 120;
0040 //  if ( minWidth > minimumWidth() )
0041 //      setMinimumWidth( minWidth );
0042 
0043     resize(minimumSizeHint());
0044     return QDialog::exec();
0045 }
0046 
0047 void
0048 ActionDialog::show()
0049 {
0050     // attempt at showing the full action name on the title...
0051     // it would work better if we could get the fontMetrics used by kwin
0052 //  int minWidth = fontMetrics().width( windowTitle() ) + 120;
0053 //  if ( minWidth > minimumWidth() )
0054 //      setMinimumWidth( minWidth );
0055 
0056     resize(minimumSizeHint());
0057     QDialog::show();
0058 }
0059 
0060 QGroupBox *
0061 ActionDialog::createGroupBox(const QString &title, bool addToLayout)
0062 {
0063     QGroupBox *groupBox = new QGroupBox(m_mainWidget);
0064     groupBox->setTitle(title);
0065 
0066     if(addToLayout)
0067         m_mainLayout->addWidget(groupBox);
0068 
0069     return groupBox;
0070 }
0071 
0072 QGridLayout *
0073 ActionDialog::createLayout(QGroupBox *groupBox)
0074 {
0075     QGridLayout *gridLayout = new QGridLayout(groupBox);
0076     gridLayout->setAlignment(Qt::AlignTop);
0077     gridLayout->setSpacing(5);
0078     return gridLayout;
0079 }