Skip to content

Commit

Permalink
Add methods to EasterEgg
Browse files Browse the repository at this point in the history
  • Loading branch information
KraTuX31 committed Apr 9, 2015
1 parent dfd9ecf commit 2841770
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 8 deletions.
8 changes: 8 additions & 0 deletions src/gui/utils/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ QPixmap Image::bytesToPixmap(const QByteArray bytes)
return QPixmap::fromImage(QImage::fromData(bytes));
}

QPixmap Image::getImage(QString path, int width, int height)
{
QPixmap img(path);
img.scaled(width,height,Qt::KeepAspectRatio);

return img;
}

QByteArray Image::imageToBytes(QImage image, const QString ext) {
QByteArray bytesArray;
QByteArray extArray = ext.toLocal8Bit();
Expand Down
12 changes: 12 additions & 0 deletions src/gui/utils/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ class Image
* @return QPixmap from bytes
*/
static QPixmap bytesToPixmap(const QByteArray bytes);

/**
* @brief Image::getImage Return a scaled image from the
* icon specified by it <i>path</i>. The image returned has a resolution of
* <i>width</i>*<i>height</i> (default 256*256)
* @param path Icon path
* @param width Icon width
* @param height Icon height
* @return Scaled image
*/
static QPixmap getImage(QString path, int width = 256, int height = 256);

};

}
Expand Down
125 changes: 125 additions & 0 deletions src/gui/widgets/coffeeeastereggwidget.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,139 @@
#include "coffeeeastereggwidget.h"
#include "ui_coffeeeastereggwidget.h"

namespace Gui {
namespace Widgets {
CoffeeEasterEggWidget::CoffeeEasterEggWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::CoffeeEasterEggWidget)
{
ui->setupUi(this);
setupUI();
}

CoffeeEasterEggWidget::~CoffeeEasterEggWidget()
{
delete ui;
}

void CoffeeEasterEggWidget::setupUI() {
_state = 0;
_drinked = 0;
ui->lbCoffee->setPixmap(
Gui::Utils::Image::getImage(":/icons/img/coffee_level0.png"));
ui->lbScreenControl->setText("<html><head/><body><p align=""center"">"
"Pour bien bosser, il faut du café!"
"</p></body></html>");
ui->btnCoffeeMaker->setText("Faire le café !");
ui->btnCoffeeMaker->setEnabled(true);
/*
":/icons/img/coffee_level0.png"
":/icons/img/coffee_level1.png"
":/icons/img/coffee_level2.png"
":/icons/img/coffee_level3.png"
":/icons/img/coffee_level4.png"
":/icons/img/coffee_ready.png"
*/
}

void CoffeeEasterEggWidget::makeCoffeeInProgress()
{
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(nextState()));
timer->start(1000);

}

void CoffeeEasterEggWidget::makeCoffeeFirstStep() {
_state = 1;
ui->lbCoffee->setPixmap(
Gui::Utils::Image::getImage(":/icons/img/coffee_level1.png"));
ui->lbScreenControl->setText("<html><head/><body><p align=""center"">"
"Chauffage de l'eau..."
"</p></body></html>");
ui->btnCoffeeMaker->setText("Faire le café !");
ui->btnCoffeeMaker->setEnabled(false);
}

void CoffeeEasterEggWidget::makeCoffeeSecondStep() {
_state = 2;
ui->lbCoffee->setPixmap(
Gui::Utils::Image::getImage(":/icons/img/coffee_level2.png"));
ui->lbScreenControl->setText("<html><head/><body><p align=""center"">"
"En train de moudre le café..."
"</p></body></html>");
ui->btnCoffeeMaker->setText("Faire le café !");
ui->btnCoffeeMaker->setEnabled(false);
}

void CoffeeEasterEggWidget::makeCoffeeThirdStep() {
_state = 3;
ui->lbCoffee->setPixmap(
Gui::Utils::Image::getImage(":/icons/img/coffee_level3.png"));
ui->lbScreenControl->setText("<html><head/><body><p align=""center"">"
"Préparation du café"
"</p></body></html>");
ui->btnCoffeeMaker->setText("Faire le café !");
ui->btnCoffeeMaker->setEnabled(false);
}

