~ubuntu-branches/ubuntu/dapper/psi/dapper

« back to all changes in this revision

Viewing changes to cutestuff/qpassivepopup/qpassivepopup.h

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2004-06-15 00:10:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040615001041-enywb6pcpe4sjsw6
Tags: 0.9.2-1
* New upstream release
* Set KDEDIR for ./configure so kde specific files get installed
* Don't install libpsiwidgets.so. It got installed in /usr/share
  where it doesn't belong. May be included (at a better location)
  later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- c++ -*-
 
2
//Modified KPassivePopup from KDE, original Copyright below
 
3
/*
 
4
 *   Copyright            : (C) 2001-2002 by Richard Moore
 
5
 *   License              : This file is released under the terms of the LGPL, version 2.
 
6
 *   Email                : rich@kde.org
 
7
 */
 
8
 
 
9
#ifndef QPASSIVEPOPUP_H
 
10
#define QPASSIVEPOPUP_H
 
11
 
 
12
#include <qframe.h>
 
13
 
 
14
class QBoxLayout;
 
15
class QTimer;
 
16
class QLabel;
 
17
 
 
18
/**
 
19
 * A dialog-like popup that displays messages without interupting the user.
 
20
 * The simplest uses of QPassivePopup are by using the various @ref message() static
 
21
 * methods. The position the popup appears at depends on the type of the parent window:
 
22
 *
 
23
 * @li Normal Windows: The popup is placed adjacent to the icon of the window.
 
24
 * @li System Tray Windows: The popup is placed adjact to the system tray window itself.
 
25
 * @li Skip Taskbar Windows: The popup is placed adjact to the window
 
26
 *     itself if it is visible, and at the edge of the desktop otherwise.
 
27
 *
 
28
 * The most basic use of QPassivePopup displays a popup containing a piece of text:
 
29
 * <pre>
 
30
 *    QPassivePopup::message( &quot;This is the message&quot;, this );
 
31
 * </pre>
 
32
 * We can create popups with titles and icons too, as this example shows:
 
33
 * <pre>
 
34
 *    QPixmap px;
 
35
 *    px.load( &quot;hi32-app-logtracker.png&quot; );
 
36
 *    QPassivePopup::message( &quot;Some title&quot;, &quot;This is the main text&quot;, px, this );
 
37
 * </pre>
 
38
 * For more control over the popup, you can use the @ref setView(QWidget *) method
 
39
 * to create a custom popup.
 
40
 * <pre>
 
41
 *    QPassivePopup *pop = new QPassivePopup( parent );
 
42
 *
 
43
 *    QVBox *vb = new QVBox( pop );
 
44
 *    (void) new QLabel( &quot;&lt;b>Isn't this great?&lt;/b>&quot;, vb );
 
45
 *
 
46
 *    QHBox *box = new QHBox( vb );
 
47
 *    (void) new QPushButton( &quot;Yes&quot;, box );
 
48
 *    (void) new QPushButton( &quot;No&quot;, box );
 
49
 *
 
50
 *    pop->setView( vb );
 
51
 *    pop->show();
 
52
 * </pre>
 
53
 *
 
54
 * @version $Id: qpassivepopup.h,v 1.2 2003/06/30 17:45:39 mblsha Exp $
 
55
 * @since 3.1
 
56
 * @author Richard Moore, rich@kde.org
 
57
 */
 
58
class QPassivePopup : public QFrame
 
