]> sigrok.org Git - pulseview.git/blame - pv/widgets/wellarray.hpp
Use bool literals for boolean values.
[pulseview.git] / pv / widgets / wellarray.hpp
CommitLineData
0c0e1888
JH
1/****************************************************************************
2**
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <QWidget>
43
ebad870b
JH
44namespace pv {
45namespace widgets {
0c0e1888 46
ebad870b
JH
47struct WellArrayData;
48
49class WellArray : public QWidget
0c0e1888
JH
50{
51 Q_OBJECT
52 Q_PROPERTY(int selectedColumn READ selectedColumn)
53 Q_PROPERTY(int selectedRow READ selectedRow)
54
55public:
f54fc97e 56 WellArray(int rows, int cols, QWidget* parent = nullptr);
0c0e1888
JH
57 QString cellContent(int row, int col) const;
58
59 int selectedColumn() const { return selCol; }
60 int selectedRow() const { return selRow; }
61
62 virtual void setCurrent(int row, int col);
63 virtual void setSelected(int row, int col);
64
65 QSize sizeHint() const;
66
67 virtual void setCellBrush(int row, int col, const QBrush &);
68 QBrush cellBrush(int row, int col);
69
70 inline int cellWidth() const
71 { return cellw; }
72
73 inline int cellHeight() const
74 { return cellh; }
75
76 inline int rowAt(int y) const
77 { return y / cellh; }
78
79 inline int columnAt(int x) const
80 { if (isRightToLeft()) return ncols - (x / cellw) - 1; return x / cellw; }
81
82 inline int rowY(int row) const
83 { return cellh * row; }
84
85 inline int columnX(int column) const
86 { if (isRightToLeft()) return cellw * (ncols - column - 1); return cellw * column; }
87
88 inline int numRows() const
89 { return nrows; }
90
91 inline int numCols() const
92 {return ncols; }
93
94 inline QRect cellRect() const
95 { return QRect(0, 0, cellw, cellh); }
96
97 inline QSize gridSize() const
98 { return QSize(ncols * cellw, nrows * cellh); }
99
100 QRect cellGeometry(int row, int column)
101 {
102 QRect r;
103 if (row >= 0 && row < nrows && column >= 0 && column < ncols)
104 r.setRect(columnX(column), rowY(row), cellw, cellh);
105 return r;
106 }
107
108 inline void updateCell(int row, int column) { update(cellGeometry(row, column)); }
109
e9213170 110Q_SIGNALS:
0c0e1888
JH
111 void selected(int row, int col);
112
113protected:
114 virtual void paintCell(QPainter *, int row, int col, const QRect&);
115 virtual void paintCellContents(QPainter *, int row, int col, const QRect&);
116
117 void mousePressEvent(QMouseEvent*);
118 void mouseReleaseEvent(QMouseEvent*);
119 void keyPressEvent(QKeyEvent*);
120 void focusInEvent(QFocusEvent*);
121 void focusOutEvent(QFocusEvent*);
d9ea9628 122 void paintEvent(QPaintEvent*);
0c0e1888
JH
123
124private:
ebad870b 125 Q_DISABLE_COPY(WellArray)
0c0e1888
JH
126
127 int nrows;
128 int ncols;
129 int cellw;
130 int cellh;
131 int curRow;
132 int curCol;
133 int selRow;
134 int selCol;
ebad870b 135 WellArrayData *d;
0c0e1888 136};
ebad870b
JH
137
138} // namespace wellarray
139} // namespace pv