diff --git a/abstractdata.cpp b/abstractdata.cpp index c3ff721..0ff20a9 100644 --- a/abstractdata.cpp +++ b/abstractdata.cpp @@ -314,7 +314,7 @@ void AbstractData::parseData() { } void AbstractData::parseData(QDataStream& in) { - qDebug()<<"AbstractData::parseData(DS)"; + qDebug()<<"AbstractData::parseData(DataStream)"; in.setByteOrder(QDataStream::LittleEndian); qint8 c; @@ -322,7 +322,6 @@ void AbstractData::parseData(QDataStream& in) { uint length; length=16; - qDebug()<<"Parsing Matrix"; in.startTransaction(); while(!in.atEnd()) { in>>c; @@ -905,7 +904,7 @@ void Program::setProg(QString data_in) { void Program::parseData() { - QTextCodec * codec = QTextCodec::codecForName("UTF8"); + QTextCodec * codec = QTextCodec::codecForName("ISO 8859-1"); QByteArray a1; a1=getData(); text = codec->toUnicode(a1); @@ -915,7 +914,7 @@ void Program::parseData() { void Program::parseData(QDataStream& in) { - QTextCodec * codec = QTextCodec::codecForName("UTF-16"); + QTextCodec * codec = QTextCodec::codecForName("ISO 8859-1"); QByteArrayMatcher matcher; QByteArray search; QByteArray phrase; @@ -1008,7 +1007,7 @@ void Notes::parseData() { // quint16 len1,len2; int formatstart; - QTextCodec * codec = QTextCodec::codecForName("UTF-16LE"); + QTextCodec * codec = QTextCodec::codecForName("UTF-8"); QByteArray a1,a3; diff --git a/cntfilesystemmodel.cpp b/cntfilesystemmodel.cpp index 35c01ec..ec66811 100644 --- a/cntfilesystemmodel.cpp +++ b/cntfilesystemmodel.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -83,6 +84,8 @@ QMimeData* contentFileSystemModel::mimeData(const QModelIndexList &indexes) cons qDebug()<<"contentFileSystemModel::mimeData"; + foreach(index,indexes) { + index=indexes.first(); // qDebug()<setText(info.baseName()); + switch (filedata.type) { case HP_PROG: @@ -130,6 +134,20 @@ QMimeData* contentFileSystemModel::mimeData(const QModelIndexList &indexes) cons } file.close(); + } + + //Allow copy to external file managers + QList urls; + QFileInfo info; + QUrl url; + foreach(index,indexes) { + info = contentFileSystemModel::fileInfo(index); + + url = QUrl::fromLocalFile(info.absoluteFilePath()); + + urls.append(url); + } + mimeDataPtr->setUrls(urls); return mimeDataPtr; } @@ -154,7 +172,18 @@ Qt::ItemFlags contentFileSystemModel::flags(const QModelIndex &index) const //Allow drop in location bool contentFileSystemModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const { - return true; + + qDebug()<formats(); + + if (data->hasUrls()) { + return true; + } + + if (data->hasText()) { + return true; + } + + return false; } //Process the drop action @@ -184,6 +213,29 @@ bool contentFileSystemModel::dropMimeData(const QMimeData* md_data, Qt::DropActi return true; } + //Check for external file drop + if (md_data->hasUrls()) { + + QString name = md_data->text(); + QList urls = md_data->urls(); + QUrl url; + QString filefrom; + QString fileto; + + foreach(url,urls) { + filefrom=url.toLocalFile(); + QFileInfo fileinfo(filefrom); + fileto=path+"/"+url.fileName(); + if(isFileType(fileinfo)) { + //consider check to limit unusual file types + QFile::copy(filefrom,fileto); + } + } + + return true; + } + + //rework QByteArray data_in; QByteArray typeary; QString name = md_data->text(); @@ -198,7 +250,6 @@ bool contentFileSystemModel::dropMimeData(const QMimeData* md_data, Qt::DropActi qDebug()<-1) @@ -305,6 +356,8 @@ AbstractData * contentFileSystemModel::readFile(QFileInfo fileinfo) const { if (file.open(QIODevice::ReadOnly),QFileDevice::AutoCloseHandle) { QDataStream in(&file); +// QTextCodec *codec = QTextCodec::codecForName("UTF-16"); +// in.setCodec(codec); in.setByteOrder(QDataStream::LittleEndian); filedata=getFileType(fileinfo); @@ -317,6 +370,12 @@ AbstractData * contentFileSystemModel::readFile(QFileInfo fileinfo) const { data->parseData(in); } break; + case HP_NOTE: { + qDebug()<<"HP_NOTE"; + data = new Notes(filedata.filename, HP_NOTE, QStringLiteral("")); + data->parseData(in); + } + break; default: ; } @@ -332,10 +391,10 @@ int contentFileSystemModel::writeFile(QFileInfo fileinfo, QByteArray data_in) co QFile file(fileinfo.absoluteFilePath()); if (file.open(QIODevice::ReadWrite)) { - QTextStream out(&file); - QTextCodec *codec = QTextCodec::codecForName("UTF-16"); - out.setCodec(codec); -// out.setByteOrder(QDataStream::LittleEndian); + QDataStream out(&file); +// QTextCodec *codec = QTextCodec::codecForName("UTF-8"); +// out.setCodec(codec); + out.setByteOrder(QDataStream::LittleEndian); // quint8 c; // for (int i =0 ;i< data_in.length();i++) @@ -384,36 +443,26 @@ bool contentFileSystemModel::createNewProgram(QMdiArea * mdiwin, QString filenam QDir dir(path); QFileInfo fileinfo(dir,filename+"."+getFileType(HP_PROG)); - /* - QFile file(fileinfo.absoluteFilePath()); - - if (file.open(QIODevice::WriteOnly)) { - - QTextStream out(&file); - out << "" << endl; - } else { - qWarning()< #include #include +#include +#include +#include //Called by the calculator Window hp_mdiTextEdit::hp_mdiTextEdit(QWidget * parent,hpTreeItem * treeItem, AbstractData * calcData) @@ -28,7 +31,7 @@ hp_mdiTextEdit::hp_mdiTextEdit(QWidget * parent,hpTreeItem * treeItem, AbstractD { setMinimumSize(200,200); setMaximumSize(1000,1000); - setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored); + setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); qDebug()<<"hp_mdiTextEdit::hp_mdiTextEdit 1"; hptreeitem=treeItem; @@ -51,7 +54,7 @@ hp_mdiTextEdit::hp_mdiTextEdit(QWidget * parent, QFileInfo filedata, AbstractDat qDebug()<<"hp_mdiTextEdit::hp_mdiTextEdit 2"; setMinimumSize(200,200); setMaximumSize(1000,1000); - setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored); + // setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); calculator=QStringLiteral("Content: "); content=true; hptreeitem=nullptr; @@ -61,6 +64,7 @@ hp_mdiTextEdit::hp_mdiTextEdit(QWidget * parent, QFileInfo filedata, AbstractDat type=calcData->getType(); setup(); setWindowTitle(calculator+filename); + resize(450,350); } void hp_mdiTextEdit::setup() { @@ -92,7 +96,41 @@ void hp_mdiTextEdit::setup() { else { qDebug()<<"hp_mdiTextEdit::setup - Data Null"; } - setWidget(textEdit); + + QIcon save(":/icons/save_22x22.png"); + QAction * actionSave= new QAction(save,"Save",this); + + QWidget * top = new QWidget(); + QBoxLayout * layout = new QVBoxLayout(); + layout->setContentsMargins(0, 0, 0, 0); + layout->setSpacing(0); + top->setLayout(layout); + + QToolBar * toolbar = new QToolBar("Save"); + toolbar->addAction(actionSave); + + QToolButton *saveButton=new QToolButton(); + QMenu * menu = new QMenu(saveButton); + menu->addAction(actionSave); + layout->setMenuBar(menu); +// layout->addWidget(toolbar); +// QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Expanding); +// sizePolicy1.setHorizontalStretch(0); +// sizePolicy1.setVerticalStretch(0); +// sizePolicy1.setHeightForWidth(textEdit->sizePolicy().hasHeightForWidth()); +// textEdit->setSizePolicy(sizePolicy1); +// layout->setSizeConstraint(QLayout::SetNoConstraint); + + layout->addWidget(textEdit); + setWidget(top); + + connect(actionSave,SIGNAL(triggered()),this,SLOT(eventSave())); + + return; +} + +void hp_mdiTextEdit::eventSave(){ + save(); } bool hp_mdiTextEdit::save(){ @@ -147,7 +185,6 @@ bool hp_mdiTextEdit::maybeSave() return true; } - void hp_mdiTextEdit::show() { if (textEdit) diff --git a/hp_mdiwindow.cpp b/hp_mdiwindow.cpp index f77bc82..ecdb46f 100644 --- a/hp_mdiwindow.cpp +++ b/hp_mdiwindow.cpp @@ -17,6 +17,10 @@ #include "hp_mdiwindow.h" #include +#include +#include +#include +#include hp_MdiWindow::hp_MdiWindow(QWidget * parent) :QMdiSubWindow(parent) @@ -32,6 +36,10 @@ void hp_MdiWindow::setup() { } +void hp_MdiWindow::eventSave() { + qDebug()<<"Save pressed"; +} + bool hp_MdiWindow::save() { qDebug()<<"hp_MdiWindow::save"; diff --git a/hp_mdiwindow.ui b/hp_mdiwindow.ui index 7fdd0e3..a3a7916 100644 --- a/hp_mdiwindow.ui +++ b/hp_mdiwindow.ui @@ -29,7 +29,30 @@ + + + toolBar + + + TopToolBarArea + + + false + + + + + + + :/icons/save_22x22.png:/icons/save_22x22.png + + + Save + + - + + + diff --git a/include/cntfilesystemmodel.h b/include/cntfilesystemmodel.h index 94a6750..8693bc2 100644 --- a/include/cntfilesystemmodel.h +++ b/include/cntfilesystemmodel.h @@ -44,6 +44,7 @@ public: void deleteFile(QModelIndex &index); void renameFile(QModelIndex &index, QString newName); hp_DataStruct getFileType(QFileInfo info) const; + bool isFileType(QFileInfo info) const; QString getFileType(hp_DataType) const; AbstractData * readFile(QFileInfo fileinfo) const; int writeFile(QFileInfo fileinfo, QByteArray data_in) const; diff --git a/include/hp_mditexteditor.h b/include/hp_mditexteditor.h index d4bed36..24a695e 100644 --- a/include/hp_mditexteditor.h +++ b/include/hp_mditexteditor.h @@ -62,6 +62,7 @@ public: signals: public slots: + void eventSave(); }; diff --git a/include/hp_mdiwindow.h b/include/hp_mdiwindow.h index 7740ece..958f9f9 100644 --- a/include/hp_mdiwindow.h +++ b/include/hp_mdiwindow.h @@ -39,6 +39,9 @@ public: void show(); ~hp_MdiWindow(); +private slots: + void eventSave(); + }; #endif // HP_MDIWINDOW_H diff --git a/texteditor.cpp b/texteditor.cpp index 2ccf4ef..a18dddb 100644 --- a/texteditor.cpp +++ b/texteditor.cpp @@ -27,7 +27,7 @@ textEditor::textEditor(QWidget *parent) : QSettings appSettings("IRGP","QtHPconnect"); wParent = parent; setAttribute(Qt::WA_DeleteOnClose); - setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); +// setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); isUntitled = true; defaultPath=QDir(appSettings.value("contentPath").toString());