File indexing completed on 2024-05-12 04:52:51
0001 /* 0002 SPDX-FileCopyrightText: 2010 Till Theato <root@ttill.de> 0003 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 #include "coloreditwidget.hpp" 0007 #include "assets/model/assetparametermodel.hpp" 0008 #include "utils/qcolorutils.h" 0009 #include "widgets/choosecolorwidget.h" 0010 0011 #include <QHBoxLayout> 0012 #include <QLabel> 0013 #include <QTextStream> 0014 0015 ColorEditWidget::ColorEditWidget(std::shared_ptr<AssetParameterModel> model, QModelIndex index, QWidget *parent) 0016 : AbstractParamWidget(std::move(model), index, parent) 0017 { 0018 // setup the comment 0019 QString name = m_model->data(m_index, Qt::DisplayRole).toString(); 0020 bool alphaEnabled = m_model->data(m_index, AssetParameterModel::AlphaRole).toBool(); 0021 QString color = m_model->data(m_index, AssetParameterModel::ValueRole).toString(); 0022 QString comment = m_model->data(m_index, AssetParameterModel::CommentRole).toString(); 0023 0024 QLabel *label = new QLabel(name, this); 0025 m_choosecolor = new ChooseColorWidget(this, QColorUtils::stringToColor(color), alphaEnabled); 0026 0027 auto *layout = new QHBoxLayout(this); 0028 layout->setContentsMargins(0, 0, 0, 0); 0029 layout->setSpacing(0); 0030 layout->addWidget(label, 1); 0031 layout->addWidget(m_choosecolor, 1); 0032 0033 // Q_EMIT the signal of the base class when appropriate 0034 connect(m_choosecolor, &ChooseColorWidget::modified, [this](const QColor &) { Q_EMIT valueChanged(m_index, getColor(), true); }); 0035 connect(m_choosecolor, &ChooseColorWidget::disableCurrentFilter, this, &AbstractParamWidget::disableCurrentFilter); 0036 // setup comment 0037 setToolTip(comment); 0038 } 0039 0040 void ColorEditWidget::slotShowComment(bool) {} 0041 0042 void ColorEditWidget::slotRefresh() 0043 { 0044 QSignalBlocker bk(this); 0045 QString color = m_model->data(m_index, AssetParameterModel::ValueRole).toString(); 0046 m_choosecolor->setColor(QColorUtils::stringToColor(color)); 0047 } 0048 0049 QString ColorEditWidget::getColor() const 0050 { 0051 return QColorUtils::colorToString(m_choosecolor->color(), m_choosecolor->isAlphaChannelEnabled()); 0052 } 0053 0054 void ColorEditWidget::setColor(const QColor &color) 0055 { 0056 m_choosecolor->setColor(color); 0057 }