Public Member Functions | Protected Member Functions | Properties | Friends

QxtPushButton Class Reference
[QxtGui]

An extended QPushButton with rotation and rich text support. More...

#include <qxtpushbutton.h>

Collaboration diagram for QxtPushButton:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 QxtPushButton (QWidget *parent=0)
 QxtPushButton (const QString &text, QWidget *parent=0)
 QxtPushButton (const QIcon &icon, const QString &text, QWidget *parent=0)
 QxtPushButton (Qxt::Rotation rotation, const QString &text, QWidget *parent=0)
virtual ~QxtPushButton ()
Qxt::Rotation rotation () const
void setRotation (Qxt::Rotation rotation)
Qt::TextFormat textFormat () const
void setTextFormat (Qt::TextFormat format)
virtual QSize sizeHint () const
virtual QSize minimumSizeHint () const

Protected Member Functions

virtual void paintEvent (QPaintEvent *event)

Properties

Qxt::Rotation rotation
 This property holds the rotation of the button.
Qt::TextFormat textFormat
 This property holds the text format of the button.

Friends

class QxtPushButtonPrivate

Detailed Description

An extended QPushButton with rotation and rich text support.

QxtPushButton is a QPushButton which can be rotated. In addition, QxtPushButton provides rich text support.

qxtpushbutton.png

QxtPushButton in action.

Definition at line 35 of file qxtpushbutton.h.


Constructor & Destructor Documentation

QxtPushButton::QxtPushButton ( QWidget *  parent = 0 ) [explicit]

Constructs a new QxtPushButton with parent.

Definition at line 117 of file qxtpushbutton.cpp.

References QXT_INIT_PRIVATE.

                                            : QPushButton(parent)
{
    QXT_INIT_PRIVATE(QxtPushButton);
}
QxtPushButton::QxtPushButton ( const QString &  text,
QWidget *  parent = 0 
) [explicit]

Constructs a new QxtPushButton with text and parent.

Definition at line 125 of file qxtpushbutton.cpp.

References QXT_INIT_PRIVATE.

                                                                 : QPushButton(text, parent)
{
    QXT_INIT_PRIVATE(QxtPushButton);
}
QxtPushButton::QxtPushButton ( const QIcon &  icon,
const QString &  text,
QWidget *  parent = 0 
) [explicit]

Constructs a new QxtPushButton with icon, text and parent.

Note:
An icon is not rendered when using rich text.

Definition at line 135 of file qxtpushbutton.cpp.

References QXT_INIT_PRIVATE.

                                                                                    : QPushButton(icon, text, parent)
{
    QXT_INIT_PRIVATE(QxtPushButton);
}
QxtPushButton::QxtPushButton ( Qxt::Rotation  rotation,
const QString &  text,
QWidget *  parent = 0 
) [explicit]

Constructs a new QxtPushButton with rotation, text and parent.

Definition at line 143 of file qxtpushbutton.cpp.

References QXT_INIT_PRIVATE, and setRotation().

                                                                                       : QPushButton(text, parent)
{
    QXT_INIT_PRIVATE(QxtPushButton);
    setRotation(rotation);
}
QxtPushButton::~QxtPushButton (  ) [virtual]

Destructs the button.

Definition at line 152 of file qxtpushbutton.cpp.

{}

Member Function Documentation

QSize QxtPushButton::minimumSizeHint (  ) const [virtual]

Definition at line 247 of file qxtpushbutton.cpp.

References sizeHint().

{
    return sizeHint();
}
void QxtPushButton::paintEvent ( QPaintEvent *  event ) [protected, virtual]

Definition at line 255 of file qxtpushbutton.cpp.

References Qxt::Clockwise, Qxt::CounterClockwise, Qxt::UpsideDown, and Vertical_Mask.

