CustusX  2023.01.05-dev+develop.0da12
An IGT application
cxColorSelectButton.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 #include "cxColorSelectButton.h"
12 #include <iostream>
13 #include <QtWidgets>
14 #include "cxSettings.h"
15 
16 namespace cx
17 {
18 
19 ColorSelectButton::ColorSelectButton(QString caption, QColor color, QWidget* parent) : QToolButton(parent)
20 {
21  if (!caption.isEmpty())
22  this->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
23  this->setText(caption);
24  connect(this, SIGNAL(clicked()), this, SLOT(clickedSlot()));
25  this->setColor(color);
26 }
27 
28 void ColorSelectButton::setColor(QColor color)
29 {
30  mColor = color;
31 
32  QPixmap pixmap(16,16);
33  pixmap.fill(mColor);
34  this->setIcon(QIcon(pixmap));
35 }
36 
37 void ColorSelectButton::clickedSlot()
38 {
39  QColor result = QColorDialog::getColor( mColor, this, "Select color", QColorDialog::ShowAlphaChannel | QColorDialog::DontUseNativeDialog);
40  if (!result.isValid())
41  return;
42  this->setColor(result);
43  emit (colorChanged(mColor));
44 }
45 
46 //---------------------------------------------------------
47 //---------------------------------------------------------
48 //---------------------------------------------------------
49 
50 SelectColorSettingButton::SelectColorSettingButton(QString caption, QString id, QString help) :
51  ColorSelectButton(caption),
52  mId(id)
53 {
54  this->setColor(settings()->value(mId).value<QColor>());
55  this->setStatusTip(help);
56  this->setToolTip(help);
59 }
60 
62 {
63  settings()->setValue(mId, color);
64 }
65 
66 }
Convenience button for chosing color. Will open a color select dialog, and color the button itself in...
SelectColorSettingButton(QString caption, QString id, QString help)
void setValue(const QString &key, const QVariant &value)
Definition: cxSettings.cpp:58
void setColor(QColor color)
void colorChanged(QColor)
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:21
ColorSelectButton(QString caption, QColor color=Qt::white, QWidget *parent=NULL)
Namespace for all CustusX production code.