File indexing completed on 2024-05-12 05:08:01
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 #include "kmm_base_widgets_export.h" 0010 0011 // ---------------------------------------------------------------------------- 0012 // QT Includes 0013 0014 #include <QFrame> 0015 class QWidget; 0016 class QMetaMethod; 0017 0018 // ---------------------------------------------------------------------------- 0019 // KDE Includes 0020 0021 // ---------------------------------------------------------------------------- 0022 // Project Includes 0023 0024 class KMM_BASE_WIDGETS_EXPORT WidgetHintFrame : public QFrame 0025 { 0026 Q_OBJECT 0027 0028 public: 0029 enum FrameStyle { 0030 Error = 0, 0031 Warning, 0032 Info, 0033 Focus, 0034 }; 0035 Q_ENUM(FrameStyle) 0036 0037 explicit WidgetHintFrame(QWidget* editWidget, FrameStyle style = Error, Qt::WindowFlags f = {}); 0038 ~WidgetHintFrame(); 0039 0040 /** 0041 * Attach the WidgetHintFrame to the widget @a w. 0042 */ 0043 void attachToWidget(QWidget* w); 0044 0045 /** 0046 * Remove the frame from the widget it is attached to. 0047 * If no widget is attached, nothing will be done. 0048 */ 0049 void detachFromWidget(); 0050 0051 /** 0052 * Set the @a style of the frame. For the style @c Focus 0053 * the @c offset will be set to 0 for all other styles 0054 * it will be set to 2. 0055 * 0056 * @sa setOffset() 0057 */ 0058 void setStyle(FrameStyle style); 0059 0060 /** 0061 * Set the offset to be kept between the attached 0062 * widget and the frame in pixels. The setting will 0063 * be overridden by setStyle(). 0064 * 0065 * @sa setStyle() 0066 */ 0067 void setOffset(int offset); 0068 0069 /** 0070 * Returns @c true when @c style is @c Error and 0071 * the frame is visible. Returns @c false otherwise. 0072 */ 0073 bool isErroneous() const; 0074 0075 /** 0076 * Returns a pointer to the widget surrounded by 0077 * the frame or @c nullptr if none is attached. 0078 * 0079 * @sa attachToWidget(), detachFromWidget() 0080 */ 0081 QWidget* editWidget() const; 0082 0083 /** 0084 * Shows the info frame around @a editWidget and in case @a tooltip 0085 * is not null (@sa QString::isNull()) the respective message will 0086 * be loaded into the @a editWidget's tooltip. In case @a tooltip is null 0087 * (the default) the @a editWidget's tooltip will not be changed. 0088 */ 0089 static void show(QWidget* editWidget, const QString& tooltip = QString()); 0090 0091 /** 0092 * Hides the info frame around @a editWidget and in case @a tooltip 0093 * is not null (@sa QString::isNull()) the respective message will 0094 * be loaded into the @a editWidget's tooltip. In case @a tooltip is null 0095 * (the default) the @a editWidget's tooltip will not be changed. 0096 */ 0097 static void hide(QWidget* editWidget, const QString& tooltip = QString()); 0098 0099 protected: 0100 bool eventFilter(QObject* o, QEvent* e) final override; 0101 0102 Q_SIGNALS: 0103 void changed(); 0104 0105 private: 0106 class Private; 0107 Private* const d; 0108 }; 0109 0110 class KMM_BASE_WIDGETS_EXPORT WidgetHintFrameCollection : public QObject 0111 { 0112 Q_OBJECT 0113 public: 0114 explicit WidgetHintFrameCollection(QObject* parent = 0); 0115 ~WidgetHintFrameCollection(); 0116 0117 void addFrame(WidgetHintFrame* frame); 0118 void addWidget(QWidget* w); 0119 void removeWidget(QWidget* w); 0120 0121 /** 0122 * Connect the @a chainedCollection so that its result affects this 0123 * collection. Only one collection can be chained. 0124 * 0125 * @returns true if the connection was setup correctly. 0126 */ 0127 bool chainFrameCollection(WidgetHintFrameCollection* chainedCollection); 0128 0129 protected: 0130 void connectNotify(const QMetaMethod& signal) override; 0131 0132 protected Q_SLOTS: 0133 virtual void unchainFrameCollection(); 0134 virtual void frameDestroyed(QObject* o); 0135 virtual void changeChainedCollectionState(bool valid); 0136 virtual void updateWidgets(); 0137 0138 Q_SIGNALS: 0139 void inputIsValid(bool valid); 0140 0141 private: 0142 class Private; 0143 Private* const d; 0144 }; 0145 0146 #endif // WIDGETHINTFRAME_H