Classes | Public Slots | Public Member Functions | Protected Member Functions | Properties

KExpandableGroupBox Class Reference

An expandable container with a QComboBox-style API. More...

#include <kexpandablegroupbox.h>

Inheritance diagram for KExpandableGroupBox:
Inheritance graph
[legend]
Collaboration diagram for KExpandableGroupBox:
Collaboration graph
[legend]

List of all members.

Classes

class  Private

Public Slots

void setExpanded (bool expanded)
void setTitle (const QString &title)

Public Member Functions

 KExpandableGroupBox (QWidget *parent=0)
 KExpandableGroupBox (const QString &title, QWidget *parent=0)
 ~KExpandableGroupBox ()
QString title () const
bool isExpanded () const
Qt::Alignment alignment () const
QWidgetwidget () const
void setWidget (QWidget *w)
void setAlignment (Qt::Alignment a)
void setAnimateExpansion (bool animate)
bool animateExpansion () const
QSize minimumSizeHint () const

Protected Member Functions

void mouseReleaseEvent (QMouseEvent *ev)
void paintEvent (QPaintEvent *)

Properties

bool expanded
QString title
Qt::Alignment alignment
bool animateExpansion

Detailed Description

An expandable container with a QComboBox-style API.

A KExpandableGroupBox provides a title label with space that you can store arbitrary widgets in, very much like a group box. However, unlike a group box, the contents is hidden by default and can be expanded by a click on the title or the folding indicator (+/-).

This class should be used within a QScrollArea, because the widget takes up more screen estate when unfolded and might otherwise enlarge your dialog beyond the physical screen size.

Example code:

 QCheckBox *cb1 = new QCheckBox(tr("Option 1"));
 QCheckBox *cb2 = new QCheckBox(tr("Option 2"));
 QCheckBox *cb3 = new QCheckBox(tr("Option 3"));

 QWidget *widget = new QWidget;
 QVBoxLayout *vbox = new QVBoxLayout(widget);
 vbox->addWidget(cb1);
 vbox->addWidget(cb2);
 vbox->addWidget(cb3);

 KExpandableGroupBox *expWidget = new KExpandableGroupBox();
 expWidget->setTitle(tr("Less Important Options"));
 expWidget->setWidget(widget);

 QScrollArea *area = new QScrollArea;
 area->setWindowTitle("Collapsible Widget Demo");
 area->setWidgetResizable(true);

 QWidget *containerWidget = new QWidget
 QVBoxLayout *lay = new QVBoxLayout(containerWidget);
 lay->addWidget(collapsibleWidget);
Author:
Daniel Molkentin <molkentin@kde.org>

Constructor & Destructor Documentation

KExpandableGroupBox::KExpandableGroupBox ( QWidget parent = 0  )  [explicit]

Default constructor.

Parameters:
parent is the parent widget

Use setTitle() and setWidget() to set the respective properties.

 : QWidget(parent), d(new KExpandableGroupBox::Private)
{
    init();
}

KExpandableGroupBox::KExpandableGroupBox ( const QString title,
QWidget parent = 0 
) [explicit]

Convinience constructor.

Parameters:
title is the title of the collaspsible widget
parent is the widget parent widget

Use setWidget() to set the widgets contents.

 : QWidget(parent), d(new KExpandableGroupBox::Private)
{
    init();
    setTitle(title);
}

KExpandableGroupBox::~KExpandableGroupBox (  ) 

{
    delete d;
}


Member Function Documentation

Qt::Alignment KExpandableGroupBox::alignment (  )  const
Returns:
the alignment of the title label
See also:
setAlignment()
bool KExpandableGroupBox::animateExpansion (  )  const
Returns:
wether or not the expansion of widget() should be animated. The default is true except on embedded platforms.
See also:
setAnimateExpansion()
bool KExpandableGroupBox::isExpanded (  )  const
Returns:
widgets wether the widget is expanded or not
See also:
setExpanded()

Referenced by mouseReleaseEvent(), and setWidget().

{
    return d->colButton->isChecked();
}

QSize KExpandableGroupBox::minimumSizeHint (  )  const

{
//    return QSize(0,16);
        return QWidget::minimumSizeHint();
}

void KExpandableGroupBox::mouseReleaseEvent ( QMouseEvent ev  )  [protected]

Reimplemented from QWidget.

{
#if 0
    if ( (ev->button() & Qt::LeftButton) && QRect(0, 0, width(), 16).contains(ev->pos())) {
        setExpanded(!isExpanded());
    }
#endif
    QWidget::mouseReleaseEvent(ev);
}

void KExpandableGroupBox::paintEvent ( QPaintEvent ev  )  [protected]

Reimplemented from QWidget.

{
#if 0
    QPainter p(this);
    QStyleOption opt;
    int h = 16; //px
        opt.rect = QRect(0, 0, h, h);
    opt.palette = palette();
    opt.state = QStyle::State_Children;
    if (d->colButton->isChecked())
        opt.state |= QStyle::State_Open;
    style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, &p);
    p.drawText(h, 0, width(), height(), Qt::TextShowMnemonic, d->title);
    p.end();
#endif
    QWidget::paintEvent(ev);
}

void KExpandableGroupBox::setAlignment ( Qt::Alignment  a  ) 

Sets the alignment of the title label.

See also:
alignment()

{
    d->label->setAlignment(a);
}

void KExpandableGroupBox::setAnimateExpansion ( bool  animate  ) 

Sets wether or not the expansion of widget() should be animated.

See also:
animateExpansion()

{
    d->animateExpansion = animate;
}

void KExpandableGroupBox::setExpanded ( bool  expanded  )  [slot]

Sets wether the widgets contents is expanded or not

See also:
isExpanded()

Referenced by mouseReleaseEvent(), and setWidget().

{
    if ( !d->widget ) {
        return;
    }

    if (!d->animateExpansion) {
        if ( !expanded )
            d->widget->setVisible( false );
    } else {
        if ( expanded )
            d->expander->setVisible( true );
        d->widget->setVisible( expanded );
    }

    d->colButton->setChecked( expanded );
    d->timeline->setDirection( expanded ? QTimeLine::Forward
                                        : QTimeLine::Backward );
    d->timeline->start();
}

void KExpandableGroupBox::setTitle ( const QString title  )  [slot]

Sets the collapsible widgets title

See also:
title()

Referenced by KExpandableGroupBox().

{
    //d->label->setText(QString("<b>%1</b>").arg(title));
    d->label->setText(title);
    d->title = title;
}

void KExpandableGroupBox::setWidget ( QWidget w  ) 

Sets the inner widgets.

See also:
widget()

Referenced by Seeker::Seeker().

{
    if (!w) {
        return;
    }

    d->widget = w;
    d->label->setBuddy(d->widget);

    if (!d->animateExpansion) {
        if ( !isExpanded() ) {
            d->widget->hide();
        }
        d->gridLayout->addWidget( d->widget, 2, 2 );
        d->gridLayout->setRowStretch( 2, 1 );
    } else {
        if ( !d->expander ) {
            d->expander = new QWidget( this );
            d->gridLayout->addWidget( d->expander, 2, 2 );
            d->gridLayout->setRowStretch( 2, 1 );
            d->expanderLayout = new QVBoxLayout( d->expander );
            d->expanderLayout->setMargin( 0 );
            d->expanderLayout->setSpacing( 0 );
            d->expander->setFixedHeight( 0 );
        }

        d->widget->setParent(d->expander);
        d->widget->show();
        d->expanderLayout->addWidget(d->widget);
    }
    setEnabled( true );

    if ( isExpanded() ) {
        setExpanded( true );
    }
}

QString KExpandableGroupBox::title (  )  const
Returns:
the widgets title
QWidget * KExpandableGroupBox::widget (  )  const
Returns:
the widget contained
See also:
setWidget()

Reimplemented in Seeker.

{
    return d->widget;
}


Property Documentation

Qt::Alignment KExpandableGroupBox::alignment [read, write]
bool KExpandableGroupBox::animateExpansion [read, write]
bool KExpandableGroupBox::expanded [read, write]
QString KExpandableGroupBox::title [read, write]

The documentation for this class was generated from the following files: