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
ToolBarButton.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 <QWidget>
29 
30 #include "ToolBarButton.h"
31 #include "QtHandlesUtils.h"
32 
33 namespace QtHandles
34 {
35 
36 template <class T>
38  : Object (go, action), m_separator (0)
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 <class T>
63 {
64 }
65 
66 template <class T>
67 void
69 {
70  typename T::properties& tp = properties<T> ();
71  QAction* action = qWidget<QAction> ();
72 
73  switch (pId)
74  {
76  action->setVisible (tp.is_visible ());
77  if (m_separator)
78  m_separator->setVisible (tp.is_visible ());
79  break;
80 
81  case T::properties::ID_TOOLTIPSTRING:
82  action->setToolTip (Utils::fromStdString (tp.get_tooltipstring ()));
83  break;
84 
85  case T::properties::ID_CDATA:
86  {
87  QImage img = Utils::makeImageFromCData (tp.get_cdata (), 16, 16);
88 
89  action->setIcon (QIcon (QPixmap::fromImage (img)));
90  }
91  break;
92 
93  case T::properties::ID_SEPARATOR:
94  if (tp.is_separator ())
95  {
96  if (! m_separator)
97  {
98  m_separator = new QAction (action);
99  m_separator->setSeparator (true);
100  m_separator->setVisible (tp.is_visible ());
101 
102  QWidget* w = qobject_cast<QWidget*> (action->parent ());
103 
104  w->insertAction (action, m_separator);
105  }
106  }
107  else
108  {
109  if (m_separator)
110  delete m_separator;
111  m_separator = 0;
112  }
113  break;
114 
115  case T::properties::ID_ENABLE:
116  action->setEnabled (tp.is_enable ());
117  break;
118 
119  default:
120  Object::update (pId);
121  break;
122  }
123 }
124 
125 }; // namespace QtHandles
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)
virtual void update(int pId)
Definition: Object.cc:133
ToolBarButton(const graphics_object &go, QAction *action)
T::properties & properties(graphics_object obj)