CustusX  18.04
An IGT application
cxColorSelectWidget.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 #include "cxColorSelectWidget.h"
13 #include "cxHelperWidgets.h"
14 
15 namespace cx
16 {
17 
18 ColorSelectWidget::ColorSelectWidget(QWidget* parent, ColorPropertyBasePtr dataInterface, QGridLayout* gridLayout, int row) :
19  OptimizedUpdateWidget(parent)
20 {
21  this->setEnabled(dataInterface->getEnabled());
22 
23  mData = dataInterface;
24  connect(mData.get(), SIGNAL(changed()), this, SLOT(setModified()));
25 
26  mLabel = new QLabel(this);
27  mLabel->setText(dataInterface->getDisplayName());
28 
29  mColorButton = new cx::ColorSelectButton("");
30 
31  // emit as queued signal because of crash issues related to handling the signal
32  // in the modal loop of the color select dialog of cx:ColorSelectButton.
33  connect(mColorButton, SIGNAL(colorChanged(QColor)), this, SLOT(valueChanged(QColor)), Qt::QueuedConnection);
34 
35  if (gridLayout) // add to input gridlayout
36  {
37  gridLayout->addLayout(mergeWidgetsIntoHBoxLayout(mLabel, addDummyMargin(this)), row, 0);
38  gridLayout->addWidget(mColorButton, row, 1);
39  }
40  else // add directly to this
41  {
42  QHBoxLayout* topLayout = new QHBoxLayout;
43  topLayout->setMargin(0);
44  this->setLayout(topLayout);
45 
46  topLayout->addWidget(mLabel);
47  topLayout->addWidget(mColorButton, 1);
48  }
49 
50  this->setModified();
51 }
52 
53 void ColorSelectWidget::valueChanged(QColor val)
54 {
55  if (val == mData->getValue())
56  return;
57  mData->setValue(val);
58 }
59 
60 void ColorSelectWidget::prePaintEvent()
61 {
62  mColorButton->blockSignals(true);
63 
64  this->setEnabled(mData->getEnabled());
65 
66  mColorButton->setColor(mData->getValue());
67  mColorButton->setToolTip(mData->getHelp());
68  mLabel->setToolTip(mData->getHelp());
69 
70  mColorButton->blockSignals(false);
71 }
72 
73 
74 } // namespace cx
75 
Convenience button for chosing color. Will open a color select dialog, and color the button itself in...
QWidget * addDummyMargin(QWidget *widget)
ColorSelectWidget(QWidget *parent, ColorPropertyBasePtr data, QGridLayout *gridLayout=0, int row=0)
QHBoxLayout * mergeWidgetsIntoHBoxLayout(QWidget *first, QWidget *second)
void setColor(QColor color)
Interface for all classes following the modified/prepaint paradigm.
boost::shared_ptr< class ColorPropertyBase > ColorPropertyBasePtr
Namespace for all CustusX production code.