Use a QLabel to show the current/total text

This commit is contained in:
luisangelsm
2026-01-18 12:58:15 +01:00
parent c4c59ab96a
commit 6053fca005
2 changed files with 69 additions and 0 deletions

View File

@ -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);

View File

@ -79,6 +79,7 @@ extern struct Preset presetYACReaderFlowOverlappedStripeConfig;
extern struct Preset pressetYACReaderFlowUpConfig;
extern struct Preset pressetYACReaderFlowDownConfig;
class QLabel;
class ImageLoader3D;
class ImageLoaderByteArray3D;
class YACReaderComicFlow3D;
@ -103,6 +104,12 @@ protected:
int updateCount;
int fontSize;
// Cached state for the index label to avoid unnecessary updates
struct IndexLabelState {
int current = -1;
int total = -1;
};
// Uniform buffer data structure (must match shader layout)
struct UniformData {
QMatrix4x4 viewProjectionMatrix;
@ -174,6 +181,10 @@ protected:
Scene scene;
QVector<PendingTextureUpload> pendingTextureUploads;
// Index label (shows "current/total" in top-left corner)
QLabel *indexLabel = nullptr;
IndexLabelState indexLabelState;
void timerEvent(QTimerEvent *) override;
int numObjects;
@ -222,6 +233,11 @@ protected:
void render(QRhiCommandBuffer *cb) override;
void releaseResources() override;
void showEvent(QShowEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
// Index label helpers
void updateIndexLabel();
void updateIndexLabelStyle();
// Helper methods
QRhiTexture *createTextureFromImage(QRhiCommandBuffer *cb, const QImage &image);