<commit_before>#include "detailswidget.h"
#include "detailsbutton.h"

#include <QtGui/QGridLayout>
#include <QtCore/QStack>
#include <QtGui/QLabel>
#include <QtGui/QGridLayout>
#include <QtGui/QPainter>

using namespace Utils;

DetailsWidget::DetailsWidget(QWidget *parent)
    : QWidget(parent),
      m_summaryLabel(new QLabel(this)),
      m_detailsButton(new DetailsButton(this)),
      m_widget(0),
      m_toolWidget(0),
      m_grid(new QGridLayout(this))

{
    m_summaryLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
    m_summaryLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);

    m_grid->addWidget(m_summaryLabel, 0, 0, 2, 0);
    m_grid->addWidget(m_detailsButton, 1, 2);

    connect(m_detailsButton, SIGNAL(clicked()),
            this, SLOT(detailsButtonClicked()));
}

DetailsWidget::~DetailsWidget()
{

}

void DetailsWidget::paintEvent(QPaintEvent *paintEvent)
{
    //TL-->                 ___________  <-- TR
    //                     |           |
    //ML->   ______________| <--MM     | <--MR
    //       |                         |
    //BL->   |_________________________| <-- BR


    QWidget::paintEvent(paintEvent);

    if (!m_detailsButton->isToggled())
        return;

    const QRect detailsGeometry = m_detailsButton->geometry();
    const QRect widgetGeometry = m_widget ? m_widget->geometry() : QRect(x(), y() + height(), width(), 0);

    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());

    QPoint mr(tr.x(), mm.y());

    int bottom = geometry().height() - 3;
    QPoint bl(1, bottom);
    QPoint br(tr.x(), bottom);

    QPainter p(this);
    p.setRenderHint(QPainter::Antialiasing);
    p.setPen(Qt::NoPen);

    p.setBrush(palette().dark());
    p.drawRoundedRect(QRect(tl, br), 5, 5);
    p.drawRoundedRect(QRect(ml, br), 5, 5);
}

void DetailsWidget::detailsButtonClicked()
{
    if (m_widget)
        m_widget->setVisible(m_detailsButton->isToggled());
    fixUpLayout();
}

void DetailsWidget::setSummaryText(const QString &text)
{
    m_summaryLabel->setText(text);
}

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;
}

void DetailsWidget::setWidget(QWidget *widget)
{
    if (m_widget == widget)
        return;
    if (m_widget) {
        m_grid->removeWidget(m_widget);
        m_widget = 0;
    }
    if (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_toolWidget = 0;
    }
    if (widget) {
        m_grid->addWidget(widget, 1, 1);
        m_toolWidget = widget;
    }
}

QWidget *DetailsWidget::toolWidget() const
{
    return m_toolWidget;
}

void DetailsWidget::fixUpLayout()
{
    if (!m_widget)
        return;
    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();
    }
}
<commit_msg>Explain fixUpLayout() of DetailsWidget in a comment<commit_after>#include "detailswidget.h"
#include "detailsbutton.h"

#include <QtGui/QGridLayout>
#include <QtCore/QStack>
#include <QtGui/QLabel>
#include <QtGui/QGridLayout>
#include <QtGui/QPainter>

using namespace Utils;

DetailsWidget::DetailsWidget(QWidget *parent)
    : QWidget(parent),
      m_summaryLabel(new QLabel(this)),
      m_detailsButton(new DetailsButton(this)),
      m_widget(0),
      m_toolWidget(0),
      m_grid(new QGridLayout(this))

{
    m_summaryLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
    m_summaryLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);

    m_grid->addWidget(m_summaryLabel, 0, 0, 2, 0);
    m_grid->addWidget(m_detailsButton, 1, 2);

    connect(m_detailsButton, SIGNAL(clicked()),
            this, SLOT(detailsButtonClicked()));
}

DetailsWidget::~DetailsWidget()
{

}

void DetailsWidget::paintEvent(QPaintEvent *paintEvent)
{
    //TL-->                 ___________  <-- TR
    //                     |           |
    //ML->   ______________| <--MM     | <--MR
    //       |                         |
    //BL->   |_________________________| <-- BR


    QWidget::paintEvent(paintEvent);

    if (!m_detailsButton->isToggled())
        return;

    const QRect detailsGeometry = m_detailsButton->geometry();
    const QRect widgetGeometry = m_widget ? m_widget->geometry() : QRect(x(), y() + height(), width(), 0);

    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());

    QPoint mr(tr.x(), mm.y());

    int bottom = geometry().height() - 3;
    QPoint bl(1, bottom);
    QPoint br(tr.x(), bottom);

    QPainter p(this);
    p.setRenderHint(QPainter::Antialiasing);
    p.setPen(Qt::NoPen);

    p.setBrush(palette().dark());
    p.drawRoundedRect(QRect(tl, br), 5, 5);
    p.drawRoundedRect(QRect(ml, br), 5, 5);
}

void DetailsWidget::detailsButtonClicked()
{
    if (m_widget)
        m_widget->setVisible(m_detailsButton->isToggled());
    fixUpLayout();
}

void DetailsWidget::setSummaryText(const QString &text)
{
    m_summaryLabel->setText(text);
}

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;
}

void DetailsWidget::setWidget(QWidget *widget)
{
    if (m_widget == widget)
        return;
    if (m_widget) {
        m_grid->removeWidget(m_widget);
        m_widget = 0;
    }
    if (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_toolWidget = 0;
    }
    if (widget) {
        m_grid->addWidget(widget, 1, 1);
        m_toolWidget = widget;
    }
}

QWidget *DetailsWidget::toolWidget() const
{
    return m_toolWidget;
}

// 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.
void DetailsWidget::fixUpLayout()
{
    if (!m_widget)
        return;
    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();
    }
}

{'fraction_non_alphanumeric': 0.147918282906646, 'fraction_numerical': 0.007757951900698216, 'mean_word_length': 3.134152859433458, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3376295', 'n_tokens_mistral': 2634, 'n_tokens_neox': 2528, 'n_words': 487}