Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcolorwell_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QCOLORWELL_P_H
6#define QCOLORWELL_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/qrect.h>
20#include <QtWidgets/qwidget.h>
21
23
24QT_BEGIN_NAMESPACE
25
26class QWellArray : public QWidget
27{
28 Q_OBJECT
29 Q_PROPERTY(int selectedColumn READ selectedColumn)
30 Q_PROPERTY(int selectedRow READ selectedRow)
31
32public:
33 QWellArray(int rows, int cols, QWidget *parent = nullptr);
34 ~QWellArray() { }
35
36 int currentColumn() const { return curCol; }
37 int currentRow() const { return curRow; }
38
39 int selectedColumn() const { return selCol; }
40 int selectedRow() const { return selRow; }
41
42 virtual void setCurrent(int row, int col);
43 virtual void setSelected(int row, int col);
44
45 QSize sizeHint() const override;
46
47 inline int cellWidth() const { return cellw; }
48
49 inline int cellHeight() const { return cellh; }
50
51 inline int rowAt(int y) const { return y / cellh; }
52
53 inline int columnAt(int x) const
54 {
55 if (isRightToLeft())
56 return ncols - (x / cellw) - 1;
57 return x / cellw;
58 }
59
60 inline int rowY(int row) const { return cellh * row; }
61
62 inline int columnX(int column) const
63 {
64 if (isRightToLeft())
65 return cellw * (ncols - column - 1);
66 return cellw * column;
67 }
68
69 inline int numRows() const { return nrows; }
70
71 inline int numCols() const { return ncols; }
72
73 inline int index(int row, int col) { return col * nrows + row; }
74
75 inline QRect cellRect() const { return QRect(0, 0, cellw, cellh); }
76
77 inline QSize gridSize() const { return QSize(ncols * cellw, nrows * cellh); }
78
79 QRect cellGeometry(int row, int column)
80 {
81 QRect r;
82 if (row >= 0 && row < nrows && column >= 0 && column < ncols)
83 r.setRect(columnX(column), rowY(row), cellw, cellh);
84 return r;
85 }
86
87 inline void updateCell(int row, int column) { update(cellGeometry(row, column)); }
88
89signals:
90 void selected(int row, int col);
91 void currentChanged(int row, int col);
92 void colorChanged(int index, QRgb color);
93
94protected:
95 virtual void paintCell(QPainter *, int row, int col, const QRect &);
96 virtual void paintCellContents(QPainter *, int row, int col, const QRect &);
97
98 void mousePressEvent(QMouseEvent *) override;
99 void mouseReleaseEvent(QMouseEvent *) override;
100 void keyPressEvent(QKeyEvent *) override;
101 void focusInEvent(QFocusEvent *) override;
102 void focusOutEvent(QFocusEvent *) override;
103 void paintEvent(QPaintEvent *) override;
104
105 void sendAccessibleChildFocusEvent();
106
107private:
108 Q_DISABLE_COPY(QWellArray)
109
110 int nrows;
111 int ncols;
112 int cellw;
113 int cellh;
114 int curRow;
115 int curCol;
116 int selRow;
117 int selCol;
118};
119
120class QColorWell : public QWellArray
121{
123public:
129
130 const QRgb *rgbValues() { return values; }
131
132protected:
133 void paintCellContents(QPainter *, int row, int col, const QRect &) override;
134 void mousePressEvent(QMouseEvent *e) override;
135 void mouseMoveEvent(QMouseEvent *e) override;
136 void mouseReleaseEvent(QMouseEvent *e) override;
137#if QT_CONFIG(draganddrop)
142#endif
143
144private:
145 const QRgb *values;
146 bool mousePressed;
147 QPoint pressPos;
148 QPoint oldCurrent;
149};
150
151QT_END_NAMESPACE
152
153#endif // QCOLORWELL_P_H
void mouseMoveEvent(QMouseEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
void mouseReleaseEvent(QMouseEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
void mousePressEvent(QMouseEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
QT_REQUIRE_CONFIG(colordialog)