File indexing completed on 2024-05-12 04:52:51
0001 /* 0002 SPDX-FileCopyrightText: 2016 Nicolas Carion 0003 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 #include "boolparamwidget.hpp" 0007 #include "assets/model/assetparametermodel.hpp" 0008 0009 BoolParamWidget::BoolParamWidget(std::shared_ptr<AssetParameterModel> model, QModelIndex index, QWidget *parent) 0010 : AbstractParamWidget(std::move(model), index, parent) 0011 { 0012 setupUi(this); 0013 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 0014 // setup the comment 0015 QString comment = m_model->data(m_index, AssetParameterModel::CommentRole).toString(); 0016 setToolTip(comment); 0017 m_labelComment->setText(comment); 0018 m_widgetComment->setHidden(true); 0019 0020 // setup the name 0021 m_labelName->setText(m_model->data(m_index, Qt::DisplayRole).toString()); 0022 setMinimumHeight(m_labelName->sizeHint().height()); 0023 0024 // set check state 0025 slotRefresh(); 0026 0027 // Q_EMIT the signal of the base class when appropriate 0028 connect(this->m_checkBox, &QCheckBox::stateChanged, this, [this](int state) { 0029 // To represent 'checked' status, Qt uses number '2', but 0030 // the boolean parameters in MLT effects use number '1' 0031 if (state == 2) { 0032 state = 1; 0033 } 0034 Q_EMIT valueChanged(m_index, QString::number(state), true); 0035 }); 0036 } 0037 0038 void BoolParamWidget::slotShowComment(bool show) 0039 { 0040 if (!m_labelComment->text().isEmpty()) { 0041 m_widgetComment->setVisible(show); 0042 } 0043 } 0044 0045 void BoolParamWidget::slotRefresh() 0046 { 0047 QSignalBlocker bk(m_checkBox); 0048 bool checked = m_model->data(m_index, AssetParameterModel::ValueRole).toInt(); 0049 m_checkBox->setChecked(checked); 0050 } 0051 0052 bool BoolParamWidget::getValue() 0053 { 0054 return m_checkBox->isChecked(); 0055 }