KTextAddons

textmessageindicator.h
1/*
2 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include <QWidget>
10class QTimer;
11namespace TextCustomEditor
12{
13/**
14 * @short A widget that displays messages in the top-left corner.
15 *
16 * This is a widget with thin border and rounded corners that displays a given
17 * text along as an icon. It's meant to be used for displaying messages to the
18 * user by placing this above other widgets.
19 * @author Laurent Montel <montel@kde.org>
20 */
22{
24public:
25 explicit TextMessageIndicator(QWidget *parent = nullptr);
26
27 enum Icon {
28 None,
29 Info,
30 Warning,
31 Error,
32 };
33
34 void display(const QString &message, const QString &details = QString(), Icon icon = None, int durationMs = 4000);
35
36protected:
37 bool eventFilter(QObject *obj, QEvent *event) override;
38 void paintEvent(QPaintEvent *e) override;
39 void mousePressEvent(QMouseEvent *e) override;
40
41private:
42 QRect computeTextRect(const QString &message, int extra_width) const;
43 void computeSizeAndResize();
44 QString mMessage;
45 QString mDetails;
46 QPixmap mSymbol;
47 QTimer *mTimer = nullptr;
48 int mLineSpacing = 0;
49};
50}
A widget that displays messages in the top-left corner.
Q_OBJECTQ_OBJECT
QObject * parent() const const
virtual bool event(QEvent *event) override
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:02:02 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.