Skip to content

Commit

Permalink
tests: port touchGraphicsItem to Qt 6
Browse files Browse the repository at this point in the history
Replace deprecated APIs with recent ones:
* QTouchEvent::touchPoints() -> points()
* QEventPoint::pos() -> position()
* QPointingDevice::Capabilities and etc -> QInputDevice::Capability

Pick-to: 6.8 6.5 6.2
Change-Id: I45335886199a65e519cbd4872138e0715dd08103
Reviewed-by: Axel Spoerl <[email protected]>
  • Loading branch information
liangqi committed Sep 20, 2024
1 parent d9d4d15 commit 1b5c6d0
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions tests/manual/touchGraphicsItem/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ class TouchableItem : public QGraphicsRectItem
case QEvent::TouchEnd:
{
QTouchEvent *te = static_cast<QTouchEvent *>(e);
for (const QEventPoint &tp : te->touchPoints()) {
for (const QEventPoint &tp : te->points()) {
QGraphicsEllipseItem *diameterItem = nullptr;
QSizeF ellipse = tp.ellipseDiameters();
if (ellipse.isNull()) {
ellipse = QSizeF(5, 5);
} else {
diameterItem = new QGraphicsEllipseItem(QRectF(tp.pos().x() - ellipse.width() / 2, tp.pos().y() - ellipse.height() / 2,
diameterItem = new QGraphicsEllipseItem(QRectF(tp.position().x() - ellipse.width() / 2, tp.position().y() - ellipse.height() / 2,
ellipse.width(), ellipse.height()), this);
diameterItem->setPen(QPen(Qt::red));
diameterItem->setBrush(QBrush(Qt::red));
if (ellipse.width() > qreal(2) && ellipse.height() > qreal(2))
ellipse.scale(ellipse.width() - 2, ellipse.height() - 2, Qt::IgnoreAspectRatio);
}
QGraphicsItem *parent = diameterItem ? static_cast<QGraphicsItem *>(diameterItem) : static_cast<QGraphicsItem *>(this);
QGraphicsEllipseItem *ellipseItem = new QGraphicsEllipseItem(QRectF(tp.pos().x() - ellipse.width() / 2,
tp.pos().y() - ellipse.height() / 2,
QGraphicsEllipseItem *ellipseItem = new QGraphicsEllipseItem(QRectF(tp.position().x() - ellipse.width() / 2,
tp.position().y() - ellipse.height() / 2,
ellipse.width(), ellipse.height()), parent);
ellipseItem->setPen(QPen(Qt::blue));
ellipseItem->setBrush(QBrush(Qt::blue));
Expand All @@ -59,24 +59,25 @@ int main(int argc, char **argv)
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(new QLabel("The blue ellipses should indicate touch point contact patches"));
qDebug() << "Touch devices:";
for (const QPointingDevice *device : QPointingDevice::devices()) {
for (const QInputDevice *device : QInputDevice::devices()) {
const QPointingDevice *dev = qobject_cast<const QPointingDevice *>(device);
QString result;
QTextStream str(&result);
str << (device->type() == QInputDevice::DeviceType::TouchScreen ? "TouchScreen" : "TouchPad")
<< " \"" << device->name() << "\", max " << device->maximumTouchPoints()
<< " \"" << device->name() << "\", max " << (dev ? dev->maximumPoints() : 0)
<< " touch points, capabilities:";
const QPointingDevice::Capabilities capabilities = device->capabilities();
if (capabilities & QPointingDevice::Capability::Position)
const QInputDevice::Capabilities capabilities = device->capabilities();
if (capabilities & QInputDevice::Capability::Position)
str << " Position";
if (capabilities & QPointingDevice::Capability::Area)
if (capabilities & QInputDevice::Capability::Area)
str << " Area";
if (capabilities & QPointingDevice::Capability::Pressure)
if (capabilities & QInputDevice::Capability::Pressure)
str << " Pressure";
if (capabilities & QPointingDevice::Velocity)
if (capabilities & QInputDevice::Capability::Velocity)
str << " Velocity";
if (capabilities & QPointingDevice::Capability::NormalizedPosition)
if (capabilities & QInputDevice::Capability::NormalizedPosition)
str << " NormalizedPosition";
if (capabilities & QInputDevice::DeviceType::MouseEmulation)
if (capabilities & QInputDevice::Capability::MouseEmulation)
str << " MouseEmulation";
vbox->addWidget(new QLabel(result));
qDebug() << " " << result;
Expand Down

0 comments on commit 1b5c6d0

Please sign in to comment.