ATLAS Offline Software
VP1ColorSelectButton.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // //
7 // Implementation of class VP1ColorSelectButton //
8 // //
9 // Author: Thomas Kittelmann <Thomas.Kittelmann@cern.ch> //
10 // //
11 // Initial version: June 2007 //
12 // //
14 
16 #include "VP1Base/VP1Msg.h"
17 
18 #include <QColor>
19 #include <QColorDialog>
20 #include <QTimer>
21 #include <QShortcut>
22 
23 //____________________________________________________________________
25 public:
26  Imp(const QColor& col, VP1ColorSelectButton* but,int the_dim) : presentcolor(col),button(but),dim(the_dim) {}
27  QColor presentcolor;
29  int dim;
30 };
31 
32 //____________________________________________________________________
33 VP1ColorSelectButton::VP1ColorSelectButton(QWidget*parent,const QColor& initialcolor,int dim)
34  : QPushButton(parent), m_d(new Imp(initialcolor,this,dim))
35 {
36  connect (this,SIGNAL(clicked()),this,SLOT(launchColorChooser()));
37  QTimer::singleShot(0, this, SLOT(updateButton()));
38 }
39 
40 //____________________________________________________________________
42 {
43  if (objectName().isEmpty())
44  setObjectName("VP1ColorSelectButton");
46 }
47 
48 //____________________________________________________________________
49 void VP1ColorSelectButton::setColButtonProperties(QPushButton* pb,const QColor& col,int dim) {
50 
51 // if (VP1Msg::verbose())
52 // VP1Msg::messageVerbose("setColButtonProperties: button="+VP1Msg::str(pb)+", color="+VP1Msg::str(col));
53 
54  if (pb->objectName().isEmpty()) {
55  VP1Msg::messageDebug("VP1ColorSelectButton::setColButtonProperties() WARNING: Empty objectName()!!");
56  pb->setObjectName("VP1ColorSelectButton_setColButtonProperties");
57  }
58 
59  if (!pb->text().isEmpty()) {
60  VP1Msg::messageDebug("VP1ColorSelectButton::setColButtonProperties() WARNING: Noticed non-empty text field. Clearing!");
61  pb->QPushButton::setText("");
62  }
63 
64  pb->setStyleSheet("QPushButton#"+pb->objectName()+" { background-color: "
65  +col.name()+"; border-color: "+col.name()+"; }");
66  pb->setFocusPolicy(Qt::NoFocus);
67  if (dim>0) {
68  QSize sz = QSize(dim,dim);
69  QSizePolicy sp(QSizePolicy::Fixed, QSizePolicy::Fixed);
70  sp.setHorizontalStretch(0);
71  sp.setVerticalStretch(0);
72  sp.setHeightForWidth(pb->sizePolicy().hasHeightForWidth());
73  pb->setSizePolicy(sp);
74  pb->setMinimumSize(sz);
75  pb->setMaximumSize(sz);
76  }
77 }
78 
79 //____________________________________________________________________
81 {
82  delete m_d; m_d=0;
83 }
84 
85 //____________________________________________________________________
87 {
88  VP1Msg::messageVerbose("VP1ColorSelectButton emitting aboutToShowColorDialog()");
91  setColor(color);
92 }
93 
94 //____________________________________________________________________
96 {
97  if (!col.isValid())
98  return;
99  if (m_d->presentcolor==col)
100  return;
102  updateButton();
103  VP1Msg::messageVerbose("VP1ColorSelectButton emitting colorChanged("+col.name()+")");
104  emit colorChanged(col);
105 }
106 
107 //____________________________________________________________________
109 {
110  return m_d->presentcolor;
111 }
112 
113 //____________________________________________________________________
114 void VP1ColorSelectButton::setText( const QString & s )
115 {
116  if (!s.isEmpty())
117  VP1Msg::messageDebug("VP1ColorSelectButton::setText() called (with '"+s+"'), but not allowed!");
118 }
119 
120 //____________________________________________________________________
122 {
123  if (m_d->dim == dim)
124  return;
125  m_d->dim = dim;
126  updateButton();
127 }
color
Definition: jFexInputByteStreamTool.cxx:25
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
yodamerge_tmp.dim
dim
Definition: yodamerge_tmp.py:239
fitman.sz
sz
Definition: fitman.py:527
keylayer_zslicemap.pb
pb
Definition: keylayer_zslicemap.py:188
VP1ColorSelectButton::VP1ColorSelectButton
VP1ColorSelectButton(QWidget *parent=0, const QColor &initialcolor=Qt::black, int dim=24)
Definition: VP1ColorSelectButton.cxx:33
VP1Msg.h
VP1ColorSelectButton::Imp
Definition: VP1ColorSelectButton.cxx:24
VP1ColorSelectButton::setColor
void setColor(const QColor &)
Definition: VP1ColorSelectButton.cxx:95
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
VP1ColorSelectButton::Imp::Imp
Imp(const QColor &col, VP1ColorSelectButton *but, int the_dim)
Definition: VP1ColorSelectButton.cxx:26
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
VP1ColorSelectButton
Definition: VP1ColorSelectButton.h:20
VP1ColorSelectButton::setColButtonProperties
static void setColButtonProperties(QPushButton *, const QColor &col, int dim)
Definition: VP1ColorSelectButton.cxx:49
VP1ColorSelectButton::Imp::presentcolor
QColor presentcolor
Definition: VP1ColorSelectButton.cxx:27
getColor
unsigned long getColor(unsigned int r, unsigned int g, unsigned int b)
VP1ColorSelectButton::~VP1ColorSelectButton
virtual ~VP1ColorSelectButton()
Definition: VP1ColorSelectButton.cxx:80
test_pyathena.parent
parent
Definition: test_pyathena.py:15
VP1ColorSelectButton::color
QColor color() const
Definition: VP1ColorSelectButton.cxx:108
VP1ColorSelectButton.h
VP1ColorSelectButton::updateButton
void updateButton()
Definition: VP1ColorSelectButton.cxx:41
VP1ColorSelectButton::colorChanged
void colorChanged(const QColor &)
VP1ColorSelectButton::Imp::dim
int dim
Definition: VP1ColorSelectButton.cxx:29
VP1Msg::messageVerbose
static void messageVerbose(const QString &)
Definition: VP1Msg.cxx:84
query_example.col
col
Definition: query_example.py:7
VP1ColorSelectButton::m_d
Imp * m_d
Definition: VP1ColorSelectButton.h:44
VP1Msg::messageDebug
static void messageDebug(const QString &)
Definition: VP1Msg.cxx:39
VP1ColorSelectButton::setDimension
void setDimension(int dim)
Definition: VP1ColorSelectButton.cxx:121
VP1ColorSelectButton::Imp::button
VP1ColorSelectButton * button
Definition: VP1ColorSelectButton.cxx:28
VP1ColorSelectButton::aboutToShowColorDialog
void aboutToShowColorDialog()
VP1ColorSelectButton::launchColorChooser
void launchColorChooser()
Definition: VP1ColorSelectButton.cxx:86
VP1ColorSelectButton::setText
void setText(const QString &)
Definition: VP1ColorSelectButton.cxx:114