Rev 201 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| Download
| RSS feed
#include "fileform.h"
#include "ui_fileform.h"
#include "mainwindow.h"
FileForm::FileForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::FileForm)
{
ui->setupUi(this);
FileForm::fdataIsChanged = false;
}
FileForm::~FileForm()
{
delete ui;
}
void FileForm::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void FileForm::on_pushButton_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Îòêðûòü ôàéë"
QString fileName;
QFile file;
QByteArray data_tmp;
fileName = QFileDialog::getOpenFileName(this,
tr("Open Image"), "", tr("All Files (*.*);;Image Files (*.png *.jpg *.bmp);;Text files (*.txt);;XML files (*.xml)")); //Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)
if (fileName.isEmpty()) return;
file.setFileName(fileName);
if (!file.open(QIODevice::ReadOnly)) return;
Data.clear();
// Data = file.readAll();
QDataStream out(&Data,QIODevice::ReadWrite);
out << fileName;
data_tmp = file.readAll();
out << data_tmp;
file.close();
FileForm::fdataIsChanged = true;
}
void FileForm::on_pushButton_2_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü ôàéë"
Data.clear();
FileForm::fdataIsChanged = true;
}
void FileForm::on_pushButton_3_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Ñîõðàíèòü ôàéë"
QByteArray data_tmp;
QFile file;
QDataStream out(&Data,QIODevice::ReadOnly);
QString fileName;
// QString fileName_tmp;
if (Data.isEmpty()) return;
out.device()->reset();
out >> fileName;
fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
fileName,
tr("All Files (*.*);;Image Files (*.png *.jpg *.bmp);;Text files (*.txt);;XML files (*.xml)"));
if (fileName.isEmpty()) return;
file.setFileName(fileName);
if (!file.open(QIODevice::WriteOnly)) return;
// Data = file.readAll();
// out.device()->reset();
data_tmp.clear();
out >> data_tmp;
int count;
count = file.write(data_tmp);
int size;
size = file.size();
file.close();
FileForm::fdataIsChanged = true;
}
void FileForm::setData(QByteArray new_data){
int i;
Data = new_data;
i++;
}