GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4MdiArea.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 "TGo4MdiArea.h"
15 
16 #include "TROOT.h"
17 #include "TCanvas.h"
18 
19 #include <QMdiSubWindow>
20 
21 #include "TGo4ViewPanel.h"
22 #include "TGo4QSettings.h"
23 
25 
27 {
28  return gInstance;
29 }
30 
31 TGo4MdiArea::TGo4MdiArea(QWidget *parent) :
32  QMdiArea(parent)
33 {
34  setSizeIncrement( QSize( 100, 100 ) );
35  setBaseSize( QSize( 100, 100 ) );
36 
37  QObject::connect(this, &TGo4MdiArea::subWindowActivated, this, &TGo4MdiArea::subWindowActivatedSlot);
38 
39  if (!gInstance) gInstance = this;
40 }
41 
43 {
44  if (gInstance == this)
45  gInstance = nullptr;
46 }
47 
49 {
50  return fxSelectedPad;
51 }
52 
54 {
55  fxSelectedPad = pad;
56  gROOT->SetSelectedPad(pad);
57  gPad = pad;
58 }
59 
61 {
62  return fxActivePanel;
63 }
64 
65 QMdiSubWindow *TGo4MdiArea::AddGo4SubWindow(QWidget *widget, Qt::WindowFlags flags)
66 {
67  QMdiSubWindow *sub = addSubWindow(widget, flags);
68  // JAM make window behavior configurable in Go4 for all Qt versions.
70  sub->setOption(QMdiSubWindow::RubberBandResize);
71  sub->setOption(QMdiSubWindow::RubberBandMove); // JAM required for qt5 performance
72  }
73  return sub;
74 }
75 
76 void TGo4MdiArea::subWindowActivatedSlot(QMdiSubWindow* sub)
77 {
78  TGo4ViewPanel *panel = sub ? dynamic_cast<TGo4ViewPanel *>(sub->widget()) : nullptr;
79 
80  if (panel && (fxActivePanel != panel))
81  panel->SetActivePad(panel->GetActivePad());
82 }
83 
85 {
86  QList<QMdiSubWindow *> windows = subWindowList();
87  for (int i = 0; i < windows.count(); ++i) {
88  TGo4ViewPanel *panel = dynamic_cast<TGo4ViewPanel *>(windows.at(i)->widget());
89  if (panel && (panel != not_this)) return panel;
90  }
91 
92  return nullptr;
93 }
94 
95 void TGo4MdiArea::ResponseOnPanelEvent(int funcid, TGo4ViewPanel *panel, TPad *pad)
96 {
97  if (!panel)
98  return;
99 
100  switch (funcid) {
102  if ((fxActivePanel != panel) && fxActivePanel)
103  fxActivePanel->SetActivePad(nullptr);
104 
105  bool changed = (fxActivePanel != panel) || (fxActivePad != pad);
106  fxActivePanel = panel;
107  fxActivePad = pad;
108 
109  if (changed)
110  emit panelSignal(panel, pad, QGo4Widget::panel_Activated);
111 
112  break;
113  }
114 
116  emit panelSignal(panel, pad, QGo4Widget::panel_Modified);
117  break;
118  }
119 
121  emit panelSignal(panel, pad, QGo4Widget::panel_Updated);
122  if ((panel == fxActivePanel) && (pad == fxActivePad))
124  break;
125  }
126 
128  if (GetSelectedPad() == pad)
129  SetSelectedPad(nullptr);
130  if (fxActivePad == pad)
131  fxActivePad = nullptr;
132  emit panelSignal(panel, pad, QGo4Widget::panel_PadDeleted);
133  break;
134  }
135 
137  if (GetSelectedPad())
138  if (panel->IsPanelPad(GetSelectedPad()))
139  SetSelectedPad(nullptr);
140 
141  if (fxActivePanel == panel) {
142  fxActivePanel = nullptr;
143  fxActivePad = nullptr;
144  }
145 
146 #ifdef __GO4WEB__
147  // try to keep gPad - nullptr can have problem when running TWebCanvas
148  if (!gPad || panel->IsPanelPad((TPad *)gPad)) {
149  TGo4ViewPanel *other = FindOtherPanel(panel);
150 
151  SetSelectedPad(other ? other->GetCanvas() : nullptr);
152  }
153 #endif
154 
155  emit panelSignal(panel, pad, QGo4Widget::panel_Deleted);
156 
157  break;
158  }
159  }
160 }
161 
TPad * fxSelectedPad
Definition: TGo4MdiArea.h:58
QMdiSubWindow * AddGo4SubWindow(QWidget *widget, Qt::WindowFlags flags=Qt::Widget)
Definition: TGo4MdiArea.cpp:65
virtual void SetActivePad(TPad *pad)
TPad * GetSelectedPad()
Definition: TGo4MdiArea.cpp:48
TGo4ViewPanel * FindOtherPanel(TGo4ViewPanel *not_this)
Definition: TGo4MdiArea.cpp:84
static TGo4MdiArea * Instance()
Definition: TGo4MdiArea.cpp:26
TPad * fxActivePad
Definition: TGo4MdiArea.h:57
TGo4MdiArea(QWidget *parent=nullptr)
Definition: TGo4MdiArea.cpp:31
void ResponseOnPanelEvent(int funcid, TGo4ViewPanel *panel, TPad *pad)
Definition: TGo4MdiArea.cpp:95
TGo4QSettings * go4sett
TGo4ViewPanel * GetActivePanel()
Definition: TGo4MdiArea.cpp:60
void subWindowActivatedSlot(QMdiSubWindow *window)
Definition: TGo4MdiArea.cpp:76
static TGo4MdiArea * gInstance
Definition: TGo4MdiArea.h:60
virtual ~TGo4MdiArea()
Definition: TGo4MdiArea.cpp:42
virtual bool IsPanelPad(TPad *pad)
bool getMoveSubwindowRubberBand()
TGo4ViewPanel * fxActivePanel
Definition: TGo4MdiArea.h:56
virtual TPad * GetActivePad()
void SetSelectedPad(TPad *pad)
Definition: TGo4MdiArea.cpp:53
virtual TCanvas * GetCanvas()
void panelSignal(TGo4ViewPanel *, TPad *, int)