File: pQueuedMessageWidget.h

package info (click to toggle)
monkeystudio 1.9.0.4%2Bgit20161218-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 41,500 kB
  • ctags: 22,118
  • sloc: cpp: 144,671; ansic: 33,969; python: 2,922; makefile: 127; sh: 122; php: 73; cs: 69
file content (126 lines) | stat: -rw-r--r-- 4,686 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/****************************************************************************
    Copyright (C) 2005 - 2011  Filipe AZEVEDO & The Monkey Studio Team
    http://monkeystudio.org licensing under the GNU GPL.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
****************************************************************************/
/*!
    \file pQueuedMessageWidget.h
    \date 2008-05-01T00:00:00
    \author Filipe AZEVEDO aka Nox P\@sNox <pasnox@gmail.com>
    \brief A QMessageBox like Widget, that can show queued message.
*/
#ifndef PQUEUEDMESSAGEWIDGET_H
#define PQUEUEDMESSAGEWIDGET_H

#include "../objects/MonkeyExport.h"

#include <QWidget>
#include <QHash>
#include <QDialogButtonBox>
#include <QPointer>
#include <QVariant>

class QLabel;
class QDialogButtonBox;

/*!
    \brief The is the \c message structure used by the pQueuedMessageWidget class.
    \details It allow to configure the message to show.
    \details Each variable is directly accessible and mostly optionnal except \c Message.
    \details A default \c Ok button is added if \c Buttons is empty.
*/
struct Q_MONKEY_EXPORT pQueuedMessage
{
    pQueuedMessage()
    {
        MilliSeconds = 0;
        Object = 0;
        Slot = 0;
    }
    
    bool operator==( const pQueuedMessage& o ) const
    {
        return Message == o.Message && MilliSeconds == o.MilliSeconds &&
            ( Pixmap.cacheKey() == o.Pixmap.cacheKey() || ( Pixmap.isNull() && o.Pixmap.isNull() ) ) &&
            Background == o.Background && Foreground == o.Foreground && Buttons == o.Buttons &&
            Object == o.Object && Slot == o.Slot && UserData == o.UserData;
    }
    
    /*! \details The message to show */
    QString Message;
    /*! \details The millisecond time to wait before the message is auto closed. Use 0 for unilimited time */
    int MilliSeconds;
    /*! \details The pixmap to show before the message */
    QPixmap Pixmap;
    /*! \details The brush to use as background */
    QBrush Background;
    /*! \details The brush to use as foreground */
    QBrush Foreground;
    /*! \details A hash representing a StandardButton role, and it's optionnal text overridding the default StandardButton text */
    QHash<QDialogButtonBox::StandardButton, QString> Buttons; // StandardButton, Button Text ( empty for standard )
    /*! \details The object that is used to invoke \c Slot */
    QPointer<QObject> Object;
    /*!
        \details If \c Object is not null, it will invoke this \c Slot, the slot must take 2 parameters :
        \details QDialogButtonBox::StandardButton : The StandardButton clicked and
        \details pQueuedMessage : The message from where the button was clicked
    */
    const char* Slot;
    /*! \details A place to stock custom user data */
    QVariant UserData;
};

/*!
    \brief A QMessageBox like Widget, that can show queued message.
    \details The messages are queued until they are closed by user or elapsed time is timeout
*/
class Q_MONKEY_EXPORT pQueuedMessageWidget : public QWidget
{
    Q_OBJECT
    
public:
    pQueuedMessageWidget( QWidget* parent = 0 );
    
    int messagesCount() const;
    pQueuedMessage currentMessage() const;

protected:
    QHash<int,pQueuedMessage> mMessages;
    static int pQueuedMessageUniqueId;
    QLabel* lPixmap;
    QLabel* lMessage;
    QDialogButtonBox* dbbButtons;

public slots:
    int append( const pQueuedMessage& message );
    int append( const QString& message, int milliseconds = 0, const QPixmap& pixmap = QPixmap(), const QBrush& background = QBrush( QColor( 255, 0, 0, 20 ) ), const QBrush& foreground = QBrush() );
    void remove( const pQueuedMessage& message );
    void remove( int id );
    void clear();

protected slots:
    void clicked( QAbstractButton* button );
    void showMessage();
    void closeMessage();

signals:
    void messageShown( const pQueuedMessage& message );
    void messageClosed( const pQueuedMessage& message );
    void cleared();
    void finished();
};

#endif // PQUEUEDMESSAGEWIDGET_H