First commit
This commit is contained in:
@@ -0,0 +1,874 @@
|
||||
#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>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
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);
|
||||
doc_DMCode = new QTextDocument();
|
||||
}
|
||||
|
||||
SceneEditOption::~SceneEditOption()
|
||||
{
|
||||
if(m_pSavePicScene)
|
||||
{
|
||||
delete m_pSavePicScene;
|
||||
}
|
||||
if(moveInput)
|
||||
{
|
||||
delete moveInput;
|
||||
}
|
||||
delete doc_DMCode;
|
||||
doc_DMCode = NULL;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
//qDebug()<<"onInkJetPrinterCurrentChanged="<<index;
|
||||
if(SCENE==sysPara->para.EditMode)
|
||||
{
|
||||
if(0==index)//edit@12-14 mainwindow tab
|
||||
{
|
||||
onStackedWidgetOptionCurrentChanged(1);
|
||||
}
|
||||
else //edit@12-14 other tabs
|
||||
{
|
||||
onStackedWidgetOptionCurrentChanged(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
void SceneEditOption::updatePrintData(QString data){
|
||||
for (int i=0;i<pPicScene->items().size();i++)
|
||||
{
|
||||
QFont font;
|
||||
if(i==0)
|
||||
{
|
||||
PicTextItem *pTextItem = (PicTextItem *)pPicScene->items().at(i);
|
||||
pTextItem->setPos(0,0);
|
||||
QString imagePath = "/home/plg/doc/WeiDL_DMCode.bmp";
|
||||
QString html="";
|
||||
QFile file("/home/plg/doc/insertDMCode.html");
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QTextStream in(&file);
|
||||
html = in.readAll();
|
||||
file.close();
|
||||
}
|
||||
doc_DMCode->setHtml(html);
|
||||
pTextItem->setDocument(doc_DMCode);
|
||||
}
|
||||
else if(i==1)
|
||||
{
|
||||
font.setFamily("wenquanyi");
|
||||
font.setPixelSize(16);
|
||||
font.setLetterSpacing(QFont::AbsoluteSpacing,0);
|
||||
font.setBold(false);
|
||||
PicTextItem *pTextItem = (PicTextItem *)pPicScene->items().at(i);
|
||||
PicTextItem *lastpTextItem = (PicTextItem *)pPicScene->items().at(i-1);
|
||||
QRectF rect= lastpTextItem->boundingRect();
|
||||
QPointF point=lastpTextItem->pos();
|
||||
pTextItem->setPos(point.x()+rect.width()+14,point.y());
|
||||
pTextItem->setPlainText(data);
|
||||
pTextItem->setFont(font);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
#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"
|
||||
#include "formscenedlg.h"
|
||||
#include <mainwindow.h>
|
||||
#include "MyFileDialog.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);
|
||||
void updatePrintData(QString);
|
||||
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);//生成场景图片
|
||||
void onStackedWidgetOptionCurrentChanged(int index);
|
||||
//edit@12-07
|
||||
void show_scene_new_dlg();
|
||||
void on_btn_test2();
|
||||
void onInkJetPrinterCurrentChanged(int index);
|
||||
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();
|
||||
void on_test_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;
|
||||
FormScenedlg *newScene;
|
||||
QTextDocument *doc_DMCode;
|
||||
};
|
||||
|
||||
#endif // SCENEEDITOPTION_H
|
||||
@@ -0,0 +1,550 @@
|
||||
#include "formscenedlg.h"
|
||||
#include "ui_formscenedlg.h"
|
||||
#include <QTimer>
|
||||
#include <QStackedWidget>
|
||||
#include <QDebug>
|
||||
#include <QScrollBar>
|
||||
|
||||
|
||||
|
||||
FormScenedlg::FormScenedlg(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::FormScenedlg),pPicScene(0),tabMainWindow(0),dialogFileOperation(0),textEdit(0)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
SWmaximumSize1={};
|
||||
SWgeometry1={};
|
||||
FVgeometry2={};
|
||||
GVgeometry3={};
|
||||
|
||||
|
||||
QPushButton *btnArray[]={
|
||||
// ui->KeyDown,
|
||||
// ui->KeyLeft,
|
||||
// ui->KeyRight,
|
||||
// ui->KeyUp,
|
||||
ui->itemLast,
|
||||
ui->itemFirst,
|
||||
ui->saveAsButton,
|
||||
ui->saveButton,
|
||||
ui->addButton,
|
||||
//ui->itemPrev,
|
||||
//ui->itemNext,
|
||||
ui->previewButton,
|
||||
ui->newfileButton,
|
||||
ui->openfileButton,
|
||||
ui->delButton,
|
||||
ui->EditItemButton,
|
||||
ui->insertImage,
|
||||
ui->reduceButton,
|
||||
ui->enlargeButton,
|
||||
ui->ZoomOrigin
|
||||
};
|
||||
|
||||
const QString sysfamily=qApp->font().family();
|
||||
|
||||
for(int i=0;i<sizeof(btnArray)/sizeof(*btnArray);i++)
|
||||
{
|
||||
QFont font = ui->ZoomOrigin->font(); // 获取当前字体
|
||||
const int defaultPointSize=30;//font.pointSize()<10?10:font.pointSize();
|
||||
|
||||
if(Public::ReadLanguageName()=="English"){
|
||||
font.setFamily("Arial");
|
||||
}
|
||||
// font.setFamily("WenQuanYiMH");
|
||||
//font.setFamily("wenquanyi");
|
||||
font.setBold(true);
|
||||
font.setPointSize(1*defaultPointSize); // 设置字体大小为12点
|
||||
font.setWeight(QFont::Black);
|
||||
btnArray[i]->setFont(font); // 应用新字体到按钮
|
||||
}
|
||||
|
||||
//不显示测试按钮
|
||||
ui->itemPrev->setVisible(false);
|
||||
ui->itemNext->setVisible(false);
|
||||
ui->ZoomOrigin->setVisible(false);
|
||||
ui->btn_test2->setVisible(false);
|
||||
|
||||
}
|
||||
|
||||
FormScenedlg::~FormScenedlg()
|
||||
{
|
||||
delete ui;
|
||||
delete dialogFileOperation;
|
||||
dialogFileOperation=0;
|
||||
}
|
||||
void FormScenedlg::horizontalScrollBar_valueChanged(int value)
|
||||
{
|
||||
QTimer::singleShot(100,this,SLOT(sceneRectChanged_timerHandler()));
|
||||
}
|
||||
|
||||
void FormScenedlg::verticalScrollBar_valueChanged(int value)
|
||||
{
|
||||
QTimer::singleShot(100,this,SLOT(sceneRectChanged_timerHandler()));
|
||||
}
|
||||
|
||||
void FormScenedlg::bindScene(PicScene *pPicScene, QGraphicsView *pGraphicViewer,QTextEdit *pTextEdit){
|
||||
this->pPicScene = pPicScene;
|
||||
this->pViewer = pGraphicViewer;
|
||||
this->textEdit = pTextEdit;
|
||||
|
||||
QObject::connect(pViewer->verticalScrollBar(), SIGNAL(valueChanged(int)), this,SLOT(verticalScrollBar_valueChanged(int)));
|
||||
QObject::connect(pViewer->horizontalScrollBar(), SIGNAL(valueChanged(int)), this,SLOT(horizontalScrollBar_valueChanged(int)));
|
||||
|
||||
dialogFileOperation = new DialogFileOperation(0);
|
||||
dialogFileOperation->setWindowTitle(tr("插入图片"));
|
||||
connect(dialogFileOperation,SIGNAL(openFile(QString,bool)),this,SLOT(onFileOpen(QString,bool)));
|
||||
|
||||
|
||||
|
||||
//edit@12-12读取旧的布局信息
|
||||
const QStackedWidget* pStackedWidget= static_cast<QStackedWidget*>(this->pViewer->parentWidget()->parentWidget());
|
||||
const QWidget* fileSceneViewer = static_cast<QWidget*>(this->pViewer->parentWidget());
|
||||
if(pStackedWidget && fileSceneViewer)
|
||||
{
|
||||
tabMainWindow=fileSceneViewer->parentWidget()->parentWidget();
|
||||
SWmaximumSize1=pStackedWidget->maximumSize();
|
||||
SWgeometry1=pStackedWidget->geometry();
|
||||
|
||||
//QSize FVmaximumSize=fileSceneViewer->maximumSize();
|
||||
FVgeometry2=fileSceneViewer->geometry();
|
||||
|
||||
//QSize GVmaximumSize=this->pViewer->maximumSize();
|
||||
GVgeometry3=this->pViewer->geometry();
|
||||
|
||||
//qDebug()<<"1-2-3-size="<<SWmaximumSize1<<", "<<SWgeometry1<<", "<<FVgeometry2<<", "<<GVgeometry3;
|
||||
}
|
||||
}
|
||||
void FormScenedlg::sceneRectChanged_timerHandler()
|
||||
{
|
||||
// if(this->pViewer && this->pPicScene)
|
||||
// {
|
||||
// const QPoint originScene=pViewer->mapFromScene(0,0);
|
||||
// if(originScene!=lastOriginScene)
|
||||
// {
|
||||
// lastOriginScene=originScene;
|
||||
this->pPicScene->update();
|
||||
// //qDebug()<<"sceneRectChanged-update="<<lastOriginScene;
|
||||
// }
|
||||
// //qDebug()<<"sceneRectChanged="<<this->pPicScene->sceneRect();
|
||||
// }
|
||||
}
|
||||
|
||||
//edit@12-12 改变布局
|
||||
void FormScenedlg::Layout_ToNew()
|
||||
{
|
||||
QStackedWidget* pStackedWidget= static_cast<QStackedWidget*>(this->pViewer->parentWidget()->parentWidget());
|
||||
QWidget* fileSceneViewer = static_cast<QWidget*>(this->pViewer->parentWidget());
|
||||
|
||||
//QWidget *tabMainWindow=fileSceneViewer->parentWidget()->parentWidget();
|
||||
QHBoxLayout *horizontalLayout=dynamic_cast<QHBoxLayout*>(FormScenedlg::findChildAll(tabMainWindow->layout(),"horizontalLayout"));//edit@12-14 信息提示栏
|
||||
FormScenedlg::showQLayout(horizontalLayout,false);
|
||||
|
||||
if(pStackedWidget && fileSceneViewer)
|
||||
{
|
||||
pStackedWidget->setMaximumSize(SWmaximumSize1.width(),SWmaximumSize1.height()+150);
|
||||
pStackedWidget->setGeometry(SWgeometry1.x(),SWgeometry1.y(),SWgeometry1.width(),SWgeometry1.height()+150);
|
||||
fileSceneViewer->setGeometry(FVgeometry2.x(),FVgeometry2.y(),FVgeometry2.width(),FVgeometry2.height()+150);
|
||||
this->pViewer->setGeometry(GVgeometry3.x(),GVgeometry3.y(),GVgeometry3.width(),GVgeometry3.height()+80);
|
||||
}
|
||||
|
||||
}
|
||||
//edit@12-12 恢复布局
|
||||
void FormScenedlg::Layout_ToDefault()
|
||||
{
|
||||
QStackedWidget* pStackedWidget= static_cast<QStackedWidget*>(this->pViewer->parentWidget()->parentWidget());
|
||||
QWidget* fileSceneViewer = static_cast<QWidget*>(this->pViewer->parentWidget());
|
||||
|
||||
//QWidget *tabMainWindow=fileSceneViewer->parentWidget()->parentWidget();
|
||||
QHBoxLayout *horizontalLayout=dynamic_cast<QHBoxLayout*>(FormScenedlg::findChildAll(tabMainWindow->layout(),"horizontalLayout"));//edit@12-14 信息提示栏
|
||||
FormScenedlg::showQLayout(horizontalLayout,true);
|
||||
|
||||
if(pStackedWidget && fileSceneViewer)
|
||||
{
|
||||
pStackedWidget->setMaximumSize(SWmaximumSize1);
|
||||
pStackedWidget->setGeometry(SWgeometry1);
|
||||
fileSceneViewer->setGeometry(FVgeometry2);
|
||||
this->pViewer->setGeometry(GVgeometry3);
|
||||
}
|
||||
}
|
||||
|
||||
void FormScenedlg::changeEvent(QEvent *e)
|
||||
{
|
||||
QWidget::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
ui->retranslateUi(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void FormScenedlg::on_addButton_clicked()
|
||||
{
|
||||
emit addButton();
|
||||
}
|
||||
|
||||
void FormScenedlg::on_EditItemButton_clicked()
|
||||
{
|
||||
emit EditItemButton();
|
||||
}
|
||||
|
||||
void FormScenedlg::on_delButton_clicked()
|
||||
{
|
||||
emit delButton();
|
||||
}
|
||||
|
||||
void FormScenedlg::on_newfileButton_clicked()
|
||||
{
|
||||
emit newfileButton();
|
||||
}
|
||||
|
||||
void FormScenedlg::on_openfileButton_clicked()
|
||||
{
|
||||
emit openfileButton();
|
||||
}
|
||||
|
||||
void FormScenedlg::on_previewButton_clicked()
|
||||
{
|
||||
pPicScene->clearSelection();
|
||||
foreach (QGraphicsItem *item, pPicScene->items()) {
|
||||
item->clearFocus();
|
||||
item->setSelected(false);
|
||||
}
|
||||
//ui->previewButton->setFocus();
|
||||
emit previewButton();
|
||||
}
|
||||
|
||||
void FormScenedlg::on_saveButton_clicked()
|
||||
{
|
||||
emit saveButton();
|
||||
}
|
||||
|
||||
void FormScenedlg::on_saveAsButton_clicked()
|
||||
{
|
||||
emit saveAsButton();
|
||||
}
|
||||
//edit@12-06 放大
|
||||
void FormScenedlg::on_enlargeButton_clicked()
|
||||
{
|
||||
emit enlargeButton();
|
||||
adjustItemsPos();
|
||||
//QTimer::singleShot(100,this,SLOT(adjustItemsPos()));
|
||||
}
|
||||
|
||||
void FormScenedlg::on_reduceButton_clicked()
|
||||
{
|
||||
emit reduceButton();
|
||||
adjustItemsPos();
|
||||
//QTimer::singleShot(100,this,SLOT(adjustItemsPos()));
|
||||
}
|
||||
|
||||
void FormScenedlg::on_KeyLeft_clicked()
|
||||
{
|
||||
pViewer->setFocus();
|
||||
#ifndef Q_OS_WIN32
|
||||
QWSServer::sendKeyEvent(0,Qt::Key_Left,Qt::NoModifier,true,false); //向系统发送键盘事件
|
||||
#endif
|
||||
//QTimer::singleShot(10,this,SLOT(adjustItemsPosFalse()));
|
||||
}
|
||||
|
||||
void FormScenedlg::on_KeyUp_clicked()
|
||||
{
|
||||
pViewer->setFocus();
|
||||
#ifndef Q_OS_WIN32
|
||||
QWSServer::sendKeyEvent(0,Qt::Key_Up,Qt::NoModifier,true,false); //向系统发送键盘事件
|
||||
#endif
|
||||
//QTimer::singleShot(10,this,SLOT(adjustItemsPosFalse()));
|
||||
}
|
||||
|
||||
void FormScenedlg::on_KeyRight_clicked()
|
||||
{
|
||||
pViewer->setFocus();
|
||||
#ifndef Q_OS_WIN32
|
||||
QWSServer::sendKeyEvent(0,Qt::Key_Right,Qt::NoModifier,true,false); //向系统发送键盘事件
|
||||
#endif
|
||||
//QTimer::singleShot(10,this,SLOT(adjustItemsPosFalse()));
|
||||
}
|
||||
|
||||
void FormScenedlg::on_KeyDown_clicked()
|
||||
{
|
||||
pViewer->setFocus();
|
||||
#ifndef Q_OS_WIN32
|
||||
QWSServer::sendKeyEvent(0,Qt::Key_Down,Qt::NoModifier,true,false); //向系统发送键盘事件
|
||||
#endif
|
||||
//QTimer::singleShot(10,this,SLOT(adjustItemsPosFalse()));
|
||||
}
|
||||
|
||||
void FormScenedlg::on_insertImage_clicked()
|
||||
{
|
||||
if(dialogFileOperation)
|
||||
{
|
||||
dialogFileOperation->refreshListView(PICFILE);
|
||||
dialogFileOperation->exec();
|
||||
}
|
||||
}
|
||||
|
||||
void FormScenedlg::on_ZoomOrigin_clicked()
|
||||
{
|
||||
adjustItemsPos(false);
|
||||
}
|
||||
|
||||
void FormScenedlg::on_btn_test2_clicked()
|
||||
{
|
||||
emit ZoomOrigin();
|
||||
|
||||
}
|
||||
|
||||
//edit@12-11 选中下一个图元
|
||||
void FormScenedlg::on_itemNext_clicked()
|
||||
{
|
||||
QList<QGraphicsItem *> items=pPicScene->items();
|
||||
if(!items.empty())
|
||||
{
|
||||
int index=0;
|
||||
for(index=0;index<items.size();index++)
|
||||
{
|
||||
if(items.at(index)->isSelected())break;
|
||||
}
|
||||
|
||||
pPicScene->clearSelection();
|
||||
if(index+1<items.size())
|
||||
{
|
||||
index+=1;
|
||||
//edit@12-11选中下一个
|
||||
items.at(index)->setSelected(true);
|
||||
items.at(index)->setFocus();
|
||||
}
|
||||
else
|
||||
{
|
||||
//edit@12-11 超范围,滚动到第一个
|
||||
index=0;
|
||||
items.front()->setSelected(true);
|
||||
items.front()->setFocus();
|
||||
}
|
||||
//PrintselectedItemInfo();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//edit@12-11选中上一个图元
|
||||
void FormScenedlg::on_itemPrev_clicked()
|
||||
{
|
||||
QList<QGraphicsItem *> items=pPicScene->items();
|
||||
if(!items.empty())
|
||||
{
|
||||
int index=0;
|
||||
for(index=0;index<items.size();index++)
|
||||
{
|
||||
if(items.at(index)->isSelected())break;
|
||||
}
|
||||
|
||||
pPicScene->clearSelection();
|
||||
if(0<=index-1)
|
||||
{
|
||||
index-=1;
|
||||
//edit@12-11选中前一个
|
||||
items.at(index)->setSelected(true);
|
||||
items.at(index)->setFocus();
|
||||
}
|
||||
else
|
||||
{
|
||||
//edit@12-11 超范围,滚动到最后位置
|
||||
index=items.size()-1;
|
||||
items.back()->setSelected(true);
|
||||
items.back()->setFocus();
|
||||
}
|
||||
//PrintselectedItemInfo();
|
||||
}
|
||||
}
|
||||
|
||||
void FormScenedlg::PrintselectedItemInfo()
|
||||
{
|
||||
foreach (QGraphicsItem *item, pPicScene->items()) {
|
||||
if(item->isSelected())
|
||||
{
|
||||
qDebug()<<"PrintselectedItemInfo-pos="<<item->pos();
|
||||
//qDebug()<<"PrintselectedItemInfo-pos="<<pPicScene->views().front()->mapFromScene(item->pos());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//edit@12-11 自动调整元素位置到原点
|
||||
void FormScenedlg::adjustItemsPos(bool bMoveScrollBar)
|
||||
{
|
||||
if(bMoveScrollBar)
|
||||
{
|
||||
pViewer->verticalScrollBar()->setValue(0);
|
||||
pViewer->horizontalScrollBar()->setValue(0);
|
||||
}
|
||||
|
||||
QPointF movePoint;
|
||||
const 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=QPointF(qCeil(oldpos.x()-left-1),qCeil(oldpos.y()-(top-pViewer->mapToScene(0,0).y()+1)));
|
||||
oldpos=QPointF(qCeil(oldpos.x()-left),qCeil(oldpos.y()-(top-pViewer->mapToScene(0,0).y())));
|
||||
item->setPos(oldpos);
|
||||
if(item->isSelected())movePoint=oldpos;
|
||||
}
|
||||
|
||||
if(bMoveScrollBar)
|
||||
{
|
||||
//pViewer->verticalScrollBar()->setValue(0);
|
||||
//pViewer->horizontalScrollBar()->setValue(0);
|
||||
|
||||
if(0<movePoint.x())
|
||||
{
|
||||
movePoint=pViewer->mapFromScene(movePoint.x(),movePoint.y());
|
||||
//pViewer->verticalScrollBar()->setValue(movePoint.y());
|
||||
pViewer->horizontalScrollBar()->setValue(movePoint.x());
|
||||
}
|
||||
}
|
||||
|
||||
if(!pPicScene->items().empty())pPicScene->update();
|
||||
|
||||
//qDebug()<<"adjustItemsPos="<<bMoveScrollBar;
|
||||
}
|
||||
void FormScenedlg::showQLayout(QLayout *layout,bool visible)
|
||||
{
|
||||
for (int i = 0; i < layout->count(); ++i) {
|
||||
QLayoutItem *item = layout->itemAt(i);
|
||||
if (QWidget *widget = item->widget()) {
|
||||
visible?widget->show():widget->hide();
|
||||
} else if (QLayout *subLayout = item->layout()) {
|
||||
showQLayout(subLayout,visible);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QObject *FormScenedlg::findChildAll(const QLayout *layout,const QString &name)
|
||||
{
|
||||
for (int i = 0; i < layout->count(); ++i) {
|
||||
QLayoutItem *item = layout->itemAt(i);
|
||||
if (QObject *widget = item->widget()) {
|
||||
if(widget->objectName()==name)return widget;
|
||||
} else if (QLayout *subLayout = item->layout()) {
|
||||
if(subLayout->objectName()==name)return subLayout;
|
||||
QObject *q= findChildAll(subLayout,name);
|
||||
if(q)return q;continue;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
void FormScenedlg::onFileOpen(QString filePath,bool ){
|
||||
pPicScene->clearSelection();
|
||||
QString html = "<img src='" + filePath + "'/>";
|
||||
textEdit->setHtml (html);
|
||||
textItem = new PicTextItem();
|
||||
pPicScene->addItem(textItem);
|
||||
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(this->pViewer->mapToScene(0,0));//edit@12-07
|
||||
textItem->setSelected(true);
|
||||
textItem->setHtml(textEdit->toHtml());
|
||||
}
|
||||
|
||||
void FormScenedlg::reset_showTextWidthHeight()
|
||||
{
|
||||
const QRectF BoundingRect=pPicScene->itemsBoundingRect();
|
||||
QLabel *labelTextWidthHeight=dynamic_cast<QLabel*>(FormScenedlg::findChildAll(tabMainWindow->layout(),"labelTextWidthHeight"));
|
||||
if(labelTextWidthHeight && 1<BoundingRect.height())
|
||||
{
|
||||
qreal bottomItem[2]={-1};//txt,img
|
||||
foreach (QGraphicsItem *item, pPicScene->items()) {
|
||||
if(item->x()<0)item->setX(0);
|
||||
if(item->y()<0)item->setY(0);
|
||||
//const int i=-1==((QGraphicsTextItem*)item)->toHtml().indexOf("img ",0,Qt::CaseInsensitive)?0:1;
|
||||
const int i=-1==((QGraphicsTextItem*)item)->toHtml().indexOf("home/plg/doc/",0,Qt::CaseInsensitive)?0:1;
|
||||
if(item->sceneBoundingRect().bottom()>bottomItem[i])
|
||||
{
|
||||
bottomItem[i]=item->sceneBoundingRect().bottom();
|
||||
}
|
||||
}
|
||||
QString newText;
|
||||
int HighlightedValue=0;
|
||||
if(bottomItem[1]+1>=bottomItem[0])
|
||||
{
|
||||
HighlightedValue=qCeil(bottomItem[1]-BoundingRect.y());
|
||||
newText=tr("[ %1行 x %2列 ]").arg(HighlightedValue).arg(qCeil(BoundingRect.width()));
|
||||
}
|
||||
else
|
||||
{
|
||||
HighlightedValue=qCeil(bottomItem[0]-BoundingRect.y()-2);
|
||||
newText=tr("[ %1行 x %2列 ]").arg(HighlightedValue).arg(qCeil(BoundingRect.width()));
|
||||
}
|
||||
|
||||
const QString oldText=labelTextWidthHeight->text();
|
||||
if(32<HighlightedValue)
|
||||
{
|
||||
//edit@12-17 超出范围的高亮提示
|
||||
labelTextWidthHeight->setText(tr("<html><head/><body><p>[<span style=\"color:red;font-size:12px;\"> %1行 </span>x %2列 ]</p></body></html>")
|
||||
.arg(HighlightedValue).arg(qCeil(BoundingRect.width())));
|
||||
}
|
||||
else
|
||||
{
|
||||
labelTextWidthHeight->setText(newText);
|
||||
}
|
||||
|
||||
if(oldText!=newText)
|
||||
{
|
||||
//QTimer::singleShot(10,this,SLOT(adjustItemsPos()));
|
||||
QTimer::singleShot(10,this,SLOT(adjustItemsPosFalse()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FormScenedlg::on_itemFirst_clicked()
|
||||
{
|
||||
int index=-1;
|
||||
const QRectF sceneRect=pPicScene->sceneRect();
|
||||
qreal left=sceneRect.width();
|
||||
QList<QGraphicsItem *> allitems=pPicScene->items();
|
||||
for(int i =0;i<allitems.size();i++)
|
||||
{
|
||||
allitems.at(i)->clearFocus();
|
||||
allitems.at(i)->setSelected(false);
|
||||
if(left>allitems.at(i)->pos().x())
|
||||
{
|
||||
index=i;
|
||||
left=allitems.at(i)->pos().x();
|
||||
}
|
||||
}
|
||||
if(-1!=index)pPicScene->items().at(index)->setSelected(true);
|
||||
adjustItemsPos();
|
||||
}
|
||||
|
||||
void FormScenedlg::on_itemLast_clicked()
|
||||
{
|
||||
pPicScene->clearSelection();
|
||||
int index=-1;
|
||||
const QRectF sceneRect=pPicScene->sceneRect();
|
||||
qreal left=0;
|
||||
QList<QGraphicsItem *> allitems=pPicScene->items();
|
||||
for(int i =0;i<allitems.size();i++)
|
||||
{
|
||||
allitems.at(i)->clearFocus();
|
||||
allitems.at(i)->setSelected(false);
|
||||
if(left<allitems.at(i)->pos().x())
|
||||
{
|
||||
index=i;
|
||||
left=allitems.at(i)->pos().x();
|
||||
}
|
||||
}
|
||||
if(-1!=index)pPicScene->items().at(index)->setSelected(true);
|
||||
adjustItemsPos();
|
||||
}
|
||||
|
||||
//void FormScenedlg::onSceneRectChanged(const QString &text)
|
||||
//{
|
||||
// qDebug()<<"FormScenedlg::sceneRectChanged=";
|
||||
//}
|
||||
@@ -0,0 +1,127 @@
|
||||
#ifndef FORMSCENEDLG_H
|
||||
#define FORMSCENEDLG_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QGraphicsView>
|
||||
#include <QKeyEvent>
|
||||
#include <QWSServer>
|
||||
#include <QBoxLayout>
|
||||
#include <QTimer>
|
||||
#include <QLabel>
|
||||
#include <QTextEdit>
|
||||
#include <QFontDatabase>
|
||||
#include <qmath.h>
|
||||
#include "picscene.h"
|
||||
#include "DialogFileOperation.h"
|
||||
#include "pictextitem.h"
|
||||
#include "myinclude.h"
|
||||
#include "Public.h"
|
||||
namespace Ui {
|
||||
class FormScenedlg;
|
||||
}
|
||||
|
||||
class FormScenedlg : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FormScenedlg(QWidget *parent = 0);
|
||||
~FormScenedlg();
|
||||
void bindScene(PicScene *pPicScene, QGraphicsView *pGraphicViewer,QTextEdit *pTextEdit);
|
||||
|
||||
|
||||
static void showQLayout(QLayout *layout, bool visible=true);
|
||||
static QObject *findChildAll(const QLayout *layout, const QString &name);
|
||||
void Layout_ToNew();
|
||||
void Layout_ToDefault();
|
||||
public slots:
|
||||
//void onSceneRectChanged(const QString &text);
|
||||
protected:
|
||||
void changeEvent(QEvent *e);
|
||||
|
||||
signals:
|
||||
void delButton();
|
||||
void saveButton();
|
||||
void openfileButton();
|
||||
void previewButton();
|
||||
void addButton();
|
||||
void EditItemButton();
|
||||
void saveAsButton();
|
||||
void newfileButton();
|
||||
void enlargeButton();
|
||||
void reduceButton();
|
||||
void ZoomOrigin();
|
||||
void btn_test2();
|
||||
private slots:
|
||||
void on_addButton_clicked();
|
||||
|
||||
void on_EditItemButton_clicked();
|
||||
|
||||
void on_delButton_clicked();
|
||||
|
||||
void on_newfileButton_clicked();
|
||||
|
||||
void on_openfileButton_clicked();
|
||||
|
||||
void on_previewButton_clicked();
|
||||
|
||||
void on_saveButton_clicked();
|
||||
|
||||
void on_saveAsButton_clicked();
|
||||
|
||||
void on_enlargeButton_clicked();
|
||||
|
||||
void on_reduceButton_clicked();
|
||||
|
||||
void on_KeyLeft_clicked();
|
||||
|
||||
void on_KeyUp_clicked();
|
||||
|
||||
void on_KeyRight_clicked();
|
||||
|
||||
void on_KeyDown_clicked();
|
||||
|
||||
void on_insertImage_clicked();
|
||||
|
||||
void on_ZoomOrigin_clicked();
|
||||
|
||||
void on_btn_test2_clicked();
|
||||
|
||||
void on_itemNext_clicked();
|
||||
|
||||
void on_itemPrev_clicked();
|
||||
|
||||
void PrintselectedItemInfo();
|
||||
void adjustItemsPos(bool bMoveScrollBar=true);
|
||||
void adjustItemsPosFalse(){adjustItemsPos(false);}
|
||||
void sceneRectChanged_timerHandler();
|
||||
void verticalScrollBar_valueChanged(int value);
|
||||
void horizontalScrollBar_valueChanged(int value);
|
||||
void onFileOpen(QString filePath, bool insertFlag);
|
||||
void reset_showTextWidthHeight();
|
||||
void on_itemFirst_clicked();
|
||||
|
||||
void on_itemLast_clicked();
|
||||
|
||||
|
||||
private:
|
||||
Ui::FormScenedlg *ui;
|
||||
PicScene *pPicScene;
|
||||
QGraphicsView *pViewer;
|
||||
|
||||
QSize SWmaximumSize1;
|
||||
QRect SWgeometry1;
|
||||
QRect FVgeometry2;
|
||||
QRect GVgeometry3;
|
||||
QPoint lastOriginScene;
|
||||
QWidget *tabMainWindow;
|
||||
DialogFileOperation *dialogFileOperation;
|
||||
QTextEdit *textEdit;
|
||||
PicTextItem *textItem;
|
||||
|
||||
|
||||
// QWidget interface
|
||||
protected:
|
||||
};
|
||||
|
||||
#endif // FORMSCENEDLG_H
|
||||
@@ -0,0 +1,866 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>FormScenedlg</class>
|
||||
<widget class="QWidget" name="FormScenedlg">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>258</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="gridLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>510</x>
|
||||
<y>90</y>
|
||||
<width>281</width>
|
||||
<height>161</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_keygroup">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="horizontalSpacing">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="verticalSpacing">
|
||||
<number>18</number>
|
||||
</property>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="KeyDown">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../image.qrc">
|
||||
<normaloff>:/icon/keydown.png</normaloff>:/icon/keydown.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="KeyLeft">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../image.qrc">
|
||||
<normaloff>:/icon/keyleft.png</normaloff>:/icon/keyleft.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="KeyRight">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../image.qrc">
|
||||
<normaloff>:/icon/keyright.png</normaloff>:/icon/keyright.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="KeyUp">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../image.qrc">
|
||||
<normaloff>:/icon/keyup.png</normaloff>:/icon/keyup.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="itemLast">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::RightToLeft</enum>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QPushButton{spacing:0px;}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Last</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../image.qrc">
|
||||
<normaloff>:/icon/keyend.png</normaloff>:/icon/keyend.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="itemFirst">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>First</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../image.qrc">
|
||||
<normaloff>:/icon/keyhome.png</normaloff>:/icon/keyhome.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="ZoomOrigin">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>425</x>
|
||||
<y>189</y>
|
||||
<width>71</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 800 16pt "wenquanyi";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>重置位置</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="btn_test2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>430</x>
|
||||
<y>50</y>
|
||||
<width>61</width>
|
||||
<height>101</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Test2</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="saveAsButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>150</x>
|
||||
<y>170</y>
|
||||
<width>131</width>
|
||||
<height>81</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>另存为</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="saveButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>11</x>
|
||||
<y>170</y>
|
||||
<width>131</width>
|
||||
<height>81</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>保存</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="previewButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>11</x>
|
||||
<y>0</y>
|
||||
<width>131</width>
|
||||
<height>81</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="palette">
|
||||
<palette>
|
||||
<active>
|
||||
<colorrole role="WindowText">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Button">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>85</red>
|
||||
<green>170</green>
|
||||
<blue>127</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Light">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>127</red>
|
||||
<green>255</green>
|
||||
<blue>191</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Midlight">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>106</red>
|
||||
<green>212</green>
|
||||
<blue>159</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Dark">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>42</red>
|
||||
<green>85</green>
|
||||
<blue>63</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Mid">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>56</red>
|
||||
<green>113</green>
|
||||
<blue>84</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Text">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="BrightText">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>255</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="ButtonText">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Base">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>255</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Window">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>85</red>
|
||||
<green>170</green>
|
||||
<blue>127</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Shadow">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="AlternateBase">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>170</red>
|
||||
<green>212</green>
|
||||
<blue>191</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="ToolTipBase">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>220</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="ToolTipText">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
</active>
|
||||
<inactive>
|
||||
<colorrole role="WindowText">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Button">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>85</red>
|
||||
<green>170</green>
|
||||
<blue>127</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Light">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>127</red>
|
||||
<green>255</green>
|
||||
<blue>191</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Midlight">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>106</red>
|
||||
<green>212</green>
|
||||
<blue>159</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Dark">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>42</red>
|
||||
<green>85</green>
|
||||
<blue>63</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Mid">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>56</red>
|
||||
<green>113</green>
|
||||
<blue>84</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Text">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="BrightText">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>255</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="ButtonText">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Base">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>255</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Window">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>85</red>
|
||||
<green>170</green>
|
||||
<blue>127</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Shadow">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="AlternateBase">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>170</red>
|
||||
<green>212</green>
|
||||
<blue>191</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="ToolTipBase">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>220</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="ToolTipText">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
</inactive>
|
||||
<disabled>
|
||||
<colorrole role="WindowText">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>42</red>
|
||||
<green>85</green>
|
||||
<blue>63</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Button">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>85</red>
|
||||
<green>170</green>
|
||||
<blue>127</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Light">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>127</red>
|
||||
<green>255</green>
|
||||
<blue>191</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Midlight">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>106</red>
|
||||
<green>212</green>
|
||||
<blue>159</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Dark">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>42</red>
|
||||
<green>85</green>
|
||||
<blue>63</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Mid">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>56</red>
|
||||
<green>113</green>
|
||||
<blue>84</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Text">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>42</red>
|
||||
<green>85</green>
|
||||
<blue>63</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="BrightText">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>255</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="ButtonText">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>42</red>
|
||||
<green>85</green>
|
||||
<blue>63</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Base">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>85</red>
|
||||
<green>170</green>
|
||||
<blue>127</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Window">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>85</red>
|
||||
<green>170</green>
|
||||
<blue>127</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="Shadow">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="AlternateBase">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>85</red>
|
||||
<green>170</green>
|
||||
<blue>127</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="ToolTipBase">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>220</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
<colorrole role="ToolTipText">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
</disabled>
|
||||
</palette>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>预览</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="addButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>11</x>
|
||||
<y>84</y>
|
||||
<width>131</width>
|
||||
<height>81</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QPushButton#evilButton {
|
||||
background-color: blue;
|
||||
border-style: outset;
|
||||
border-width: 2px;
|
||||
border-radius: 10px;
|
||||
border-color: beige;
|
||||
font: bold 14px;
|
||||
min-width: 10em;
|
||||
padding: 6px;
|
||||
}
|
||||
QPushButton#evilButton:pressed {
|
||||
background-color: rgb(224, 0, 0);
|
||||
border-style: inset;
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>新增图元</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="itemNext">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>480</x>
|
||||
<y>230</y>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Next-item</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="newfileButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>150</x>
|
||||
<y>0</y>
|
||||
<width>131</width>
|
||||
<height>81</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>新建</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="openfileButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>290</x>
|
||||
<y>0</y>
|
||||
<width>131</width>
|
||||
<height>81</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>打开</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="delButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>290</x>
|
||||
<y>170</y>
|
||||
<width>131</width>
|
||||
<height>81</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>删除图元</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="EditItemButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>290</x>
|
||||
<y>84</y>
|
||||
<width>131</width>
|
||||
<height>81</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>编辑图元</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="insertImage">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>150</x>
|
||||
<y>84</y>
|
||||
<width>131</width>
|
||||
<height>81</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>插入图像</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="itemPrev">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>460</x>
|
||||
<y>230</y>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Prev-item</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="reduceButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>510</x>
|
||||
<y>0</y>
|
||||
<width>131</width>
|
||||
<height>81</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>场景缩小</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="enlargeButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>660</x>
|
||||
<y>0</y>
|
||||
<width>131</width>
|
||||
<height>81</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>场景放大</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../image.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,64 @@
|
||||
#include "myview.h"
|
||||
#include <QWheelEvent>
|
||||
#include "picscene.h"
|
||||
#include <QDebug>
|
||||
MyView::MyView(QWidget *parent) :
|
||||
QGraphicsView(parent)
|
||||
{
|
||||
zoomRatio = 1;
|
||||
//setDragMode(QGraphicsView::ScrollHandDrag);//手型拖动
|
||||
//setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
//setFocusPolicy( Qt::NoFocus );
|
||||
}
|
||||
static float a = 1.61;
|
||||
void MyView::ZoomOut(void)
|
||||
{
|
||||
if(zoomRatio < 6)
|
||||
{
|
||||
zoomRatio++;
|
||||
// scale(2,2);
|
||||
scale(a,a);
|
||||
}
|
||||
}
|
||||
|
||||
void MyView::ZoomIn(void)
|
||||
{
|
||||
if(zoomRatio > 2)
|
||||
{
|
||||
zoomRatio--;
|
||||
scale(1/a,1/a);
|
||||
}
|
||||
}
|
||||
|
||||
//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,28 @@
|
||||
#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,172 @@
|
||||
#if 1
|
||||
#include "picscene.h"
|
||||
#include <QDebug>
|
||||
#include <QRectF>
|
||||
#include <QPainter>
|
||||
#include <QGraphicsView>
|
||||
PicScene::PicScene(QObject *parent) :
|
||||
QGraphicsScene(parent),IsdrawBackground(false)
|
||||
{
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
update();//edit@12-12
|
||||
#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);
|
||||
}
|
||||
//edit@12-09
|
||||
void PicScene::drawBackground(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
QGraphicsScene::drawBackground(painter,rect);
|
||||
|
||||
if(IsdrawBackground)
|
||||
{
|
||||
Q_UNUSED(rect);
|
||||
QPen pen;
|
||||
|
||||
const qreal left=rect.left();
|
||||
const qreal right=rect.right();
|
||||
const qreal top=rect.top();
|
||||
const qreal bottom=rect.bottom();
|
||||
|
||||
const int step=1;
|
||||
//pen.setColor(QColor(60,60,60));
|
||||
pen.setColor(Qt::lightGray);
|
||||
//pen.setColor(Qt::darkCyan);
|
||||
pen.setWidth(0);
|
||||
//pen.setStyle(Qt::DashLine);
|
||||
painter->setPen(pen);
|
||||
//绘制横线
|
||||
//绘制Y轴正半轴
|
||||
for(int i=0;i>=top;i-=step)
|
||||
{
|
||||
painter->drawLine(left,i,right,i);
|
||||
}
|
||||
|
||||
//绘制Y轴负半轴
|
||||
for(int i=0;i<=bottom;i+=step)
|
||||
{
|
||||
painter->drawLine(left,i,right,i);
|
||||
}
|
||||
|
||||
//绘制竖线
|
||||
//绘制X轴正半轴
|
||||
for(int i=0;i<=right;i+=step)
|
||||
{
|
||||
painter->drawLine(i,top,i,bottom);
|
||||
}
|
||||
//绘制X轴负半轴
|
||||
for(int i=0;i>=left;i-=step)
|
||||
{
|
||||
painter->drawLine(i,top,i,bottom);
|
||||
}
|
||||
|
||||
//edit@12-11
|
||||
pen.setColor(Qt::green);
|
||||
painter->setPen(pen);
|
||||
QRectF BoundingRect=this->itemsBoundingRect();
|
||||
BoundingRect.setHeight(32);
|
||||
painter->drawRect(BoundingRect);
|
||||
}
|
||||
|
||||
emit showTextWidthHeight();
|
||||
}
|
||||
//edit@12-09
|
||||
void PicScene::setIsdrawBackground(bool newIsdrawBackground)
|
||||
{
|
||||
IsdrawBackground = newIsdrawBackground;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,76 @@
|
||||
#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);
|
||||
void setIsdrawBackground(bool newIsdrawBackground);
|
||||
signals:
|
||||
//void itemInserted(DiagramItem *item);
|
||||
void textInserted(QGraphicsTextItem *item);
|
||||
void itemSelected(QGraphicsItem *item);
|
||||
void xmlContentChanged();
|
||||
//void sceneRectChanged(const QRectF &rect);//edit@12-12
|
||||
void showTextWidthHeight();
|
||||
void adjustItemsPos();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||
void drawBackground(QPainter *painter, const QRectF &rect);
|
||||
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;
|
||||
private:
|
||||
bool IsdrawBackground;
|
||||
};
|
||||
#endif
|
||||
#endif // PICSCENE_H
|
||||
@@ -0,0 +1,149 @@
|
||||
#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 0
|
||||
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 )
|
||||
{
|
||||
//edit@12-07
|
||||
QPointF newPos = this->pos();
|
||||
//qDebug()<<"mouseReleaseEvent-tem->pos="<<newPos;
|
||||
this->setPos(qCeil(newPos.x()),qCeil(newPos.y()));
|
||||
scene()->update();
|
||||
|
||||
|
||||
// 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)
|
||||
{
|
||||
foreach (QGraphicsItem *item, scene()->selectedItems()) {
|
||||
if(event->key() == Qt::Key_Left)
|
||||
{
|
||||
item->moveBy(-1, 0);
|
||||
}
|
||||
else if(event->key() == Qt::Key_Right)
|
||||
{
|
||||
item->moveBy(1, 0);
|
||||
}
|
||||
else if(event->key() == Qt::Key_Up)
|
||||
{
|
||||
item->moveBy(0, -1);
|
||||
}
|
||||
else if(event->key() == Qt::Key_Down)
|
||||
{
|
||||
item->moveBy(0, 1);
|
||||
}
|
||||
}
|
||||
if(!scene()->selectedItems().empty())
|
||||
{
|
||||
scene()->update();
|
||||
}
|
||||
|
||||
//QPointF newPos = this->pos();
|
||||
//const 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);
|
||||
// //edit@12-09
|
||||
// this->setPos(view->mapToScene(newPos.x(),newPos.y()));
|
||||
// }
|
||||
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