File indexing completed on 2024-05-19 04:29:25

0001 /*
0002  *  SPDX-FileCopyrightText: 2023 L. E. Segovia <amy@amyspark.me>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "kis_warning_block.h"
0008 
0009 #include <QHBoxLayout>
0010 #include <QLabel>
0011 #include <qnamespace.h>
0012 
0013 struct Q_DECL_HIDDEN KisWarningBlock::Private {
0014     QLabel *lblIcon = nullptr;
0015     QLabel *lblText = nullptr;
0016 };
0017 
0018 KisWarningBlock::KisWarningBlock(QWidget *parent)
0019     : QGroupBox(parent)
0020     , m_d(new Private())
0021 {
0022     QHBoxLayout *layout = new QHBoxLayout(this);
0023 
0024     m_d->lblIcon = new QLabel(this);
0025     m_d->lblText = new QLabel(this);
0026 
0027     m_d->lblText->setTextFormat(Qt::RichText);
0028     m_d->lblIcon->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0029     m_d->lblText->setWordWrap(true);
0030     m_d->lblText->setTextInteractionFlags(Qt::LinksAccessibleByKeyboard | Qt::LinksAccessibleByMouse);
0031     m_d->lblText->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
0032 
0033     layout->addWidget(m_d->lblIcon);
0034     layout->addWidget(m_d->lblText);
0035     layout->setAlignment(Qt::AlignVCenter | Qt::AlignJustify);
0036 
0037     connect(m_d->lblText, &QLabel::linkActivated, this, &KisWarningBlock::linkActivated);
0038 }
0039 
0040 QString KisWarningBlock::text() const
0041 {
0042     return m_d->lblText->text();
0043 }
0044 
0045 QPixmap KisWarningBlock::pixmap() const
0046 {
0047 #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
0048     return m_d->lblIcon->pixmap(Qt::ReturnByValue);
0049 #else
0050     return QPixmap(*m_d->lblIcon->pixmap());
0051 #endif
0052 }
0053 
0054 void KisWarningBlock::setText(const QString &text)
0055 {
0056     m_d->lblText->setText(text);
0057 }
0058 
0059 void KisWarningBlock::setPixmap(const QPixmap &icon)
0060 {
0061     m_d->lblIcon->setPixmap(icon);
0062 }
0063 
0064 KisWarningBlock::~KisWarningBlock() = default;