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