GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ToggleTool.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2011-2015 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include "ToggleTool.h"
28 
29 #include "ToolBarButton.cc"
30 
31 namespace QtHandles
32 {
33 
34 ToggleTool*
36 {
37  Object* parent = Object::parentObject (go);
38 
39  if (parent)
40  {
41  QWidget* parentWidget = parent->qWidget<QWidget> ();
42 
43  if (parentWidget)
44  return new ToggleTool (go, new QAction (parentWidget));
45  }
46 
47  return 0;
48 }
49 
50 ToggleTool::ToggleTool (const graphics_object& go, QAction* action)
51  : ToolBarButton<uitoggletool> (go, action)
52 {
53  uitoggletool::properties& tp = properties<uitoggletool> ();
54 
55  action->setCheckable (true);
56  action->setChecked (tp.is_state ());
57 
58  connect (action, SIGNAL (toggled (bool)),
59  this, SLOT (triggered (bool)));
60 }
61 
63 {
64 }
65 
66 void
68 {
69  uitoggletool::properties& tp = properties<uitoggletool> ();
70  QAction* action = qWidget<QAction> ();
71 
72  switch (pId)
73  {
75  action->setChecked (tp.is_state ());
76  break;
77 
78  default:
80  break;
81  }
82 }
83 
84 void
85 ToggleTool::triggered (bool checked)
86 {
87  gh_manager::post_set (m_handle, "state", checked, false);
89  checked
90  ? "oncallback"
91  : "offcallback");
92  gh_manager::post_callback (m_handle, "clickedcallback");
93 }
94 
95 };
static void post_callback(const graphics_handle &h, const std::string &name, const octave_value &data=Matrix())
Definition: graphics.h:13329
void update(int pId)
Definition: ToggleTool.cc:67
void triggered(bool checked)
Definition: ToggleTool.cc:85
static Object * parentObject(const graphics_object &go)
Definition: Object.cc:170
graphics_handle m_handle
Definition: Object.h:100
T * qWidget(void)
Definition: Object.h:74
static ToggleTool * create(const graphics_object &go)
Definition: ToggleTool.cc:35
bool is_state(void) const
Definition: graphics.h:12921
ToggleTool(const graphics_object &go, QAction *action)
Definition: ToggleTool.cc:50
static void post_set(const graphics_handle &h, const std::string &name, const octave_value &value, bool notify_toolkit=true)
Definition: graphics.h:13343