?? qbuttongroup.cpp
字號:
/****************************************************************************** $Id: qt/src/widgets/qbuttongroup.cpp 2.3.12 edited 2005-10-27 $**** Implementation of QButtonGroup class**** Created : 950130**** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.**** This file is part of the widgets module of the Qt GUI Toolkit.**** This file may be distributed under the terms of the Q Public License** as defined by Trolltech AS of Norway and appearing in the file** LICENSE.QPL included in the packaging of this file.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition** licenses may use this file in accordance with the Qt Commercial License** Agreement provided with the Software.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for** information about Qt Commercial License Agreements.** See http://www.trolltech.com/qpl/ for QPL licensing information.** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "qbuttongroup.h"#ifndef QT_NO_BUTTONGROUP#include "qbutton.h"#include "qlist.h"#include "qradiobutton.h"#include "qapplication.h"#ifdef QT_KEYPAD_MODEextern bool qt_modalEditingEnabled;#endif// NOT REVISED/*! \class QButtonGroup qbuttongroup.h \brief The QButtonGroup widget organizes QButton widgets in a group. \ingroup organizers A button group widget makes it easier to deal with groups of buttons. A button in a button group is associated with a unique identifer. The button group emits a clicked() signal with this identifier when the button is clicked. Thus, a button group is an ideal solution when you have several similar buttons and want to connect all their clicked() signals, for example, to one slot. An \link setExclusive() exclusive\endlink button group switches off all toggle buttons except the one that was clicked. A button group is by default non-exclusive. All \link QRadioButton radio buttons\endlink that are \link insert() inserted\endlink, will be mutually exclusive even if the button group is non-exclusive. There are two ways of using a button group: <ol> <li>The button group is a parent widget of a number of buttons, i.e. the button group is the parent argument in the button constructor. The buttons are assigned identifiers 0, 1, 2 etc. in the order they are created. A QButtonGroup can display a frame and a title because it inherits QGroupBox. <li>The button group is an invisible widget and the contained buttons have some other parent widget. A button must then be manually inserted using the insert() function with an identifer. </ol> <img src=qbttngrp-m.png> <img src=qbttngrp-w.png> \sa QButton, QPushButton, QCheckBox, QRadioButton*/struct QButtonItem{ QButton *button; int id;};class QButtonList: public QList<QButtonItem>{public: QButtonList() {} ~QButtonList() {}};typedef QListIterator<QButtonItem> QButtonListIt;/*! Constructs a button group with no title. The \e parent and \e name arguments are passed to the QWidget constructor.*/QButtonGroup::QButtonGroup( QWidget *parent, const char *name ) : QGroupBox( parent, name ){ init();}/*! Constructs a button group with a title. The \e parent and \e name arguments are passed to the QWidget constructor.*/QButtonGroup::QButtonGroup( const QString &title, QWidget *parent, const char *name ) : QGroupBox( title, parent, name ){ init();}/*! Constructs a button group with no title. Child widgets will be arranged in \a strips rows or columns (depending on \a orientation). The \e parent and \e name arguments are passed to the QWidget constructor.*/QButtonGroup::QButtonGroup( int strips, Orientation orientation, QWidget *parent, const char *name ) : QGroupBox( strips, orientation, parent, name ){ init();}/*! Constructs a button group with a \a title. Child widgets will be arranged in \a strips rows or columns (depending on \a orientation). The \e parent and \e name arguments are passed to the QWidget constructor.*/QButtonGroup::QButtonGroup( int strips, Orientation orientation, const QString &title, QWidget *parent, const char *name ) : QGroupBox( strips, orientation, title, parent, name ){ init();}/*! Initializes the button group.*/void QButtonGroup::init(){ buttons = new QButtonList; CHECK_PTR( buttons ); buttons->setAutoDelete( TRUE ); excl_grp = FALSE; radio_excl = TRUE;}/*! \reimp */QButtonGroup::~QButtonGroup(){ QButtonList * tmp = buttons; QButtonItem *bi = tmp->first(); buttons = 0; while( bi ) { bi->button->setGroup(0); bi = tmp->next(); } delete tmp;}/*! Returns TRUE if the button group is exclusive, otherwise FALSE. \sa setExclusive()*/bool QButtonGroup::isExclusive() const{ return excl_grp;}/*! Sets the button group to be exclusive if \e enable is TRUE, or to be non-exclusive if \e enable is FALSE. An exclusive button group switches off all other toggle buttons when one is switched on. This is ideal for groups of \link QRadioButton radio buttons\endlink. A non-exclusive group allow many buttons to be switched on at the same time. The default setting is FALSE. \sa isExclusive()*/void QButtonGroup::setExclusive( bool enable ){ excl_grp = enable;}/*! Inserts a button with the identifier \e id into the button group. Returns the button identifier. It is not necessary to manually insert buttons that have this button group as their parent widget. An exception is when you want custom identifiers instead of the default 0, 1, 2 etc. The button is assigned the identifier \e id or an automatically generated identifier. It works as follows: If \e id >= 0, this identifier is assigned. If \e id == -1 (default), the identifier is equal to the number of buttons in the group. If \e id is any other negative integer, for instance -2, a unique identifier (negative integer \<= -2) is generated. Inserting several buttons with \e id = -1 assigns the identifiers 0, 1, 2, etc. \sa find(), remove(), setExclusive()*/int QButtonGroup::insert( QButton *button, int id ){ if ( button->group() ) button->group()->remove( button ); static int seq_no = -2; QButtonItem *bi = new QButtonItem; CHECK_PTR( bi ); if ( id < -1 ) bi->id = seq_no--; else if ( id == -1 ) bi->id = buttons->count(); else bi->id = id; bi->button = button; button->setGroup(this); buttons->append( bi ); connect( button, SIGNAL(pressed()) , SLOT(buttonPressed()) ); connect( button, SIGNAL(released()), SLOT(buttonReleased()) ); connect( button, SIGNAL(clicked()) , SLOT(buttonClicked()) ); connect( button, SIGNAL(toggled(bool)) , SLOT(buttonToggled(bool)) );#ifdef QT_KEYPAD_MODE if( !qt_modalEditingEnabled )#endif if ( button->isToggleButton() && !button->isOn() && selected() && (selected()->focusPolicy() & TabFocus) != 0 ) button->setFocusPolicy( (FocusPolicy)(button->focusPolicy() & ~TabFocus) ); return bi->id;}/*! Returns the number of buttons in the group.*/int QButtonGroup::count() const{ return buttons->count();}/*! Removes a button from the button group. \sa insert()*/void QButtonGroup::remove( QButton *button ){ if ( !buttons ) return; QButtonListIt it( *buttons ); QButtonItem *i; while ( (i=it.current()) != 0 ) { ++it; if ( i->button == button ) { buttons->remove( i ); button->setGroup(0); button->disconnect( this ); return; } }}/*! Finds and returns a pointer to the button with the specified identifier \e id. Returns null if the button was not found.*/QButton *QButtonGroup::find( int id ) const{ // introduce a QButtonListIt if calling anything for ( QButtonItem *i=buttons->first(); i; i=buttons->next() ) if ( i->id == id ) return i->button; return 0;}/*! \fn void QButtonGroup::pressed( int id )
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -