casa
$Rev:20696$
|
00001 //# QtButtonGroup.qo.h: Like QButtonGroup but with additional functionality. 00002 //# Copyright (C) 2009 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id: $ 00027 #ifndef QTBUTTONGROUP_QO_H_ 00028 #define QTBUTTONGROUP_QO_H_ 00029 00030 #include <QAbstractButton> 00031 00032 namespace casa { 00033 00034 // This class meant to be used almost identically to an exclusive QButtonGroup. 00035 // The difference is that this class allows all QAbstractButtons to be 00036 // unchecked; in other words, either one button is checked or none are. Some 00037 // methods from QButtonGroup have not been included, but they would be easy to 00038 // include if desired. 00039 class QtButtonGroup : public QObject { 00040 Q_OBJECT 00041 00042 public: 00043 // Constructor that takes optional parent object. 00044 QtButtonGroup(QObject* parent); 00045 00046 // Destructor. 00047 ~QtButtonGroup(); 00048 00049 00050 // See QButtonGroup::buttons(). 00051 QList<QAbstractButton*> buttons() const; 00052 00053 // See QButtonGroup::checkedButton(). Will return NULL if no button is 00054 // currently checked. 00055 QAbstractButton* checkedButton() const; 00056 00057 // See QButtonGroup::addButton(). 00058 void addButton(QAbstractButton* button); 00059 00060 // See QButtonGroup::removeButton(). 00061 void removeButton(QAbstractButton* button); 00062 00063 // Returns whether this group is enabled or not. 00064 bool isEnabled() const; 00065 00066 public slots: 00067 // Sets all buttons to enabled. 00068 void setEnabled(bool enabled); 00069 00070 // Sets all buttons to disabled. 00071 void setDisabled(bool disabled) { setEnabled(!disabled); } 00072 00073 signals: 00074 // See QButtonGroup::buttonClicked(). 00075 void buttonClicked(QAbstractButton* button); 00076 00077 // See QButtonGroup::buttonPressed(). 00078 void buttonPressed(QAbstractButton* button); 00079 00080 // See QButtonGroup::buttonReleased(). 00081 void buttonReleased(QAbstractButton* button); 00082 00083 // This signals is emitted when all buttons in the group have been 00084 // unchecked. 00085 void unchecked(); 00086 00087 private: 00088 // Enabled flag. 00089 bool isEnabled_; 00090 00091 // Currently checked button, or NULL if none are checked. 00092 QAbstractButton* itsCheckedButton_; 00093 00094 // Buttons in group. 00095 QList<QAbstractButton*> itsButtons_; 00096 00097 00098 // Method for when a button is the group is checked or toggled. 00099 void toggled_(QAbstractButton* button, bool checked); 00100 00101 private slots: 00102 // Slot for QAbstractButton::clicked(), which calls toggled_() as needed. 00103 void clicked(bool checked); 00104 00105 // Slot for QAbstractButton::toggled(), which calls toggled_() as needed. 00106 void toggled(bool checked); 00107 00108 // Slot for QAbstractButton::pressed(). 00109 void pressed(); 00110 00111 // Slot for QAbstractButton::released(). 00112 void released(); 00113 }; 00114 00115 } 00116 00117 #endif /* QTBUTTONGROUP_QO_H_ */