More fixes

This commit is contained in:
Nicolas Mailloux 2023-06-12 21:18:42 -04:00
parent 73ff36502e
commit ddf9be2edd
2 changed files with 12 additions and 11 deletions

View file

@ -17,7 +17,7 @@ egg::egg(QWidget *parent) :
ui->contributorName->setFont(QFont("Inter"));
graphicsScene = new QGraphicsScene(this);
changeIndex(index);
QTimer::singleShot(500, this, SLOT(changeIndexSlot()));
}
egg::~egg()
@ -35,20 +35,16 @@ void egg::changeIndex(int index) {
tux-linux (3)
*/
if(firstRun == true) {
firstRun = false;
}
else {
graphicsScene->clear();
ui->graphicsView->items().clear();
}
graphicsScene->clear();
QPixmap pixmap(":/resources/egg/" + QString::number(index) + ".jpg");
graphicsScene->addPixmap(pixmap);
ui->graphicsView->setScene(graphicsScene);
// Shrinking scene if item is smaller than previous one
QRectF rect = graphicsScene->itemsBoundingRect();
graphicsScene->setSceneRect(rect);
ui->graphicsView->setScene(graphicsScene);
ui->graphicsView->fitInView(graphicsScene->sceneRect(), Qt::KeepAspectRatio);
// Contributor name
QString name = "<div align='center'><b>";
@ -68,6 +64,10 @@ void egg::changeIndex(int index) {
ui->contributorName->setText(name);
}
void egg::changeIndexSlot() {
changeIndex(index);
}
void egg::on_previousBtn_clicked()
{
if(index - 1 <= maximumIndex && index - 1 >= 0) {
@ -94,4 +94,3 @@ void egg::on_quitBtn_clicked()
{
this->close();
}

View file

@ -4,6 +4,7 @@
#include <QDialog>
#include <QMessageBox>
#include <QGraphicsScene>
#include <QTimer>
#include "functions.h"
@ -21,11 +22,12 @@ public:
int index = 0;
const int maximumIndex = 3;
bool firstRun = true;
void changeIndex(int index);
private slots:
void on_previousBtn_clicked();
void on_nextBtn_clicked();
void changeIndex(int index);
void changeIndexSlot();
void on_quitBtn_clicked();
private: