Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
DDqtControls.h
Go to the documentation of this file.
1/* This file is part of MoDELib, distributed under GNU GPL v2. */
2#ifndef model_DDqtControls_H_
3#define model_DDqtControls_H_
4#include <QCheckBox>
5#include <QGroupBox>
6#include <QGridLayout>
7#include <QLabel>
8#include <QVBoxLayout>
9#include <QShowEvent>
10
12{
13 // Keep the contents in one widget so collapsing preserves each child's own
14 // visibility, enabled state, and nested group selection.
15 class GroupBox : public QGroupBox
16 {
17 QWidget *body = nullptr;
18
19 protected:
20 void showEvent(QShowEvent *event) override;
21
22 public:
23 explicit GroupBox(const QString &title, QWidget *parent = nullptr);
24 };
25
26 inline QGroupBox *box(const QString &title, QWidget *parent, const QString &description,
27 QCheckBox *toggle = nullptr)
28 {
29 auto *group = new GroupBox(title, parent);
30 group->setToolTip(description);
31 group->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
32 new QGridLayout(group);
33 if (toggle)
34 {
35 // Preserve existing actor handlers and programmatic state changes;
36 // the visible group checkbox is the single user-facing control.
37 group->setCheckable(true);
38 group->setChecked(toggle->isChecked());
39 toggle->hide();
40 QObject::connect(group, &QGroupBox::toggled, toggle, &QCheckBox::setChecked);
41 QObject::connect(toggle, &QCheckBox::toggled, group, &QGroupBox::setChecked);
42 }
43 return group;
44 }
45
46 inline QGridLayout *grid(QGroupBox *group)
47 {
48 return static_cast<QGridLayout *>(group->layout());
49 }
50
51 inline void field(QGridLayout *layout, int row, const QString &title, QWidget *input, const QString &description)
52 {
53 auto *label = new QLabel(title);
54 label->setBuddy(input);
55 label->setToolTip(description);
56 input->setToolTip(description);
57 input->setAccessibleName(title);
58 layout->addWidget(label, row, 0);
59 layout->addWidget(input, row, 1);
60 layout->setColumnStretch(1, 1);
61 }
62} // namespace model::controls
63#endif
void showEvent(QShowEvent *event) override
GroupBox(const QString &title, QWidget *parent=nullptr)
QGridLayout * grid(QGroupBox *group)
QGroupBox * box(const QString &title, QWidget *parent, const QString &description, QCheckBox *toggle=nullptr)
void field(QGridLayout *layout, int row, const QString &title, QWidget *input, const QString &description)
int parent