-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontextmenu.cpp
executable file
·95 lines (73 loc) · 2.52 KB
/
contextmenu.cpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "contextmenu.h"
ContextMenu::ContextMenu(QWidget *parent) :
QDialog(parent)
{
setWindowFlags(Qt::FramelessWindowHint | Qt::Widget);
setAutoFillBackground(true);
calendar = new QPushButton();
network = new QPushButton();
settings = new QPushButton();
quit = new QPushButton();
calendar->setIcon(QIcon(":calendar.png"));
calendar->setToolTip(tr("Calendar"));
network->setIcon(QIcon(":network.png"));
network->setToolTip(tr("Network"));
settings->setIcon(QIcon(":settings.png"));
settings->setToolTip(tr("Settings"));
quit->setIcon(QIcon(":quit.png"));
quit->setToolTip(tr("Quit"));
connect(calendar, SIGNAL(clicked()),
this, SIGNAL(requestCalendar()));
connect(network, SIGNAL(clicked()),
this, SIGNAL(requestNetwork()));
connect(settings, SIGNAL(clicked()),
this, SIGNAL(requestSettings()));
connect(quit, SIGNAL(clicked()),
this, SIGNAL(requestQuit()));
connect(calendar, SIGNAL(clicked()),
this, SLOT(hide()));
connect(network, SIGNAL(clicked()),
this, SLOT(hide()));
connect(settings, SIGNAL(clicked()),
this, SLOT(hide()));
QHBoxLayout *layout = new QHBoxLayout();
layout->addWidget(calendar);
layout->addWidget(network);
layout->addWidget(settings);
layout->addWidget(quit);
setModal(true);
setBackgroundRole(QPalette::Window);
setLayout(layout);
}
void ContextMenu::show() {
if(!isHidden()) {
hide();
return;
}
//qDebug() << "[debug] parent: " << parentWidget()->size();
//qDebug() << "[debug] pos: " << pos();
//resize(QSize(parentWidget()->size().width(), 32));
//move(0, parentWidget()->size().height()-32);
QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry");
animation->setDuration(170);
animation->setStartValue(QRect(0, parentWidget()->size().height(), parentWidget()->size().width(), 0));
animation->setEndValue(QRect(0, parentWidget()->size().height()-42, parentWidget()->size().width(), 42));
animation->start();
QDialog::show();
calendar->setFocus();
calendar->setDefault(true);
}
void ContextMenu::hide()
{
QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry");
animation->setDuration(150);
animation->setStartValue(QRect(0, parentWidget()->size().height()-42, parentWidget()->size().width(), 42));
animation->setEndValue(QRect(0, parentWidget()->size().height(), parentWidget()->size().width(), 0));
connect(animation, SIGNAL(finished()),
this, SLOT(privHide()));
animation->start();
}
void ContextMenu::privHide()
{
QDialog::hide();
}