YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
customgroupbox.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6
7#include "customgroupbox.h"
8#include "ui_customgroupbox.h"
9
11 : QPushButton(parent)
12{
13
14}
15
20
22 QWidget(parent),
23 ui(new Ui::CustomGroupBox),
24 m_visible(true)
25{
26 ui->setupUi(this);
27 m_layout = new QVBoxLayout;
28 m_layout->setMargin(0);
29 ui->frame->setLayout(m_layout);
30 const int minHeight = 10; //This avoids the containing scroll area to add too much white space
31 ui->contentWidget->setMinimumHeight(minHeight);
32
33 toggle(true);
34
35 connect(ui->arrowButton, SIGNAL(clicked(bool)), this, SLOT(onArrowPressed(bool)));
36 connect(ui->header, SIGNAL(sig_titleDoubleClick()), this, SLOT(onTitleDoubleClick()));
37
38 ui->header->setAttribute(Qt::WA_StyledBackground, true);
39
40 QAction* expandAll = m_contextMenu.addAction("Expand all");
41 connect(expandAll, SIGNAL(triggered()), this, SLOT(onExpandAll()));
42
43 QAction* collapseAll = m_contextMenu.addAction("Collapse all");
44 connect(collapseAll, SIGNAL(triggered()), this, SLOT(onCollapseAll()));
45
46}
47
49{
50 delete ui;
51}
52
53void CustomGroupBox::setTitle(const QString &string)
54{
55 ui->header->setText(string);
56}
57
58void CustomGroupBox::setTitleBackgroundColor(const QColor &backgroundColor)
59{
60
61 QString stileSheet = QString("text-align: left; color: rgb(35, 38, 41); background-color: rgb(%1, %2, %3)")
62 .arg(backgroundColor.red()).arg(backgroundColor.green()).arg(backgroundColor.blue());
63 ui->header->setStyleSheet(stileSheet);
64}
65
67{
68 QString stileSheet = QString("text-align: left; color: rgb(35, 38, 41);");
69 ui->header->setStyleSheet(stileSheet);
70}
71
72void CustomGroupBox::setTitleIcon(const QIcon &icon)
73{
74 ui->header->setIcon(icon);
75}
76
77void CustomGroupBox::addWidget(QWidget *widget)
78{
79 m_layout->addWidget(widget);
80}
81
82void CustomGroupBox::toggle(bool visible)
83{
84 ui->contentWidget->setVisible(visible);
85 m_visible = visible;
86 ui->arrowButton->setArrowType(m_visible ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow);
87}
88
90{
91 if (enable)
92 {
93 ui->header->setContextMenuPolicy(Qt::CustomContextMenu);
94
95 connect(ui->header, SIGNAL(customContextMenuRequested(QPoint)),
96 this, SLOT(onShowContextMenu(QPoint)));
97 }
98 else
99 {
100 ui->header->setContextMenuPolicy(Qt::NoContextMenu);
101
102 disconnect(ui->header, SIGNAL(customContextMenuRequested(QPoint)),
103 this, SLOT(onShowContextMenu(QPoint)));
104 }
105}
106
108{
109 return m_visible;
110}
111
113{
114 for (int i = 0; i < m_layout->count(); ++i)
115 {
116 QWidget* child = m_layout->itemAt(i)->widget();
117 if (child->objectName() == "CustomGroupBox")
118 {
119 CustomGroupBox* casted = static_cast<CustomGroupBox*>(child); //using static_cast for downcasting should be safe considering the if clause
120 casted->toggle(visible);
121 }
122 }
123}
124
125void CustomGroupBox::onArrowPressed(bool)
126{
127 toggle(!m_visible);
128}
129
130void CustomGroupBox::onTitleDoubleClick()
131{
133}
134
135void CustomGroupBox::onExpandAll()
136{
137 toggleChildren(true);
138}
139
140void CustomGroupBox::onCollapseAll()
141{
142 toggleChildren(false);
143}
144
145void CustomGroupBox::onShowContextMenu(QPoint pos)
146{
147 m_contextMenu.exec(mapToGlobal(pos));
148}
int SIGNAL(int pid, int signum)
void mouseDoubleClickEvent(QMouseEvent *) override
CustomGroupBoxLabel(QWidget *parent=nullptr)
~CustomGroupBox() override
void setTitleIcon(const QIcon &icon)
void sig_titleDoubleClick()
CustomGroupBox(QWidget *parent=nullptr)
void enableCollapseAllContextMenu(bool enable)
void toggle(bool visible)
void setTitleBackgroundColor(const QColor &backgroundColor)
bool visible() const
void toggleChildren(bool visible)
void addWidget(QWidget *widget)
void setTitle(const QString &string)
void removeTitleBackground()
Definition aboutdlg.h:11