2009-10-01 14:39:31 +02:00
|
|
|
#include "detailswidget.h"
|
|
|
|
|
#include "detailsbutton.h"
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QGridLayout>
|
|
|
|
|
#include <QtCore/QStack>
|
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),
|
|
|
|
|
m_widget(0),
|
|
|
|
|
m_toolWidget(0)
|
|
|
|
|
{
|
|
|
|
|
m_grid = new QGridLayout(this);
|
2009-10-01 15:58:46 +02:00
|
|
|
//m_grid->setMargin(0);
|
2009-10-01 14:39:31 +02:00
|
|
|
m_summaryLabel = new QLabel(this);
|
|
|
|
|
m_summaryLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
|
m_detailsButton = new DetailsButton(this);
|
|
|
|
|
|
|
|
|
|
m_grid->addWidget(m_summaryLabel, 0, 0, 2, 0);
|
|
|
|
|
m_grid->addWidget(m_detailsButton, 0, 2);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
// | |
|
|
|
|
|
//ML-> ______________| <--MM |
|
|
|
|
|
// | |
|
|
|
|
|
//BL-> |_________________________| <-- BR
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QWidget::paintEvent(paintEvent);
|
|
|
|
|
|
|
|
|
|
if (!m_detailsButton->isToggled())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QRect detailsGeometry = m_detailsButton->geometry();
|
|
|
|
|
QRect widgetGeometry = m_widget->geometry();
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
int bottom = geometry().height() - 3;
|
|
|
|
|
QPoint bl(1, bottom);
|
|
|
|
|
QPoint br(tr.x(), bottom);
|
|
|
|
|
|
|
|
|
|
QPainter p(this);
|
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
|
QColor c = palette().color(QPalette::Background);
|
|
|
|
|
c = c.darker(115);
|
|
|
|
|
p.setBrush(c);
|
|
|
|
|
//p.setBrush(palette().button());
|
|
|
|
|
|
|
|
|
|
// QPolygon polygon;
|
|
|
|
|
// polygon << tl << tr << br << bl << ml << mm;
|
|
|
|
|
// p.drawConvexPolygon(polygon);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DetailsWidget::setWidget(QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
if (m_widget == widget)
|
|
|
|
|
return;
|
|
|
|
|
if (m_widget)
|
|
|
|
|
m_grid->removeWidget(m_widget);
|
|
|
|
|
m_grid->addWidget(widget, 2, 0, 1, 3);
|
|
|
|
|
m_widget = widget;
|
|
|
|
|
m_widget->setVisible(m_detailsButton->isToggled());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DetailsWidget::setToolWidget(QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
if (m_toolWidget == widget)
|
|
|
|
|
return;
|
|
|
|
|
if (m_toolWidget)
|
|
|
|
|
m_grid->removeWidget(m_toolWidget);
|
|
|
|
|
m_grid->addWidget(widget, 0, 1);
|
|
|
|
|
m_toolWidget = widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DetailsWidget::fixUpLayout()
|
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|