First commit
This commit is contained in:
@@ -0,0 +1,239 @@
|
||||
#include "DialogSaveFile.h"
|
||||
#include "ui_dialogsavefile.h"
|
||||
#include <QDir>
|
||||
#include <QStringListModel>
|
||||
#include <SysPara.h>
|
||||
#include <QAbstractItemView>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QMessageBox>
|
||||
#include <Public.h>
|
||||
#include<QStandardItemModel>
|
||||
#include"HtmlDelegate.h"
|
||||
#include <QTextCodec>
|
||||
#include <QByteArray>
|
||||
#include <QDebug>
|
||||
|
||||
DialogSaveFile::DialogSaveFile(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::DialogSaveFile)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->setWindowTitle(tr("保存"));
|
||||
ui->textEditView->setReadOnly(true);
|
||||
ui->textEditView->setLineWrapMode(QTextEdit::NoWrap);
|
||||
ui->textEditView->document()->setDocumentMargin(0);
|
||||
this->setFixedSize(this->geometry().width(),this->geometry().height());
|
||||
EditMode=4;
|
||||
#ifdef EnableArabic
|
||||
setFileNameFlag=false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void DialogSaveFile::refreshListView(int mode){
|
||||
|
||||
QString dirPath = ui->radioButtonLocal->isChecked()?DOC_ROOT_DIR:UDISK_DOC_ROOT_DIR;
|
||||
QDir dir(dirPath);
|
||||
QStringList filters;
|
||||
EditMode = mode;
|
||||
if(mode == TXTFILE) filters << "*.html" << "*.txt" << "*.TXT" << "*.jpeg" << "*.gif" << "*.jpg" << "*.bmp"<< "*.BMP"; // txtmode
|
||||
else if(mode == PICFILE) filters << "*.png";// <<"*.jpg" ; // picmode
|
||||
else if(mode == SCENE) filters << "*.xml";// scene mode
|
||||
else filters << "*.html" << "*.bmp" << "*.BMP" <<"*.jpg"<<"*.gif";
|
||||
dir.setNameFilters(filters);
|
||||
dir.setFilter(QDir::Files);
|
||||
#ifndef EnableArabic
|
||||
QStringListModel *model = new QStringListModel(dir.entryList());
|
||||
#else
|
||||
QStringList entries=dir.entryList();
|
||||
QStandardItemModel *model = new QStandardItemModel();
|
||||
for(int i=0;i<entries.size();i++){
|
||||
QStandardItem *item1 = new QStandardItem(entries.at(i));
|
||||
int lastIndex=entries.at(i).lastIndexOf(".");
|
||||
if(lastIndex != -1){
|
||||
int secondLastIndex = entries.at(i).lastIndexOf(".",lastIndex-1);
|
||||
if(secondLastIndex != -1){
|
||||
QString subsuffix=entries.at(i).mid(secondLastIndex);
|
||||
if(subsuffix.contains(".a.")){
|
||||
QString subsuffix2=entries.at(i).mid(lastIndex);
|
||||
QString subname=entries.at(i).mid(0,secondLastIndex);
|
||||
QString stringhtml=QString("<span style=font-family:'biyangarabic';>%1</span><span style=font-family:'biyang';>%2</span>").arg(subname).arg(subsuffix2);
|
||||
QStandardItem *item2 = new QStandardItem(stringhtml);
|
||||
model->appendRow(item2);
|
||||
}
|
||||
}else{
|
||||
model->appendRow(item1);
|
||||
}
|
||||
}
|
||||
}
|
||||
ui->listViewFile->setItemDelegate(new HtmlDelegate);
|
||||
#endif
|
||||
|
||||
ui->listViewFile->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
ui->listViewFile->setModel(model); //useList是个QListView
|
||||
int count = ui->listViewFile->model()->rowCount();
|
||||
if(count){
|
||||
QModelIndex index = ui->listViewFile->model()->index(0 , 0);
|
||||
ui->listViewFile->setCurrentIndex(index);
|
||||
on_listViewFile_entered(index);
|
||||
}
|
||||
|
||||
#ifdef EnableArabic
|
||||
QFont font;
|
||||
if(!setFileNameFlag){
|
||||
font.setFamily("biyang");
|
||||
ui->lineEdit->setFont(font);
|
||||
}else {
|
||||
font.setFamily("biyangarabic");
|
||||
ui->lineEdit->setFont(font);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
DialogSaveFile::~DialogSaveFile()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void DialogSaveFile::on_listViewFile_entered(const QModelIndex &index)
|
||||
{
|
||||
#ifdef EnableArabic
|
||||
QFont font;
|
||||
QString fileName=index.data().toString();
|
||||
if(fileName.endsWith("</span>")){
|
||||
QTextDocument doc;
|
||||
doc.setHtml(fileName);
|
||||
fileName= doc.toPlainText();
|
||||
font.setFamily("biyangarabic");
|
||||
ui->lineEdit->setFont(font);
|
||||
ui->lineEdit->setText(QString(QFileInfo(fileName).baseName()));
|
||||
int position = fileName.lastIndexOf(".");
|
||||
fileName.insert(position,".a");
|
||||
}else{
|
||||
font.setFamily("biyang");
|
||||
ui->lineEdit->setFont(font);
|
||||
ui->lineEdit->setText( QFileInfo(fileName).baseName() );
|
||||
}
|
||||
#endif
|
||||
|
||||
QString dirPath = ui->radioButtonLocal->isChecked()?DOC_ROOT_DIR:UDISK_DOC_ROOT_DIR;
|
||||
#ifndef EnableArabic
|
||||
QString filePath = dirPath + index.data().toString();
|
||||
#else
|
||||
QString filePath = dirPath + fileName;
|
||||
#endif
|
||||
if(filePath.endsWith(".gif") || filePath.endsWith(".jpeg") || filePath.endsWith(".jpg") ||
|
||||
filePath.endsWith(".png") || filePath.endsWith(".bmp")|| filePath.endsWith(".BMP")|| filePath.endsWith(".nda")){
|
||||
ui->textEditView->clear();
|
||||
ui->textEditView->setHtml(QString("<img src='%1'/>").arg(filePath));
|
||||
}
|
||||
else {
|
||||
QFile file(filePath);
|
||||
if (!file.open(QFile::ReadOnly))
|
||||
return ;
|
||||
QByteArray data = file.readAll();
|
||||
QTextCodec *codec = Qt::codecForHtml(data);
|
||||
QString str = codec->toUnicode(data);
|
||||
if (Qt::mightBeRichText(str)) {
|
||||
if(!ui->radioButtonLocal->isChecked())
|
||||
str.replace(DOC_ROOT_DIR,UDISK_DOC_ROOT_DIR); //必须替换相应的路径
|
||||
ui->textEditView->setHtml(str);
|
||||
} else {
|
||||
str = QString::fromLocal8Bit(data);
|
||||
ui->textEditView->setPlainText(str);
|
||||
}
|
||||
}
|
||||
#ifndef EnableArabic
|
||||
ui->lineEdit->setText( QFileInfo(ui->listViewFile->currentIndex().data().toString()).baseName() );
|
||||
#endif
|
||||
}
|
||||
void DialogSaveFile::on_listViewFile_clicked(const QModelIndex &index)
|
||||
{
|
||||
on_listViewFile_entered(index);
|
||||
}
|
||||
|
||||
void DialogSaveFile::on_pushButtonNext_pressed()
|
||||
{
|
||||
QModelIndex currIndex = ui->listViewFile->currentIndex();
|
||||
int count = ui->listViewFile->model()->rowCount();
|
||||
if(count){
|
||||
QModelIndex index = ui->listViewFile->model()->index((currIndex.row() + 1)%count, 0);
|
||||
ui->listViewFile->setCurrentIndex(index);
|
||||
on_listViewFile_entered(index);
|
||||
}
|
||||
ui->lineEdit->setText(QFileInfo(ui->listViewFile->currentIndex().data().toString()).baseName());
|
||||
}
|
||||
|
||||
void DialogSaveFile::on_pushButtonLast_pressed()
|
||||
{
|
||||
QModelIndex currIndex = ui->listViewFile->currentIndex();
|
||||
int count = ui->listViewFile->model()->rowCount();
|
||||
if(count){
|
||||
QModelIndex index = ui->listViewFile->model()->index(currIndex.row() == 0?(count - 1):(currIndex.row() - 1), 0);
|
||||
ui->listViewFile->setCurrentIndex(index);
|
||||
on_listViewFile_entered(index);
|
||||
}
|
||||
ui->lineEdit->setText(QFileInfo(ui->listViewFile->currentIndex().data().toString()).baseName());
|
||||
}
|
||||
|
||||
void DialogSaveFile::on_pushButtonExit_pressed()
|
||||
{
|
||||
hide();
|
||||
}
|
||||
//void DialogSaveFile::on_lostfocuse_pressed()
|
||||
//{
|
||||
// hide();
|
||||
//}
|
||||
void DialogSaveFile::on_pushButtonSave_clicked()
|
||||
{
|
||||
QModelIndex index = ui->listViewFile->currentIndex();
|
||||
QString dirPath = ui->radioButtonLocal->isChecked()?DOC_ROOT_DIR:UDISK_DOC_ROOT_DIR;
|
||||
//QString filePath = dirPath + index.data().toString();
|
||||
QString filePath = dirPath + ui->lineEdit->text();// index.data().toString();
|
||||
#ifdef EnableArabic
|
||||
if(setFileNameFlag){
|
||||
filePath = dirPath + ui->lineEdit->text()+".a";
|
||||
}
|
||||
#endif
|
||||
emit saveFile(filePath,false);
|
||||
hide();
|
||||
}
|
||||
|
||||
void DialogSaveFile::on_radioButtonLocal_released()
|
||||
{
|
||||
refreshListView(EditMode);
|
||||
}
|
||||
|
||||
void DialogSaveFile::on_radioButtonUdisk_released()
|
||||
{
|
||||
|
||||
QDir dir(UDISK_DOC_ROOT_DIR);
|
||||
if(!dir.exists()){
|
||||
QMessageBox::warning(0,tr("警告"),tr("U盘未插入或U盘根目录下的doc文件夹不存在!"));
|
||||
}
|
||||
refreshListView(EditMode);
|
||||
}
|
||||
void DialogSaveFile::setEnterFileName(QString strFile)
|
||||
{
|
||||
ui->lineEdit->setText(strFile);
|
||||
//ui->lineEdit->setFocus();
|
||||
}
|
||||
void DialogSaveFile::setTitleTxt(QString str)
|
||||
{
|
||||
setWindowTitle(str);
|
||||
}
|
||||
|
||||
#ifdef EnableArabic
|
||||
void DialogSaveFile::setFileNameEnglishOrArabic(bool flag){
|
||||
QFont font;
|
||||
setFileNameFlag=flag;
|
||||
//qDebug()<<"setFileNameFlag :"<<flag;
|
||||
if(flag){
|
||||
font.setFamily("biyangarabic");
|
||||
}else {
|
||||
font.setFamily("biyang");
|
||||
}
|
||||
ui->lineEdit->setFont(font);
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user