File indexing completed on 2024-05-12 04:52:51

0001 /*
0002     SPDX-FileCopyrightText: 2019 Jean-Baptiste Mardelle
0003     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 
0006 #include "clickablelabelwidget.hpp"
0007 #include "assets/model/assetparametermodel.hpp"
0008 #include "core.h"
0009 
0010 #include <QApplication>
0011 #include <QClipboard>
0012 #include <QIcon>
0013 #include <QLabel>
0014 #include <QPushButton>
0015 #include <QToolButton>
0016 #include <QVBoxLayout>
0017 
0018 ClickableLabelParamWidget::ClickableLabelParamWidget(std::shared_ptr<AssetParameterModel> model, QModelIndex index, QWidget *parent)
0019     : AbstractParamWidget(std::move(model), index, parent)
0020 {
0021     // setup the comment
0022     m_displayName = m_model->data(m_index, Qt::DisplayRole).toString();
0023     QString comment = m_model->data(m_index, AssetParameterModel::CommentRole).toString();
0024     setToolTip(comment);
0025     auto *layout = new QHBoxLayout(this);
0026     m_tb = new QToolButton(this);
0027     m_tb->setCursor(Qt::PointingHandCursor);
0028     m_tb->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
0029     m_label = new QLabel(this);
0030     m_label->setWordWrap(true);
0031     layout->setContentsMargins(0, 0, 0, 0);
0032     layout->addWidget(m_tb);
0033     layout->addWidget(m_label);
0034     connect(m_tb, &QToolButton::clicked, this, [&]() {
0035         QClipboard *clipboard = QApplication::clipboard();
0036         QString value = m_model->data(m_index, AssetParameterModel::ValueRole).toString();
0037         clipboard->setText(value);
0038     });
0039     connect(m_label, &QLabel::linkActivated, this, [&](const QString &result) {
0040         QClipboard *clipboard = QApplication::clipboard();
0041         clipboard->setText(result);
0042     });
0043     slotRefresh();
0044 }
0045 
0046 void ClickableLabelParamWidget::slotShowComment(bool show)
0047 {
0048     Q_UNUSED(show);
0049     /*if (!m_labelComment->text().isEmpty()) {
0050         m_widgetComment->setVisible(show);
0051     }*/
0052 }
0053 
0054 void ClickableLabelParamWidget::slotRefresh()
0055 {
0056     QString value = m_model->data(m_index, AssetParameterModel::ValueRole).toString();
0057     m_label->setText(QStringLiteral("<a href=\"%1\">").arg(value) + m_displayName + QStringLiteral("</a>"));
0058     setVisible(!value.isEmpty());
0059     setMinimumHeight(value.isEmpty() ? 0 : m_tb->sizeHint().height());
0060     Q_EMIT updateHeight();
0061 }
0062 
0063 bool ClickableLabelParamWidget::getValue()
0064 {
0065     return true;
0066 }