Geant4  10.00.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 <TCanvas.h>
50 #include <TH1.h>
51 #include <TAxis.h>
52 #include <TList.h>
53 #include "CexmcHistoWidget.hh"
54 
55 
56 void CexmcHistoWidget::contextMenuEvent( QContextMenuEvent * event )
57 {
58  /* TRootContextMenu responsiveness is very ugly and unstable in Geant4
59  * environment, so we have to replace it with something more useful
60  * (e.g. unzooming histogram axes).
61  * We can switcn back to context menu as soon as ROOT will implement Qt
62  * backend for its context menu.
63  * TQtWidget utilizes QContextMenuEvent::Other reason to draw
64  * TRootContextMenu object. */
65  if ( event->reason() == QContextMenuEvent::Other )
66  {
67  TCanvas * canvas( Canvas() );
68  TObject * object( NULL );
69  TListIter curPrimitive( canvas->GetListOfPrimitives() );
70  while ( ( object = curPrimitive.Next() ) )
71  {
72  if ( ! object->InheritsFrom( "TH1" ) )
73  continue;
74  TH1 * histo( static_cast< TH1 * >( object ) );
75  TAxis * axis( histo->GetXaxis() );
76  if ( axis )
77  axis->UnZoom();
78  axis = histo->GetYaxis();
79  if ( axis )
80  axis->UnZoom();
81  axis = histo->GetZaxis();
82  if ( axis )
83  axis->UnZoom();
84  }
85  canvas->Update();
86  }
87 }
88 
89 #endif
90