Пример #1
0
void CollapsibleWidget::addWidget(QWidget *pWidget, const bool &pCollapsible)
{
    // Make sure that there is a widget to add

    if (!pWidget)
        return;

    // We want to add a widget, so we first need to add a header to our layout

    CollapsibleHeaderWidget *header = new CollapsibleHeaderWidget(mSeparatorColor, pCollapsible, this);

    // Let our header know whether it is the first header

    header->setFirstHeader(mHeaders.isEmpty());

    // Let our header know that, if anything, it is our new last header, meaning
    // that our previous last header is not the last one anymore

    if (!mHeaders.isEmpty())
        mHeaders.last()->setLastHeader(false);

    header->setLastHeader(true);

    // Now, we can actually add the header to our layout, as well as keep track
    // of it

    mLayout->addWidget(header);

    mHeaders << header;

    // Add the widget itself

    mLayout->addWidget(pWidget);

    // Create a connection to show/hide our widget depending on the collapsed
    // state of our header, as well as one to let people know about our overall
    // new collapsible state

    if (pCollapsible) {
        connect(header, SIGNAL(widgetVisible(const bool &)),
                pWidget, SLOT(setVisible(bool)));

        connect(header, SIGNAL(widgetVisible(const bool &)),
                this, SLOT(emitCollapsed()));
    }
}
Пример #2
0
void CollapsibleWidget::addWidget(QWidget *pWidget)
{
    // Make sure that there is a widget to add

    if (!pWidget)
        return;

    // We want to add a new widget, so we first need to add a new header to our
    // layout

    int beforeIndex = 2*mHeaders.count();

    CollapsibleHeaderWidget *header = new CollapsibleHeaderWidget(mSeparatorColor, this);

    // Let our header know whether it is the first header

    header->setFirstHeader(!beforeIndex);

    // Let our header know that, if anything, it is our new last header, meaning
    // that our previous header is not the last one anymore

    if (!mHeaders.isEmpty())
        mHeaders.last()->setLastHeader(false);

    header->setLastHeader(true);

    // Now, we can actually add the header to our layout, as well as keep track
    // of it

    mLayout->insertWidget(beforeIndex, header);

    mHeaders.append(header);

    // Add the new widget itself

    mLayout->insertWidget(++beforeIndex, pWidget);

    // Create a connection to show/hide our widget depending on the collapsed
    // state of our header

    connect(header, SIGNAL(widgetVisible(const bool &)),
            pWidget, SLOT(setVisible(bool)));
}