GNU Octave
4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ContextMenu.cc
Go to the documentation of this file.
1
/*
2
3
Copyright (C) 2011-2018 Michael Goffioul
4
5
This file is part of Octave.
6
7
Octave is free software: you can redistribute it and/or modify it
8
under the terms of the GNU General Public License as published by
9
the Free Software Foundation, either version 3 of the License, or
10
(at your option) any later version.
11
12
Octave is distributed in the hope that it will be useful, but
13
WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
16
17
You should have received a copy of the GNU General Public License
18
along with Octave; see the file COPYING. If not, see
19
<https://www.gnu.org/licenses/>.
20
21
*/
22
23
#if defined (HAVE_CONFIG_H)
24
# include "config.h"
25
#endif
26
27
#include <QMenu>
28
29
#include "
Backend.h
"
30
#include "
ContextMenu.h
"
31
#include "
QtHandlesUtils.h
"
32
33
namespace
QtHandles
34
{
35
36
ContextMenu*
37
ContextMenu::create
(
const
graphics_object
& go)
38
{
39
Object
*xparent =
Object::parentObject
(go);
40
41
if
(xparent)
42
{
43
QWidget
*
w
= xparent->
qWidget
<
QWidget
> ();
44
45
return
new
ContextMenu
(go,
new
QMenu
(
w
));
46
}
47
48
return
nullptr
;
49
}
50
51
ContextMenu::ContextMenu
(
const
graphics_object
& go,
QMenu
*xmenu)
52
:
Object
(go, xmenu)
53
{
54
xmenu->setAutoFillBackground (
true
);
55
56
connect (xmenu, SIGNAL (
aboutToShow
(
void
)), SLOT (
aboutToShow
(
void
)));
57
connect (xmenu, SIGNAL (
aboutToHide
(
void
)), SLOT (
aboutToHide
(
void
)));
58
}
59
60
ContextMenu::~ContextMenu
(
void
)
61
{ }
62
63
void
64
ContextMenu::update
(
int
pId)
65
{
66
uicontextmenu::properties
& up = properties<uicontextmenu> ();
67
QMenu
*xmenu = qWidget<QMenu> ();
68
69
switch
(pId)
70
{
71
case
base_properties::ID_VISIBLE:
72
if
(up.is_visible ())
73
{
74
Matrix
pos = up.get_position ().matrix_value ();
75
QWidget
*parentW = xmenu->parentWidget ();
76
QPoint pt;
77
78
pt.rx () =
octave::math::round
(pos(0));
79
pt.ry () = parentW->height () -
octave::math::round
(pos(1));
80
pt = parentW->mapToGlobal (pt);
81
82
xmenu->popup (pt);
83
}
84
else
85
xmenu->hide ();
86
break
;
87
default
:
88
Object::update
(pId);
89
break
;
90
}
91
}
92
93
void
94
ContextMenu::aboutToShow
(
void
)
95
{
96
gh_manager::post_callback
(
m_handle
,
"callback"
);
97
gh_manager::post_set
(
m_handle
,
"visible"
,
"on"
,
false
);
98
}
99
100
void
101
ContextMenu::aboutToHide
(
void
)
102
{
103
gh_manager::post_set
(
m_handle
,
"visible"
,
"off"
,
false
);
104
}
105
106
QWidget
*
107
ContextMenu::menu
(
void
)
108
{
109
return
qWidget<QWidget> ();
110
}
111
112
void
113
ContextMenu::executeAt
(
const
base_properties
& props,
const
QPoint& pt)
114
{
115
graphics_handle
h
= props.get_uicontextmenu ();
116
117
if
(
h
.ok ())
118
{
119
gh_manager::auto_lock
lock;
120
graphics_object
go =
gh_manager::get_object
(
h
);
121
122
if
(go.
valid_object
())
123
{
124
ContextMenu
*cMenu =
125
dynamic_cast<
ContextMenu
*
>
(
Backend::toolkitObject
(go));
126
127
if
(cMenu)
128
{
129
QMenu
*
menu
= cMenu->
qWidget
<
QMenu
> ();
130
131
if
(
menu
)
132
menu
->popup (pt);
133
}
134
}
135
}
136
}
137
138
}
ContextMenu.h
gh_manager::post_callback
static void post_callback(const graphics_handle &h, const std::string &name, const octave_value &data=Matrix())
Definition:
graphics.in.h:6214
QtHandles::Object
Definition:
Object.h:40
uicontextmenu::properties
Definition:
graphics.in.h:5392
QWidget
QtHandles::ContextMenu::ContextMenu
ContextMenu(const graphics_object &go, QMenu *menu)
Definition:
ContextMenu.cc:51
QtHandles::Object::parentObject
static Object * parentObject(const graphics_object &go)
Definition:
Object.cc:165
QtHandles::ContextMenu
Definition:
ContextMenu.h:36
QtHandles::ContextMenu::executeAt
static void executeAt(const base_properties &props, const QPoint &pt)
Definition:
ContextMenu.cc:113
graphics_object::valid_object
bool valid_object(void) const
Definition:
graphics.in.h:2806
QtHandlesUtils.h
h
double h
Definition:
graphics.cc:11808
QtHandles
Definition:
__init_qt__.cc:44
gh_manager::auto_lock
Definition:
graphics.in.h:6270
QtHandles::ContextMenu::aboutToShow
void aboutToShow(void)
Definition:
ContextMenu.cc:94
Faddeeva::w
std::complex< double > w(std::complex< double > z, double relerr=0)
QtHandles::Object::m_handle
graphics_handle m_handle
Definition:
Object.h:115
QtHandles::Object::qWidget
T * qWidget(void)
Definition:
Object.h:74
QtHandles::ContextMenu::update
void update(int pId)
Definition:
ContextMenu.cc:64
Matrix
Definition:
dMatrix.h:36
QMenu
QtHandles::ContextMenu::~ContextMenu
~ContextMenu(void)
Definition:
ContextMenu.cc:60
Backend.h
QtHandles::Backend::toolkitObject
static Object * toolkitObject(const graphics_object &go)
Definition:
Backend.cc:212
QtHandles::Object::update
virtual void update(int pId)
Definition:
Object.cc:132
QtHandles::ContextMenu::aboutToHide
void aboutToHide(void)
Definition:
ContextMenu.cc:101
base_properties
Definition:
graphics.in.h:2180
octave_handle
Definition:
oct-handle.h:35
gh_manager::get_object
static graphics_object get_object(double val)
Definition:
graphics.in.h:6098
octave::math::round
double round(double x)
Definition:
lo-mappers.h:145
graphics_object
Definition:
graphics.in.h:2660
QtHandles::ContextMenu::create
static ContextMenu * create(const graphics_object &go)
Definition:
ContextMenu.cc:37
QtHandles::ContextMenu::menu
QWidget * menu(void)
Definition:
ContextMenu.cc:107
gh_manager::post_set
static void post_set(const graphics_handle &h, const std::string &name, const octave_value &value, bool notify_toolkit=true)
Definition:
graphics.in.h:6228
libgui
graphics
ContextMenu.cc
Generated on Sat Sep 1 2018 14:01:37 for GNU Octave by
1.8.14