Mantid
Loading...
Searching...
No Matches
CheckboxHeader.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8
9namespace MantidQt {
10namespace MantidWidgets {
11
17CheckboxHeader::CheckboxHeader(Qt::Orientation orientation, QWidget *parent)
18 : QHeaderView(orientation, parent), m_checked(false) {
19 show();
20 setSectionsClickable(true);
21}
22
27void CheckboxHeader::setChecked(bool checked) {
28 if (isEnabled() && m_checked != checked) {
29 m_checked = checked;
30 updateSection(0);
31 emit toggled(m_checked);
32 }
33}
34
41void CheckboxHeader::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const {
42 painter->save();
43 QHeaderView::paintSection(painter, rect, logicalIndex);
44 painter->restore();
45
46 if (logicalIndex == 0) {
47 // We have to clear the data otherwise the default "1" appears.
48 model()->setHeaderData(0, Qt::Horizontal, tr(""));
49
50 QStyleOptionButton option;
51
52 if (isEnabled()) {
53 option.state |= QStyle::State_Enabled;
54 }
55
56 option.rect = checkBoxRect(rect);
57 option.state |= m_checked ? QStyle::State_On : QStyle::State_Off;
58
59 style()->drawControl(QStyle::CE_CheckBox, &option, painter);
60 }
61}
62
67void CheckboxHeader::mousePressEvent(QMouseEvent *event) {
68 if (isEnabled() && logicalIndexAt(event->pos()) == 0) {
70 updateSection(0);
71 emit toggled(m_checked);
72 } else {
73 QHeaderView::mousePressEvent(event);
74 }
75}
76
77QRect CheckboxHeader::checkBoxRect(const QRect &sourceRect) const {
78 QStyleOptionButton checkBoxStyleOption;
79
80 QRect checkBoxRect = style()->subElementRect(QStyle::SE_CheckBoxIndicator, &checkBoxStyleOption);
81
82 QPoint checkBoxPoint(sourceRect.x() + 3, sourceRect.y() + sourceRect.height() / 2 - checkBoxRect.height() / 2);
83
84 return QRect(checkBoxPoint, checkBoxRect.size());
85}
86
87} // namespace MantidWidgets
88} // namespace MantidQt
CheckboxHeader(Qt::Orientation orientation, QWidget *parent=nullptr)
Override QHeaderView constructor.
void mousePressEvent(QMouseEvent *event) override
Set the checkbox to checked when it is clicked.
void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const override
Overrides QHeaderView allowing checkbox functionality in the first column of the table.
QRect checkBoxRect(const QRect &sourceRect) const
The area around the checkbox.
void setChecked(bool checked)
Has the user checked the checkbox in the header?
bool m_checked
The state of the checkbox in the column header.
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
MANTID_GEOMETRY_DLL PolygonEdge::Orientation orientation(const PolygonEdge &focusEdge, const PolygonEdge &refEdge, double &t)
Calculate the orientation type of one edge wrt to another.
Definition: PolygonEdge.cpp:81