VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
toolButtonWrapperWidget.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2015 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
8 
10 
11 #pragma once
12 
15 
16 #include <QtWidgets/QFrame>
17 #include <QtGui/QPixmap>
18 #include <boost/signals2.hpp>
19 
20 class QAction;
21 class QHBoxLayout;
22 class QAbstractButton;
23 class QSpacerItem;
24 
25 namespace makVrf
26 {
33  {
34  Q_OBJECT
35 
36  public:
37  struct Layout
38  {
39  int spacers = 0;
40  QHBoxLayout* layout;
41  std::vector<QAbstractButton*> buttons;
43  QSpacerItem* spacerItem;
44  };
45 
46  public:
47  DtToolButtonWrapperWidget(makVrv::DtDe& de, QWidget* parent, const Qt::WindowFlags& flags = 0);
48 
49  //DTOR
50  virtual ~DtToolButtonWrapperWidget();
51 
52  template <typename T> T* createPrototype()
53  {
54  T* b = new T(this);
55 
56  b->setFocusPolicy( Qt::NoFocus );
57  b->setIconSize(myIconSize);
58  b->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
59 
60  return b;
61  }
62 
63  template <typename T> T* createButton()
64  {
65  T* b = createPrototype<T>();
66 
67  this->myButtons.push_back(b);
68 
69  return b;
70  }
71 
73  template <typename T> T* addAction(const QString& action, bool resetLayout = true)
74  {
75  T* b = createButton<T>();
76  b->setText(action);
77 
78  if (resetLayout)
79  {
80  this->addToLayout(b);
81  }
82 
83  return b;
84  }
85 
87  template <typename T> T* addActionWithIcon(const std::string& icon, bool resetLayout = true)
88  {
89  T* b = createButton<T>();
90 
92 
93  if (resetLayout)
94  {
95  this->addToLayout(b);
96  }
97 
98  return b;
99  }
100 
102  template <typename T> T* addAction(const QIcon& icon, bool resetLayout = true)
103  {
104  T* b = createButton<T>();
105 
106  b->setIcon(icon);
107 
108  if (resetLayout)
109  {
110  this->addToLayout(b);
111  }
112 
113  return b;
114  }
115 
117  template <typename T> T* addAction(QAction* act, bool resetLayout = true)
118  {
119  T* b = createButton<T>();
120  b->setAutoRaise(true);
121  b->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
122  b->setDefaultAction(act);
123 
124  if (resetLayout)
125  {
126  this->addToLayout(b);
127  }
128 
129  return b;
130  }
131 
133  virtual int rightMarginForLine(int) const;
134 
137  virtual void setRightMarginForLine(int margin, int line = -1);
138 
140  virtual void removeRightMarginForLine(int line = -1);
141 
143  virtual void removeButton(QAbstractButton*, bool resetLayout = true);
144 
146  virtual void layoutButtons(bool force = false);
147 
150  virtual void setButtons(const std::vector<QAbstractButton*>& buttons, bool deleteCurrentButtons = false);
151 
153  virtual void setRightToLeftLayout(bool);
154  bool setRightToLeftLayout() const
155  {
156  return myRightToLeftLayout;
157  }
158 
159  bool needsLayout() const
160  {
161  return myNeedsLayout;
162  }
163 
165  enum SizeMode
166  {
167  FillAtEnd = 1,
168  SizeToFit = 2,
169  SingleColumn = 3
170  };
171 
172  virtual void setSizeMode(SizeMode);
174  {
175  return mySizeMode;
176  }
177 
178  int buttonsShown() const
179  {
180  return myButtonsShown;
181  }
182 
183  const std::vector<QAbstractButton*>& buttons() const
184  {
185  return myButtons;
186  }
187 
188  std::vector<QAbstractButton*>& buttons()
189  {
190  return myButtons;
191  }
192 
193  virtual bool hasButton(QAbstractButton*) const;
194 
196  virtual void setIconSize(const QSize&);
197  const QSize& iconSize() const
198  {
199  return myIconSize;
200  }
201 
203  virtual void setIconSpacing(int);
204  int iconSpacing() const
205  {
206  return myIconSpacing;
207  }
208 
210  virtual void clear();
211 
213  virtual void setUseFixedWidth(bool);
214  bool useFixedWidth() const
215  {
216  return myUseFixedWidth;
217  }
218 
219  virtual void fixWidth();
220  virtual void fixHeight();
221 
223  virtual void setFixedButtonWidth(int);
224  int fixedButtonWidth() const
225  {
226  return myFixedButtonWidth;
227  }
228 
231  virtual void setFixedButtonHeight(int);
232  int fixedButtonHeight() const
233  {
234  return myFixedButtonHeight;
235  }
236 
238  int layoutHeight() const
239  {
240  return myLayouts.size() * fixedButtonHeight();
241  }
242 
244  virtual void setShowMaximum(int);
245  int showMaximum() const
246  {
247  return myShowMaximum;
248  }
249 
251  virtual void setMaximumLines(int);
252  int maximumLines() const
253  {
254  return myMaximumLines;
255  }
256 
257  bool reachedMaximum() const
258  {
259  return myReachedMaximum;
260  }
261 
262  virtual bool buttonsLeftToDisplay() const;
263 
264  int numRows() const
265  {
266  return myLayouts.size();
267  }
268 
269  const std::vector<Layout>& layouts() const
270  {
271  return myLayouts;
272  }
273 
274  std::vector<Layout>& layouts()
275  {
276  return myLayouts;
277  }
278 
280  virtual void setBlockResizeLayout(bool);
281  bool blockResizeLayout() const
282  {
283  return myBlockResizeLayout;
284  }
285 
287  virtual void setSignalResizeLayout(bool);
288  bool signalResizeLayout() const
289  {
290  return mySignalResizeLayout;
291  }
292 
294  virtual void setCreateDefaultIcon(bool b);
295  bool createDefaultIcon() const
296  {
297  return myCreateDefaultIcon;
298  }
299 
301  virtual void setSetToolTipToText(bool);
302  bool setToolTipToText() const
303  {
304  return mySetToolTipToText;
305  }
306 
307  virtual void setSizeHeightToLayout(bool);
308  bool sizeHeightToLayout() const
309  {
310  return mySizeHeightToLayout;
311  }
312 
313  boost::signals2::signal<void ()> signal_resizeLayout;
314  boost::signals2::signal<void (bool)> signal_maximumReached;
315 
316  public:
317  boost::signals2::signal<void ()> signal_buttonsLayedOut;
318  boost::signals2::signal<void (Layout&, QAbstractButton*)> signal_buttonLayedOut;
319 
320  protected slots:
321  virtual void layoutFromTimer();
322 
323  protected:
324  virtual QPixmap createDefaultIcon(const QString&) const;
325  virtual void resizeEvent(QResizeEvent*);
326  virtual void showEvent(QShowEvent*);
327  virtual void addToLayout(QAbstractButton*, bool forceLayout = false);
328 
329  protected:
330  std::vector<Layout> myLayouts;
331  std::vector<QAbstractButton*> myButtons;
332  std::map<int, int> myRightMarginForLine;
333 
334  QSize myIconSize;
351  bool mySizeHeightToLayout = false;
352 
355  };
356 }
SizeMode sizeMode() const
Definition: toolButtonWrapperWidget.h:173
const std::vector< Layout > & layouts() const
Definition: toolButtonWrapperWidget.h:269
bool setToolTipToText() const
Definition: toolButtonWrapperWidget.h:302
bool signalResizeLayout() const
Definition: toolButtonWrapperWidget.h:288
int myShowMaximum
Definition: toolButtonWrapperWidget.h:342
bool mySetTimer
Definition: toolButtonWrapperWidget.h:345
T * addAction(const QIcon &icon, bool resetLayout=true)
Adds a new button with an icon.
Definition: toolButtonWrapperWidget.h:102
const std::vector< QAbstractButton * > & buttons() const
Definition: toolButtonWrapperWidget.h:183
int numRows() const
Definition: toolButtonWrapperWidget.h:264
int myIconSpacing
Definition: toolButtonWrapperWidget.h:335
This class will try and space out items such that they will wrap to multiple rows if buttons (or text...
Definition: toolButtonWrapperWidget.h:32
int myButtonsShown
Definition: toolButtonWrapperWidget.h:343
std::vector< Layout > myLayouts
Definition: toolButtonWrapperWidget.h:330
int maximumLines() const
Definition: toolButtonWrapperWidget.h:252
int iconSpacing() const
Definition: toolButtonWrapperWidget.h:204
makVrv::DtDe & myDe
Definition: toolButtonWrapperWidget.h:354
const QSize & iconSize() const
Definition: toolButtonWrapperWidget.h:197
Definition: toolButtonWrapperWidget.h:37
std::vector< QAbstractButton * > & buttons()
Definition: toolButtonWrapperWidget.h:188
Contains makVrv::DtWidgetIconStyleManager class declaration.
bool myRightToLeftLayout
Definition: toolButtonWrapperWidget.h:341
T * addAction(const QString &action, bool resetLayout=true)
Adds a new button with text. Up to caller to determine what to do with the returned tool button...
Definition: toolButtonWrapperWidget.h:73
bool myUseFixedWidth
Definition: toolButtonWrapperWidget.h:348
QSpacerItem * spacerItem
Definition: toolButtonWrapperWidget.h:43
std::vector< Layout > & layouts()
Definition: toolButtonWrapperWidget.h:274
static DtWidgetIconStyleManager & instance(DtDe &de)
Returns a reference to the DtWidgetIconStyleManager instance This function will register the manager ...
bool myInResize
Definition: toolButtonWrapperWidget.h:344
bool needsLayout() const
Definition: toolButtonWrapperWidget.h:159
bool setRightToLeftLayout() const
Definition: toolButtonWrapperWidget.h:154
int myFixedButtonHeight
Definition: toolButtonWrapperWidget.h:340
bool myBlockResizeLayout
Definition: toolButtonWrapperWidget.h:346
bool mySignalResizeLayout
Definition: toolButtonWrapperWidget.h:347
bool myNeedsLayout
Definition: toolButtonWrapperWidget.h:337
bool useFixedWidth() const
Definition: toolButtonWrapperWidget.h:214
boost::signals2::signal< void(Layout &, QAbstractButton *)> signal_buttonLayedOut
Definition: toolButtonWrapperWidget.h:318
int fixedButtonHeight() const
Definition: toolButtonWrapperWidget.h:232
bool mySetToolTipToText
Definition: toolButtonWrapperWidget.h:350
QHBoxLayout * layout
Definition: toolButtonWrapperWidget.h:40
T * createPrototype()
Definition: toolButtonWrapperWidget.h:52
int buttonsShown() const
Definition: toolButtonWrapperWidget.h:178
SizeMode
Sets the mode of display. Default is FillByRank.
Definition: toolButtonWrapperWidget.h:165
SizeMode mySizeMode
Definition: toolButtonWrapperWidget.h:353
virtual void manageWidget(QObject *widgetToManage, const std::string &iconFileNameOrPath)
Add a new widget to the manager. The manager will now manage the icon style for the widget...
#define DT_DLL_VRFGUICOMMONQT
Definition: vrfGuiCommonQt.h:20
boost::signals2::signal< void(bool)> signal_maximumReached
Definition: toolButtonWrapperWidget.h:314
std::map< int, int > myRightMarginForLine
Definition: toolButtonWrapperWidget.h:332
boost::signals2::signal< void()> signal_buttonsLayedOut
Definition: toolButtonWrapperWidget.h:317
int layoutHeight() const
The layout height is the number of layouts by the fixed button height.
Definition: toolButtonWrapperWidget.h:238
bool reachedMaximum() const
Definition: toolButtonWrapperWidget.h:257
bool sizeHeightToLayout() const
Definition: toolButtonWrapperWidget.h:308
T * addActionWithIcon(const std::string &icon, bool resetLayout=true)
Adds a new button with a managed icon.
Definition: toolButtonWrapperWidget.h:87
bool blockResizeLayout() const
Definition: toolButtonWrapperWidget.h:281
int showMaximum() const
Definition: toolButtonWrapperWidget.h:245
std::vector< QAbstractButton * > buttons
Definition: toolButtonWrapperWidget.h:41
bool myCreateDefaultIcon
Definition: toolButtonWrapperWidget.h:349
boost::signals2::signal< void()> signal_resizeLayout
Definition: toolButtonWrapperWidget.h:313
bool myReachedMaximum
Definition: toolButtonWrapperWidget.h:338
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:72
int myFixedButtonWidth
Definition: toolButtonWrapperWidget.h:339
int currentWidth
Definition: toolButtonWrapperWidget.h:42
T * addAction(QAction *act, bool resetLayout=true)
Adds a new action into the dialog for sizing.
Definition: toolButtonWrapperWidget.h:117
QSize myIconSize
Definition: toolButtonWrapperWidget.h:334
int fixedButtonWidth() const
Definition: toolButtonWrapperWidget.h:224
std::vector< QAbstractButton * > myButtons
Definition: toolButtonWrapperWidget.h:331
T * createButton()
Definition: toolButtonWrapperWidget.h:63
bool createDefaultIcon() const
Definition: toolButtonWrapperWidget.h:295
int myMaximumLines
Definition: toolButtonWrapperWidget.h:336

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)