BuildmLearn Toolkit  2.0.4
BuildmLearn Toolkit is an easy-to-use program that helps users make mobile apps without any knowledge of application development.
 All Classes Functions Enumerations Groups Pages
systemtrayicon.h
1 /*
2  Copyright (c) 2012, BuildmLearn Contributors listed at http://buildmlearn.org/people/
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 
11  * Redistributions in binary form must reproduce the above copyright notice,
12  this list of conditions and the following disclaimer in the documentation
13  and/or other materials provided with the distribution.
14 
15  * Neither the name of the BuildmLearn nor the names of its
16  contributors may be used to endorse or promote products derived from
17  this software without specific prior written permission.
18 
19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 
31 #ifndef SYSTEMTRAYICON_H
32 #define SYSTEMTRAYICON_H
33 
34 #include <QSystemTrayIcon>
35 
36 #include "definitions/definitions.h"
37 
38 #if defined(Q_OS_WIN)
39 #include <QMenu>
40 #endif
41 
42 
43 class QEvent;
44 
45 #if defined(Q_OS_WIN)
46 /// \brief Tray icon Windows-specific menu.
47 class TrayIconMenu : public QMenu {
48  Q_OBJECT
49 
50  public:
51  /// \brief Constructor.
52  /// \param title Title of the tray icon.
53  /// \param parent Parent for the tray icon.
54  explicit TrayIconMenu(const QString &title, QWidget *parent);
55  virtual ~TrayIconMenu();
56 
57  protected:
58  /// \brief Custom event handler.
59  /// \param event Information about the event which just occurred.
60  /// \return Returns true if event was handler, otherwise returns false.
61  bool event(QEvent *event);
62 };
63 #endif
64 
65 /// \brief Application-wide tray icon.
66 class SystemTrayIcon : public QSystemTrayIcon {
67  Q_OBJECT
68 
69  public:
70  /// \brief Constructor.
71  /// \param icon Icon for tray icon.
72  /// \param parent Parent of tray icon.
73  explicit SystemTrayIcon(const QString &icon, QObject *parent = 0);
74  virtual ~SystemTrayIcon();
75 
76  /// \brief Displays new balloon tip with message.
77  /// \param title Title of message.
78  /// \param message Content of message.
79  /// \param icon Icon of message.
80  /// \param milliseconds_timeout_hint Number of miliseconds for message to being visible.
81  /// \param click_target Target object for balloon tip click.
82  /// \param click_slot Target object method for balloon tip click.
83  /// \warning Use this in cooperation with isSystemTrayActivated() method.
84  void showMessage(const QString &title,
85  const QString &message,
86  MessageIcon icon = Information,
87  int milliseconds_timeout_hint = TRAY_ICON_BUBBLE_TIMEOUT,
88  QObject *click_target = NULL,
89  const char *click_slot = NULL);
90 
91  /// \brief Indicates whether tray icon is supported.
92  /// \return Returns true if tray icon is supported.
93  /// \see isSystemTrayActivated()
94  static bool isSystemTrayAvailable();
95 
96  public slots:
97  /// \brief Displays tray icon.
98  void show();
99 
100  private slots:
101  void onActivated(QSystemTrayIcon::ActivationReason reason);
102  void showPrivate();
103 
104  signals:
105  /// \brief Emitted if user clicks tray icon with left mouse button.
106  void leftMouseClicked();
107 
108  private:
109  QObject *m_bubbleClickTarget;
110  char *m_bubbleClickSlot;
111 };
112 
113 #endif // SYSTEMTRAYICON_H
SystemTrayIcon(const QString &icon, QObject *parent=0)
Constructor.
void leftMouseClicked()
Emitted if user clicks tray icon with left mouse button.
void showMessage(const QString &title, const QString &message, MessageIcon icon=Information, int milliseconds_timeout_hint=TRAY_ICON_BUBBLE_TIMEOUT, QObject *click_target=NULL, const char *click_slot=NULL)
Displays new balloon tip with message.
void show()
Displays tray icon.
static bool isSystemTrayAvailable()
Indicates whether tray icon is supported.
Application-wide tray icon.