GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ToolBarButton.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 // This file should not include config.h. It is only included in other
24 // C++ source files that should have included config.h before including
25 // this file.
26 
27 #include <QAction>
28 #include <QWidget>
29 
30 #include "ToolBarButton.h"
31 #include "QtHandlesUtils.h"
32 
33 namespace QtHandles
34 {
35 
36  template <typename T>
37  ToolBarButton<T>::ToolBarButton (const graphics_object& go, QAction *action)
38  : Object (go, action), m_separator (nullptr)
39  {
40  typename T::properties& tp = properties<T> ();
41 
42  action->setToolTip (Utils::fromStdString (tp.get_tooltipstring ()));
43  action->setVisible (tp.is_visible ());
44  QImage img = Utils::makeImageFromCData (tp.get_cdata (), 16, 16);
45  action->setIcon (QIcon (QPixmap::fromImage (img)));
46  if (tp.is_separator ())
47  {
48  m_separator = new QAction (action);
49  m_separator->setSeparator (true);
50  m_separator->setVisible (tp.is_visible ());
51  }
52  action->setEnabled (tp.is_enable ());
53 
54  QWidget *w = qobject_cast<QWidget *> (action->parent ());
55 
56  w->insertAction (w->actions ().back (), action);
57  if (m_separator)
58  w->insertAction (action, m_separator);
59  }
60 
61  template <typename T>
63  { }
64 
65  template <typename T>
66  void
68  {
69  typename T::properties& tp = properties<T> ();
70  QAction *action = qWidget<QAction> ();
71 
72  switch (pId)
73  {
74  case base_properties::ID_VISIBLE:
75  action->setVisible (tp.is_visible ());
76  if (m_separator)
77  m_separator->setVisible (tp.is_visible ());
78  break;
79 
80  case T::properties::ID_TOOLTIPSTRING:
81  action->setToolTip (Utils::fromStdString (tp.get_tooltipstring ()));
82  break;
83 
84  case T::properties::ID_CDATA:
85  {
86  QImage img = Utils::makeImageFromCData (tp.get_cdata (), 16, 16);
87 
88  action->setIcon (QIcon (QPixmap::fromImage (img)));
89  }
90  break;
91 
92  case T::properties::ID_SEPARATOR:
93  if (tp.is_separator ())
94  {
95  if (! m_separator)
96  {
97  m_separator = new QAction (action);
98  m_separator->setSeparator (true);
99  m_separator->setVisible (tp.is_visible ());
100 
101  QWidget *w = qobject_cast<QWidget *> (action->parent ());
102 
103  w->insertAction (action, m_separator);
104  }
105  }
106  else
107  {
108  if (m_separator)
109  delete m_separator;
110  m_separator = nullptr;
111  }
112  break;
113 
114  case T::properties::ID_ENABLE:
115  action->setEnabled (tp.is_enable ());
116  break;
117 
118  default:
119  Object::update (pId);
120  break;
121  }
122  }
123 
124 }
QString fromStdString(const std::string &s)
std::complex< double > w(std::complex< double > z, double relerr=0)
QImage makeImageFromCData(const octave_value &v, int width, int height)
ToolBarButton(const graphics_object &go, QAction *action)
T::properties & properties(graphics_object obj)