void CoffeeEasterEggWidget::makeCoffeeFourthStep() {
_state = 4;
ui->lbCoffee->setPixmap(
Gui::Utils::Image::getImage(":/icons/img/coffee_level4.png"));
ui->lbScreenControl->setText("<html><head/><body><p align=""center"">"
"Préparation du café..."
"</p></body></html>");
ui->btnCoffeeMaker->setText("Faire le café !");
ui->btnCoffeeMaker->setEnabled(false);
}

void CoffeeEasterEggWidget::makeCoffeeReadyStep() {
_state = 5;
if (!isDrinked()) {
ui->lbCoffee->setPixmap(
Gui::Utils::Image::getImage(":/icons/img/coffee_ready.png"));
ui->lbScreenControl->setText("<html><head/><body><p align=""center"">"
"Café prêt :)"
"</p></body></html>");
ui->btnCoffeeMaker->setText("Faire le café !");
ui->btnCoffeeMaker->setEnabled(false);
_drinked++;
} else {
setupUI();
}

}

bool CoffeeEasterEggWidget::isDrinked() {
return _drinked == 3;
}

void CoffeeEasterEggWidget::nextState() {
switch(_state) {
case 0:
setupUI();
break;
case 1:
makeCoffeeFirstStep();
break;
case 2:
makeCoffeeSecondStep();
break;
case 3:
makeCoffeeThirdStep();
break;
case 4:
makeCoffeeFourthStep();
break;
case 5:
makeCoffeeReadyStep();
break;
default:
setupUI();
}
}


}
}
30 changes: 30 additions & 0 deletions src/gui/widgets/coffeeeastereggwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,51 @@
#define COFFEEEASTEREGGWIDGET_H

#include <QWidget>
#include <QTimer>
#include "gui/utils/image.h"

namespace Ui {
class CoffeeEasterEggWidget;
}

namespace Gui {
namespace Widgets {

/**
* @brief The CoffeeEasterEggWidget class
*/
class CoffeeEasterEggWidget : public QWidget
{
Q_OBJECT

public:
/**
* @brief CoffeeEasterEggWidget
* @param parent
*/
explicit CoffeeEasterEggWidget(QWidget *parent = 0);
~CoffeeEasterEggWidget();

void setupUI();

void makeCoffeeInProgress();

void makeCoffeeFirstStep();
void makeCoffeeSecondStep();
void makeCoffeeThirdStep();
void makeCoffeeFourthStep();
void makeCoffeeReadyStep();
bool isDrinked();

public slots:
void nextState();
private:
Ui::CoffeeEasterEggWidget *ui;
int _state;
int _drinked;

};
}
}

#endif // COFFEEEASTEREGGWIDGET_H
40 changes: 32 additions & 8 deletions src/gui/widgets/coffeeeastereggwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,37 @@
<x>0</x>
<y>0</y>
<width>274</width>
<height>355</height>
<height>364</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<widget class="QLabel" name="lbScreenControl">
<property name="minimumSize">
<size>
<width>0</width>
<height>48</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>72</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="text">
<string>TextLabel</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;Pour bien bosser, il faut du café!&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<widget class="QLabel" name="lbCoffee">
<property name="minimumSize">
<size>
<width>256</width>
Expand All @@ -36,14 +51,21 @@
</size>
</property>
<property name="text">
<string>TextLabel</string>
<string/>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="btnCoffeeMaker">
<property name="text">
<string>PushButton</string>
<string>Faire le café !</string>
</property>
<property name="icon">
<iconset resource="../../icons.qrc">
<normaloff>:/icons/img/coffee_ready.png</normaloff>:/icons/img/coffee_ready.png</iconset>
</property>
</widget>
</item>
Expand All @@ -62,6 +84,8 @@
</item>
</layout>
</widget>
<resources/>
<resources>
<include location="../../icons.qrc"/>
</resources>
<connections/>
</ui>

0 comments on commit 2841770

Please sign in to comment.