Gui: NotificationBox - New non-intrusive auto-closing notification box

======================================================================

In short, a "tooltip" alike notification, where the user can continue working without having
to interact with the notification. If the user is interested in the notification, he or she can
stop to read it. If not interested, the user can ignore it and continue working. The notification
will automatically disappear when the timer lapses or before that time, as described below.

A new widget similar to QToolTip, to have a similar look and feel
and interface, while avoiding early closing on user action.

QToolTip is not intended for notifications, but to provide contextual help. While
QToolTip could have been used for part of the functionality (by filtering out events),
other parts required additional changes to the interface

Gui::NotificationBox is a reimplementation intended to provide user notifications. It
relies on the proven code of QToolTip for the wanted behaviour.

Additional functionality:
- A notification box has a minimum time for which it won't close, unless popped out (click inside
the notification).
- After the minimum time, if left mouse button is clicked (anywhere) it auto-closes, as it is
understood the user has continued working.
- After a maximum time, it will automatically close (even in nothing is clicked).
This commit is contained in:
Abdullah Tahiri
2023-02-02 14:26:50 +01:00
committed by abdullahtahiriyo
parent 6d4a90c605
commit 8925399dbb
3 changed files with 429 additions and 0 deletions

75
src/Gui/NotificationBox.h Normal file
View File

@@ -0,0 +1,75 @@
/***************************************************************************
* Copyright (c) 2023 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com > *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 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 Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef GUI_NOTIFICATIONBOX_H
#define GUI_NOTIFICATIONBOX_H
namespace Gui {
/** This class provides a non-intrusive tip alike notification
* dialog, which unlike QToolTip, is kept shown during a time.
*
* The notification is shown during minShowTime, unless pop out
* (i.e. clicked inside the notification).
*
* The notification will show up to a maximum of msecShowTime. The
* only event that closes the notification between minShowTime and
* msecShowTime is a mouse button click (anywhere of the screen).
*
* When msecShowTime is not provided, it is calculated based on the length
* of the text.
*
* This class interface and its implementation are based on QT's
* QToolTip.
*/
class NotificationBox
{
NotificationBox() = delete;
public:
/** Shows a non-intrusive notification.
* @param pos Position at which the notification will be shown
* @param msecShowTime Time after which the notification will auto-close (unless it is closed by an event, see class documentation above)
* @param minShowTime Time during which the notification can only be made disappear by popping it out (clicking inside it).
*/
static void showText(const QPoint &pos, const QString &text, int msecShowTime = -1, unsigned int minShowTime = 0);
/// Hides a notification.
static inline void hideText() { showText(QPoint(), QString()); }
/// Returns whether a notification is being shown or not.
static bool isVisible();
/// Returns the text of the notification.
static QString text();
/// Returns the palette.
static QPalette palette();
/// Sets the palette.
static void setPalette(const QPalette &);
/// Returns the font of the notification.
static QFont font();
/// Sets the font to be used in the notification.
static void setFont(const QFont &);
};
} // namespace Gui
#endif // GUI_NOTIFICATIONBOX_H