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
4#ifndef QCOLORWELL_P_H
5#define QCOLORWELL_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qrect.h>
19#include <QtWidgets/qwidget.h>
20
22
23QT_BEGIN_NAMESPACE
24
25class QWellArray : public QWidget
26{
27 Q_OBJECT
28 Q_PROPERTY(int selectedColumn READ selectedColumn)
29 Q_PROPERTY(int selectedRow READ selectedRow)
30
31public:
32 QWellArray(int rows, int cols, QWidget *parent = nullptr);
33 ~QWellArray() { }
34
35 int selectedColumn() const { return selCol; }
36 int selectedRow() const { return selRow; }
37
38 virtual void setCurrent(int row, int col);
39 virtual void setSelected(int row, int col);
40
41 QSize sizeHint() const override;
42
43 inline int cellWidth() const { return cellw; }
44
45 inline int cellHeight() const { return cellh; }
46
47 inline int rowAt(int y) const { return y / cellh; }
48
49 inline int columnAt(int x) const
50 {
51 if (isRightToLeft())
52 return ncols - (x / cellw) - 1;
53 return x / cellw;
54 }
55
56 inline int rowY(int row) const { return cellh * row; }
57
58 inline int columnX(int column) const
59 {
60 if (isRightToLeft())
61 return cellw * (ncols - column - 1);
62 return cellw * column;
63 }
64
65 inline int numRows() const { return nrows; }
66
67 inline int numCols() const { return ncols; }
68
69 inline QRect cellRect() const { return QRect(0, 0, cellw, cellh); }
70
71 inline QSize gridSize() const { return QSize(ncols * cellw, nrows * cellh); }
72
73 QRect cellGeometry(int row, int column)
74 {
75 QRect r;
76 if (row >= 0 && row < nrows && column >= 0 && column < ncols)
77 r.setRect(columnX(column), rowY(row), cellw, cellh);
78 return r;
79 }
80
81 inline void updateCell(int row, int column) { update(cellGeometry(row, column)); }
82
83signals:
84 void selected(int row, int col);
85 void currentChanged(int row, int col);
86 void colorChanged(int index, QRgb color);
87
88protected:
89 virtual void paintCell(QPainter *, int row, int col, const QRect &);
90 virtual void paintCellContents(QPainter *, int row, int col, const QRect &);
91
92 void mousePressEvent(QMouseEvent *) override;
93 void mouseReleaseEvent(QMouseEvent *) override;
94 void keyPressEvent(QKeyEvent *) override;
95 void focusInEvent(QFocusEvent *) override;
96 void focusOutEvent(QFocusEvent *) override;
97 void paintEvent(QPaintEvent *) override;
98
99private:
100 Q_DISABLE_COPY(QWellArray)
101
102 int nrows;
103 int ncols;
104 int cellw;
105 int cellh;
106 int curRow;
107 int curCol;
108 int selRow;
109 int selCol;
110};
111
112class QColorWell : public QWellArray
113{
114public:
115 QColorWell(QWidget *parent, int r, int c, const QRgb *vals)
116 : QWellArray(r, c, parent), values(vals), mousePressed(false), oldCurrent(-1, -1)
117 {
118 setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
119 }
120
121protected:
122 void paintCellContents(QPainter *, int row, int col, const QRect &) override;
123 void mousePressEvent(QMouseEvent *e) override;
124 void mouseMoveEvent(QMouseEvent *e) override;
125 void mouseReleaseEvent(QMouseEvent *e) override;
126#if QT_CONFIG(draganddrop)
131#endif
132
133private:
134 const QRgb *values;
135 bool mousePressed;
136 QPoint pressPos;
137 QPoint oldCurrent;
138};
139
140QT_END_NAMESPACE
141
142#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...
QColorWell(QWidget *parent, int r, int c, const QRgb *vals)
void paintCellContents(QPainter *, int row, int col, const QRect &) override
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)