A
download qradiobutton.cpp
Language: C++
License: GPL
Copyright: (C) 1992-2006 Trolltech ASA. All rights reserved.
LOC: 107
Project Info
qt-copy
Server: KDE Repo
Type: svn
...py\qt‑copy\src\gui\widgets\
   qabstractbutton.cpp
   qabstractbutton.h
   qabstractbutton_p.h
   qabstractscrollarea.cpp
   qabstractscrollarea.h
   qabstractscrollarea_p.h
   qabstractslider.cpp
   qabstractslider.h
   qabstractslider_p.h
   qabstractspinbox.cpp
   qabstractspinbox.h
   qabstractspinbox_p.h
   qbuttongroup.cpp
   qbuttongroup.h
   qcalendarwidget.cpp
   qcalendarwidget.h
   qcheckbox.cpp
   qcheckbox.h
   qcombobox.cpp
   qcombobox.h
   qcombobox_p.h
   qdatetimeedit.cpp
   qdatetimeedit.h
   qdatetimeedit_p.h
   qdial.cpp
   qdial.h
   qdialogbuttonbox.cpp
   qdialogbuttonbox.h
   qdockwidget.cpp
   qdockwidget.h
   qdockwidget_p.h
   qdockwidgetlayout.cpp
   qdockwidgetlayout_p.h
   qeffects.cpp
   qeffects_p.h
   qfocusframe.cpp
   qfocusframe.h
   qfontcombobox.cpp
   qfontcombobox.h
   qframe.cpp
   qframe.h
   qframe_p.h
   qgroupbox.cpp
   qgroupbox.h
   qlabel.cpp
   qlabel.h
   qlabel_p.h
   qlcdnumber.cpp
   qlcdnumber.h
   qlineedit.cpp
   qlineedit.h
   qlineedit_p.h
   qmainwindow.cpp
   qmainwindow.h
   qmainwindowlayout.cpp
   qmainwindowlayout_p.h
   qmenu.cpp
   qmenu.h
   qmenu_p.h
   qmenubar.cpp
   qmenubar.h
   qmenubar_p.h
   qmenudata.cpp
   qmenudata.h
   qprogressbar.cpp
   qprogressbar.h
   qpushbutton.cpp
   qpushbutton.h
   qradiobutton.cpp
   qradiobutton.h
   qrubberband.cpp
   qrubberband.h
   qscrollarea.cpp
   qscrollarea.h
   qscrollarea_p.h
   qscrollbar.cpp
   qscrollbar.h
   qsizegrip.cpp
   qsizegrip.h
   qslider.cpp
   qslider.h
   qspinbox.cpp
   qspinbox.h
   qsplashscreen.cpp
   qsplashscreen.h
   qsplitter.cpp
   qsplitter.h
   qsplitter_p.h
   qstackedwidget.cpp
   qstackedwidget.h
   qstatusbar.cpp
   qstatusbar.h
   qtabbar.cpp
   qtabbar.h
   qtabbar_p.h
   qtabwidget.cpp
   qtabwidget.h
   qtextbrowser.cpp
   qtextbrowser.h
   qtextedit.cpp
   qtextedit.h
   qtextedit_p.h
   qtoolbar.cpp
   qtoolbar.h
   qtoolbar_p.h
   qtoolbarextension.cpp
   qtoolbarextension_p.h
   qtoolbarhandle.cpp
   qtoolbarhandle_p.h
   qtoolbarseparator.cpp
   qtoolbarseparator_p.h
   qtoolbox.cpp
   qtoolbox.h
   qtoolbutton.cpp
   qtoolbutton.h
   qvalidator.cpp
   qvalidator.h
   qwidgetanimator.cpp
   qwidgetanimator_p.h
   qwidgetresizehandler.cpp
   qwidgetresizehandler_p.h
   qworkspace.cpp
   qworkspace.h
   widgets.pri

/****************************************************************************
**
** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.  Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
** http://www.trolltech.com/products/qt/opensource.html
**
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://www.trolltech.com/products/qt/licensing.html or contact the
** sales department at sales@trolltech.com.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/

#include "qradiobutton.h"
#include "qapplication.h"
#include "qbitmap.h"
#include "qbuttongroup.h"
#include "qstylepainter.h"
#include "qstyle.h"
#include "qstyleoption.h"
#include "qevent.h"

#include "private/qabstractbutton_p.h"

class QRadioButtonPrivate : public QAbstractButtonPrivate
{
    Q_DECLARE_PUBLIC(QRadioButton)
public:
    QRadioButtonPrivate():hovering(true){}
    uint hovering : 1;
};


/*!
    \class QRadioButton
    \brief The QRadioButton widget provides a radio button with a text label.

    \ingroup basic
    \mainclass

    A QRadioButton is an option button that can be switched on (checked) or
    off (unchecked). Radio buttons typically present the user with a "one
    of many" choice. In a group of radio buttons only one radio button at
    a time can be checked; if the user selects another button, the
    previously selected button is switched off.

    Radio buttons are autoExclusive by default. If auto-exclusive is
    enabled, radio buttons that belong to the same parent widget
    behave as if they were part of the same exclusive button group. If
    you need multiple exclusive button groups for radio buttons that
    belong to the same parent widget, put them into a QButtonGroup.

    Whenever a button is switched on or off it emits the toggled() signal.
    Connect to this signal if you want to trigger an action each time the
    button changes state. Use isChecked() to see if a particular button is
    selected.

    Just like QPushButton, a radio button displays text, and
    optionally a small icon. The text can be set in the constructor or
    with setText(); the icon is set with setIcon().

    Important inherited members: text(), setText(), text(),
    setDown(), isDown(), autoRepeat(), group(), setAutoRepeat(),
    toggle(), pressed(), released(), clicked(), and toggled().

    \table 100%
    \row \o \inlineimage plastique-radiobutton.png Screenshot of a Plastique radio button
         \o A radio button shown in the \l{Plastique Style Widget Gallery}{Plastique widget style}.
    \row \o \inlineimage windows-radiobutton.png Screenshot of a Windows XP radio button
         \o A radio button shown in the \l{Windows XP Style Widget Gallery}{Windows XP widget style}.
    \row \o \inlineimage macintosh-radiobutton.png Screenshot of a Macintosh radio button
         \o A radio button shown in the \l{Macintosh Style Widget Gallery}{Macintosh widget style}.
    \endtable

    \sa QPushButton, QToolButton, QCheckBox, {fowler}{GUI Design Handbook: Radio Button},
        {Group Box Example}
*/


