simple_mtglife

changeset 4:7cac97dca573

added coin flip
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 26 Jan 2015 07:48:56 +0200
parents 292c9a4b18d7
children 64df1dc24735
files data/mtg_heads.png data/mtg_tails.png mainwin.cc mainwin.h mainwin.ui resources.qrc simple_mtglife.pro
diffstat 7 files changed, 26 insertions(+), 1 deletions(-) [+]
line diff
     1.1 Binary file data/mtg_heads.png has changed
     2.1 Binary file data/mtg_tails.png has changed
     3.1 --- a/mainwin.cc	Mon Jan 26 06:03:12 2015 +0200
     3.2 +++ b/mainwin.cc	Mon Jan 26 07:48:56 2015 +0200
     3.3 @@ -1,3 +1,4 @@
     3.4 +#include <random>
     3.5  #include <QMessageBox>
     3.6  #include "mainwin.h"
     3.7  #include "ui_mainwin.h"
     3.8 @@ -69,3 +70,17 @@
     3.9              "GNU General Public License version 3 (or any later version).";
    3.10      QMessageBox::about(this, "About simple_mtglife", about_text);
    3.11  }
    3.12 +
    3.13 +void MainWin::on_action_flip_coin_triggered()
    3.14 +{
    3.15 +    static std::mt19937 gen;
    3.16 +    static std::bernoulli_distribution distr(0.5);
    3.17 +    bool res = distr(gen);
    3.18 +
    3.19 +    QMessageBox msg;
    3.20 +    msg.setText(res ? "<big>heads!</big>" : "<big>tails!</big>");
    3.21 +    msg.setIconPixmap(QPixmap(res ? ":data/mtg_heads.png" : ":data/mtg_tails.png"));
    3.22 +    msg.setWindowTitle("Coin flip");
    3.23 +    msg.setModal(true);
    3.24 +    msg.exec();
    3.25 +}
     4.1 --- a/mainwin.h	Mon Jan 26 06:03:12 2015 +0200
     4.2 +++ b/mainwin.h	Mon Jan 26 07:48:56 2015 +0200
     4.3 @@ -34,6 +34,8 @@
     4.4  
     4.5      void on_action_about_triggered();
     4.6  
     4.7 +    void on_action_flip_coin_triggered();
     4.8 +
     4.9  private:
    4.10  	Ui::MainWin *ui;
    4.11  };
     5.1 --- a/mainwin.ui	Mon Jan 26 06:03:12 2015 +0200
     5.2 +++ b/mainwin.ui	Mon Jan 26 07:48:56 2015 +0200
     5.3 @@ -405,6 +405,7 @@
     5.4       <string>&amp;File</string>
     5.5      </property>
     5.6      <addaction name="action_reset"/>
     5.7 +    <addaction name="action_flip_coin"/>
     5.8      <addaction name="separator"/>
     5.9      <addaction name="action_quit"/>
    5.10     </widget>
    5.11 @@ -432,6 +433,11 @@
    5.12      <string>&amp;About</string>
    5.13     </property>
    5.14    </action>
    5.15 +  <action name="action_flip_coin">
    5.16 +   <property name="text">
    5.17 +    <string>&amp;Flip coin</string>
    5.18 +   </property>
    5.19 +  </action>
    5.20   </widget>
    5.21   <layoutdefault spacing="6" margin="11"/>
    5.22   <resources>
     6.1 --- a/resources.qrc	Mon Jan 26 06:03:12 2015 +0200
     6.2 +++ b/resources.qrc	Mon Jan 26 07:48:56 2015 +0200
     6.3 @@ -1,5 +1,7 @@
     6.4  <RCC>
     6.5      <qresource prefix="/">
     6.6          <file>data/icon-96px.png</file>
     6.7 +        <file>data/mtg_heads.png</file>
     6.8 +        <file>data/mtg_tails.png</file>
     6.9      </qresource>
    6.10  </RCC>
     7.1 --- a/simple_mtglife.pro	Mon Jan 26 06:03:12 2015 +0200
     7.2 +++ b/simple_mtglife.pro	Mon Jan 26 07:48:56 2015 +0200
     7.3 @@ -19,7 +19,7 @@
     7.4  
     7.5  FORMS    += mainwin.ui
     7.6  
     7.7 -CONFIG += mobility
     7.8 +CONFIG += mobility c++11
     7.9  MOBILITY = 
    7.10  
    7.11  DISTFILES += \