Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Data Structures | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes
omni::ui::proj::TuningLayout Class Reference

Tuning Layout Similar to VBoxLayout, except that widgets with a PREVIEW Role have a size with aspect ratio of associated tuning. More...

#include <TuningLayout.h>

Inheritance diagram for omni::ui::proj::TuningLayout:
Inheritance graph
[legend]
Collaboration diagram for omni::ui::proj::TuningLayout:
Collaboration graph
[legend]

Data Structures

struct  ItemWrapper
 

Public Types

enum  Role { Role::TITLE, Role::PARAMETER, Role::PREVIEW }
 Role of a widget defines resize behaviour. More...
 
typedef std::vector< std::pair
< QWidget *, Role > > 
widgetgroup_type
 

Public Member Functions

 TuningLayout (Tuning *parent)
 
 ~TuningLayout ()
 
void addItem (QLayoutItem *item)
 Add item, with PARAMETER Role. More...
 
void addWidget (QWidget *widget)
 Add widget with PARAMETER Role. More...
 
void addWidget (QWidget *widget, Role)
 Add widget with Role. More...
 
int count () const
 Return number of widgets. More...
 
int indexOf (QWidget *widget) const
 Get index of given widget. More...
 
QLayoutItem * itemAt (int index) const
 Return item at index. More...
 
QLayoutItem * takeAt (int index)
 Remove widget at index. More...
 
void setGeometry (const QRect &rect)
 Set geometry of all widgets. More...
 
QRect geometry () const
 
void setWidgets (widgetgroup_type const &_widgets)
 Clears layout and inserts the given widgets. More...
 
void clear ()
 Clear layout. More...
 
QSize minimumSize () const
 Return minimum size. More...
 
QSize sizeHint () const
 Return size hint, is equal to minimum size. More...
 

Private Types

enum  SizeType { MINIMUMSIZE, SIZEHINT }
 

Private Member Functions

omni::proj::Tuningtuning ()
 
omni::proj::Tuning const * tuning () const
 
void add (QLayoutItem *_item, Role _role)
 Add a layout item with Role. More...
 
QSize calculateSize (SizeType sizeType) const
 

Private Attributes

std::vector< ItemWrapperitems_
 

Detailed Description

Tuning Layout Similar to VBoxLayout, except that widgets with a PREVIEW Role have a size with aspect ratio of associated tuning.

Member Typedef Documentation

typedef std::vector<std::pair<QWidget *, Role> > omni::ui::proj::TuningLayout::widgetgroup_type

Member Enumeration Documentation

Role of a widget defines resize behaviour.

Enumerator
TITLE 
PARAMETER 
PREVIEW 
40  {
41  TITLE, // Fixed size
42  PARAMETER, // Fixed size
43  PREVIEW // Size with aspect ratio of tuning
44  };
Enumerator
MINIMUMSIZE 
SIZEHINT 
114 { MINIMUMSIZE, SIZEHINT };
Definition: TuningLayout.h:114
Definition: TuningLayout.h:114

Constructor & Destructor Documentation

omni::ui::proj::TuningLayout::TuningLayout ( Tuning parent)
28  :
29  QLayout(_parent)
30  {}
omni::ui::proj::TuningLayout::~TuningLayout ( )
33  {
34  clear();
35  }
void clear()
Clear layout.
Definition: TuningLayout.cpp:146

Member Function Documentation

void omni::ui::proj::TuningLayout::add ( QLayoutItem *  _item,
Role  _role 
)
private

Add a layout item with Role.

198  {
199  items_.emplace_back(_item, _role);
200  invalidate();
201  }
std::vector< ItemWrapper > items_
Definition: TuningLayout.h:117
void omni::ui::proj::TuningLayout::addItem ( QLayoutItem *  item)

Add item, with PARAMETER Role.

38  {
39  add(_item, Role::PARAMETER);
40  }
void add(QLayoutItem *_item, Role _role)
Add a layout item with Role.
Definition: TuningLayout.cpp:197
void omni::ui::proj::TuningLayout::addWidget ( QWidget *  widget)

Add widget with PARAMETER Role.

43  {
44  add(new QWidgetItem(widget), Role::PARAMETER);
45  }
void add(QLayoutItem *_item, Role _role)
Add a layout item with Role.
Definition: TuningLayout.cpp:197
void omni::ui::proj::TuningLayout::addWidget ( QWidget *  widget,
Role  _role 
)

Add widget with Role.

48  {
49  add(new QWidgetItem(widget), _role);
50  }
void add(QLayoutItem *_item, Role _role)
Add a layout item with Role.
Definition: TuningLayout.cpp:197
QSize omni::ui::proj::TuningLayout::calculateSize ( SizeType  sizeType) const
private

Increase height by aspect ratio

89  {
90  if (!tuning()) return QSize(0, 0);
91 
92 
93  int _border = 2;
94  int _width = 0;
95  int _height = _border;
96 
97  auto _parent = static_cast<Tuning *>(parent());
98 
99  for (auto& _item : items_)
100  {
101  switch (_item.role_)
102  {
103  case Role::PARAMETER:
104  case Role::TITLE:
105  _height += 36 / _parent->devicePixelRatio();
106  break;
107 
108  case Role::PREVIEW:
109 
110  if (!tuning()) continue;
111 
112  /// Increase height by aspect ratio
113  _height += _parent->width() /
114  float(tuning()->width()) * tuning()->height();
115  break;
116  }
117  }
118  _height += _border;
119 
120  return QSize(_width, _height);
121  }
std::vector< ItemWrapper > items_
Definition: TuningLayout.h:117
omni::proj::Tuning * tuning()
Definition: TuningLayout.cpp:123
int height() const
Returns height of screen.
Definition: Tuning.cpp:192
void omni::ui::proj::TuningLayout::clear ( )

