Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: overxfl0w13 en 14 Agosto 2012, 02:58 am



Título: [Aporte] Deletreador C++
Publicado por: overxfl0w13 en 14 Agosto 2012, 02:58 am
Buenas compañeros, vengo a dejar el code de un deletreador hecho en C++ con Gui en Qt, que aunque estoy de vacaciones, siempre sale tiempo para programar algo :).

La voz es mia (cutre) porque no he podido encontrar nada por google y actualmente solo tiene las letras en español con posible ampliación a letras en inglés (si encuentro alguna).

Screen: (http://i48.tinypic.com/2nspd3m.png)

Descarga Exe: http://www.mediafire.com/?u4oa2f857av35kl (http://www.mediafire.com/?u4oa2f857av35kl)


Headers:

Deletreador.hpp:

Código
  1. #include <QtGui>
  2.  
  3. class deletreador
  4. {
  5.        public:
  6.            deletreador(QString texto,QString idiomasel);
  7.  
  8.        private:
  9.            QString textRead;
  10.            QSound *letraRead;
  11. };
  12.  
  13.  

Window.hpp:

Código
  1. #include <QObject>
  2. #include <QtGui>
  3. #include <QMessageBox>
  4.  
  5. class window : public QMainWindow
  6. {
  7.        Q_OBJECT
  8.  
  9.        public:
  10.  
  11.              window();
  12.              void compruebaPalindromo();
  13.              void primeLetra();
  14.              void ultimLetra();
  15.              void longiCadena();
  16.              void funcionReves();
  17.  
  18.        private slots:
  19.  
  20.              void deletrear();
  21.  
  22.        public:
  23.  
  24.              QWidget *myWindow;
  25.              QVBoxLayout *mainLayout,*izqLayout,*derLayout;
  26.              QHBoxLayout *izqderLayout,*buttonLayout;
  27.              QLineEdit *textIn;
  28.              QPushButton *acceptButton;
  29.              QLabel *ultimaLetra,*primeraLetra,*longitudCadena,*palindroma,*mainImage,*mainCongratulations,*mainSpace,*spaceTwo,*spaceThree,*textoReves,*selecIdioma,*labelTexto;
  30.              QString textoDel,ulLetra,priLetra,textPalin,acumPalin,textoRev,idiomasel;
  31.              QPixmap *image;
  32.              QToolBar *languageToolbar;
  33.              QMessageBox *mensaje;
  34.              QComboBox *idiomas;
  35. };
  36.  
  37.  

Sources:

Window.cpp:

Código
  1. #include "window.hpp"
  2. #include "deletreador.hpp"
  3.  
  4. window::window()
  5. {
  6.    // Definicion
  7.  
  8.    myWindow = new QWidget;
  9.    mainLayout = new QVBoxLayout;
  10.    izqLayout = new QVBoxLayout;
  11.    derLayout = new QVBoxLayout;
  12.    izqderLayout = new QHBoxLayout;
  13.    textIn = new QLineEdit;
  14.    idiomas = new QComboBox;
  15.    buttonLayout = new QHBoxLayout;
  16.    labelTexto = new QLabel("Inserta el texto");
  17.    labelTexto->setAlignment(Qt::AlignCenter);
  18.  
  19.  
  20.    /***********************************/
  21.  
  22.    idiomas->addItem("Español");
  23.    idiomas->addItem("Inglés");
  24.    acceptButton = new QPushButton("Deletrear");
  25.    mainImage = new QLabel;
  26.    mensaje = new QMessageBox;
  27.    mensaje->setText("Cadena Vacia");
  28.    image = new QPixmap("Resources/Images/libro.png");
  29.    mainImage->setPixmap(*image);
  30.    mainImage->setAlignment(Qt::AlignCenter);
  31.    ultimaLetra = new QLabel("La ultima letra es: ");
  32.    textoReves = new QLabel("La cadena invertida es: ");
  33.    selecIdioma = new QLabel("Idioma seleccionado: " + idiomas->currentText());
  34.    mainSpace = new QLabel(" ");
  35.    spaceTwo = new QLabel(" ");
  36.    spaceThree = new QLabel(" ");
  37.    primeraLetra = new QLabel("La primera letra es: ");
  38.    longitudCadena = new QLabel("La longitud del texto es: ");
  39.    palindroma = new QLabel("La palabra es palindroma: ");
  40.    mainCongratulations = new QLabel("By Overxfl0w");
  41.    mainCongratulations->setAlignment(Qt::AlignCenter);
  42.    mainCongratulations->setText("<font size=3 color=#0000FF>By Overxfl0w to elhacker.net</font>");
  43.    idiomas->setFixedSize(100,20);
  44.  
  45.    // Conexiones
  46.  
  47.    QObject::connect(acceptButton,SIGNAL(clicked()),this,SLOT(deletrear()));
  48.  
  49.    // Construccion
  50.  
  51.    myWindow->setMinimumSize(420,360);
  52.    myWindow->setMaximumSize(420,360);
  53.    buttonLayout->addWidget(idiomas);
  54.    buttonLayout->addWidget(acceptButton);
  55.    izqLayout->addWidget(primeraLetra);
  56.    izqLayout->addWidget(ultimaLetra);
  57.    izqLayout->addWidget(textoReves);
  58.    derLayout->addWidget(selecIdioma);
  59.    derLayout->addWidget(palindroma);
  60.    derLayout->addWidget(longitudCadena);
  61.    izqderLayout->addLayout(izqLayout);
  62.    izqderLayout->addLayout(derLayout);
  63.    mainLayout->addWidget(mainImage);
  64.    mainLayout->addWidget(spaceThree);
  65.    mainLayout->addWidget(labelTexto);
  66.    mainLayout->addWidget(textIn);
  67.    mainLayout->addLayout(buttonLayout);
  68.    mainLayout->addWidget(mainSpace);
  69.    mainLayout->addLayout(izqderLayout);
  70.    mainLayout->addWidget(spaceTwo);
  71.    mainLayout->addWidget(mainCongratulations);
  72.    myWindow->setLayout(mainLayout);
  73.    myWindow->setWindowTitle("Speller By Overxfl0w");
  74.    myWindow->show();
  75. }
  76.  
  77. void window::deletrear()
  78. {
  79.    if(textIn->text() != "")
  80.    {
  81.        primeLetra();
  82.        ultimLetra();
  83.        funcionReves();
  84.        compruebaPalindromo();
  85.        longiCadena();
  86.        delete selecIdioma;
  87.        idiomasel = idiomas->currentText();
  88.        selecIdioma = new QLabel("Idioma seleccionado: " + idiomasel);
  89.        derLayout->addWidget(selecIdioma);
  90.        deletreador deletreador(textIn->text(),idiomasel);
  91.    }
  92.    else
  93.    {
  94.        mensaje->exec();
  95.    }
  96.  
  97. }
  98.  
  99. void window::primeLetra()
  100. {
  101.    priLetra = textIn->text();
  102.    delete primeraLetra;
  103.    primeraLetra = new QLabel("La primera letra es: " + priLetra[0]);
  104.    izqLayout->addWidget(primeraLetra);
  105.  
  106. }
  107.  
  108. void window::ultimLetra()
  109. {
  110.    int longitud = textIn->text().length();
  111.    ulLetra = textIn->text();
  112.    delete ultimaLetra;
  113.    ultimaLetra = new QLabel("La ultima letra es: " +ulLetra[longitud-1]);
  114.    izqLayout->addWidget(ultimaLetra);
  115. }
  116.  
  117. void window::longiCadena()
  118. {
  119.    int longitud2 = textIn->text().length();
  120.    delete longitudCadena;
  121.    longitudCadena = new QLabel("La longitud del texto es: " + QString::number(longitud2));
  122.    derLayout->addWidget(longitudCadena);
  123. }
  124.  
  125. void window::compruebaPalindromo()
  126. {
  127.    textPalin = textIn->text();
  128.    acumPalin = "";
  129.    for(int x = textPalin.length()-1;x>=0;x--)
  130.    {
  131.        acumPalin = acumPalin + textPalin[x];
  132.    }
  133.    if(textPalin == acumPalin)
  134.    {
  135.        delete palindroma;
  136.        palindroma = new QLabel("La palabra es palindroma: Si");
  137.        derLayout->addWidget(palindroma);
  138.        acumPalin = "";
  139.    }
  140.    else
  141.    {
  142.        delete palindroma;
  143.        palindroma = new QLabel("La palabra es palindroma: No");
  144.        derLayout->addWidget(palindroma);
  145.        acumPalin = "";
  146.    }
  147.  
  148. }
  149.  
  150. void window::funcionReves()
  151. {
  152.    textPalin = textIn->text();
  153.    textoRev = "";
  154.    for(int x = textPalin.length()-1;x>=0;x--)
  155.    {
  156.        textoRev = textoRev + textPalin[x];
  157.    }
  158.    delete textoReves;
  159.    textoReves = new QLabel("La cadena invertida es: " + textoRev);
  160.    izqLayout->addWidget(textoReves);
  161. }
  162.  

Deletreador.cpp:

Código
  1. #include "deletreador.hpp"
  2. #include "window.hpp"
  3. #include <windows.h>
  4.  
  5. deletreador::deletreador(QString texto,QString idiomasel)
  6. {
  7.    textRead = texto;
  8.    if(idiomasel == "Español")
  9.    {
  10.    for(int x=0;x<textRead.length();x++)
  11.    {
  12.        if(textRead[x] != ' ')
  13.        {
  14.        letraRead = new QSound("Resources/Sounds/Spanish/"+textRead[x]+".wav");
  15.        letraRead->play();
  16.        Sleep(1100);
  17.        }
  18.    }
  19.    }
  20.    if(idiomasel == "Inglés")
  21.    {
  22.        for(int x=0;x<textRead.length();x++)
  23.        {
  24.            if(textRead[x] != ' ')
  25.            {
  26.            letraRead = new QSound("Resources/Sounds/English/"+textRead[x]+".wav");
  27.            letraRead->play();
  28.            Sleep(1100);
  29.            }
  30.        }
  31.        }
  32.    }
  33.  

Main.cpp:

Código
  1. #include "window.hpp"
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5.    QApplication app(argc, argv);
  6.    window window;
  7.    return app.exec();
  8. }
  9.  

PD: Usa windows.h para el Sleep si surge cualquier problema, incluir la libreria stdio.h con la función sleep pasándole un int como valor para los segundos.
Un saludo :)


Título: Re: [Aporte] Deletreador C++
Publicado por: eleon en 14 Agosto 2012, 03:29 am
:O Genial, gracias por el aporte.

EDITO:

Una pregunta, ¿qué tipo de funciones (parte gráfica o llamadas al sistema) no has encontrado en QT y has tenido que usar la API de Windows?.

No tengo mucha mano con QT y quisiera saber qué cosas se puede hacer con ella y qué cosas no se pueden hacer.

Gracias.


Título: Re: [Aporte] Deletreador C++
Publicado por: overxfl0w13 en 14 Agosto 2012, 03:49 am
:O Genial, gracias por el aporte.

EDITO:

Una pregunta, ¿qué tipo de funciones (parte gráfica o llamadas al sistema) no has encontrado en QT y has tenido que usar la API de Windows?.

No tengo mucha mano con QT y quisiera saber qué cosas se puede hacer con ella y qué cosas no se pueden hacer.

Gracias.

La API de Windows no la he usado nada para la parte gráfica, únicamente para hacer un sleep entre letra y letra y que así de tiempo a la reproducción de las mismas.

Con Qt puedes hacer  bastantes cosas desde frameworks hasta manejar diferentes tipos de servidores, sockets... Te dejo la documentación que va de lujo y no estaría de más que te mirases sus clases,métodos etc:

http://qt-project.org/doc/qt-4.8/

Un saludo :)


Título: Re: [Aporte] Deletreador C++
Publicado por: avesudra en 14 Agosto 2012, 14:38 pm
¡Olé que arte! Ahora con sílabas, mm eso es más complicado , pues habría que hacer una función que separase cada palabra en sílabas que habrá reglas, no me acuerdo.De todas maneras por si te da por hacerlo aquí están todas las sílabas:
http://www.solosequenosenada.com/gramatica/spanish/listado_silabas.php
PD: Se te han olvidado los números.


Título: Re: [Aporte] Deletreador C++
Publicado por: overxfl0w13 en 14 Agosto 2012, 20:30 pm
¡Olé que arte! Ahora con sílabas, mm eso es más complicado , pues habría que hacer una función que separase cada palabra en sílabas que habrá reglas, no me acuerdo.De todas maneras por si te da por hacerlo aquí están todas las sílabas:
http://www.solosequenosenada.com/gramatica/spanish/listado_silabas.php
PD: Se te han olvidado los números.

En un principio el proyecto era para leer frases completas, pero surgieron problemas precisamente con las sílabas. Tenía pensado grabar todas las combinaciones de 2 silabas y hacerlo más limitado, pero al final preferí dejarlo así :).

Lo de los números no se me había olvidado. simplemente que es muy pesado ir grabando letra a letra y número a número, no había ganas xD

Un saludo :)


Título: Re: [Aporte] Deletreador C++
Publicado por: avesudra en 14 Agosto 2012, 20:42 pm
Es que son demasiadas silabas comprendo que sea un coñazo.


Título: Re: [Aporte] Deletreador C++
Publicado por: Kasswed en 15 Agosto 2012, 14:00 pm
Muy útil, gracias por el aporte.

Ahora el mundo irá a mejor.