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
MouseModeActionGroup.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 <QAction>
28 #include <QIcon>
29 
30 #include "Figure.h"
31 #include "MouseModeActionGroup.h"
32 
33 namespace QtHandles
34 {
35 
37  : QObject (xparent), m_current (0)
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 
67 void
69 {
70  if (! checked)
71  {
72  if (sender () == m_current)
73  {
74  m_current = 0;
75  emit modeChanged (NoMode);
76  }
77  }
78  else
79  {
80  int i = m_actions.indexOf (qobject_cast<QAction*> (sender ()));
81 
82  if (i >= 0)
83  {
84  m_current = m_actions[i];
85  for (int j = 0; j < m_actions.size (); j++)
86  {
87  // SelectMode cancels all the others but the button
88  // doesn't remain highlighed.
89 
90  if (j != i || i+1 == SelectMode)
91  m_actions[j]->setChecked (false);
92  }
93 
94  emit modeChanged (static_cast<MouseMode> (i+1));
95  }
96  }
97 }
98 
99 void
101 {
102  for (int i = 0; i < m_actions.size (); i++)
103  m_actions[i]->setChecked (i+1 == mode);
104 
105  // SelectMode cancels all the others but the button doesn't remain
106  // highlighed.
107 
108  if (mode == SelectMode)
109  m_actions[SelectMode-1]->setChecked (false);
110 }
111 
112 };
MouseMode
Definition: Figure.h:38