File indexing completed on 2024-05-12 04:52:54
0001 /* 0002 SPDX-FileCopyrightText: 2016 Nicolas Carion 0003 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 #include "listparamwidget.h" 0007 #include "assets/model/assetparametermodel.hpp" 0008 #include "core.h" 0009 #include "mainwindow.h" 0010 0011 ListParamWidget::ListParamWidget(std::shared_ptr<AssetParameterModel> model, QModelIndex index, QWidget *parent) 0012 : AbstractParamWidget(std::move(model), index, parent) 0013 { 0014 setupUi(this); 0015 0016 // Get data from model 0017 QString comment = m_model->data(m_index, AssetParameterModel::CommentRole).toString(); 0018 0019 // setup the comment 0020 setToolTip(comment); 0021 m_labelComment->setText(comment); 0022 m_widgetComment->setHidden(true); 0023 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 0024 m_list->setIconSize(QSize(50, 30)); 0025 setMinimumHeight(m_list->sizeHint().height()); 0026 // setup the name 0027 m_labelName->setText(m_model->data(m_index, Qt::DisplayRole).toString()); 0028 slotRefresh(); 0029 0030 // Q_EMIT the signal of the base class when appropriate 0031 // The connection is ugly because the signal "currentIndexChanged" is overloaded in QComboBox 0032 connect(this->m_list, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, 0033 [this](int) { Q_EMIT valueChanged(m_index, m_list->itemData(m_list->currentIndex()).toString(), true); }); 0034 } 0035 0036 void ListParamWidget::setCurrentIndex(int index) 0037 { 0038 m_list->setCurrentIndex(index); 0039 } 0040 0041 void ListParamWidget::setCurrentText(const QString &text) 0042 { 0043 m_list->setCurrentText(text); 0044 } 0045 0046 void ListParamWidget::addItem(const QString &text, const QVariant &value) 0047 { 0048 m_list->addItem(text, value); 0049 } 0050 0051 void ListParamWidget::setItemIcon(int index, const QIcon &icon) 0052 { 0053 m_list->setItemIcon(index, icon); 0054 } 0055 0056 void ListParamWidget::setIconSize(const QSize &size) 0057 { 0058 m_list->setIconSize(size); 0059 } 0060 0061 void ListParamWidget::slotShowComment(bool show) 0062 { 0063 if (!m_labelComment->text().isEmpty()) { 0064 m_widgetComment->setVisible(show); 0065 } 0066 } 0067 0068 QString ListParamWidget::getValue() 0069 { 0070 return m_list->currentData().toString(); 0071 } 0072 0073 void ListParamWidget::slotRefresh() 0074 { 0075 const QSignalBlocker bk(m_list); 0076 m_list->clear(); 0077 QStringList names = m_model->data(m_index, AssetParameterModel::ListNamesRole).toStringList(); 0078 QStringList values = m_model->data(m_index, AssetParameterModel::ListValuesRole).toStringList(); 0079 QString value = m_model->data(m_index, AssetParameterModel::ValueRole).toString(); 0080 if (values.first() == QLatin1String("%lumaPaths")) { 0081 // Special case: Luma files 0082 // Create thumbnails 0083 if (pCore->getCurrentFrameSize().width() > 1000) { 0084 // HD project 0085 values = MainWindow::m_lumaFiles.value(QStringLiteral("16_9")); 0086 } else if (pCore->getCurrentFrameSize().height() > 1000) { 0087 values = MainWindow::m_lumaFiles.value(QStringLiteral("9_16")); 0088 } else if (pCore->getCurrentFrameSize().height() == pCore->getCurrentFrameSize().width()) { 0089 values = MainWindow::m_lumaFiles.value(QStringLiteral("square")); 0090 } else if (pCore->getCurrentFrameSize().height() == 480) { 0091 values = MainWindow::m_lumaFiles.value(QStringLiteral("NTSC")); 0092 } else { 0093 values = MainWindow::m_lumaFiles.value(QStringLiteral("PAL")); 0094 } 0095 m_list->addItem(i18n("None (Dissolve)")); 0096 for (int j = 0; j < values.count(); ++j) { 0097 const QString &entry = values.at(j); 0098 const QString name = values.at(j).section(QLatin1Char('/'), -1); 0099 m_list->addItem(pCore->nameForLumaFile(name), entry); 0100 if (!entry.isEmpty() && (entry.endsWith(QLatin1String(".png")) || entry.endsWith(QLatin1String(".pgm")))) { 0101 if (MainWindow::m_lumacache.contains(entry)) { 0102 m_list->setItemIcon(j + 1, QPixmap::fromImage(MainWindow::m_lumacache.value(entry))); 0103 } 0104 } 0105 } 0106 if (!value.isEmpty() && values.contains(value)) { 0107 m_list->setCurrentIndex(values.indexOf(value) + 1); 0108 } 0109 } else { 0110 if (names.count() != values.count()) { 0111 names = values; 0112 } 0113 for (int i = 0; i < names.count(); i++) { 0114 m_list->addItem(names.at(i), values.at(i)); 0115 } 0116 if (!value.isEmpty()) { 0117 int ix = m_list->findData(value); 0118 if (ix > -1) { 0119 m_list->setCurrentIndex(ix); 0120 } 0121 } 0122 } 0123 }