| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #ifndef CCHECKBOXHEADERVIEW
- #define CCHECKBOXHEADERVIEW
- #endif // CCHECKBOXHEADERVIEW
- #include <QtGui>
- #include <QHeaderView>
- #include <QStyleOptionButton>
- #include <QStyle>
- #include "SNCCore_global.h"
- class SNCCORESHARED_EXPORT XCheckBoxHeaderView : public QHeaderView
- {
- Q_OBJECT
- public:
- XCheckBoxHeaderView( int checkColumnIndex,
- Qt::Orientation orientation,
- QWidget * parent = 0) :
- QHeaderView(orientation, parent)
- {
- m_checkColIdx = checkColumnIndex;
- }
- signals:
- void selected();
- void unselected();
- protected:
- void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
- {
- painter->save();
- QHeaderView::paintSection(painter, rect, logicalIndex);
- painter->restore();
- if (logicalIndex == m_checkColIdx)
- {
- QStyleOptionButton option;
- int width = 10;
- for (int i=0; i<logicalIndex; ++i)
- width += sectionSize( i );
- option.rect = QRect(width, 5, 15, 15);
- if (isOn)
- option.state = QStyle::State_On;
- else
- option.state = QStyle::State_Off;
- // this->style()->drawPrimitive(QStyle::PE_IndicatorCheckBox, &option, painter);
- this->style()->drawControl(QStyle::CE_CheckBox, &option, painter);
- }
- }
- void mousePressEvent(QMouseEvent *event)
- {
- if (visualIndexAt(event->pos().x()) == m_checkColIdx)
- {
- // setSortIndicatorShown( false );
- if (isOn)
- {
- isOn = false;
- emit unselected();
- }
- else
- {
- isOn = true;
- emit selected();
- }
- this->updateSection(m_checkColIdx);
- }
- // else
- // setSortIndicatorShown( true );
- QHeaderView::mousePressEvent(event);
- }
- private:
- bool isOn;
- int m_checkColIdx;
- };
|