File indexing completed on 2024-05-19 12:54:44
0001 /* This file is part of the KDE libraries 0002 * 0003 * Copyright (c) 2011 Aurélien Gâteau <agateau@kde.org> 0004 * Copyright (C) 2011-2012 Jarosław Staniek <staniek@kde.org> 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Lesser General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2.1 of the License, or (at your option) any later version. 0010 * 0011 * This library 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 GNU 0014 * Lesser General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Lesser General Public 0017 * License along with this library; if not, write to the Free Software 0018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0019 * 02110-1301 USA 0020 */ 0021 #ifndef KMESSAGEWIDGET_H 0022 #define KMESSAGEWIDGET_H 0023 0024 #include "kexiutils_export.h" 0025 0026 #include <QFrame> 0027 0028 class KMessageWidgetPrivate; 0029 0030 /** 0031 * @short A widget to provide feedback or propose opportunistic interactions. 0032 * 0033 * KMessageWidget can be used to provide inline positive or negative 0034 * feedback, or to implement opportunistic interactions. 0035 * 0036 * As a feedback widget, KMessageWidget provides a less intrusive alternative 0037 * to "OK Only" message boxes. If you do not need the modalness of KMessageBox, 0038 * consider using KMessageWidget instead. 0039 * 0040 * <b>Negative feedback</b> 0041 * 0042 * The KMessageWidget can be used as a secondary indicator of failure: the 0043 * first indicator is usually the fact the action the user expected to happen 0044 * did not happen. 0045 * 0046 * Example: User fills a form, clicks "Submit". 0047 * 0048 * @li Expected feedback: form closes 0049 * @li First indicator of failure: form stays there 0050 * @li Second indicator of failure: a KMessageWidget appears on top of the 0051 * form, explaining the error condition 0052 * 0053 * When used to provide negative feedback, KMessageWidget should be placed 0054 * close to its context. In the case of a form, it should appear on top of the 0055 * form entries. 0056 * 0057 * KMessageWidget should get inserted in the existing layout. Space should not 0058 * be reserved for it, otherwise it becomes "dead space", ignored by the user. 0059 * KMessageWidget should also not appear as an overlay to prevent blocking 0060 * access to elements the user needs to interact with to fix the failure. 0061 * 0062 * <b>Positive feedback</b> 0063 * 0064 * KMessageWidget can be used for positive feedback but it shouldn't be 0065 * overused. It is often enough to provide feedback by simply showing the 0066 * results of an action. 0067 * 0068 * Examples of acceptable uses: 0069 * 0070 * @li Confirm success of "critical" transactions 0071 * @li Indicate completion of background tasks 0072 * 0073 * Example of inadapted uses: 0074 * 0075 * @li Indicate successful saving of a file 0076 * @li Indicate a file has been successfully removed 0077 * 0078 * <b>Opportunistic interaction</b> 0079 * 0080 * Opportunistic interaction is the situation where the application suggests to 0081 * the user an action they could be interested in perform, either based on an 0082 * action the user just triggered or an event which the application noticed. 0083 * 0084 * Example of acceptable uses: 0085 * 0086 * @li A browser can propose remembering a recently entered password 0087 * @li A music collection can propose ripping a CD which just got inserted 0088 * @li A chat application may notify the user a "special friend" just connected 0089 */ 0090 class KEXIUTILS_EXPORT KMessageWidget : public QFrame 0091 { 0092 Q_OBJECT 0093 0094 Q_PROPERTY(QString text READ text WRITE setText) 0095 Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap) 0096 Q_PROPERTY(bool closeButtonVisible READ isCloseButtonVisible WRITE setCloseButtonVisible) 0097 Q_PROPERTY(MessageType messageType READ messageType WRITE setMessageType) 0098 public: 0099 enum MessageType { 0100 Positive, 0101 Information, 0102 Warning, 0103 Error 0104 }; 0105 Q_ENUM(MessageType) 0106 0107 enum CalloutPointerDirection { 0108 NoPointer, 0109 Up, 0110 Down, 0111 Left, 0112 Right 0113 }; 0114 Q_ENUM(CalloutPointerDirection) 0115 0116 /** 0117 * Constructs a KMessageWidget with the specified parent. 0118 */ 0119 explicit KMessageWidget(QWidget *parent = 0); 0120 0121 explicit KMessageWidget(const QString &text, QWidget *parent = 0); 0122 0123 KMessageWidget(QWidget *contentsWidget, QWidget *parent); 0124 0125 ~KMessageWidget(); 0126 0127 QString text() const; 0128 0129 bool wordWrap() const; 0130 0131 bool isCloseButtonVisible() const; 0132 0133 bool clickClosesMessage() const; 0134 0135 MessageType messageType() const; 0136 0137 CalloutPointerDirection calloutPointerDirection() const; 0138 0139 void addAction(QAction *action); 0140 0141 void removeAction(QAction *action); 0142 0143 void setDefaultAction(QAction *action); 0144 0145 void setButtonLeftAlignedForAction(QAction *action); 0146 0147 /** 0148 * @brief Sets autodeletion flag to be on or off. 0149 * If autodeletion is on, the widget is automatically 0150 * deleted after hide() or animatedHide() using QObject::deleteLater(). 0151 * Autodeletion is false by default. 0152 */ 0153 void setAutoDelete(bool set); 0154 0155 QSize sizeHint() const override; 0156 0157 QSize minimumSizeHint() const override; 0158 0159 QPoint calloutPointerPosition() const; 0160 0161 public Q_SLOTS: 0162 void setText(const QString &text); 0163 0164 void setWordWrap(bool wordWrap); 0165 0166 void setCloseButtonVisible(bool visible); 0167 0168 void setClickClosesMessage(bool set); 0169 0170 void setMessageType(KMessageWidget::MessageType type); 0171 0172 void setCalloutPointerDirection(KMessageWidget::CalloutPointerDirection direction); 0173 0174 //! Sets global position for callout pointer 0175 void setCalloutPointerPosition(const QPoint& globalPos); 0176 0177 QBrush backgroundBrush() const; 0178 0179 QBrush borderBrush() const; 0180 0181 /** 0182 * Show the widget using an animation, unless 0183 * KexiUtils::graphicsEffectLevel() does not allow simple effects. 0184 */ 0185 void animatedShow(); 0186 0187 /** 0188 * Hide the widget using an animation, unless 0189 * KexiUtils::graphicsEffectLevel() does not allow simple effects. 0190 */ 0191 void animatedHide(); 0192 0193 void resizeToContents(); 0194 0195 Q_SIGNALS: 0196 void animatedShowFinished(); 0197 void animatedHideFinished(); 0198 0199 protected: 0200 virtual void paintEvent(QPaintEvent *event) override; 0201 0202 virtual bool event(QEvent *event) override; 0203 0204 virtual void resizeEvent(QResizeEvent *event) override; 0205 0206 virtual void showEvent(QShowEvent *event) override; 0207 0208 private Q_SLOTS: 0209 void slotTimeLineChanged(qreal value); 0210 void slotTimeLineFinished(); 0211 void tryClickCloseMessage(); 0212 0213 private: 0214 KMessageWidgetPrivate *const d; 0215 friend class KMessageWidgetPrivate; 0216 }; 0217 0218 #endif /* KMESSAGEWIDGET_H */