LP-311 Remove basic/advanced stabilization tab auto-switch (autotune/txpid lock issues)
[librepilot.git] / ground / gcs / src / libs / utils / detailswidget.cpp
blob11a95537bd2dd66c50ab7607a62f70239f4e8f1a
1 /**
2 ******************************************************************************
4 * @file detailswidget.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
7 * @brief
8 * @see The GNU Public License (GPL) Version 3
9 * @defgroup
10 * @{
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "detailswidget.h"
30 #include "detailsbutton.h"
32 #include <QGridLayout>
33 #include <QtCore/QStack>
34 #include <QLabel>
35 #include <QGridLayout>
36 #include <QPainter>
38 using namespace Utils;
40 DetailsWidget::DetailsWidget(QWidget *parent)
41 : QWidget(parent),
42 m_summaryLabel(new QLabel(this)),
43 m_detailsButton(new DetailsButton(this)),
44 m_widget(0),
45 m_toolWidget(0),
46 m_grid(new QGridLayout(this))
48 m_grid->setContentsMargins(4, 3, 4, 3);
50 m_summaryLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
51 m_summaryLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
53 m_grid->addWidget(m_summaryLabel, 0, 0);
54 m_grid->addWidget(m_detailsButton, 0, 2, 1, 1, Qt::AlignBottom);
56 m_dummyWidget = new QWidget(this);
57 m_dummyWidget->setMaximumHeight(4);
58 m_dummyWidget->setMaximumHeight(4);
59 m_dummyWidget->setVisible(false);
60 m_grid->addWidget(m_dummyWidget, 2, 0, 1, 1);
62 connect(m_detailsButton, SIGNAL(clicked()),
63 this, SLOT(detailsButtonClicked()));
66 DetailsWidget::~DetailsWidget()
69 void DetailsWidget::paintEvent(QPaintEvent *paintEvent)
71 // TL--> ___________ <-- TR
72 // | |
73 // ML-> ______________| <--MM | <--MR
74 // | |
75 // BL-> |_________________________| <-- BR
78 QWidget::paintEvent(paintEvent);
80 if (!m_detailsButton->isToggled()) {
81 return;
84 const QRect detailsGeometry = m_detailsButton->geometry();
85 const QRect widgetGeometry = m_widget ? m_widget->geometry() : QRect(x(), y() + height(), width(), 0);
87 QPoint tl(detailsGeometry.topLeft());
88 tl += QPoint(-3, -3);
90 QPoint tr(detailsGeometry.topRight());
91 tr += QPoint(3, -3);
93 QPoint mm(detailsGeometry.left() - 3, widgetGeometry.top() - 3);
95 QPoint ml(1, mm.y());
97 QPoint mr(tr.x(), mm.y());
99 int bottom = geometry().height() - 3;
100 QPoint bl(1, bottom);
101 QPoint br(tr.x(), bottom);
103 QPainter p(this);
104 p.setRenderHint(QPainter::Antialiasing);
105 p.setPen(Qt::NoPen);
107 p.setBrush(palette().dark());
108 p.drawRoundedRect(QRect(tl, br), 5, 5);
109 p.drawRoundedRect(QRect(ml, br), 5, 5);
112 void DetailsWidget::detailsButtonClicked()
114 bool visible = m_detailsButton->isToggled();
116 if (m_widget) {
117 m_widget->setVisible(visible);
119 m_dummyWidget->setVisible(visible);
120 fixUpLayout();
123 void DetailsWidget::setSummaryText(const QString &text)
125 m_summaryLabel->setText(text);
128 QString DetailsWidget::summaryText() const
130 return m_summaryLabel->text();
133 bool DetailsWidget::expanded() const
135 return m_detailsButton->isToggled();
138 void DetailsWidget::setExpanded(bool v)
140 if (expanded() != v) {
141 m_detailsButton->animateClick();
145 QWidget *DetailsWidget::widget() const
147 return m_widget;
150 void DetailsWidget::setWidget(QWidget *widget)
152 if (m_widget == widget) {
153 return;
155 if (m_widget) {
156 m_grid->removeWidget(m_widget);
157 m_widget = 0;
159 if (widget) {
160 m_grid->addWidget(widget, 1, 0, 1, 3);
161 m_widget = widget;
162 bool visible = m_detailsButton->isToggled();
163 m_widget->setVisible(visible);
164 m_dummyWidget->setVisible(visible);
168 void DetailsWidget::setToolWidget(QWidget *widget)
170 if (m_toolWidget == widget) {
171 return;
173 if (m_toolWidget) {
174 m_grid->removeWidget(m_toolWidget);
175 m_toolWidget = 0;
177 if (widget) {
178 m_grid->addWidget(widget, 0, 1, 1, 1, Qt::AlignBottom);
179 m_toolWidget = widget;
183 QWidget *DetailsWidget::toolWidget() const
185 return m_toolWidget;
188 void DetailsWidget::fixUpLayout()
190 if (!m_widget) {
191 return;
193 QWidget *parent = m_widget;
194 QStack<QWidget *> widgets;
195 while ((parent = parent->parentWidget()) && parent && parent->layout()) {
196 widgets.push(parent);
197 parent->layout()->update();
200 while (!widgets.isEmpty()) {
201 widgets.pop()->layout()->activate();