CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/Fireworks/TableWidget/src/FWColumnLabelCellRenderer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     TableWidget
00004 // Class  :     FWColumnLabelCellRenderer
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Mon Feb  2 16:44:04 EST 2009
00011 // $Id: FWColumnLabelCellRenderer.cc,v 1.3 2012/02/22 00:15:44 amraktad Exp $
00012 //
00013 
00014 #include <cassert>
00015 
00016 // system include files
00017 #include "TVirtualX.h"
00018 #include "TGFont.h"
00019 
00020 // user include files
00021 #include "Fireworks/TableWidget/interface/FWColumnLabelCellRenderer.h"
00022 
00023 
00024 //
00025 // constants, enums and typedefs
00026 //
00027 
00028 //
00029 // static data member definitions
00030 //
00031 
00032 //
00033 // constructors and destructor
00034 //
00035 FWColumnLabelCellRenderer::FWColumnLabelCellRenderer(const TGGC* iContext, bool isSortable):
00036 FWTextTableCellRenderer(iContext), 
00037 m_sortOrder(fireworks::table::kNotSorted),
00038 m_sizeOfOrderIcon(height()),
00039 m_isSortable(isSortable)
00040 {
00041   if (m_isSortable)
00042   {
00043    FontMetrics_t metrics;
00044    font()->GetFontMetrics(&metrics);
00045 
00046    m_sizeOfOrderIcon -= 2*metrics.fDescent;
00047    m_sizeOfOrderIconStartX = metrics.fDescent;
00048    //we want the number to be even so that the point of the triangle 
00049    // will be right in the middle
00050    if(1 == m_sizeOfOrderIcon % 2) {
00051       ++m_sizeOfOrderIcon;
00052    }
00053   }
00054 }
00055 
00056 
00057 // FWColumnLabelCellRenderer::FWColumnLabelCellRenderer(const FWColumnLabelCellRenderer& rhs)
00058 // {
00059 //    // do actual copying here;
00060 // }
00061 
00062 FWColumnLabelCellRenderer::~FWColumnLabelCellRenderer()
00063 {
00064 }
00065 
00066 //
00067 // assignment operators
00068 //
00069 // const FWColumnLabelCellRenderer& FWColumnLabelCellRenderer::operator=(const FWColumnLabelCellRenderer& rhs)
00070 // {
00071 //   //An exception safe implementation is
00072 //   FWColumnLabelCellRenderer temp(rhs);
00073 //   swap(rhs);
00074 //
00075 //   return *this;
00076 // }
00077 
00078 //
00079 // member functions
00080 //
00081 void FWColumnLabelCellRenderer::setSortOrder(fireworks::table::SortOrder iOrder) {
00082   
00083   if (!m_isSortable) assert (iOrder ==  fireworks::table::kNotSorted);
00084   
00085   m_sortOrder = iOrder;
00086 }
00087 
00088 void 
00089 FWColumnLabelCellRenderer::draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight)
00090 {
00091   if (m_isSortable) 
00092   {
00093     using namespace fireworks::table;
00094     UInt_t h = m_sizeOfOrderIcon;
00095     const GContext_t c = graphicsContext()->GetGC();
00096     int dY = m_sizeOfOrderIconStartX;
00097     
00098     if(kAscendingSort == m_sortOrder) {
00099       gVirtualX->DrawLine(iID, c, iX+h/2, iY+2+dY,   iX,   iY+h-2+dY);
00100       gVirtualX->DrawLine(iID, c, iX,     iY+h-2+dY, iX+h, iY+h-2+dY);
00101       gVirtualX->DrawLine(iID, c, iX+h/2, iY+2+dY,   iX+h, iY+h-2+dY);
00102     }
00103     if(kDescendingSort == m_sortOrder){
00104       gVirtualX->DrawLine(iID, c, iX,     iY+2+dY,   iX+h, iY+2+dY);
00105       gVirtualX->DrawLine(iID, c, iX+h/2, iY+h-2+dY, iX+h, iY+2+dY);
00106       gVirtualX->DrawLine(iID, c, iX+h/2, iY+h-2+dY, iX,   iY+2+dY);      
00107     }
00108     FWTextTableCellRenderer::draw(iID,iX+kGap+h,iY,iWidth-kGap-h,iHeight);
00109   }
00110   else
00111   {
00112     return FWTextTableCellRenderer::draw(iID, iX+kGap, iY-kGap, iWidth, iHeight);
00113   }
00114 
00115 }
00116 
00117 //
00118 // const member functions
00119 //
00120 fireworks::table::SortOrder FWColumnLabelCellRenderer::sortOrder() const
00121 {
00122    return m_sortOrder;
00123 }
00124 
00125 UInt_t FWColumnLabelCellRenderer::width() const
00126 {
00127   if (m_isSortable)
00128    return FWTextTableCellRenderer::width()+kGap+m_sizeOfOrderIcon;
00129   else {
00130     return FWTextTableCellRenderer::width() + kGap*2;
00131   }
00132 
00133 }
00134 
00135 //
00136 // static member functions
00137 //