cp-pum4

Untitled

Apr 26th, 2012
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //mainwindow.h
  2.  
  3. #ifndef MAINWINDOW_H
  4. #define MAINWINDOW_H
  5.  
  6. #include <QMainWindow>
  7. #include <QtCore>
  8. #include <QtGui>
  9.  
  10.  
  11. namespace Ui {
  12. class MainWindow;
  13. }
  14.  
  15. class MainWindow : public QMainWindow
  16. {
  17.     Q_OBJECT
  18.    
  19. public:
  20.     explicit MainWindow(QWidget *parent = 0);
  21.     ~MainWindow();
  22.    
  23. private slots:
  24.     void on_actionNuevo_triggered();
  25.  
  26.     void on_actionAbrir_triggered();
  27.  
  28.     void on_actionGuardar_triggered();
  29.  
  30.     void on_actionGuardar_Como_triggered();
  31.  
  32.     void on_actionCopiar_triggered();
  33.  
  34.     void on_actionCortar_triggered();
  35.  
  36.     void on_actionDeshacer_triggered();
  37.  
  38.     void on_actionRehacer_triggered();
  39.  
  40.     void on_actionAyuda_triggered();
  41.  
  42.     void on_actionAcerca_De_triggered();
  43.  
  44.     void on_actionPegar_triggered();
  45.  
  46. private:
  47.     Ui::MainWindow *ui;
  48.  
  49.     QString bn;
  50. };
  51.  
  52. #endif // MAINWINDOW_H
  53.  
  54.  
  55.  
  56. //mainwindow.cpp
  57.  
  58. #include "mainwindow.h"
  59. #include "ui_mainwindow.h"
  60.  
  61. MainWindow::MainWindow(QWidget *parent) :
  62.     QMainWindow(parent),
  63.     ui(new Ui::MainWindow)
  64. {
  65.     ui->setupUi(this);
  66.     this->setCentralWidget(ui->textEdit);
  67.  
  68. }
  69.  
  70. MainWindow::~MainWindow()
  71. {
  72.     delete ui;
  73. }
  74.  
  75. void MainWindow::on_actionNuevo_triggered()
  76. {
  77.     bn = "";
  78.     ui->textEdit->setPlainText("");
  79.  
  80. }
  81.  
  82. void MainWindow::on_actionAbrir_triggered()
  83. {
  84.     QString pbloc = QFileDialog::getOpenFileName(this, "Abrir un Archivo");
  85.  
  86.     if(!pbloc.isEmpty())
  87.     {
  88.         QFile archT(pbloc);
  89.         if(archT.open(QFile::ReadOnly | QFile::Text))
  90.         {
  91.             bn = pbloc;
  92.             QTextStream n(&archT);
  93.             QString tex = n.readAll();
  94.             archT.close();
  95.  
  96.             ui->textEdit->setPlainText(tex);
  97.         }
  98.     }
  99. }
  100.  
  101. void MainWindow::on_actionGuardar_triggered()
  102. {
  103.     QFile archJ(bn);
  104.     if(archJ.open(QFile::ReadOnly | QFile::Text))
  105.     {
  106.         QTextStream stream(&archJ);
  107.  
  108.         stream << ui->textEdit->toPlainText();
  109.  
  110.         archJ.flush();
  111.         archJ.close();
  112.     }
  113. }
  114.  
  115. void MainWindow::on_actionGuardar_Como_triggered()
  116. {
  117.     QString pbloc = QFileDialog::getSaveFileName(this,"Guardar como");
  118.  
  119.     if(!pbloc.isEmpty())
  120.     {
  121.         bn = pbloc;
  122.         on_actionGuardar_triggered();
  123.     }
  124. }
  125.  
  126. void MainWindow::on_actionCopiar_triggered()
  127. {
  128.     ui->textEdit->copy();
  129. }
  130.  
  131. void MainWindow::on_actionCortar_triggered()
  132. {
  133.     ui->textEdit->cut();
  134. }
  135.  
  136. void MainWindow::on_actionPegar_triggered()
  137. {
  138.     ui->textEdit->paste();
  139. }
  140.  
  141. void MainWindow::on_actionDeshacer_triggered()
  142. {
  143.     ui->textEdit->undo();
  144. }
  145.  
  146. void MainWindow::on_actionRehacer_triggered()
  147. {
  148.     ui->textEdit->redo();
  149. }
  150.  
  151. void MainWindow::on_actionAyuda_triggered()
  152. {
  153.     QMessageBox::information(this,"Ayuda", "<h1>Aqui pondras toda tu ayuda</h1");
  154. }
  155.  
  156. void MainWindow::on_actionAcerca_De_triggered()
  157. {
  158.     QMessageBox::information(this,"Acerca De",
  159.                              "<b>Este es un ejemplo de un bloc de notas para la familia de cyberlocos <font color=blue>by cp-pUm4</font></b>");
  160.  
  161. }
  162.  
  163.  
  164. //main.cpp
  165.  
  166.  
  167. #include <QtGui/QApplication>
  168. #include "mainwindow.h"
  169.  
  170. int main(int argc, char *argv[])
  171. {
  172.     QApplication a(argc, argv);
  173.     MainWindow w;
  174.     w.show();
  175.    
  176.     return a.exec();
  177. }
Advertisement
Add Comment
Please, Sign In to add comment