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

View file

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