summaryrefslogtreecommitdiffstats
path: root/pica-client/picaactioncenter.cpp
blob: 8d36a4b4156be985936249b28f5c55cfe431934c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "picaactioncenter.h"
#include "globals.h"
#include "mainwindow.h"
#include "skynet.h"
#include <QApplication>
#include <QMessageBox>
#include <QPalette>
#include <QDesktopServices>
#include <QEvent>
#include <QMouseEvent>

PicaActionCenter::PicaActionCenter(QObject *parent) :
    QObject(parent)
{
    exitAct = new QAction(tr("E&xit"),this);
    exitAct->setStatusTip(tr("Close Pica Pica messenger and exit"));
    connect(exitAct,SIGNAL(triggered()),this,SLOT(exit()));

    aboutAct = new QAction(tr("A&bout"),this);
    aboutAct->setStatusTip(tr("About Pica Pica Messenger"));
    connect(aboutAct,SIGNAL(triggered()),this,SLOT(about()));
    link = new QLabel;
    link->installEventFilter(this);
}

bool PicaActionCenter::eventFilter(QObject *obj, QEvent *ev)
{
    QMouseEvent *mEvent = (QMouseEvent*)ev;

    if (obj == link && mEvent->button() == Qt::LeftButton &&
            ev->type() == QEvent::MouseButtonRelease) {
        QDesktopServices::openUrl(QUrl(link->text()));
    }

    ev->accept();
}

void PicaActionCenter::about()
{
#ifdef PACKAGE_VERSION
#define VERSION_STRING "v"PACKAGE_VERSION
#else
#define VERSION_STRING ""
#endif

    QMessageBox mbx;
    mbx.setWindowIcon(picapica_ico_sit);
    mbx.setIconPixmap(picapica_ico_sit.pixmap(32));
    QString author = "Pica Pica Messenger "VERSION_STRING"\n"
                     "(c) 2012 Anton Sviridenko";

    link->setParent(&mbx);
    link->setText("http://picapica.im");
    int x = author.count("\n") + 1;
    float f = mbx.font().pointSize();
    link->move(60, f * 2 * x);
    link->resize(150, 30);
    link->setForegroundRole(QPalette::Link);
    QCursor cursor;
    cursor.setShape(Qt::PointingHandCursor);
    link->setCursor(cursor);

    QString contrib = "\n\n\nContributors:\nDaniil Ustinov - bugfixes";
    mbx.setText(tr(QString(author + contrib).toStdString().c_str()));

    mbx.exec();
}

void PicaActionCenter::exit()
{
    if (mainwindow)
        mainwindow->close();

    skynet->Exit();
    QApplication::instance()->quit();
}