File indexing completed on 2024-05-12 04:19:41

0001 // vim: set tabstop=4 shiftwidth=4 expandtab:
0002 /*
0003 Gwenview: an image viewer
0004 Copyright 2009 Aurélien Gâteau <agateau@kde.org>
0005 
0006 This program is free software; you can redistribute it and/or
0007 modify it under the terms of the GNU General Public License
0008 as published by the Free Software Foundation; either version 2
0009 of the License, or (at your option) any later version.
0010 
0011 This program is distributed in the hope that it will be useful,
0012 but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 GNU General Public License for more details.
0015 
0016 You should have received a copy of the GNU General Public License
0017 along with this program; if not, write to the Free Software
0018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
0019 
0020 */
0021 // Self
0022 #include "hudmessagebubble.h"
0023 
0024 // Qt
0025 #include <QGraphicsLinearLayout>
0026 
0027 // KF
0028 #include <KGuiItem>
0029 
0030 // Local
0031 #include "gwenview_lib_debug.h"
0032 #include <lib/hud/hudbutton.h>
0033 #include <lib/hud/hudcountdown.h>
0034 #include <lib/hud/hudlabel.h>
0035 #include <lib/hud/hudtheme.h>
0036 
0037 namespace Gwenview
0038 {
0039 static const int TIMEOUT = 10000;
0040 
0041 struct HudMessageBubblePrivate {
0042     QGraphicsWidget *mWidget = nullptr;
0043     QGraphicsLinearLayout *mLayout = nullptr;
0044     HudCountDown *mCountDown = nullptr;
0045     HudLabel *mLabel = nullptr;
0046 };
0047 
0048 HudMessageBubble::HudMessageBubble(QGraphicsWidget *parent)
0049     : HudWidget(parent)
0050     , d(new HudMessageBubblePrivate)
0051 {
0052     d->mWidget = new QGraphicsWidget;
0053     d->mCountDown = new HudCountDown;
0054     d->mLabel = new HudLabel;
0055 
0056     connect(d->mCountDown, &HudCountDown::timeout, this, &HudMessageBubble::fadeOut);
0057     connect(this, &HudMessageBubble::fadedOut, this, &HudMessageBubble::deleteLater);
0058 
0059     d->mLayout = new QGraphicsLinearLayout(d->mWidget);
0060     d->mLayout->setContentsMargins(0, 0, 0, 0);
0061     d->mLayout->addItem(d->mCountDown);
0062     d->mLayout->addItem(d->mLabel);
0063 
0064     init(d->mWidget, HudWidget::OptionCloseButton);
0065     d->mCountDown->start(TIMEOUT);
0066 }
0067 
0068 HudMessageBubble::~HudMessageBubble()
0069 {
0070     delete d;
0071 }
0072 
0073 void HudMessageBubble::setText(const QString &text)
0074 {
0075     d->mLabel->setText(text);
0076 }
0077 
0078 HudButton *HudMessageBubble::addButton(const KGuiItem &guiItem)
0079 {
0080     auto button = new HudButton;
0081     button->setText(guiItem.text());
0082     button->setIcon(guiItem.icon());
0083     d->mLayout->addItem(button);
0084     return button;
0085 }
0086 
0087 } // namespace
0088 
0089 #include "moc_hudmessagebubble.cpp"