File indexing completed on 2024-12-01 04:37:05
0001 /* 0002 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "selectedmessagebackgroundanimationwidget.h" 0008 #include "room/selectedmessagebackgroundanimation.h" 0009 #include <QPaintEvent> 0010 #include <QPainter> 0011 #include <QPushButton> 0012 #include <QVBoxLayout> 0013 SelectedMessageBackgroundAnimationWidget::SelectedMessageBackgroundAnimationWidget(QWidget *parent) 0014 : QWidget{parent} 0015 , mLabel(new SelectedMessageBackgroundAnimationLabel(this)) 0016 { 0017 auto mainLayout = new QVBoxLayout(this); 0018 mainLayout->addWidget(mLabel); 0019 0020 auto pushButton = new QPushButton(QStringLiteral("Activate"), this); 0021 mainLayout->addWidget(pushButton); 0022 connect(pushButton, &QPushButton::clicked, this, [this] { 0023 auto animation = new SelectedMessageBackgroundAnimation(nullptr, this); 0024 connect(animation, &SelectedMessageBackgroundAnimation::backgroundColorChanged, this, [this, animation]() { 0025 mLabel->setBackgroundColor(animation->backgroundColor()); 0026 }); 0027 animation->start(); 0028 }); 0029 } 0030 0031 SelectedMessageBackgroundAnimationWidget::~SelectedMessageBackgroundAnimationWidget() = default; 0032 0033 // Label 0034 SelectedMessageBackgroundAnimationLabel::SelectedMessageBackgroundAnimationLabel(QWidget *parent) 0035 : QWidget(parent) 0036 { 0037 } 0038 0039 SelectedMessageBackgroundAnimationLabel::~SelectedMessageBackgroundAnimationLabel() = default; 0040 0041 void SelectedMessageBackgroundAnimationLabel::setBackgroundColor(const QColor &col) 0042 { 0043 mBackgroundColor = col; 0044 update(); 0045 } 0046 0047 void SelectedMessageBackgroundAnimationLabel::paintEvent(QPaintEvent *event) 0048 { 0049 QPainter p(this); 0050 p.fillRect(event->rect(), mBackgroundColor); 0051 } 0052 0053 #include "moc_selectedmessagebackgroundanimationwidget.cpp"