Tray icon works...

This commit is contained in:
Martin Rotter 2014-01-10 12:59:21 +01:00
parent 35497a55b7
commit db15474aa3
2 changed files with 9 additions and 7 deletions

View File

@ -24,8 +24,8 @@ bool TrayIconMenu::event(QEvent *event) {
event->type() == QEvent::Show) { event->type() == QEvent::Show) {
QTimer::singleShot(0, this, SLOT(hide())); QTimer::singleShot(0, this, SLOT(hide()));
SystemTrayIcon::instance()->showMessage(APP_LONG_NAME, SystemTrayIcon::instance()->showMessage(APP_LONG_NAME,
tr("Close opened modal dialogs first."), tr("Close opened modal dialogs first."),
QSystemTrayIcon::Warning); QSystemTrayIcon::Warning);
} }
return QMenu::event(event); return QMenu::event(event);
} }
@ -69,9 +69,10 @@ bool SystemTrayIcon::isSystemTrayAvailable() {
} }
bool SystemTrayIcon::isSystemTrayActivated() { bool SystemTrayIcon::isSystemTrayActivated() {
// TODO: check if this can be rewritten for bigger speed.
return SystemTrayIcon::isSystemTrayAvailable() && Settings::instance()->value(APP_CFG_GUI, return SystemTrayIcon::isSystemTrayAvailable() && Settings::instance()->value(APP_CFG_GUI,
"use_tray_icon", "use_tray_icon",
true).toBool(); true).toBool();
} }
SystemTrayIcon *SystemTrayIcon::instance() { SystemTrayIcon *SystemTrayIcon::instance() {
@ -89,6 +90,7 @@ void SystemTrayIcon::deleteInstance() {
qDebug("Disabling tray icon and raising main application window."); qDebug("Disabling tray icon and raising main application window.");
static_cast<FormMain*>((*s_trayIcon).parent())->display(); static_cast<FormMain*>((*s_trayIcon).parent())->display();
delete s_trayIcon.data(); delete s_trayIcon.data();
s_trayIcon = NULL;
// Make sure that application quits when last window is closed. // Make sure that application quits when last window is closed.
qApp->setQuitOnLastWindowClosed(true); qApp->setQuitOnLastWindowClosed(true);
@ -121,7 +123,7 @@ void SystemTrayIcon::show() {
// TODO: Set better colors for number -> better readability. // TODO: Set better colors for number -> better readability.
void SystemTrayIcon::setNumber(int number) { void SystemTrayIcon::setNumber(int number) {
if (number < 0) { if (number <= 0) {
QSystemTrayIcon::setIcon(QIcon(m_normalIcon)); QSystemTrayIcon::setIcon(QIcon(m_normalIcon));
} }
else { else {
@ -131,7 +133,7 @@ void SystemTrayIcon::setNumber(int number) {
font.setBold(true); font.setBold(true);
trayPainter.begin(&background); trayPainter.begin(&background);
trayPainter.setPen(Qt::black); trayPainter.setBrush(Qt::black);
// Numbers with more than 2 digits won't be readable, display // Numbers with more than 2 digits won't be readable, display
// infinity symbol in that case. // infinity symbol in that case.

View File

@ -42,7 +42,7 @@ class SystemTrayIcon : public QSystemTrayIcon {
// WARNING: Use this in cooperation with SystemTrayIcon::isSystemTrayActivated(). // WARNING: Use this in cooperation with SystemTrayIcon::isSystemTrayActivated().
static SystemTrayIcon *instance(); static SystemTrayIcon *instance();
// Sets the number to be visible in the tray icon, -1 removes it. // Sets the number to be visible in the tray icon, number <= 0 removes it.
void setNumber(int number = -1); void setNumber(int number = -1);
// Explicitle clears SystemTrayIcon instance from the memory. // Explicitle clears SystemTrayIcon instance from the memory.