File indexing completed on 2024-05-12 16:43:55

0001 /*
0002     SPDX-FileCopyrightText: 2015-2018 Thomas Baumgart <tbaumgart@kde.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef WIDGETHINTFRAME_H
0007 #define WIDGETHINTFRAME_H
0008 
0009 // ----------------------------------------------------------------------------
0010 // QT Includes
0011 
0012 #include <QFrame>
0013 class QWidget;
0014 
0015 // ----------------------------------------------------------------------------
0016 // KDE Includes
0017 
0018 // ----------------------------------------------------------------------------
0019 // Project Includes
0020 
0021 class WidgetHintFrame : public QFrame
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     enum FrameStyle {
0027         Error = 0,
0028         Warning,
0029         Info,
0030     };
0031     Q_ENUM(FrameStyle)
0032 
0033     explicit WidgetHintFrame(QWidget* editWidget, FrameStyle style = Error, Qt::WindowFlags f = 0);
0034     ~WidgetHintFrame();
0035 
0036     void attachToWidget(QWidget* w);
0037     void detachFromWidget();
0038 
0039     bool isErroneous() const;
0040 
0041     QWidget* editWidget() const;
0042 
0043     /**
0044      * Shows the info frame around @a editWidget and in case @a tooltip
0045      * is not null (@sa QString::isNull()) the respective message will
0046      * be loaded into the @a editWidget's tooltip. In case @a tooltip is null
0047      * (the default) the @a editWidget's tooltip will not be changed.
0048      */
0049     static void show(QWidget* editWidget, const QString& tooltip = QString());
0050 
0051     /**
0052      * Hides the info frame around @a editWidget and in case @a tooltip
0053      * is not null (@sa QString::isNull()) the respective message will
0054      * be loaded into the @a editWidget's tooltip. In case @a tooltip is null
0055      * (the default) the @a editWidget's tooltip will not be changed.
0056      */
0057     static void hide(QWidget* editWidget, const QString& tooltip = QString());
0058 
0059 protected:
0060     bool eventFilter(QObject* o, QEvent* e) final override;
0061 
0062 Q_SIGNALS:
0063     void changed();
0064 
0065 private:
0066     class Private;
0067     Private * const d;
0068 };
0069 
0070 class WidgetHintFrameCollection : public QObject
0071 {
0072     Q_OBJECT
0073 public:
0074     explicit WidgetHintFrameCollection(QObject* parent = 0);
0075     ~WidgetHintFrameCollection();
0076 
0077     void addFrame(WidgetHintFrame* frame);
0078     void addWidget(QWidget* w);
0079     void removeWidget(QWidget* w);
0080 
0081 protected Q_SLOTS:
0082     virtual void frameDestroyed(QObject* o);
0083     virtual void updateWidgets();
0084 
0085 Q_SIGNALS:
0086     void inputIsValid(bool valid);
0087 
0088 private:
0089     class Private;
0090     Private * const d;
0091 };
0092 
0093 #endif // WIDGETHINTFRAME_H
0094