GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4Style.cpp
Go to the documentation of this file.
1 // $Id$
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4Style.h"
15 
16 #include "TStyle.h"
17 #include "TColor.h"
18 #include "TPad.h"
19 
20 #include "TGo4Picture.h"
21 #include "TGo4MdiArea.h"
22 #include "TGo4ViewPanel.h"
23 #include "TGo4QSettings.h"
24 
25 #include <QColorDialog>
26 
27 TGo4Style::TGo4Style(QWidget *parent, const char *name, Qt::WindowFlags fl) :
28  QWidget( parent, fl ), fbMenuLock(false), fbSettingPanelData(false)
29 {
30  setObjectName(name ? name : "Go4Style");
31  setupUi(this);
32 
33  QObject::connect(Palette, QOverload<int>::of(&QSpinBox::valueChanged), this, &TGo4Style::SetPalette);
34  QObject::connect(PaletteComboBox, QOverload<int>::of(&QComboBox::activated), this, &TGo4Style::SetNamedPalette);
35  QObject::connect(ContourSpin, QOverload<int>::of(&QSpinBox::valueChanged), this, &TGo4Style::SetContourLevels);
36  QObject::connect(PadColor, &QPushButton::clicked, this, &TGo4Style::SetPadColor);
37 
39 
40  for(int i=GO4NAMEDPAL_MIN; i<=GO4NAMEDPAL_MAX+2; ++i) // need two indices more for Go4_None and Go4_Default
41  {
42  PaletteComboBox->addItem("dummy");
43  }
44  PaletteComboBox->setItemText(Go4_None, "unnamed palette");
45  PaletteComboBox->setItemText(Go4_Default, "ClassicDefault");
46  PaletteComboBox->setItemText(Go4_DeepSea, "DeepSea");
47  PaletteComboBox->setItemText(Go4_GreyScale, "GreyScale");
48  PaletteComboBox->setItemText(Go4_DarkBodyRadiator, "DarkBodyRadiator");
49  PaletteComboBox->setItemText(Go4_BlueYellow, "BlueYellow");
50  PaletteComboBox->setItemText(Go4_RainBow, "RainBow");
51  PaletteComboBox->setItemText(Go4_InvertedDarkBodyRadiator,"InvertedDarkBodyRadiator");
52 // below for ROOT 6 only. This is all handled by indices of init loop above
53  PaletteComboBox->setItemText(Go4_Bird, "Bird");
54  PaletteComboBox->setItemText(Go4_Cubehelix, "Cubehelix");
55  PaletteComboBox->setItemText(Go4_GreenRedViolet, "GreenRedViolet");
56  PaletteComboBox->setItemText(Go4_BlueRedYellow, "BlueRedYellow");
57  PaletteComboBox->setItemText(Go4_Ocean, "Ocean");
58  PaletteComboBox->setItemText(Go4_ColorPrintableOnGrey, "ColorPrintableOnGrey");
59  PaletteComboBox->setItemText(Go4_Alpine, "Alpine");
60  PaletteComboBox->setItemText(Go4_Aquamarine, "Aquamarine");
61  PaletteComboBox->setItemText(Go4_Army, "Army");
62  PaletteComboBox->setItemText(Go4_Atlantic, "Atlantic");
63  PaletteComboBox->setItemText(Go4_Aurora, "Aurora");
64  PaletteComboBox->setItemText(Go4_Avocado, "Avocado");
65  PaletteComboBox->setItemText(Go4_Beach, "Beach");
66  PaletteComboBox->setItemText(Go4_BlackBody, "BlackBody");
67  PaletteComboBox->setItemText(Go4_BlueGreenYellow, "BlueGreenYellow");
68  PaletteComboBox->setItemText(Go4_BrownCyan, "BrownCyan");
69  PaletteComboBox->setItemText(Go4_CMYK, "CMYK");
70  PaletteComboBox->setItemText(Go4_Candy, "Candy");
71  PaletteComboBox->setItemText(Go4_Cherry, "Cherry");
72  PaletteComboBox->setItemText(Go4_Coffee, "Coffee");
73  PaletteComboBox->setItemText(Go4_DarkRainBow, "DarkRainBow");
74  PaletteComboBox->setItemText(Go4_DarkTerrain, "DarkTerrain");
75  PaletteComboBox->setItemText(Go4_Fall, "Fall");
76  PaletteComboBox->setItemText(Go4_FruitPunch, "FruitPunch");
77  PaletteComboBox->setItemText(Go4_Fuchsia, "Fuchsia");
78  PaletteComboBox->setItemText(Go4_GreyYellow, "GreyYellow");
79  PaletteComboBox->setItemText(Go4_GreenBrownTerrain, "GreenBrownTerrain");
80  PaletteComboBox->setItemText(Go4_GreenPink, "GreenPink");
81  PaletteComboBox->setItemText(Go4_Island, "Island");
82  PaletteComboBox->setItemText(Go4_Lake, "Lake");
83  PaletteComboBox->setItemText(Go4_LightTemperature, "LightTemperature");
84  PaletteComboBox->setItemText(Go4_LightTerrain, "LightTerrain");
85  PaletteComboBox->setItemText(Go4_Mint, "Mint");
86  PaletteComboBox->setItemText(Go4_Neon, "Neon");
87  PaletteComboBox->setItemText(Go4_Pastel, "Pastel");
88  PaletteComboBox->setItemText(Go4_Pearl, "Pearl");
89  PaletteComboBox->setItemText(Go4_Pigeon, "Pigeon");
90  PaletteComboBox->setItemText(Go4_Plum, "Plum");
91  PaletteComboBox->setItemText(Go4_RedBlue, "RedBlue");
92  PaletteComboBox->setItemText(Go4_Rose, "Rose");
93  PaletteComboBox->setItemText(Go4_Rust, "Rust");
94  PaletteComboBox->setItemText(Go4_SandyTerrain, "SandyTerrain");
95  PaletteComboBox->setItemText(Go4_Sienna, "Sienna");
96  PaletteComboBox->setItemText(Go4_Solar, "Solar");
97  PaletteComboBox->setItemText(Go4_SouthWest, "SouthWest");
98  PaletteComboBox->setItemText(Go4_StarryNight, "StarryNight");
99  PaletteComboBox->setItemText(Go4_Sunset, "Sunset");
100  PaletteComboBox->setItemText(Go4_TemperatureMap, "TemperatureMap");
101  PaletteComboBox->setItemText(Go4_Thermometer, "Thermometer");
102  PaletteComboBox->setItemText(Go4_Valentine, "Valentine");
103  PaletteComboBox->setItemText(Go4_VisibleSpectrum, "VisibleSpectrum");
104  PaletteComboBox->setItemText(Go4_WaterMelon, "WaterMelon");
105  PaletteComboBox->setItemText(Go4_Cool, "Cool");
106  PaletteComboBox->setItemText(Go4_Copper, "Copper");
107  PaletteComboBox->setItemText(Go4_GistEarth, "GistEarth");
108  PaletteComboBox->setItemText(Go4_Viridis, "Viridis");
109 
110  // here defaults from settings:
111  int min,max,def;
112  go4sett->getPaletteOpt(min,def,max);
113 
114  SetPaletteRange(min,def,max);
115 }
116 
117 void TGo4Style::SetPaletteRange(int min, int def, int max)
118 {
119  Palette->setMinimum(min);
120  Palette->setMaximum(max);
121  Palette->setValue(def);
122  def = Palette->value(); // spinbox automatic limiting of range
123  // gStyle->SetPalette(def,0,0);
124  gStyle->SetPalette(def);
125  SetPalette(def);
126  RefreshPaletteText(min, max);
127 }
128 
129 void TGo4Style::RefreshPaletteText(int min, int max)
130 {
131  // mark unavailable entries in palette selection box:
132  QString label;
133  const QString notavailable = "not avail:";
134  for (int pt = 0; pt <= GO4NAMEDPAL_MAX + 2 - GO4NAMEDPAL_MIN; ++pt) { // need two indices more for Go4_None and Go4_Default
135  int ix = DecodePalette((Go4_Palette_t)pt);
136  if (ix < 0)
137  continue;
138  label = PaletteComboBox->itemText(pt);
139  label.remove(notavailable); // clear any old markers
140  if ((ix < min) || (ix > max)) {
141  label.prepend(notavailable);
142  }
143  PaletteComboBox->setItemText(pt, label);
144  }
145 }
146 
148 {
149  QColor c = QColorDialog::getColor();
150  if (!c.isValid()) return;
151  Int_t color = TColor::GetColor(c.red(), c.green(), c.blue());
153  if (panel)
154  panel->ChangeDrawOption(101, color, nullptr);
155 }
156 
158 {
160  if (panel)
161  panel->ChangeDrawOption(100, t, nullptr);
162  if (!fbMenuLock) { // try to avoid feedback of qt signals between widget slots
163  fbMenuLock = true;
164  PaletteComboBox->setCurrentIndex(CodePalette(t));
165  fbMenuLock = false;
166  }
167 }
168 
170 {
171  int ix = DecodePalette((Go4_Palette_t)i);
172  if (ix < 0)
173  return;
174  // range check of current preferences here:
175  if (ix < Palette->minimum()) {
176  ix = Palette->minimum();
177  PaletteComboBox->setCurrentIndex(CodePalette(ix)); // show correct palette name here.
178  }
179  if (ix > Palette->maximum()) {
180  ix = Palette->maximum();
181  PaletteComboBox->setCurrentIndex(CodePalette(ix)); // show correct palette name here.
182  }
183  if (!fbMenuLock) // try to avoid feedback of qt signals between widget slots
184  {
185  fbMenuLock = true;
186  Palette->setValue(ix);
187  fbMenuLock = false;
188  }
189 }
190 
192 {
193  Go4_Palette_t rev;
194  if (i == 1)
195  rev = Go4_Default;
196  else if (i < GO4NAMEDPAL_MIN || i > GO4NAMEDPAL_MAX)
197  rev = Go4_None;
198  else
199  rev = (Go4_Palette_t)(i + 2 - GO4NAMEDPAL_MIN); // account Go4_None and Go4_Default offset
200  return rev;
201 }
202 
204 {
205  if (key == Go4_None) return -1;
206  if (key == Go4_Default) return 1; // old default rainbow index
207  return key - 2 + GO4NAMEDPAL_MIN; // account Go4_None and Go4_Default offset
208 }
209 
211 {
212  if (fbSettingPanelData) return;
213 
215  if (panel)
216  panel->ChangeDrawOption(18, nlvl, nullptr);
217 }
218 
219 void TGo4Style::panelSlot(TGo4ViewPanel *panel, TPad *pad, int signalid)
220 {
221  switch (signalid) {
224  break;
227  TGo4Picture *padopt = panel->GetPadOptions(pad);
228  if (!padopt) break;
229 
230  int nlvl = padopt->GetHisContour();
231 
232  fbSettingPanelData = true;
233 
234  ContourSpin->setValue(nlvl>0 ? nlvl : 20);
235 
236  fbSettingPanelData = false;
237 
238  break;
239  }
240  default:
241  break;
242  }
243 }
virtual void SetContourLevels(int nlvl)
Definition: TGo4Style.cpp:210
static TGo4MdiArea * Instance()
Definition: TGo4MdiArea.cpp:26
virtual void SetNamedPalette(int i)
Definition: TGo4Style.cpp:169
Go4_Palette_t CodePalette(int i)
Definition: TGo4Style.cpp:191
virtual void SetPalette(int t)
Definition: TGo4Style.cpp:157
bool fbMenuLock
Definition: TGo4Style.h:128
TGo4Style(QWidget *parent=nullptr, const char *name=nullptr, Qt::WindowFlags fl=Qt::Widget)
Definition: TGo4Style.cpp:27
virtual void panelSlot(TGo4ViewPanel *panel, TPad *pad, int signalid)
Definition: TGo4Style.cpp:219
virtual void SetPaletteRange(int min, int def, int max)
Definition: TGo4Style.cpp:117
#define GO4NAMEDPAL_MAX
Definition: TGo4Style.h:26
TGo4QSettings * go4sett
TGo4ViewPanel * GetActivePanel()
Definition: TGo4MdiArea.cpp:60
virtual void SetPadColor()
Definition: TGo4Style.cpp:147
virtual TGo4Picture * GetPadOptions(TPad *pad)
Go4_Palette_t
Definition: TGo4Style.h:28
Int_t GetHisContour() const
int DecodePalette(Go4_Palette_t key)
Definition: TGo4Style.cpp:203
void getPaletteOpt(int &min, int &def, int &max)
void RefreshPaletteText(int min, int max)
Definition: TGo4Style.cpp:129
virtual void ChangeDrawOption(int kind, int value, const char *drawopt)
#define GO4NAMEDPAL_MIN
Definition: TGo4Style.h:24
bool fbSettingPanelData
Definition: TGo4Style.h:129
void panelSignal(TGo4ViewPanel *, TPad *, int)