Fraxinus  2023.01.05-dev+develop.0da12
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 }
QWidget * addDummyMargin(QWidget *widget)
QHBoxLayout * mergeWidgetsIntoHBoxLayout(QWidget *first, QWidget *second)
boost::shared_ptr< class BoolPropertyBase > BoolPropertyBasePtr
Interface for all classes following the modified/prepaint paradigm.
CheckBoxWidget(QWidget *parent, BoolPropertyBasePtr data, QGridLayout *gridLayout=0, int row=0)
Namespace for all CustusX production code.