Geant4  10.02.p01
CexmcHistoWidget.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 /*
27  * =============================================================================
28  *
29  * Filename: CexmcHistoWidget.cc
30  *
31  * Description: histogram widget without context menu
32  * (derived from TQtWidget)
33  *
34  * Version: 1.0
35  * Created: 15.03.2010 19:01:52
36  * Revision: none
37  * Compiler: gcc
38  *
39  * Author: Alexey Radkov (),
40  * Company: PNPI
41  *
42  * =============================================================================
43  */
44 
45 #ifdef CEXMC_USE_ROOTQT
46 
47 #include <QContextMenuEvent>
48 #include <TObject.h>
49 #include <TH1.h>
50 #include <TAxis.h>
51 #include <TList.h>
52 #include "CexmcHistoWidget.hh"
53 
54 
55 CexmcHistoWidget::CexmcHistoWidget()
56 {
57  /* this is a workaround of the repaint bug in the ROOT Qt backend:
58  * see http://root.cern.ch/phpBB3/viewtopic.php?f=3&t=17081#p73055 */
59  fCanvas->SetFillColor( 10 );
60 }
61 
62 
63 void CexmcHistoWidget::contextMenuEvent( QContextMenuEvent * event )
64 {
65  /* TRootContextMenu responsiveness is very ugly and unstable in Geant4
66  * environment, so we have to replace it with something more useful
67  * (e.g. unzooming histogram axes).
68  * We can switcn back to context menu as soon as ROOT will implement Qt
69  * backend for its context menu.
70  * TQtWidget utilizes QContextMenuEvent::Other reason to draw
71  * TRootContextMenu object. */
72  if ( event->reason() == QContextMenuEvent::Other )
73  {
74  TObject * object( NULL );
75  TListIter curPrimitive( fCanvas->GetListOfPrimitives() );
76  while ( ( object = curPrimitive.Next() ) )
77  {
78  if ( ! object->InheritsFrom( TH1::Class() ) )
79  continue;
80  TH1 * histo( static_cast< TH1 * >( object ) );
81  TAxis * axis( histo->GetXaxis() );
82  if ( axis )
83  axis->UnZoom();
84  axis = histo->GetYaxis();
85  if ( axis )
86  axis->UnZoom();
87  axis = histo->GetZaxis();
88  if ( axis )
89  axis->UnZoom();
90  }
91  fCanvas->Update();
92  }
93 }
94 
95 #endif
96