ctkButtonGroup.cpp

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Library:   CTK
00004  
00005   Copyright (c) 2010  Kitware Inc.
00006 
00007   Licensed under the Apache License, Version 2.0 (the "License");
00008   you may not use this file except in compliance with the License.
00009   You may obtain a copy of the License at
00010 
00011       http://www.commontk.org/LICENSE
00012 
00013   Unless required by applicable law or agreed to in writing, software
00014   distributed under the License is distributed on an "AS IS" BASIS,
00015   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016   See the License for the specific language governing permissions and
00017   limitations under the License.
00018  
00019 =========================================================================*/
00020 
00021 //Qt includes  
00022 #include <QAbstractButton>
00023 #include <QDebug>
00024 #include <QWeakPointer>
00025 
00026 // CTK includes
00027 #include "ctkButtonGroup.h"
00028 
00029 //-----------------------------------------------------------------------------
00030 class ctkButtonGroupPrivate : public ctkPrivate<ctkButtonGroup>
00031 {
00032 public:
00033   CTK_DECLARE_PUBLIC(ctkButtonGroup);
00034   bool IsLastButtonPressedChecked;
00035 };
00036 
00037 //------------------------------------------------------------------------------
00038 ctkButtonGroup::ctkButtonGroup(QObject* _parent)
00039   :QButtonGroup(_parent)
00040 {
00041   CTK_INIT_PRIVATE(ctkButtonGroup);
00042   connect(this, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(onButtonClicked(QAbstractButton*)));
00043   connect(this, SIGNAL(buttonPressed(QAbstractButton*)), this, SLOT(onButtonPressed(QAbstractButton*)));
00044 }
00045 
00046 //------------------------------------------------------------------------------
00047 void ctkButtonGroup::onButtonClicked(QAbstractButton *clickedButton)
00048 {
00049   CTK_D(ctkButtonGroup);
00050   if (!this->exclusive() || !d->IsLastButtonPressedChecked)
00051     {
00052     return;
00053     }
00054   this->removeButton(clickedButton);
00055   clickedButton->setChecked(false);
00056   this->addButton(clickedButton);
00057 }
00058 
00059 //------------------------------------------------------------------------------
00060 void ctkButtonGroup::onButtonPressed(QAbstractButton *pressedButton)
00061 {
00062   CTK_D(ctkButtonGroup);
00063   Q_ASSERT(pressedButton);
00064   d->IsLastButtonPressedChecked = pressedButton->isChecked();
00065 }
00066 
00067 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines