DarthVictor

Untitled

Nov 29th, 2011
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.52 KB | None | 0 0
  1.  
  2. //**********************************
  3. //**********************************
  4. //********mainwindow.h**************
  5. //**********************************
  6. //**********************************
  7.  
  8.  
  9. #ifndef MAINWINDOW_H
  10. #define MAINWINDOW_H
  11.  
  12. #include <QMainWindow>
  13. #include <QFile>
  14. #include <QFileDialog>
  15. #include <QString>
  16. #include <iostream>
  17. #include <stdio.h>
  18. #include <cstdlib>
  19. #include <QMessageBox>
  20. #include <fstream>
  21. /**
  22. * @author Victor Mello Floriano
  23. */
  24.  
  25. //Download 4 windows :
  26. //Download 4 Linux 32 bits :
  27. //Donwload 4 Linux 64 bits :
  28. namespace Ui {
  29.     class MainWindow;
  30. }
  31.  
  32. class MainWindow : public QMainWindow
  33. {
  34.     Q_OBJECT
  35.  
  36. public:
  37.     explicit MainWindow(QWidget *parent = 0);
  38.     ~MainWindow();
  39.  
  40. private slots:
  41.     void on_actionOpen_triggered();
  42.     void on_actionSave_triggered();
  43.     void on_actionQUIT_triggered();
  44.     void on_actionFULLSCREEN_triggered();
  45.  
  46. private:
  47.     Ui::MainWindow *ui;
  48. };
  49.  
  50. #endif // MAINWINDOW_H
  51.  
  52. //**********************************
  53. //**********************************
  54. //********mainwindow.cpp************
  55. //**********************************
  56. //**********************************
  57.  
  58.  
  59. #include "mainwindow.h"
  60. #include "ui_mainwindow.h"
  61.  
  62. using namespace std;
  63. MainWindow::MainWindow(QWidget *parent) :
  64.     QMainWindow(parent),
  65.     ui(new Ui::MainWindow)
  66. {
  67.     ui->setupUi(this);
  68. }
  69.  
  70. MainWindow::~MainWindow()
  71. {
  72.     delete ui;
  73. }
  74.  
  75. void MainWindow::on_actionOpen_triggered()
  76. {
  77.     QString fileName = QFileDialog::getOpenFileName(this,tr("Abrir arquivo"),"","*.txt");
  78.     ifstream f (fileName.toStdString().c_str());
  79.  
  80.     if(!f.is_open())
  81.     {
  82.         QMessageBox msgBox;
  83.                  msgBox.setText("Error n 666 you are not doomed \n especifique um caminho ");
  84.                  msgBox.exec();
  85.                  return;
  86.     }
  87.     string l;
  88.     QString s;
  89.     QString aux;
  90.     s.clear();
  91.     aux.clear();
  92.     while(f.good())
  93.     {
  94.         getline(f,l);
  95.         //cout<<l<<"\n";
  96.         aux=aux.fromStdString(l);
  97.         //cout<<aux.toStdString()<<"\n";
  98.         s=s+aux+"\n";
  99.        // cout<<s.toStdString()<<"\n";
  100.  
  101.     }
  102.  
  103.     ui->plainTextEdit->setPlainText(s);
  104. }
  105.  
  106. void MainWindow::on_actionSave_triggered()
  107. {
  108.     QString fileName = QFileDialog::getSaveFileName(this,tr("Salvar arquivo"),"","*.txt");
  109.     QString texto = ui->plainTextEdit->toPlainText();
  110.     //cout<<texto.toStdString(); //Apenas para teste
  111.     FILE * f;
  112.     f = fopen(fileName.toStdString().c_str(),"w+");
  113.     if(f==NULL)
  114.     {
  115.         QMessageBox msgBox;
  116.                  msgBox.setText("Error n 666 you are not doomed \n especifique um caminho ");
  117.                  msgBox.exec();
  118.                  return;
  119.     }
  120.  
  121.     fputs(texto.toStdString().c_str(),f);
  122.     fclose(f);
  123.  
  124.  
  125. }
  126.  
  127. void MainWindow::on_actionQUIT_triggered()
  128. {
  129.     this->close();
  130. }
  131.  
  132.  
  133.  
  134. void MainWindow::on_actionFULLSCREEN_triggered()
  135. {
  136.     if(!this->isFullScreen())
  137.     {
  138.         this->showFullScreen();
  139.         return;
  140.     }
  141.     this->showMaximized();
  142. }
  143.  
  144.  
  145. //**********************************
  146. //**********************************
  147. //********mainwindow.ui************
  148. //**********************************
  149. //**********************************
  150.  
  151.  
  152.  
  153.  
  154. <?xml version="1.0" encoding="UTF-8"?>
  155. <ui version="4.0">
  156.  <class>MainWindow</class>
  157.  <widget class="QMainWindow" name="MainWindow">
  158.   <property name="geometry">
  159.    <rect>
  160.     <x>0</x>
  161.     <y>0</y>
  162.     <width>1008</width>
  163.     <height>798</height>
  164.    </rect>
  165.   </property>
  166.   <property name="windowTitle">
  167.    <string>notepad</string>
  168.   </property>
  169.   <widget class="QWidget" name="centralWidget">
  170.    <layout class="QGridLayout" name="gridLayout">
  171.     <item row="0" column="0">
  172.      <widget class="QPlainTextEdit" name="plainTextEdit"/>
  173.     </item>
  174.    </layout>
  175.   </widget>
  176.   <widget class="QMenuBar" name="menuBar">
  177.    <property name="geometry">
  178.     <rect>
  179.      <x>0</x>
  180.      <y>0</y>
  181.      <width>1008</width>
  182.      <height>21</height>
  183.     </rect>
  184.    </property>
  185.    <widget class="QMenu" name="menuFILE">
  186.     <property name="title">
  187.      <string>FILE</string>
  188.     </property>
  189.     <addaction name="separator"/>
  190.     <addaction name="actionOpen"/>
  191.     <addaction name="separator"/>
  192.     <addaction name="actionSave"/>
  193.     <addaction name="separator"/>
  194.     <addaction name="actionQUIT"/>
  195.     <addaction name="separator"/>
  196.     <addaction name="actionFULLSCREEN"/>
  197.    </widget>
  198.    <addaction name="menuFILE"/>
  199.   </widget>
  200.   <widget class="QToolBar" name="mainToolBar">
  201.    <attribute name="toolBarArea">
  202.     <enum>TopToolBarArea</enum>
  203.    </attribute>
  204.    <attribute name="toolBarBreak">
  205.     <bool>false</bool>
  206.    </attribute>
  207.   </widget>
  208.   <widget class="QStatusBar" name="statusBar"/>
  209.   <action name="actionOpen">
  210.    <property name="text">
  211.     <string>Open</string>
  212.    </property>
  213.    <property name="shortcut">
  214.     <string>Ctrl+O</string>
  215.    </property>
  216.   </action>
  217.   <action name="actionSave">
  218.    <property name="text">
  219.     <string>Save</string>
  220.    </property>
  221.    <property name="shortcut">
  222.     <string>Ctrl+S</string>
  223.    </property>
  224.   </action>
  225.   <action name="actionQUIT">
  226.    <property name="text">
  227.     <string>QUIT</string>
  228.    </property>
  229.    <property name="shortcut">
  230.     <string>Ctrl+Q</string>
  231.    </property>
  232.   </action>
  233.   <action name="actionFULLSCREEN">
  234.    <property name="text">
  235.     <string>FULLSCREEN</string>
  236.    </property>
  237.    <property name="shortcut">
  238.     <string>Ctrl+F</string>
  239.    </property>
  240.   </action>
  241.  </widget>
  242.  <layoutdefault spacing="6" margin="11"/>
  243.  <resources/>
  244.  <connections/>
  245. </ui>
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
Advertisement
Add Comment
Please, Sign In to add comment