PixelLightAPI  .
AbstractToggleButton.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: AbstractToggleButton.h                         *
00003  *
00004  *  Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLGUI_ABSTRACTTOGGLEBUTTON_H__
00024 #define __PLGUI_ABSTRACTTOGGLEBUTTON_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLGui/Widgets/Base/AbstractButton.h"
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Namespace                                             ]
00036 //[-------------------------------------------------------]
00037 namespace PLGui {
00038 
00039 
00040 //[-------------------------------------------------------]
00041 //[ Forward declarations                                  ]
00042 //[-------------------------------------------------------]
00043 class ButtonGroup;
00044 
00045 
00046 //[-------------------------------------------------------]
00047 //[ Classes                                               ]
00048 //[-------------------------------------------------------]
00049 /**
00050 *  @brief
00051 *    Abstract base class for toggle buttons (two or three states)
00052 */
00053 class AbstractToggleButton : public AbstractButton {
00054 
00055 
00056     //[-------------------------------------------------------]
00057     //[ Class definition                                      ]
00058     //[-------------------------------------------------------]
00059     pl_class(PLGUI_RTTI_EXPORT, AbstractToggleButton, "PLGui", PLGui::AbstractButton, "Abstract base class for toggle buttons (two or three states)")
00060         // Attributes
00061         pl_attribute(PartiallyAllowed,  bool,                       false,      ReadWrite,  GetSet, "Is the third state (PartiallyChecked) allowed?",   "")
00062         pl_attribute(State,             pl_enum_type(ECheckState),  NotChecked, ReadWrite,  GetSet, "Current check state",                              "")
00063         // Signals
00064         pl_signal_1(SignalToggled,  ECheckState,    "The button has been toggled",  "")
00065         // Slots
00066         pl_slot_1(OnGroupActivate,  AbstractToggleButton*,  "Group callback",   "")
00067     pl_class_end
00068 
00069 
00070     //[-------------------------------------------------------]
00071     //[ Public functions                                      ]
00072     //[-------------------------------------------------------]
00073     public:
00074         /**
00075         *  @brief
00076         *    Constructor
00077         *
00078         *  @param[in] pParent
00079         *    Pointer to the parent widget
00080         */
00081         PLGUI_API AbstractToggleButton(Widget *pParent = nullptr);
00082 
00083         /**
00084         *  @brief
00085         *    Destructor
00086         */
00087         PLGUI_API virtual ~AbstractToggleButton();
00088 
00089         /**
00090         *  @brief
00091         *    Get group that the toggle button belongs to
00092         *
00093         *  @return
00094         *    Pointer to button group (can be a null pointer)
00095         */
00096         PLGUI_API ButtonGroup *GetGroup() const;
00097 
00098         /**
00099         *  @brief
00100         *    Set group that the toggle button belongs to
00101         *
00102         *  @param[in] pGroup
00103         *    Pointer to button group
00104         */
00105         PLGUI_API void SetGroup(ButtonGroup *pGroup);
00106 
00107         /**
00108         *  @brief
00109         *    Check if the toggle button can be checked partially (third state)
00110         *
00111         *  @return
00112         *    'true', if the state PartiallyChecked is allowed, else 'false'
00113         */
00114         PLGUI_API bool GetPartiallyAllowed() const;
00115 
00116         /**
00117         *  @brief
00118         *    Set if the toggle button can be checked partially (third state)
00119         *
00120         *  @param[in] bPartiallyAllowed
00121         *    'true', if the state PartiallyChecked is allowed, else 'false'
00122         */
00123         PLGUI_API void SetPartiallyAllowed(bool bPartiallyAllowed);
00124 
00125         /**
00126         *  @brief
00127         *    Get checked-state of button
00128         *
00129         *  @return
00130         *    Check state
00131         */
00132         PLGUI_API ECheckState GetState() const;
00133 
00134         /**
00135         *  @brief
00136         *    Set checked-state of button
00137         *
00138         *  @param[in] nState
00139         *    Check state
00140         *
00141         *  @remarks
00142         *    This function also emits a checked-event when called.
00143         */
00144         PLGUI_API void SetState(ECheckState nState);
00145 
00146         /**
00147         *  @brief
00148         *    Toggle button
00149         *
00150         *  @remarks
00151         *    Toggles the state of the button in the following way:
00152         *      NotChecked     -> Checked
00153         *      PartialChecked -> Checked
00154         *      Checked        -> NotChecked
00155         *    This function also emits a checked-event when called.
00156         */
00157         PLGUI_API void Toggle();
00158 
00159 
00160     //[-------------------------------------------------------]
00161     //[ Protected virtual AbstractToggleButton functions      ]
00162     //[-------------------------------------------------------]
00163     protected:
00164         virtual void OnButtonToggled(ECheckState nChecked);
00165 
00166 
00167     //[-------------------------------------------------------]
00168     //[ Protected virtual AbstractButton functions            ]
00169     //[-------------------------------------------------------]
00170     protected:
00171         virtual void OnButtonClicked() override;
00172 
00173 
00174     //[-------------------------------------------------------]
00175     //[ Protected functions                                   ]
00176     //[-------------------------------------------------------]
00177     protected:
00178         /**
00179         *  @brief
00180         *    This function is called when a button of the group is activated
00181         *
00182         *  @param[in] pButton
00183         *    Pointer to button that is being activated
00184         */
00185         void OnGroupActivate(AbstractToggleButton *pButton);
00186 
00187 
00188     //[-------------------------------------------------------]
00189     //[ Protected data                                        ]
00190     //[-------------------------------------------------------]
00191     protected:
00192         ButtonGroup *m_pGroup;              /**< Pointer to button group, can be a null pointer */
00193         bool         m_bPartiallyAllowed;   /**< Is the third state (PartiallyChecked) allowed? */
00194         ECheckState  m_nState;              /**< Current check state */
00195 
00196 
00197 };
00198 
00199 
00200 //[-------------------------------------------------------]
00201 //[ Namespace                                             ]
00202 //[-------------------------------------------------------]
00203 } // PLGui
00204 
00205 
00206 #endif // __PLGUI_ABSTRACTTOGGLEBUTTON_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:50:50
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported