⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qgroupbox.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 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://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** 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 "qgroupbox.h"#ifndef QT_NO_GROUPBOX#include "qapplication.h"#include "qbitmap.h"#include "qdrawutil.h"#include "qevent.h"#include "qlayout.h"#include "qradiobutton.h"#include "qstyle.h"#include "qstyleoption.h"#include "qstylepainter.h"#ifndef QT_NO_ACCESSIBILITY#include "qaccessible.h"#endif#include <private/qwidget_p.h>#include "qdebug.h"class QGroupBoxPrivate : public QWidgetPrivate{    Q_DECLARE_PUBLIC(QGroupBox)public:    void skip();    void init();    void calculateFrame();    QString title;    int align;#ifndef QT_NO_SHORTCUT    int shortcutId;#endif    void _q_fixFocus(Qt::FocusReason reason);    void _q_setChildrenEnabled(bool b);    void click();    bool flat;    bool checkable;    bool checked;    bool hover;    QStyle::SubControl pressedControl;};/*!    Initialize \a option with the values from this QGroupBox. This method    is useful for subclasses when they need a QStyleOptionGroupBox, but don't want    to fill in all the information themselves.    \sa QStyleOption::initFrom()*/void QGroupBox::initStyleOption(QStyleOptionGroupBox *option) const{    if (!option)        return;    Q_D(const QGroupBox);    option->initFrom(this);    option->text = d->title;    option->lineWidth = 1;    option->midLineWidth = 0;    option->textAlignment = Qt::Alignment(d->align);    option->activeSubControls |= d->pressedControl;    option->subControls = QStyle::SC_GroupBoxFrame;    if (d->hover)        option->state |= QStyle::State_MouseOver;    else        option->state &= ~QStyle::State_MouseOver;    if (d->flat)        option->features |= QStyleOptionFrameV2::Flat;    if (d->checkable) {        option->subControls |= QStyle::SC_GroupBoxCheckBox;        option->state |= (d->checked ? QStyle::State_On : QStyle::State_Off);        if (d->pressedControl == QStyle::SC_GroupBoxCheckBox                || d->pressedControl == QStyle::SC_GroupBoxLabel)            option->state |= QStyle::State_Sunken;    }    if (!testAttribute(Qt::WA_SetPalette))        option->textColor = QColor(style()->styleHint(QStyle::SH_GroupBox_TextLabelColor,                                   option, this));    if (!d->title.isEmpty())        option->subControls |= QStyle::SC_GroupBoxLabel;}void QGroupBoxPrivate::click(){    Q_Q(QGroupBox);    QPointer<QGroupBox> guard(q);    q->setChecked(!checked);    if (!guard)        return;    emit q->clicked(checked);}/*!    \class QGroupBox    \brief The QGroupBox widget provides a group box frame with a title.    \ingroup organizers    \ingroup geomanagement    \ingroup appearance    \mainclass    A group box provides a frame, a title and a keyboard shortcut, and    displays various other widgets inside itself. The title is on top,    the keyboard shortcut moves keyboard focus to one of the group    box's child widgets.    QGroupBox also lets you set the \l title (normally set in the    constructor) and the title's \l alignment. Group boxes can be    \l checkable; child widgets in checkable group boxes are enabled or    disabled depending on whether or not the group box is \l checked.    You can minimize the space consumption of a group box by enabling    the \l flat property. In most \l{QStyle}{styles}, enabling this    property results in the removal of the left, right and bottom    edges of the frame.    QGroupBox doesn't automatically lay out the child widgets (which    are often \l{QCheckBox}es or \l{QRadioButton}s but can be any    widgets). The following example shows how we can set up a    QGroupBox with a layout:    \quotefromfile widgets/groupbox/window.cpp    \skipto = new QGroupBox    \printuntil setLayout(    \table 100%    \row \o \inlineimage windowsxp-groupbox.png Screenshot of a Windows XP style group box         \o \inlineimage macintosh-groupbox.png Screenshot of a Macintosh style group box         \o \inlineimage plastique-groupbox.png Screenshot of a Plastique style group box    \row \o A \l{Windows XP Style Widget Gallery}{Windows XP style} group box.         \o A \l{Macintosh Style Widget Gallery}{Macintosh style} group box.         \o A \l{Plastique Style Widget Gallery}{Plastique style} group box.    \endtable    \sa QButtonGroup, {Group Box Example}*//*!    Constructs a group box widget with the given \a parent but with no title.*/QGroupBox::QGroupBox(QWidget *parent)    : QWidget(*new QGroupBoxPrivate, parent, 0){    Q_D(QGroupBox);    d->init();}/*!    Constructs a group box with the given \a title and \a parent.*/QGroupBox::QGroupBox(const QString &title, QWidget *parent)    : QWidget(*new QGroupBoxPrivate, parent, 0){    Q_D(QGroupBox);    d->init();    setTitle(title);}/*!    Destroys the group box.*/QGroupBox::~QGroupBox(){}void QGroupBoxPrivate::init(){    Q_Q(QGroupBox);    align = Qt::AlignLeft;#ifndef QT_NO_SHORTCUT    shortcutId = 0;#endif    flat = false;    checkable = false;    checked = true;    hover = false;    pressedControl = QStyle::SC_None;    calculateFrame();    q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred,                      QSizePolicy::GroupBox));}void QGroupBox::setTitle(const QString &title){    Q_D(QGroupBox);    if (d->title == title)                                // no change        return;    d->title = title;#ifndef QT_NO_SHORTCUT    releaseShortcut(d->shortcutId);    d->shortcutId = grabShortcut(QKeySequence::mnemonic(title));#endif    d->calculateFrame();    update();    updateGeometry();#ifndef QT_NO_ACCESSIBILITY    QAccessible::updateAccessibility(this, 0, QAccessible::NameChanged);#endif}/*!    \property QGroupBox::title    \brief the group box title text    The group box title text will have a keyboard shortcut if the title    contains an ampersand ('&') followed by a letter.    \code        g->setTitle("&User information");    \endcode    In the example above, \key Alt+U moves the keyboard focus to the    group box. See the \l {QShortcut#mnemonic}{QShortcut}    documentation for details (to display an actual ampersand, use    '&&').    There is no default title text.    \sa alignment*/QString QGroupBox::title() const{    Q_D(const QGroupBox);    return d->title;}/*!    \property QGroupBox::alignment    \brief the alignment of the group box title.    Most styles place the title at the top of the frame. The horizontal    alignment of the title can be specified using single values from    the following list:    \list    \i Qt::AlignLeft aligns the title text with the left-hand side of the group box.    \i Qt::AlignRight aligns the title text with the right-hand side of the group box.    \i Qt::AlignHCenter aligns the title text with the horizontal center of the group box.    \endlist    The default alignment is Qt::AlignLeft.    \sa Qt::Alignment*/Qt::Alignment QGroupBox::alignment() const{    Q_D(const QGroupBox);    return QFlag(d->align);}void QGroupBox::setAlignment(int alignment){    Q_D(QGroupBox);    d->align = alignment;    updateGeometry();    update();}/*! \reimp*/void QGroupBox::resizeEvent(QResizeEvent *e){    QWidget::resizeEvent(e);    updateGeometry();}/*! \reimp*/void QGroupBox::paintEvent(QPaintEvent *){    QStylePainter paint(this);    QStyleOptionGroupBox option;    initStyleOption(&option);    paint.drawComplexControl(QStyle::CC_GroupBox, option);}/*! \reimp  */bool QGroupBox::event(QEvent *e){    Q_D(QGroupBox);#ifndef QT_NO_SHORTCUT    if (e->type() == QEvent::Shortcut) {        QShortcutEvent *se = static_cast<QShortcutEvent *>(e);        if (se->shortcutId() == d->shortcutId) {            if (!isCheckable()) {                d->_q_fixFocus(Qt::ShortcutFocusReason);            } else {                d->click();                setFocus(Qt::ShortcutFocusReason);            }            return true;        }    }#endif    QStyleOptionGroupBox box;    initStyleOption(&box);    switch (e->type()) {    case QEvent::HoverEnter:    case QEvent::HoverMove: {        QStyle::SubControl control = style()->hitTestComplexControl(QStyle::CC_GroupBox, &box,                                                                    static_cast<QHoverEvent *>(e)->pos(),                                                                    this);        bool oldHover = d->hover;        d->hover = d->checkable && (control == QStyle::SC_GroupBoxLabel || control == QStyle::SC_GroupBoxCheckBox);        if (oldHover != d->hover) {            QRect rect = style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxCheckBox, this)                         | style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxLabel, this);            update(rect);        }        return true;    }    case QEvent::HoverLeave:        d->hover = false;        if (d->checkable) {            QRect rect = style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxCheckBox, this)                         | style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxLabel, this);            update(rect);        }        return true;    case QEvent::KeyPress: {        QKeyEvent *k = static_cast<QKeyEvent*>(e);        if (!k->isAutoRepeat() && (k->key() == Qt::Key_Select || k->key() == Qt::Key_Space)) {            d->pressedControl = QStyle::SC_GroupBoxCheckBox;            update(style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxCheckBox, this));            return true;        }        break;    }    case QEvent::KeyRelease: {        QKeyEvent *k = static_cast<QKeyEvent*>(e);        if (!k->isAutoRepeat() && (k->key() == Qt::Key_Select || k->key() == Qt::Key_Space)) {            bool toggle = (d->pressedControl == QStyle::SC_GroupBoxLabel                           || d->pressedControl == QStyle::SC_GroupBoxCheckBox);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -