CMS 3D CMS Logo

VisCSCPlotWidgetAxisX Class Reference

#include <VisReco/VisMuonCSC/interface/VisCSCPlotWidgetAxisX.h>

List of all members.

Public Member Functions

QSize minimumSizeHint () const
QSize sizeHint () const
 VisCSCPlotWidgetAxisX (const int nbins, QWidget *parent=0, const char *name=0)
 ~VisCSCPlotWidgetAxisX (void)

Protected Member Functions

void paintEvent (QPaintEvent *)

Private Attributes

int m_bins


Detailed Description

Definition at line 5 of file VisCSCPlotWidgetAxisX.h.


Constructor & Destructor Documentation

VisCSCPlotWidgetAxisX::VisCSCPlotWidgetAxisX ( const int  nbins,
QWidget *  parent = 0,
const char *  name = 0 
)

Definition at line 7 of file VisCSCPlotWidgetAxisX.cc.

References m_bins.

00007                                                                                               : QWidget(parent, name), 
00008 m_bins(nbins)
00009 {
00010         assert(m_bins>0);
00011 }

VisCSCPlotWidgetAxisX::~VisCSCPlotWidgetAxisX ( void   ) 

Definition at line 13 of file VisCSCPlotWidgetAxisX.cc.

00014 {
00015 }


Member Function Documentation

QSize VisCSCPlotWidgetAxisX::minimumSizeHint (  )  const

Definition at line 16 of file VisCSCPlotWidgetAxisX.cc.

00017 {
00018         // minimumSizeHint/sizeHint must be coordinated with y axis/VisCSCPlotWidget 
00019         return QSize( 80, 40 );
00020 }

void VisCSCPlotWidgetAxisX::paintEvent ( QPaintEvent *   )  [protected]

Definition at line 25 of file VisCSCPlotWidgetAxisX.cc.

References i, int, j, label, m_bins, scale, and width.

00026 {
00027         QPainter painter(this);
00028         painter.setPen(Qt::blue);
00029         QFont sansFont( "Helvetica", 9 );
00030         painter.setFont( sansFont );
00031         QFontMetrics fm( sansFont );
00032 
00033         // assume every five bins is a good choice: change to 16 for CSC
00034         const int bin_spacing = 16;
00035         QPointArray scale( 4 * int(floor(float(m_bins) / bin_spacing)) );
00036         int yoffset = 2;
00037         int tickHeight = 4;
00038 
00039         // don't forget that the last pixel is width()-1
00040         for (int i = bin_spacing, j = 0; i <= m_bins; i += bin_spacing )
00041         {
00042                 // labels go under center of bin before tick marks
00043                 QString label = QString("%1").arg(i);
00044                 int labelWidth = fm.width(label);
00045                 int xtext = int(floor( (i - 0.5F)*width()/m_bins - labelWidth/2.F + 0.5F) );
00046                 // check to see last label doesn't stick over the edge
00047                 if (xtext > width()-1 - fm.width(label))
00048                 {
00049                         xtext = width()-1 - fm.width(label);
00050                 }
00051                 painter.drawText( xtext, fm.height(), label );
00052                 // draw tick marks
00053                 scale.setPoint(j++, int(float(i - bin_spacing)*(width()-1)/m_bins + 0.5F), yoffset+tickHeight );
00054                 scale.setPoint(j++, int(float(i - bin_spacing)*(width()-1)/m_bins + 0.5F), yoffset );
00055                 scale.setPoint(j++, int(float(i              )*(width()-1)/m_bins + 0.5F), yoffset );
00056                 scale.setPoint(j++, int(float(i              )*(width()-1)/m_bins + 0.5F), yoffset+tickHeight );
00057         }       
00058         painter.drawPolyline(scale);
00059 }

QSize VisCSCPlotWidgetAxisX::sizeHint ( void   )  const

Definition at line 21 of file VisCSCPlotWidgetAxisX.cc.

00022 {
00023         return QSize( 400, 50 );
00024 }


Member Data Documentation

int VisCSCPlotWidgetAxisX::m_bins [private]

Definition at line 16 of file VisCSCPlotWidgetAxisX.h.

Referenced by paintEvent(), and VisCSCPlotWidgetAxisX().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:35:11 2009 for CMSSW by  doxygen 1.5.4