Loading...
Searching...
No Matches
lib/score/widgets/Layout.hpp
1#pragma once
2#include <QComboBox>
3#include <QFormLayout>
4#include <QGridLayout>
5#include <QLabel>
6#include <QVBoxLayout>
7
8namespace score
9{
10// Custom form layout due to
11// https://stackoverflow.com/questions/41715124/qformlayout-does-not-expand-widget-full-height-to-maximum-widget-height
12class FormLayout : public QGridLayout
13{
14public:
15 void addRow(QString&& text, QWidget* widg)
16 {
17 const auto nextRow = rowCount();
18 addWidget(
19 new QLabel{std::move(text)}, nextRow, 0, 1, 1, Qt::AlignHCenter | Qt::AlignTop);
20 addWidget(widg, nextRow, 1, 1, 1);
21 }
22};
23}
24
25// REFACTORME - find a better name
26namespace Inspector
27{
36inline void fitInInspector(QWidget* w)
37{
38 if(!w)
39 return;
40
41 auto fit = [](QComboBox* cb) {
42 cb->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
43 cb->setMinimumContentsLength(8);
44 };
45
46 if(auto cb = qobject_cast<QComboBox*>(w))
47 fit(cb);
48 for(auto cb : w->findChildren<QComboBox*>())
49 fit(cb);
50}
51
52class Layout final : public QFormLayout
53{
54public:
55 Layout(QWidget* widg = nullptr)
56 : QFormLayout{widg}
57 {
58 this->setContentsMargins(0, 0, 0, 0);
59 this->setSpacing(3);
60 this->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
61 // this->setLabelAlignment(Qt::AlignRight);
62 }
63
64 // Every widget going through here is fitted to the panel (see
65 // fitInInspector); the QFormLayout overloads are not virtual, so the
66 // layout has to be used as an Inspector::Layout for that to apply.
67 void addRow(QWidget* label, QWidget* field)
68 {
69 fitInInspector(field);
70 QFormLayout::addRow(label, field);
71 }
72 void addRow(const QString& label, QWidget* field)
73 {
74 fitInInspector(field);
75 QFormLayout::addRow(label, field);
76 }
77 void addRow(QWidget* w)
78 {
80 QFormLayout::addRow(w);
81 }
82 void insertRow(int row, QWidget* label, QWidget* field)
83 {
84 fitInInspector(field);
85 QFormLayout::insertRow(row, label, field);
86 }
87 void insertRow(int row, const QString& label, QWidget* field)
88 {
89 fitInInspector(field);
90 QFormLayout::insertRow(row, label, field);
91 }
92 void insertRow(int row, QWidget* w)
93 {
95 QFormLayout::insertRow(row, w);
96 }
97 using QFormLayout::addRow;
98 using QFormLayout::insertRow;
99};
100
101class VBoxLayout final : public QVBoxLayout
102{
103public:
104 VBoxLayout(QWidget* widg = nullptr)
105 : QVBoxLayout{widg}
106 {
107 this->setContentsMargins(0, 0, 0, 0);
108 this->setSpacing(3);
109 }
110};
111}
Definition lib/score/widgets/Layout.hpp:53
Definition lib/score/widgets/Layout.hpp:102
Definition lib/score/widgets/Layout.hpp:13
Classes used for making and extending the inspector (default right panel).
Definition lib/score/widgets/Layout.hpp:27
void fitInInspector(QWidget *w)
Keeps a widget from forcing the inspector wider than its panel.
Definition lib/score/widgets/Layout.hpp:36
Base toolkit upon which the software is built.
Definition Application.cpp:117