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