mirror of
https://github.com/YACReader/yacreader
synced 2026-03-02 19:00:04 -05:00
Use a QLabel to show the current/total text
This commit is contained in:
@ -51,6 +51,12 @@ YACReaderFlow3D::YACReaderFlow3D(QWidget *parent, struct Preset p)
|
||||
setSampleCount(4);
|
||||
|
||||
timerId = -1;
|
||||
|
||||
// Create and configure the index label
|
||||
indexLabel = new QLabel(this);
|
||||
indexLabel->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
indexLabel->setAutoFillBackground(false);
|
||||
updateIndexLabelStyle();
|
||||
}
|
||||
|
||||
YACReaderFlow3D::~YACReaderFlow3D()
|
||||
@ -369,6 +375,9 @@ void YACReaderFlow3D::render(QRhiCommandBuffer *cb)
|
||||
// Update positions and animations
|
||||
updatePositions();
|
||||
|
||||
// Update index label if values changed
|
||||
updateIndexLabel();
|
||||
|
||||
// Prepare view-projection matrix
|
||||
// Use fixed 20.0 degrees FOV - zoom is controlled via cfZ (camera distance)
|
||||
QMatrix4x4 projectionMatrix;
|
||||
@ -654,6 +663,12 @@ void YACReaderFlow3D::showEvent(QShowEvent *event)
|
||||
startAnimationTimer();
|
||||
}
|
||||
|
||||
void YACReaderFlow3D::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QRhiWidget::resizeEvent(event);
|
||||
updateIndexLabelStyle();
|
||||
}
|
||||
|
||||
void YACReaderFlow3D::cleanupAnimation()
|
||||
{
|
||||
config.animationStep = stepBackup;
|
||||
@ -1168,6 +1183,11 @@ void YACReaderFlow3D::setBackgroundColor(const QColor &color)
|
||||
void YACReaderFlow3D::setTextColor(const QColor &color)
|
||||
{
|
||||
textColor = color;
|
||||
|
||||
QPalette palette = indexLabel->palette();
|
||||
palette.setColor(QPalette::WindowText, textColor);
|
||||
indexLabel->setPalette(palette);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
@ -1299,6 +1319,39 @@ QVector3D YACReaderFlow3D::getPlaneIntersection(int x, int y, YACReader3DImageRH
|
||||
return ray_origin + ray_vector * (intersection_ray_determinant / intersection_LES_determinant);
|
||||
}
|
||||
|
||||
void YACReaderFlow3D::updateIndexLabel()
|
||||
{
|
||||
int currentDisplay = currentSelected + 1;
|
||||
int totalDisplay = numObjects;
|
||||
|
||||
if (indexLabelState.current != currentDisplay || indexLabelState.total != totalDisplay) {
|
||||
indexLabelState.current = currentDisplay;
|
||||
indexLabelState.total = totalDisplay;
|
||||
indexLabel->setText(QString("%1/%2").arg(currentDisplay).arg(totalDisplay));
|
||||
indexLabel->adjustSize();
|
||||
}
|
||||
}
|
||||
|
||||
void YACReaderFlow3D::updateIndexLabelStyle()
|
||||
{
|
||||
int w = width();
|
||||
int h = height();
|
||||
|
||||
int newFontSize = static_cast<int>((w + h) * 0.010);
|
||||
if (newFontSize < 10)
|
||||
newFontSize = 10;
|
||||
|
||||
QFont font("Arial", newFontSize);
|
||||
indexLabel->setFont(font);
|
||||
|
||||
QPalette palette = indexLabel->palette();
|
||||
palette.setColor(QPalette::WindowText, textColor);
|
||||
indexLabel->setPalette(palette);
|
||||
|
||||
indexLabel->move(10, 10);
|
||||
indexLabel->adjustSize();
|
||||
}
|
||||
|
||||
QSize YACReaderFlow3D::minimumSizeHint() const
|
||||
{
|
||||
return QSize(320, 200);
|
||||
|
||||
Reference in New Issue
Block a user