-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactionmenu.cpp
More file actions
112 lines (100 loc) · 2.82 KB
/
Copy pathactionmenu.cpp
File metadata and controls
112 lines (100 loc) · 2.82 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* $Id: actionmenu.cpp */
/*
* Copyright (C) 2012-2014 Dmytro Mishchenko <arkadiamail@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "actionmenu.h"
#include "sysdepapp.h"
#include <QPushButton>
#include <QMouseEvent>
//#include <QDebug>
ActionMenu::ActionMenu(QWidget *parent) :
QDialog(parent),
btnName(),
_startPoint(0,0),
_endPoint(0,0)
{
}
QString ActionMenu::getButtonName() const
{
return btnName;
}
void ActionMenu::buttonClicked()
{
QPushButton *button = (QPushButton *)sender();
btnName = button->objectName();
done(QDialog::Accepted);
}
/*
void ActionMenu::focusOutEvent(QFocusEvent *event)
{
qDebug() << "focusOutEvent in action menu";
QDialog::focusOutEvent(event);
}
*/
bool ActionMenu::event(QEvent *event)
{
if (event->type() == QEvent::WindowDeactivate) {
done(QDialog::Rejected);
}
return QDialog::event(event);
}
void ActionMenu::mousePressEvent(QMouseEvent *event)
{
_startPoint = event->pos();
QDialog::mousePressEvent(event);
}
void ActionMenu::mouseReleaseEvent(QMouseEvent *event)
{
_endPoint = event->pos();
int xDiff = _startPoint.x() - _endPoint.x();
int yDiff = _startPoint.y() - _endPoint.y();
if(qAbs(xDiff) > qAbs(yDiff)) {
// horizontal swipe detected, now find direction
if( _startPoint.x() > _endPoint.x() ) {
//qDebug() << "swipe left";
} else {
//qDebug() << "swipe right";
done(QDialog::Rejected);
return;
}
}
/*
else {
// vertical swipe detected, now find direction
if( _startPoint.y() > _endPoint.y() ) {
qDebug() << "swipe up";
} else {
qDebug() << "swipe down";
}
}
*/
QDialog::mouseReleaseEvent(event);
}
void ActionMenu::show()
{
QRect wp = (qobject_cast<SysDepApp *>(qApp))->getActionMenuSize(sizeHint());
//qDebug() << "min hint" << minimumSizeHint();
//qDebug() << "size hint" << sizeHint();
//qDebug() << "app act menu size" << wp;
#if !defined(Q_OS_QNX)
setWindowFlags(Qt::Popup);
#endif
QDialog::show();
setFocus();
resize(wp.size());
move(wp.topLeft());
}