PulseView  unreleased development snapshot
A Qt-based sigrok GUI
wellarray.hpp
Go to the documentation of this file.
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 #ifndef PULSEVIEW_PV_WIDGETS_WELLARRAY_HPP
43 #define PULSEVIEW_PV_WIDGETS_WELLARRAY_HPP
44 
45 #include <QWidget>
46 
47 namespace pv {
48 namespace widgets {
49 
50 struct WellArrayData;
51 
52 class WellArray : public QWidget
53 {
54  Q_OBJECT
55  Q_PROPERTY(int selectedColumn READ selectedColumn) // clazy:exclude=qproperty-without-notify
56  Q_PROPERTY(int selectedRow READ selectedRow) // clazy:exclude=qproperty-without-notify
57 
58 public:
59  WellArray(int rows, int cols, QWidget* parent = nullptr);
60  QString cellContent(int row, int col) const;
61 
62  int selectedColumn() const { return selCol; }
63  int selectedRow() const { return selRow; }
64 
65  virtual void setCurrent(int row, int col);
66  virtual void setSelected(int row, int col);
67 
68  QSize sizeHint() const;
69 
70  virtual void setCellBrush(int row, int col, const QBrush &);
71  QBrush cellBrush(int row, int col);
72 
73  inline int cellWidth() const
74  { return cellw; }
75 
76  inline int cellHeight() const
77  { return cellh; }
78 
79  inline int rowAt(int y) const
80  { return y / cellh; }
81 
82  inline int columnAt(int x) const
83  { if (isRightToLeft()) return ncols - (x / cellw) - 1; return x / cellw; }
84 
85  inline int rowY(int row) const
86  { return cellh * row; }
87 
88  inline int columnX(int column) const
89  { if (isRightToLeft()) return cellw * (ncols - column - 1); return cellw * column; }
90 
91  inline int numRows() const
92  { return nrows; }
93 
94  inline int numCols() const
95  {return ncols; }
96 
97  inline QRect cellRect() const
98  { return QRect(0, 0, cellw, cellh); }
99 
100  inline QSize gridSize() const
101  { return QSize(ncols * cellw, nrows * cellh); }
102 
103  QRect cellGeometry(int row, int column)
104  {
105  QRect r;
106  if (row >= 0 && row < nrows && column >= 0 && column < ncols)
107  r.setRect(columnX(column), rowY(row), cellw, cellh);
108  return r;
109  }
110 
111  inline void updateCell(int row, int column) { update(cellGeometry(row, column)); }
112 
113 Q_SIGNALS:
114  void selected(int row, int col);
115 
116 protected:
117  virtual void paintCell(QPainter *, int row, int col, const QRect&);
118  virtual void paintCellContents(QPainter *, int row, int col, const QRect&);
119 
120  void mousePressEvent(QMouseEvent*);
121  void mouseReleaseEvent(QMouseEvent*);
122  void keyPressEvent(QKeyEvent*);
123  void focusInEvent(QFocusEvent*);
124  void focusOutEvent(QFocusEvent*);
125  void paintEvent(QPaintEvent*);
126 
127 private:
128  Q_DISABLE_COPY(WellArray)
129 
130  int nrows;
131  int ncols;
132  int cellw;
133  int cellh;
134  int curRow;
135  int curCol;
136  int selRow;
137  int selCol;
139 };
140 
141 } // namespace widgets
142 } // namespace pv
143 
144 #endif // PULSEVIEW_PV_WIDGETS_WELLARRAY_HPP
WellArrayData * d
Definition: wellarray.hpp:138
void keyPressEvent(QKeyEvent *)
Definition: wellarray.cpp:265
virtual void setSelected(int row, int col)
Definition: wellarray.cpp:209
virtual void paintCellContents(QPainter *, int row, int col, const QRect &)
Definition: wellarray.cpp:154
int selectedRow() const
Definition: wellarray.hpp:63
void paintEvent(QPaintEvent *)
Definition: wellarray.cpp:52
QRect cellRect() const
Definition: wellarray.hpp:97
void focusOutEvent(QFocusEvent *)
Definition: wellarray.cpp:258
int numCols() const
Definition: wellarray.hpp:94
int columnAt(int x) const
Definition: wellarray.hpp:82
QBrush cellBrush(int row, int col)
Definition: wellarray.cpp:247
int rowAt(int y) const
Definition: wellarray.hpp:79
void focusInEvent(QFocusEvent *)
Definition: wellarray.cpp:226
virtual void paintCell(QPainter *, int row, int col, const QRect &)
Definition: wellarray.cpp:124
int cellHeight() const
Definition: wellarray.hpp:76
int rowY(int row) const
Definition: wellarray.hpp:85
QSize gridSize() const
Definition: wellarray.hpp:100
void selected(int row, int col)
QString cellContent(int row, int col) const
virtual void setCellBrush(int row, int col, const QBrush &)
Definition: wellarray.cpp:231
QRect cellGeometry(int row, int column)
Definition: wellarray.hpp:103
void mouseReleaseEvent(QMouseEvent *)
Definition: wellarray.cpp:173
int numRows() const
Definition: wellarray.hpp:91
void mousePressEvent(QMouseEvent *)
Definition: wellarray.cpp:166
QSize sizeHint() const
Definition: wellarray.cpp:117
int cellWidth() const
Definition: wellarray.hpp:73
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t x(y+z)
int columnX(int column) const
Definition: wellarray.hpp:88
int selectedColumn() const
Definition: wellarray.hpp:62
virtual void setCurrent(int row, int col)
Definition: wellarray.cpp:185
void updateCell(int row, int column)
Definition: wellarray.hpp:111