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  Center = 4
171  };
172 
173  virtual void setSizeMode(SizeMode);
175  {
176  return mySizeMode;
177  }
178 
179  int buttonsShown() const
180  {
181  return myButtonsShown;
182  }
183 
184  const std::vector<QAbstractButton*>& buttons() const
185  {
186  return myButtons;
187  }
188 
189  std::vector<QAbstractButton*>& buttons()
190  {
191  return myButtons;
192  }
193 
194  virtual bool hasButton(QAbstractButton*) const;
195 
197  virtual void setIconSize(const QSize&);
198  const QSize& iconSize() const
199  {
200  return myIconSize;
201  }
202 
204  virtual void setIconSpacing(int);
205  int iconSpacing() const
206  {
207  return myIconSpacing;
208  }
209 
211  virtual void clear();
212 
214  virtual void setUseFixedWidth(bool);
215  bool useFixedWidth() const
216  {
217  return myUseFixedWidth;
218  }
219 
220  virtual void fixWidth();
221  virtual void fixHeight();
222 
224  virtual void setFixedButtonWidth(int);
225  int fixedButtonWidth() const
226  {
227  return myFixedButtonWidth;
228  }
229 
232  virtual void setFixedButtonHeight(int);
233  int fixedButtonHeight() const
234  {
235  return myFixedButtonHeight;
236  }
237 
239  int layoutHeight() const
240  {
241  return myLayouts.size() * fixedButtonHeight();
242  }
243 
245  virtual void setShowMaximum(int);
246  int showMaximum() const
247  {
248  return myShowMaximum;
249  }
250 
252  virtual void setMaximumLines(int);
253  int maximumLines() const
254  {
255  return myMaximumLines;
256  }
257 
258  bool reachedMaximum() const
259  {
260  return myReachedMaximum;
261  }
262 
263  virtual bool buttonsLeftToDisplay() const;
264 
265  int numRows() const
266  {
267  return myLayouts.size();
268  }
269 
270  const std::vector<Layout>& layouts() const
271  {
272  return myLayouts;
273  }
274 
275  std::vector<Layout>& layouts()
276  {
277  return myLayouts;
278  }
279 
281  virtual void setBlockResizeLayout(bool);
282  bool blockResizeLayout() const
283  {
284  return myBlockResizeLayout;
285  }
286 
288  virtual void setSignalResizeLayout(bool);
289  bool signalResizeLayout() const
290  {
291  return mySignalResizeLayout;
292  }
293 
295  virtual void setCreateDefaultIcon(bool b);
296  bool createDefaultIcon() const
297  {
298  return myCreateDefaultIcon;
299  }
300 
302  virtual void setSetToolTipToText(bool);
303  bool setToolTipToText() const
304  {
305  return mySetToolTipToText;
306  }
307 
308  virtual void setSizeHeightToLayout(bool);
309  bool sizeHeightToLayout() const
310  {
311  return mySizeHeightToLayout;
312  }
313 
314  boost::signals2::signal<void ()> signal_resizeLayout;
315  boost::signals2::signal<void (bool)> signal_maximumReached;
316 
317  public:
318  boost::signals2::signal<void ()> signal_buttonsLayedOut;
319  boost::signals2::signal<void (Layout&, QAbstractButton*)> signal_buttonLayedOut;
320 
321  protected slots:
322  virtual void layoutFromTimer();
323 
324  protected:
325  virtual QPixmap createDefaultIcon(const QString&) const;
326  virtual void resizeEvent(QResizeEvent*);
327  virtual void showEvent(QShowEvent*);
328  virtual void addToLayout(QAbstractButton*, bool forceLayout = false);
329 
330  protected:
331  std::vector<Layout> myLayouts;
332  std::vector<QAbstractButton*> myButtons;
333  std::map<int, int> myRightMarginForLine;
334 
335  QSize myIconSize;
352  bool mySizeHeightToLayout = false;
353 
356  };
357 }
SizeMode sizeMode() const
Definition: toolButtonWrapperWidget.h:174
const std::vector< Layout > & layouts() const
Definition: toolButtonWrapperWidget.h:270
bool setToolTipToText() const
Definition: toolButtonWrapperWidget.h:303
bool signalResizeLayout() const
Definition: toolButtonWrapperWidget.h:289
int myShowMaximum
Definition: toolButtonWrapperWidget.h:343
bool mySetTimer
Definition: toolButtonWrapperWidget.h:346
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:184
int numRows() const
Definition: toolButtonWrapperWidget.h:265
int myIconSpacing
Definition: toolButtonWrapperWidget.h:336
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:344
std::vector< Layout > myLayouts
Definition: toolButtonWrapperWidget.h:331
int maximumLines() const
Definition: toolButtonWrapperWidget.h:253
int iconSpacing() const
Definition: toolButtonWrapperWidget.h:205
makVrv::DtDe & myDe
Definition: toolButtonWrapperWidget.h:355
const QSize & iconSize() const
Definition: toolButtonWrapperWidget.h:198
Definition: toolButtonWrapperWidget.h:37
std::vector< QAbstractButton * > & buttons()
Definition: toolButtonWrapperWidget.h:189
Contains makVrv::DtWidgetIconStyleManager class declaration.
bool myRightToLeftLayout
Definition: toolButtonWrapperWidget.h:342
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:349
QSpacerItem * spacerItem
Definition: toolButtonWrapperWidget.h:43
std::vector< Layout > & layouts()
Definition: toolButtonWrapperWidget.h:275
static DtWidgetIconStyleManager & instance(DtDe &de)
Returns a reference to the DtWidgetIconStyleManager instance This function will register the manager ...
bool myInResize
Definition: toolButtonWrapperWidget.h:345
bool needsLayout() const
Definition: toolButtonWrapperWidget.h:159
bool setRightToLeftLayout() const
Definition: toolButtonWrapperWidget.h:154
int myFixedButtonHeight
Definition: toolButtonWrapperWidget.h:341
bool myBlockResizeLayout
Definition: toolButtonWrapperWidget.h:347
bool mySignalResizeLayout
Definition: toolButtonWrapperWidget.h:348
bool myNeedsLayout
Definition: toolButtonWrapperWidget.h:338
bool useFixedWidth() const
Definition: toolButtonWrapperWidget.h:215
boost::signals2::signal< void(Layout &, QAbstractButton *)> signal_buttonLayedOut
Definition: toolButtonWrapperWidget.h:319
int fixedButtonHeight() const
Definition: toolButtonWrapperWidget.h:233
bool mySetToolTipToText
Definition: toolButtonWrapperWidget.h:351
QHBoxLayout * layout
Definition: toolButtonWrapperWidget.h:40
T * createPrototype()
Definition: toolButtonWrapperWidget.h:52
int buttonsShown() const
Definition: toolButtonWrapperWidget.h:179
SizeMode
Sets the mode of display. Default is FillByRank.
Definition: toolButtonWrapperWidget.h:165
SizeMode mySizeMode
Definition: toolButtonWrapperWidget.h:354
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:315
std::map< int, int > myRightMarginForLine
Definition: toolButtonWrapperWidget.h:333
boost::signals2::signal< void()> signal_buttonsLayedOut
Definition: toolButtonWrapperWidget.h:318
int layoutHeight() const
The layout height is the number of layouts by the fixed button height.
Definition: toolButtonWrapperWidget.h:239
bool reachedMaximum() const
Definition: toolButtonWrapperWidget.h:258
bool sizeHeightToLayout() const
Definition: toolButtonWrapperWidget.h:309
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:282
int showMaximum() const
Definition: toolButtonWrapperWidget.h:246
std::vector< QAbstractButton * > buttons
Definition: toolButtonWrapperWidget.h:41
bool myCreateDefaultIcon
Definition: toolButtonWrapperWidget.h:350
boost::signals2::signal< void()> signal_resizeLayout
Definition: toolButtonWrapperWidget.h:314
bool myReachedMaximum
Definition: toolButtonWrapperWidget.h:339
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:340
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:335
int fixedButtonWidth() const
Definition: toolButtonWrapperWidget.h:225
std::vector< QAbstractButton * > myButtons
Definition: toolButtonWrapperWidget.h:332
T * createButton()
Definition: toolButtonWrapperWidget.h:63
bool createDefaultIcon() const
Definition: toolButtonWrapperWidget.h:296
int myMaximumLines
Definition: toolButtonWrapperWidget.h:337

Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)