Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:32

0001 // -*- C++ -*-
0002 //
0003 // Package:     TableWidget
0004 // Class  :     FWColumnLabelCellRenderer
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Mon Feb  2 16:44:04 EST 2009
0011 //
0012 
0013 #include <cassert>
0014 
0015 // system include files
0016 #include "TVirtualX.h"
0017 #include "TGFont.h"
0018 
0019 // user include files
0020 #include "Fireworks/TableWidget/interface/FWColumnLabelCellRenderer.h"
0021 
0022 //
0023 // constants, enums and typedefs
0024 //
0025 
0026 //
0027 // static data member definitions
0028 //
0029 
0030 //
0031 // constructors and destructor
0032 //
0033 FWColumnLabelCellRenderer::FWColumnLabelCellRenderer(const TGGC* iContext, bool isSortable)
0034     : FWTextTableCellRenderer(iContext),
0035       m_sortOrder(fireworks::table::kNotSorted),
0036       m_sizeOfOrderIcon(height()),
0037       m_isSortable(isSortable) {
0038   if (m_isSortable) {
0039     FontMetrics_t metrics;
0040     font()->GetFontMetrics(&metrics);
0041 
0042     m_sizeOfOrderIcon -= 2 * metrics.fDescent;
0043     m_sizeOfOrderIconStartX = metrics.fDescent;
0044     //we want the number to be even so that the point of the triangle
0045     // will be right in the middle
0046     if (1 == m_sizeOfOrderIcon % 2) {
0047       ++m_sizeOfOrderIcon;
0048     }
0049   }
0050 }
0051 
0052 // FWColumnLabelCellRenderer::FWColumnLabelCellRenderer(const FWColumnLabelCellRenderer& rhs)
0053 // {
0054 //    // do actual copying here;
0055 // }
0056 
0057 FWColumnLabelCellRenderer::~FWColumnLabelCellRenderer() {}
0058 
0059 //
0060 // assignment operators
0061 //
0062 // const FWColumnLabelCellRenderer& FWColumnLabelCellRenderer::operator=(const FWColumnLabelCellRenderer& rhs)
0063 // {
0064 //   //An exception safe implementation is
0065 //   FWColumnLabelCellRenderer temp(rhs);
0066 //   swap(rhs);
0067 //
0068 //   return *this;
0069 // }
0070 
0071 //
0072 // member functions
0073 //
0074 void FWColumnLabelCellRenderer::setSortOrder(fireworks::table::SortOrder iOrder) {
0075   if (!m_isSortable)
0076     assert(iOrder == fireworks::table::kNotSorted);
0077 
0078   m_sortOrder = iOrder;
0079 }
0080 
0081 void FWColumnLabelCellRenderer::draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight) {
0082   if (m_isSortable) {
0083     using namespace fireworks::table;
0084     UInt_t h = m_sizeOfOrderIcon;
0085     const GContext_t c = graphicsContext()->GetGC();
0086     int dY = m_sizeOfOrderIconStartX;
0087 
0088     if (kAscendingSort == m_sortOrder) {
0089       gVirtualX->DrawLine(iID, c, iX + h / 2, iY + 2 + dY, iX, iY + h - 2 + dY);
0090       gVirtualX->DrawLine(iID, c, iX, iY + h - 2 + dY, iX + h, iY + h - 2 + dY);
0091       gVirtualX->DrawLine(iID, c, iX + h / 2, iY + 2 + dY, iX + h, iY + h - 2 + dY);
0092     }
0093     if (kDescendingSort == m_sortOrder) {
0094       gVirtualX->DrawLine(iID, c, iX, iY + 2 + dY, iX + h, iY + 2 + dY);
0095       gVirtualX->DrawLine(iID, c, iX + h / 2, iY + h - 2 + dY, iX + h, iY + 2 + dY);
0096       gVirtualX->DrawLine(iID, c, iX + h / 2, iY + h - 2 + dY, iX, iY + 2 + dY);
0097     }
0098     FWTextTableCellRenderer::draw(iID, iX + kGap + h, iY, iWidth - kGap - h, iHeight);
0099   } else {
0100     return FWTextTableCellRenderer::draw(iID, iX + kGap, iY - kGap, iWidth, iHeight);
0101   }
0102 }
0103 
0104 //
0105 // const member functions
0106 //
0107 fireworks::table::SortOrder FWColumnLabelCellRenderer::sortOrder() const { return m_sortOrder; }
0108 
0109 UInt_t FWColumnLabelCellRenderer::width() const {
0110   if (m_isSortable)
0111     return FWTextTableCellRenderer::width() + kGap + m_sizeOfOrderIcon;
0112   else {
0113     return FWTextTableCellRenderer::width() + kGap * 2;
0114   }
0115 }
0116 
0117 //
0118 // static member functions
0119 //