2009-10-01 14:39:31 +02:00
|
|
|
#include "detailswidget.h"
|
|
|
|
|
#include "detailsbutton.h"
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QGridLayout>
|
|
|
|
|
#include <QtCore/QStack>
|
2009-10-02 10:12:32 +02:00
|
|
|
#include <QtGui/QLabel>
|
|
|
|
|
#include <QtGui/QGridLayout>
|
2009-10-01 15:58:46 +02:00
|
|
|
#include <QtGui/QPainter>
|
2009-10-01 14:39:31 +02:00
|
|
|
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
DetailsWidget::DetailsWidget(QWidget *parent)
|
|
|
|
|
: QWidget(parent),
|
2009-10-02 10:12:32 +02:00
|
|
|
m_summaryLabel(new QLabel(this)),
|
|
|
|
|
m_detailsButton(new DetailsButton(this)),
|
2009-10-01 14:39:31 +02:00
|
|
|
m_widget(0),
|
2009-10-02 10:12:32 +02:00
|
|
|
m_toolWidget(0),
|
|
|
|
|
m_grid(new QGridLayout(this))
|
|
|
|
|
|
2009-10-01 14:39:31 +02:00
|
|
|
{
|
2009-10-01 18:42:56 +02:00
|
|
|
m_summaryLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
2009-10-01 14:39:31 +02:00
|
|
|
m_summaryLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
|
|
|
|
|
|
m_grid->addWidget(m_summaryLabel, 0, 0, 2, 0);
|
2009-10-01 18:42:56 +02:00
|
|
|
m_grid->addWidget(m_detailsButton, 1, 2);
|
2009-10-01 14:39:31 +02:00
|
|
|
|
|
|
|
|
connect(m_detailsButton, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(detailsButtonClicked()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DetailsWidget::~DetailsWidget()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-01 15:58:46 +02:00
|
|
|
void DetailsWidget::paintEvent(QPaintEvent *paintEvent)
|
|
|
|
|
{
|
|
|
|
|
//TL--> ___________ <-- TR
|
|
|
|
|
// | |
|
2009-10-01 18:42:56 +02:00
|
|
|
//ML-> ______________| <--MM | <--MR
|
2009-10-01 15:58:46 +02:00
|
|
|
// | |
|
2009-10-01 18:42:56 +02:00
|
|
|
//BL-> |_________________________| <-- BR
|
2009-10-01 15:58:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
QWidget::paintEvent(paintEvent);
|
|
|
|
|
|
|
|
|
|
if (!m_detailsButton->isToggled())
|
|
|
|
|
return;
|
|
|
|
|
|
2009-10-02 10:12:32 +02:00
|
|
|
const QRect detailsGeometry = m_detailsButton->geometry();
|
|
|
|
|
const QRect widgetGeometry = m_widget ? m_widget->geometry() : QRect(x(), y() + height(), width(), 0);
|
2009-10-01 15:58:46 +02:00
|
|
|
|
|
|
|
|
QPoint tl(detailsGeometry.topLeft());
|
|
|
|
|
tl += QPoint(-3, -3);
|
|
|
|
|
|
|
|
|
|
QPoint tr(detailsGeometry.topRight());
|
|
|
|
|
tr += QPoint(3, -3);
|
|
|
|
|
|
|
|
|
|
QPoint mm(detailsGeometry.left() - 3, widgetGeometry.top() - 3);
|
|
|
|
|
|
|
|
|
|
QPoint ml(1, mm.y());
|
|
|
|
|
|
2009-10-01 18:42:56 +02:00
|
|
|
QPoint mr(tr.x(), mm.y());
|
|
|
|
|
|
2009-10-01 15:58:46 +02:00
|
|
|
int bottom = geometry().height() - 3;
|
|
|
|
|
QPoint bl(1, bottom);
|
|
|
|
|
QPoint br(tr.x(), bottom);
|
|
|
|
|
|
|
|
|
|
QPainter p(this);
|
2009-10-01 18:42:56 +02:00
|
|
|
p.setRenderHint(QPainter::Antialiasing);
|
2009-10-01 15:58:46 +02:00
|
|
|
p.setPen(Qt::NoPen);
|
2009-10-01 18:42:56 +02:00
|
|
|
|
|
|
|
|
p.setBrush(palette().dark());
|
2009-10-01 15:58:46 +02:00
|
|
|
p.drawRoundedRect(QRect(tl, br), 5, 5);
|
|
|
|
|
p.drawRoundedRect(QRect(ml, br), 5, 5);
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-01 14:39:31 +02:00
|
|
|
void DetailsWidget::detailsButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
if (m_widget)
|
|
|
|
|
m_widget->setVisible(m_detailsButton->isToggled());
|
|
|
|
|
fixUpLayout();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DetailsWidget::setSummaryText(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
m_summaryLabel->setText(text);
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-02 10:12:32 +02:00
|
|
|
QString DetailsWidget::summaryText() const
|
|
|
|
|
{
|
|
|
|
|
return m_summaryLabel->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DetailsWidget::expanded() const
|
|
|
|
|
{
|
|
|
|
|
return m_detailsButton->isToggled();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DetailsWidget::setExpanded(bool v)
|
|
|
|
|
{
|
|
|
|
|
if (expanded() != v)
|
|
|
|
|
m_detailsButton->animateClick();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *DetailsWidget::widget() const
|
|
|
|
|
{
|
|
|
|
|
return m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-01 14:39:31 +02:00
|
|
|
void DetailsWidget::setWidget(QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
if (m_widget == widget)
|
|
|
|
|
return;
|
2009-10-02 10:12:32 +02:00
|
|
|
if (m_widget) {
|
2009-10-01 14:39:31 +02:00
|
|
|
m_grid->removeWidget(m_widget);
|
2009-10-02 10:12:32 +02:00
|
|
|
m_widget = 0;
|
|
|
|
|
}
|
|
|
|
|
if (widget) {
|
|
|
|
|
m_grid->addWidget(widget, 2, 0, 1, 3);
|
|
|
|
|
m_widget = widget;
|
|
|
|
|
m_widget->setVisible(m_detailsButton->isToggled());
|
|
|
|
|
}
|
2009-10-01 14:39:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DetailsWidget::setToolWidget(QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
if (m_toolWidget == widget)
|
|
|
|
|
return;
|
2009-10-02 10:12:32 +02:00
|
|
|
if (m_toolWidget) {
|
2009-10-01 14:39:31 +02:00
|
|
|
m_grid->removeWidget(m_toolWidget);
|
2009-10-02 10:12:32 +02:00
|
|
|
m_toolWidget = 0;
|
|
|
|
|
}
|
|
|
|
|
if (widget) {
|
|
|
|
|
m_grid->addWidget(widget, 1, 1);
|
|
|
|
|
m_toolWidget = widget;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *DetailsWidget::toolWidget() const
|
|
|
|
|
{
|
|
|
|
|
return m_toolWidget;
|
2009-10-01 14:39:31 +02:00
|
|
|
}
|
|
|
|
|
|
2009-10-05 15:26:06 +02:00
|
|
|
// This function works around a qt limitation.
|
|
|
|
|
// In a deeply nested widget structure, nested layouts
|
|
|
|
|
// tell their parents per a delayed invocation that they
|
|
|
|
|
// need to repaint. Thus hiding a widget triggers
|
|
|
|
|
// one relayout (and repaint) for each level of widget
|
|
|
|
|
// nesting. We circumvent that, by forcing a update()
|
|
|
|
|
// activate() on the widget after hiding.
|
2009-10-01 14:39:31 +02:00
|
|
|
void DetailsWidget::fixUpLayout()
|
|
|
|
|
{
|
2009-10-02 10:12:32 +02:00
|
|
|
if (!m_widget)
|
|
|
|
|
return;
|
2009-10-01 14:39:31 +02:00
|
|
|
QWidget *parent = m_widget;
|
|
|
|
|
QStack<QWidget *> widgets;
|
|
|
|
|
while((parent = parent->parentWidget()) && parent && parent->layout()) {
|
|
|
|
|
widgets.push(parent);
|
|
|
|
|
parent->layout()->update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while(!widgets.isEmpty()) {
|
|
|
|
|
widgets.pop()->layout()->activate();
|
|
|
|
|
}
|
|
|
|
|
}
|