NorMIT-nav  22.09
An IGT application
cxCheckBoxWidget.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 
13 /*
14  * sscCheckBoxWidget.cpp
15  *
16  * Created on: Feb 7, 2011
17  * Author: christiana
18  */
19 
20 #include "cxCheckBoxWidget.h"
21 #include <QGridLayout>
22 #include "cxHelperWidgets.h"
23 
24 namespace cx
25 {
26 
27 CheckBoxWidget::CheckBoxWidget(QWidget* parent, BoolPropertyBasePtr dataInterface, QGridLayout* gridLayout, int row) :
28  OptimizedUpdateWidget(parent)
29 {
30  this->setEnabled(dataInterface->getEnabled());
31 
32  mData = dataInterface;
33  connect(mData.get(), SIGNAL(changed()), this, SLOT(setModified()));
34 
35  mLabel = new QLabel(this);
36  mLabel->setText(dataInterface->getDisplayName());
37 
38  mCheckBox = new QCheckBox(this);
39  connect(mCheckBox, SIGNAL(toggled(bool)), this, SLOT(valueChanged(bool)));
40 
41  if (gridLayout) // add to input gridlayout
42  {
43  gridLayout->addLayout(mergeWidgetsIntoHBoxLayout(mLabel, addDummyMargin(this)), row, 0);
44  gridLayout->addWidget(mCheckBox, row, 1);
45  }
46  else // add directly to this
47  {
48  QHBoxLayout* topLayout = new QHBoxLayout;
49  topLayout->setMargin(0);
50  this->setLayout(topLayout);
51 
52  topLayout->addWidget(mLabel);
53  topLayout->addWidget(mCheckBox, 1);
54  }
55 
56  this->setModified();
57 }
58 
59 void CheckBoxWidget::valueChanged(bool val)
60 {
61  if (val == mData->getValue())
62  return;
63  mData->setValue(val);
64 }
65 
66 void CheckBoxWidget::prePaintEvent()
67 {
68  mCheckBox->blockSignals(true);
69 
70  this->setEnabled(mData->getEnabled());
71  mCheckBox->setEnabled(mData->getEnabled());
72 
73  mCheckBox->setChecked(mData->getValue());
74  mCheckBox->setToolTip(mData->getHelp());
75  mLabel->setToolTip(mData->getHelp());
76 
77  mCheckBox->blockSignals(false);
78 }
79 
80 // --------------------------------------------------------
81 
82 
83 }
cx::CheckBoxWidget::CheckBoxWidget
CheckBoxWidget(QWidget *parent, BoolPropertyBasePtr data, QGridLayout *gridLayout=0, int row=0)
Definition: cxCheckBoxWidget.cpp:27
cx::addDummyMargin
QWidget * addDummyMargin(QWidget *widget)
Definition: cxHelperWidgets.cpp:123
cx::OptimizedUpdateWidget::setModified
virtual void setModified()
Definition: cxOptimizedUpdateWidget.cpp:36
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cxCheckBoxWidget.h
cx::mergeWidgetsIntoHBoxLayout
QHBoxLayout * mergeWidgetsIntoHBoxLayout(QWidget *first, QWidget *second)
Definition: cxHelperWidgets.cpp:131
cxHelperWidgets.h
cx::BoolPropertyBasePtr
boost::shared_ptr< class BoolPropertyBase > BoolPropertyBasePtr
Definition: cxImageFileStreamerService.h:22
cx::OptimizedUpdateWidget
Interface for all classes following the modified/prepaint paradigm.
Definition: cxOptimizedUpdateWidget.h:41