ATLAS Offline Software
VP1DockWidget.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // //
7 // Implementation of class VP1DockWidget //
8 // //
9 // Author: Thomas Kittelmann <Thomas.Kittelmann@cern.ch> //
10 // //
11 // Initial version: April 2007 //
12 // //
14 
15 #include "VP1Gui/VP1DockWidget.h"
16 #include "VP1Gui/VP1TabManager.h"
18 
19 #include <QFrame>
20 #include <QEvent>
21 #include <QSet>
22 #include <QVBoxLayout>
23 #include <QContextMenuEvent>
24 #include <QMenu>
25 
26 #include <cassert>
27 #include <iostream>
28 
29 //____________________________________________________________________
31 public:
32  class FilterItem;
34  Imp (const Imp&) = delete;
35  Imp& operator= (const Imp&) = delete;
38  QFrame * frame;
39  QVBoxLayout * vboxLayout;
43  bool selected;
46 };
47 
48 //____________________________________________________________________
49 class VP1DockWidget::Imp::FilterItem : public QObject {
50 public:
51  FilterItem(VP1DockWidget* dw) : QObject(dw),m_dw(dw) {}
53 
54  void init() {
56  m_activationevents.insert(QEvent::ContextMenu);
57  //m_activationevents.insert(QEvent::EnterEditFocus); --> Does not compile.
58  m_activationevents.insert(QEvent::FocusIn);
59  m_activationevents.insert(QEvent::KeyPress);
60  m_activationevents.insert(QEvent::MouseButtonDblClick);
61  m_activationevents.insert(QEvent::MouseButtonPress);
62  m_activationevents.insert(QEvent::TabletPress);
63  m_activationevents.insert(QEvent::Wheel);
64  }
65 
66 protected:
67  QSet<QEvent::Type> m_activationevents;
68 
69  bool eventFilter ( QObject * watched, QEvent * event ) {
70 
71  if (event->type()==QEvent::ChildAdded) {
72  //Maybe the user added a widget, so update the event filters (todo: test that it works):
73  for (QObject* c : watched->children()) {
76  }
77  return false;
78  }
79 
80  if ( !m_dw->m_d->selected && m_activationevents.contains(event->type()) ) {
81  m_dw->setSelected();
83  }
84  // if ( watched==m_dw && event->type() == QEvent::Enter )
85  // m_dw->channelWidget()->setFocus(Qt::OtherFocusReason);
86 
87  return false;
88  }
89 
90  void installEventFilterRecursively(QObject * child, const bool& remove=false ) {
91  //NB: we install it on all QObjects in the tree rather than just
92  //the QWidgets, since we need to watch for ChildAdded events.
93  if (child==this)
94  return;
95  if (!child){
96  std::cerr<<"installEventFilterRecursively: Child is NULL. Aborting."<<std::endl;
97  return;
98  }
99  if (remove)
100  child->removeEventFilter(this);
101  else
102  child->installEventFilter(this);
103  for (QObject* c : child->children())
105  }
106 };
107 
108 //____________________________________________________________________
110  : filteritem(new FilterItem(the_dw)), dw(the_dw), frame(0), vboxLayout(0),channelwidget(cw),
111  unselectedmargin(0),selected(false),tabmanager(the_tabmanager) {}
112 
113 //____________________________________________________________________
115 {
116  delete m_d->filteritem;
117  delete m_d; m_d=0;
118 }
119 
120 //______________________________________________________________________
122 {
123  return "background-color: rgba(0, 0, 255, 12%)";
124 }
125 
126 //______________________________________________________________________
128  : QDockWidget ( cw->unique_name(), 0 ), m_d(new Imp(this,cw,tm))
129 {
130 
131  setObjectName("VP1DockWidget:"+cw->name());//For storing/saving the layout of the dock widgets within the dock area.
132 
133  setFocusProxy(cw);
134 
135  setAllowedAreas(Qt::TopDockWidgetArea);
136  setFeatures(VP1DockWidget::DockWidgetMovable | VP1DockWidget::DockWidgetFloatable);
137 
138  m_d->selectedstylesheet="QFrame#VP1DockWidgetFrame { "+highlightStyle()+" } ";
139 
140  //Add frame, which will light up on selection:
141  m_d->frame = new QFrame(this);
142  m_d->frame->setObjectName("VP1DockWidgetFrame");
143  cw->setObjectName("IVP1ChannelWidget:"+cw->name());
144  ensureCWHasParent();//setup the cw in the frame
145 
146  //Figure out what margin our drawn frame imposes:
147  setSelected();
148  QMargins marg = m_d->frame->contentsMargins();
149  Q_ASSERT(marg.left()==marg.top()&&marg.left()==marg.right()&&marg.left()==marg.bottom()&&"Qt changed its margin behaviour for QFrame!!");
150  m_d->unselectedmargin=marg.left();
151 
152  //Channel starts unselected:
153  setUnselected();
154 
155  connect(cw,SIGNAL(uniqueNameChanged(QString)),this,SLOT(updateTitle()));
156  connect(cw,SIGNAL(systemRefreshInfoChanged(QString,int,int)),this,SLOT(systemRefreshInfoChanged(QString,int,int)));
157 
158  //Setup a watch for selections:
159  m_d->filteritem->init();
160 
161 }
162 
163 //______________________________________________________________________
165 {
166  if (!channelWidget()||!channelWidget()->parent())
167  return;
168  channelWidget()->setParent(0);
169  setWidget(0);
170  if (m_d->frame->layout()&&m_d->frame->layout()->indexOf(m_d->channelwidget)>=0) {
171  assert(m_d->vboxLayout);
172  m_d->vboxLayout->removeWidget(m_d->channelwidget);
173  }
174 }
175 
176 //______________________________________________________________________
178 {
179  if (!channelWidget()||channelWidget()->parent())
180  return;
181  if (!m_d->frame->layout()) {
182  assert(!m_d->vboxLayout);
183  m_d->vboxLayout = new QVBoxLayout(0);
184  m_d->frame->setLayout(m_d->vboxLayout);
185  m_d->vboxLayout->setObjectName("vp1dock-frame-layout");
186  m_d->vboxLayout->setSpacing(0);
187  }
188  if (m_d->frame->layout()->indexOf(m_d->channelwidget)<0)
189  m_d->frame->layout()->addWidget(m_d->channelwidget);
190  channelWidget()->setParent(m_d->frame);
191  setWidget(m_d->frame);
192 }
193 
194 //______________________________________________________________________
195 void VP1DockWidget::systemRefreshInfoChanged(QString sysrefreshing, int nsysOn, int nsysOnRefreshed)
196 {
197  assert(nsysOnRefreshed<=nsysOn);
198  if (nsysOn==nsysOnRefreshed) {
199  // assert(sysrefreshing.isEmpty());
200  m_d->title_refreshpart.clear();
201  updateTitle();
202  return;
203  }
204  assert(nsysOnRefreshed<nsysOn);
205  if (sysrefreshing.isEmpty()) {
206  m_d->title_refreshpart = " [Refreshed "+QString::number(nsysOnRefreshed)+"/"+QString::number(nsysOn)+"]";
207  } else {
208  m_d->title_refreshpart = " [Refreshing "+QString::number(nsysOnRefreshed+1)+"/"+QString::number(nsysOn)+": "+sysrefreshing+" ]";
209  }
210  updateTitle();
211 }
212 
213 //______________________________________________________________________
215 {
216  if (m_d->selected)
217  setWindowTitle(">>> "+m_d->channelwidget->unique_name()+m_d->title_refreshpart+" <<<");
218  else
219  setWindowTitle(m_d->channelwidget->unique_name()+m_d->title_refreshpart);
220 }
221 
222 //______________________________________________________________________
224 {
225  if (m_d->selected)
226  return;
227  m_d->selected=true;
228  m_d->frame->setStyleSheet(m_d->selectedstylesheet);
229  assert(m_d->vboxLayout);
230  m_d->vboxLayout->setMargin(0);
231  m_d->frame->setFrameShape(QFrame::StyledPanel);
232  updateTitle();
233 }
234 
235 //______________________________________________________________________
237 {
238  if (!m_d->selected)
239  return;
240  m_d->selected=false;
241  m_d->frame->setStyleSheet("");
242  assert(m_d->vboxLayout);
243  m_d->vboxLayout->setMargin(m_d->unselectedmargin);
244  m_d->frame->setFrameShape(QFrame::NoFrame);
245  updateTitle();
246 }
247 
248 //______________________________________________________________________
250 {
251  return m_d->channelwidget;
252 }
253 
254 //______________________________________________________________________
256 {
257  return m_d->selected;
258 }
259 
260 //______________________________________________________________________
261 void VP1DockWidget::contextMenuEvent ( QContextMenuEvent * event )
262 {
263  //Inside the frame, we use the normal behaviour:
264  if (m_d->frame->geometry().contains(event->pos())) {
265  QDockWidget::contextMenuEvent ( event );
266  return;
267  }
268  //Outside we show our contextmenu:
269 
270  //Construct menu:
271  QMenu menu(this);
272 // menu.addAction("Channel: "+m_d->channelwidget->unique_name())->setEnabled(false);
273 // menu.addSeparator();
274 
275  QAction* pFullScreenAction = menu.addAction("Show &full Screen");
276  menu.addSeparator();
277  QAction* pRemoveAction = menu.addAction("&Remove channel");
278  menu.addSeparator ();
279  QAction* pMoveChannelAction = menu.addAction("&Move to tab");
280 
281  QStringList tablist = m_d->tabmanager->tabList();
282  QMenu menu_movechan(this);
283  if (tablist.count()==1) {
284  menu_movechan.addAction("No other tabs available")->setEnabled(false);
285  } else {
286  QString thistab = m_d->tabmanager->channelToTab(m_d->channelwidget);
287  for (QString tab : tablist) {
288  if (tab!=thistab)
289  menu_movechan.addAction(tab)->setData("MOVECHAN");
290  }
291  }
292  pMoveChannelAction->setMenu(&menu_movechan);
293 
294  //Execute
295  QAction * selAct = menu.exec(event->globalPos());
296  //Act on selection:
297  if (!selAct)
298  return;
299  if (selAct==pFullScreenAction) {
301  return;
302  }
303  if (selAct==pRemoveAction) {
305  return;
306  }
307  if (selAct->data()=="MOVECHAN") {
309  return;
310  }
311  std::cout<<"ERROR in VP1DockWidget::contextMenuEvent!!!!!"<<std::endl;
312 
313 }
314 
315 //______________________________________________________________________
316 void VP1DockWidget::resizeEvent ( QResizeEvent * event )
317 {
319  QDockWidget::resizeEvent(event);
320 }
VP1DockWidget::VP1DockWidget
VP1DockWidget(IVP1ChannelWidget *cw, VP1TabManager *tm)
Definition: VP1DockWidget.cxx:127
VP1DockWidget::contextMenuEvent
void contextMenuEvent(QContextMenuEvent *event)
Definition: VP1DockWidget.cxx:261
VP1DockWidget::Imp::unselectedmargin
int unselectedmargin
Definition: VP1DockWidget.cxx:41
VP1DockWidget::highlightStyle
static QString highlightStyle()
Definition: VP1DockWidget.cxx:121
VP1DockWidget::Imp::selected
bool selected
Definition: VP1DockWidget.cxx:43
VP1DockWidget::Imp::FilterItem::FilterItem
FilterItem(VP1DockWidget *dw)
Definition: VP1DockWidget.cxx:51
VP1DockWidget::wasSelected
void wasSelected(VP1DockWidget *)
VP1DockWidget::m_d
Imp * m_d
Definition: VP1DockWidget.h:54
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
python.TriggerConfig.menu
menu
Definition: TriggerConfig.py:842
IVP1ChannelWidget::dockResized
virtual void dockResized()
Definition: IVP1ChannelWidget.cxx:315
VP1DockWidget::isSelected
bool isSelected() const
Definition: VP1DockWidget.cxx:255
VP1DockWidget::Imp::FilterItem
Definition: VP1DockWidget.cxx:49
IVP1ChannelWidget::unique_name
const QString unique_name() const
Definition: IVP1ChannelWidget.cxx:175
VP1DockWidget::Imp::FilterItem::installEventFilterRecursively
void installEventFilterRecursively(QObject *child, const bool &remove=false)
Definition: VP1DockWidget.cxx:90
PixelModuleFeMask_create_db.remove
string remove
Definition: PixelModuleFeMask_create_db.py:83
menu
make the sidebar many part of the config
Definition: hcg.cxx:551
VP1DockWidget::resizeEvent
void resizeEvent(QResizeEvent *event)
Definition: VP1DockWidget.cxx:316
VP1DockWidget
Definition: VP1DockWidget.h:24
VP1DockWidget::updateTitle
void updateTitle()
Definition: VP1DockWidget.cxx:214
VP1TabManager::tabList
QStringList tabList()
Definition: VP1TabManager.cxx:539
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
VP1DockWidget::Imp::FilterItem::eventFilter
bool eventFilter(QObject *watched, QEvent *event)
Definition: VP1DockWidget.cxx:69
VP1DockWidget.h
VP1DockWidget::Imp::Imp
Imp(const Imp &)=delete
VP1DockWidget::Imp::tabmanager
VP1TabManager * tabmanager
Definition: VP1DockWidget.cxx:45
test_pyathena.parent
parent
Definition: test_pyathena.py:15
VP1DockWidget::Imp::filteritem
FilterItem * filteritem
Definition: VP1DockWidget.cxx:36
VP1TabManager::removeChannelAfterQueueEmpties
void removeChannelAfterQueueEmpties(const QString &)
Definition: VP1TabManager.cxx:1509
IVP1ChannelWidget
Definition: IVP1ChannelWidget.h:34
VP1DockWidget::setSelected
void setSelected()
Definition: VP1DockWidget.cxx:223
VP1DockWidget::ensureCWHasNoParent
void ensureCWHasNoParent()
Definition: VP1DockWidget.cxx:164
VP1DockWidget::Imp::FilterItem::m_activationevents
QSet< QEvent::Type > m_activationevents
Definition: VP1DockWidget.cxx:67
VP1DockWidget::setUnselected
void setUnselected()
Definition: VP1DockWidget.cxx:236
VP1DockWidget::Imp::FilterItem::m_dw
VP1DockWidget * m_dw
Definition: VP1DockWidget.cxx:52
VP1DockWidget::Imp::operator=
Imp & operator=(const Imp &)=delete
python.selection.number
number
Definition: selection.py:20
VP1TabManager::showChannelFullScreen
void showChannelFullScreen(IVP1ChannelWidget *)
Definition: VP1TabManager.cxx:358
VP1DockWidget::Imp::dw
VP1DockWidget * dw
Definition: VP1DockWidget.cxx:37
VP1DockWidget::Imp::channelwidget
IVP1ChannelWidget * channelwidget
Definition: VP1DockWidget.cxx:40
VP1DockWidget::Imp
Definition: VP1DockWidget.cxx:30
VP1DockWidget::Imp::selectedstylesheet
QString selectedstylesheet
Definition: VP1DockWidget.cxx:42
VP1DockWidget::Imp::vboxLayout
QVBoxLayout * vboxLayout
Definition: VP1DockWidget.cxx:39
VP1DockWidget::Imp::title_refreshpart
QString title_refreshpart
Definition: VP1DockWidget.cxx:44
VP1DockWidget::channelWidget
IVP1ChannelWidget * channelWidget() const
Definition: VP1DockWidget.cxx:249
VP1DockWidget::Imp::frame
QFrame * frame
Definition: VP1DockWidget.cxx:38
VP1TabManager
Definition: VP1TabManager.h:30
IVP1ChannelWidget::name
const QString & name() const
Definition: IVP1ChannelWidget.cxx:180
VP1DockWidget::~VP1DockWidget
virtual ~VP1DockWidget()
Definition: VP1DockWidget.cxx:114
VP1DockWidget::Imp::FilterItem::init
void init()
Definition: VP1DockWidget.cxx:54
python.compressB64.c
def c
Definition: compressB64.py:93
VP1DockWidget::Imp::Imp
Imp(VP1DockWidget *_dw, IVP1ChannelWidget *cw, VP1TabManager *tabmanager)
Definition: VP1DockWidget.cxx:109
VP1DockWidget::systemRefreshInfoChanged
void systemRefreshInfoChanged(QString sysrefreshing, int nsysOn, int nsysOnRefreshed)
Definition: VP1DockWidget.cxx:195
VP1DockWidget::ensureCWHasParent
void ensureCWHasParent()
Definition: VP1DockWidget.cxx:177
VP1TabManager::moveChannelToTab
void moveChannelToTab(QString channeluniquename, QString tabname)
Definition: VP1TabManager.cxx:683
IVP1ChannelWidget.h
VP1TabManager::channelToTab
QString channelToTab(IVP1ChannelWidget *)
Definition: VP1TabManager.cxx:1406
VP1TabManager.h