File indexing completed on 2024-12-01 04:36:50

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "clickablewidget.h"
0008 #include <QHBoxLayout>
0009 #include <QIcon>
0010 
0011 ClickableWidget::ClickableWidget(const QString &userName, QWidget *parent)
0012     : QWidget(parent)
0013     , mName(userName)
0014     , mLabel(new QLabel(mName, this))
0015     , mClickableLabel(new ClickableLabel(this))
0016 {
0017     auto mainLayout = new QHBoxLayout(this);
0018     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0019     mainLayout->setContentsMargins({});
0020 
0021     mLabel->setObjectName(QStringLiteral("mUserLabel"));
0022     mainLayout->addWidget(mLabel);
0023 
0024     mClickableLabel->setObjectName(QStringLiteral("mClickableLabel"));
0025     mainLayout->addWidget(mClickableLabel);
0026     connect(mClickableLabel, &ClickableLabel::clicked, this, &ClickableWidget::slotRemove);
0027 }
0028 
0029 ClickableWidget::~ClickableWidget() = default;
0030 
0031 void ClickableWidget::slotRemove()
0032 {
0033     Q_EMIT removeClickableWidget(mName);
0034 }
0035 
0036 QString ClickableWidget::name() const
0037 {
0038     return mName;
0039 }
0040 
0041 void ClickableWidget::setName(const QString &userName)
0042 {
0043     mName = userName;
0044 }
0045 
0046 QString ClickableWidget::identifier() const
0047 {
0048     return mIdentifier;
0049 }
0050 
0051 void ClickableWidget::setIdentifier(const QString &userId)
0052 {
0053     mIdentifier = userId;
0054 }
0055 
0056 ClickableLabel::ClickableLabel(QWidget *parent)
0057     : QLabel(parent)
0058 {
0059     setPixmap(QIcon::fromTheme(QStringLiteral("delete")).pixmap(18, 18));
0060 }
0061 
0062 ClickableLabel::~ClickableLabel() = default;
0063 
0064 void ClickableLabel::mousePressEvent(QMouseEvent *event)
0065 {
0066     Q_EMIT clicked();
0067     QLabel::mousePressEvent(event);
0068 }
0069 
0070 #include "moc_clickablewidget.cpp"