Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //**********************************
- //**********************************
- //********mainwindow.h**************
- //**********************************
- //**********************************
- #ifndef MAINWINDOW_H
- #define MAINWINDOW_H
- #include <QMainWindow>
- #include <QFile>
- #include <QFileDialog>
- #include <QString>
- #include <iostream>
- #include <stdio.h>
- #include <cstdlib>
- #include <QMessageBox>
- #include <fstream>
- /**
- * @author Victor Mello Floriano
- */
- //Download 4 windows :
- //Download 4 Linux 32 bits :
- //Donwload 4 Linux 64 bits :
- namespace Ui {
- class MainWindow;
- }
- class MainWindow : public QMainWindow
- {
- Q_OBJECT
- public:
- explicit MainWindow(QWidget *parent = 0);
- ~MainWindow();
- private slots:
- void on_actionOpen_triggered();
- void on_actionSave_triggered();
- void on_actionQUIT_triggered();
- void on_actionFULLSCREEN_triggered();
- private:
- Ui::MainWindow *ui;
- };
- #endif // MAINWINDOW_H
- //**********************************
- //**********************************
- //********mainwindow.cpp************
- //**********************************
- //**********************************
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- using namespace std;
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::on_actionOpen_triggered()
- {
- QString fileName = QFileDialog::getOpenFileName(this,tr("Abrir arquivo"),"","*.txt");
- ifstream f (fileName.toStdString().c_str());
- if(!f.is_open())
- {
- QMessageBox msgBox;
- msgBox.setText("Error n 666 you are not doomed \n especifique um caminho ");
- msgBox.exec();
- return;
- }
- string l;
- QString s;
- QString aux;
- s.clear();
- aux.clear();
- while(f.good())
- {
- getline(f,l);
- //cout<<l<<"\n";
- aux=aux.fromStdString(l);
- //cout<<aux.toStdString()<<"\n";
- s=s+aux+"\n";
- // cout<<s.toStdString()<<"\n";
- }
- ui->plainTextEdit->setPlainText(s);
- }
- void MainWindow::on_actionSave_triggered()
- {
- QString fileName = QFileDialog::getSaveFileName(this,tr("Salvar arquivo"),"","*.txt");
- QString texto = ui->plainTextEdit->toPlainText();
- //cout<<texto.toStdString(); //Apenas para teste
- FILE * f;
- f = fopen(fileName.toStdString().c_str(),"w+");
- if(f==NULL)
- {
- QMessageBox msgBox;
- msgBox.setText("Error n 666 you are not doomed \n especifique um caminho ");
- msgBox.exec();
- return;
- }
- fputs(texto.toStdString().c_str(),f);
- fclose(f);
- }
- void MainWindow::on_actionQUIT_triggered()
- {
- this->close();
- }
- void MainWindow::on_actionFULLSCREEN_triggered()
- {
- if(!this->isFullScreen())
- {
- this->showFullScreen();
- return;
- }
- this->showMaximized();
- }
- //**********************************
- //**********************************
- //********mainwindow.ui************
- //**********************************
- //**********************************
- <?xml version="1.0" encoding="UTF-8"?>
- <ui version="4.0">
- <class>MainWindow</class>
- <widget class="QMainWindow" name="MainWindow">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>1008</width>
- <height>798</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>notepad</string>
- </property>
- <widget class="QWidget" name="centralWidget">
- <layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0">
- <widget class="QPlainTextEdit" name="plainTextEdit"/>
- </item>
- </layout>
- </widget>
- <widget class="QMenuBar" name="menuBar">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>1008</width>
- <height>21</height>
- </rect>
- </property>
- <widget class="QMenu" name="menuFILE">
- <property name="title">
- <string>FILE</string>
- </property>
- <addaction name="separator"/>
- <addaction name="actionOpen"/>
- <addaction name="separator"/>
- <addaction name="actionSave"/>
- <addaction name="separator"/>
- <addaction name="actionQUIT"/>
- <addaction name="separator"/>
- <addaction name="actionFULLSCREEN"/>
- </widget>
- <addaction name="menuFILE"/>
- </widget>
- <widget class="QToolBar" name="mainToolBar">
- <attribute name="toolBarArea">
- <enum>TopToolBarArea</enum>
- </attribute>
- <attribute name="toolBarBreak">
- <bool>false</bool>
- </attribute>
- </widget>
- <widget class="QStatusBar" name="statusBar"/>
- <action name="actionOpen">
- <property name="text">
- <string>Open</string>
- </property>
- <property name="shortcut">
- <string>Ctrl+O</string>
- </property>
- </action>
- <action name="actionSave">
- <property name="text">
- <string>Save</string>
- </property>
- <property name="shortcut">
- <string>Ctrl+S</string>
- </property>
- </action>
- <action name="actionQUIT">
- <property name="text">
- <string>QUIT</string>
- </property>
- <property name="shortcut">
- <string>Ctrl+Q</string>
- </property>
- </action>
- <action name="actionFULLSCREEN">
- <property name="text">
- <string>FULLSCREEN</string>
- </property>
- <property name="shortcut">
- <string>Ctrl+F</string>
- </property>
- </action>
- </widget>
- <layoutdefault spacing="6" margin="11"/>
- <resources/>
- <connections/>
- </ui>
Advertisement
Add Comment
Please, Sign In to add comment