Clear layout.

147  {
148  QLayoutItem *l;
149 
150  while ((l = takeAt(0))) delete l;
151  }
QLayoutItem * takeAt(int index)
Remove widget at index.
Definition: TuningLayout.cpp:76
int omni::ui::proj::TuningLayout::count ( ) const

Return number of widgets.

53  {
54  return items_.size();
55  }
std::vector< ItemWrapper > items_
Definition: TuningLayout.h:117
QRect omni::ui::proj::TuningLayout::geometry ( ) const
190  {
191  auto _rect = QLayout::geometry();
192 
193  _rect.setWidth(_rect.width() - 16);
194  return _rect;
195  }
int omni::ui::proj::TuningLayout::indexOf ( QWidget *  widget) const

Get index of given widget.

58  {
59  int _index = -1;
60 
61  for (auto& _item : items_)
62  {
63  if (_item.widget() == widget) return _index;
64 
65  ++_index;
66  }
67  return _index;
68  }
std::vector< ItemWrapper > items_
Definition: TuningLayout.h:117
QLayoutItem * omni::ui::proj::TuningLayout::itemAt ( int  index) const

Return item at index.

71  {
72  return (index >= 0 &&
73  index < items_.size()) ? items_[index].item_ : nullptr;
74  }
std::vector< ItemWrapper > items_
Definition: TuningLayout.h:117
QSize omni::ui::proj::TuningLayout::minimumSize ( ) const

Return minimum size.

154  {
155  return calculateSize(MINIMUMSIZE);
156  }
QSize calculateSize(SizeType sizeType) const
Definition: TuningLayout.cpp:88
Definition: TuningLayout.h:114
void omni::ui::proj::TuningLayout::setGeometry ( const QRect &  rect)

Set geometry of all widgets.

Adjust geometry for each widget

Widget height is constant except for preview

Increase height

164  {
165  if (!tuning()) return;
166 
167  const int _border = 2;
168  int _height = _border;
169 
170  auto _parent = static_cast<Tuning *>(parent());
171 
172  /// Adjust geometry for each widget
173  for (auto& _item : items_)
174  {
175  auto _widget = _item.widget();
176 
177  /// Widget height is constant except for preview
178  int _widgetHeight = _item.role_ == Role::PREVIEW ? _parent->width() /
179  float(tuning()->width()) * tuning()->height() :
180  36 / _parent->devicePixelRatio();
181  _widget->setGeometry(_border, _height,
182  _parent->width() - _border * 2, _widgetHeight);
183  _widget->show();
184 
185  /// Increase height
186  _height += _widgetHeight;
187  }
188  }
std::vector< ItemWrapper > items_
Definition: TuningLayout.h:117
omni::proj::Tuning * tuning()
Definition: TuningLayout.cpp:123
int height() const
Returns height of screen.
Definition: Tuning.cpp:192
void omni::ui::proj::TuningLayout::setWidgets ( widgetgroup_type const &  _widgets)

Clears layout and inserts the given widgets.

134  {
135  clear();
136 
137  for (auto& _widgetRole : _widgets)
138  {
139  auto& _widget = _widgetRole.first;
140  auto& _role = _widgetRole.second;
141  addWidget(_widget, _role);
142  }
143  update();
144  }
void addWidget(QWidget *widget)
Add widget with PARAMETER Role.
Definition: TuningLayout.cpp:42
void clear()
Clear layout.
Definition: TuningLayout.cpp:146
QSize omni::ui::proj::TuningLayout::sizeHint ( ) const

Return size hint, is equal to minimum size.

159  {
160  return calculateSize(SIZEHINT);
161  }
Definition: TuningLayout.h:114
QSize calculateSize(SizeType sizeType) const
Definition: TuningLayout.cpp:88
QLayoutItem * omni::ui::proj::TuningLayout::takeAt ( int  index)

Remove widget at index.

77  {
78  QLayoutItem *_item = itemAt(index);
79 
80  if (_item)
81  {
82  items_.erase(items_.begin() + index);
83  return _item;
84  }
85  return nullptr;
86  }
std::vector< ItemWrapper > items_
Definition: TuningLayout.h:117
QLayoutItem * itemAt(int index) const
Return item at index.
Definition: TuningLayout.cpp:70
omni::proj::Tuning * omni::ui::proj::TuningLayout::tuning ( )
private
124  {
125  return static_cast<Tuning *>(parent())->tuning();
126  }
omni::proj::Tuning * tuning()
Definition: TuningLayout.cpp:123
omni::proj::Tuning const * omni::ui::proj::TuningLayout::tuning ( ) const
private
129  {
130  return static_cast<Tuning const *>(parent())->tuning();
131  }
omni::proj::Tuning * tuning()
Definition: TuningLayout.cpp:123

Field Documentation

std::vector<ItemWrapper> omni::ui::proj::TuningLayout::items_
private

The documentation for this class was generated from the following files: