Public Slots | Public Member Functions | Protected Member Functions | Properties | Friends

QxtLetterBoxWidget Class Reference
[QxtGui]

A letter box widget. More...

#include <qxtletterboxwidget.h>

Collaboration diagram for QxtLetterBoxWidget:
Collaboration graph
[legend]

List of all members.

Public Slots

void resizeWidget ()

Public Member Functions

 QxtLetterBoxWidget (QWidget *parent=0)
 ~QxtLetterBoxWidget ()
QColor backgroundColor () const
void setBackgroundColor (const QColor &color)
void clearBackgroundColor ()
int margin () const
void setMargin (int margin)
QWidget * widget () const
void setWidget (QWidget *widget)
uint resizeDelay () const
void setResizeDelay (uint delay)

Protected Member Functions

void resizeEvent (QResizeEvent *event)

Properties

QColor backgroundColor
 This property holds the background color.
int margin
 This property holds the margin.
uint resizeDelay
 This property holds the delay of resize.

Friends

class QxtLetterBoxWidgetPrivate

Detailed Description

A letter box widget.

QxtLetterBoxWidget preserves the aspect ratio of its content widget.

Use QWidget::sizeIncrement to define the aspect ratio:

    QxtLetterBoxWidget letterBox;
    widget->setSizeIncrement(16, 9);
    letterBox.setWidget(widget);
    letterBox.show();

Definition at line 34 of file qxtletterboxwidget.h.


Constructor & Destructor Documentation

QxtLetterBoxWidget::QxtLetterBoxWidget ( QWidget *  parent = 0 )

Constructs a new QxtLetterBoxWidget with parent.

Definition at line 54 of file qxtletterboxwidget.cpp.

References QXT_INIT_PRIVATE, and resizeWidget().

                                                      : QFrame(parent)
{
    QXT_INIT_PRIVATE(QxtLetterBoxWidget);
    connect(&qxt_d().timer, SIGNAL(timeout()), this, SLOT(resizeWidget()));
}
QxtLetterBoxWidget::~QxtLetterBoxWidget (  )

Destructs the group box.

Definition at line 63 of file qxtletterboxwidget.cpp.

{
}

Member Function Documentation

QColor QxtLetterBoxWidget::backgroundColor (  ) const
void QxtLetterBoxWidget::clearBackgroundColor (  )

Definition at line 90 of file qxtletterboxwidget.cpp.

References setBackgroundColor().

{
    setBackgroundColor(QColor());
    setAutoFillBackground(false);
}
int QxtLetterBoxWidget::margin (  ) const

Referenced by resizeWidget(), and setMargin().

uint QxtLetterBoxWidget::resizeDelay (  ) const

Referenced by resizeEvent().

void QxtLetterBoxWidget::resizeEvent ( QResizeEvent *  event ) [protected]

Definition at line 185 of file qxtletterboxwidget.cpp.

References resizeDelay(), and resizeWidget().

{
    QFrame::resizeEvent(event);
    if (resizeDelay() > 0)
        qxt_d().timer.start();
    else
        resizeWidget();
}
void QxtLetterBoxWidget::resizeWidget (  ) [slot]

Resizes the content widget.

Definition at line 169 of file qxtletterboxwidget.cpp.

References margin().

Referenced by QxtLetterBoxWidget(), resizeEvent(), setMargin(), and setWidget().

{
    if (qxt_d().center)
    {
        QSize s = qxt_d().center->sizeIncrement();
        s.scale(size(), Qt::KeepAspectRatio);
        s -= QSize(2 * qxt_d().margin, 2 * qxt_d().margin);
        s = QLayout::closestAcceptableSize(qxt_d().center, s);
        QRect r = QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, s, rect());
        qxt_d().center->setGeometry(r);
    }
}
void QxtLetterBoxWidget::setBackgroundColor ( const QColor &  color )

Definition at line 82 of file qxtletterboxwidget.cpp.

Referenced by clearBackgroundColor().

{
    QPalette pal = palette();
    pal.setColor(QPalette::Window, color);
    setPalette(pal);
    setAutoFillBackground(true);
}
void QxtLetterBoxWidget::setMargin ( int  margin )

Definition at line 107 of file qxtletterboxwidget.cpp.

References margin(), and resizeWidget().

{
    if (qxt_d().margin != margin)
    {
        qxt_d().margin = margin;
        resizeWidget();
    }
}
void QxtLetterBoxWidget::setResizeDelay ( uint  delay )

Definition at line 161 of file qxtletterboxwidget.cpp.

{
    qxt_d().timer.setInterval(delay);
}
void QxtLetterBoxWidget::setWidget ( QWidget *  widget )

Sets the given widget to be the letter box's widget.

Note:
QxtLetterBox takes ownership of the widget pointer and deletes it at the appropriate time.
See also:
widget()

Definition at line 135 of file qxtletterboxwidget.cpp.

References resizeWidget(), and widget().

{
    if (qxt_d().center && qxt_d().center != widget)
        qxt_d().center->deleteLater();
    qxt_d().center = widget;
    if (widget)
    {
        widget->setParent(this);
        resizeWidget();
    }
}
QWidget * QxtLetterBoxWidget::widget (  ) const

Returns the widget for the letter box. This function returns zero if the widget has not been set.

See also:
setWidget()

Definition at line 122 of file qxtletterboxwidget.cpp.

Referenced by setWidget().

{
    return qxt_d().center;
}

Friends And Related Function Documentation

friend class QxtLetterBoxWidgetPrivate [friend]

Definition at line 37 of file qxtletterboxwidget.h.


Property Documentation

QColor QxtLetterBoxWidget::backgroundColor [read, write]

This property holds the background color.

This property is provided for convenience. This property corresponds to QPalette::Window.

Note:
Setting or clearing the property also sets the property QWidget::autoFillBackground as true or false, respectively.

Definition at line 37 of file qxtletterboxwidget.h.

int QxtLetterBoxWidget::margin [read, write]

This property holds the margin.

The default value is 0.

Definition at line 39 of file qxtletterboxwidget.h.

uint QxtLetterBoxWidget::resizeDelay [read, write]

This property holds the delay of resize.

The default value is 0 which means immediate resize.

Using a short resize delay might be useful if the widget is complex and resizing it is expensive.

Definition at line 40 of file qxtletterboxwidget.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines