~sachinr/xpad/xpad-qt

« back to all changes in this revision

Viewing changes to src/main.cpp

  • Committer: Sachin Raut
  • Date: 2013-09-18 15:08:32 UTC
  • Revision ID: great.sachin@gmail.com-20130918150832-086xl1b73jch29xi
initial import of qt port of xpad
add tray icon
options in tray icon
1) new pad
2) exit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include "padwindow.h"
 
3
 
 
4
#include <QApplication>
 
5
#include <QtCore>
 
6
#include <QSystemTrayIcon>
 
7
#include <QMenu>
 
8
 
 
9
#include <memory>
 
10
 
 
11
#include <padgroup.h>
 
12
 
 
13
using namespace std;
 
14
 
 
15
int main(int argc, char *argv[])
 
16
{
 
17
    QApplication a(argc, argv);
 
18
 
 
19
    // create tray icon
 
20
    unique_ptr<QSystemTrayIcon> trayicon(new QSystemTrayIcon);
 
21
    trayicon->setIcon(QIcon("/home/sachin/.xpad-qt/xpad.png"));
 
22
    trayicon->setVisible(true);
 
23
    trayicon->show();
 
24
 
 
25
    // new pad action
 
26
    auto new_pad_action = new QAction("&New Pad", NULL);
 
27
    unique_ptr<PadGroup> padGroup(new PadGroup());
 
28
    QObject::connect(new_pad_action, SIGNAL(triggered()), (QObject*)padGroup.get(), SLOT(CreateNewPad()));
 
29
 
 
30
    // quit menu
 
31
    auto quitAction = new QAction("&Quit", NULL);
 
32
    trayicon->connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
 
33
 
 
34
    // create menu
 
35
    auto trayIconMenu = new QMenu();
 
36
    trayIconMenu->addAction(new_pad_action);
 
37
    trayIconMenu->addSeparator();
 
38
    trayIconMenu->addAction(quitAction);
 
39
    trayicon->setContextMenu(trayIconMenu);
 
40
 
 
41
    //wait untill quit message is posted
 
42
    int ret_value = a.exec();
 
43
    trayicon->hide();
 
44
    return ret_value;
 
45
}