GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
MouseModeActionGroup.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 <QAction>
28 #include <QIcon>
29 
30 #include "Figure.h"
31 #include "MouseModeActionGroup.h"
32 
33 namespace QtHandles
34 {
35 
37  : QObject (xparent), m_current (nullptr)
38  {
39  m_actions.append (new QAction (QIcon (":/images/rotate.png"),
40  tr ("Rotate"), this));
41  QAction *zoom_in = new QAction ("Z+", this);
42  zoom_in->setToolTip (tr ("Zoom In"));
43  m_actions.append (zoom_in);
44 
45  QAction *zoom_out = new QAction ("Z-", this);
46  zoom_out->setToolTip (tr ("Zoom Out"));
47  m_actions.append (zoom_out);
48 
49  m_actions.append (new QAction (QIcon (":/images/pan.png"),
50  tr ("Pan"), this));
51  m_actions.append (new QAction (QIcon::fromTheme ("insert-text"),
52  tr ("Insert Text"), this));
53  m_actions.append (new QAction (QIcon (":/images/select.png"),
54  tr ("Select"), this));
55 
56  foreach (QAction *a, m_actions)
57  {
58  a->setCheckable (true);
59  connect (a, SIGNAL (toggled (bool)), this, SLOT (actionToggled (bool)));
60  }
61  }
62 
64  { }
65 
66  void
68  {
69  if (! checked)
70  {
71  if (sender () == m_current)
72  {
73  m_current = nullptr;
74  emit modeChanged (NoMode);
75  }
76  }
77  else
78  {
79  int i = m_actions.indexOf (qobject_cast<QAction *> (sender ()));
80 
81  if (i >= 0)
82  {
84  for (int j = 0; j < m_actions.size (); j++)
85  {
86  // SelectMode cancels all the others but the button
87  // doesn't remain highlighed.
88 
89  if (j != i || i+1 == SelectMode)
90  m_actions[j]->setChecked (false);
91  }
92 
93  emit modeChanged (static_cast<MouseMode> (i+1));
94  }
95  }
96  }
97 
98  void
100  {
101  for (int i = 0; i < m_actions.size (); i++)
102  m_actions[i]->setChecked (i+1 == mode);
103 
104  // SelectMode cancels all the others but the button doesn't remain
105  // highlighed.
106 
107  if (mode == SelectMode)
108  m_actions[SelectMode-1]->setChecked (false);
109  }
110 
111 };
MouseMode
Definition: Figure.h:39
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
Definition: data.cc:6348
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:400
void modeChanged(MouseMode mode)
MouseModeActionGroup(QObject *parent=nullptr)
for i
Definition: data.cc:5264