importantmessageswidget.h
1 //------------------------------------------------------------------------------
2 // importantmessageswidget.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2011 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef __IMPORTANTMESSAGESWIDGET_H__
24 #define __IMPORTANTMESSAGESWIDGET_H__
25 
26 #include "dptr.h"
27 
28 #include <QSharedPointer>
29 #include <QWidget>
30 
31 class QDateTime;
32 class QLabel;
33 class QVBoxLayout;
34 
45 class ImportantMessagesWidget : public QWidget
46 {
47  Q_OBJECT
48 
49 public:
50  class Handler
51  {
52  public:
53  virtual ~Handler() = default;
54  virtual void remove() = 0;
55  };
56  friend class Handler;
57 
58  ImportantMessagesWidget(QWidget *pParent = nullptr);
59  ~ImportantMessagesWidget() override;
60 
65  unsigned maxMessages() const;
66  void setMaxMessages(unsigned num);
67 
68 public slots:
74  QSharedPointer<Handler> addMessage(const QString &message);
75 
86  QSharedPointer<Handler> addMessage(const QString &message, const QDateTime &dateTime);
87 
98  QSharedPointer<Handler> addMessage(const QString &message, unsigned timestamp);
99 
105  void clear();
106 
116  void removeOldest(int num);
117 
121  void removeOneOldest();
122 
123 private:
125 
126  void remove(QLabel *label);
127 
128 private slots:
135  void dropOldWidgetsIfBeyondLimit();
136 };
137 
138 #endif