File indexing completed on 2024-06-23 04:40:19
0001 /* 0002 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QWidget> 0010 class QTimer; 0011 namespace TextCustomEditor 0012 { 0013 /** 0014 * @short A widget that displays messages in the top-left corner. 0015 * 0016 * This is a widget with thin border and rounded corners that displays a given 0017 * text along as an icon. It's meant to be used for displaying messages to the 0018 * user by placing this above other widgets. 0019 * @author Laurent Montel <montel@kde.org> 0020 */ 0021 class TextMessageIndicator : public QWidget 0022 { 0023 Q_OBJECT 0024 public: 0025 explicit TextMessageIndicator(QWidget *parent = nullptr); 0026 0027 enum Icon { 0028 None, 0029 Info, 0030 Warning, 0031 Error, 0032 }; 0033 0034 void display(const QString &message, const QString &details = QString(), Icon icon = None, int durationMs = 4000); 0035 0036 protected: 0037 bool eventFilter(QObject *obj, QEvent *event) override; 0038 void paintEvent(QPaintEvent *e) override; 0039 void mousePressEvent(QMouseEvent *e) override; 0040 0041 private: 0042 QRect computeTextRect(const QString &message, int extra_width) const; 0043 void computeSizeAndResize(); 0044 QString mMessage; 0045 QString mDetails; 0046 QPixmap mSymbol; 0047 QTimer *mTimer = nullptr; 0048 int mLineSpacing = 0; 0049 }; 0050 }