| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2022 Abdullah Tahiri <[email protected]> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
#ifndef GUI_NOTIFICATIONAREA_H |
| 24 |
#define GUI_NOTIFICATIONAREA_H |
| 25 |
|
| 26 |
#include <QPushButton> |
| 27 |
#include <QString> |
| 28 |
|
| 29 |
#include <map> |
| 30 |
#include <memory> |
| 31 |
|
| 32 |
#include <Base/Observer.h> |
| 33 |
#include <Base/Parameter.h> |
| 34 |
|
| 35 |
namespace App |
| 36 |
{ |
| 37 |
class Document; |
| 38 |
} |
| 39 |
|
| 40 |
namespace Gui |
| 41 |
{ |
| 42 |
|
| 43 |
struct NotificationAreaP; |
| 44 |
|
| 45 |
class NotificationArea: public QPushButton |
| 46 |
{ |
| 47 |
enum class TrayIcon |
| 48 |
{ |
| 49 |
Normal, |
| 50 |
MissedNotifications, |
| 51 |
}; |
| 52 |
|
| 53 |
public: |
| 54 |
class ParameterObserver: public ParameterGrp::ObserverType |
| 55 |
{ |
| 56 |
public: |
| 57 |
explicit ParameterObserver(NotificationArea* notificationarea); |
| 58 |
~ParameterObserver() override; |
| 59 |
|
| 60 |
void OnChange(Base::Subject<const char*>& rCaller, const char* sReason) override; |
| 61 |
|
| 62 |
private: |
| 63 |
NotificationArea* notificationArea; |
| 64 |
ParameterGrp::handle hGrp; |
| 65 |
std::map<std::string, std::function<void(const std::string& string)>> parameterMap; |
| 66 |
}; |
| 67 |
|
| 68 |
NotificationArea(QWidget* parent = nullptr); |
| 69 |
~NotificationArea() override; |
| 70 |
|
| 71 |
void pushNotification(const QString& notifiername, const QString& message, Base::LogStyle level); |
| 72 |
|
| 73 |
bool areDeveloperWarningsActive() const; |
| 74 |
bool areDeveloperErrorsActive() const; |
| 75 |
|
| 76 |
private: |
| 77 |
void showInNotificationArea(); |
| 78 |
bool confirmationRequired(Base::LogStyle level); |
| 79 |
void showConfirmationDialog(const QString& notifiername, const QString& message); |
| 80 |
void slotRestoreFinished(const App::Document&); |
| 81 |
|
| 82 |
void mousePressEvent(QMouseEvent* e) override; |
| 83 |
|
| 84 |
void setIcon(TrayIcon trayIcon); |
| 85 |
|
| 86 |
private: |
| 87 |
std::unique_ptr<NotificationAreaP> pImp; |
| 88 |
}; |
| 89 |
|
| 90 |
|
| 91 |
} // namespace Gui |
| 92 |
|
| 93 |
#endif // GUI_NOTIFICATIONAREA_H |