2013-05-18 00:58:49 +00:00
|
|
|
/* This file is part of the KDE libraries
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011 Aurélien Gâteau <agateau@kde.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301 USA
|
|
|
|
*/
|
|
|
|
#ifndef KMESSAGEWIDGET_H
|
|
|
|
#define KMESSAGEWIDGET_H
|
|
|
|
|
|
|
|
#include <QFrame>
|
|
|
|
|
|
|
|
class KMessageWidgetPrivate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @short A widget to provide feedback or propose opportunistic interactions.
|
|
|
|
*
|
|
|
|
* KMessageWidget can be used to provide inline positive or negative
|
|
|
|
* feedback, or to implement opportunistic interactions.
|
|
|
|
*
|
|
|
|
* As a feedback widget, KMessageWidget provides a less intrusive alternative
|
|
|
|
* to "OK Only" message boxes. If you do not need the modalness of KMessageBox,
|
|
|
|
* consider using KMessageWidget instead.
|
|
|
|
*
|
|
|
|
* <b>Negative feedback</b>
|
|
|
|
*
|
|
|
|
* The KMessageWidget can be used as a secondary indicator of failure: the
|
|
|
|
* first indicator is usually the fact the action the user expected to happen
|
|
|
|
* did not happen.
|
|
|
|
*
|
|
|
|
* Example: User fills a form, clicks "Submit".
|
|
|
|
*
|
|
|
|
* @li Expected feedback: form closes
|
|
|
|
* @li First indicator of failure: form stays there
|
|
|
|
* @li Second indicator of failure: a KMessageWidget appears on top of the
|
|
|
|
* form, explaining the error condition
|
|
|
|
*
|
|
|
|
* When used to provide negative feedback, KMessageWidget should be placed
|
|
|
|
* close to its context. In the case of a form, it should appear on top of the
|
|
|
|
* form entries.
|
|
|
|
*
|
|
|
|
* KMessageWidget should get inserted in the existing layout. Space should not
|
|
|
|
* be reserved for it, otherwise it becomes "dead space", ignored by the user.
|
|
|
|
* KMessageWidget should also not appear as an overlay to prevent blocking
|
|
|
|
* access to elements the user needs to interact with to fix the failure.
|
|
|
|
*
|
|
|
|
* <b>Positive feedback</b>
|
|
|
|
*
|
|
|
|
* KMessageWidget can be used for positive feedback but it shouldn't be
|
|
|
|
* overused. It is often enough to provide feedback by simply showing the
|
|
|
|
* results of an action.
|
|
|
|
*
|
|
|
|
* Examples of acceptable uses:
|
|
|
|
*
|
|
|
|
* @li Confirm success of "critical" transactions
|
|
|
|
* @li Indicate completion of background tasks
|
|
|
|
*
|
|
|
|
* Example of inadapted uses:
|
|
|
|
*
|
|
|
|
* @li Indicate successful saving of a file
|
|
|
|
* @li Indicate a file has been successfully removed
|
|
|
|
*
|
|
|
|
* <b>Opportunistic interaction</b>
|
|
|
|
*
|
|
|
|
* Opportunistic interaction is the situation where the application suggests to
|
|
|
|
* the user an action he could be interested in perform, either based on an
|
|
|
|
* action the user just triggered or an event which the application noticed.
|
|
|
|
*
|
|
|
|
* Example of acceptable uses:
|
|
|
|
*
|
|
|
|
* @li A browser can propose remembering a recently entered password
|
|
|
|
* @li A music collection can propose ripping a CD which just got inserted
|
|
|
|
* @li A chat application may notify the user a "special friend" just connected
|
|
|
|
*
|
|
|
|
* @author Aurélien Gâteau <agateau@kde.org>
|
|
|
|
* @since 4.7
|
|
|
|
*/
|
2014-02-28 04:09:57 +00:00
|
|
|
class KMessageWidget : public QFrame {
|
|
|
|
Q_OBJECT
|
|
|
|
Q_ENUMS(MessageType)
|
|
|
|
|
|
|
|
Q_PROPERTY(QString text READ text WRITE setText)
|
|
|
|
Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
|
|
|
|
Q_PROPERTY(bool closeButtonVisible READ isCloseButtonVisible WRITE setCloseButtonVisible)
|
|
|
|
Q_PROPERTY(MessageType messageType READ messageType WRITE setMessageType)
|
|
|
|
Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
|
2013-05-18 00:58:49 +00:00
|
|
|
public:
|
2014-02-28 04:09:57 +00:00
|
|
|
enum MessageType {
|
|
|
|
Positive,
|
|
|
|
Information,
|
|
|
|
Warning,
|
|
|
|
Error
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-03-05 20:19:45 +00:00
|
|
|
* Constructs a KMessageWidget with the specified parent.
|
|
|
|
*/
|
2014-02-28 04:09:57 +00:00
|
|
|
explicit KMessageWidget(QWidget *parent = 0);
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
explicit KMessageWidget(const QString &text, QWidget *parent = 0);
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
~KMessageWidget();
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
QString text() const;
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
bool wordWrap() const;
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
bool isCloseButtonVisible() const;
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
MessageType messageType() const;
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void addAction(QAction *action);
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void removeAction(QAction *action);
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
QSize sizeHint() const;
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
QSize minimumSizeHint() const;
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
int heightForWidth(int width) const;
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
/**
|
2014-03-05 20:19:45 +00:00
|
|
|
* The icon shown on the left of the text. By default, no icon is shown.
|
|
|
|
* @since 4.11
|
|
|
|
*/
|
2014-02-28 04:09:57 +00:00
|
|
|
QIcon icon() const;
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
public
|
|
|
|
Q_SLOTS:
|
|
|
|
void setText(const QString &text);
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void setWordWrap(bool wordWrap);
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void setCloseButtonVisible(bool visible);
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void setMessageType(KMessageWidget::MessageType type);
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
/**
|
2014-03-05 20:19:45 +00:00
|
|
|
* Show the widget using an animation, unless
|
|
|
|
* KGlobalSettings::graphicsEffectLevel() does not allow simple effects.
|
|
|
|
*/
|
2014-02-28 04:09:57 +00:00
|
|
|
void animatedShow();
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
/**
|
2014-03-05 20:19:45 +00:00
|
|
|
* Hide the widget using an animation, unless
|
|
|
|
* KGlobalSettings::graphicsEffectLevel() does not allow simple effects.
|
|
|
|
*/
|
2014-02-28 04:09:57 +00:00
|
|
|
void animatedHide();
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
/**
|
2014-03-05 20:19:45 +00:00
|
|
|
* Define an icon to be shown on the left of the text
|
|
|
|
* @since 4.11
|
|
|
|
*/
|
2014-02-28 04:09:57 +00:00
|
|
|
void setIcon(const QIcon &icon);
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-11-17 01:28:48 +00:00
|
|
|
int bestContentHeight() const;
|
2013-05-18 00:58:49 +00:00
|
|
|
Q_SIGNALS:
|
2014-02-28 04:09:57 +00:00
|
|
|
/**
|
2014-03-05 20:19:45 +00:00
|
|
|
* This signal is emitted when the user clicks a link in the text label.
|
|
|
|
* The URL referred to by the href anchor is passed in contents.
|
|
|
|
* @param contents text of the href anchor
|
|
|
|
* @see QLabel::linkActivated()
|
|
|
|
* @since 4.10
|
|
|
|
*/
|
2014-02-28 04:09:57 +00:00
|
|
|
void linkActivated(const QString &contents);
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
/**
|
2014-03-05 20:19:45 +00:00
|
|
|
* This signal is emitted when the user hovers over a link in the text label.
|
|
|
|
* The URL referred to by the href anchor is passed in contents.
|
|
|
|
* @param contents text of the href anchor
|
|
|
|
* @see QLabel::linkHovered()
|
|
|
|
* @since 4.11
|
|
|
|
*/
|
2014-02-28 04:09:57 +00:00
|
|
|
void linkHovered(const QString &contents);
|
2013-05-18 00:58:49 +00:00
|
|
|
|
|
|
|
protected:
|
2014-02-28 04:09:57 +00:00
|
|
|
void paintEvent(QPaintEvent *event);
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
bool event(QEvent *event);
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void resizeEvent(QResizeEvent *event);
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void showEvent(QShowEvent *event);
|
2013-05-18 00:58:49 +00:00
|
|
|
|
|
|
|
private:
|
2014-02-28 04:09:57 +00:00
|
|
|
KMessageWidgetPrivate *const d;
|
|
|
|
friend class KMessageWidgetPrivate;
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
Q_PRIVATE_SLOT(d, void slotTimeLineChanged(qreal))
|
|
|
|
Q_PRIVATE_SLOT(d, void slotTimeLineFinished())
|
2013-05-18 00:58:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
// KMessageWidgetPrivate
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
class QLabel;
|
|
|
|
class QToolButton;
|
|
|
|
class QTimeLine;
|
|
|
|
#include <QIcon>
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
class KMessageWidgetPrivate {
|
2013-05-18 00:58:49 +00:00
|
|
|
public:
|
2014-02-28 04:09:57 +00:00
|
|
|
void init(KMessageWidget *);
|
|
|
|
|
|
|
|
KMessageWidget *q;
|
|
|
|
QFrame *content;
|
|
|
|
QLabel *iconLabel;
|
|
|
|
QLabel *textLabel;
|
|
|
|
QToolButton *closeButton;
|
|
|
|
QTimeLine *timeLine;
|
2013-05-18 00:58:49 +00:00
|
|
|
QIcon icon;
|
|
|
|
|
|
|
|
KMessageWidget::MessageType messageType;
|
|
|
|
bool wordWrap;
|
2014-02-28 04:09:57 +00:00
|
|
|
QList<QToolButton *> buttons;
|
2013-05-18 00:58:49 +00:00
|
|
|
QPixmap contentSnapShot;
|
|
|
|
|
|
|
|
void createLayout();
|
|
|
|
void updateSnapShot();
|
|
|
|
void updateLayout();
|
|
|
|
void slotTimeLineChanged(qreal);
|
|
|
|
void slotTimeLineFinished();
|
|
|
|
|
|
|
|
int bestContentHeight() const;
|
|
|
|
};
|
|
|
|
|
2014-02-11 18:14:46 +00:00
|
|
|
#endif // KMESSAGEWIDGET_H
|