]>
Commit | Line | Data |
---|---|---|
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 | ||
44 | struct QWellArrayData; | |
45 | ||
46 | class QWellArray : public QWidget | |
47 | { | |
48 | Q_OBJECT | |
49 | Q_PROPERTY(int selectedColumn READ selectedColumn) | |
50 | Q_PROPERTY(int selectedRow READ selectedRow) | |
51 | ||
52 | public: | |
53 | QWellArray(int rows, int cols, QWidget* parent=0); | |
0c0e1888 JH |
54 | QString cellContent(int row, int col) const; |
55 | ||
56 | int selectedColumn() const { return selCol; } | |
57 | int selectedRow() const { return selRow; } | |
58 | ||
59 | virtual void setCurrent(int row, int col); | |
60 | virtual void setSelected(int row, int col); | |
61 | ||
62 | QSize sizeHint() const; | |
63 | ||
64 | virtual void setCellBrush(int row, int col, const QBrush &); | |
65 | QBrush cellBrush(int row, int col); | |
66 | ||
67 | inline int cellWidth() const | |
68 | { return cellw; } | |
69 | ||
70 | inline int cellHeight() const | |
71 | { return cellh; } | |
72 | ||
73 | inline int rowAt(int y) const | |
74 | { return y / cellh; } | |
75 | ||
76 | inline int columnAt(int x) const | |
77 | { if (isRightToLeft()) return ncols - (x / cellw) - 1; return x / cellw; } | |
78 | ||
79 | inline int rowY(int row) const | |
80 | { return cellh * row; } | |
81 | ||
82 | inline int columnX(int column) const | |
83 | { if (isRightToLeft()) return cellw * (ncols - column - 1); return cellw * column; } | |
84 | ||
85 | inline int numRows() const | |
86 | { return nrows; } | |
87 | ||
88 | inline int numCols() const | |
89 | {return ncols; } | |
90 | ||
91 | inline QRect cellRect() const | |
92 | { return QRect(0, 0, cellw, cellh); } | |
93 | ||
94 | inline QSize gridSize() const | |
95 | { return QSize(ncols * cellw, nrows * cellh); } | |
96 | ||
97 | QRect cellGeometry(int row, int column) | |
98 | { | |
99 | QRect r; | |
100 | if (row >= 0 && row < nrows && column >= 0 && column < ncols) | |
101 | r.setRect(columnX(column), rowY(row), cellw, cellh); | |
102 | return r; | |
103 | } | |
104 | ||
105 | inline void updateCell(int row, int column) { update(cellGeometry(row, column)); } | |
106 | ||
107 | signals: | |
108 | void selected(int row, int col); | |
109 | ||
110 | protected: | |
111 | virtual void paintCell(QPainter *, int row, int col, const QRect&); | |
112 | virtual void paintCellContents(QPainter *, int row, int col, const QRect&); | |
113 | ||
114 | void mousePressEvent(QMouseEvent*); | |
115 | void mouseReleaseEvent(QMouseEvent*); | |
116 | void keyPressEvent(QKeyEvent*); | |
117 | void focusInEvent(QFocusEvent*); | |
118 | void focusOutEvent(QFocusEvent*); | |
119 | void paintEvent(QPaintEvent *); | |
120 | ||
121 | private: | |
122 | Q_DISABLE_COPY(QWellArray) | |
123 | ||
124 | int nrows; | |
125 | int ncols; | |
126 | int cellw; | |
127 | int cellh; | |
128 | int curRow; | |
129 | int curCol; | |
130 | int selRow; | |
131 | int selCol; | |
132 | QWellArrayData *d; | |
133 | }; |