Advertisement
Guest User

Untitled

a guest
Feb 19th, 2012
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.09 KB | None | 0 0
  1. #include "FenPendu.h"
  2. #include <time.h>
  3. #include <QDebug>
  4.  
  5.  
  6. FenPendu::FenPendu(QWidget *parent) : QMainWindow(parent)
  7. {
  8.     setWindowTitle("Pendu par alexandre :p");
  9.     cree_barre();
  10.     choisir_mot();
  11.     clavier_label();
  12. }
  13.  
  14. void FenPendu::cree_barre()
  15. {
  16.     m_menu_fichier = menuBar()->addMenu("&Fichier");
  17.     m_menu_propos = menuBar()->addMenu("&A propos");
  18.  
  19.     m_act_nouveauMot = m_menu_fichier->addAction("&Nouveau mot");
  20.     m_act_quitter = m_menu_fichier->addAction("&Quitter");
  21.     m_act_APropos = m_menu_propos->addAction("&A propos");
  22.     m_act_AProposQt = m_menu_propos->addAction("A propos de &Qt");
  23.  
  24.     m_act_nouveauMot->setShortcut(QKeySequence("CTRL+N"));
  25.     m_act_quitter->setShortcut(QKeySequence("CTRL+Q"));
  26.  
  27.     m_act_APropos->setShortcut(QKeySequence(Qt::Key_Help));
  28.     m_act_nouveauMot->setShortcut(QKeySequence("CTRL+A"));
  29.  
  30.     connect(m_act_quitter, SIGNAL(triggered()), qApp, SLOT(quit()));
  31.     connect(m_act_APropos, SIGNAL(triggered()), this, SLOT(APropos()));
  32.     connect(m_act_AProposQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
  33. }
  34.  
  35. void FenPendu::clavier_label()
  36. {
  37.     QVBoxLayout *vboxPrinc = new QVBoxLayout;
  38.     layout = new QGridLayout;
  39.     QWidget *conteneur = new QWidget(this);
  40.  
  41.     m_labelMot = new QLabel;
  42.  
  43.     QString stringLabel;
  44.     for(int i = 0; i <= m_motTirer.length(); i++)
  45.         stringLabel += "*";
  46.  
  47.     m_labelMot->setText(stringLabel);
  48.     m_labelMot->setFrameStyle(QFrame::Panel);
  49.     m_labelMot->setFont(QFont("arial", 25));
  50.  
  51.     vboxPrinc->addWidget(m_labelMot, 0, Qt::AlignCenter);
  52.  
  53.     QSignalMapper *mapper = new QSignalMapper(this);
  54.  
  55.     QPushButton *button;
  56.  
  57.     int col(0);
  58.     int row(0);
  59.     for ( char i('a'); i <= 'z'; i++ )
  60.     {
  61.         if ( (i - 'a')%7 == 0 )
  62.         {
  63.             col = 0;
  64.             row++;
  65.         }
  66.  
  67.         button = new QPushButton(QString(i));
  68.         layout->addWidget(button, row, col, Qt::AlignCenter);
  69.         connect(button, SIGNAL(clicked()), mapper, SLOT(map()));
  70.         mapper->setMapping(button, QString(i));
  71.         col++;
  72.     }
  73.     connect(mapper, SIGNAL(mapped(QString)), this, SLOT(analyserLettre(QString)));
  74.     vboxPrinc->addLayout(layout);
  75.     conteneur->setLayout(vboxPrinc);
  76.     setCentralWidget(conteneur);
  77. }
  78.  
  79. qint8 FenPendu::choisir_mot()
  80. {
  81.     QFile dictionnaire("dico.dic");
  82.     srand(time(NULL));
  83.     if(dictionnaire.open(QIODevice::ReadOnly | QIODevice::Text))
  84.     {
  85.         QTextStream flux(&dictionnaire);
  86.  
  87.         for(int i = rand()%22740; i != 0; i--)
  88.             m_motTirer = flux.readLine();
  89.  
  90.  
  91.  
  92.  
  93.  
  94.         return m_motTirer.length();
  95.     }
  96.  
  97.     else
  98.     {
  99.         QMessageBox::critical(0, "Erreur", "Le fichier \"dico.dic\" n'a pas été trouvé");
  100.         exit(1);
  101.     }
  102. }
  103.  
  104. void FenPendu::analyserLettre(const QString lettre)
  105. {
  106.     qDebug() << m_motTirer;
  107.     for(int i = 0; i <= m_motTirer.length(); i++)
  108.     {
  109.         if(lettre == m_motTirer.at(i))
  110.             qDebug() << m_motTirer.at(i);
  111.  
  112.     }
  113. }
  114.  
  115. void FenPendu::APropos()
  116. {
  117.     FenAPropos *FenetreAPropos = new FenAPropos(this);
  118.     FenetreAPropos->exec();
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement