DarthVictor

Untitled

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