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.
8 * @see The GNU Public License (GPL) Version 3
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
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>
35 #include <QGridLayout>
38 using namespace Utils
;
40 DetailsWidget::DetailsWidget(QWidget
*parent
)
42 m_summaryLabel(new QLabel(this)),
43 m_detailsButton(new DetailsButton(this)),
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
73 // ML-> ______________| <--MM | <--MR
75 // BL-> |_________________________| <-- BR
78 QWidget::paintEvent(paintEvent
);
80 if (!m_detailsButton
->isToggled()) {
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());
90 QPoint
tr(detailsGeometry
.topRight());
93 QPoint
mm(detailsGeometry
.left() - 3, widgetGeometry
.top() - 3);
97 QPoint
mr(tr
.x(), mm
.y());
99 int bottom
= geometry().height() - 3;
100 QPoint
bl(1, bottom
);
101 QPoint
br(tr
.x(), bottom
);
104 p
.setRenderHint(QPainter::Antialiasing
);
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();
117 m_widget
->setVisible(visible
);
119 m_dummyWidget
->setVisible(visible
);
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
150 void DetailsWidget::setWidget(QWidget
*widget
)
152 if (m_widget
== widget
) {
156 m_grid
->removeWidget(m_widget
);
160 m_grid
->addWidget(widget
, 1, 0, 1, 3);
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
) {
174 m_grid
->removeWidget(m_toolWidget
);
178 m_grid
->addWidget(widget
, 0, 1, 1, 1, Qt::AlignBottom
);
179 m_toolWidget
= widget
;
183 QWidget
*DetailsWidget::toolWidget() const
188 void DetailsWidget::fixUpLayout()
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();