diff --git a/ofdEditor/model/Command/SetTextBlodCmd.cpp b/ofdEditor/model/Command/SetTextBlodCmd.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9bbc0e9d137952e62d0fbbdc3cec0bfbeb9d7af9 --- /dev/null +++ b/ofdEditor/model/Command/SetTextBlodCmd.cpp @@ -0,0 +1,22 @@ +#include "SetTextBlodCmd.h" +#include + +SetTextBlodCmd::SetTextBlodCmd(DocTextBlock *docTextBlock, QTextCursor &cursor, QUndoCommand *parent) +{ + m_docTextBlock=docTextBlock; + m_cursor=cursor; +} + +void SetTextBlodCmd::undo() +{ + QTextCharFormat fmt; + fmt.setFontWeight(QFont::Normal); + m_docTextBlock->mergeFormatOnWordOrSelection(m_cursor,fmt); +} + +void SetTextBlodCmd::redo() +{ + QTextCharFormat fmt; + fmt.setFontWeight(QFont::Bold); + m_docTextBlock->mergeFormatOnWordOrSelection(m_cursor,fmt); +} diff --git a/ofdEditor/model/Command/SetTextBlodCmd.h b/ofdEditor/model/Command/SetTextBlodCmd.h new file mode 100644 index 0000000000000000000000000000000000000000..89f76b6c10ea0008991ceaf7268c0e542aac56a0 --- /dev/null +++ b/ofdEditor/model/Command/SetTextBlodCmd.h @@ -0,0 +1,28 @@ +#ifndef COMMANDS_H +#define COMMANDS_H + +#include +#include +#include + +class DocPassage; +class DocTextBlock; +class DocPage; +class DocLayer; + +class SetTextBlodCmd:public QUndoCommand +{ +public: + SetTextBlodCmd(DocTextBlock *docTextBlock,QTextCursor &cursor,QUndoCommand *parent=0); + + // QUndoCommand interface +public: + void undo(); + void redo(); + +private: + DocTextBlock *m_docTextBlock; + QTextCursor m_cursor; +}; + +#endif // COMMANS_H diff --git a/ofdEditor/model/Convert/Doc_OFDConvertor.cpp b/ofdEditor/model/Convert/Doc_OFDConvertor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..82ca3b2c79100b80062f327cd9a826f70d607e2e --- /dev/null +++ b/ofdEditor/model/Convert/Doc_OFDConvertor.cpp @@ -0,0 +1,49 @@ +#include "Doc_OFDConvertor.h" +#include "Doc/DocPassage.h" +#include "Doc/DocPage.h" +#include "Doc/DocBlock.h" +#include "Doc/DocTextBlock.h" +#include "Doc/DocLayer.h" + +#include "DataTypes/basic_datatype.h" +#include "DataTypes/document/ofd.h" + + + +Doc_OFDConvertor::Doc_OFDConvertor(QObject *parent) + : QObject(parent) +{ + +} + +/** + * @Author Chaoqun + * @brief 将Doc文件转换为ofd文件类型,启动程序 + * @param DocPassage *passage + * @return OFD* + * @date 2017/06/22 + */ +OFD *Doc_OFDConvertor::doc_to_ofd(DocPassage *passage) +{ + +} + +void Doc_OFDConvertor::buildDocInfo() +{ + +} + +void Doc_OFDConvertor::buildPage() +{ + +} + +void Doc_OFDConvertor::buildLayer(DocLayer *layer) +{ + +} + +void Doc_OFDConvertor::buildText(DocTextBlock *textBlock) +{ + +} diff --git a/ofdEditor/model/Convert/Doc_OFDConvertor.h b/ofdEditor/model/Convert/Doc_OFDConvertor.h new file mode 100644 index 0000000000000000000000000000000000000000..79b32bdb55f5f1cbe662c9ffbebf8842a9e8e006 --- /dev/null +++ b/ofdEditor/model/Convert/Doc_OFDConvertor.h @@ -0,0 +1,44 @@ +#ifndef DOC_OFDCONVERTOR_H +#define DOC_OFDCONVERTOR_H + +#include +#include "model_global.h" + +class DocPassage; // 文章 +class DocPage; // 页 +class DocLayer; // 层 +class DocBlock; // 块 +class DocTextBlock; // 文本框 + +class OFD; // OFD文件模型 + +/** + * @Author Chaoqun + * @brief 将文章转换成为一个 OFD文件,直至保存为.ofd文件 + * @date 2017/06/22 + */ +class MODELSHARED_EXPORT Doc_OFDConvertor + : public QObject +{ + Q_OBJECT +public: + explicit Doc_OFDConvertor(QObject *parent = 0); + OFD *doc_to_ofd(DocPassage* passage); // 执行程序入口 + +signals: + +public slots: + +private: + void buildDocInfo(); // 存储DocInfo相关的信息 + void buildPage(); // 储存文本信息,顺便整理文件 + void buildLayer(DocLayer* layer); // 将一层中的信息存储出来 + void buildText(DocTextBlock* textBlock); // 将DocTextBlock中的信息转换处理 + +private: + DocPassage* passage; // 文章 + OFD* ofdFile; // OFD对象 + +}; + +#endif // DOC_OFDCONVERTOR_H diff --git a/ofdEditor/model/Convert/OFD_DocConvertor.cpp b/ofdEditor/model/Convert/OFD_DocConvertor.cpp index efa7b27338728f95b32d219c31cbd69d2f67f7da..ea000f202013c38ad93bd693bd1de9c984472350 100644 --- a/ofdEditor/model/Convert/OFD_DocConvertor.cpp +++ b/ofdEditor/model/Convert/OFD_DocConvertor.cpp @@ -13,7 +13,9 @@ #include "Tool/UnitTool.h" #include "DataTypes/text/TextCode.h" #include "DataTypes/text/CT_Text.h" - +#include "DataTypes/image/CT_DrawParam.h" +#include "DataTypes/Color/CT_ColorSpace.h" +#include "Convert/Objects/MinTextUnit.h" OFD_DocConvertor::OFD_DocConvertor() { @@ -30,18 +32,20 @@ OFD_DocConvertor::OFD_DocConvertor() DocPassage *OFD_DocConvertor::ofd_to_doc(OFD *ofd) { DocPassage * passage = NULL; + this->ofdFile = ofd; try{ passage = new DocPassage(); - + passage->setVisible(false); // version passage->setVersion(ofd->getOfdVersion()); passage->setDocType(ofd->getDocType()); QVector * bodys = ofd->getDocBodies(); DocBody * docBody = (*bodys)[0]; // DocBody - passage->setDocInfo(*(docBody->getDocInfo())); + + passage->setDocInfo(*(docBody->getDocInfo())); // 设置文档元信息 Document * document = (*(ofd->getDocuments()))[0]; // Document @@ -54,9 +58,8 @@ DocPassage *OFD_DocConvertor::ofd_to_doc(OFD *ofd) { // 生成每一页 - DocPage * newPage = this->buildDocPage((*pages)[i]); + DocPage * newPage = this->buildDocPage(passage, (*pages)[i]); newPage->setVisible(true); - passage->addPage(newPage); } } catch(...) @@ -64,10 +67,11 @@ DocPassage *OFD_DocConvertor::ofd_to_doc(OFD *ofd) qDebug() << "ofd_to_doc:exception."; } + passage->setVisible(true); return passage; } -DocPage *OFD_DocConvertor::buildDocPage(Page *ct_page) +DocPage *OFD_DocConvertor::buildDocPage(DocPassage *passage, Page *ct_page) { DocPage * page; try @@ -88,6 +92,7 @@ DocPage *OFD_DocConvertor::buildDocPage(Page *ct_page) page = new DocPage(); } + passage->addPage(page); // 加入到文章中来 page->setVisible(false); // 先隐藏显示 // 将每一层加入到页中 @@ -95,7 +100,7 @@ DocPage *OFD_DocConvertor::buildDocPage(Page *ct_page) for(int i = 0; i < layers->size(); i++) { CT_Layer* layer = (*layers)[i]; - qDebug() << "excute insertLayer: " << i; +// qDebug() << "excute insertLayer: " << i; this->insertLayer(page,layer); // 将该层的内容加入到页面中 } @@ -190,69 +195,111 @@ void OFD_DocConvertor::insertPageBlock(DocPage *page, */ void OFD_DocConvertor::insertCT_Text(DocPage *page, DocPage::Layer layer, CT_Text *text) { -// qDebug() << "execute insert CT_Text"; +// qDebug() << "execute insert CT_Text" << text->getID(); + CT_Color * fillColor = text->getFillColor(); // 获得填充颜色 + QColor color = this->ctColorToQColor(fillColor); // 获得填充颜色 + + CT_Base* base_font = + (*this->ofdFile->getDocuments())[0] + ->getIDTable()->getItem( + text->getFont().getRefID()); + QFont textFont; + if(base_font != NULL) + { + // 确保存在该数据 + CT_Font* ctFont = (CT_Font*) base_font; + QString font_name = ctFont->getFontName(); // 字体名 + QString family_name = ctFont->getFamilyName(); // 字体族名 +// qDebug() << font_name << " "<< family_name; + textFont.setFamily(family_name); +// qDebug() << "After setting font family :"<* textCodes = text->getTextCode(); + // 处理每一个textCode + QVector* textCodes = text->getTextCode(); // 获得文字内容 + int length = textCodes->size(); // 数量 +// qDebug() << "textCodes' length:" << length; + for(int i = 0 ; i< length; i++) + { + TextCode* textCode = (*textCodes)[i]; // 当前处理的块 +// qDebug() << "deal with current textcode:" << i; + + // 求出单个块的保卫面积 + double height = text->getSize(); // 高等于字体的高 + double width = 0; // 所有deltax相加再加上一个字宽 + double x = text->boundary.getX() + textCode->getX(); // 左上角 x坐标 + double y = text->boundary.getY() + textCode->getY() - height; // 左上角y值 + + // 计算宽度 + ST_Array arrayDeltaX = textCode->getDeltaX(); +// qDebug() << "deltax length" <getText(); // 文本内容 +// qDebug() << "has compute the boundary"; -// qDebug() << "insert Content:" << content; + // 获得文本内容 + QString content = textCode->getText(); // 文本内容 - DocTextBlock *textBlock = new DocTextBlock(); - DocBlock *block = new DocBlock(); - block->setWidget(textBlock); + qDebug() << "insert Content:" << content; - ST_Box box = text->getBoundary(); - block->resize(UnitTool::mmToPixel(box.getDeltaX()), - UnitTool::mmToPixel(box.getDeltaY())); - block->setPos(UnitTool::mmToPixel(box.getX()), - UnitTool::mmToPixel(box.getY())); + DocTextBlock *textBlock = new DocTextBlock(); // 新建文本块 + DocBlock *block = new DocBlock(); // 新建块 + block->setWidget(textBlock); // 将块放入文本块中 - QTextCursor cursor = textBlock->textCursor(); // 获得光标 + block->resize(UnitTool::mmToPixel(width), + UnitTool::mmToPixel(height)); // 调整块大小 + block->setPos(UnitTool::mmToPixel(x), + UnitTool::mmToPixel(y)); // 设置位置 - // 去掉QTextEdit的无用的边框 - textBlock->document()->setDocumentMargin(0); // document - QTextFrame * frame = textBlock->document()->rootFrame(); - QTextFrameFormat frameFormat = frame->frameFormat(); // frameFormat - // 清除没用的边缘距离 - frameFormat.setTopMargin(0); - frameFormat.setBottomMargin(0); - frameFormat.setLeftMargin(0); - frameFormat.setRightMargin(0); - frameFormat.setPadding(0); + QTextCursor cursor = textBlock->textCursor(); // 获得光标 - frame->setFrameFormat(frameFormat); // 应用Frame格式 + // 去掉QTextEdit的无用的边框 + textBlock->document()->setDocumentMargin(0); // document + QTextFrame * frame = textBlock->document()->rootFrame(); + QTextFrameFormat frameFormat = frame->frameFormat(); // frameFormat - QTextBlockFormat blockFormat = cursor.blockFormat(); // 块格式 - QTextCharFormat charFormat = cursor.charFormat(); // 字符格式 - QFont font = charFormat.font(); // 字体 + // 清除没用的边缘距离 + frameFormat.setTopMargin(0); + frameFormat.setBottomMargin(0); + frameFormat.setLeftMargin(0); + frameFormat.setRightMargin(0); + frameFormat.setPadding(0); - // 字号 - font.setPixelSize(UnitTool::mmToPixel(text->getSize())); // 字号 + frame->setFrameFormat(frameFormat); // 应用Frame格式 - // 上下间距 - blockFormat.setTopMargin(0); - blockFormat.setBottomMargin(0); - blockFormat.setLeftMargin(0); - blockFormat.setRightMargin(0); - blockFormat.setLineHeight(0,QTextBlockFormat::MinimumHeight); + QTextBlockFormat blockFormat = cursor.blockFormat(); // 块格式 + QTextCharFormat charFormat = cursor.charFormat(); // 字符格式 + QFont font = charFormat.font(); // 字体 + font.setPixelSize(UnitTool::mmToPixel(text->getSize())); // 字号 + font.setFamily(textFont.family()); // 设置字体 - // 应用格式 - charFormat.setFont(font); // 应用字体格式 - cursor.setCharFormat(charFormat); // 应用字符格式 - cursor.setBlockFormat(blockFormat); // 应用文字块样式 + // 上下间距 + blockFormat.setTopMargin(0); + blockFormat.setBottomMargin(0); + blockFormat.setLeftMargin(0); + blockFormat.setRightMargin(0); + blockFormat.setLineHeight(0,QTextBlockFormat::MinimumHeight); -// qDebug() <<"Set Format"; + // 应用格式 + charFormat.setFont(font); // 应用字体格式 + charFormat.setForeground(color); // 设置文字颜色 + cursor.setCharFormat(charFormat); // 应用字符格式 + cursor.setBlockFormat(blockFormat); // 应用文字块样式 - cursor.insertText(content); + cursor.insertText(content); // 插入文本 +// qDebug()<<"page->addBlock"; + page->addBlock(block,layer); // 插入到场景中 - // 插入到场景中 - page->addBlock(block,layer); + } } @@ -265,3 +312,88 @@ void OFD_DocConvertor::insertCT_Image(DocPage *page, DocPage::Layer layer, CT_Im { } + +/** + * @Author Chaoqun + * @brief 将CT_Color转换为QColor + * @param CT_Color *ct_color + * @return QColor + * @date 2017/06/22 + */ +QColor OFD_DocConvertor::ctColorToQColor(CT_Color *ct_color) +{ + + QColor defaultColor(Qt::black); // 设置默认颜色 + + Document* document = (*this->ofdFile->getDocuments())[0]; + ID_Table* table = document->getIDTable(); + + CT_Base* base = table->getItem( + ct_color->getColorSpace().getRefID()); + + // 返回NULL 就判断为默认颜色 + if(base == NULL) + { + return defaultColor; + } + CT_ColorSpace* colorSpace = (CT_ColorSpace*)base; // 获得颜色空间 + + QString colorType = colorSpace->getType(); // 获得颜色类型 + colorType.toUpper(); // 转换为大写字母 + + ST_Array value = ct_color->getValue(); // 颜色的值 + + if(colorType == "RGB") + { + // 如果是RGB颜色空间 + if(value.length() < 3) + { + return defaultColor; + } + + // rgb + int red = value[0].toInt(); + int green = value[1].toInt(); + int blue = value[2].toInt(); + + QColor color; + color.setRgb(red,green,blue); + return color; + } + else if(colorType == "GRAY") + { + // 如果是GRAY颜色空间 + if(value.length() < 1) + { + return defaultColor; + } + int gray = value[0].toInt(); + QColor color; + color.setRgb(gray,gray,gray); + } + else if(colorType == "CMYK") + { + // 如果是CMYK颜色空间 + if(value.length() < 4) + { + return defaultColor; + } +// qDebug() << value[0] << value[1] << value[2] << value[3]; + + // cyan (C), magenta (M), yellow (Y) and black (K) + int cyan = value[0].toInt(); + int magenta = value[1].toInt(); + int yellow = value[2].toInt(); + int black = value[3].toInt(); + QColor color; + color.setCmyk(cyan,magenta,yellow,black); + return color; + } + else + { + // 如果都不是 + qDebug() << "Can't search the accurate color"; + return defaultColor; + } + +} diff --git a/ofdEditor/model/Convert/OFD_DocConvertor.h b/ofdEditor/model/Convert/OFD_DocConvertor.h index a63689246e5d801bd79a09be49a48d9bd04eaf49..035c0008d28d09002fe70197ef6751ff1806451a 100644 --- a/ofdEditor/model/Convert/OFD_DocConvertor.h +++ b/ofdEditor/model/Convert/OFD_DocConvertor.h @@ -14,6 +14,7 @@ class CT_PageBlock; class CT_Text; class CT_Path; class CT_Image; +class CT_Color; /** * @Author Chaoqun @@ -27,31 +28,34 @@ class MODELSHARED_EXPORT OFD_DocConvertor public: OFD_DocConvertor(); - DocPassage * ofd_to_doc(OFD * ofd); // 生成文档 + DocPassage * ofd_to_doc(OFD * ofd); // 生成文档 private: OFD * ofdFile; // 当前处理时使用的ofd文件-用来方便获取到公用的特征 - DocPage * buildDocPage(Page * ct_page); // 生成页 + DocPage * buildDocPage(DocPassage * passage , + Page * ct_page); // 生成页 void insertLayer(DocPage * page, - CT_Layer * layer ); // 将每一层加入到页中 + CT_Layer * layer ); // 将每一层加入到页中 void insertPageBlock(DocPage * page, CT_Layer * layer, - CT_PageBlock* pageBlock); // 用于针对块可能嵌套的情况 + CT_PageBlock* pageBlock); // 用于针对块可能嵌套的情况 void insertCT_Text(DocPage * page, DocPage::Layer layer, - CT_Text *text); // 插入CT_Text类 + CT_Text *text); // 插入CT_Text类 void insertCT_Path(DocPage * page, CT_Layer * layer, - CT_Path *path); // 插入CT_Path + CT_Path *path); // 插入CT_Path void insertCT_Image(DocPage * page, DocPage::Layer layer, - CT_Image *image); // 插入CT_Image + CT_Image *image); // 插入CT_Image + + QColor ctColorToQColor(CT_Color* ct_color); // 颜色转换 }; diff --git a/ofdEditor/model/Convert/Objects/MinTextUnit.cpp b/ofdEditor/model/Convert/Objects/MinTextUnit.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6cd92672e95d7742dceee9cb086373e5ae16dae3 --- /dev/null +++ b/ofdEditor/model/Convert/Objects/MinTextUnit.cpp @@ -0,0 +1,6 @@ +#include "MinTextUnit.h" + +MinTextUnit::MinTextUnit(QObject *parent) : QObject(parent) +{ + +} diff --git a/ofdEditor/model/Convert/Objects/MinTextUnit.h b/ofdEditor/model/Convert/Objects/MinTextUnit.h new file mode 100644 index 0000000000000000000000000000000000000000..6d13f5f508d640ac0f3d77d29fda92bb0ae4739c --- /dev/null +++ b/ofdEditor/model/Convert/Objects/MinTextUnit.h @@ -0,0 +1,37 @@ +#ifndef MINTEXTUNIT_H +#define MINTEXTUNIT_H + +#include +#include +#include +#include +#include + +#include "model_global.h" + +// 中间转换的数据类型,为了求速度,全部设为公有数据. +class MODELSHARED_EXPORT MinTextUnit + : public QObject +{ + Q_OBJECT +public: + explicit MinTextUnit(QObject *parent = 0); + + + +signals: + +public slots: + +public: + QColor fillColor; // 填充颜色 + QColor strokeColor; // 描边颜色 + QFont font; // 字体 + double x,y; // 左下角坐标 + QString text; // 内容 + double lt_x,lt_y,width,height; // 边界 + QVector delta_x; // 偏移量 + +}; + +#endif // MINTEXTUNIT_H diff --git a/ofdEditor/model/Doc/DocBlock.cpp b/ofdEditor/model/Doc/DocBlock.cpp index d3b297f04906a7c641a9b2364a65ecd3b68a6e86..49d029f4d105af777008056a5a84e2e004afb8d9 100644 --- a/ofdEditor/model/Doc/DocBlock.cpp +++ b/ofdEditor/model/Doc/DocBlock.cpp @@ -10,6 +10,11 @@ #include #include +#include "Doc/DocTextBlock.h" +#include "Doc/DocLayer.h" +#include "Doc/DocPage.h" +#include "Doc/DocPassage.h" + DocBlock::DocBlock(QGraphicsItem *parent , Qt::WindowFlags wFlags) :QGraphicsProxyWidget(parent,wFlags) { @@ -26,6 +31,34 @@ DocBlock::DocBlock(QGraphicsItem *parent , Qt::WindowFlags wFlags) this->setAcceptHoverEvents(true); } +/** + * @Author Chaoqun + * @brief 获得所在的页 + * @param void + * @return DocPage* + * @date 2017/06/21 + */ +DocPage *DocBlock::getPage() +{ + DocLayer* layer = this->getLayer(); + return layer->getPage(); +} + +/** + * @Author Chaoqun + * @brief 获得文章 + * @param void + * @return DocPassage * + * @date 2017/06/21 + */ +DocPassage *DocBlock::getPassage() +{ + DocPage* page = this->getPage(); + if(page == NULL) + return NULL; + return page->getPassage(); +} + /** * @Author Chaoqun * @brief 绘制控制器 @@ -93,10 +126,39 @@ void DocBlock::resize(const QSizeF &size) */ void DocBlock::setZValue(qreal z) { +// qDebug()<<"setZValue:" << z; QGraphicsProxyWidget::setZValue(z); this->realZValue = z; // 设置本地记录 } +/** + *@Author Chaoqun + *@brief 槽函数,设置Block坐标位置 + *@param qreal x + *@param qreal y + *@return 返回值 + *@date 2017/06/20 + */ +void DocBlock::setPos(qreal x, qreal y) +{ + QGraphicsProxyWidget::setPos(x,y); +} + +/** + *@Author Chaoqun + *@brief 从场景中移除本框 + *@param void + *@return void + *@date 2017/06/20 + */ +void DocBlock::remove() +{ + QGraphicsScene *scene = this->scene(); // 查找到本块所在的场景 + scene->removeItem(this); // 从场景中移除该组件 + + emit this->signals_blockRemoved(this); // 发出信号 +} + /** * @Author Chaoqun @@ -165,17 +227,17 @@ void DocBlock::hoverMoveEvent(QGraphicsSceneHoverEvent *event) || (this->currentStatus(event->pos()) == blockResize && this->isFocused)) { - this->setCursor(Qt::SizeFDiagCursor); // 设置为角落缩放 + this->setCursor(Qt::SizeFDiagCursor); // 设置为角落缩放 } else if(this->rectAdjust == blockMove || (this->currentStatus(event->pos()) == blockMove && this->isFocused)) { - this->setCursor(Qt::SizeAllCursor); // 设置为移动样式 + this->setCursor(Qt::SizeAllCursor); // 设置为移动样式 } else if(this->cursor().shape() != Qt::IBeamCursor) { -// this->unsetCursor(); // 取消设置鼠标-效果不好 +// this->unsetCursor(); // 取消设置鼠标-效果不好 // qDebug() <<"Redo hoverEnterEvent"; QGraphicsProxyWidget::hoverEnterEvent(event); // 执行重新进入,设置鼠标 } @@ -259,16 +321,47 @@ void DocBlock::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) * @brief 可以实现右键菜单 * @param 参数 * @return 返回值 - * @date 2017/xx/xx + * @date 2017/06/20 */ void DocBlock::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { -// QMenu menu; -// QAction *removeAction = menu.addAction("Remove"); -// QAction *markAction = menu.addAction("Mark"); QGraphicsProxyWidget::contextMenuEvent(event); } +/** + * @Author Chaoqun + * @brief 设置内容 + * @param QWidget *widget + * @return void + * @date 2017/06/20 + */ +void DocBlock::setWidget(QWidget *widget) +{ + QGraphicsProxyWidget::setWidget(widget); +} + +/** + * @Author Chaoqun + * @brief 多台的函数,方便在加入DocTextBlock时建立一些信号槽 + * @param QWidget *widget + * @return 返回值 + * @date 2017/06/20 + */ +void DocBlock::setWidget(DocTextBlock *textBlock) +{ + // 建立connect + connect(textBlock,SIGNAL(signals_remove(DocTextBlock*)), + this,SLOT(remove())); // 和块做移除连接 + connect(textBlock,SIGNAL(signals_setZValue(qreal)), + this,SLOT(setZValue(qreal))); // 建立设置Z值的信号连接 + + textBlock->setBlock(this); // 给DocTextBlock设置引用 + this->textBlock = textBlock; // 给DocBlock设置引用 + + QGraphicsProxyWidget::setWidget(textBlock); +} + + /** * @Author Chaoqun * @brief 检查鼠标是否在重置大小区域 @@ -317,3 +410,34 @@ DocBlock::RectAdjustStatus DocBlock::currentStatus(const QPointF &pos) return blockNone; } +/** + * @Author Chaoqun + * @brief 判断是其中装的是否是DocTextBlock + * @param void + * @return bool + * @date 2017/06/23 + */ +bool DocBlock::isTextBlock() +{ + if(this->textBlock == NULL) + { + return false; + } + else + { + return true; + } +} + +/** + * @Author Chaoqun + * @brief 获得DocTextBlock + * @param void + * @return DocTextBlock* + * @date 2017/06/23 + */ +DocTextBlock *DocBlock::getTextBlock() +{ + return this->textBlock; +} + diff --git a/ofdEditor/model/Doc/DocBlock.h b/ofdEditor/model/Doc/DocBlock.h index 0e70625d6ab52013266ccab5f6e91c453ece8073..76fbfdea3eba7affeea64d418023caa4e65ccdfd 100644 --- a/ofdEditor/model/Doc/DocBlock.h +++ b/ofdEditor/model/Doc/DocBlock.h @@ -8,6 +8,9 @@ class DocLayer; class QPainter; +class DocTextBlock; +class DocPage; +class DocPassage; /** @@ -25,47 +28,59 @@ public: DocBlock(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); enum RectAdjustStatus{blockNone , blockResize , blockMove}; // 对块的大小状态进行调整 - RectAdjustStatus rectAdjust; // 用来标识当前修改尺寸的状态 + RectAdjustStatus rectAdjust; // 用来标识当前修改尺寸的状态 + DocLayer * getLayer(){return this->layer;} // 获得所在的层 + DocPage * getPage(); // 获得所在页 + DocPassage *getPassage(); // 获得所在文章 + void paintHandle(QPainter& painter); // 绘制负责变换的控制器 + qreal getZValue(){return this->realZValue;} // 获得当前块所在的Z值 + RectAdjustStatus currentStatus(const QPointF& pos); // 鼠标所在位置可以进行什么调整 - void setLayer(DocLayer * layer){this->layer = layer;} - DocLayer * getLayer(){return this->layer;} + bool isTextBlock(); // 判断是否DocBlock装的是否是DocTextBlock + DocTextBlock *getTextBlock(); // 获得DocTextBlock - void paintHandle(QPainter& painter); // 绘制负责变换的控制器 +public slots: // 槽函数 + void setLayer(DocLayer * layer){this->layer = layer;} void resize(qreal w, qreal h); // 继承函数 void resize(const QSizeF &size); // 继承函数 - void setZValue(qreal z); // 继承该函数 + void setPos(qreal x, qreal y); // 设置位置 + // 移动位置应该在所在的DocPage中吧…… + void remove(); // 从场景中移除本框 + void setWidget(QWidget* widget); // 旧的函数 + void setWidget(DocTextBlock *textBlock); // SetWidget protected: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget) override; - // 用来绘制变化 - void focusInEvent(QFocusEvent *event) override; // 焦点关注 - void focusOutEvent(QFocusEvent *event) override; // 焦点离开 + QWidget *widget); // 用来绘制变化 + void focusInEvent (QFocusEvent *event); // 焦点关注 + void focusOutEvent (QFocusEvent *event); // 焦点离开 // 用来修改鼠标 - void hoverMoveEvent(QGraphicsSceneHoverEvent *event); // 鼠标悬浮响应 - void mousePressEvent(QGraphicsSceneMouseEvent * event) override; - void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; - void mouseReleaseEvent(QGraphicsSceneMouseEvent * event) override; + void hoverMoveEvent (QGraphicsSceneHoverEvent *event); // 鼠标悬浮响应 + void mousePressEvent (QGraphicsSceneMouseEvent * event); + void mouseMoveEvent (QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent (QGraphicsSceneMouseEvent * event); + void contextMenuEvent (QGraphicsSceneContextMenuEvent *event); // 邮件菜单吧 - void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); private: - DocBox boundary; // 该块的外包矩形 - DocLayer * layer; // 该块在哪一个层之中 + DocBox boundary; // 该块的外包矩形 + DocLayer * layer; // 该块在哪一个层之中 + QSizeF blockSize; // 用来纪录大小 + QPointF blockOldPos; // 用来记录旧的位置 - QSizeF blockSize; // 用来纪录大小 - QPointF blockOldPos; // 用来记录旧的位置 + DocTextBlock* textBlock; // 存下引用 - bool isFocused; // 是否被聚焦 - bool blockIsResizing; // 是否正在改变大小 + bool isFocused; // 是否被聚焦 + bool blockIsResizing; // 是否正在改变大小 bool isInResizeArea(const QPointF& pos); // 检查鼠标是否在重置大小区域 - qreal realZValue; //真是的z值 + qreal realZValue; // 真实的z值 + +signals: + void signals_blockRemoved(DocBlock* block); // 当本块被移除时发出信号 -public: - RectAdjustStatus currentStatus(const QPointF& pos); // 鼠标所在位置可以进行什么调整 }; #endif // DOCBLOCK_H diff --git a/ofdEditor/model/Doc/DocLayer.cpp b/ofdEditor/model/Doc/DocLayer.cpp index 1cafbdc0b38918241be9733e4031207468e1dc27..07da6603ff9f92799dc1ae9d93e39363f66c608e 100644 --- a/ofdEditor/model/Doc/DocLayer.cpp +++ b/ofdEditor/model/Doc/DocLayer.cpp @@ -2,7 +2,8 @@ #include "Doc/DocBlock.h" // 块 #include "Doc/DocTable.h" // 表格 #include "Doc/DocDrawParam.h" - +#include "Doc/DocPage.h" +#include "Doc/DocPassage.h" DocLayer::DocLayer() { @@ -79,6 +80,8 @@ void DocLayer::setZValue(qreal z) void DocLayer::addBlock(DocBlock *block) { this->blocks.append(block); // 追加到队尾 + block->setZValue(this->zValue); // 设置Z值 + block->setLayer(this); // 设置引用 } /** @@ -101,6 +104,18 @@ void DocLayer::removeBlock(DocBlock *block) } } +/** + * @Author Chaoqun + * @brief 设置页 + * @param DocPage * page + * @return void + * @date 2017/06/21 + */ +void DocLayer::setPage(DocPage *page) +{ + this->parent = page; +} + /** * @Author Chaoqun * @brief 获得本层的所有blocks @@ -119,3 +134,30 @@ QVector* DocLayer::getBlocks() return vector; } + +/** + * @Author Chaoqun + * @brief 获得页 + * @param void + * @return DocPage* + * @date 2017/06/21 + */ +DocPage *DocLayer::getPage() +{ + return this->parent; +} + +/** + * @Author Chaoqun + * @brief 获得文章 + * @param void + * @return DocPassage * + * @date 2017/06/21 + */ +DocPassage *DocLayer::getPassage() +{ + DocPage *page = this->getPage(); + if(page == NULL) + return NULL; + return page->getPassage(); +} diff --git a/ofdEditor/model/Doc/DocLayer.h b/ofdEditor/model/Doc/DocLayer.h index 5319f70344c89441d9dd7834007a14cd318ea517..d18bc3ed28848c8037368113aeea9e414259fb58 100644 --- a/ofdEditor/model/Doc/DocLayer.h +++ b/ofdEditor/model/Doc/DocLayer.h @@ -9,6 +9,7 @@ class DocBlock; // 块 class DocTable; // 表格 class DocDrawParam; // 默认绘画模式 +class DocPassage; // 文章 /** * @Author Chaoqun @@ -22,17 +23,21 @@ public: DocLayer(DocPage::Layer layer); ~DocLayer(); - void setZValue(qreal z); // 设置本层的 ZValue的值 - qreal getZValue(){return this->zValue;} // 获取本层的 ZValue的值 - void addBlock(DocBlock *block); // 添加Block - void removeBlock(DocBlock* block); // 移除Block - QVector *getBlocks(); // 获得所有Block + qreal getZValue(){return this->zValue;} // 获取本层的 ZValue的值 + QVector *getBlocks(); // 获得所有Block DocPage::Layer getLayer(){return type;} - void setLayer(DocPage::Layer layer){this->type = layer;} + DocPage* getPage(); // 找到层所在的Page + DocPassage *getPassage(); // 找到文章 +public slots: +void setZValue(qreal z); // 设置本层的 ZValue的值 +void addBlock(DocBlock *block); // 添加Block +void removeBlock(DocBlock* block); // 移除Block +void setLayer(DocPage::Layer layer){this->type = layer;} +void setPage(DocPage* page); // 设置page private: diff --git a/ofdEditor/model/Doc/DocPage.cpp b/ofdEditor/model/Doc/DocPage.cpp index ad3c760b0591296ee2df7b54cddee5477cf03566..e5c94f227a16e6917f46e2514fb2114d2f91dccc 100644 --- a/ofdEditor/model/Doc/DocPage.cpp +++ b/ofdEditor/model/Doc/DocPage.cpp @@ -8,6 +8,7 @@ #include "Doc/DocTable.h" #include "Doc/DocPicture.h" #include "Doc/DocGraph.h" +#include "Doc/DocPassage.h" #include #include @@ -45,6 +46,23 @@ DocPage::~DocPage() } +DocPassage *DocPage::getPassage() +{ + return this->passage; +} + +/** + * @Author Chaoqun + * @brief 设置文章引用 + * @param DocPassage *passage + * @return void + * @date 2017/06/20 + */ +void DocPage::setPassage(DocPassage *passage) +{ + this->passage = passage; // 设置 passage +} + /** * @Author Chaoqun @@ -91,10 +109,29 @@ QSize DocPage::getSize() void DocPage::addBlock(DocBlock *block, DocPage::Layer layer) { - qDebug() << "DocPage::addBlock excuted"; +// qDebug() << "DocPage::addBlock excuted"; this->docScene->addItem(block); // 添加元素 // qDebug() << "DocPage::addBlock excuted this->docScene->addItem(block);"; + // 插入DocTextBlock + if(block->isTextBlock()) + { + DocTextBlock* textBlock = block->getTextBlock(); // 获得TextBlock + DocPassage* passage = this->getPassage(); // 获得passage + emit this->signals_insertTextBlock(textBlock); // 发射信号 + + // 转发信号给passage + connect(textBlock,SIGNAL(signals_currentBlockFormatChanged(QTextBlockFormat&)), + passage,SIGNAL(signals_currentBlockFormatChanged(QTextBlockFormat&))); + connect(textBlock,SIGNAL(signals_currentCharFormatChanged(QTextCharFormat&)), + passage,SIGNAL(signals_currentCharFormatChanged(QTextCharFormat&))); + connect(textBlock,SIGNAL(signals_currentTextBlock(DocTextBlock*)), + passage,SIGNAL(signals_currentTextBlock(DocTextBlock*))); + + } +// qDebug()<< "connect"; + + // 分到层 switch (layer) { case Body: this->bodyLayer->addBlock(block); @@ -112,7 +149,6 @@ void DocPage::addBlock(DocBlock *block, DocPage::Layer layer) break; } - } /** @@ -161,6 +197,19 @@ void DocPage::setInsertBlockType(InsertBlockInfo &blockInfo) // qDebug()<<"Set InsertBlockInfo successfully!"; } +/** + * @Author Chaoqun + * @brief 从passage中移除本页内容 + * @param 参数 + * @return 返回值 + * @date 2017/06/23 + */ +void DocPage::remove() +{ + DocPassage * passage = this->getPassage(); + passage->removePage(this); +} + /** * @Author Chaoqun @@ -385,8 +434,16 @@ void DocPage::init() // 新建三个层 this->foregroundLayer = new DocLayer(Foreground); + this->foregroundLayer->setPage(this); + this->foregroundLayer->setZValue(1000); + this->bodyLayer = new DocLayer(DocPage::Body); + this->bodyLayer->setPage(this); + this->bodyLayer->setZValue(0); + this->backgroundLayer = new DocLayer(Background); + this->backgroundLayer->setPage(this); + this->backgroundLayer->setZValue(-1000); // this->setBackgroundRole(QPalette::Dark); this->insertBlockInfo = NULL; diff --git a/ofdEditor/model/Doc/DocPage.h b/ofdEditor/model/Doc/DocPage.h index aadda592626533def3443ba1d6a1bfa0c4fd19ed..8291d088990ef8cdf18391f3d5582deda2d7536b 100644 --- a/ofdEditor/model/Doc/DocPage.h +++ b/ofdEditor/model/Doc/DocPage.h @@ -16,6 +16,7 @@ class DocBlock; class DocTextBlock; class InsertBlockInfo; class DocPageScene; +class DocPassage; /** * @Author Chaoqun @@ -27,20 +28,25 @@ class MODELSHARED_EXPORT DocPage { Q_OBJECT public: - enum Layer{Body,Foreground,Background}; // 分为三层 + enum Layer{Body,Foreground,Background}; // 分为三层 enum BlockFlag{none,draw,drawMove,blockMove}; // 插入时的绘制状态 - enum BlockType{text,image,table}; // 插入时的类型 + enum BlockType{text,image,table}; // 插入时的类型 explicit DocPage(QWidget * parent = 0); DocPage(double width, double height, double scaleFactor,QWidget * parent = 0); ~DocPage(); - void setSize(double width, double height); // 设置页面大小 + DocPassage *getPassage(); // 获得文章 QSize getSize(); // 获得页面像素大小 double getWidth(){return width_mm;} // 返回毫米单位宽度 double getHeight(){return height_mm;} // 返回毫米单位高度 + BlockFlag getBlockFlag(){return this->newBlockFlag;} + +public slots: + void setSize(double width, double height); // 设置页面大小 + void setPassage(DocPassage * passage); // 设置文章 void addBlock(DocBlock* block, DocPage::Layer layer); // 为页面添加一个新元素 // void addBlock(DocTextBlock* textBlock, DocPage::Layer layer); // 为页面添加一个新元素 void addItem(QGraphicsItem *item); // 拓展接口 @@ -48,22 +54,22 @@ public: Qt::WindowFlags wFlags = Qt::WindowFlags()); void setBlockFlag(BlockFlag flag){this->newBlockFlag = flag;} - BlockFlag getBlockFlag(){return this->newBlockFlag;} - void setInsertBlockType(InsertBlockInfo& blockInfo); // 设置下一个要插入的block的信息 - + void setInsertBlockType(InsertBlockInfo& blockInfo); // 设置下一个要插入的block的信息 + void remove(); // 移除本页 protected: void paintEvent(QPaintEvent *event); - void mouseDoubleClickEvent(QMouseEvent *event) override; - void mousePressEvent(QMouseEvent *event) override; - void mouseMoveEvent(QMouseEvent *event) override; - void mouseReleaseEvent(QMouseEvent *event) override; - + void mouseDoubleClickEvent(QMouseEvent *event) ; + void mousePressEvent(QMouseEvent *event) ; + void mouseMoveEvent(QMouseEvent *event) ; + void mouseReleaseEvent(QMouseEvent *event) ; private: - DocPageScene* docScene; // 场景数据 - //QVector layers; // 一个文档具有很多层 + + void init(); // 初始化UI + DocPassage * passage; // 页所属文章 + DocPageScene* docScene; // 场景数据 DocLayer* foregroundLayer; // 前景层 DocLayer* bodyLayer; // 正文层 @@ -74,24 +80,24 @@ private: // 还应该有模板页 //CT_PageArea* area; // 页面大小描述 - double width_mm; // 页面的宽 --单位 mm - double height_mm; // 页面的高 - - double scaleFactor; // 表示缩放倍数 - - void init(); // 初始化UI + double width_mm; // 页面的宽 --单位 mm + double height_mm; // 页面的高 + double scaleFactor; // 表示缩放倍数 - QPointF oldPos; // 用来移动时使用,计算距离 - QPointF newPos; // 新点 + QPointF oldPos; // 用来移动时使用,计算距离 + QPointF newPos; // 新点 BlockFlag newBlockFlag; // 是否画块 - -// QList items; DocBlock * activeBlock; // 正在活跃的那个DocBlock +signals: // 信号 + + void signals_insertTextBlock(DocTextBlock* textBlock ); // 插入文本框信号 + void signals_removeTextBlock(DocTextBlock* textBlock ); // 移除文本框信号 }; + /** * @Author Chaoqun * @brief 希望用它来传递插入block的具体信息,包含层、类型等概念 diff --git a/ofdEditor/model/Doc/DocPassage.cpp b/ofdEditor/model/Doc/DocPassage.cpp index 347c9872fbad66e6a91ded9c6f409eb74758912b..66e39e58bfefb6b3460770157d2eef12c8837bf6 100644 --- a/ofdEditor/model/Doc/DocPassage.cpp +++ b/ofdEditor/model/Doc/DocPassage.cpp @@ -10,7 +10,7 @@ #include #include #include - +#include /** * @Author Chaoqun @@ -20,6 +20,7 @@ DocPassage::DocPassage(QWidget *parent) :docType("OFD"),version("1.0"),QScrollArea(parent) { + undoStack=new QUndoStack(this); this->scaleFactor = 1.0; // 缩放100% this->docInfo = new CT_DocInfo(); // 文档元信息 // this->commonData = new CT_CommonData(); @@ -40,6 +41,7 @@ DocPassage::DocPassage(QWidget *parent, QString version, QString docType, double scaleFactor) :QScrollArea(parent) { + undoStack=new QUndoStack(this); this->version = version; this->docType = docType; this->scaleFactor = scaleFactor; @@ -95,14 +97,13 @@ void DocPassage::addPage(DocPage *page) // 先添加到 vector this->pages.append(page); - - // 再添加到ScrollArea - + // 添加到ScrollArea this->adjustWidgetSize(); // 调整大小 - this->layout->addWidget(page,0,Qt::AlignCenter); // 向layout中增加一页,并居中显示 this->layout->update(); // 更新 + page->setPassage(this); // 设置页所属的文章 + qDebug() << "You have added an new page"; @@ -138,6 +139,43 @@ void DocPassage::appendNewPage(DocPage *page) this->addPage(page); // 此处调用addPage } +/** + * @Author Chaoqun + * @brief 移除指定的页 + * @param 参数 + * @return 返回值 + * @date 2017/06/20 + */ +void DocPassage::removePage(int index) +{ + DocPage* page = this->pages[index]; // 获取该页面数据 + this->removePage(page); // 移除页面 + +} + +/** + * @Author Chaoqun + * @brief 移除指定的页面 + * @param DocPage *page + * @return void + * @date 2017/06/20 + */ +void DocPassage::removePage(DocPage *page) +{ + int index = this->pages.indexOf(page); // 获取到该页所在的位置 +// qDebug()<<"pages size" << this->pages.size(); + + this->layout->removeWidget(page); // 从场景中移除页面 + page->deleteLater(); // 移除页面 + + this->pages.remove(index); // 从数据中移除页面 +// qDebug()<<"pages size" << this->pages.size(); + + this->adjustWidgetSize(); // 调整大小 + this->layout->update(); // 更新 + +} + /** * @Author Chaoqun * @brief 设置文档原信息 @@ -150,6 +188,18 @@ void DocPassage::setDocInfo(CT_DocInfo &docInfo) this->docInfo->copy(docInfo); } +/** + * @Author Chaoqun + * @brief 测试 + * @param 参数 + * @return 返回值 + * @date 2017/06/22 + */ +void DocPassage::testMessage() +{ + qDebug()<<"passage success"; +} + /** * @Author Chaoqun * @brief 获得文档原信息 @@ -157,11 +207,33 @@ void DocPassage::setDocInfo(CT_DocInfo &docInfo) * @return CT_DocInfo * @date 2017/05/23 */ -CT_DocInfo DocPassage::getDocInfo() +CT_DocInfo *DocPassage::getDocInfo() +{ + return this->docInfo; +} + +/** + * @Author Chaoqun + * @brief 获得文档中所有的页面 + * @param void + * @return 返回值 + * @date 2017/06/20 + */ +QVector &DocPassage::getPages() +{ + return this->pages; +} + +/** + * @Author Chaoqun + * @brief 获得某一页 + * @param int index + * @return DocPage * + * @date 2017/06/20 + */ +DocPage *DocPassage::getPage(int index) { - CT_DocInfo docInfo; - docInfo.copy( *this->docInfo); - return docInfo; + return this->pages[index]; } /** @@ -171,10 +243,10 @@ CT_DocInfo DocPassage::getDocInfo() * @return void * @date 2017/05/23 */ -//void DocPassage::setCommonData(CT_CommonData* commonData) -//{ -// (this->commonData)->copy(commonData); -//} +void DocPassage::setCommonData(CT_CommonData* commonData) +{ + this->commonData = commonData; +} /** * @Author Chaoqun @@ -183,13 +255,35 @@ CT_DocInfo DocPassage::getDocInfo() * @return CT_CommonData * @date 2017/05/23 */ -//CT_CommonData DocPassage::getCommonData() -//{ -// CT_CommonData common; -// common.copy(this->commonData); +CT_CommonData* DocPassage::getCommonData() +{ + return this->commonData; +} -// return common; -//} +/** + * @Author Chaoqun + * @brief 设置 docID + * @param void + * @return void + * @date 2017/06/23 + */ +void DocPassage::resetDocId() +{ + QUuid uuid = QUuid::createUuid(); // 创建uuid + QString docId = uuid.toString(); // 转换为字符串 + + // 去掉字符串的链接符号 {0142d46f-60b5-47cf-8310-50008cc7cb3a} + // 0142d46f60b547cf831050008cc7cb3a + docId.remove(docId.length()-1, 1); + docId.remove(docId.length() -13, 1); + docId.remove(docId.length() -17,1); + docId.remove(docId.length() -21, 1); + docId.remove(docId.length() - 25,1); + docId.remove(0,1); + qDebug() << "uuid : " << docId; + + this->docInfo->setDocID(docId); +} /** * @Author Chaoqun @@ -218,6 +312,8 @@ void DocPassage::closeEvent(QCloseEvent *event) void DocPassage::init() { + this->docInfo = new CT_DocInfo(); // 新建文档 元信息 + this->resetDocId(); // 设置UUID this->layout = new QVBoxLayout; // 新建布局 // 新增widget @@ -304,7 +400,8 @@ void DocPassage::adjustWidgetSize() height += verticalWhite; width += 2*horizontalWhite; - this->widget->setMinimumSize(width, height); // 设置内容大小 +// this->widget->setMinimumSize(width, height); // 设置内容大小 + this->widget->resize(width,height); // 保存计算结果 this->widgetWidth = width; @@ -318,8 +415,6 @@ void DocPassage::adjustWidgetSize() adjustScrollBar(this->verticalScrollBar(), this->scaleFactor); - - qDebug() <<"widget's Size"<widget->size(); qDebug() << "ScrollArea's Size" << this->size(); diff --git a/ofdEditor/model/Doc/DocPassage.h b/ofdEditor/model/Doc/DocPassage.h index 1e817a870488e62629d85c7cd6b1f89e6f383f55..9a5e7d23d0832023941885686e5253ba26793fe0 100644 --- a/ofdEditor/model/Doc/DocPassage.h +++ b/ofdEditor/model/Doc/DocPassage.h @@ -10,11 +10,18 @@ #include #include // 树状排布 #include +#include +#include +#include +#include + // 类声明 class DocPage; class CT_DocInfo; class CT_CommonData; +class DocBlock; +class DocTextBlock; /** * @Author Chaoqun @@ -31,42 +38,58 @@ public: QString docType,double scaleFactor); ~DocPassage(); + CT_DocInfo* getDocInfo(); // 获取CT_DocInfo数据 + QString getVersion( ){return this->version;} + QString getDocType( ){return this->docType;} + QVector& getPages(); // 获得文档中包含的所有页面 + DocPage *getPage(int index); // 获得文档中的某一页 + QUndoStack *undoStack; // 撤销队列 + +public slots: void addPage(DocPage *page); // 添加一个新页面 void addPassage(QVector& passage); // 添加很多界面 void appendNewPage(DocPage *page = NULL); // 如果为空,则代表假如空白页 + void removePage(int index); // 移除某一页 + void removePage(DocPage* page); // 移除某一页 + // DocInfo void setDocInfo( CT_DocInfo & docInfo ); - CT_DocInfo getDocInfo(); // CommonData -// void setCommonData(CT_CommonData* commonData); -// CT_CommonData getCommonData(); + void setCommonData(CT_CommonData* commonData); // 注意,设置的是直接的指针 + CT_CommonData* getCommonData(); // 注意,返回的是直接的指针 // Version void setVersion(QString version){this->version = version;} - QString getVersion( ){return this->version;} // DocType void setDocType(QString docType){this->docType = docType;} - QString getDocType( ){return this->docType;} + // docId + void resetDocId(); // 重新设置DocId + + void testMessage(); // 测试信号是否走通 protected: void resizeEvent(QResizeEvent* event); - void closeEvent(QCloseEvent *event); // 继承,关闭前提示保存 - private: // 数据区 QString version; // OFD 版本默认 1.0 QString docType; // 类型默认是 OFD CT_DocInfo* docInfo; // 文档元数据结构 ofd/CT_DocInfo -// CT_CommonData* commonData; // 文档公用文档数据 + CT_CommonData* commonData; // 文档公用文档数据 QVector pages; // 既作为数据,也作为渲染 + // 文件信息 + QString filePath; + QString fileName; + QString tempPath; // 保存成文件前的临时路径 + // 个人觉得可以用上UUID tmp/"uuid-fileName" + // 渲染区 QVBoxLayout * layout; // 纵向排列 QWidget * widget; // 用widget做缓冲 @@ -78,16 +101,21 @@ private: int horizontalWhite; // 白色页面左右两边的灰色区域 int verticalWhite; // 白色页面上下的灰色区域 - -private: - void init(); // 初始化 + void init(); // 初始化 void adjustScrollBar(QScrollBar *scrollBar, - double factor); // 调整滑动条 - void adjustScrollBarRange(); //调整滑动条范围 - void adjustWidgetSize(); // 根据页数来自动调整widget大小 - - - + double factor); // 调整滑动条 + void adjustScrollBarRange(); //调整滑动条范围 + void adjustWidgetSize(); // 根据页数来自动调整widget大小 + +signals: + void signals_insertTextBlock(DocTextBlock* textBlock); // 用来转发信号 + void signals_removeTextBlock(DocTextBlock* textBlock); // 用来转发信号 + + void signals_currentCharFormatChanged( + QTextCharFormat& fmt); // 当前选择的charFormat发生了变化 + void signals_currentBlockFormatChanged( + QTextBlockFormat& fmt); // 当前选择的block格式发生了变化 + void signals_currentTextBlock(DocTextBlock* textBlock); // 当前操作的textBlock }; diff --git a/ofdEditor/model/Doc/DocTextBlock.cpp b/ofdEditor/model/Doc/DocTextBlock.cpp index 27bebdcbc0ecd2b82a3d7be23d813de24d636335..e7d0582ea5bba26da4dc91e8def5b74af54da67a 100644 --- a/ofdEditor/model/Doc/DocTextBlock.cpp +++ b/ofdEditor/model/Doc/DocTextBlock.cpp @@ -2,6 +2,10 @@ #include "Doc/DocParagraph.h" #include "Widget/ParagraphFormatDialog.h" #include "Widget/FontSettingDialog.h" +#include "Doc/DocPage.h" +#include "Doc/DocLayer.h" +#include "Doc/DocPassage.h" +#include "Command/SetTextBlodCmd.h" #include #include @@ -13,13 +17,10 @@ #include + DocTextBlock::DocTextBlock(QWidget *parent) :QTextEdit(parent) { -// QTextCursor cursor(this->textCursor()); -// cursor.insertText(tr("testsesetstsetestes")); - -// this->setBackgroundRole(QPalette::Dark); this->init(); // 调用初始化函数 } @@ -42,6 +43,67 @@ void DocTextBlock::setContent(QString str) cursor.insertText(str); } +/** + * @Author Chaoqun + * @brief 获得文章 + * @param void + * @return 返回值 + * @date 2017/06/21 + */ +DocPassage *DocTextBlock::getPassage() +{ + DocPage* page = this->getPage(); // 查找所在的页 +// qDebug() << "getPassage success"; + if(page == NULL) + return NULL; + return page->getPassage(); // 返回所在页所在的文章 +} + +/** + * @Author Chaoqun + * @brief 获得所在的页 + * @param void + * @return DocPage* + * @date 2017/06/21 + */ +DocPage *DocTextBlock::getPage() +{ + DocLayer* layer = this->getLayer(); // 获得层 + if(layer == NULL) + return NULL; +// qDebug() << "GetPage success"; + return layer->getPage(); // 由层去获得passage +} + +/** + * @Author Chaoqun + * @brief 获得所在的层 + * @param void + * @return DocLayer* + * @date 2017/06/21 + */ +DocLayer *DocTextBlock::getLayer() +{ + DocBlock* block = this->block; + if(block == NULL) + return NULL; +// qDebug()<<"get layer success"; + return block->getLayer(); +} + +/** + * @Author Chaoqun + * @brief 获得Block的指针 + * @param void + * @return DocBlock* + * @date 2017/06/21 + */ +DocBlock *DocTextBlock::getBlock() +{ +// qDebug()<<"getBlock test success"; + return this->block; +} + /** * @Author Chaoqun * @brief 用来合并格式 @@ -66,41 +128,134 @@ void DocTextBlock::mergeFormatOnWordOrSelection( /** * @Author Chaoqun - * @brief 当前CharFormat样式发上改变的响应函数, - * 当增加了一个字体控制的widget时,可以使用 - * @param const QTextCharFormat &format + * @brief 合并指定光标下的char和文字格式 + * @param QTextCursor &cursor + * @param QTextCharFormat &format * @return void - * @date 2017/05/21 + * @date 2017/06/22 */ -void DocTextBlock::currentCharFormatChangedEvent( - const QTextCharFormat &format) +void DocTextBlock::mergeFormatOnWordOrSelection( + QTextCursor &cursor, QTextCharFormat &format) { + if(!cursor.hasSelection()) + { + // 如果没有选择文字段落 + cursor.select(QTextCursor::WordUnderCursor); + qDebug() << "cursor has no selection!"; + } + cursor.mergeCharFormat(format); // 合并光标下的 QTextCharFormat +// this->mergeCurrentCharFormat(format); // 合并当前的 QTextCharFormat +} +/** + * @Author Chaoqun + * @brief 合并当前光标下块的格式 + * @param QTextBlockFormat &blockFormat + * @return void + * @date 2017/06/22 + */ +void DocTextBlock::mergeBlockFormatOnBlock( + QTextBlockFormat &blockFormat) +{ + QTextCursor cursor = this->textCursor(); // 光标 + if(!cursor.hasSelection()) + { + cursor.select(QTextCursor::BlockUnderCursor); // 选择光标下的块 + } + + cursor.mergeBlockFormat(blockFormat); } /** * @Author Chaoqun - * @brief 光标位置发生改变时的响应函数 - * @param void + * @brief 合并给定光标下的块格式 + * @param QTextCursor &cursor + * @param QTextBlockFormat &blockFormat * @return void - * @date 2017/05/21 + * @date 2017/06/22 */ -void DocTextBlock::cursorPositionChangedEvent() +void DocTextBlock::mergeBlockFormatOnBlock( + QTextCursor cursor, QTextBlockFormat &blockFormat) { - // qDebug() << "Cursor Position Changed!"; + if(!cursor.hasSelection()) + { + cursor.select(QTextCursor::BlockUnderCursor); // 选择光标下的块 + } + + cursor.mergeBlockFormat(blockFormat); } + void DocTextBlock::setFont(const QFont &font) { -// QTextCharFormat currentFormat = -// this->currentCharFormat(); // 当前选择文字的样式 + QTextCursor cursor = this->textCursor(); QTextCharFormat currentFormat = cursor.charFormat(); currentFormat.setFont(font); // 设置字体 -// mergeCurrentCharFormat(currentFormat); - mergeFormatOnWordOrSelection(currentFormat); + mergeFormatOnWordOrSelection(currentFormat); // 合并字体样式 +} + +/** + * @Author Chaoqun + * @brief 设置给定光标下的字体格式 + * @param QTextCursor &cursor + * @param const QFont &font + * @return void + * @date 2017/06/22 + */ +void DocTextBlock::setFont( + QTextCursor &cursor, const QFont &font) +{ + QTextCharFormat currentFormat = cursor.charFormat(); + + currentFormat.setFont(font); // 设置字体 + + mergeFormatOnWordOrSelection(cursor, currentFormat); // 合并给定光标下的字体样式 +} + +/** + * @Author Chaoqun + * @brief 设置block + * @param DocBlock *block + * @return 返回值 + * @date 2017/06/21 + */ +void DocTextBlock::setBlock(DocBlock *block) +{ + this->block = block; // 设置Block +} + +/** + * @Author Chaoqun + * @brief 通知DocBlock,从DocPage中移除本文本框 + * @param void + * @return void + * @date 2017/06/20 + */ +void DocTextBlock::remove() +{ + emit signals_remove(this); // 发送信号,remove +} + +/** + * @Author Chaoqun + * @brief 控制是否显示文本框的边界 + * @param bool show + * @return void + * @date 2017/06/22 + */ +void DocTextBlock::showBoundaryFrame(bool show) +{ + if(show) + { + this->setFrameStyle(QFrame::Box); // 显示边框 + } + else + { + this->setFrameStyle(QFrame::NoFrame); // 隐藏边框 + } } @@ -113,14 +268,54 @@ void DocTextBlock::setFont(const QFont &font) * @date 2017/05/20 */ void DocTextBlock::textBold() +{ +// QTextCharFormat fmt; +// QTextCharFormat currentFormat = this->currentCharFormat(); // 当前选择文字的样式 +// fmt.setFontWeight(currentFormat.fontWeight() != QFont::Bold ? // 设置粗细 +// QFont::Bold : QFont::Normal); + +// mergeFormatOnWordOrSelection(fmt); // 合并格式 + QTextCursor cursor=this->textCursor(); + textBold(cursor,0); +} + +/** + * @Author Chaoqun + * @brief 使用QTextCursor作为参数,并且通过mode参数可以控制是否设置加粗, + * 方便Command操作进行使用 + * mode = -1 普通, + * mode = 0 一般模式同无参的这个函数 + * mode = 1 加粗 + * @param QTextCursor & + * @return void + * @date 2017/06/20 + */ +void DocTextBlock::textBold(QTextCursor &cursor, int mode) { QTextCharFormat fmt; - QTextCharFormat currentFormat = this->currentCharFormat(); // 当前选择文字的样式 - fmt.setFontWeight(currentFormat.fontWeight() != QFont::Bold ? // 设置粗细 - QFont::Bold : QFont::Normal); + QTextCharFormat currentCharFormat = cursor.charFormat(); + switch (mode) { + case -1: + fmt.setFontWeight(QFont::Normal); // 设置普通 + break; + case 0: + fmt.setFontWeight(currentCharFormat.fontWeight() != QFont::Bold ? // 设置粗细 + QFont::Bold : QFont::Normal); + break; + case 1: + fmt.setFontWeight(QFont::Bold); // 设置加粗 + break; + } - mergeFormatOnWordOrSelection(fmt); // 合并格式 + mergeFormatOnWordOrSelection(cursor,fmt); // 合并给定光标下的字体 + if(currentCharFormat.fontWeight()==QFont::Normal) + { + DocPassage *parentPassage=this->getPassage(); + QUndoCommand *setTextBlodCmd=new SetTextBlodCmd(this,cursor); + parentPassage->undoStack->push(setTextBlodCmd); + qDebug()<<"stack size:"<undoStack->count(); + } } /** @@ -141,6 +336,38 @@ void DocTextBlock::textUnderline() mergeFormatOnWordOrSelection(fmt); // 合并格式 } +/** + * @Author Chaoqun + * @brief 设置下划线 + * @param QTextCursor& cursor + * @param mode -1 取消下划线 + * @param mode 0 正常机制 + * @param mode 1 设置下划线 + * @return 返回值 + * @date 2017/06/22 + */ +void DocTextBlock::textUnderline(QTextCursor &cursor, int mode) +{ + QTextCharFormat fmt; + QTextCharFormat currentFormat = cursor.charFormat(); // 当前选择文字的样式 + + switch (mode) + { + case -1: + fmt.setFontUnderline(false); + break; + case 0: + fmt.setFontUnderline(currentFormat.fontUnderline()? + false:true); + case 1: + fmt.setFontUnderline(true); + default: + break; + } + + mergeFormatOnWordOrSelection(cursor,fmt); // 合并格式 +} + /** * @Author Chaoqun * @brief 设置斜体 @@ -158,6 +385,42 @@ void DocTextBlock::textItalic() mergeFormatOnWordOrSelection(fmt); // 合并格式 } +/** + * @Author Chaoqun + * @brief 设置斜体 + * @param QTextCursor &cursor 选中文字的光标 + * @param mode -1 取消斜体 + * @param mode 0 正常模式 + * @param mode 1 加入斜体 + * @return void + * @date 2017/06/22 + */ +void DocTextBlock::textItalic(QTextCursor &cursor, int mode) +{ + QTextCharFormat fmt; + QTextCharFormat currentFormat = cursor.charFormat(); // 当前选择文字的样式 + + switch (mode) { + case -1: + fmt.setFontItalic(false); // 取消斜体 + break; + case 0: + fmt.setFontItalic(currentFormat.fontItalic() == true? // 设置斜体 + false:true); + break; + case 1: + fmt.setFontItalic(true); // 设置斜体 + break; + default: + break; + } + + fmt.setFontItalic(currentFormat.fontItalic() == true? // 设置斜体 + false:true); + + mergeFormatOnWordOrSelection(cursor,fmt); // 合并格式 +} + /** * @Author Chaoqun * @brief 弹出一个段落属性设置的QDialog,设置好了后, @@ -199,6 +462,21 @@ void DocTextBlock::setTextColor() } +/** + * @Author Chaoqun + * @brief 摘要 + * @param 参数 + * @return 返回值 + * @date 2017/06/22 + */ +void DocTextBlock::setTextColor(QTextCursor& cursor,QColor color) +{ + QTextCharFormat fmt; + fmt.setForeground(color); // 设置前景-文字的颜色 + + mergeFormatOnWordOrSelection(cursor,fmt); +} + /** * @Author Chaoqun * @brief 通过字体小窗口设置字体 @@ -257,11 +535,36 @@ void DocTextBlock::setTextBlockFormat(QTextBlockFormat &blockFormat) } cursor.setBlockFormat(blockFormat); - qDebug()<<"Change the selected QTextBlock' Format. Test"; + + + // 发出信号 + emit this->signals_currentBlockFormatChanged(blockFormat); } +/** + * @Author Chaoqun + * @brief 设置给定光标下的块的格式 + * @param QTextCursor &cursor + * @param QTextBlockFormat &blockFormat + * @return void + * @date 2017/06/22 + */ +void DocTextBlock::setTextBlockFormat( + QTextCursor &cursor, QTextBlockFormat &blockFormat) +{ + if(!cursor.hasSelection()) + { + // 如果没有选择文字段落 + cursor.select(QTextCursor::WordUnderCursor); + qDebug() << "cursor has no selection!"; + } + + cursor.setBlockFormat(blockFormat); + +} + /** * @Author Chaoqun * @brief 直接修改选中的文字的CharFormat @@ -281,6 +584,59 @@ void DocTextBlock::setCharFormatOnWordOrSelection( } cursor.setCharFormat(format); // 设置光标下的 QTextCharFormat this->setCurrentCharFormat(format); // 合并当前的 QTextCharFormat + + // 发射信号 + emit this->signals_currentCharFormatChanged(format); +} + +/** + * @Author Chaoqun + * @brief 设置给定光标的char格式 + * @param QTextCursor &cursor + * @param QTextCharFormat &format + * @return void + * @date 2017/06/22 + */ +void DocTextBlock::setCharFormatOnWordOrSelection( + QTextCursor &cursor, QTextCharFormat &format) +{ + if(!cursor.hasSelection()) + { + // 如果没有选择文字段落 + cursor.select(QTextCursor::WordUnderCursor); + qDebug() << "cursor has no selection!"; + } + cursor.setCharFormat(format); // 设置光标下的 QTextCharFormat + this->setCurrentCharFormat(format); // 合并当前的 QTextCharFormat +} + +/** + * @Author Chaoqun + * @brief 设置选择文字的格式 + * @param QTextCharFormat &format + * @return void + * @date 2017/06/23 + */ +void DocTextBlock::setCharFormatOnSelection( + QTextCharFormat &format) +{ + QTextCursor cursor = this->textCursor(); // 获得光标 + cursor.setCharFormat(format); // 设置字符格式 + this->setTextCursor(cursor); // 并应用光标 +} + +/** + * @Author Chaoqun + * @brief 设置给定光标的,选择的文字的格式 + * @param QTextCursor &cursor + * @param QTextCharFormat &format + * @return void + * @date 2017/06/23 + */ +void DocTextBlock::serCharFormatOnSelection( + QTextCursor &cursor, QTextCharFormat &format) +{ + cursor.setCharFormat(format); // 设置字符格式 } /** @@ -293,15 +649,22 @@ void DocTextBlock::setCharFormatOnWordOrSelection( void DocTextBlock::contextMenuEvent(QContextMenuEvent *event) { - this->ContextMenu = createStandardContextMenu(); // 拓展标准菜单 - this->ContextMenu->addAction(this->actionBold); // 加粗 - this->ContextMenu->addAction(this->actionItalic); // 斜体 - this->ContextMenu->addAction(this->actionUnderline); // 下划线 - this->ContextMenu->addAction(this->actionColor); // 颜色 - this->ContextMenu->addSeparator(); // 分界线 - this->ContextMenu->addAction(this->actionFontSet); // 字体设置 - this->ContextMenu->addAction(this->actionParagraph); // 段落设置 - this->ContextMenu->addAction(this->actionFontSetTest);// 字体 + this->ContextMenu = createStandardContextMenu(); // 拓展标准菜单 + this->ContextMenu->addAction(this->actionBold); // 加粗 + this->ContextMenu->addAction(this->actionItalic); // 斜体 + this->ContextMenu->addAction(this->actionUnderline); // 下划线 + this->ContextMenu->addAction(this->actionColor); // 颜色 + this->ContextMenu->addSeparator(); // 分界线 + this->ContextMenu->addAction(this->actionFontSet); // 字体设置 + this->ContextMenu->addAction(this->actionParagraph); // 段落设置 + this->ContextMenu->addAction(this->actionFontSetTest); // 字体 + this->ContextMenu->addAction(this->actionRemove); // 移除操作 + + connect(this->ContextMenu, SIGNAL(aboutToHide()), + this,SLOT(contextMenuAboutToHideEvent())); // 测试 + + this->tempZValue = this->getBlock()->getZValue(); + emit this->signals_setZValue(2000); // 展示菜单 this->ContextMenu->exec(event->globalPos()); @@ -317,7 +680,10 @@ void DocTextBlock::contextMenuEvent(QContextMenuEvent *event) */ void DocTextBlock::focusInEvent(QFocusEvent *e) { - this->setFrameStyle(QFrame::Box); + this->showBoundaryFrame(true); + + emitFormatSignals(); // 当鼠标移进时,必须发出信号 + QTextEdit::focusInEvent(e); } @@ -330,10 +696,90 @@ void DocTextBlock::focusInEvent(QFocusEvent *e) */ void DocTextBlock::focusOutEvent(QFocusEvent *e) { - this->setFrameStyle(QFrame::NoFrame); + this->showBoundaryFrame(false); + QTextEdit::focusOutEvent(e); } +/** + * @Author Chaoqun + * @brief 用来当右键菜单消失时,调整块的深度 + * @param 参数 + * @return 返回值 + * @date 2017/06/22 + */ +void DocTextBlock::contextMenuAboutToHideEvent() +{ + emit this->signals_setZValue(this->tempZValue); // 还原Z值 + this->focusInEvent(new QFocusEvent(QEvent::FocusIn)); // 关注它 +} + +/** + * @Author Chaoqun + * @brief 用来检查当前的格式是否发生改变,并向外界发出信号 + * @param 参数 + * @return 返回值 + * @date 2017/06/22 + */ +void DocTextBlock::checkCurrentFormat() +{ + QTextCursor cursor = this->textCursor(); //获得当前的光标 + // 比较当前光标位置的类型和已有的是否一致,不一致的话,当前的类型,并发射信号 + QTextBlockFormat blockFormat = cursor.blockFormat(); // 块格式 + QTextCharFormat charFormat = cursor.charFormat(); // 字符格式 + + // 处理字符格式 + if(this->_currentCharFormat == charFormat) + { + // 如果字符格式相等 +// qDebug() << "charFormat does not change!"; + } + else + { +// qDebug() << "charFormat changes! " +// << "And emit signal signals_currentCharFormatChanged!"; + // 如果字符格式变化 + this->_currentCharFormat = charFormat; // 更新char格式 + emit this->signals_currentCharFormatChanged(charFormat); // 发射char格式变更信号 + } + + // 处理块格式 + if(this->_currentBlockFormat == blockFormat) + { + // 格式相等 +// qDebug() << "blockFormat does not change!"; + } + else + { +// qDebug() << "blockFormat changes! " +// << "And emit signal signals_currentBlockFormatChanged!"; + // 格式不相等 + this->_currentBlockFormat = blockFormat; // 存储新格式 + emit this->signals_currentBlockFormatChanged(blockFormat); // 发射blockFormat变更信号 + } + emit this->signals_currentTextBlock(this); // 发射Text Block信号 +// qDebug() << "check format"; +} + +/** + * @Author Chaoqun + * @brief 将所有的信号发出 + * @param void + * @return void + * @date 2017/06/23 + */ +void DocTextBlock::emitFormatSignals() +{ + QTextCursor cursor = this->textCursor(); // 光标 + this->_currentBlockFormat = cursor.blockFormat(); // 获得块格式 + this->_currentCharFormat = cursor.charFormat(); // 获得字符格式 + + // 发射三个信号 + emit this->signals_currentBlockFormatChanged(this->_currentBlockFormat); + emit this->signals_currentCharFormatChanged(this->_currentCharFormat); + emit this->signals_currentTextBlock(this); +} + /** * @Author Chaoqun * @brief 初始化函数 @@ -351,20 +797,18 @@ void DocTextBlock::init() // 设置为背景透明 this->viewport()->setAttribute(Qt::WA_TranslucentBackground, true); -// // 无边框 + // 无边框 this->setFrameStyle(QFrame::NoFrame); - this->initFormat(); // 初始化格式 - - + this->initFormat(); // 初始化格式 - // 连接当前charFormat改变函数 - connect(this, SIGNAL(currentCharFormatChanged(QTextCharFormat)), - this, SLOT(currentCharFormatChangedEvent(QTextCharFormat))); + QTextCursor cursor = this->textCursor(); // 获得光标 + this->_currentBlockFormat = cursor.blockFormat(); // 块格式 + this->_currentCharFormat = cursor.charFormat(); // 字符格式 // 连接当前光标位置改变事件 connect(this, SIGNAL(cursorPositionChanged()), - this, SLOT(cursorPositionChangedEvent())); + this, SLOT(checkCurrentFormat())); this->initAcitons(); // 初始化QAction相关 } @@ -427,26 +871,19 @@ void DocTextBlock::initAcitons() this->connect(this->actionParagraph,SIGNAL(triggered()), this,SLOT(textParagraph())); + // 移除文本框 + this->actionRemove = new QAction(tr("Remove"),NULL); + + this->connect(this->actionRemove,SIGNAL(triggered(bool)), + this,SLOT(remove())); // 链接信号,可以移除文本框 // 字体窗口测试 this->actionFontSetTest = new QAction(tr("FontDialogTest"),NULL); this->connect(this->actionFontSetTest, SIGNAL(triggered()), this, SLOT(customFontDialog())); - // 右键菜单 -// this->ContextMenu = createStandardContextMenu(); // 拓展标准菜单 -// this->ContextMenu->addAction(this->actionBold); // 加粗 -// this->ContextMenu->addAction(this->actionItalic); // 斜体 -// this->ContextMenu->addAction(this->actionUnderline); // 下划线 -// this->ContextMenu->addAction(this->actionColor); // 颜色 -// this->ContextMenu->addSeparator(); // 分界线 -// this->ContextMenu->addAction(this->actionFontSet); // 字体设置 -// this->ContextMenu->addAction(this->actionParagraph); // 段落设置 -// this->ContextMenu->addAction(this->actionFontSetTest);// 字体 - } - /** * @Author Chaoqun * @brief 初始化文字的样式 diff --git a/ofdEditor/model/Doc/DocTextBlock.h b/ofdEditor/model/Doc/DocTextBlock.h index a683b3f2ce655db5aafa98947945e7fa03f542cd..51815bc759d76acdc5537a852f2b5920bc521438 100644 --- a/ofdEditor/model/Doc/DocTextBlock.h +++ b/ofdEditor/model/Doc/DocTextBlock.h @@ -6,14 +6,19 @@ #include #include #include +#include -class DocParagraph; +//class DocParagraph; class QAction; class QTextBlockFormat; // 块格式 class QTextFrameFormat; // 框架格式 class QTextCharFormat; // 字节格式 class QFont; // 字体格式 -class ParagraphFormatDialog; +class ParagraphFormatDialog;// 段落样式 +class DocPassage; // 文章 +class DocPage; // 获得所在页 +class DocLayer; // 层 +class commands; class MODELSHARED_EXPORT DocTextBlock :public QTextEdit @@ -24,29 +29,69 @@ public: ~DocTextBlock(); void setContent(QString str); // 设置内容 + DocPassage* getPassage(); // 获得文章 + DocPage* getPage(); // 获得页 + DocLayer* getLayer(); // 获得层 + DocBlock* getBlock(); // 获得Block + public slots: - void textBold(); // 粗体 + + void textBold(); // 将光标选择的文字粗体 + void textBold(QTextCursor& cursor, int mode = 0); // 将给定光标选择的文字设置为粗体 void textUnderline(); // 下划线 + void textUnderline(QTextCursor& cursor, int mode = 0);// 设置下划线 void textItalic(); // 斜体 + void textItalic(QTextCursor& cursor, int mode = 0); // 设置斜体 + void setTextColor(); // 设置字体颜色 + void setTextColor(QTextCursor& cursor,QColor color); // 设置颜色 + void textParagraph(); // 设置段落 -// void textFamily(const QString &f); -// void textSize(const QString &p); -// void textStyle(int styleIndex); - void setTextColor(); // 设置字体颜色 -// void textAlign(QAction *a); + void textFontDialog(); // 通过字体小窗口设置字体 void customFontDialog(); // 自定义的字体窗口设置 + void setTextBlockFormat( QTextBlockFormat& blockFormat); // 设置块格式 + void setTextBlockFormat( + QTextCursor& cursor, + QTextBlockFormat& blockFormat); // 设置给定光标下块格式 void setCharFormatOnWordOrSelection( QTextCharFormat &format); // 设置选中字段的QTextCharFormat + // 如果没有选中,则会选择光标所在行的字体 + void setCharFormatOnWordOrSelection( + QTextCursor& cursor, + QTextCharFormat &format); // 设置给定光标的QTextCharFormat + + void setCharFormatOnSelection( + QTextCharFormat &format); // 设置选中字段的QTextCharFormat + void serCharFormatOnSelection( + QTextCursor& cursor, + QTextCharFormat &format); // 设置给定光标下,文字的格式 void mergeFormatOnWordOrSelection( QTextCharFormat &format); // 合并格式 + void mergeFormatOnWordOrSelection( + QTextCursor& cursor, + QTextCharFormat &format); // 合并指定光标处的文字格式 + void mergeBlockFormatOnBlock( + QTextBlockFormat& blockFormat); // 合并blockFormat格式 + void mergeBlockFormatOnBlock( + QTextCursor cursor, + QTextBlockFormat &blockFormat); // 合并给定光标下块的格式 + + void setFont(const QFont &font); // 设置格式 + void setFont( + QTextCursor& cursor, + const QFont &font); // 设置给定光标下的字体格式 + + // 关于框的一些其他部分 + void setBlock(DocBlock* block); // 设置Block + void remove(); // 移除本文本框 + void showBoundaryFrame(bool show); // 是否显示边界 protected: @@ -55,13 +100,9 @@ protected: void focusOutEvent(QFocusEvent *e); private slots: - - - void currentCharFormatChangedEvent( - const QTextCharFormat &format); // 选中的文字格式发生了变化 - void cursorPositionChangedEvent( ); // 光标位置发生改变 - void setFont(const QFont &font); // 设置格式 - + void contextMenuAboutToHideEvent(); // 右键菜单隐藏绑定事件 + void checkCurrentFormat(); // 检查当前的格式是否发生改变 + void emitFormatSignals(); // 发射格式的信号 private: QString content; // 文字内容 @@ -76,12 +117,27 @@ private: QAction * actionColor; // 设置颜色 QAction * actionFontSet; // 设置字体 QAction * actionParagraph; // 设置段落 + QAction * actionRemove; // 移除文本框 QAction * actionFontSetTest; // 新字体窗口测试 QMenu * ContextMenu; // 右键菜单 + DocBlock* block; // 本类型所在的block + + qreal tempZValue; // 存储临时Z值 + + QTextBlockFormat _currentBlockFormat; // 当前BlockFormat + QTextCharFormat _currentCharFormat; // 当前 +signals: + void signals_remove(DocTextBlock* textBlock); // 移除文本框的信号。 + void signals_setZValue(qreal z); // 设置Z值的信号 + void signals_currentCharFormatChanged( + QTextCharFormat& fmt); // 当前选择的charFormat发生了变化 + void signals_currentBlockFormatChanged( + QTextBlockFormat& fmt); // 当前选择的block格式发生了变化、 + void signals_currentTextBlock(DocTextBlock* textBlock); // 当前操作的textBlock }; diff --git a/ofdEditor/model/Widget/DocInfoDialog.cpp b/ofdEditor/model/Widget/DocInfoDialog.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d9d8601dcc30ba28423e61b2f7149f6626d02a94 --- /dev/null +++ b/ofdEditor/model/Widget/DocInfoDialog.cpp @@ -0,0 +1,148 @@ +#include "DocInfoDialog.h" +#include "ui_DocInfoDialog.h" + +#include "DataTypes/document/ct_docinfo.h" +#include +#include + +DocInfoDialog::DocInfoDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::DocInfoDialog) +{ + ui->setupUi(this); +} + +DocInfoDialog::DocInfoDialog(CT_DocInfo *docInfo,QWidget *parent = 0): + QDialog(parent), ui(new Ui::DocInfoDialog) +{ + ui->setupUi(this); + this->docInfo = docInfo; + this->init(); + this->initUi(); +} + +DocInfoDialog::~DocInfoDialog() +{ + delete ui; +} + +/** + * @Author Chaoqun + * @brief 初始化 + * @param void + * @return void + * @date 2017/06/23 + */ +void DocInfoDialog::init() +{ + connect(ui->author, SIGNAL(textChanged(QString)), + this,SLOT(editAuthor(QString))); // 作者 + connect(ui->title, SIGNAL(textChanged(QString)), + this, SLOT(editTitle(QString))); // 题目 + connect(ui->subject, SIGNAL(textChanged(QString)), + this, SLOT(editSubject(QString))); // 主题 + connect(ui->abstract_2, SIGNAL(textChanged(QString)), + this, SLOT(editAbstract(QString))); // 摘要 + connect(ui->fileType, SIGNAL(textChanged(QString)), + this,SLOT(editFileType(QString))); // 文档类型 + connect(ui->fileCover, SIGNAL(textChanged(QString)), + this,SLOT(editFileCover(QString))); // 文档封面 + connect(ui->btn_uuid, SIGNAL(pressed()), + this, SLOT(resetDocId())); // 重置UUID + +} + +/** + * @Author Chaoqun + * @brief 初始化UI界面 + * @param void + * @return void + * @date 2017/06/23 + */ +void DocInfoDialog::initUi() +{ + // 文件名 + + // 文件id + ui->docId->setText(this->docInfo->getDocID()); + + // 标题 + ui->title->setText(this->docInfo->getTitle()); + + // 作者 + ui->author->setText(this->docInfo->getAuthor()); + + // 主题 + ui->subject->setText(this->docInfo->getSubject()); + + // 摘要 + ui->abstract_2->setText(this->docInfo->getAbstract()); + + // 文档类型 + ui->fileType->setText(this->docInfo->getDocUsage()); + + // 文档封面 + ui->fileCover->setText(this->docInfo->getCover()); + + // 创建日期 + ui->creationDate->setText(this->docInfo->getCreationDate()); + + // 最后修改时间 + ui->modDate->setText(this->docInfo->getModDate()); + + // 创建者应用程序 + ui->createApp->setText(this->docInfo->getCreator()); + + // 应用程序版本 + ui->creatorVersion->setText(this->docInfo->getCreatorVersion()); + +} + + +void DocInfoDialog::editTitle(const QString &text) +{ + this->docInfo->setTitle(text); // 设置标题 +} + +void DocInfoDialog::editAuthor(const QString &text) +{ + this->docInfo->setAuthor(text); +} + +void DocInfoDialog::editSubject(const QString &text) +{ + this->docInfo->setSubject(text); +} + +void DocInfoDialog::editAbstract(const QString &text) +{ + this->docInfo->setAbstract(text); +} + +void DocInfoDialog::editFileType(const QString &text) +{ + this->docInfo->setDocUsage(text); +} + +void DocInfoDialog::editFileCover(const QString &text) +{ + this->docInfo->setCover(text); +} + +void DocInfoDialog::resetDocId() +{ + QUuid uuid = QUuid::createUuid(); // 创建一个新的uuid + QString docId = uuid.toString(); + + docId.remove(docId.length()-1, 1); + docId.remove(docId.length() -13, 1); + docId.remove(docId.length() -17,1); + docId.remove(docId.length() -21, 1); + docId.remove(docId.length() - 25,1); + docId.remove(0,1); + + qDebug() << "new uuid: " << docId; + + this->docInfo->setDocID(docId); + ui->docId->setText(docId); +} diff --git a/ofdEditor/model/Widget/DocInfoDialog.h b/ofdEditor/model/Widget/DocInfoDialog.h new file mode 100644 index 0000000000000000000000000000000000000000..463453a31a0e07a7fb3f7a6f365e3f87cf43336a --- /dev/null +++ b/ofdEditor/model/Widget/DocInfoDialog.h @@ -0,0 +1,40 @@ +#ifndef DOCINFODIALOG_H +#define DOCINFODIALOG_H + +#include +#include "model_global.h" +class CT_DocInfo; // 文档元信息 + +namespace Ui { +class DocInfoDialog; +} + +class MODELSHARED_EXPORT DocInfoDialog : public QDialog +{ + Q_OBJECT + +public: + explicit DocInfoDialog(QWidget *parent = 0); + + DocInfoDialog(CT_DocInfo* docInfo,QWidget *parent); + + ~DocInfoDialog(); + +private: + Ui::DocInfoDialog *ui; + CT_DocInfo* docInfo; // 文档元信息 + void init(); // 初始化 + void initUi(); // 初始化ui + +public slots: + void editTitle(const QString & text); // 修改标题 + void editAuthor(const QString & text); // 修改作者 + void editSubject(const QString & text); // 修改主题 + void editAbstract(const QString & text); // 修改摘要 + void editFileType(const QString & text); // 文档类型 + void editFileCover(const QString & text); // 文档封面 + void resetDocId(); // 重置UUID + +}; + +#endif // DOCINFODIALOG_H diff --git a/ofdEditor/model/Widget/DocInfoDialog.ui b/ofdEditor/model/Widget/DocInfoDialog.ui new file mode 100644 index 0000000000000000000000000000000000000000..28d14a4211b53be525790ba7a30835d20da2bf84 --- /dev/null +++ b/ofdEditor/model/Widget/DocInfoDialog.ui @@ -0,0 +1,279 @@ + + + DocInfoDialog + + + + 0 + 0 + 483 + 641 + + + + Dialog + + + + + 70 + 590 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 10 + 20 + 461 + 361 + + + + 说明 + + + + + 21 + 21 + 411 + 301 + + + + + + + 文件: + + + + + + + 文档ID: + + + + + + + 更改 + + + + + + + 标题: + + + + + + + + + + 作者: + + + + + + + + + + 主题: + + + + + + + + + + 摘要: + + + + + + + + + + 关键字: + + + + + + + + + + 文档类型: + + + + + + + + + + 文档封面: + + + + + + + + + + 创建日期: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 10 + 420 + 461 + 151 + + + + 高级 + + + + + 20 + 30 + 431 + 111 + + + + + + + 最近修改时间: + + + + + + + + + + + + + + 创建应用程序: + + + + + + + + + + + + + + 应用程序版本: + + + + + + + + + + + + + + + + + + buttonBox + accepted() + DocInfoDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DocInfoDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/ofdEditor/model/Widget/FontSettingDialog.cpp b/ofdEditor/model/Widget/FontSettingDialog.cpp index 84732d1926bbf85efc295c3c46fa0eeb20589980..5b2f4a5a13a362db8441a3786bb492ef20e475ae 100644 --- a/ofdEditor/model/Widget/FontSettingDialog.cpp +++ b/ofdEditor/model/Widget/FontSettingDialog.cpp @@ -124,7 +124,7 @@ void FontSettingDialog::initConnect() this, SLOT(accept_slots())); // 窗口接受确认的信号 connect(this,SIGNAL(sendFont(QTextCharFormat&)), - this->textBlock,SLOT(setCharFormatOnWordOrSelection(QTextCharFormat&))); // 发送字体 + this->textBlock,SLOT(setCharFormatOnSelection(QTextCharFormat&))); // 发送字体 } diff --git a/ofdEditor/model/Widget/ParagraphFormatDialog.ui b/ofdEditor/model/Widget/ParagraphFormatDialog.ui index 661cb5e084151438ca76b41413bc7d9b38f741d4..c5adafc2e758005709db06753eb88cc5d43053d4 100644 --- a/ofdEditor/model/Widget/ParagraphFormatDialog.ui +++ b/ofdEditor/model/Widget/ParagraphFormatDialog.ui @@ -22,362 +22,278 @@ false - - - - 10 - 600 - 461 - 32 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - + 10 30 - 461 - 131 + 451 + 451 - - 对齐方式 - - - - - 10 - 30 - 70 - 20 - - - - 水平 - - - - - - 100 - 30 - 93 - 24 - - - - 0 - - - QComboBox::AdjustToContents - - - - 左对齐 - - - - - 右对齐 - - - - - 居中 - - - - - 两端对齐 - - - - - - - 10 - 60 - 70 - 20 - - - - 竖直 - - - - - - 100 - 60 - 61 - 24 - - - - QComboBox::AdjustToContents - - - - 居上 - - - - - 居下 - - - - - 居中 - - - - - - - 10 - 90 - 70 - 20 - - - - 文字方向 - - - - - - 100 - 90 - 77 - 24 - - - - QComboBox::AdjustToContents - - - - 左到右 - - - - - 右到左 - - - - - - - - 10 - 170 - 461 - 91 - - - - 缩进 - - - - - 10 - 30 - 70 - 20 - - - - 整体缩进 - - - - - - 100 - 30 - 100 - 20 - - - - 10000 - - - - - - 100 - 60 - 100 - 20 - - - - 10000.000000000000000 - - - - - - 10 - 60 - 70 - 20 - - - - 首行缩进 - - - - - - - 10 - 290 - 461 - 161 - - - - 间距 - - - - - 100 - 60 - 100 - 20 - - - - 10000.000000000000000 - - - - - - 10 - 60 - 70 - 20 - - - - 段后 - - - - - - 100 - 30 - 100 - 20 - - - - 10000.000000000000000 - - - - - - 10 - 30 - 70 - 20 - - - - 段前 - - - - - - 330 - 90 - 100 - 20 - - - - 10000.000000000000000 - - - - - - 240 - 90 - 70 - 20 - - - - - - - - - - 100 - 90 - 93 - 24 - - - - QComboBox::AdjustToContents - + - - 单倍行距 - + + + 对齐方式 + + + + + 10 + 30 + 261 + 91 + + + + + + + 水平 + + + + + + + 0 + + + QComboBox::AdjustToContents + + + + 左对齐 + + + + + 右对齐 + + + + + 居中 + + + + + 两端对齐 + + + + + + + + 竖直 + + + + + + + QComboBox::AdjustToContents + + + + 居上 + + + + + 居下 + + + + + 居中 + + + + + + + + 文字方向 + + + + + + + QComboBox::AdjustToContents + + + + 左到右 + + + + + 右到左 + + + + + + + - - 多倍行距 - + + + 缩进 + + + + + 10 + 30 + 261 + 81 + + + + + + + 整体缩进 + + + + + + + 10000 + + + + + + + 首行缩进 + + + + + + + 10000.000000000000000 + + + + + + - - 固定值 - + + + 间距 + + + + + 10 + 30 + 431 + 91 + + + + + + + 段前 + + + + + + + 10000.000000000000000 + + + + + + + 段后 + + + + + + + 10000.000000000000000 + + + + + + + 行距策略 + + + + + + + QComboBox::AdjustToContents + + + + 单倍行距 + + + + + 多倍行距 + + + + + 固定值 + + + + + 最小值 + + + + + + + + + + + + + + + 10000.000000000000000 + + + + + + - - 最小值 - + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + - - - - - 10 - 90 - 70 - 20 - - - - 行距策略 - - + diff --git a/ofdEditor/model/Widget/ParagraphFormatWidget.ui b/ofdEditor/model/Widget/ParagraphFormatWidget.ui index 993df7dbb7a572c3646a627956e51a8fc222419d..a4b4401bc2f678468393944bb293657859778e15 100644 --- a/ofdEditor/model/Widget/ParagraphFormatWidget.ui +++ b/ofdEditor/model/Widget/ParagraphFormatWidget.ui @@ -34,542 +34,348 @@ 段落属性 - + 0 - 0 - 2 - 2 - - - - - - - - 0 - 10 - 70 - 20 - - - - - 16 - - - - 常规 - - - Qt::AutoText - - - Qt::AlignCenter - - - - - - 10 - 40 - 70 - 25 - - - - 对齐方式: - - - - - - 100 - 40 - 100 - 25 - - - - QComboBox::AdjustToMinimumContentsLength - - - 10 - - - - 左对齐 - - - - - 右对齐 - - - - - 居中 - - - - - 自动对齐 - - - - - - - 0 - 110 - 70 - 20 - - - - - 宋体 - 16 - - - - 缩进 - - - Qt::AlignCenter - - - - - - 10 - 80 - 461 - 20 - - - - Qt::Horizontal - - - - - - 10 - 420 - 461 - 20 - - - - Qt::Horizontal - - - - - - 10 - 230 - 461 - 20 - - - - Qt::Horizontal - - - - - - 10 - 150 - 70 - 20 - - - - 整体缩进 - - - - - - 100 - 150 - 100 - 20 - - - - Qt::AlignCenter - - - - - - 10 - 180 - 70 - 20 - - - - 首行缩进 - - - - - - 100 - 180 - 100 - 20 - - - - Qt::AlignCenter - - - - - - 0 - 260 - 70 - 20 - - - - - 宋体 - 16 - - - - 间距 - - - Qt::AlignCenter - - - - - - 100 - 300 - 100 - 20 - - - - Qt::AlignCenter - - - - - - 10 - 330 - 70 - 20 - - - - 段后 - - - - - - 100 - 330 - 100 - 20 - - - - Qt::AlignCenter - - - - - - 10 - 300 - 70 - 20 - - - - 段前 - - - - - - 10 - 360 - 70 - 25 - - - - 行高策略 - - - - - - 100 - 360 - 100 - 25 - - - - QComboBox::AdjustToMinimumContentsLength - - - 10 - - - - 单倍行高 - - - - - 多倍行高 - - - - - 固定值 - - - - - 最小值 - - - - - - - 250 - 360 - 70 - 20 - - - - 行高值 - - - - - - 320 - 360 - 100 - 20 - - - - Qt::AlignCenter - - - - - - 10 - 490 - 70 - 20 - - - - 上边距 - - - - - - 100 - 520 - 100 - 20 - - - - Qt::AlignCenter - - - - - - 100 - 490 - 100 - 20 - - - - Qt::AlignCenter - - - - - - 0 - 450 - 70 - 20 - - - - - 宋体 - 16 - - - - 边距 - - - Qt::AlignCenter - - - - - - 10 - 520 - 70 - 20 - - - - 下边距 - - - - - - 340 - 520 - 100 - 20 - - - - Qt::AlignCenter - - - - - - 250 - 490 - 70 - 20 - - - - 左边距 - - - - - - 340 - 490 - 100 - 20 - - - - Qt::AlignCenter - - - - - - 250 - 520 - 70 - 20 - - - - 右边距 - - - - - - 270 - 610 - 80 - 25 - - - - 确定 - - - - - - 360 - 610 - 80 - 25 - - - - 取消 - - - - - - 250 - 40 - 70 - 25 - - - - 文字方向 - - - - - - 340 - 40 - 100 - 25 - - - - QComboBox::AdjustToMinimumContentsLength - - - 10 - - - - 自左向右 - - - - - 自右向左 - - + 50 + 431 + 421 + + + + + + + + + + + 16 + + + + 常规 + + + Qt::AutoText + + + Qt::AlignCenter + + + + + + + 对齐方式: + + + + + + + QComboBox::AdjustToMinimumContentsLength + + + 10 + + + + 左对齐 + + + + + 右对齐 + + + + + 居中 + + + + + 自动对齐 + + + + + + + + 文字方向 + + + + + + + QComboBox::AdjustToMinimumContentsLength + + + 10 + + + + 自左向右 + + + + + 自右向左 + + + + + + + + Qt::Horizontal + + + + + + + + 宋体 + 16 + + + + 缩进 + + + Qt::AlignCenter + + + + + + + 整体缩进 + + + + + + + Qt::AlignCenter + + + + + + + 首行缩进 + + + + + + + Qt::AlignCenter + + + + + + + Qt::Horizontal + + + + + + + + 宋体 + 16 + + + + 间距 + + + Qt::AlignCenter + + + + + + + 段前 + + + + + + + Qt::AlignCenter + + + + + + + 段后 + + + + + + + Qt::AlignCenter + + + + + + + 行高策略 + + + + + + + QComboBox::AdjustToMinimumContentsLength + + + 10 + + + + 单倍行高 + + + + + 多倍行高 + + + + + 固定值 + + + + + 最小值 + + + + + + + + 行高值 + + + + + + + Qt::AlignCenter + + + + + + + Qt::Horizontal + + + + + + + + 宋体 + 16 + + + + 边距 + + + Qt::AlignCenter + + + + + + + 上边距 + + + + + + + Qt::AlignCenter + + + + + + + 左边距 + + + + + + + Qt::AlignCenter + + + + + + + 下边距 + + + + + + + Qt::AlignCenter + + + + + + + 右边距 + + + + + + + Qt::AlignCenter + + + + + + + 确定 + + + + + + + 取消 + + + + diff --git a/ofdEditor/model/model.pro b/ofdEditor/model/model.pro index 63ec673a7f7b2a0e00923d6e078c52a4d62fc78e..60a6a97e5f4de5ecc728811e7e5d6f1dd6e77dd0 100644 --- a/ofdEditor/model/model.pro +++ b/ofdEditor/model/model.pro @@ -48,7 +48,11 @@ SOURCES += model.cpp \ Widget/ParagraphFormatDialog.cpp \ Widget/FontSettingDialog.cpp \ Convert/OFD_DocConvertor.cpp \ - Convert/MergeCT_Texts.cpp + Convert/MergeCT_Texts.cpp \ + Convert/Doc_OFDConvertor.cpp \ + Convert/Objects/MinTextUnit.cpp \ + Widget/DocInfoDialog.cpp \ + Command/SetTextBlodCmd.cpp HEADERS += model.h\ model_global.h \ @@ -76,7 +80,11 @@ HEADERS += model.h\ Widget/ParagraphFormatDialog.h \ Widget/FontSettingDialog.h \ Convert/OFD_DocConvertor.h \ - Convert/MergeCT_Texts.h + Convert/MergeCT_Texts.h \ + Convert/Doc_OFDConvertor.h \ + Convert/Objects/MinTextUnit.h \ + Widget/DocInfoDialog.h \ + Command/SetTextBlodCmd.h DESTDIR = ../bin # 生成文件在这 MOC_DIR = ./moc # Q_OBJECT 类转换后的文件 @@ -103,4 +111,5 @@ win32{ FORMS += \ Widget/ParagraphFormatWidget.ui \ Widget/ParagraphFormatDialog.ui \ - Widget/FontSettingDialog.ui + Widget/FontSettingDialog.ui \ + Widget/DocInfoDialog.ui diff --git a/ofdEditor/ofd/DataTypes/document/OFD.h b/ofdEditor/ofd/DataTypes/document/OFD.h index 8f5ded5d5ac0464a5f63d56b09fbcf16fdb1a8a0..67d12a08c52c68219d7fc784235bcc141c9a62de 100644 --- a/ofdEditor/ofd/DataTypes/document/OFD.h +++ b/ofdEditor/ofd/DataTypes/document/OFD.h @@ -16,7 +16,7 @@ class OFDSHARED_EXPORT OFD { //主入口文件的根元素 QVector * docs; - //私有方法 + //公有 public: friend class OFDParser; diff --git a/ofdEditor/ofd/DataTypes/document/ofd.h b/ofdEditor/ofd/DataTypes/document/ofd.h index 8f5ded5d5ac0464a5f63d56b09fbcf16fdb1a8a0..67d12a08c52c68219d7fc784235bcc141c9a62de 100644 --- a/ofdEditor/ofd/DataTypes/document/ofd.h +++ b/ofdEditor/ofd/DataTypes/document/ofd.h @@ -16,7 +16,7 @@ class OFDSHARED_EXPORT OFD { //主入口文件的根元素 QVector * docs; - //私有方法 + //公有 public: friend class OFDParser; diff --git a/ofdEditor/ofd/ofd_parser.h b/ofdEditor/ofd/ofd_parser.h index 91fbe638b20a835e92fccfbc85e1069b4093ba3c..79aa6b986627f7b379e3eb2a4f24b7c959d03bf7 100644 --- a/ofdEditor/ofd/ofd_parser.h +++ b/ofdEditor/ofd/ofd_parser.h @@ -57,9 +57,12 @@ class OFDSHARED_EXPORT OFDParser { //解析OFD.xml public: OFDParser(QString _path); + OFD * getData() { + return data; } + }; diff --git a/ofdEditor/start/ActionConnector/ActionConnector.cpp b/ofdEditor/start/ActionConnector/ActionConnector.cpp index 8608a9a3d41d4f61aa3c7bf86334957dc86207cb..d555724ceb3937e2cd8861362471d5cef33157c9 100644 --- a/ofdEditor/start/ActionConnector/ActionConnector.cpp +++ b/ofdEditor/start/ActionConnector/ActionConnector.cpp @@ -2,6 +2,10 @@ #include "Doc/DocPassage.h" #include "ui/PassageMainWindow.h" #include "Doc/DocPage.h" +#include "DataTypes/document/ct_docinfo.h" +#include "Widget/DocInfoDialog.h" + +#include "app/APPInfo.h" #include #include @@ -18,6 +22,22 @@ ActionConnector::ActionConnector(PassageMainWindow *mainWindow) init(); } +void ActionConnector::showAttribute() +{ + if(this->passage == NULL) + { + qDebug() << "show attribute this->passage == NULL"; + return; + } + + + CT_DocInfo * docInfo = this->passage->getDocInfo(); + DocInfoDialog* dialog = new DocInfoDialog(docInfo,this->mainWindow); // 设置窗口 + dialog->exec(); // 运行 + qDebug() << "show Attribute"; + +} + void ActionConnector::setMainWindow(PassageMainWindow *mainWindow) { this->mainWindow = mainWindow; @@ -34,7 +54,9 @@ void ActionConnector::setMainWindow(PassageMainWindow *mainWindow) */ void ActionConnector::addNewPage() { - this->updateActivePassage(); // 更新选择的文章。 + + if(this->passage == NULL) + return; this->passage->appendNewPage(); // 在队尾增加一页 } @@ -48,8 +70,12 @@ void ActionConnector::addNewPage() */ void ActionConnector::addNewBlock(InsertBlockInfo& blockInfo) { + if(this->passage == NULL) + { + return; + } - this->updateActivePassage(); // 更新文章 +// this->updateActivePassage(); // 更新文章 DocPage * page = qobject_cast(this->passage->focusWidget()); if(page == NULL) { @@ -71,49 +97,79 @@ void ActionConnector::addNewBlock(InsertBlockInfo& blockInfo) void ActionConnector::addTextBlock() { + if(this->passage == NULL) + return; InsertBlockInfo blockInfo(this->defaultLayer,DocPage::text); // 设置插入文本框信息 this->addNewBlock(blockInfo); } void ActionConnector::addImageBlock() { + if(this->passage == NULL) + return; InsertBlockInfo blockInfo(this->defaultLayer,DocPage::image); // 设置插入文本框信息 this->addNewBlock(blockInfo); } void ActionConnector::addTableBlock() { + if(this->passage == NULL) + return; InsertBlockInfo blockInfo(this->defaultLayer,DocPage::table); // 设置插入文本框信息 this->addNewBlock(blockInfo); } +void ActionConnector::undo() +{ + qDebug() <<"undo"; + this->passage->undoStack->undo(); +} + +void ActionConnector::redo() +{ + qDebug() <<"redo"; + this->passage->undoStack->redo(); +} + +void ActionConnector::setDocPassage(DocPassage *passage) +{ + this->passage = passage; +} + /** * @Author Chaoqun - * @brief 更新,确保当前操作的对象是活动窗口 + * @brief 更新当前的活跃窗口 * @param 参数 * @return 返回值 - * @date 2017/05/15 + * @date 2017/06/23 */ -void ActionConnector::updateActivePassage() +void ActionConnector::updateActivePassage(QMdiSubWindow *window) { - DocPassage* temp = this->mainWindow->activeMdiChild(); - if(temp == NULL) + if(window == NULL) + { + qDebug() << "updateActivePassage NULL" + << "there's no actived window"; + this->passage = NULL; + return; + } + DocPassage* passage = qobject_cast(window->widget()); // 获得文档 + if(passage == NULL) { - qDebug()<< " You haven't select any passage. " - <<"void ActionConnector::updateActivePassage()"; + qDebug()<< "The active MdiWindow may not DocPassage"; this->passage = NULL; } else { - this->passage = temp; - // 待CT_DocType配置好了,这里可以输出文档名称 + this->passage = passage; } } void ActionConnector::init() { this->defaultLayer = DocPage::Body; + this->passage = NULL; // 初始化为空 + } diff --git a/ofdEditor/start/ActionConnector/ActionConnector.h b/ofdEditor/start/ActionConnector/ActionConnector.h index ffe0728bc78bc287339c3f3cda1f000b0453bd09..878056ba29c007670847a09b24d993b27ee61623 100644 --- a/ofdEditor/start/ActionConnector/ActionConnector.h +++ b/ofdEditor/start/ActionConnector/ActionConnector.h @@ -3,6 +3,8 @@ #include #include "Doc/DocPage.h" +#include + class DocPassage; class PassageMainWindow; @@ -21,24 +23,29 @@ public: ActionConnector(); ActionConnector(PassageMainWindow * mainWindow); + DocPage::Layer getDefaultLayer(){return this->defaultLayer;} + public slots: + void showAttribute(); // 显示文档元信息 void setMainWindow(PassageMainWindow * mainWindow); // 设置主窗口 void addNewPage(); // 添加一个新页面 void addNewBlock(InsertBlockInfo &blockInfo); // 插入一个块 void addTextBlock(); // 插入文本框 void addImageBlock(); // 插入图片框 void addTableBlock(); // 插入表格 + void undo(); // undo + void redo(); // redo + void setDocPassage(DocPassage* passage); // 设置passage void setDefaultLayer(DocPage::Layer layer){this->defaultLayer = layer;} - DocPage::Layer getDefaultLayer(){return this->defaultLayer;} + + void updateActivePassage(QMdiSubWindow * window ); // 更新当前操作的文章 private: PassageMainWindow * mainWindow; // 主窗口 DocPassage * passage; // 当前活跃文档 DocPage::Layer defaultLayer; // 当前默认插入的层 - void updateActivePassage(); // 更新,确保当前操作的对象是活动的窗口 - void init(); // 初始化 diff --git a/ofdEditor/start/app/APPInfo.cpp b/ofdEditor/start/app/APPInfo.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f0d377af555c46cc88491a1751816710da79689d --- /dev/null +++ b/ofdEditor/start/app/APPInfo.cpp @@ -0,0 +1,45 @@ +#include "APPInfo.h" +#include +#include +#include +#include + +APPInfo::APPInfo(QObject *parent) : QObject(parent) +{ + +} + +QString APPInfo::GetAppName() +{ + return this->appName; +} + +QString APPInfo::GetAppVersion() +{ + return this->appVersion; +} + +void APPInfo::initFromFile() +{ + QFile file(":/appInfo/source/appInfo.json"); // 将文件存在resource内 + if(!file.open(QIODevice::ReadOnly)) + { + qDebug() << "open app information file failed"; + return; + } + + QTextStream txtInput(&file); // 设置文件流 + QString str = txtInput.readAll(); // 读全部文件 + qDebug() << str; + +} + +void APPInfo::setAppName(QString &name) +{ + this->appName = name; +} + +void APPInfo::setAppVersion(QString &version) +{ + this->appVersion = version; +} diff --git a/ofdEditor/start/app/APPInfo.h b/ofdEditor/start/app/APPInfo.h new file mode 100644 index 0000000000000000000000000000000000000000..5fe183970db7bba326682092c989e870877ed47d --- /dev/null +++ b/ofdEditor/start/app/APPInfo.h @@ -0,0 +1,30 @@ +#ifndef APPINFO_H +#define APPINFO_H + +#include +#include + +class APPInfo + : public QObject +{ + Q_OBJECT +public: + explicit APPInfo(QObject *parent = 0); + + QString GetAppName(); // 获得应用名称 + QString GetAppVersion(); // 获得应用版本号 + + void initFromFile(); // 从文件中获取版本信息 + +signals: + +public slots: + void setAppName(QString &name); // 设置名称 + void setAppVersion(QString &version); // 设置版本号 + +private: + QString appName; // 应用名称 + QString appVersion; // app版本 +}; + +#endif // APPINFO_H diff --git a/ofdEditor/start/appinfo.qrc b/ofdEditor/start/appinfo.qrc new file mode 100644 index 0000000000000000000000000000000000000000..e6b0c6e90541325ec77490a8fd2d72a7c1765325 --- /dev/null +++ b/ofdEditor/start/appinfo.qrc @@ -0,0 +1,5 @@ + + + source/appInfo.json + + diff --git a/ofdEditor/start/source/appInfo.json b/ofdEditor/start/source/appInfo.json new file mode 100644 index 0000000000000000000000000000000000000000..96f1088cd56a701a1c754fe6d1cb0a9e61aa7412 --- /dev/null +++ b/ofdEditor/start/source/appInfo.json @@ -0,0 +1,4 @@ +{ + "AppName": "ofdEditor", + "AppVersion": "0.1.0.0" +} diff --git a/ofdEditor/start/start.pro b/ofdEditor/start/start.pro index d56a76bcc3f295495fd69c28b032c07db64ed7a2..153a8dc1807a3d4cc1fc25b0a91a20f8feec2492 100644 --- a/ofdEditor/start/start.pro +++ b/ofdEditor/start/start.pro @@ -28,11 +28,13 @@ DEFINES += QT_DEPRECATED_WARNINGS SOURCES += main.cpp\ mainwindow.cpp \ ui/PassageMainWindow.cpp \ - ActionConnector/ActionConnector.cpp + ActionConnector/ActionConnector.cpp \ + app/APPInfo.cpp HEADERS += mainwindow.h \ ui/PassageMainWindow.h \ - ActionConnector/ActionConnector.h + ActionConnector/ActionConnector.h \ + app/APPInfo.h DESTDIR = ../bin # 生成文件在这 MOC_DIR = ./moc # Q_OBJECT 类转换后的文件 @@ -53,6 +55,7 @@ win32{ } RESOURCES += \ - icons.qrc + icons.qrc \ + appinfo.qrc FORMS += diff --git a/ofdEditor/start/ui/PassageMainWindow.cpp b/ofdEditor/start/ui/PassageMainWindow.cpp index e9150723c91cb69962d9ec582d05dff504d89ecf..76f366dd151662ffd5d393828f1dae6fc6f62b4a 100644 --- a/ofdEditor/start/ui/PassageMainWindow.cpp +++ b/ofdEditor/start/ui/PassageMainWindow.cpp @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include "Doc/DocPassage.h" @@ -23,6 +25,8 @@ #include "ofd_parser.h" #include "DataTypes/document/ofd.h" #include "Convert/OFD_DocConvertor.h" // OFD 转 Doc 工具 +#include "Doc/DocPage.h" +#include "Doc/DocTextBlock.h" PassageMainWindow::PassageMainWindow(QWidget *parent) :QMainWindow(parent) @@ -49,9 +53,8 @@ DocPassage *PassageMainWindow::createMdiChild() DocPassage * child = new DocPassage(this); child->addPage(new DocPage()); // 添加一个空白页 - this->area->addSubWindow(child); - child->setVisible(true); // 设置可见 - child->showMaximized(); + this->addDocPassage(child); // 加入到本视区 + return child; } @@ -115,6 +118,9 @@ void PassageMainWindow::initAction() this->printAction->setStatusTip(tr("Print your document")); this->printAction->setIcon(QIcon(":/icons/source/icons/print.png")); + this->attributeAction = new QAction(tr("Attribute"),NULL); // 文档属性 + this->attributeAction->setStatusTip(tr("Show you the attribute of the actived passage")); + this->undoAction = new QAction(tr("Undo"),NULL); // 撤销操作 this->undoAction->setStatusTip(tr("Undo your last action")); this->undoAction->setShortcut(QKeySequence::Undo); @@ -193,6 +199,7 @@ void PassageMainWindow::initAction() this->filesMenu->addAction(this->saveAction); this->filesMenu->addAction(this->saveAsAction); this->filesMenu->addAction(this->printAction); + this->filesMenu->addAction(this->attributeAction); this->editMenu->addAction(this->undoAction); this->editMenu->addAction(this->redoAction); @@ -255,12 +262,21 @@ void PassageMainWindow::connectAction() connect(this->openFileAtcion, SIGNAL(triggered(bool)), this, SLOT(openFile())); //打开文件 + connect(this->attributeAction, SIGNAL(triggered(bool)), + this->connector, SLOT(showAttribute())); // 显示文档属性 + connect(this->insertNewPageAction, SIGNAL(triggered(bool)), this->connector, SLOT(addNewPage())); // 在文章尾部加入新的一页 // connect(this->insertTextBlockAction, &QAction::triggered, // this->connector, &ActionConnector::addNewBlock); // 插入新块 + //undo operation + connect(this->undoAction,SIGNAL(triggered(bool)),this->connector,SLOT(undo())); + + //redo operation + connect(this->redoAction,SIGNAL(triggered(bool)),this->connector,SLOT(redo())); + connect(this->insertTextBlockAction, SIGNAL(triggered()), this->connector, SLOT(addTextBlock())); // 插入文本框 @@ -269,6 +285,15 @@ void PassageMainWindow::connectAction() connect(this->insertTableAction, SIGNAL(triggered()), this->connector, SLOT(addTableBlock())); // 插入表格 + + connect(this->textFormat,SIGNAL(triggered(bool)), + this,SLOT(fontDialog())); // 修改字体 + + connect(this->paragraphFormat,SIGNAL(triggered(bool)), + this,SLOT(paragraphDialog())); // 修改段落 + + connect(this->area, SIGNAL(subWindowActivated(QMdiSubWindow*)), + this->connector, SLOT(updateActivePassage(QMdiSubWindow*))); // 检测ActivePassage更新 } /** @@ -316,15 +341,77 @@ void PassageMainWindow::openFile() OFDParser ofdParser(tempPath + "/OFD.xml"); // 新建临时路径 // OFDParser ofdParser("C:/Users/User/Desktop/表格/OFD.xml"); OFD* data = ofdParser.getData(); // 读取出OFD文件 + qDebug()<< "ofd file open"; OFD_DocConvertor convert; DocPassage* passage = convert.ofd_to_doc(data); this->addDocPassage(passage); // 添加文章 + } +} +/** + * @Author Chaoqun + * @brief 打开字体框 + * @param void + * @return void + * @date 2017/06/23 + */ +void PassageMainWindow::fontDialog() +{ + this->textBlock->customFontDialog(); // 用自定义窗口修改字体 +} +/** + * @Author Chaoqun + * @brief 用自定义窗口修改段落格式 + * @param void + * @return void + * @date 2017/06/23 + */ +void PassageMainWindow::paragraphDialog() +{ + this->textBlock->textParagraph(); // 用自定义段落窗口修改段落 +} - } +/** + * @Author Chaoqun + * @brief 接受当前处理的文字块的更新 + * @param DocTextBlock *textBlock + * @return void + * @date 2017/06/23 + */ +void PassageMainWindow::acceptTextBlock(DocTextBlock *textBlock) +{ + this->textBlock = textBlock; // 修改引用 +} + +/** + * @Author Chaoqun + * @brief 接受当前处理的块格式 + * @param QTextBlockFormat &blockFormat + * @return void + * @date 2017/06/23 + */ +void PassageMainWindow::acceptTextBlockFormat(QTextBlockFormat &blockFormat) +{ + this->_currentBlockFormat = &blockFormat; // 留下引用 + + // 更新界面显示 +} + +/** + * @Author Chaoqun + * @brief 接受字符格式 + * @param QTextCharFormat &charFormat + * @return void + * @date 2017/06/23 + */ +void PassageMainWindow::acceptTextCharFormat(QTextCharFormat &charFormat) +{ + this->_currentCharFormat = &charFormat; // 留下引用 + + // 更新界面显示 } /** @@ -356,8 +443,22 @@ DocPassage *PassageMainWindow::addDocPassage(DocPassage *passage) return NULL; } - this->area->addSubWindow(passage); + this->area->addSubWindow(passage); // 插入子窗口 + this->connector->setDocPassage(passage); // 设置引用 + passage->setVisible(true); // 设置可见 passage->showMaximized(); + + // 处理变更的blockFormat + this->connect(passage,SIGNAL(signals_currentBlockFormatChanged(QTextBlockFormat&)), + this,SLOT(acceptTextBlockFormat(QTextBlockFormat&))); + // 处理变更的charFormat + this->connect(passage,SIGNAL(signals_currentCharFormatChanged(QTextCharFormat&)), + this,SLOT(acceptTextCharFormat(QTextCharFormat&))); + // 处理变更的textBlock + this->connect(passage,SIGNAL(signals_currentTextBlock(DocTextBlock*)), + this,SLOT(acceptTextBlock(DocTextBlock*))); + return passage; } + diff --git a/ofdEditor/start/ui/PassageMainWindow.h b/ofdEditor/start/ui/PassageMainWindow.h index 6d8ed6c149eb8be38c344f9a935edd32bc089c5a..8ac631178739f64cb406ed163c088bbb1c95274b 100644 --- a/ofdEditor/start/ui/PassageMainWindow.h +++ b/ofdEditor/start/ui/PassageMainWindow.h @@ -4,11 +4,16 @@ #include #include #include +#include // 字体框 +#include // 选择框 class QAction; class QMenu; class QMdiArea; class DocPassage; +class DocTextBlock; +class QTextCharFormat; +class QTextBlockFormat; class ActionConnector; // 函数功能的中间件 // 编辑窗口的主界面 @@ -46,6 +51,7 @@ private: QAction * saveAction; // 保存 QAction * saveAsAction; // 另存为 QAction * printAction; // 打印 + QAction * attributeAction; // 文档属性 // 编辑 QAction * undoAction; // 撤销 @@ -72,6 +78,7 @@ private: QAction * helpAciton; // 帮助文档,如何使用本软件 QMdiArea * area; // 多窗口区域 + QVectorpassages; // 存储所有的passage ActionConnector* connector; // 功能连接中间件 @@ -81,12 +88,19 @@ private: void connectAction(); // 链接QAction的相应事件 void disconnectAction(); // 断开事件响应 -private slots: - void openFile(); // 打开新文件 - + DocTextBlock *textBlock; // 文字块 + QTextCharFormat* _currentCharFormat; // 当前字符格式 + QTextBlockFormat* _currentBlockFormat; // 当前块格式 +private slots: + void openFile(); // 打开新文件 + void fontDialog(); // 打开字体框 + void paragraphDialog(); // 打开段落框 + void acceptTextBlock(DocTextBlock* textBlock); // 接受当前处理的文字块的更新 + void acceptTextBlockFormat(QTextBlockFormat& blockFormat); // 接受当前处理的块格式 + void acceptTextCharFormat(QTextCharFormat& charFormat); // 接受当前处理的字符格式 };