/*
    Initializes the radio button.
*/
static void qRadioButtonInit(QRadioButton *button)
{
    button->setCheckable(true);
    button->setAutoExclusive(true);
    button->setMouseTracking(true);
}


/*!
    Constructs a radio button with the given \a parent, but with no text or
    pixmap.

    The \a parent argument is passed on to the QAbstractButton constructor.
*/

QRadioButton::QRadioButton(QWidget *parent)
    : QAbstractButton(*new QRadioButtonPrivate, parent)
{
    qRadioButtonInit(this);
}

/*!
    Constructs a radio button with the given \a parent and a \a text string.

    The \a parent argument is passed on to the QAbstractButton constructor.
*/

QRadioButton::QRadioButton(const QString &text, QWidget *parent)
    : QAbstractButton(*new QRadioButtonPrivate, parent)
{
    qRadioButtonInit(this);
    setText(text);
}

static QStyleOptionButton getStyleOption(const QRadioButton *btn, bool hitButton = false)
{
    QStyleOptionButton opt;
    opt.init(btn);
    opt.text = btn->text();
    opt.icon = btn->icon();
    opt.iconSize = btn->iconSize();
    if (btn->isDown())
        opt.state |= QStyle::State_Sunken;
    opt.state |= (btn->isChecked() ? QStyle::State_On : QStyle::State_Off);
    if (btn->testAttribute(Qt::WA_Hover) && btn->underMouse()) {
        if (hitButton)
            opt.state |= QStyle::State_MouseOver;
        else
            opt.state &= ~QStyle::State_MouseOver;
    }
    return opt;
}

/*!
    \reimp
*/
QSize QRadioButton::sizeHint() const
{
    ensurePolished();
    QStyleOptionButton opt = getStyleOption(this);
    QSize sz = style()->itemTextRect(fontMetrics(), QRect(0, 0, 1, 1), Qt::TextShowMnemonic,
                                     false, text()).size();
    if (!opt.icon.isNull())
        sz = QSize(sz.width() + opt.iconSize.width() + 4, qMax(sz.height(), opt.iconSize.height()));
    return (style()->sizeFromContents(QStyle::CT_RadioButton, &opt, sz, this).
            expandedTo(QApplication::globalStrut()));
}

/*!
    \reimp
*/
bool QRadioButton::hitButton(const QPoint &pos) const
{
    QStyleOptionButton opt = getStyleOption(this);
    return style()->subElementRect(QStyle::SE_RadioButtonClickRect, &opt, this).contains(pos);
}

/*!
    \reimp
*/
void QRadioButton::mouseMoveEvent(QMouseEvent *e)
{
    Q_D(QRadioButton);
    if (testAttribute(Qt::WA_Hover)) {
        bool hit = false;
        if (underMouse())
            hit = hitButton(e->pos());

        if (hit != d->hovering) {
            update();
            d->hovering = hit;
        }
    }

    QAbstractButton::mouseMoveEvent(e);
}

/*!\reimp
 */
void QRadioButton::paintEvent(QPaintEvent *)
{
    Q_D(QRadioButton);
    QStylePainter p(this);
    QStyleOptionButton opt = getStyleOption(this, d->hovering);
    p.drawControl(QStyle::CE_RadioButton, opt);
}

/*! \reimp */
bool QRadioButton::event(QEvent *e)
{
    return QAbstractButton::event(e);
}

#ifdef QT3_SUPPORT
/*!
    Use one of the constructors that doesn't take the \a name
    argument and then use setObjectName() instead.
*/
QRadioButton::QRadioButton(QWidget *parent, const char* name)
    : QAbstractButton(*new QRadioButtonPrivate, parent)
{
    setObjectName(QString::fromAscii(name));
    qRadioButtonInit(this);
}

/*!
    Use one of the constructors that doesn't take the \a name
    argument and then use setObjectName() instead.
*/
QRadioButton::QRadioButton(const QString &text, QWidget *parent, const char* name)
    : QAbstractButton(*new QRadioButtonPrivate, parent)
{
    setObjectName(QString::fromAscii(name));
    qRadioButtonInit(this);
    setText(text);
}

#endif

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us