2023-09-24 03:09:03 +00:00
|
|
|
#include "scrolltest.h"
|
|
|
|
|
|
|
|
scrolltest::scrolltest(QWidget *parent)
|
|
|
|
: QWidget{parent}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void scrolltest::paintEvent(QPaintEvent *)
|
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
widgetWindowHeight = this->height();
|
|
|
|
|
|
|
|
fontSize = 12;
|
|
|
|
|
|
|
|
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
2023-09-24 07:30:29 +00:00
|
|
|
//painter.setFont(QFont(this->fontInfo().family(), fontSize));
|
2023-09-24 03:09:03 +00:00
|
|
|
painter.setWindow(QRect(0, 0, this->width(), widgetWindowHeight));
|
|
|
|
|
2023-09-24 07:30:29 +00:00
|
|
|
//painter.setPen(Qt::red);
|
2023-09-24 03:09:03 +00:00
|
|
|
painter.drawText(0,widgetWindowHeight, resultText );
|
|
|
|
}
|
|
|
|
|
|
|
|
void scrolltest::wheelEvent(QWheelEvent *we)
|
|
|
|
{
|
2023-09-24 07:30:29 +00:00
|
|
|
int clicksX = abs(we->angleDelta().x());
|
|
|
|
int clicksY = abs(we->angleDelta().y());
|
2023-09-24 03:09:03 +00:00
|
|
|
|
2023-09-24 07:30:29 +00:00
|
|
|
if(clicksX > maxX)
|
2023-09-24 03:09:03 +00:00
|
|
|
maxX = clicksX;
|
|
|
|
|
2023-09-24 07:30:29 +00:00
|
|
|
if(clicksY > maxY)
|
2023-09-24 03:09:03 +00:00
|
|
|
maxY = clicksY;
|
|
|
|
|
2023-09-24 07:30:29 +00:00
|
|
|
if( (clicksX !=0) && (clicksX < minX))
|
|
|
|
minX = clicksX;
|
2023-09-24 03:09:03 +00:00
|
|
|
|
2023-09-24 07:30:29 +00:00
|
|
|
if( (clicksY !=0) && (clicksY < minY))
|
|
|
|
minY = clicksY;
|
2023-09-24 03:09:03 +00:00
|
|
|
|
|
|
|
resultText = QString("X: %1, Y: %2, maxX: %3, maxY: %4")
|
|
|
|
.arg(clicksX).arg(clicksY).arg(maxX).arg(maxY);
|
|
|
|
|
|
|
|
if(minX != 999999)
|
|
|
|
resultText.append(QString(", minX: %1").arg(minX));
|
|
|
|
|
|
|
|
if(minY != 999999)
|
|
|
|
resultText.append(QString(", minY: %1").arg(minY));
|
|
|
|
|
|
|
|
//QFontMetrics fm(this->font());
|
|
|
|
//int neededWidth = fm.horizontalAdvance(resultText);
|
|
|
|
//this->resize(this->height(), neededWidth);
|
|
|
|
|
|
|
|
emit haveRawClicksXY(clicksX, clicksY);
|
|
|
|
update();
|
|
|
|
}
|