wfview/scrolltest.cpp

57 wiersze
1.4 KiB
C++
Czysty Zwykły widok Historia

#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));
painter.setWindow(QRect(0, 0, this->width(), widgetWindowHeight));
2023-09-24 07:30:29 +00:00
//painter.setPen(Qt::red);
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 07:30:29 +00:00
if(clicksX > maxX)
maxX = clicksX;
2023-09-24 07:30:29 +00:00
if(clicksY > maxY)
maxY = clicksY;
2023-09-24 07:30:29 +00:00
if( (clicksX !=0) && (clicksX < minX))
minX = clicksX;
2023-09-24 07:30:29 +00:00
if( (clicksY !=0) && (clicksY < minY))
minY = clicksY;
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();
}