{
    Q_UNUSED(event);

    // the only reliable way to detect text changes
    if (text() != qxt_d().text)
    {
        qxt_d().text = text();
        if (qxt_d().isRichText())
            qxt_d().doc->setHtml(qxt_d().text);
        updateGeometry();
    }

    QStylePainter painter(this);
    painter.rotate(qxt_d().rot);
    switch (qxt_d().rot)
    {
    case Qxt::UpsideDown:
        painter.translate(-width(), -height());
        break;

    case Qxt::Clockwise:
        painter.translate(0, -width());
        break;

    case Qxt::CounterClockwise:
        painter.translate(-height(), 0);
        break;

    default:
        // nothing to do
        break;
    }

    const QStyleOptionButton option = qxt_d().getStyleOption();
    painter.drawControl(QStyle::CE_PushButton, option);

#if QT_VERSION >= 0x040200
    if (qxt_d().isRichText())
    {
        int dx = 0;
        int dy = 0;
        if (option.state & (QStyle::State_On | QStyle::State_Sunken))
        {
            dx += style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal, &option, this);
            dy += style()->pixelMetric(QStyle::PM_ButtonShiftVertical, &option, this);
        }

        QRect area = rect();
        const QSizeF docSize = qxt_d().doc->documentLayout()->documentSize();
        if (qxt_d().rot & Vertical_Mask)
        {
            dx += static_cast<int>((height() - docSize.width())  / 2);
            dy += static_cast<int>((width()  - docSize.height()) / 2);
            painter.translate(dx, dy);

            QSize size = area.size();
            size.transpose();
            area.setSize(size);
        }
        else
        {
            dx += static_cast<int>((width()  - docSize.width())  / 2);
            dy += static_cast<int>((height() - docSize.height()) / 2);
            painter.translate(dx, dy);
        }
        qxt_d().doc->drawContents(&painter, area);
    }
#endif // QT_VERSION
}
Qxt::Rotation QxtPushButton::rotation (  ) const

Referenced by setRotation().

void QxtPushButton::setRotation ( Qxt::Rotation  rotation )

Definition at line 169 of file qxtpushbutton.cpp.

References Qxt::Clockwise, Qxt::CounterClockwise, Qxt::NoRotation, rotation(), and Qxt::UpsideDown.

Referenced by QxtPushButton().

{
    if (qxt_d().rot != rotation)
    {
        qxt_d().rot = rotation;
        switch (rotation)
        {
        case Qxt::NoRotation:
        case Qxt::UpsideDown:
            setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
            break;

        case Qxt::Clockwise:
        case Qxt::CounterClockwise:
            setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
            break;

        default:
            // nothing to do
            break;
        }
        updateGeometry();
        update();
    }
}
void QxtPushButton::setTextFormat ( Qt::TextFormat  format )

Definition at line 212 of file qxtpushbutton.cpp.

{
    if (qxt_d().format != format)
    {
        qxt_d().format = format;
        if (!qxt_d().isRichText())
        {
            delete qxt_d().doc;
            qxt_d().doc = 0;
        }
        qxt_d().text.clear();
        update();
        updateGeometry();
    }
}
QSize QxtPushButton::sizeHint (  ) const [virtual]

Definition at line 231 of file qxtpushbutton.cpp.

References Vertical_Mask.

Referenced by minimumSizeHint().

{
    QSize size;
    if (qxt_d().isRichText())
        size = qxt_d().doc->documentLayout()->documentSize().toSize();
    else
        size = QPushButton::sizeHint();

    if (qxt_d().rot & Vertical_Mask)
        size.transpose();
    return size;
}
Qt::TextFormat QxtPushButton::textFormat (  ) const

Friends And Related Function Documentation

friend class QxtPushButtonPrivate [friend]

Definition at line 38 of file qxtpushbutton.h.


Property Documentation

Qxt::Rotation QxtPushButton::rotation [read, write]

This property holds the rotation of the button.

The button is rotated according to this property. The default value is Qxt::NoRotation.

See also:
Qxt::Rotation

Definition at line 38 of file qxtpushbutton.h.

Qt::TextFormat QxtPushButton::textFormat [read, write]

This property holds the text format of the button.

Supported formats are Qt::PlainText, Qt::RichText and Qt::AutoText.

The default format is Qt::PlainText.

Note:
Rich text requires Qt 4.2 or newer.
See also:
Qt::TextFormat

Definition at line 40 of file qxtpushbutton.h.


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