Chatterino
LayoutHelper.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QLayout>
4 #include <boost/variant.hpp>
5 
6 class QWidget;
7 class QScrollArea;
8 
9 namespace chatterino {
10 
11 using LayoutItem = boost::variant<QWidget *, QLayoutItem *>;
12 using WidgetOrLayout = boost::variant<QWidget *, QLayout *>;
13 
14 QWidget *wrapLayout(QLayout *layout);
15 QScrollArea *makeScrollArea(WidgetOrLayout item);
16 
17 template <typename T>
18 T *makeLayout(std::initializer_list<LayoutItem> items)
19 {
20  auto t = new T;
21 
22  for (auto &item : items)
23  {
24  switch (item.which())
25  {
26  case 0:
27  t->addItem(new QWidgetItem(boost::get<QWidget *>(item)));
28  break;
29  case 1:
30  t->addItem(boost::get<QLayoutItem *>(item));
31  break;
32  }
33  }
34 
35  t->setContentsMargins(0, 0, 0, 0);
36 
37  return t;
38 }
39 
40 template <typename T, typename With>
41 T *makeWidget(With with)
42 {
43  auto t = new T;
44 
45  with(t);
46 
47  return t;
48 }
49 
50 } // namespace chatterino
QScrollArea * makeScrollArea(WidgetOrLayout item)
Definition: LayoutHelper.cpp:15
Definition: Application.cpp:48
QWidget * wrapLayout(QLayout *layout)
Definition: LayoutHelper.cpp:8
boost::variant< QWidget *, QLayout * > WidgetOrLayout
Definition: LayoutHelper.hpp:12
T * makeLayout(std::initializer_list< LayoutItem > items)
Definition: LayoutHelper.hpp:18
T * makeWidget(With with)
Definition: LayoutHelper.hpp:41
boost::variant< QWidget *, QLayoutItem * > LayoutItem
Definition: LayoutHelper.hpp:11