#include "CHeaderView.h" #include #include #include #include "pub_utility_api/FileUtil.h" CHeaderView::CHeaderView(QWidget *parent, int nAddCheckBoxColumn): QHeaderView(Qt::Horizontal, parent), m_bChecked(false) { m_indicatorCheck = iot_public::CFileUtil::getPathOfResFile("gui/icon/alarm/ckb-select.png").c_str(); m_indicatorUnCheck = iot_public::CFileUtil::getPathOfResFile("gui/icon/alarm/unchecked.png").c_str(); setSectionsClickable(true); connect(this, SIGNAL(sectionClicked(int)), this, SLOT(onHeaderClicked(int))); m_nAddCheckBoxColumn = nAddCheckBoxColumn; } QString CHeaderView::plotIndicatorCheck() { return m_indicatorCheck; } void CHeaderView::setPlotIndicatorCheck(const QString &url) { m_indicatorCheck = url; } QString CHeaderView::plotIndicatorUnCheck() { return m_indicatorUnCheck; } void CHeaderView::setPlotIndicatorUnCheck(const QString &url) { m_indicatorUnCheck = url; } void CHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const { painter->save(); QHeaderView::paintSection(painter,rect,logicalIndex); painter->restore(); if(logicalIndex == m_nAddCheckBoxColumn) { painter->save(); QStyleOptionButton button; button.state |= QStyle::State_Enabled; QRect rc(rect.left()+(rect.width()-20)/2,rect.top()+(rect.height()-20)/2,20,20); button.rect = rc; QString file; if(m_bChecked) { file = m_indicatorCheck; }else { file = m_indicatorUnCheck; } button.iconSize = QSize(button.rect.width()+2,button.rect.height()+2); button.icon = QIcon(file); button.features = QStyleOptionButton::Flat; QApplication::style()->drawControl(QStyle::CE_PushButton,&button,painter); painter->restore(); } } void CHeaderView::onHeaderClicked(int index) { if(index == m_nAddCheckBoxColumn) { m_bChecked = !m_bChecked; this->repaint(); emit sigColumnCheck(0, m_bChecked); } } void CHeaderView::clearCheck() { m_bChecked = false; emit sigColumnCheck(0, m_bChecked); }