hlp:640x480-小屏vx4齿轮泵代码提交
This commit is contained in:
@@ -0,0 +1,674 @@
|
||||
#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 "myview.h"
|
||||
#include "LogInfo.h"
|
||||
#include <QTextBlockFormat>
|
||||
#include <QTextBlock>
|
||||
|
||||
MoveInput* moveInput;
|
||||
SceneEditOption::SceneEditOption(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::SceneEditOption)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
void SceneEditOption::bindSysPara(SysPara *sysPara){
|
||||
this->sysPara = sysPara;
|
||||
}
|
||||
void SceneEditOption::enableButtonSave(){
|
||||
if(!ui->saveButton->isEnabled())
|
||||
ui->saveButton->setEnabled(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
|
||||
}
|
||||
|
||||
void SceneEditOption::on_previewButton_pressed()
|
||||
{
|
||||
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);
|
||||
textItem->setPos(0,0);
|
||||
textItem->setPlainText("Vernon Bach Printer");
|
||||
ui->saveButton->setEnabled(true);
|
||||
//qDebug()<<"sysPara->para.textEditCharSpace:"<<sysPara->para.textEditCharSpace;
|
||||
#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);
|
||||
}
|
||||
|
||||
}
|
||||
#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();
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
#ifndef SCENEEDITOPTION_H
|
||||
#define SCENEEDITOPTION_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTextEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
#include <QTextCharFormat>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QGraphicsView>
|
||||
#include "ParaSettingUI.h"
|
||||
#include "MyFileDialog.h"
|
||||
#include <QComboBox>
|
||||
#include <QPushButton>
|
||||
#include <QCheckBox>
|
||||
#include "DialogFileOperation.h"
|
||||
#include "DialogInsertVari.h"
|
||||
#include "DialogFontSize.h"
|
||||
#include "DialogLineSpace.h"
|
||||
#include "PicWidget.h"
|
||||
#include <QtGui/QStackedWidget>
|
||||
#include "dlgQrCode.h"
|
||||
#include "QBarCode.h"
|
||||
#include "DialogSaveFile.h"
|
||||
#include "SceneEditOption.h"
|
||||
#include "pictextitem.h"
|
||||
#include "picscene.h"
|
||||
#include "moveinput.h"
|
||||
|
||||
namespace Ui {
|
||||
class SceneEditOption;
|
||||
}
|
||||
|
||||
class SceneEditOption : public QWidget,public ParaSettingUI
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SceneEditOption(QWidget *parent = 0);
|
||||
~SceneEditOption();
|
||||
|
||||
void bindStackWidget(QStackedWidget *stackedWidgetOption,QStackedWidget *stackedWidgetText);
|
||||
void bindSysPara(SysPara *sysPara);
|
||||
void bindScene(PicScene *pPicScene, QGraphicsView *pGraphicViewer, QTextEdit *pTextEdit);
|
||||
signals:
|
||||
void previewScene();
|
||||
void addPicTextItem();
|
||||
void importFile(QString);
|
||||
void delItem();
|
||||
void saveScene(QString);
|
||||
void openSceneFile(QString);
|
||||
void editItem();
|
||||
void editItemMode();
|
||||
void fileNameChanged(QString);
|
||||
void generateQRCode(QString);
|
||||
public slots:
|
||||
void enableButtonSave();
|
||||
void onSaveASFile(QString filename,bool Flag);
|
||||
void saveFile();
|
||||
void onFileOpen(QString filePath,bool insertFlag);
|
||||
void onEditItemDone();
|
||||
void onCreateSceneImage(QString filePath);//生成场景图片
|
||||
|
||||
private slots:
|
||||
void on_delButton_pressed();
|
||||
|
||||
void on_saveButton_pressed();
|
||||
void on_openfileButton_pressed();
|
||||
|
||||
void on_previewButton_pressed();
|
||||
|
||||
void on_addButton_pressed();
|
||||
|
||||
void on_EditItemButton_pressed();
|
||||
|
||||
void on_saveAsButton_pressed();
|
||||
|
||||
void on_newfileButton_pressed();
|
||||
void on_enlargeButton_pressed();
|
||||
void on_reduceButton_pressed();
|
||||
|
||||
private:
|
||||
void parseVbfile(QXmlStreamReader &reader);
|
||||
bool maybeSave();
|
||||
Ui::SceneEditOption *ui;
|
||||
QStackedWidget *stackedWidgetOption;
|
||||
QStackedWidget *stackedWidgetText;
|
||||
PicScene *pPicScene;
|
||||
QGraphicsView *pViewer;
|
||||
QTextEdit *textEdit;
|
||||
QGraphicsScene *m_pSavePicScene;
|
||||
bool m_CreateImageFlag;
|
||||
|
||||
DialogFileOperation *dialogFileOperation;
|
||||
#ifdef MYSAVEFILEDLG
|
||||
DialogSaveFile *dialogSaveFile;
|
||||
#endif
|
||||
MyFileDialog *fileDialog;
|
||||
|
||||
PicTextItem *textItem;
|
||||
//PicScene *scene;
|
||||
QString currFileName;
|
||||
void onSceneAccepted(PicTextItem *pTextItem);
|
||||
int editMode;//保存当前的编辑模式
|
||||
QString xmlfileName;
|
||||
};
|
||||
|
||||
#endif // SCENEEDITOPTION_H
|
||||
@@ -0,0 +1,63 @@
|
||||
#include "myview.h"
|
||||
#include <QWheelEvent>
|
||||
#include "picscene.h"
|
||||
|
||||
MyView::MyView(QWidget *parent) :
|
||||
QGraphicsView(parent)
|
||||
{
|
||||
zoomRatio = 1;
|
||||
//setDragMode(QGraphicsView::ScrollHandDrag);//手型拖动
|
||||
//setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
//setFocusPolicy( Qt::NoFocus );
|
||||
}
|
||||
|
||||
void MyView::ZoomOut(void)
|
||||
{
|
||||
if(zoomRatio < 3)
|
||||
{
|
||||
zoomRatio++;
|
||||
scale(2,2);
|
||||
}
|
||||
}
|
||||
|
||||
void MyView::ZoomIn(void)
|
||||
{
|
||||
if(zoomRatio > 0)
|
||||
{
|
||||
zoomRatio--;
|
||||
scale(0.5,0.5);
|
||||
}
|
||||
}
|
||||
|
||||
//void MyView::wheelEvent(QWheelEvent*event) //滚轮事件
|
||||
//{
|
||||
//// if(event->delta() > 0) //如果鼠标滚轮远离使用者,则delta()返回正值
|
||||
//// scale(0.5,0.5); //视图缩放
|
||||
//// else scale(2,2);
|
||||
//}
|
||||
|
||||
|
||||
//void MyView::mousePressEvent(QMouseEvent*event)
|
||||
//{
|
||||
//// rotate(90); //视图旋转顺时针90度
|
||||
//}
|
||||
|
||||
void MyView::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
//event->accept();
|
||||
//parent()->event((QEvent*) event);
|
||||
if (event->key() == Qt::Key_Left || event->key() == Qt::Key_Right || event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
|
||||
{
|
||||
// 处理上下键事件
|
||||
PicScene* picScene = dynamic_cast<PicScene*>(this->scene());
|
||||
if(picScene)
|
||||
{
|
||||
picScene->keyPressEvent(event);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 其他键事件交给父类处理
|
||||
QGraphicsView::keyPressEvent(event);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef MYVIEW_H
|
||||
#define MYVIEW_H
|
||||
|
||||
#include <QGraphicsView>
|
||||
|
||||
class MyView : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MyView(QWidget *parent = 0);
|
||||
|
||||
void ZoomOut(void);
|
||||
void ZoomIn(void);
|
||||
private:
|
||||
char zoomRatio;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
protected :
|
||||
// void wheelEvent(QWheelEvent *event);
|
||||
// void mousePressEvent(QMouseEvent *event);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
};
|
||||
|
||||
#endif // MYVIEW_H
|
||||
@@ -0,0 +1,108 @@
|
||||
#if 1
|
||||
#include "picscene.h"
|
||||
#include <QDebug>
|
||||
#include <QRectF>
|
||||
PicScene::PicScene(QObject *parent) :
|
||||
QGraphicsScene(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void PicScene::setMode(Mode mode)
|
||||
{
|
||||
myMode = mode;
|
||||
}
|
||||
|
||||
void PicScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
{
|
||||
if (mouseEvent->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
QGraphicsScene::mousePressEvent(mouseEvent);
|
||||
}
|
||||
|
||||
//! [9]
|
||||
|
||||
//! [10]
|
||||
void PicScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
{
|
||||
#if 0
|
||||
if (myMode == InsertLine && line != 0) {
|
||||
QLineF newLine(line->line().p1(), mouseEvent->scenePos());
|
||||
line->setLine(newLine);
|
||||
} else if (myMode == MoveItem) {
|
||||
QGraphicsScene::mouseMoveEvent(mouseEvent);
|
||||
}
|
||||
#else
|
||||
QGraphicsScene::mouseMoveEvent(mouseEvent);
|
||||
|
||||
#endif
|
||||
}
|
||||
//! [10]
|
||||
|
||||
//! [11]
|
||||
void PicScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
{
|
||||
#if 0 //不需要这个功能
|
||||
if (line != 0 && myMode == InsertLine) {
|
||||
QList<QGraphicsItem *> startItems = items(line->line().p1());
|
||||
if (startItems.count() && startItems.first() == line)
|
||||
startItems.removeFirst();
|
||||
QList<QGraphicsItem *> endItems = items(line->line().p2());
|
||||
if (endItems.count() && endItems.first() == line)
|
||||
endItems.removeFirst();
|
||||
|
||||
removeItem(line);
|
||||
delete line;
|
||||
//! [11] //! [12]
|
||||
|
||||
if (startItems.count() > 0 && endItems.count() > 0 &&
|
||||
startItems.first()->type() == DiagramItem::Type &&
|
||||
endItems.first()->type() == DiagramItem::Type &&
|
||||
startItems.first() != endItems.first()) {
|
||||
DiagramItem *startItem =
|
||||
qgraphicsitem_cast<DiagramItem *>(startItems.first());
|
||||
DiagramItem *endItem =
|
||||
qgraphicsitem_cast<DiagramItem *>(endItems.first());
|
||||
Arrow *arrow = new Arrow(startItem, endItem);
|
||||
arrow->setColor(myLineColor);
|
||||
startItem->addArrow(arrow);
|
||||
endItem->addArrow(arrow);
|
||||
arrow->setZValue(-1000.0);
|
||||
addItem(arrow);
|
||||
arrow->updatePosition();
|
||||
}
|
||||
}
|
||||
//! [12] //! [13]
|
||||
line = 0;
|
||||
#endif
|
||||
QGraphicsScene::mouseReleaseEvent(mouseEvent);
|
||||
//QRectF Rect=QGraphicsScene.itemsBoundingRect();
|
||||
//qDebug()<<"GraphicsScene itemsBoundingRect "<<itemsBoundingRect();
|
||||
//qDebug()<<"GraphicsScene toRect "<<itemsBoundingRect().pos();
|
||||
//qDebug()<<"GraphicsScene rect "<<sceneRect();
|
||||
//qDebug()<<"RectF.y "<<itemsBoundingRect().y();
|
||||
//qDebug()<<"RectF.height "<<itemsBoundingRect().height();
|
||||
//qDebug()<<"RectF.width "<<itemsBoundingRect().width();
|
||||
//qDebug()<<"asdfasdf";
|
||||
//qDebug()<<"GraphicsScene "<<sceneRect();
|
||||
//emit xmlContentChanged();
|
||||
}
|
||||
//! [13]
|
||||
|
||||
//! [14]
|
||||
bool PicScene::isItemChange(int type)
|
||||
{
|
||||
foreach (QGraphicsItem *item, selectedItems()) {
|
||||
if (item->type() == type)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//! [14]
|
||||
|
||||
void PicScene::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
QGraphicsScene::keyPressEvent(event);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,72 @@
|
||||
#ifndef PICSCENE_H
|
||||
#define PICSCENE_H
|
||||
#if 1
|
||||
#include <QGraphicsScene>
|
||||
#include "pictextitem.h"
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QGraphicsSceneMouseEvent;
|
||||
class QMenu;
|
||||
class QPointF;
|
||||
class QGraphicsLineItem;
|
||||
class QFont;
|
||||
class QGraphicsTextItem;
|
||||
class QColor;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class PicScene : public QGraphicsScene
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Mode { InsertItem, InsertLine, InsertText, InsertPic, MoveItem };
|
||||
explicit PicScene(QObject *parent = 0);
|
||||
|
||||
QFont font() const
|
||||
{ return myFont; }
|
||||
QColor textColor() const
|
||||
{ return myTextColor; }
|
||||
QColor itemColor() const
|
||||
{ return myItemColor; }
|
||||
QColor lineColor() const
|
||||
{ return myLineColor; }
|
||||
void setLineColor(const QColor &color);
|
||||
void setTextColor(const QColor &color);
|
||||
void setItemColor(const QColor &color);
|
||||
void setFont(const QFont &font);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
|
||||
public slots:
|
||||
void setMode(Mode mode);
|
||||
//void setItemType(DiagramItem::DiagramType type);
|
||||
//void editorLostFocus(DiagramTextItem *item);
|
||||
|
||||
signals:
|
||||
//void itemInserted(DiagramItem *item);
|
||||
void textInserted(QGraphicsTextItem *item);
|
||||
void itemSelected(QGraphicsItem *item);
|
||||
void xmlContentChanged();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||
|
||||
private:
|
||||
bool isItemChange(int type);
|
||||
|
||||
//DiagramItem::DiagramType myItemType;
|
||||
QMenu *myItemMenu;
|
||||
Mode myMode;
|
||||
bool leftButtonDown;
|
||||
QPointF startPoint;
|
||||
QGraphicsLineItem *line;
|
||||
QFont myFont;
|
||||
PicTextItem *textItem;
|
||||
QColor myTextColor;
|
||||
QColor myItemColor;
|
||||
QColor myLineColor;
|
||||
|
||||
};
|
||||
#endif
|
||||
#endif // PICSCENE_H
|
||||
@@ -0,0 +1,135 @@
|
||||
#if 1
|
||||
#include <QtGui>
|
||||
#include "pictextitem.h"
|
||||
#include "picscene.h"
|
||||
#include "moveinput.h"
|
||||
|
||||
extern MoveInput* moveInput;
|
||||
PicTextItem::PicTextItem(QGraphicsItem *parent, QGraphicsScene *scene) :
|
||||
QGraphicsTextItem(parent,scene)
|
||||
{
|
||||
setFlag(QGraphicsItem::ItemIsMovable);
|
||||
setFlag(QGraphicsItem::ItemIsSelectable);
|
||||
//setFlag(QGraphicsItem::ItemIsFocusScope);
|
||||
setFlag(QGraphicsItem::ItemIsFocusable);
|
||||
//setTextInteractionFlags(Qt::NoTextInteraction);
|
||||
QFont font;
|
||||
font.setFamily("wenquanyi");
|
||||
font.setPixelSize(12);
|
||||
//document()->setDefaultFont(font);//如果加上这句后,默认的都是wenquanyi 12点阵,看起来这个字体有问题,会黑屏,所以用界面的字体 WenQuanYiMH 代替
|
||||
document()->setDefaultStyleSheet("p { margin: 0; }");
|
||||
document()->setDocumentMargin(0);
|
||||
SpecialConditions = false;
|
||||
CatchCnt1CurrValue = -1;
|
||||
CatchCnt1StartValue = -1;
|
||||
}
|
||||
//! [1]
|
||||
QVariant PicTextItem::itemChange(GraphicsItemChange change,
|
||||
const QVariant &value)
|
||||
{
|
||||
#if 0
|
||||
if (change == QGraphicsItem::ItemSelectedHasChanged)
|
||||
emit selectedChange(this);
|
||||
return value;
|
||||
#else
|
||||
//qDebug()<<"item posi: "<< pos();
|
||||
if (change == ItemSceneChange && scene()) {
|
||||
// value is the new position.
|
||||
QPointF newPos = value.toPoint();
|
||||
QRectF rect = scene()->sceneRect();
|
||||
if (!rect.contains(newPos)) {
|
||||
// Keep the item inside the scene rect.
|
||||
newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
|
||||
newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
|
||||
//return newPos;
|
||||
}
|
||||
}
|
||||
#if 1
|
||||
if (change == ItemSelectedChange && scene()) {
|
||||
if(moveInput->isHidden() && value == 1){
|
||||
QRect rec = QApplication::desktop()->screenGeometry();
|
||||
//QPoint point = widget->mapToGlobal (QPoint(0,0)); //全局坐标
|
||||
QRect myRec = moveInput->geometry();
|
||||
moveInput->setGeometry(rec.width()/2,rec.height()/2 ,myRec.width(),myRec.height());
|
||||
|
||||
moveInput->show();
|
||||
}
|
||||
if(value == 0)
|
||||
{
|
||||
moveInput->hide();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
#endif
|
||||
}
|
||||
//! [1]
|
||||
|
||||
//! [2]
|
||||
void PicTextItem::focusOutEvent(QFocusEvent *event)
|
||||
{
|
||||
// setTextInteractionFlags(Qt::NoTextInteraction);
|
||||
moveInput->hide();
|
||||
emit lostFocus(this);
|
||||
QGraphicsTextItem::focusOutEvent(event);
|
||||
//
|
||||
}
|
||||
//! [2]
|
||||
|
||||
//! [5]
|
||||
void PicTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
//if (textInteractionFlags() == Qt::NoTextInteraction)
|
||||
// setTextInteractionFlags(Qt::TextEditorInteraction);
|
||||
//setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||
QGraphicsTextItem::mouseDoubleClickEvent(event);
|
||||
//emit itemEdit(toHtml());
|
||||
}
|
||||
//! [5]
|
||||
|
||||
//限制图元拖动范围
|
||||
void PicTextItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
|
||||
{
|
||||
QPointF newPos = this->pos();
|
||||
QRectF rect = scene()->sceneRect();
|
||||
if (!rect.contains(newPos)) {
|
||||
// Keep the item inside the scene rect.
|
||||
newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
|
||||
newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
|
||||
this->setPos(newPos);
|
||||
}
|
||||
QGraphicsTextItem::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void PicTextItem::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if(event->key() == Qt::Key_Left)
|
||||
{
|
||||
moveBy(-1, 0);
|
||||
}
|
||||
else if(event->key() == Qt::Key_Right)
|
||||
{
|
||||
moveBy(1, 0);
|
||||
}
|
||||
else if(event->key() == Qt::Key_Up)
|
||||
{
|
||||
moveBy(0, -1);
|
||||
}
|
||||
else if(event->key() == Qt::Key_Down)
|
||||
{
|
||||
moveBy(0, 1);
|
||||
}
|
||||
|
||||
QPointF newPos = this->pos();
|
||||
QRectF rect = scene()->sceneRect();
|
||||
if (!rect.contains(newPos)) {
|
||||
// Keep the item inside the scene rect.
|
||||
newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
|
||||
newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
|
||||
this->setPos(newPos);
|
||||
}
|
||||
QGraphicsTextItem::keyPressEvent(event);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef PICTEXTITEM_H
|
||||
#define PICTEXTITEM_H
|
||||
|
||||
#include <QGraphicsTextItem>
|
||||
#include <QPen>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#if 1
|
||||
class QFocusEvent;
|
||||
class QGraphicsItem;
|
||||
class QGraphicsScene;
|
||||
class QGraphicsSceneMouseEvent;
|
||||
|
||||
class PicTextItem : public QGraphicsTextItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum { Type = UserType + 3 };
|
||||
explicit PicTextItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
|
||||
|
||||
int type() const
|
||||
{ return Type; }
|
||||
|
||||
signals:
|
||||
void lostFocus(PicTextItem *item);
|
||||
void selectedChange(QGraphicsItem *item);
|
||||
void itemEdit(QString);
|
||||
|
||||
protected:
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
void focusOutEvent(QFocusEvent *event);
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
|
||||
public slots:
|
||||
|
||||
public:
|
||||
bool SpecialConditions;
|
||||
int CatchCnt1StartValue;
|
||||
int CatchCnt1CurrValue;
|
||||
|
||||
};
|
||||
#endif
|
||||
#endif // PICTEXTITEM_H
|
||||
@@ -0,0 +1,186 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SceneEditOption</class>
|
||||
<widget class="QWidget" name="SceneEditOption">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>924</width>
|
||||
<height>58</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="previewButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>预览</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="newfileButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>新建</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="openfileButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>打开</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="saveButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>保存</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="saveAsButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>另存为</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="addButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>新增图元</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="EditItemButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>编辑图元</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="delButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>删除图元</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="enlargeButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>放大</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../image.qrc">
|
||||
<normaloff>:/icon/zoomin.png</normaloff>:/icon/zoomin.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="reduceButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>缩小</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../image.qrc">
|
||||
<normaloff>:/icon/zoomout.png</normaloff>:/icon/zoomout.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../image.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,8 @@
|
||||
#include "sceneviewwidget.h"
|
||||
#include <QGraphicsScene>
|
||||
|
||||
SceneViewWidget::SceneViewWidget(QWidget *parent) :
|
||||
QWidget(parent)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef SCENEVIEWWIDGET_H
|
||||
#define SCENEVIEWWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QGraphicsView>
|
||||
class SceneViewWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SceneViewWidget(QWidget *parent = 0);
|
||||
QGraphicsView *pView;
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // SCENEVIEWWIDGET_H
|
||||
Reference in New Issue
Block a user