59
{
 
60
    Q_OBJECT
 
61
 
 
62
public:
 
63
    /**
 
64
     * Creates a popup for the specified widget.
 
65
     */
 
66
    QPassivePopup( QWidget *parent, const char *name=0, WFlags f=0 );
 
67
    QPassivePopup( const char *name=0, WFlags f=0 );
 
68
 
 
69
    /**
 
70
     * Creates a popup for the specified window.
 
71
     */
 
72
    QPassivePopup( WId parent, const char *name=0, WFlags f=0 );
 
73
 
 
74
    /**
 
75
     * Cleans up.
 
76
     */
 
77
    virtual ~QPassivePopup();
 
78
 
 
79
    /**
 
80
     * Sets the main view to be the specified widget (which must be a child of the popup).
 
81
     */
 
82
    void setView( QWidget *child );
 
83
 
 
84
    /**
 
85
     * Creates a standard view then calls @ref #setView(QWidget*) .
 
86
     */
 
87
    void setView( const QString &caption, const QString &text = QString::null );
 
88
 
 
89
    /**
 
90
     * Creates a standard view then calls @ref #setView(QWidget*) .
 
91
     */
 
92
    virtual void setView( const QString &caption, const QString &text, const QPixmap &icon );
 
93
 
 
94
    /**
 
95
     * Returns the main view.
 
96
     */
 
97
    QWidget *view() const { return msgView; }
 
98
 
 
99
    /**
 
100
     * Returns the delay before the popup is removed automatically.
 
101
     */
 
102
    int timeout() const { return hideDelay; }
 
103
 
 
104
    /**
 
105
     * Enables / disables auto-deletion of this widget when the #timeout
 
106
     * occurs.
 
107
     * The default is false. If you use the class-methods message(),
 
108
     * auto-delection is turned on by default.
 
109
     */
 
110
    virtual void setAutoDelete( bool autoDelete );
 
111
 
 
112
    /**
 
113
     * @returns true if the widget auto-deletes itself when the #timeout occurs.
 
114
     * @see #setAutoDelete
 
115
     */
 
116
    bool autoDelete() const { return m_autoDelete; }
 
117
 
 
118
    /**
 
119
     * Convenience method that displays popup with the specified  message  beside the
 
120
     * icon of the specified widget.
 
121
     * Note that the returned object is destroyed when it is hidden.
 
122
     * @see #setAutoDelete
 
123
     */
 
124
    static QPassivePopup *message( const QString &text, QWidget *parent, const char *name=0 );
 
125
 
 
126
    /**
 
127
     * Convenience method that displays popup with the specified caption and message
 
128
     * beside the icon of the specified widget.
 
129
     * Note that the returned object is destroyed when it is hidden.
 
130
     * @see #setAutoDelete
 
131
     */
 
132
    static QPassivePopup *message( const QString &caption, const QString &text,
 
133
                                   QWidget *parent, const char *name=0 );
 
134
 
 
135
    /**
 
136
     * Convenience method that displays popup with the specified icon, caption and
 
137
     * message beside the icon of the specified widget.
 
138
     * Note that the returned object is destroyed when it is hidden.
 
139
     * @see #setAutoDelete
 
140
     */
 
141
    static QPassivePopup *message( const QString &caption, const QString &text,
 
142
                                   const QPixmap &icon,
 
143
                                   QWidget *parent, const char *name=0, int timeout = -1 );
 
144
 
 
145
    /**
 
146
     * Convenience method that displays popup with the specified icon, caption and
 
147
     * message beside the icon of the specified window.
 
148
     * Note that the returned object is destroyed when it is hidden.
 
149
     * @see #setAutoDelete
 
150
     */
 
151
    static QPassivePopup *message( const QString &caption, const QString &text,
 
152
                                   const QPixmap &icon,
 
153
                                   WId parent, const char *name=0, int timeout = -1 );
 
154
 
 
155
    /**
 
156
     * Returns a QString broken with <br> tags around every size chars
 
157
     * of caption
 
158
     */
 
159
    static QString *splitMessage(QString caption, uint splitsize, uint maxsize);
 
160
    
 
161
public slots:
 
162
    /**
 
163
     * Sets the delay for the popup is removed automatically. Setting the delay to 0
 
164
     * disables the #timeout, if you're doing this, you may want to connect the
 
165
     * @ref clicked() signal to the hide() slot.
 
166
         * Setting the delay to -1 makes it use the default value.
 
167
     */
 
168
    void setTimeout( int delay );
 
169
 
 
170
    /**
 
171
     * Reimplemented to reposition the popup.
 
172
     */
 
173
    virtual void show();
 
174
 
 
175
signals:
 
176
    /**
 
177
     * Emitted when the popup is clicked.
 
178
     */
 
179
    void clicked();
 
180
 
 
181
    /**
 
182
     * Emitted when the popup is clicked.
 
183
     */
 
184
    void clicked( QPoint pos );
 
185
 
 
186
protected:
 
187
    /**
 
188
     * This method positions the popup.
 
189
     */
 
190
    virtual void positionSelf();
 
191
 
 
192
    /**
 
193
     * Reimplemented to destroy the object when @ref autoDelete() is
 
194
     * enabled.
 
195
     */
 
196
    virtual void hideEvent( QHideEvent * );
 
197
 
 
198
    /**
 
199
     * Moves the popup to be adjacent to the icon of the specified rectangle.
 
200
     */
 
201
    void moveNear( QRect target );
 
202
 
 
203
    /**
 
204
     * Reimplemented to detect mouse clicks.
 
205
     */
 
206
    virtual void mouseReleaseEvent( QMouseEvent *e );
 
207
 
 
208
private:
 
209
    void init();
 
210
 
 
211
    WId window;
 
212
    QWidget *msgView;
 
213
    QBoxLayout *layout;
 
214
    int hideDelay;
 
215
    QTimer *hideTimer;
 
216
 
 
217
    QLabel *ttlIcon;
 
218
    QLabel *ttl;
 
219
    QLabel *msg;
 
220
 
 
221
    bool m_autoDelete;
 
222
 
 
223
    void updateMask();
 
224
 
 
225
    /* @internal */
 
226
    class Private *d;
 
227
};
 
228
 
 
229
#endif // QPASSIVEPOPUP_H
 
230