fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / kdeui / util / kpassivepopup.h
blob474c9fcb7e7a39a311324f460f8da868cdd77a4e
1 // -*- c++ -*-
3 /*
4 * Copyright : (C) 2001-2006 by Richard Moore
5 * Copyright : (C) 2004-2005 by Sascha Cunz
6 * License : This file is released under the terms of the LGPL, version 2.
7 * Email : rich@kde.org
8 * Email : sascha.cunz@tiscali.de
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #ifndef KPASSIVEPOPUP_H
26 #define KPASSIVEPOPUP_H
28 #include <kdeui_export.h>
30 #include <QtGui/QFrame>
32 class KVBox;
33 class QSystemTrayIcon;
35 /**
36 * @short A dialog-like popup that displays messages without interrupting the user.
38 * The simplest uses of KPassivePopup are by using the various message() static
39 * methods. The position the popup appears at depends on the type of the parent window:
41 * @li Normal Windows: The popup is placed adjacent to the icon of the window.
42 * @li System Tray Windows: The popup is placed adjact to the system tray window itself.
43 * @li Skip Taskbar Windows: The popup is placed adjact to the window
44 * itself if it is visible, and at the edge of the desktop otherwise.
46 * You also have the option of calling show with a QPoint as a parameter that
47 * removes the automatic placing of KPassivePopup and shows it in the point you want.
49 * The most basic use of KPassivePopup displays a popup containing a piece of text:
50 * \code
51 * KPassivePopup::message( "This is the message", this );
52 * \endcode
53 * We can create popups with titles and icons too, as this example shows:
54 * \code
55 * QPixmap px;
56 * px.load( "hi32-app-logtracker.png" );
57 * KPassivePopup::message( "Some title", "This is the main text", px, this );
58 * \endcode
59 * This screenshot shows a popup with both a caption and a main text which is
60 * being displayed next to the toolbar icon of the window that triggered it:
61 * \image html kpassivepopup.png "A passive popup"
63 * For more control over the popup, you can use the setView(QWidget *) method
64 * to create a custom popup.
65 * \code
66 * KPassivePopup *pop = new KPassivePopup( parent );
68 * KVBox *vb = new KVBox( pop );
69 * (void) new QLabel( vb, "<b>Isn't this great?</b>" );
71 * KHBox *box = new KHBox( vb );
72 * (void) new QPushButton( "Yes", box );
73 * (void) new QPushButton( "No", box );
75 * pop->setView( vb );
76 * pop->show();
77 * \endcode
79 * @author Richard Moore, rich@kde.org
80 * @author Sascha Cunz, sascha.cunz@tiscali.de
82 class KDEUI_EXPORT KPassivePopup : public QFrame
84 Q_OBJECT
85 Q_PROPERTY (bool autoDelete READ autoDelete WRITE setAutoDelete )
86 Q_PROPERTY (int timeout READ timeout WRITE setTimeout )
87 Q_PROPERTY (QRect defaultArea READ defaultArea )
89 public:
90 /**
91 * Styles that a KPassivePopup can have.
93 enum PopupStyle
95 Boxed, ///< Information will appear in a framed box (default)
96 Balloon, ///< Information will appear in a comic-alike balloon
97 CustomStyle=128 ///< Ids greater than this are reserved for use by subclasses
101 * Creates a popup for the specified widget.
103 explicit KPassivePopup( QWidget *parent=0, Qt::WFlags f = 0 );
106 * Creates a popup for the specified window.
108 explicit KPassivePopup( WId parent );
110 #if 0 // These break macos and win32 where the definition of WId makes them ambiguous
112 * Creates a popup for the specified widget.
113 * THIS WILL BE REMOVED, USE setPopupStyle().
115 explicit KPassivePopup( int popupStyle, QWidget *parent=0, Qt::WFlags f=0 ) KDE_DEPRECATED;
118 * Creates a popup for the specified window.
119 * THIS WILL BE REMOVED, USE setPopupStyle().
121 KPassivePopup( int popupStyle, WId parent, Qt::WFlags f=0 ) KDE_DEPRECATED;
122 #endif
125 * Cleans up.
127 virtual ~KPassivePopup();
130 * Sets the main view to be the specified widget (which must be a child of the popup).
132 void setView( QWidget *child );
135 * Creates a standard view then calls setView(QWidget*) .
137 void setView( const QString &caption, const QString &text = QString() );
140 * Creates a standard view then calls setView(QWidget*) .
142 virtual void setView( const QString &caption, const QString &text, const QPixmap &icon );
145 * Returns a widget that is used as standard view if one of the
146 * setView() methods taking the QString arguments is used.
147 * You can use the returned widget to customize the passivepopup while
148 * keeping the look similar to the "standard" passivepopups.
150 * After customizing the widget, pass it to setView( QWidget* )
152 * @param caption The window caption (title) on the popup
153 * @param text The text for the popup
154 * @param icon The icon to use for the popup
155 * @param parent The parent widget used for the returned KVBox. If left 0L,
156 * then "this", i.e. the passive popup object will be used.
158 * @return a KVBox containing the given arguments, looking like the
159 * standard passivepopups.
160 * @see setView( QWidget * )
161 * @see setView( const QString&, const QString& )
162 * @see setView( const QString&, const QString&, const QPixmap& )
164 KVBox * standardView( const QString& caption, const QString& text,
165 const QPixmap& icon, QWidget *parent = 0L );
168 * Returns the main view.
170 QWidget *view() const;
173 * Returns the delay before the popup is removed automatically.
175 int timeout() const;
178 * Enables / disables auto-deletion of this widget when the timeout
179 * occurs.
180 * The default is false. If you use the class-methods message(),
181 * auto-deletion is turned on by default.
183 virtual void setAutoDelete( bool autoDelete );
186 * @returns true if the widget auto-deletes itself when the timeout occurs.
187 * @see setAutoDelete
189 bool autoDelete() const;
192 * If no relative window (eg taskbar button, system tray window) is
193 * available, use this rectangle (pass it to moveNear()).
194 * Basically KWindowSystem::workArea() with width and height set to 0
195 * so that moveNear uses the upper-left position.
196 * @return The QRect to be passed to moveNear() if no other is
197 * available.
199 QRect defaultArea() const;
202 * Returns the position to which this popup is anchored.
204 QPoint anchor() const;
207 * Sets the anchor of this popup. The popup tries automatically to adjust
208 * itself somehow around the point.
210 void setAnchor( const QPoint& anchor );
212 // TODO KDE4: give all the static methods a const QPoint p = QPoint() that in
213 // case the point is not null calls the show(const QPoint &p) method instead
214 // of the show() one.
216 * Convenience method that displays popup with the specified message beside the
217 * icon of the specified widget.
218 * Note that the returned object is destroyed when it is hidden.
219 * @see setAutoDelete
221 static KPassivePopup *message( const QString &text, QWidget *parent );
224 * Convenience method that displays popup with the specified message beside the
225 * icon of the specified QSystemTrayIcon.
226 * Note that the returned object is destroyed when it is hidden.
227 * @see setAutoDelete
229 static KPassivePopup *message( const QString &text, QSystemTrayIcon *parent );
232 * Convenience method that displays popup with the specified caption and message
233 * beside the icon of the specified widget.
234 * Note that the returned object is destroyed when it is hidden.
235 * @see setAutoDelete
237 static KPassivePopup *message( const QString &caption, const QString &text,
238 QWidget *parent );
241 * Convenience method that displays popup with the specified caption and message
242 * beside the icon of the specified QSystemTrayIcon.
243 * Note that the returned object is destroyed when it is hidden.
244 * @see setAutoDelete
246 static KPassivePopup *message( const QString &caption, const QString &text,
247 QSystemTrayIcon *parent );
250 * Convenience method that displays popup with the specified icon, caption and
251 * message beside the icon of the specified widget.
252 * Note that the returned object is destroyed when it is hidden.
253 * @see setAutoDelete
255 static KPassivePopup *message( const QString &caption, const QString &text,
256 const QPixmap &icon,
257 QWidget *parent, int timeout = -1 );
260 * Convenience method that displays popup with the specified icon, caption and
261 * message beside the icon of the specified QSystemTrayIcon.
262 * Note that the returned object is destroyed when it is hidden.
263 * @see setAutoDelete
265 static KPassivePopup *message( const QString &caption, const QString &text,
266 const QPixmap &icon,
267 QSystemTrayIcon *parent, int timeout = -1 );
270 * Convenience method that displays popup with the specified icon, caption and
271 * message beside the icon of the specified window.
272 * Note that the returned object is destroyed when it is hidden.
273 * @see setAutoDelete
275 static KPassivePopup *message( const QString &caption, const QString &text,
276 const QPixmap &icon,
277 WId parent, int timeout = -1 );
280 * Convenience method that displays popup with the specified popup-style and message beside the
281 * icon of the specified widget.
282 * Note that the returned object is destroyed when it is hidden.
283 * @see setAutoDelete
285 static KPassivePopup *message( int popupStyle, const QString &text, QWidget *parent );
288 * Convenience method that displays popup with the specified popup-style and message beside the
289 * icon of the specified QSystemTrayIcon.
290 * Note that the returned object is destroyed when it is hidden.
291 * @see setAutoDelete
293 static KPassivePopup *message( int popupStyle, const QString &text, QSystemTrayIcon *parent );
296 * Convenience method that displays popup with the specified popup-style, caption and message
297 * beside the icon of the specified QSystemTrayIcon.
298 * Note that the returned object is destroyed when it is hidden.
299 * @see setAutoDelete
301 static KPassivePopup *message( int popupStyle, const QString &caption, const QString &text,
302 QSystemTrayIcon *parent );
305 * Convenience method that displays popup with the specified popup-style, caption and message
306 * beside the icon of the specified widget.
307 * Note that the returned object is destroyed when it is hidden.
308 * @see setAutoDelete
310 static KPassivePopup *message( int popupStyle, const QString &caption, const QString &text,
311 QWidget *parent );
314 * Convenience method that displays popup with the specified popup-style, icon, caption and
315 * message beside the icon of the specified widget.
316 * Note that the returned object is destroyed when it is hidden.
317 * @see setAutoDelete
319 static KPassivePopup *message( int popupStyle, const QString &caption, const QString &text,
320 const QPixmap &icon,
321 QWidget *parent, int timeout = -1 );
324 * Convenience method that displays popup with the specified popup-style, icon, caption and
325 * message beside the icon of the specified QSystemTrayIcon.
326 * Note that the returned object is destroyed when it is hidden.
327 * @see setAutoDelete
329 static KPassivePopup *message( int popupStyle, const QString &caption, const QString &text,
330 const QPixmap &icon,
331 QSystemTrayIcon *parent, int timeout = -1 );
334 * Convenience method that displays popup with the specified popup-style, icon, caption and
335 * message beside the icon of the specified window.
336 * Note that the returned object is destroyed when it is hidden.
337 * @see setAutoDelete
339 static KPassivePopup *message( int popupStyle, const QString &caption, const QString &text,
340 const QPixmap &icon,
341 WId parent, int timeout = -1 );
344 public Q_SLOTS:
346 * Sets the delay for the popup is removed automatically. Setting the delay to 0
347 * disables the timeout, if you're doing this, you may want to connect the
348 * clicked() signal to the hide() slot.
349 * Setting the delay to -1 makes it use the default value.
351 * @see timeout
353 void setTimeout( int delay );
356 * Sets the visual appearance of the popup.
357 * @see PopupStyle
359 void setPopupStyle( int popupstyle );
362 * Reimplemented to reposition the popup.
364 void show();
367 * Shows the popup in the given point
369 void show(const QPoint &p);
371 virtual void setVisible(bool visible);
373 Q_SIGNALS:
375 * Emitted when the popup is clicked.
377 void clicked();
380 * Emitted when the popup is clicked.
382 void clicked( const QPoint &pos );
384 protected:
386 * This method positions the popup.
388 virtual void positionSelf();
391 * Reimplemented to destroy the object when autoDelete() is
392 * enabled.
394 virtual void hideEvent( QHideEvent * );
397 * Moves the popup to be adjacent to the icon of the specified rectangle.
399 void moveNear( const QRect &target );
402 * Calculates the position to place the popup near the specified rectangle.
404 QPoint calculateNearbyPoint( const QRect &target);
407 * Reimplemented to detect mouse clicks.
409 virtual void mouseReleaseEvent( QMouseEvent *e );
412 * Updates the transparency mask. Unused if PopupStyle == Boxed
414 void updateMask();
417 * Overwrite to paint the border when PopupStyle == Balloon.
418 * Unused if PopupStyle == Boxed
420 virtual void paintEvent( QPaintEvent* pe );
422 private:
423 void init( WId window );
425 /* @internal */
426 class Private;
427 Private *const d;
430 #endif // KPASSIVEPOPUP_H
432 // Local Variables:
433 // c-basic-offset: 4
434 // End: