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
Headers:
Deletreador.hpp:
Window.hpp:
Sources:
Window.cpp:
Deletreador.cpp:
Main.cpp:
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
![:) :)](https://forum.elhacker.net/Smileys/navidad/smiley.gif)
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
Headers:
Deletreador.hpp:
Código (cpp) [Seleccionar]
#include <QtGui>
class deletreador
{
public:
deletreador(QString texto,QString idiomasel);
private:
QString textRead;
QSound *letraRead;
};
Window.hpp:
Código (cpp) [Seleccionar]
#include <QObject>
#include <QtGui>
#include <QMessageBox>
class window : public QMainWindow
{
Q_OBJECT
public:
window();
void compruebaPalindromo();
void primeLetra();
void ultimLetra();
void longiCadena();
void funcionReves();
private slots:
void deletrear();
public:
QWidget *myWindow;
QVBoxLayout *mainLayout,*izqLayout,*derLayout;
QHBoxLayout *izqderLayout,*buttonLayout;
QLineEdit *textIn;
QPushButton *acceptButton;
QLabel *ultimaLetra,*primeraLetra,*longitudCadena,*palindroma,*mainImage,*mainCongratulations,*mainSpace,*spaceTwo,*spaceThree,*textoReves,*selecIdioma,*labelTexto;
QString textoDel,ulLetra,priLetra,textPalin,acumPalin,textoRev,idiomasel;
QPixmap *image;
QToolBar *languageToolbar;
QMessageBox *mensaje;
QComboBox *idiomas;
};
Sources:
Window.cpp:
Código (cpp) [Seleccionar]
#include "window.hpp"
#include "deletreador.hpp"
window::window()
{
// Definicion
myWindow = new QWidget;
mainLayout = new QVBoxLayout;
izqLayout = new QVBoxLayout;
derLayout = new QVBoxLayout;
izqderLayout = new QHBoxLayout;
textIn = new QLineEdit;
idiomas = new QComboBox;
buttonLayout = new QHBoxLayout;
labelTexto = new QLabel("Inserta el texto");
labelTexto->setAlignment(Qt::AlignCenter);
/***********************************/
idiomas->addItem("Español");
idiomas->addItem("Inglés");
acceptButton = new QPushButton("Deletrear");
mainImage = new QLabel;
mensaje = new QMessageBox;
mensaje->setText("Cadena Vacia");
image = new QPixmap("Resources/Images/libro.png");
mainImage->setPixmap(*image);
mainImage->setAlignment(Qt::AlignCenter);
ultimaLetra = new QLabel("La ultima letra es: ");
textoReves = new QLabel("La cadena invertida es: ");
selecIdioma = new QLabel("Idioma seleccionado: " + idiomas->currentText());
mainSpace = new QLabel(" ");
spaceTwo = new QLabel(" ");
spaceThree = new QLabel(" ");
primeraLetra = new QLabel("La primera letra es: ");
longitudCadena = new QLabel("La longitud del texto es: ");
palindroma = new QLabel("La palabra es palindroma: ");
mainCongratulations = new QLabel("By Overxfl0w");
mainCongratulations->setAlignment(Qt::AlignCenter);
mainCongratulations->setText("<font size=3 color=#0000FF>By Overxfl0w to elhacker.net</font>");
idiomas->setFixedSize(100,20);
// Conexiones
QObject::connect(acceptButton,SIGNAL(clicked()),this,SLOT(deletrear()));
// Construccion
myWindow->setMinimumSize(420,360);
myWindow->setMaximumSize(420,360);
buttonLayout->addWidget(idiomas);
buttonLayout->addWidget(acceptButton);
izqLayout->addWidget(primeraLetra);
izqLayout->addWidget(ultimaLetra);
izqLayout->addWidget(textoReves);
derLayout->addWidget(selecIdioma);
derLayout->addWidget(palindroma);
derLayout->addWidget(longitudCadena);
izqderLayout->addLayout(izqLayout);
izqderLayout->addLayout(derLayout);
mainLayout->addWidget(mainImage);
mainLayout->addWidget(spaceThree);
mainLayout->addWidget(labelTexto);
mainLayout->addWidget(textIn);
mainLayout->addLayout(buttonLayout);
mainLayout->addWidget(mainSpace);
mainLayout->addLayout(izqderLayout);
mainLayout->addWidget(spaceTwo);
mainLayout->addWidget(mainCongratulations);
myWindow->setLayout(mainLayout);
myWindow->setWindowTitle("Speller By Overxfl0w");
myWindow->show();
}
void window::deletrear()
{
if(textIn->text() != "")
{
primeLetra();
ultimLetra();
funcionReves();
compruebaPalindromo();
longiCadena();
delete selecIdioma;
idiomasel = idiomas->currentText();
selecIdioma = new QLabel("Idioma seleccionado: " + idiomasel);
derLayout->addWidget(selecIdioma);
deletreador deletreador(textIn->text(),idiomasel);
}
else
{
mensaje->exec();
}
}
void window::primeLetra()
{
priLetra = textIn->text();
delete primeraLetra;
primeraLetra = new QLabel("La primera letra es: " + priLetra[0]);
izqLayout->addWidget(primeraLetra);
}
void window::ultimLetra()
{
int longitud = textIn->text().length();
ulLetra = textIn->text();
delete ultimaLetra;
ultimaLetra = new QLabel("La ultima letra es: " +ulLetra[longitud-1]);
izqLayout->addWidget(ultimaLetra);
}
void window::longiCadena()
{
int longitud2 = textIn->text().length();
delete longitudCadena;
longitudCadena = new QLabel("La longitud del texto es: " + QString::number(longitud2));
derLayout->addWidget(longitudCadena);
}
void window::compruebaPalindromo()
{
textPalin = textIn->text();
acumPalin = "";
for(int x = textPalin.length()-1;x>=0;x--)
{
acumPalin = acumPalin + textPalin[x];
}
if(textPalin == acumPalin)
{
delete palindroma;
palindroma = new QLabel("La palabra es palindroma: Si");
derLayout->addWidget(palindroma);
acumPalin = "";
}
else
{
delete palindroma;
palindroma = new QLabel("La palabra es palindroma: No");
derLayout->addWidget(palindroma);
acumPalin = "";
}
}
void window::funcionReves()
{
textPalin = textIn->text();
textoRev = "";
for(int x = textPalin.length()-1;x>=0;x--)
{
textoRev = textoRev + textPalin[x];
}
delete textoReves;
textoReves = new QLabel("La cadena invertida es: " + textoRev);
izqLayout->addWidget(textoReves);
}
Deletreador.cpp:
Código (cpp) [Seleccionar]
#include "deletreador.hpp"
#include "window.hpp"
#include <windows.h>
deletreador::deletreador(QString texto,QString idiomasel)
{
textRead = texto;
if(idiomasel == "Español")
{
for(int x=0;x<textRead.length();x++)
{
if(textRead[x] != ' ')
{
letraRead = new QSound("Resources/Sounds/Spanish/"+textRead[x]+".wav");
letraRead->play();
Sleep(1100);
}
}
}
if(idiomasel == "Inglés")
{
for(int x=0;x<textRead.length();x++)
{
if(textRead[x] != ' ')
{
letraRead = new QSound("Resources/Sounds/English/"+textRead[x]+".wav");
letraRead->play();
Sleep(1100);
}
}
}
}
Main.cpp:
Código (cpp) [Seleccionar]
#include "window.hpp"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
window window;
return app.exec();
}
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
![:) :)](https://forum.elhacker.net/Smileys/navidad/smiley.gif)