Changeset 29 for gui/main_window.cpp


Ignore:
Timestamp:
01/06/08 11:59:56 (4 years ago)
Author:
roeland
Message:

Basic system tray icon works

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gui/main_window.cpp

    r28 r29  
    11#include <cmath> 
    22#include <QtGui> 
     3#include <QIcon> 
    34 
    45#include "main_window.h" 
     
    78MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) 
    89{ 
    9     QSettings settings; 
    10  
    1110    setupUi(this); 
    1211 
     
    6059    connect(&statusTimer, SIGNAL(timeout()), &mpd, SLOT(getStatus())); 
    6160 
     61    //Tray icon 
     62    setupTrayIcon(); 
     63    if (settings.value("systemtray").toBool()) { 
     64        trayIcon->show(); 
     65    } 
     66 
    6267    mpd.getStatus(); 
    6368    mpd.listAllInfo(); 
     
    7176}*/ 
    7277 
     78void MainWindow::closeEvent(QCloseEvent *event)  
     79{ 
     80    if (trayIcon->isVisible()) { 
     81        QMessageBox::information(this, tr("Systray"), 
     82            tr("The program will keep running in the " 
     83            "system tray. To terminate the program, " 
     84            "choose <b>Quit</b> in the context menu " 
     85            "of the system tray entry.")); 
     86        hide(); 
     87        event->ignore(); 
     88    } 
     89} 
     90 
     91void MainWindow::setupTrayIcon() 
     92{ 
     93    //Setup Actions 
     94    minimizeAction = new QAction(tr("Mi&nimize"), this); 
     95    connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide())); 
     96 
     97    maximizeAction = new QAction(tr("Ma&ximize"), this); 
     98    connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized())); 
     99 
     100    restoreAction = new QAction(tr("&Restore"), this); 
     101    connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal())); 
     102 
     103    quitAction = new QAction(tr("&Quit"), this); 
     104    connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); 
     105 
     106    //Setup Menu 
     107    trayIconMenu = new QMenu(this); 
     108    trayIconMenu->addAction(minimizeAction); 
     109    trayIconMenu->addAction(maximizeAction); 
     110    trayIconMenu->addAction(restoreAction); 
     111    trayIconMenu->addSeparator(); 
     112    trayIconMenu->addAction(quitAction); 
     113 
     114    //Setup Icon 
     115    QIcon icon("images/bad.svg");    
     116     
     117    //Mix it 
     118    trayIcon = new QSystemTrayIcon(this); 
     119    trayIcon->setContextMenu(trayIconMenu); 
     120    trayIcon->setIcon(icon); 
     121} 
     122 
    73123void MainWindow::showPreferencesDialog() 
    74124{ 
    75125    PreferencesDialog pref(this); 
     126    connect(&pref, SIGNAL(systemTraySet(bool)), trayIcon, SLOT(setVisible(bool))); 
    76127    pref.exec(); 
    77128} 
Note: See TracChangeset for help on using the changeset viewer.