2 * Copyright (C) 2011 Toni Gundogdu <legatvs@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 * Constructor: NSystray
34 * Initializes the object.
36 NSysTray::NSysTray(QObject
*parent
/*=NULL*/, const QString
& text
/*=""*/)
37 : QSystemTrayIcon(parent
), trayMenu(NULL
)
47 * Shorthand for setting the tooltip message.
50 * text - Text to be used a a new tooltip message
55 NSysTray
& NSysTray::operator<<(const QString
& text
)
62 * Function: addTrayMenuAction
64 * Adds a new action to the tray menu.
67 * signal - Signal to connect to
69 * method - Method that handles the signal
71 * checkable - Whether the action should be checkable
73 void NSysTray::addTrayMenuAction(const char *signal
,
77 const bool checkable
/*=false*/)
79 QAction
*action
= new QAction(text
, this);
80 action
->setCheckable(checkable
);
81 connect(action
, signal
, receiver
, method
);
82 trayMenu
->addAction(action
);
86 * Function: addTrayMenuSeparator
88 * Adds a separator to the tray menu.
90 void NSysTray::addTrayMenuSeparator()
92 QAction
*a
= new QAction(this);
93 a
->setSeparator(true);
94 trayMenu
->addAction(a
);
98 * Function: findTrayMenuAction
100 * Returns a matching tray menu action.
103 * text - Action text to match
106 * Pointer to an action or NULL if nothing was matched
108 QAction
*NSysTray::findTrayMenuAction(const QString
& text
)
110 foreach (QAction
*action
, trayMenu
->actions())
112 if (action
->text() == text
)
115 #ifdef ENABLE_VERBOSE
116 qWarning() << __PRETTY_FUNCTION__
<< __LINE__
119 << "\" not found in tray menu";
125 * Function: setTrayMenu()
127 * Makes the created tray menu the context menu for the tray icon.
129 void NSysTray::setTrayMenu()
131 setContextMenu(trayMenu
);
136 /* vim: set ts=2 sw=2 tw=72 expandtab: */