834 lines
36 KiB
Plaintext
834 lines
36 KiB
Plaintext
#include "SceneEditOption.h"
|
||
#include "pictextitem.h"
|
||
#include "ui_sceneEditOption.h"
|
||
#include <QDir>
|
||
#include <QStringListModel>
|
||
#include <SysPara.h>
|
||
#include <QAbstractItemView>
|
||
#include <QFile>
|
||
#include <QTextStream>
|
||
#include <QMessageBox>
|
||
#include <Public.h>
|
||
|
||
#include <QTextCodec>
|
||
#include <QByteArray>
|
||
#include <QDebug>
|
||
#include <QXmlStreamWriter>
|
||
#include <QLabel>
|
||
|
||
#include "myview.h"
|
||
#include "LogInfo.h"
|
||
#include <QTextBlockFormat>
|
||
#include <QTextBlock>
|
||
#include <QPalette>
|
||
|
||
MoveInput* moveInput;
|
||
SceneEditOption::SceneEditOption(QWidget *parent) :
|
||
QWidget(parent),
|
||
ui(new Ui::SceneEditOption),newScene(0)
|
||
{
|
||
ui->setupUi(this);
|
||
editMode = SCENE;
|
||
xmlfileName = "";
|
||
dialogFileOperation = new DialogFileOperation(0);
|
||
#ifdef MYSAVEFILEDLG
|
||
dialogSaveFile =new DialogSaveFile(0);
|
||
//connect(dialogSaveFile,SIGNAL(saveFile(QString,bool)),this,SLOT(onSaveASFile(QString,bool)));
|
||
#endif
|
||
m_CreateImageFlag = false;
|
||
m_pSavePicScene = new QGraphicsScene();
|
||
m_pSavePicScene->setSceneRect(QRectF(0, 0, 3200, MAX_PRINT_ROW_NUM)); //生成图片的场景
|
||
moveInput = new MoveInput(parent);
|
||
}
|
||
|
||
SceneEditOption::~SceneEditOption()
|
||
{
|
||
if(m_pSavePicScene)
|
||
{
|
||
delete m_pSavePicScene;
|
||
}
|
||
if(moveInput)
|
||
{
|
||
delete moveInput;
|
||
}
|
||
}
|
||
|
||
void SceneEditOption::bindStackWidget(QStackedWidget *stackedWidgetOption,QStackedWidget *stackedWidgetText){
|
||
this->stackedWidgetOption = stackedWidgetOption;// stackedWidgetOption
|
||
this->stackedWidgetText = stackedWidgetText;
|
||
connect(this->stackedWidgetOption,SIGNAL(currentChanged(int)),this,SLOT(onStackedWidgetOptionCurrentChanged(int)));
|
||
}
|
||
|
||
void SceneEditOption::bindSysPara(SysPara *sysPara){
|
||
this->sysPara = sysPara;
|
||
}
|
||
void SceneEditOption::enableButtonSave(){
|
||
if(!ui->saveButton->isEnabled())
|
||
ui->saveButton->setEnabled(true);
|
||
}
|
||
void SceneEditOption::onStackedWidgetOptionCurrentChanged(int index)
|
||
{
|
||
const QString objectName=this->stackedWidgetOption->currentWidget()->objectName();
|
||
// const QString objectName=this->stackedWidgetOption->widget(index)->objectName();
|
||
qDebug()<<"index="<<index<<", objectName="<<objectName;
|
||
if(newScene)
|
||
{
|
||
if("senceEditOption"==objectName && SCENE==sysPara->para.EditMode)
|
||
{
|
||
// qDebug()<<"显示新场景--open";
|
||
this->pPicScene->setIsdrawBackground(true);
|
||
this->stackedWidgetOption->hide();
|
||
// //show_scene_new_dlg();
|
||
// foreach (QLayout *lay, listQLayout) {
|
||
// newScene->showQLayout(lay,false);
|
||
// }
|
||
newScene->Layout_ToNew();
|
||
newScene->show();
|
||
}
|
||
else
|
||
{
|
||
// qDebug()<<"隐藏新场景--hide";
|
||
this->pPicScene->setIsdrawBackground(false);
|
||
this->stackedWidgetOption->setVisible(true);
|
||
newScene->hide();
|
||
newScene->Layout_ToDefault();
|
||
// foreach (QLayout *lay, listQLayout) {
|
||
// newScene->showQLayout(lay,true);
|
||
// }
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
}
|
||
}
|
||
|
||
void SceneEditOption::bindScene(PicScene *pPicScene, QGraphicsView *pGraphicViewer,QTextEdit *pTextEdit){
|
||
this->pPicScene = pPicScene;
|
||
this->pViewer = pGraphicViewer;
|
||
this->textEdit = pTextEdit;
|
||
//connect(pPicScene,SIGNAL(xmlContentChanged ()),this,SLOT(enableButtonSave()));
|
||
connect(pPicScene,SIGNAL(selectionChanged()),this,SLOT(enableButtonSave()));
|
||
|
||
ui->saveButton->setEnabled(false);
|
||
connect(dialogFileOperation,SIGNAL(openFile(QString,bool)),this,SLOT(onFileOpen(QString,bool)));
|
||
connect(dialogFileOperation,SIGNAL(createSceneImage(QString)),this,SLOT(onCreateSceneImage(QString)));
|
||
#ifdef MYSAVEFILEDLG
|
||
connect(dialogSaveFile,SIGNAL(saveFile(QString,bool)),this,SLOT(onSaveASFile(QString,bool)));
|
||
#endif
|
||
//edit@12-06 显示网格线
|
||
this->pPicScene->setIsdrawBackground(true);
|
||
}
|
||
|
||
void SceneEditOption::show_scene_new_dlg()
|
||
{
|
||
QWidget *tabMainWindow=this->parentWidget()->parentWidget();
|
||
|
||
if(!newScene)
|
||
{
|
||
this->stackedWidgetOption->hide();
|
||
newScene=new FormScenedlg(tabMainWindow);
|
||
newScene->setObjectName("newScene");
|
||
|
||
newScene->setAutoFillBackground(true);
|
||
newScene->setPalette(tabMainWindow->palette());
|
||
|
||
newScene->bindScene(this->pPicScene,this->pViewer,this->textEdit);
|
||
//edit@12-07另一种信号通信
|
||
connect(newScene,SIGNAL(delButton()),this,SLOT(on_delButton_pressed()));
|
||
connect(newScene,SIGNAL(saveButton()),this,SLOT(on_saveButton_pressed()));
|
||
connect(newScene,SIGNAL(openfileButton()),this,SLOT(on_openfileButton_pressed()));
|
||
connect(newScene,SIGNAL(previewButton()),this,SLOT(on_previewButton_pressed()));
|
||
//connect(newScene,SIGNAL(previewButton()),this,SIGNAL(previewScene()));
|
||
|
||
connect(newScene,SIGNAL(addButton()),this,SLOT(on_addButton_pressed()));
|
||
connect(newScene,SIGNAL(EditItemButton()),this,SLOT(on_EditItemButton_pressed()));
|
||
connect(newScene,SIGNAL(saveAsButton()),this,SLOT(on_saveAsButton_pressed()));
|
||
connect(newScene,SIGNAL(newfileButton()),this,SLOT(on_newfileButton_pressed()));
|
||
connect(newScene,SIGNAL(enlargeButton()),this,SLOT(on_enlargeButton_pressed()));
|
||
connect(newScene,SIGNAL(reduceButton()),this,SLOT(on_reduceButton_pressed()));
|
||
connect(newScene,SIGNAL(ZoomOrigin()),this,SLOT(on_test_pressed()));
|
||
connect(newScene,SIGNAL(btn_test2()),this,SLOT(on_btn_test2()));
|
||
connect(this->pPicScene,SIGNAL(showTextWidthHeight()),newScene,SLOT(reset_showTextWidthHeight()));
|
||
//connect(this->pPicScene,SIGNAL(adjustItemsPos()),newScene,SLOT(adjustItemsPosFalse()));
|
||
|
||
newScene->move(0,270);
|
||
newScene->Layout_ToNew();
|
||
}
|
||
}
|
||
|
||
void SceneEditOption::on_previewButton_pressed()
|
||
{
|
||
this->pPicScene->setIsdrawBackground(false);
|
||
emit previewScene();
|
||
}
|
||
|
||
|
||
void SceneEditOption::on_addButton_pressed()
|
||
{
|
||
pPicScene->clearSelection();
|
||
#if 0
|
||
emit addPicTextItem();
|
||
#else
|
||
textItem = new PicTextItem();
|
||
//textItem->setFont(myFont);
|
||
//textItem->setTextInteractionFlags(Qt::TextEditorInteraction);
|
||
pPicScene->addItem(textItem);
|
||
//textItem->setDefaultTextColor(myTextColor);
|
||
//QFont font = textItem->font();
|
||
//font.setLetterSpacing(QFont::AbsoluteSpacing,sysPara->para.textEditCharSpace);
|
||
//textItem->setFont(font);
|
||
|
||
QList<QGraphicsItem *> items = pPicScene->items();
|
||
if(pPicScene->items().count()>1){
|
||
QRectF itemRect= items.at(1)->boundingRect();
|
||
textItem->setPos( items.at(1)->scenePos().x()+itemRect.width()+20, items.at(1)->scenePos().y());
|
||
}
|
||
//else textItem->setPos(0,0);
|
||
else textItem->setPos(this->pViewer->mapToScene(0,0));//edit@12-07
|
||
|
||
textItem->setPlainText("Vernon Bach Printer");
|
||
ui->saveButton->setEnabled(true);
|
||
//qDebug()<<"sysPara->para.textEditCharSpace:"<<sysPara->para.textEditCharSpace;
|
||
|
||
//edit@12-12 新的打开方式直接进入编辑模式
|
||
textItem->setPlainText("");
|
||
textItem->setSelected(true);
|
||
on_EditItemButton_pressed();
|
||
#endif
|
||
}
|
||
bool SceneEditOption::maybeSave(){
|
||
|
||
if (xmlfileName.startsWith(QLatin1String(":/")))
|
||
return true;
|
||
|
||
QMessageBox msgBox(QMessageBox::Information,tr("提示"),tr("文档已经改变,是否保存?"));
|
||
QPushButton *saveButton = msgBox.addButton(tr("保存"), QMessageBox::ActionRole);
|
||
QPushButton *cancleSaveButton = msgBox.addButton(tr("放弃保存"), QMessageBox::ActionRole);
|
||
QPushButton *abortButton = msgBox.addButton(QMessageBox::Cancel);
|
||
|
||
msgBox.exec();
|
||
|
||
if (msgBox.clickedButton() == saveButton) {
|
||
on_saveButton_pressed();
|
||
return false;
|
||
} else if (msgBox.clickedButton() == cancleSaveButton) {
|
||
return true;
|
||
}
|
||
else
|
||
return false;
|
||
|
||
return true;
|
||
}
|
||
void SceneEditOption::on_newfileButton_pressed()
|
||
{
|
||
if (maybeSave()) {
|
||
pPicScene->clear();
|
||
pViewer->viewport()->update();
|
||
unsigned char SpecialVarEnable = 0;
|
||
sysPara->devOp->fpgaWr(0xa4b0,(unsigned char *)&SpecialVarEnable,1);
|
||
xmlfileName = "";
|
||
QFile file(xmlfileName);
|
||
emit fileNameChanged(QFileInfo(xmlfileName).fileName());
|
||
}
|
||
#ifdef VARCOLOR
|
||
textEdit->insertHtml(QString("<span style='background:#ffffff;color=#000000;'> <span />"));
|
||
#endif
|
||
}
|
||
void SceneEditOption::on_delButton_pressed()
|
||
{
|
||
#if 0
|
||
|
||
#else
|
||
foreach (QGraphicsItem *item, pPicScene->selectedItems()) {
|
||
pPicScene->removeItem(item);
|
||
delete item;
|
||
ui->saveButton->setEnabled(true);
|
||
}
|
||
#endif
|
||
}
|
||
void SceneEditOption::on_saveAsButton_pressed()
|
||
{
|
||
pPicScene->clearSelection();
|
||
#ifdef MYSAVEFILEDLG
|
||
disconnect(dialogSaveFile,SIGNAL(saveFile(QString,bool)),0,0);
|
||
connect(dialogSaveFile,SIGNAL(saveFile(QString,bool)),this,SLOT(onSaveASFile(QString,bool)));
|
||
dialogSaveFile->refreshListView(editMode);
|
||
dialogSaveFile->show();
|
||
dialogSaveFile->setEnterFileName("");
|
||
#endif
|
||
}
|
||
void SceneEditOption::on_saveButton_pressed()
|
||
{
|
||
pPicScene->clearSelection();
|
||
#if 0
|
||
|
||
#else
|
||
if(xmlfileName.isEmpty())
|
||
{
|
||
qDebug()<<"xml file null";
|
||
#ifdef MYSAVEFILEDLG
|
||
disconnect(dialogSaveFile,SIGNAL(saveFile(QString,bool)),0,0);
|
||
connect(dialogSaveFile,SIGNAL(saveFile(QString,bool)),this,SLOT(onSaveASFile(QString,bool)));
|
||
dialogSaveFile->refreshListView(editMode);
|
||
dialogSaveFile->show();
|
||
dialogSaveFile->setEnterFileName("");
|
||
|
||
#endif
|
||
}
|
||
else
|
||
{
|
||
pPicScene->update();
|
||
saveFile();
|
||
if(sysPara){
|
||
sysPara->sysFile =xmlfileName;
|
||
snprintf(sysPara->para.lastOpenedFileName,sizeof(sysPara->para.lastOpenedFileName),"%s",xmlfileName.toAscii().constData());
|
||
}
|
||
//snprintf(sysPara->para.lastOpenedFileName,sizeof(sysPara->para.lastOpenedFileName),"%s",xmlfileName.toAscii().constData());
|
||
ui->saveButton->setEnabled(false);
|
||
emit fileNameChanged(QFileInfo(xmlfileName).fileName());
|
||
}
|
||
#endif
|
||
}
|
||
void SceneEditOption::on_openfileButton_pressed()
|
||
{
|
||
pPicScene->clearSelection();
|
||
#if 0
|
||
}
|
||
#else
|
||
dialogFileOperation->refreshListView(editMode);
|
||
dialogFileOperation->exec();
|
||
#endif
|
||
}
|
||
void SceneEditOption::on_EditItemButton_pressed()
|
||
{
|
||
#if 0
|
||
|
||
#else
|
||
foreach (QGraphicsItem *item, pPicScene->selectedItems())
|
||
{
|
||
if(item)
|
||
{
|
||
PicTextItem *pTextItem = (PicTextItem *)item;
|
||
//qDebug()<<"edit Item";
|
||
//ui->textEdit->setText(pTextItem->toHtml());
|
||
textEdit->setHtml(pTextItem->toHtml());
|
||
//切换到textedit的界面
|
||
emit editItemMode();
|
||
//stackedWidgetText->setCurrentWidget(ui->pageTextEdit);
|
||
//stackedWidgetOption->setCurrentWidget(ui->textEditOption);
|
||
stackedWidgetText->setCurrentIndex(0);
|
||
stackedWidgetOption->setCurrentIndex(0);
|
||
ui->saveButton->setEnabled(true);
|
||
//edit@12-12
|
||
pPicScene->clearSelection();
|
||
item->setSelected(true);
|
||
break;
|
||
}
|
||
|
||
}
|
||
#endif
|
||
}
|
||
void SceneEditOption::onEditItemDone()
|
||
{
|
||
#if 1
|
||
//stackedWidgetText->setCurrentWidget(ui->fileSceneViewer);
|
||
//stackedWidgetOption->setCurrentWidget(ui->senceEditOption);
|
||
stackedWidgetText->setCurrentIndex(3);
|
||
stackedWidgetOption->setCurrentIndex(1);
|
||
foreach (QGraphicsItem *item, pPicScene->selectedItems())
|
||
{
|
||
if(item)
|
||
{
|
||
PicTextItem *pTextItem = (PicTextItem *)item;
|
||
//qDebug()<<"edit Item done";
|
||
QFont font = pTextItem->font();
|
||
font.setLetterSpacing(QFont::AbsoluteSpacing,sysPara->para.textEditCharSpace);
|
||
pTextItem->setFont(font);
|
||
pTextItem->setHtml(textEdit->toHtml());
|
||
onSceneAccepted(pTextItem);
|
||
}
|
||
|
||
}
|
||
#endif
|
||
}
|
||
void SceneEditOption::onCreateSceneImage(QString filePath)
|
||
{
|
||
m_CreateImageFlag = true;
|
||
m_pSavePicScene->clear();
|
||
onFileOpen(filePath,false);
|
||
#if 1
|
||
m_pSavePicScene->clearSelection();
|
||
QSize size(m_pSavePicScene->itemsBoundingRect().width(),m_pSavePicScene->itemsBoundingRect().height());
|
||
QImage image(size,QImage::Format_ARGB32);
|
||
image.fill(0x00ffffff);//填充白色
|
||
//image.save("./printScene.jpg");//图片
|
||
QPainter painter(&image);
|
||
m_pSavePicScene->render(&painter,QRectF(),m_pSavePicScene->itemsBoundingRect());
|
||
//qDebug()<<"scene rect:"<<pPicScene->itemsBoundingRect();
|
||
image.save("./printSceneView.png");//图片
|
||
|
||
#endif
|
||
m_CreateImageFlag = false;
|
||
}
|
||
|
||
extern QStringList stringListRecive;
|
||
|
||
void SceneEditOption::parseVbfile(QXmlStreamReader &reader) {
|
||
// int textItemPosX;
|
||
// int textItemPosY;
|
||
// textItemPosX = picText->pos().x() - pPicScene->itemsBoundingRect().x();
|
||
// textItemPosY = picText->pos().y() - pPicScene->itemsBoundingRect().y();
|
||
float pos_x,pos_y;
|
||
bool Condition= false ;
|
||
int CatchStartValue = -1;
|
||
int CatchValue = -1;
|
||
while (!reader.atEnd()) {
|
||
reader.readNext();
|
||
if (reader.isStartElement()) { // 开始元素
|
||
QString strElementName = reader.name().toString();
|
||
if (QString::compare(strElementName, "VBfile") == 0) {
|
||
//qDebug() << QString::fromLocal8Bit("********** 开始元素<VBfile> ********** ");
|
||
} else if (QString::compare(strElementName, QString("pointer_x")) == 0) { // 方式一
|
||
reader.readNext();
|
||
if (reader.isCharacters()) {
|
||
pos_x = reader.text().toString().toDouble();
|
||
//qDebug() << QString("pointer_x:%1").arg(reader.text().toString());
|
||
}
|
||
} else if (QString::compare(strElementName, QString("pointer_y")) == 0) { // 方式二
|
||
pos_y = reader.readElementText().toDouble();
|
||
//qDebug() << QString("pointer_y:%1").arg(reader.readElementText());
|
||
}
|
||
else if (QString::compare(strElementName, QString("Condition")) == 0) {
|
||
Condition = reader.readElementText().toInt() ? true : false;
|
||
}
|
||
else if (QString::compare(strElementName, QString("CatchStartValue")) == 0) {
|
||
CatchStartValue = reader.readElementText().toInt();
|
||
}
|
||
else if (QString::compare(strElementName, QString("CatchValue")) == 0) {
|
||
CatchValue = reader.readElementText().toInt();
|
||
}
|
||
else if (QString::compare(strElementName, QString("html_src")) == 0) {
|
||
//qDebug() << QString("html_src:%1").arg(reader.readElementText());
|
||
}
|
||
} else if (reader.isEntityReference()) { // 实体引用
|
||
QString strName = reader.name().toString();
|
||
QString strText = reader.text().toString();
|
||
//qDebug() << QString("EntityReference : %1(%2)").arg(strName).arg(strText);
|
||
} else if (reader.isCDATA()) { // CDATA
|
||
QString strCDATA = reader.text().toString();
|
||
//qDebug() << QString("CDATA : %1").arg(strCDATA);
|
||
PicTextItem *pPictText = new PicTextItem();
|
||
if(m_CreateImageFlag)
|
||
{
|
||
m_pSavePicScene->addItem(pPictText);
|
||
}
|
||
else
|
||
{
|
||
pPicScene->addItem(pPictText);
|
||
}
|
||
QFont font = pPictText->font();
|
||
font.setLetterSpacing(QFont::AbsoluteSpacing,sysPara->para.textEditCharSpace);
|
||
pPictText->setFont(font);
|
||
pPictText->setPos(pos_x,pos_y);
|
||
pPictText->SpecialConditions = Condition;
|
||
pPictText->CatchCnt1StartValue = CatchStartValue;
|
||
pPictText->CatchCnt1CurrValue = CatchValue;
|
||
// Condition= false ;
|
||
// CatchValue = -1;
|
||
//LogInfo::setRunStatusText(tr("接收文件解析::2"));
|
||
if(!sysPara->status.forTemplateUse || m_CreateImageFlag)
|
||
{
|
||
pPictText->setHtml(strCDATA);
|
||
}
|
||
else
|
||
{
|
||
//qDebug() << tr("接收文件解析:");
|
||
//LogInfo::setRunStatusText(tr("接收文件解析::3"));
|
||
//stringListRecive << "aaaa" << "bbbb" << "cccc";
|
||
if(strCDATA.contains("#1111") || strCDATA.contains("<img src=\"/home/plg/doc/modbusQR#01.bmp\" />"))
|
||
{
|
||
if(stringListRecive.size() > 0)
|
||
{
|
||
if(strCDATA.contains("#1111"))
|
||
{
|
||
strCDATA.replace("#1111",stringListRecive.at(0).toStdString().c_str());
|
||
}
|
||
else if(strCDATA.contains("<img src=\"/home/plg/doc/modbusQR#01.bmp\" />"))
|
||
{
|
||
emit generateQRCode(stringListRecive.at(0));
|
||
strCDATA.replace("modbusQR#01.bmp","modbusQR.bmp");
|
||
}
|
||
}
|
||
|
||
}
|
||
else if(strCDATA.contains("#2222") || strCDATA.contains("<img src=\"/home/plg/doc/modbusQR#02.bmp\" />"))
|
||
{
|
||
if(stringListRecive.size() > 1)
|
||
{
|
||
if(strCDATA.contains("#2222"))
|
||
{
|
||
strCDATA.replace("#2222",stringListRecive.at(1).toStdString().c_str());
|
||
}
|
||
else if(strCDATA.contains("<img src=\"/home/plg/doc/modbusQR#02.bmp\" />"))
|
||
{
|
||
emit generateQRCode(stringListRecive.at(1));
|
||
strCDATA.replace("modbusQR#02.bmp","modbusQR.bmp");
|
||
}
|
||
}
|
||
}
|
||
else if(strCDATA.contains("#3333") || strCDATA.contains("<img src=\"/home/plg/doc/modbusQR#03.bmp\" />"))
|
||
{
|
||
if(stringListRecive.size() > 2)
|
||
{
|
||
if(strCDATA.contains("#3333"))
|
||
{
|
||
strCDATA.replace("#3333",stringListRecive.at(2).toStdString().c_str());
|
||
}
|
||
else if(strCDATA.contains("<img src=\"/home/plg/doc/modbusQR#03.bmp\" />"))
|
||
{
|
||
emit generateQRCode(stringListRecive.at(2));
|
||
strCDATA.replace("modbusQR#03.bmp","modbusQR.bmp");
|
||
}
|
||
}
|
||
}
|
||
pPictText->setHtml(strCDATA);
|
||
}
|
||
// if(Condition)
|
||
// {
|
||
// SpecialVarPrint specialVarPrint;
|
||
// specialVarPrint.SpecialVarEnable = Condition;
|
||
// specialVarPrint.SpecialVarCountStart = CatchStartValue;
|
||
// specialVarPrint.SpecialVarCountEnd = CatchValue;
|
||
// specialVarPrint.SpecialVarColStart = 3 + pos_x- pPicScene->itemsBoundingRect().x();
|
||
// specialVarPrint.SpecialVarColEnd = 3 + pos_x - pPicScene->itemsBoundingRect().x()+ pPictText->boundingRect().width();
|
||
// specialVarPrint.SpecialVarRowStart = pos_y - pPicScene->itemsBoundingRect().y();
|
||
// specialVarPrint.SpecialVarRowEnd = pos_y - pPicScene->itemsBoundingRect().y()+ pPictText->boundingRect().height();
|
||
// sysPara->devOp->fpgaWr(0xa4b0,(unsigned char *)&specialVarPrint,sizeof(SpecialVarPrint)); // Send specialVarPrint 2022-8-6
|
||
// LogInfo::setRunStatusText(tr("发送特殊变量内容:"));
|
||
// LogInfo::setRunStatusText(tr("SpecialVarEnable:%1").arg(QString().sprintf("%02X",specialVarPrint.SpecialVarEnable)));
|
||
// LogInfo::setRunStatusText(tr("SpecialVarCountStart:%1").arg(QString().sprintf("%02X",specialVarPrint.SpecialVarCountStart)));
|
||
// LogInfo::setRunStatusText(tr("SpecialVarCountEnd:%1").arg(QString().sprintf("%02X",specialVarPrint.SpecialVarCountEnd)));
|
||
// LogInfo::setRunStatusText(tr("SpecialVarColStart:%1").arg(QString().sprintf("%02X",specialVarPrint.SpecialVarColStart)));
|
||
// LogInfo::setRunStatusText(tr("SpecialVarColEnd:%1").arg(QString().sprintf("%02X",specialVarPrint.SpecialVarColEnd)));
|
||
// LogInfo::setRunStatusText(tr("SpecialVarRowStart:%1").arg(QString().sprintf("%02X",specialVarPrint.SpecialVarRowStart)));
|
||
// LogInfo::setRunStatusText(tr("SpecialVarRowEnd:%1").arg(QString().sprintf("%02X",specialVarPrint.SpecialVarRowEnd)));
|
||
// LogInfo::setRunStatusText(tr("itemsBoundingRect().y():%1").arg(QString().sprintf("%02X",pPicScene->itemsBoundingRect().y())));
|
||
// LogInfo::setRunStatusText(tr("itemsBoundingRect().x():%1").arg(QString().sprintf("%02X",pPicScene->itemsBoundingRect().x())));
|
||
// }
|
||
Condition= false ;
|
||
CatchValue = -1;
|
||
CatchStartValue = -1;
|
||
|
||
reader.readNext();
|
||
if (reader.isCharacters()) {
|
||
QString strCharacters = reader.text().toString();
|
||
//qDebug() << QString("Characters : %1").arg(strCharacters);
|
||
}
|
||
} else if (reader.isEndElement()) { // 结束元素
|
||
QString strElementName = reader.name().toString();
|
||
if (QString::compare(strElementName, "Blogs") == 0) {
|
||
//qDebug() << QString::fromLocal8Bit("********** 结束元素<Blogs> ********** ");
|
||
break; // 跳出循环(解析 QXmlStreamReader::EndDocument)
|
||
} else if (QString::compare(strElementName, "Blog") == 0) {
|
||
//qDebug() << QString::fromLocal8Bit("********** 结束元素<Blog> ********** ");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/*
|
||
* 和DialogFileOperation对接
|
||
* */
|
||
void SceneEditOption::onFileOpen(QString filePath,bool insertFlag){
|
||
if(editMode==SCENE) {
|
||
if(filePath.endsWith(".xml"))
|
||
{
|
||
QFile file(filePath);
|
||
|
||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { // 以只写模式打开文件
|
||
xmlfileName=filePath;
|
||
QXmlStreamReader reader(&file);
|
||
if(!m_CreateImageFlag)
|
||
{
|
||
pPicScene->clear();
|
||
pViewer->viewport()->update();
|
||
unsigned char SpecialVarEnable = 0;
|
||
sysPara->devOp->fpgaWr(0xa4b0,(unsigned char *)&SpecialVarEnable,1);
|
||
}
|
||
// 解析 XML,直到结束
|
||
while (!reader.atEnd()) {
|
||
|
||
// 读取下一个元素
|
||
QXmlStreamReader::TokenType nType = reader.readNext();
|
||
|
||
switch (nType) {
|
||
case QXmlStreamReader::StartDocument: { // 开始文档
|
||
//qDebug() << QString::fromLocal8Bit("********** 开始文档(XML 声明) ********** ");
|
||
// XML 声明
|
||
QString strVersion = reader.documentVersion().toString();
|
||
QString strEncoding = reader.documentEncoding().toString();
|
||
bool bAlone = reader.isStandaloneDocument();
|
||
//qDebug() << QString::fromLocal8Bit("版本:%1 编码:%2 Standalone:%3")
|
||
// .arg(strVersion).arg(strEncoding).arg(bAlone) << "\r\n";
|
||
break;
|
||
}
|
||
case QXmlStreamReader::Comment: { // 注释
|
||
//qDebug() << QString::fromLocal8Bit("********** 注释 ********** ");
|
||
QString strComment = reader.text().toString();
|
||
//qDebug() << strComment << "\r\n";
|
||
break;
|
||
}
|
||
case QXmlStreamReader::ProcessingInstruction: { // 处理指令
|
||
//qDebug() << QString::fromLocal8Bit("********** 处理指令 ********** ");
|
||
QString strProcInstr = reader.processingInstructionData().toString();
|
||
//qDebug() << strProcInstr << "\r\n";
|
||
break;
|
||
}
|
||
case QXmlStreamReader::DTD: { // DTD
|
||
//qDebug() << QString::fromLocal8Bit("********** DTD ********** ");
|
||
QString strDTD = reader.text().toString();
|
||
QXmlStreamNotationDeclarations notationDeclarations = reader.notationDeclarations(); // 符号声明
|
||
QXmlStreamEntityDeclarations entityDeclarations = reader.entityDeclarations(); // 实体声明
|
||
// DTD 声明
|
||
QString strDTDName = reader.dtdName().toString();
|
||
QString strDTDPublicId = reader.dtdPublicId().toString(); // DTD 公开标识符
|
||
QString strDTDSystemId = reader.dtdSystemId().toString(); // DTD 系统标识符
|
||
//qDebug() << QString::fromLocal8Bit("DTD : %1").arg(strDTD);
|
||
//qDebug() << QString::fromLocal8Bit("DTD 名称 : %1").arg(strDTDName);
|
||
//qDebug() << QString::fromLocal8Bit("DTD 公开标识符 : %1").arg(strDTDPublicId);
|
||
//qDebug() << QString::fromLocal8Bit("DTD 系统标识符 : %1").arg(strDTDSystemId);
|
||
//qDebug() << "\r\n";
|
||
|
||
break;
|
||
}
|
||
case QXmlStreamReader::StartElement: { // 开始元素
|
||
QString strElementName = reader.name().toString();
|
||
if (QString::compare(strElementName, "VBfiles") == 0) { // 根元素
|
||
//qDebug() << QString::fromLocal8Bit("********** 开始元素<VBfiles> ********** ");
|
||
QXmlStreamAttributes attributes = reader.attributes();
|
||
if (attributes.hasAttribute("Version")) {
|
||
QString strVersion = attributes.value("Version").toString();
|
||
//qDebug() << QString::fromLocal8Bit("属性:Version(%1)").arg(strVersion);
|
||
}
|
||
|
||
parseVbfile(reader);
|
||
}
|
||
break;
|
||
}
|
||
case QXmlStreamReader::EndDocument: { // 结束文档
|
||
//qDebug() << QString::fromLocal8Bit("********** 结束文档 ********** ");
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (reader.hasError()) { // 解析出错
|
||
//qDebug() << QString::fromLocal8Bit("错误信息:%1 行号:%2 列号:%3 字符位移:%4").arg(reader.errorString()).arg(reader.lineNumber()).arg(reader.columnNumber()).arg(reader.characterOffset());
|
||
}
|
||
//qDebug()<<"open done";
|
||
file.close(); // 关闭文件
|
||
//snprintf(sysPara->para.lastOpenedFileName,sizeof(sysPara->para.lastOpenedFileName),"%s",filePath.toAscii().constData());
|
||
if(!m_CreateImageFlag)//生成图片显示
|
||
{
|
||
if(sysPara)
|
||
{
|
||
sysPara->sysFile =filePath;
|
||
sysPara->loadParaFromFile();
|
||
//qDebug()<<"textedit txt mode onFileOpen" << sysPara->sysFile;
|
||
snprintf(sysPara->para.lastOpenedFileName,sizeof(sysPara->para.lastOpenedFileName),"%s",filePath.toAscii().constData());
|
||
}
|
||
|
||
emit fileNameChanged(QFileInfo(xmlfileName).fileName());
|
||
ui->saveButton->setEnabled(false);
|
||
QList<QGraphicsItem *> items = pPicScene->items();
|
||
foreach (QGraphicsItem *item, items) {
|
||
PicTextItem *picText = qgraphicsitem_cast<PicTextItem*>(item);
|
||
onSceneAccepted(picText);
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
void SceneEditOption::saveFile(){
|
||
#if 1
|
||
//qDebug()<<"SceneEditOption save scene start";
|
||
//QList<QGraphicsItem *> itemList = pPicScene->items();
|
||
//qDebug()<<"xmlfileName:"<< xmlfileName;
|
||
|
||
QFile file(xmlfileName);
|
||
if (!file.open(QFile::WriteOnly | QFile::Text)) { // 只写模式打开文件
|
||
qDebug() << QString("Cannot write file %1(%2).").arg(xmlfileName).arg(file.errorString());
|
||
return;
|
||
}
|
||
//qDebug()<<"open xmlfileName successfull";
|
||
|
||
QXmlStreamWriter writer(&file);
|
||
|
||
// writer.setCodec("GBK"); // XML 编码
|
||
writer.setAutoFormatting(true); // 自动格式化
|
||
writer.writeStartDocument("1.0", true); // 开始文档(XML 声明)
|
||
writer.writeComment(QString::fromLocal8Bit("Vernon Bach graphic scene file")); // 注释
|
||
//writer.writeProcessingInstruction("xml-stylesheet type=\"text/css\" href=\"style.css\""); // 处理指令
|
||
|
||
// DTD <!ELEMENT VBfiles (VBfile) >
|
||
writer.writeDTD(QString::fromLocal8Bit("<!DOCTYPE VBfiles [ <!ELEMENT VBfiles (VBfile) > <!ELEMENT VBfile (pointer_x,pointer_y,html_src)> <!ELEMENT pointer_x (#PCDATA)><!ELEMENT pointer_y (#PCDATA)><!ELEMENT html_src (#PCDATA)> ]>"));
|
||
//writer.writeDTD(QString::fromLocal8Bit("<!DOCTYPE Blogs [ <!ENTITY Copyright \"Copyright 2016《Qt实战一二三》\"> <!ELEMENT Blogs (Blog)> <!ELEMENT Blog (作者,主页,个人说明)> <!ELEMENT 作者 (#PCDATA)> <!ELEMENT 主页 (#PCDATA)> <!ELEMENT 个人说明 (#PCDATA)> ]>"));
|
||
|
||
writer.writeStartElement("VBfiles"); // 开始根元素 <picscene>
|
||
writer.writeAttribute("Version", "1.0"); // 属性
|
||
|
||
QList<QGraphicsItem *> items = pPicScene->items();
|
||
foreach (QGraphicsItem *item, items) {
|
||
PicTextItem *picText = qgraphicsitem_cast<PicTextItem*>(item);
|
||
//qDebug()<<"item position: "<< picText->pos();
|
||
writer.writeStartElement("VBfile"); // 开始子元素 <picscene>
|
||
writer.writeTextElement(QString::fromLocal8Bit("pointer_x"), QString::fromLocal8Bit("%1").arg(picText->pos().x()));
|
||
writer.writeTextElement(QString::fromLocal8Bit("pointer_y"), QString::fromLocal8Bit("%1").arg(picText->pos().y()));
|
||
writer.writeTextElement(QString::fromLocal8Bit("Condition"), QString::fromLocal8Bit("%1").arg(picText->SpecialConditions? 1:0));
|
||
writer.writeTextElement(QString::fromLocal8Bit("CatchStartValue"), QString::fromLocal8Bit("%1").arg(picText->CatchCnt1StartValue));
|
||
writer.writeTextElement(QString::fromLocal8Bit("CatchValue"), QString::fromLocal8Bit("%1").arg(picText->CatchCnt1CurrValue));
|
||
//writer.writeEntityReference("Copyright");
|
||
//writer.writeCDATA(QString::fromLocal8Bit("html code"));
|
||
writer.writeTextElement(QString::fromLocal8Bit("html_src"), QString::fromLocal8Bit("my_src"));
|
||
writer.writeCDATA((picText->toHtml()));
|
||
//qDebug()<<"tohtml"<<picText->toHtml();
|
||
//writer.writeCharacters(">");
|
||
//writer.writeEmptyElement(QString::fromLocal8Bit("Empty")); // 空元素
|
||
writer.writeEndElement(); // 结束子元素 </picscene>
|
||
}
|
||
|
||
writer.writeEndElement(); // 结束根元素 </picscenes>
|
||
writer.writeEndDocument(); // 结束文档
|
||
//qDebug()<<"sceneEditOption save done";
|
||
//#if defined(__CONVERTERBOARD__)|| defined(__VX__)
|
||
#if 1
|
||
fsync(file.handle());
|
||
#endif
|
||
file.close(); // 关闭文件
|
||
|
||
#endif
|
||
}
|
||
|
||
void SceneEditOption::onSaveASFile(QString filename,bool Flag){// use for dialogSaveFile class
|
||
qDebug()<<filename;
|
||
xmlfileName = filename;
|
||
if(!filename.endsWith(".xml",Qt::CaseInsensitive))
|
||
xmlfileName += ".xml";
|
||
|
||
saveFile();
|
||
if(sysPara){
|
||
sysPara->sysFile =xmlfileName;
|
||
snprintf(sysPara->para.lastOpenedFileName,sizeof(sysPara->para.lastOpenedFileName),"%s",xmlfileName.toAscii().constData());
|
||
}
|
||
//snprintf(sysPara->para.lastOpenedFileName,sizeof(sysPara->para.lastOpenedFileName),"%s",xmlfileName.toAscii().constData());
|
||
ui->saveButton->setEnabled(false);
|
||
emit fileNameChanged(QFileInfo(xmlfileName).fileName());
|
||
}
|
||
void SceneEditOption::on_enlargeButton_pressed()
|
||
{
|
||
((MyView*)pViewer)->ZoomOut();
|
||
}
|
||
void SceneEditOption::on_reduceButton_pressed()
|
||
{
|
||
((MyView*)pViewer)->ZoomIn();
|
||
}
|
||
|
||
void SceneEditOption::onSceneAccepted(PicTextItem *pTextItem){
|
||
//dialogLineSpace->getValue(&sysPara->para.textEditLineSpace,&sysPara->para.textEditCharSpace);
|
||
for(QTextBlock textBlock = pTextItem->document()->begin();textBlock != pTextItem->document()->end(); textBlock = textBlock.next()){
|
||
// textBlock.setVisible(false);
|
||
QTextBlockFormat textBlockFormat = textBlock.blockFormat();
|
||
textBlockFormat.setAlignment(Qt::AlignTop);
|
||
textBlockFormat.setTopMargin(-1);
|
||
//textBlockFormat.setLineHeight(sysPara->para.fontPixelSize + sysPara->para.textEditLineSpace, QTextBlockFormat::FixedHeight);
|
||
//textBlockFormat.setLineHeight(0, QTextBlockFormat::LineDistanceHeight);
|
||
textBlockFormat.setBottomMargin(sysPara->para.textEditLineSpace-1);
|
||
//textBlockFormat.setBottomMargin(-1);
|
||
QTextCursor textCursor = pTextItem->textCursor();
|
||
textCursor.setPosition(textBlock.position());
|
||
textCursor.setBlockFormat(textBlockFormat);
|
||
pTextItem->setTextCursor(textCursor);
|
||
}
|
||
|
||
// QTextCharFormat fmt;
|
||
// //fmt.setFontWordSpacing(sysPara->para.textEditCharSpace);
|
||
// fmt.setFontLetterSpacing(sysPara->para.textEditCharSpace); qDebug() << sysPara->para.textEditCharSpace;
|
||
// mergeFormatOnWordOrSelection(fmt);
|
||
QFont font = pTextItem->font();
|
||
font.setLetterSpacing(QFont::AbsoluteSpacing,sysPara->para.textEditCharSpace);
|
||
pTextItem->setFont(font);
|
||
sysPara->saveParaToFile();
|
||
}
|
||
|
||
//edit@12-10
|
||
void SceneEditOption::on_test_pressed()
|
||
{
|
||
const QPoint originScene=pViewer->mapFromScene(0,0);
|
||
const QRectF sceneRect=pPicScene->sceneRect();
|
||
const QRectF BoundingRect=pPicScene->itemsBoundingRect();
|
||
qDebug()<<QString("originScene=(%1,%2)").arg(originScene.x()).arg(originScene.y())<<",sceneRect="<<sceneRect<<",BoundingRect="<<BoundingRect;
|
||
qDebug()<<"pViewer-geometry="<<pViewer->geometry();
|
||
qreal bottom=0;
|
||
bool isTextItem=true;
|
||
foreach (const QGraphicsItem *item, pPicScene->items()) {
|
||
if(item->sceneBoundingRect().bottom()>bottom)
|
||
{
|
||
bottom=item->sceneBoundingRect().bottom();
|
||
isTextItem=-1==((QGraphicsTextItem*)item)->toHtml().indexOf("img ",0,Qt::CaseInsensitive)?true:false;
|
||
}
|
||
qDebug()<<"item-pos="<<item->pos()
|
||
<<", isSelected="<<item->isSelected()
|
||
<<", text="<<((QGraphicsTextItem*)item)->toPlainText()
|
||
//<<", html="<<((QGraphicsTextItem*)item)->toHtml()
|
||
<<", type="<<(-1==((QGraphicsTextItem*)item)->toHtml().indexOf("img ",0,Qt::CaseInsensitive)?true:false)
|
||
<<", button-pos="<<item->sceneBoundingRect().bottom()
|
||
;
|
||
}
|
||
qDebug()<<"bottom="<<bottom<<", isTextItem="<<isTextItem;
|
||
|
||
int value=pViewer->horizontalScrollBar()->value();
|
||
qDebug()<<"pViewer-horizontalScrollBar-value="<<value;
|
||
|
||
pPicScene->update();
|
||
pViewer->update();
|
||
}
|
||
//edit@12-10
|
||
void SceneEditOption::on_btn_test2()
|
||
{
|
||
const QPoint originScene=pViewer->mapFromScene(0,0);
|
||
QRectF sceneRect=pPicScene->sceneRect();
|
||
|
||
qreal left=sceneRect.width(),top=sceneRect.width();
|
||
foreach (const QGraphicsItem *item, pPicScene->items()) {
|
||
left=qMin(left,item->pos().x());
|
||
top=qMin(top,item->pos().y());
|
||
}
|
||
|
||
foreach (QGraphicsItem *item, pPicScene->items()) {
|
||
QPointF oldpos=item->pos();
|
||
//oldpos=pViewer->mapToScene(oldpos.x()-left,oldpos.y()-top);
|
||
oldpos=QPointF(oldpos.x()-left,oldpos.y()-(top-pViewer->mapToScene(0,0).y()));
|
||
item->setPos(oldpos);
|
||
}
|
||
pPicScene->update();
|
||
}
|
||
|
||
void SceneEditOption::onInkJetPrinterCurrentChanged(int index)
|
||
{
|
||
if(SCENE==sysPara->para.EditMode)
|
||
{
|
||
if(0==index)//edit@12-14 mainwindow tab
|
||
{
|
||
onStackedWidgetOptionCurrentChanged(1);
|
||
}
|
||
else //edit@12-14 other tabs
|
||
{
|
||
onStackedWidgetOptionCurrentChanged(0);
|
||
}
|
||
}
|
||
}
|