From fea4fbdca4b402f80f6b55bd4230e1d88897ce12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=B6=85=E7=BE=A4?= Date: Tue, 20 Jun 2017 20:27:41 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E5=88=A0=E9=99=A4Do?= =?UTF-8?q?cTextBlock=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdEditor/model/Convert/Doc_OFDConvertor.cpp | 7 +++ ofdEditor/model/Convert/Doc_OFDConvertor.h | 18 ++++++ ofdEditor/model/Doc/DocBlock.cpp | 63 ++++++++++++++++++-- ofdEditor/model/Doc/DocBlock.h | 53 ++++++++-------- ofdEditor/model/Doc/DocTextBlock.cpp | 59 +++++++++--------- ofdEditor/model/Doc/DocTextBlock.h | 27 ++++----- ofdEditor/model/model.pro | 6 +- 7 files changed, 160 insertions(+), 73 deletions(-) create mode 100644 ofdEditor/model/Convert/Doc_OFDConvertor.cpp create mode 100644 ofdEditor/model/Convert/Doc_OFDConvertor.h diff --git a/ofdEditor/model/Convert/Doc_OFDConvertor.cpp b/ofdEditor/model/Convert/Doc_OFDConvertor.cpp new file mode 100644 index 0000000..7943414 --- /dev/null +++ b/ofdEditor/model/Convert/Doc_OFDConvertor.cpp @@ -0,0 +1,7 @@ +#include "Doc_OFDConvertor.h" + +Doc_OFDConvertor::Doc_OFDConvertor(QObject *parent) + : QObject(parent) +{ + +} diff --git a/ofdEditor/model/Convert/Doc_OFDConvertor.h b/ofdEditor/model/Convert/Doc_OFDConvertor.h new file mode 100644 index 0000000..e3df7be --- /dev/null +++ b/ofdEditor/model/Convert/Doc_OFDConvertor.h @@ -0,0 +1,18 @@ +#ifndef DOC_OFDCONVERTOR_H +#define DOC_OFDCONVERTOR_H + +#include + +class Doc_OFDConvertor : public QObject +{ + Q_OBJECT +public: + explicit Doc_OFDConvertor(QObject *parent = 0); + +signals: + +public slots: + +}; + +#endif // DOC_OFDCONVERTOR_H diff --git a/ofdEditor/model/Doc/DocBlock.cpp b/ofdEditor/model/Doc/DocBlock.cpp index d3b297f..13aafc9 100644 --- a/ofdEditor/model/Doc/DocBlock.cpp +++ b/ofdEditor/model/Doc/DocBlock.cpp @@ -10,6 +10,8 @@ #include #include +#include "Doc/DocTextBlock.h" + DocBlock::DocBlock(QGraphicsItem *parent , Qt::WindowFlags wFlags) :QGraphicsProxyWidget(parent,wFlags) { @@ -97,6 +99,32 @@ void DocBlock::setZValue(qreal 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); // 从场景中移除该组件 +} + /** * @Author Chaoqun @@ -259,16 +287,43 @@ 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()), + this,SLOT(remove())); // 和块做移除连接 + connect(textBlock,SIGNAL(signals_setZValue(qreal)), + this,SLOT(setZValue(qreal))); // 建立设置Z值的信号连接 + + QGraphicsProxyWidget::setWidget(textBlock); +} + /** * @Author Chaoqun * @brief 检查鼠标是否在重置大小区域 diff --git a/ofdEditor/model/Doc/DocBlock.h b/ofdEditor/model/Doc/DocBlock.h index 0e70625..8e2019b 100644 --- a/ofdEditor/model/Doc/DocBlock.h +++ b/ofdEditor/model/Doc/DocBlock.h @@ -8,6 +8,7 @@ class DocLayer; class QPainter; +class DocTextBlock; /** @@ -25,47 +26,51 @@ public: DocBlock(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); enum RectAdjustStatus{blockNone , blockResize , blockMove}; // 对块的大小状态进行调整 - RectAdjustStatus rectAdjust; // 用来标识当前修改尺寸的状态 - - void setLayer(DocLayer * layer){this->layer = layer;} + RectAdjustStatus rectAdjust; // 用来标识当前修改尺寸的状态 DocLayer * getLayer(){return this->layer;} - void paintHandle(QPainter& painter); // 绘制负责变换的控制器 + qreal getZValue(){return this->realZValue;} // 获得当前块所在的Z值 + RectAdjustStatus currentStatus(const QPointF& pos); // 鼠标所在位置可以进行什么调整 + void setWidget(QWidget* widget); // 旧的函数 + void setWidget(DocTextBlock *textBlock); // SetWidget + +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(); // 从场景中移除本框 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; // 该块在哪一个层之中 - QSizeF blockSize; // 用来纪录大小 - QPointF blockOldPos; // 用来记录旧的位置 - bool isFocused; // 是否被聚焦 - bool blockIsResizing; // 是否正在改变大小 +private: + DocBox boundary; // 该块的外包矩形 + DocLayer * layer; // 该块在哪一个层之中 + QSizeF blockSize; // 用来纪录大小 + QPointF blockOldPos; // 用来记录旧的位置 + + bool isFocused; // 是否被聚焦 + bool blockIsResizing; // 是否正在改变大小 bool isInResizeArea(const QPointF& pos); // 检查鼠标是否在重置大小区域 - qreal realZValue; //真是的z值 + qreal realZValue; // 真实的z值 -public: - RectAdjustStatus currentStatus(const QPointF& pos); // 鼠标所在位置可以进行什么调整 }; #endif // DOCBLOCK_H diff --git a/ofdEditor/model/Doc/DocTextBlock.cpp b/ofdEditor/model/Doc/DocTextBlock.cpp index 27bebdc..4d0c66e 100644 --- a/ofdEditor/model/Doc/DocTextBlock.cpp +++ b/ofdEditor/model/Doc/DocTextBlock.cpp @@ -16,10 +16,6 @@ DocTextBlock::DocTextBlock(QWidget *parent) :QTextEdit(parent) { -// QTextCursor cursor(this->textCursor()); -// cursor.insertText(tr("testsesetstsetestes")); - -// this->setBackgroundRole(QPalette::Dark); this->init(); // 调用初始化函数 } @@ -103,6 +99,18 @@ void DocTextBlock::setFont(const QFont &font) mergeFormatOnWordOrSelection(currentFormat); } +/** + * @Author Chaoqun + * @brief 通知DocBlock,从DocPage中移除本文本框 + * @param void + * @return void + * @date 2017/06/20 + */ +void DocTextBlock::remove() +{ + emit signals_remove(); // 发送信号,remove +} + /** @@ -293,15 +301,18 @@ 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); // 移除操作 + + emit this->signals_setZValue(2000); // 将位置提升至最高层 // 展示菜单 this->ContextMenu->exec(event->globalPos()); @@ -317,7 +328,7 @@ void DocTextBlock::contextMenuEvent(QContextMenuEvent *event) */ void DocTextBlock::focusInEvent(QFocusEvent *e) { - this->setFrameStyle(QFrame::Box); + this->setFrameStyle(QFrame::Box); // 显示边框 QTextEdit::focusInEvent(e); } @@ -330,7 +341,7 @@ void DocTextBlock::focusInEvent(QFocusEvent *e) */ void DocTextBlock::focusOutEvent(QFocusEvent *e) { - this->setFrameStyle(QFrame::NoFrame); + this->setFrameStyle(QFrame::NoFrame); // 隐藏边框 QTextEdit::focusOutEvent(e); } @@ -351,7 +362,7 @@ void DocTextBlock::init() // 设置为背景透明 this->viewport()->setAttribute(Qt::WA_TranslucentBackground, true); -// // 无边框 + // 无边框 this->setFrameStyle(QFrame::NoFrame); this->initFormat(); // 初始化格式 @@ -427,23 +438,17 @@ 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);// 字体 - } diff --git a/ofdEditor/model/Doc/DocTextBlock.h b/ofdEditor/model/Doc/DocTextBlock.h index a683b3f..ee4f5d0 100644 --- a/ofdEditor/model/Doc/DocTextBlock.h +++ b/ofdEditor/model/Doc/DocTextBlock.h @@ -31,22 +31,20 @@ public slots: void textUnderline(); // 下划线 void textItalic(); // 斜体 void textParagraph(); // 设置段落 -// void textFamily(const QString &f); -// void textSize(const QString &p); -// void textStyle(int styleIndex); - void setTextColor(); // 设置字体颜色 -// void textAlign(QAction *a); + void setTextColor(); // 设置字体颜色 void textFontDialog(); // 通过字体小窗口设置字体 void customFontDialog(); // 自定义的字体窗口设置 void setTextBlockFormat( QTextBlockFormat& blockFormat); // 设置块格式 - void setCharFormatOnWordOrSelection( QTextCharFormat &format); // 设置选中字段的QTextCharFormat - void mergeFormatOnWordOrSelection( QTextCharFormat &format); // 合并格式 - + void currentCharFormatChangedEvent( + const QTextCharFormat &format); // 选中的文字格式发生了变化 + void cursorPositionChangedEvent( ); // 光标位置发生改变 + void setFont(const QFont &font); // 设置格式 + void remove(); // 移除本文本框 protected: @@ -54,14 +52,6 @@ protected: void focusInEvent(QFocusEvent *e); void focusOutEvent(QFocusEvent *e); -private slots: - - - void currentCharFormatChangedEvent( - const QTextCharFormat &format); // 选中的文字格式发生了变化 - void cursorPositionChangedEvent( ); // 光标位置发生改变 - void setFont(const QFont &font); // 设置格式 - private: QString content; // 文字内容 @@ -76,11 +66,16 @@ private: QAction * actionColor; // 设置颜色 QAction * actionFontSet; // 设置字体 QAction * actionParagraph; // 设置段落 + QAction * actionRemove; // 移除文本框 QAction * actionFontSetTest; // 新字体窗口测试 QMenu * ContextMenu; // 右键菜单 +signals: + void signals_remove(); // 移除文本框的信号。 + void signals_setZValue(qreal z); // 设置Z值的信号 + }; diff --git a/ofdEditor/model/model.pro b/ofdEditor/model/model.pro index 63ec673..5e5c657 100644 --- a/ofdEditor/model/model.pro +++ b/ofdEditor/model/model.pro @@ -48,7 +48,8 @@ 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 HEADERS += model.h\ model_global.h \ @@ -76,7 +77,8 @@ 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 DESTDIR = ../bin # 生成文件在这 MOC_DIR = ./moc # Q_OBJECT 类转换后的文件 -- Gitee From 2940aca368ca1476f41d7d56ff94f87f031ae02a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=B6=85=E7=BE=A4?= Date: Tue, 20 Jun 2017 21:14:22 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E6=9A=82=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdEditor/model/Doc/DocPassage.cpp | 14 ++++++++++++-- ofdEditor/model/Doc/DocPassage.h | 14 +++++++++----- ofdEditor/model/Doc/DocTextBlock.cpp | 12 ++++++++++++ ofdEditor/model/Doc/DocTextBlock.h | 3 ++- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/ofdEditor/model/Doc/DocPassage.cpp b/ofdEditor/model/Doc/DocPassage.cpp index 347c987..5fd2afd 100644 --- a/ofdEditor/model/Doc/DocPassage.cpp +++ b/ofdEditor/model/Doc/DocPassage.cpp @@ -164,6 +164,18 @@ CT_DocInfo DocPassage::getDocInfo() return docInfo; } +/** + * @Author Chaoqun + * @brief 获得文档中所有的页面 + * @param void + * @return 返回值 + * @date 2017/06/20 + */ +QVector &DocPassage::getPages() +{ + return this->pages; +} + /** * @Author Chaoqun * @brief 设置CommonData,深拷贝 @@ -318,8 +330,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 1e817a8..b339057 100644 --- a/ofdEditor/model/Doc/DocPassage.h +++ b/ofdEditor/model/Doc/DocPassage.h @@ -15,6 +15,8 @@ class DocPage; class CT_DocInfo; class CT_CommonData; +class DocBlock; +class DocTextBlock; /** * @Author Chaoqun @@ -51,10 +53,12 @@ public: void setDocType(QString docType){this->docType = docType;} QString getDocType( ){return this->docType;} + QVector& getPages(); // 获得文档中包含的所有页面 + + protected: void resizeEvent(QResizeEvent* event); - void closeEvent(QCloseEvent *event); // 继承,关闭前提示保存 @@ -80,11 +84,11 @@ private: private: - void init(); // 初始化 + void init(); // 初始化 void adjustScrollBar(QScrollBar *scrollBar, - double factor); // 调整滑动条 - void adjustScrollBarRange(); //调整滑动条范围 - void adjustWidgetSize(); // 根据页数来自动调整widget大小 + double factor); // 调整滑动条 + void adjustScrollBarRange(); //调整滑动条范围 + void adjustWidgetSize(); // 根据页数来自动调整widget大小 diff --git a/ofdEditor/model/Doc/DocTextBlock.cpp b/ofdEditor/model/Doc/DocTextBlock.cpp index 4d0c66e..cd807a1 100644 --- a/ofdEditor/model/Doc/DocTextBlock.cpp +++ b/ofdEditor/model/Doc/DocTextBlock.cpp @@ -131,6 +131,18 @@ void DocTextBlock::textBold() } +/** + * @Author Chaoqun + * @brief QTextCursor & + * @param 参数 + * @return 返回值 + * @date 2017/06/20 + */ +void DocTextBlock::textBold(QTextCursor &cursor) +{ + +} + /** * @Author Chaoqun * @brief 设置下划线 diff --git a/ofdEditor/model/Doc/DocTextBlock.h b/ofdEditor/model/Doc/DocTextBlock.h index ee4f5d0..81c31d0 100644 --- a/ofdEditor/model/Doc/DocTextBlock.h +++ b/ofdEditor/model/Doc/DocTextBlock.h @@ -27,7 +27,8 @@ public: public slots: - void textBold(); // 粗体 + void textBold(); // 将光标选择的文字粗体 + void textBold(QTextCursor& cursor); // 将给定光标选择的文字设置为粗体 void textUnderline(); // 下划线 void textItalic(); // 斜体 void textParagraph(); // 设置段落 -- Gitee From 991fa0fff4c7ab39bc4e6ee61610143bf92fcd22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=B6=85=E7=BE=A4?= Date: Tue, 20 Jun 2017 22:04:50 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Doc=20=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdEditor/model/Doc/DocPage.cpp | 13 +++++++ ofdEditor/model/Doc/DocPage.h | 59 ++++++++++++++++++---------- ofdEditor/model/Doc/DocPassage.cpp | 62 ++++++++++++++++++++++++++++-- ofdEditor/model/Doc/DocPassage.h | 18 +++++++-- ofdEditor/model/Doc/DocTextBlock.h | 2 +- 5 files changed, 125 insertions(+), 29 deletions(-) diff --git a/ofdEditor/model/Doc/DocPage.cpp b/ofdEditor/model/Doc/DocPage.cpp index ad3c760..b630b2d 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,18 @@ DocPage::~DocPage() } +/** + * @Author Chaoqun + * @brief 设置文章引用 + * @param DocPassage *passage + * @return void + * @date 2017/06/20 + */ +void DocPage::setPassage(DocPassage *passage) +{ + this->passage = passage; // 设置 passage +} + /** * @Author Chaoqun diff --git a/ofdEditor/model/Doc/DocPage.h b/ofdEditor/model/Doc/DocPage.h index aadda59..5d43b80 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,26 @@ 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 setPassage(DocPassage * passage); // 设置文章 + DocPassage *getPassage(); // 获得文章 - void setSize(double width, double height); // 设置页面大小 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 addBlock(DocBlock* block, DocPage::Layer layer); // 为页面添加一个新元素 // void addBlock(DocTextBlock* textBlock, DocPage::Layer layer); // 为页面添加一个新元素 void addItem(QGraphicsItem *item); // 拓展接口 @@ -48,21 +55,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的信息 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; // 场景数据 + + void init(); // 初始化UI + DocPassage * passage; // 页所属文章 + + DocPageScene* docScene; // 场景数据 //QVector layers; // 一个文档具有很多层 DocLayer* foregroundLayer; // 前景层 @@ -74,24 +82,35 @@ private: // 还应该有模板页 //CT_PageArea* area; // 页面大小描述 - double width_mm; // 页面的宽 --单位 mm - double height_mm; // 页面的高 - - double scaleFactor; // 表示缩放倍数 + double width_mm; // 页面的宽 --单位 mm + double height_mm; // 页面的高 + double scaleFactor; // 表示缩放倍数 - void init(); // 初始化UI - - QPointF oldPos; // 用来移动时使用,计算距离 - QPointF newPos; // 新点 + QPointF oldPos; // 用来移动时使用,计算距离 + QPointF newPos; // 新点 BlockFlag newBlockFlag; // 是否画块 // QList items; DocBlock * activeBlock; // 正在活跃的那个DocBlock +signals: // 信号 + void signals_remove(); // 本页面被移除信号 }; +/** + * @Author Chaoqun + * @brief 获得文章 + * @param void + * @return DocPassage + * @date 2017/06/20 + */ +DocPassage *DocPage::getPassage() +{ + return this->passage; +} + /** * @Author Chaoqun * @brief 希望用它来传递插入block的具体信息,包含层、类型等概念 diff --git a/ofdEditor/model/Doc/DocPassage.cpp b/ofdEditor/model/Doc/DocPassage.cpp index 5fd2afd..a3cbe35 100644 --- a/ofdEditor/model/Doc/DocPassage.cpp +++ b/ofdEditor/model/Doc/DocPassage.cpp @@ -95,14 +95,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 +137,37 @@ 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->layout->removeWidget(page); // 从场景中移除页面 + this->pages.remove(index); // 从数据中移除页面 + +} + +/** + * @Author Chaoqun + * @brief 移除指定的页面 + * @param DocPage *page + * @return void + * @date 2017/06/20 + */ +void DocPassage::removePage(DocPage *page) +{ + int index = this->pages.indexOf(page); // 获取到该页所在的位置 + this->pages.remove(index); + this->layout->removeWidget(page); + +} + /** * @Author Chaoqun * @brief 设置文档原信息 @@ -150,6 +180,18 @@ void DocPassage::setDocInfo(CT_DocInfo &docInfo) this->docInfo->copy(docInfo); } +/** + * @Author Chaoqun + * @brief 测试 + * @param 参数 + * @return 返回值 + * @date 2017/06/xx + */ +void DocPassage::testMessage() +{ + qDebug()<<"passage success"; +} + /** * @Author Chaoqun * @brief 获得文档原信息 @@ -176,6 +218,18 @@ QVector &DocPassage::getPages() return this->pages; } +/** + * @Author Chaoqun + * @brief 获得某一页 + * @param int index + * @return DocPage * + * @date 2017/06/20 + */ +DocPage *DocPassage::getPage(int index) +{ + return this->pages[index]; +} + /** * @Author Chaoqun * @brief 设置CommonData,深拷贝 diff --git a/ofdEditor/model/Doc/DocPassage.h b/ofdEditor/model/Doc/DocPassage.h index b339057..005febf 100644 --- a/ofdEditor/model/Doc/DocPassage.h +++ b/ofdEditor/model/Doc/DocPassage.h @@ -33,13 +33,22 @@ 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); // 获得文档中的某一页 + +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); @@ -47,13 +56,14 @@ public: // 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;} - QVector& getPages(); // 获得文档中包含的所有页面 + void testMessage(); // 测试信号是否走通 + + + diff --git a/ofdEditor/model/Doc/DocTextBlock.h b/ofdEditor/model/Doc/DocTextBlock.h index 81c31d0..1068ea0 100644 --- a/ofdEditor/model/Doc/DocTextBlock.h +++ b/ofdEditor/model/Doc/DocTextBlock.h @@ -22,7 +22,7 @@ class MODELSHARED_EXPORT DocTextBlock public: DocTextBlock(QWidget *parent = NULL); ~DocTextBlock(); - void setContent(QString str); // 设置内容 + void setContent(QString str); // 设置内 -- Gitee From 7f47dec94adbee5263ebe44ce5583926c5c22219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=B6=85=E7=BE=A4?= Date: Wed, 21 Jun 2017 09:17:28 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E5=81=9A=E4=BA=86=E4=BA=9B=E6=94=B9?= =?UTF-8?q?=E5=8A=A8=EF=BC=8CDocTextBlock=20=E5=8F=AF=E4=BB=A5=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=89=BE=E5=88=B0=20DocBlock=20DocLayer=20DocPage=20D?= =?UTF-8?q?ocPassage=E7=AD=89=20DocBlock=20=E5=8F=AF=E4=BB=A5=E6=89=BE?= =?UTF-8?q?=E5=88=B0=20DocLayer=20DocPage=20DocPassage=20DocLayer=20?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E6=89=BE=E5=88=B0=20DocPage=20DocPassage=20D?= =?UTF-8?q?ocPage=20=E5=8F=AF=E4=BB=A5=E6=89=BE=E5=88=B0=20=20DocPassage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdEditor/model/Doc/DocBlock.cpp | 32 ++++++++++++ ofdEditor/model/Doc/DocBlock.h | 14 +++-- ofdEditor/model/Doc/DocLayer.cpp | 43 +++++++++++++++- ofdEditor/model/Doc/DocLayer.h | 17 ++++--- ofdEditor/model/Doc/DocPage.cpp | 10 ++++ ofdEditor/model/Doc/DocPage.h | 17 +------ ofdEditor/model/Doc/DocPassage.cpp | 21 +++++--- ofdEditor/model/Doc/DocTextBlock.cpp | 76 ++++++++++++++++++++++++++++ ofdEditor/model/Doc/DocTextBlock.h | 20 ++++++-- 9 files changed, 214 insertions(+), 36 deletions(-) diff --git a/ofdEditor/model/Doc/DocBlock.cpp b/ofdEditor/model/Doc/DocBlock.cpp index 13aafc9..854af47 100644 --- a/ofdEditor/model/Doc/DocBlock.cpp +++ b/ofdEditor/model/Doc/DocBlock.cpp @@ -11,6 +11,9 @@ #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) @@ -28,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 绘制控制器 @@ -320,6 +351,7 @@ void DocBlock::setWidget(DocTextBlock *textBlock) this,SLOT(remove())); // 和块做移除连接 connect(textBlock,SIGNAL(signals_setZValue(qreal)), this,SLOT(setZValue(qreal))); // 建立设置Z值的信号连接 + textBlock->setBlock(this); // 设置引用 QGraphicsProxyWidget::setWidget(textBlock); } diff --git a/ofdEditor/model/Doc/DocBlock.h b/ofdEditor/model/Doc/DocBlock.h index 8e2019b..26d61f0 100644 --- a/ofdEditor/model/Doc/DocBlock.h +++ b/ofdEditor/model/Doc/DocBlock.h @@ -9,6 +9,8 @@ class DocLayer; class QPainter; class DocTextBlock; +class DocPage; +class DocPassage; /** @@ -26,13 +28,14 @@ public: DocBlock(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); enum RectAdjustStatus{blockNone , blockResize , blockMove}; // 对块的大小状态进行调整 - RectAdjustStatus rectAdjust; // 用来标识当前修改尺寸的状态 - DocLayer * getLayer(){return this->layer;} + 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 setWidget(QWidget* widget); // 旧的函数 - void setWidget(DocTextBlock *textBlock); // SetWidget + public slots: // 槽函数 void setLayer(DocLayer * layer){this->layer = layer;} @@ -42,6 +45,9 @@ public slots: // 槽函数 void setPos(qreal x, qreal y); // 设置位置 // 移动位置应该在所在的DocPage中吧…… void remove(); // 从场景中移除本框 + void setWidget(QWidget* widget); // 旧的函数 + void setWidget(DocTextBlock *textBlock); // SetWidget + protected: diff --git a/ofdEditor/model/Doc/DocLayer.cpp b/ofdEditor/model/Doc/DocLayer.cpp index 1cafbdc..8ea48ac 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,7 @@ void DocLayer::setZValue(qreal z) void DocLayer::addBlock(DocBlock *block) { this->blocks.append(block); // 追加到队尾 + block->setLayer(this); // 设置引用 } /** @@ -101,6 +103,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 +133,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 5319f70..7fbb8c9 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 b630b2d..d33dee2 100644 --- a/ofdEditor/model/Doc/DocPage.cpp +++ b/ofdEditor/model/Doc/DocPage.cpp @@ -46,6 +46,11 @@ DocPage::~DocPage() } +DocPassage *DocPage::getPassage() +{ + return this->passage; +} + /** * @Author Chaoqun * @brief 设置文章引用 @@ -398,8 +403,13 @@ void DocPage::init() // 新建三个层 this->foregroundLayer = new DocLayer(Foreground); + this->foregroundLayer->setPage(this); + this->bodyLayer = new DocLayer(DocPage::Body); + this->bodyLayer->setPage(this); + this->backgroundLayer = new DocLayer(Background); + this->backgroundLayer->setPage(this); // this->setBackgroundRole(QPalette::Dark); this->insertBlockInfo = NULL; diff --git a/ofdEditor/model/Doc/DocPage.h b/ofdEditor/model/Doc/DocPage.h index 5d43b80..6519553 100644 --- a/ofdEditor/model/Doc/DocPage.h +++ b/ofdEditor/model/Doc/DocPage.h @@ -36,9 +36,8 @@ public: DocPage(double width, double height, double scaleFactor,QWidget * parent = 0); ~DocPage(); - void setPassage(DocPassage * passage); // 设置文章 - DocPassage *getPassage(); // 获得文章 + DocPassage *getPassage(); // 获得文章 QSize getSize(); // 获得页面像素大小 double getWidth(){return width_mm;} // 返回毫米单位宽度 double getHeight(){return height_mm;} // 返回毫米单位高度 @@ -47,7 +46,7 @@ public: 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); // 拓展接口 @@ -69,7 +68,6 @@ private: void init(); // 初始化UI DocPassage * passage; // 页所属文章 - DocPageScene* docScene; // 场景数据 //QVector layers; // 一个文档具有很多层 @@ -99,17 +97,6 @@ signals: // 信号 }; -/** - * @Author Chaoqun - * @brief 获得文章 - * @param void - * @return DocPassage - * @date 2017/06/20 - */ -DocPassage *DocPage::getPassage() -{ - return this->passage; -} /** * @Author Chaoqun diff --git a/ofdEditor/model/Doc/DocPassage.cpp b/ofdEditor/model/Doc/DocPassage.cpp index a3cbe35..fe833da 100644 --- a/ofdEditor/model/Doc/DocPassage.cpp +++ b/ofdEditor/model/Doc/DocPassage.cpp @@ -147,9 +147,7 @@ void DocPassage::appendNewPage(DocPage *page) void DocPassage::removePage(int index) { DocPage* page = this->pages[index]; // 获取该页面数据 - - this->layout->removeWidget(page); // 从场景中移除页面 - this->pages.remove(index); // 从数据中移除页面 + this->removePage(page); // 移除页面 } @@ -162,9 +160,17 @@ void DocPassage::removePage(int index) */ void DocPassage::removePage(DocPage *page) { - int index = this->pages.indexOf(page); // 获取到该页所在的位置 - this->pages.remove(index); - this->layout->removeWidget(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(); // 更新 } @@ -370,7 +376,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; diff --git a/ofdEditor/model/Doc/DocTextBlock.cpp b/ofdEditor/model/Doc/DocTextBlock.cpp index cd807a1..76db7ac 100644 --- a/ofdEditor/model/Doc/DocTextBlock.cpp +++ b/ofdEditor/model/Doc/DocTextBlock.cpp @@ -2,6 +2,9 @@ #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 #include @@ -38,6 +41,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 用来合并格式 @@ -99,6 +163,18 @@ void DocTextBlock::setFont(const QFont &font) mergeFormatOnWordOrSelection(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中移除本文本框 diff --git a/ofdEditor/model/Doc/DocTextBlock.h b/ofdEditor/model/Doc/DocTextBlock.h index 1068ea0..c599d84 100644 --- a/ofdEditor/model/Doc/DocTextBlock.h +++ b/ofdEditor/model/Doc/DocTextBlock.h @@ -7,13 +7,16 @@ #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 MODELSHARED_EXPORT DocTextBlock :public QTextEdit @@ -22,11 +25,18 @@ class MODELSHARED_EXPORT DocTextBlock public: DocTextBlock(QWidget *parent = NULL); ~DocTextBlock(); - void setContent(QString str); // 设置内 + void setContent(QString str); // 设置内容 + + DocPassage* getPassage(); // 获得文章 + DocPage* getPage(); // 获得页 + DocLayer* getLayer(); // 获得层 + DocBlock* getBlock(); // 获得Block public slots: + + // 文档编辑部分 void textBold(); // 将光标选择的文字粗体 void textBold(QTextCursor& cursor); // 将给定光标选择的文字设置为粗体 void textUnderline(); // 下划线 @@ -45,6 +55,9 @@ public slots: const QTextCharFormat &format); // 选中的文字格式发生了变化 void cursorPositionChangedEvent( ); // 光标位置发生改变 void setFont(const QFont &font); // 设置格式 + + // 关于框的一些其他部分 + void setBlock(DocBlock* block); // 设置Block void remove(); // 移除本文本框 protected: @@ -72,6 +85,7 @@ private: QAction * actionFontSetTest; // 新字体窗口测试 QMenu * ContextMenu; // 右键菜单 + DocBlock* block; // 本类型所在的block signals: void signals_remove(); // 移除文本框的信号。 -- Gitee From d206f68db4b10558ce6a3f6a2cb8c38ed336fb27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=B6=85=E7=BE=A4?= Date: Thu, 22 Jun 2017 10:23:00 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E5=B0=86=20DoctextBlock=E5=86=99?= =?UTF-8?q?=E5=BE=97=E6=9B=B4=E5=90=88=E7=90=86=E4=BA=86=E4=B8=80=E4=BA=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/Convert/Objects/MinTextUnit.cpp | 6 + ofdEditor/model/Convert/Objects/MinTextUnit.h | 25 ++ ofdEditor/model/Doc/DocLayer.h | 2 +- ofdEditor/model/Doc/DocTextBlock.cpp | 241 ++++++++++++++++-- ofdEditor/model/Doc/DocTextBlock.h | 40 ++- ofdEditor/model/model.pro | 6 +- 6 files changed, 291 insertions(+), 29 deletions(-) create mode 100644 ofdEditor/model/Convert/Objects/MinTextUnit.cpp create mode 100644 ofdEditor/model/Convert/Objects/MinTextUnit.h diff --git a/ofdEditor/model/Convert/Objects/MinTextUnit.cpp b/ofdEditor/model/Convert/Objects/MinTextUnit.cpp new file mode 100644 index 0000000..6cd9267 --- /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 0000000..b10c012 --- /dev/null +++ b/ofdEditor/model/Convert/Objects/MinTextUnit.h @@ -0,0 +1,25 @@ +#ifndef MINTEXTUNIT_H +#define MINTEXTUNIT_H + +#include +#include +#include "model_global.h" + +class MODELSHARED_EXPORT MinTextUnit + : public QObject +{ + Q_OBJECT +public: + explicit MinTextUnit(QObject *parent = 0); + +signals: + +public slots: + +private: + QColor fill_color; // 填充颜色 + QColor stroke_color; // 描边颜色 + +}; + +#endif // MINTEXTUNIT_H diff --git a/ofdEditor/model/Doc/DocLayer.h b/ofdEditor/model/Doc/DocLayer.h index 7fbb8c9..d18bc3e 100644 --- a/ofdEditor/model/Doc/DocLayer.h +++ b/ofdEditor/model/Doc/DocLayer.h @@ -29,7 +29,7 @@ public: QVector *getBlocks(); // 获得所有Block DocPage::Layer getLayer(){return type;} DocPage* getPage(); // 找到层所在的Page - DocPassage* getPassage(); // 找到文章 + DocPassage *getPassage(); // 找到文章 public slots: diff --git a/ofdEditor/model/Doc/DocTextBlock.cpp b/ofdEditor/model/Doc/DocTextBlock.cpp index 76db7ac..d57e96f 100644 --- a/ofdEditor/model/Doc/DocTextBlock.cpp +++ b/ofdEditor/model/Doc/DocTextBlock.cpp @@ -126,41 +126,91 @@ 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::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::currentCharFormatChangedEvent( - const QTextCharFormat &format) +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); // 合并给定光标下的字体样式 } /** @@ -209,14 +259,33 @@ void DocTextBlock::textBold() /** * @Author Chaoqun - * @brief QTextCursor & - * @param 参数 - * @return 返回值 + * @brief 使用QTextCursor作为参数,并且通过mode参数可以控制是否设置加粗, + * 方便Command操作进行使用 + * mode = -1 普通, + * mode = 0 一般模式同无参的这个函数 + * mode = 1 加粗 + * @param QTextCursor & + * @return void * @date 2017/06/20 */ -void DocTextBlock::textBold(QTextCursor &cursor) +void DocTextBlock::textBold(QTextCursor &cursor, int mode) { + QTextCharFormat fmt; + 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(cursor,fmt); // 合并给定光标下的字体 } /** @@ -237,6 +306,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 设置斜体 @@ -254,6 +355,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,设置好了后, @@ -295,6 +432,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 通过字体小窗口设置字体 @@ -353,11 +505,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 @@ -377,6 +554,30 @@ 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 } /** diff --git a/ofdEditor/model/Doc/DocTextBlock.h b/ofdEditor/model/Doc/DocTextBlock.h index c599d84..f097055 100644 --- a/ofdEditor/model/Doc/DocTextBlock.h +++ b/ofdEditor/model/Doc/DocTextBlock.h @@ -6,6 +6,7 @@ #include #include #include +#include //class DocParagraph; class QAction; @@ -36,25 +37,48 @@ public: public slots: - // 文档编辑部分 void textBold(); // 将光标选择的文字粗体 - void textBold(QTextCursor& cursor); // 将给定光标选择的文字设置为粗体 + void textBold(QTextCursor& cursor, int mode = 0); // 将给定光标选择的文字设置为粗体 void textUnderline(); // 下划线 + void textUnderline(QTextCursor& cursor, int mode = 0);// 设置下划线 void textItalic(); // 斜体 - void textParagraph(); // 设置段落 + void textItalic(QTextCursor& cursor, int mode = 0); // 设置斜体 void setTextColor(); // 设置字体颜色 + void setTextColor(QTextCursor& cursor,QColor color); // 设置颜色 + + void textParagraph(); // 设置段落 + 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 mergeFormatOnWordOrSelection( QTextCharFormat &format); // 合并格式 - void currentCharFormatChangedEvent( - const QTextCharFormat &format); // 选中的文字格式发生了变化 - void cursorPositionChangedEvent( ); // 光标位置发生改变 + 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 @@ -90,6 +114,10 @@ private: signals: void signals_remove(); // 移除文本框的信号。 void signals_setZValue(qreal z); // 设置Z值的信号 + void signals_currentCharFormatChanged( + QTextCharFormat& fmt); // 当前选择的charFormat发生了变化 + void signals_currentBlockFormatChanged( + QTextBlockFormat& fmt); // 当前选择的block格式发生了变化、 diff --git a/ofdEditor/model/model.pro b/ofdEditor/model/model.pro index 5e5c657..e7b846c 100644 --- a/ofdEditor/model/model.pro +++ b/ofdEditor/model/model.pro @@ -49,7 +49,8 @@ SOURCES += model.cpp \ Widget/FontSettingDialog.cpp \ Convert/OFD_DocConvertor.cpp \ Convert/MergeCT_Texts.cpp \ - Convert/Doc_OFDConvertor.cpp + Convert/Doc_OFDConvertor.cpp \ + Convert/Objects/MinTextUnit.cpp HEADERS += model.h\ model_global.h \ @@ -78,7 +79,8 @@ HEADERS += model.h\ Widget/FontSettingDialog.h \ Convert/OFD_DocConvertor.h \ Convert/MergeCT_Texts.h \ - Convert/Doc_OFDConvertor.h + Convert/Doc_OFDConvertor.h \ + Convert/Objects/MinTextUnit.h DESTDIR = ../bin # 生成文件在这 MOC_DIR = ./moc # Q_OBJECT 类转换后的文件 -- Gitee From bc1fd75e20e36768189846b9b565df09bada2a89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=B6=85=E7=BE=A4?= Date: Thu, 22 Jun 2017 11:17:51 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E5=8F=B3=E9=94=AE=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E9=81=AE=E7=9B=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdEditor/model/Doc/DocBlock.cpp | 5 ++- ofdEditor/model/Doc/DocBlock.h | 1 + ofdEditor/model/Doc/DocLayer.cpp | 1 + ofdEditor/model/Doc/DocPage.cpp | 3 ++ ofdEditor/model/Doc/DocTextBlock.cpp | 46 ++++++++++++++++++++++++++-- ofdEditor/model/Doc/DocTextBlock.h | 10 ++++++ 6 files changed, 62 insertions(+), 4 deletions(-) diff --git a/ofdEditor/model/Doc/DocBlock.cpp b/ofdEditor/model/Doc/DocBlock.cpp index 854af47..14764ec 100644 --- a/ofdEditor/model/Doc/DocBlock.cpp +++ b/ofdEditor/model/Doc/DocBlock.cpp @@ -126,6 +126,7 @@ void DocBlock::resize(const QSizeF &size) */ void DocBlock::setZValue(qreal z) { +// qDebug()<<"setZValue:" << z; QGraphicsProxyWidget::setZValue(z); this->realZValue = z; // 设置本地记录 } @@ -351,11 +352,13 @@ void DocBlock::setWidget(DocTextBlock *textBlock) this,SLOT(remove())); // 和块做移除连接 connect(textBlock,SIGNAL(signals_setZValue(qreal)), this,SLOT(setZValue(qreal))); // 建立设置Z值的信号连接 - textBlock->setBlock(this); // 设置引用 + + textBlock->setBlock(this); // 设置引用 QGraphicsProxyWidget::setWidget(textBlock); } + /** * @Author Chaoqun * @brief 检查鼠标是否在重置大小区域 diff --git a/ofdEditor/model/Doc/DocBlock.h b/ofdEditor/model/Doc/DocBlock.h index 26d61f0..1895c41 100644 --- a/ofdEditor/model/Doc/DocBlock.h +++ b/ofdEditor/model/Doc/DocBlock.h @@ -49,6 +49,7 @@ public slots: // 槽函数 void setWidget(DocTextBlock *textBlock); // SetWidget + protected: void paint(QPainter *painter, diff --git a/ofdEditor/model/Doc/DocLayer.cpp b/ofdEditor/model/Doc/DocLayer.cpp index 8ea48ac..07da660 100644 --- a/ofdEditor/model/Doc/DocLayer.cpp +++ b/ofdEditor/model/Doc/DocLayer.cpp @@ -80,6 +80,7 @@ void DocLayer::setZValue(qreal z) void DocLayer::addBlock(DocBlock *block) { this->blocks.append(block); // 追加到队尾 + block->setZValue(this->zValue); // 设置Z值 block->setLayer(this); // 设置引用 } diff --git a/ofdEditor/model/Doc/DocPage.cpp b/ofdEditor/model/Doc/DocPage.cpp index d33dee2..6b871ce 100644 --- a/ofdEditor/model/Doc/DocPage.cpp +++ b/ofdEditor/model/Doc/DocPage.cpp @@ -404,12 +404,15 @@ 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/DocTextBlock.cpp b/ofdEditor/model/Doc/DocTextBlock.cpp index d57e96f..1edb508 100644 --- a/ofdEditor/model/Doc/DocTextBlock.cpp +++ b/ofdEditor/model/Doc/DocTextBlock.cpp @@ -237,6 +237,25 @@ void DocTextBlock::remove() emit signals_remove(); // 发送信号,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); // 隐藏边框 + } +} + /** @@ -601,7 +620,11 @@ void DocTextBlock::contextMenuEvent(QContextMenuEvent *event) this->ContextMenu->addAction(this->actionFontSetTest); // 字体 this->ContextMenu->addAction(this->actionRemove); // 移除操作 - emit this->signals_setZValue(2000); // 将位置提升至最高层 + connect(this->ContextMenu, SIGNAL(aboutToHide()), + this,SLOT(contextMenuAboutToHideEvent())); // 测试 + + this->tempZValue = this->getBlock()->getZValue(); + emit this->signals_setZValue(2000); // 展示菜单 this->ContextMenu->exec(event->globalPos()); @@ -617,7 +640,9 @@ void DocTextBlock::contextMenuEvent(QContextMenuEvent *event) */ void DocTextBlock::focusInEvent(QFocusEvent *e) { - this->setFrameStyle(QFrame::Box); // 显示边框 + this->showBoundaryFrame(true); + emit this->signals_focusIn(); + QTextEdit::focusInEvent(e); } @@ -630,10 +655,25 @@ void DocTextBlock::focusInEvent(QFocusEvent *e) */ void DocTextBlock::focusOutEvent(QFocusEvent *e) { - this->setFrameStyle(QFrame::NoFrame); // 隐藏边框 + this->showBoundaryFrame(false); + emit this->signals_focusOut(); + 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 初始化函数 diff --git a/ofdEditor/model/Doc/DocTextBlock.h b/ofdEditor/model/Doc/DocTextBlock.h index f097055..a58afff 100644 --- a/ofdEditor/model/Doc/DocTextBlock.h +++ b/ofdEditor/model/Doc/DocTextBlock.h @@ -83,6 +83,7 @@ public slots: // 关于框的一些其他部分 void setBlock(DocBlock* block); // 设置Block void remove(); // 移除本文本框 + void showBoundaryFrame(bool show); // 是否显示边界 protected: @@ -90,6 +91,8 @@ protected: void focusInEvent(QFocusEvent *e); void focusOutEvent(QFocusEvent *e); +private slots: + void contextMenuAboutToHideEvent(); // 右键菜单隐藏绑定事件 private: QString content; // 文字内容 @@ -111,9 +114,16 @@ private: QMenu * ContextMenu; // 右键菜单 DocBlock* block; // 本类型所在的block + qreal tempZValue; // 存储临时Z值 + signals: void signals_remove(); // 移除文本框的信号。 void signals_setZValue(qreal z); // 设置Z值的信号 + + // 用来控制Z值信号 + void signals_focusIn(); + void signals_focusOut(); + void signals_currentCharFormatChanged( QTextCharFormat& fmt); // 当前选择的charFormat发生了变化 void signals_currentBlockFormatChanged( -- Gitee From 6e06dc7a0120a93f37fac40770577792e6d87516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=B6=85=E7=BE=A4?= Date: Thu, 22 Jun 2017 17:19:55 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E9=A2=9C=E8=89=B2=EF=BC=8C=E5=AD=97=E4=BD=93=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E6=9C=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdEditor/model/Convert/OFD_DocConvertor.cpp | 221 ++++++++++++++---- ofdEditor/model/Convert/OFD_DocConvertor.h | 3 + ofdEditor/model/Convert/Objects/MinTextUnit.h | 18 +- ofdEditor/model/Doc/DocBlock.cpp | 6 +- ofdEditor/model/Doc/DocTextBlock.h | 2 +- ofdEditor/ofd/DataTypes/document/OFD.h | 2 +- ofdEditor/ofd/DataTypes/document/ofd.h | 2 +- ofdEditor/ofd/ofd_parser.h | 3 + 8 files changed, 202 insertions(+), 55 deletions(-) diff --git a/ofdEditor/model/Convert/OFD_DocConvertor.cpp b/ofdEditor/model/Convert/OFD_DocConvertor.cpp index efa7b27..5764488 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,6 +32,7 @@ OFD_DocConvertor::OFD_DocConvertor() DocPassage *OFD_DocConvertor::ofd_to_doc(OFD *ofd) { DocPassage * passage = NULL; + this->ofdFile = ofd; try{ @@ -190,69 +193,110 @@ 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); // 插入文本 + page->addBlock(block,layer); // 插入到场景中 - // 插入到场景中 - page->addBlock(block,layer); + } } @@ -265,3 +309,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 a636892..d10417d 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 @@ -53,6 +54,8 @@ private: DocPage::Layer layer, CT_Image *image); // 插入CT_Image + QColor ctColorToQColor(CT_Color* ct_color); // 颜色转换 + }; #endif // OFD_DOCCONVERTOR_H diff --git a/ofdEditor/model/Convert/Objects/MinTextUnit.h b/ofdEditor/model/Convert/Objects/MinTextUnit.h index b10c012..6d13f5f 100644 --- a/ofdEditor/model/Convert/Objects/MinTextUnit.h +++ b/ofdEditor/model/Convert/Objects/MinTextUnit.h @@ -3,8 +3,13 @@ #include #include +#include +#include +#include + #include "model_global.h" +// 中间转换的数据类型,为了求速度,全部设为公有数据. class MODELSHARED_EXPORT MinTextUnit : public QObject { @@ -12,13 +17,20 @@ class MODELSHARED_EXPORT MinTextUnit public: explicit MinTextUnit(QObject *parent = 0); + + signals: public slots: -private: - QColor fill_color; // 填充颜色 - QColor stroke_color; // 描边颜色 +public: + QColor fillColor; // 填充颜色 + QColor strokeColor; // 描边颜色 + QFont font; // 字体 + double x,y; // 左下角坐标 + QString text; // 内容 + double lt_x,lt_y,width,height; // 边界 + QVector delta_x; // 偏移量 }; diff --git a/ofdEditor/model/Doc/DocBlock.cpp b/ofdEditor/model/Doc/DocBlock.cpp index 14764ec..2f2c4aa 100644 --- a/ofdEditor/model/Doc/DocBlock.cpp +++ b/ofdEditor/model/Doc/DocBlock.cpp @@ -225,17 +225,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); // 执行重新进入,设置鼠标 } diff --git a/ofdEditor/model/Doc/DocTextBlock.h b/ofdEditor/model/Doc/DocTextBlock.h index a58afff..267baec 100644 --- a/ofdEditor/model/Doc/DocTextBlock.h +++ b/ofdEditor/model/Doc/DocTextBlock.h @@ -120,7 +120,7 @@ signals: void signals_remove(); // 移除文本框的信号。 void signals_setZValue(qreal z); // 设置Z值的信号 - // 用来控制Z值信号 + // 该块被focus的信号 void signals_focusIn(); void signals_focusOut(); diff --git a/ofdEditor/ofd/DataTypes/document/OFD.h b/ofdEditor/ofd/DataTypes/document/OFD.h index 8f5ded5..67d12a0 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 8f5ded5..67d12a0 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 91fbe63..79aa6b9 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; } + }; -- Gitee From 4d73b4858efd991e97a399ad6c9a0a50112d6003 Mon Sep 17 00:00:00 2001 From: "vera71@126.com" Date: Fri, 23 Jun 2017 15:10:26 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8F=92=E9=94=80?= =?UTF-8?q?=E5=92=8C=E9=87=8D=E5=81=9A=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BB=A5?= =?UTF-8?q?=E5=AD=97=E4=BD=93=E5=8A=A0=E7=B2=97=E4=B8=BA=E4=BE=8B=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdEditor/model/Command/commands.cpp | 22 +++++++++++++++ ofdEditor/model/Command/commands.h | 28 +++++++++++++++++++ ofdEditor/model/Doc/DocPassage.cpp | 2 ++ ofdEditor/model/Doc/DocPassage.h | 4 ++- ofdEditor/model/Doc/DocTextBlock.cpp | 22 +++++++++++---- ofdEditor/model/Doc/DocTextBlock.h | 1 + ofdEditor/model/model.pro | 6 ++-- .../start/ActionConnector/ActionConnector.cpp | 12 ++++++++ .../start/ActionConnector/ActionConnector.h | 2 ++ ofdEditor/start/ui/PassageMainWindow.cpp | 6 ++++ 10 files changed, 96 insertions(+), 9 deletions(-) create mode 100644 ofdEditor/model/Command/commands.cpp create mode 100644 ofdEditor/model/Command/commands.h diff --git a/ofdEditor/model/Command/commands.cpp b/ofdEditor/model/Command/commands.cpp new file mode 100644 index 0000000..17e3ed7 --- /dev/null +++ b/ofdEditor/model/Command/commands.cpp @@ -0,0 +1,22 @@ +#include "commands.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/commands.h b/ofdEditor/model/Command/commands.h new file mode 100644 index 0000000..89f76b6 --- /dev/null +++ b/ofdEditor/model/Command/commands.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/Doc/DocPassage.cpp b/ofdEditor/model/Doc/DocPassage.cpp index fe833da..644352f 100644 --- a/ofdEditor/model/Doc/DocPassage.cpp +++ b/ofdEditor/model/Doc/DocPassage.cpp @@ -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; diff --git a/ofdEditor/model/Doc/DocPassage.h b/ofdEditor/model/Doc/DocPassage.h index 005febf..ed78682 100644 --- a/ofdEditor/model/Doc/DocPassage.h +++ b/ofdEditor/model/Doc/DocPassage.h @@ -10,6 +10,7 @@ #include #include // 树状排布 #include +#include // 类声明 class DocPage; @@ -62,7 +63,8 @@ public slots: void testMessage(); // 测试信号是否走通 - +public: + QUndoStack *undoStack; diff --git a/ofdEditor/model/Doc/DocTextBlock.cpp b/ofdEditor/model/Doc/DocTextBlock.cpp index 1edb508..9339ffa 100644 --- a/ofdEditor/model/Doc/DocTextBlock.cpp +++ b/ofdEditor/model/Doc/DocTextBlock.cpp @@ -14,6 +14,7 @@ #include #include #include +#include DocTextBlock::DocTextBlock(QWidget *parent) @@ -267,13 +268,14 @@ void DocTextBlock::showBoundaryFrame(bool show) */ void DocTextBlock::textBold() { - QTextCharFormat fmt; - QTextCharFormat currentFormat = this->currentCharFormat(); // 当前选择文字的样式 - fmt.setFontWeight(currentFormat.fontWeight() != QFont::Bold ? // 设置粗细 - QFont::Bold : QFont::Normal); - - mergeFormatOnWordOrSelection(fmt); // 合并格式 +// 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); } /** @@ -305,6 +307,14 @@ void DocTextBlock::textBold(QTextCursor &cursor, int mode) } 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(); + } } /** diff --git a/ofdEditor/model/Doc/DocTextBlock.h b/ofdEditor/model/Doc/DocTextBlock.h index 267baec..bb5be83 100644 --- a/ofdEditor/model/Doc/DocTextBlock.h +++ b/ofdEditor/model/Doc/DocTextBlock.h @@ -18,6 +18,7 @@ class ParagraphFormatDialog;// 段落样式 class DocPassage; // 文章 class DocPage; // 获得所在页 class DocLayer; // 层 +class commands; class MODELSHARED_EXPORT DocTextBlock :public QTextEdit diff --git a/ofdEditor/model/model.pro b/ofdEditor/model/model.pro index e7b846c..2c2a558 100644 --- a/ofdEditor/model/model.pro +++ b/ofdEditor/model/model.pro @@ -50,7 +50,8 @@ SOURCES += model.cpp \ Convert/OFD_DocConvertor.cpp \ Convert/MergeCT_Texts.cpp \ Convert/Doc_OFDConvertor.cpp \ - Convert/Objects/MinTextUnit.cpp + Convert/Objects/MinTextUnit.cpp \ + Command/commands.cpp HEADERS += model.h\ model_global.h \ @@ -80,7 +81,8 @@ HEADERS += model.h\ Convert/OFD_DocConvertor.h \ Convert/MergeCT_Texts.h \ Convert/Doc_OFDConvertor.h \ - Convert/Objects/MinTextUnit.h + Convert/Objects/MinTextUnit.h \ + Command/commands.h DESTDIR = ../bin # 生成文件在这 MOC_DIR = ./moc # Q_OBJECT 类转换后的文件 diff --git a/ofdEditor/start/ActionConnector/ActionConnector.cpp b/ofdEditor/start/ActionConnector/ActionConnector.cpp index 8608a9a..9eae0db 100644 --- a/ofdEditor/start/ActionConnector/ActionConnector.cpp +++ b/ofdEditor/start/ActionConnector/ActionConnector.cpp @@ -87,6 +87,18 @@ void ActionConnector::addTableBlock() this->addNewBlock(blockInfo); } +void ActionConnector::undo() +{ + qDebug() <<"undo"; + this->passage->undoStack->undo(); +} + +void ActionConnector::redo() +{ + qDebug() <<"redo"; + this->passage->undoStack->redo(); +} + diff --git a/ofdEditor/start/ActionConnector/ActionConnector.h b/ofdEditor/start/ActionConnector/ActionConnector.h index ffe0728..9dd8be2 100644 --- a/ofdEditor/start/ActionConnector/ActionConnector.h +++ b/ofdEditor/start/ActionConnector/ActionConnector.h @@ -28,6 +28,8 @@ public slots: void addTextBlock(); // 插入文本框 void addImageBlock(); // 插入图片框 void addTableBlock(); // 插入表格 + void undo(); // undo + void redo(); // redo void setDefaultLayer(DocPage::Layer layer){this->defaultLayer = layer;} DocPage::Layer getDefaultLayer(){return this->defaultLayer;} diff --git a/ofdEditor/start/ui/PassageMainWindow.cpp b/ofdEditor/start/ui/PassageMainWindow.cpp index e915072..58f0365 100644 --- a/ofdEditor/start/ui/PassageMainWindow.cpp +++ b/ofdEditor/start/ui/PassageMainWindow.cpp @@ -261,6 +261,12 @@ void PassageMainWindow::connectAction() // 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())); // 插入文本框 -- Gitee From ff88d8af4865a7a9ec5259238ee5680c3e11a76f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=B6=85=E7=BE=A4?= Date: Fri, 23 Jun 2017 17:31:30 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E7=9A=84=E5=93=8D=E5=BA=94=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdEditor/model/Convert/Doc_OFDConvertor.cpp | 42 +++++++ ofdEditor/model/Convert/Doc_OFDConvertor.h | 28 ++++- ofdEditor/model/Convert/OFD_DocConvertor.h | 16 +-- ofdEditor/model/Doc/DocBlock.cpp | 38 +++++- ofdEditor/model/Doc/DocBlock.h | 7 ++ ofdEditor/model/Doc/DocPage.cpp | 34 +++++- ofdEditor/model/Doc/DocPage.h | 8 +- ofdEditor/model/Doc/DocPassage.cpp | 19 ++- ofdEditor/model/Doc/DocPassage.h | 25 ++-- ofdEditor/model/Doc/DocTextBlock.cpp | 114 ++++++++++++++++-- ofdEditor/model/Doc/DocTextBlock.h | 21 ++-- ofdEditor/model/Widget/DocInfoDialog.cpp | 14 +++ ofdEditor/model/Widget/DocInfoDialog.h | 22 ++++ ofdEditor/model/Widget/DocInfoDialog.ui | 71 +++++++++++ ofdEditor/model/Widget/FontSettingDialog.cpp | 2 +- ofdEditor/model/model.pro | 9 +- .../start/ActionConnector/ActionConnector.cpp | 30 ++--- .../start/ActionConnector/ActionConnector.h | 8 +- ofdEditor/start/ui/PassageMainWindow.cpp | 97 ++++++++++++++- ofdEditor/start/ui/PassageMainWindow.h | 19 ++- 20 files changed, 537 insertions(+), 87 deletions(-) create mode 100644 ofdEditor/model/Widget/DocInfoDialog.cpp create mode 100644 ofdEditor/model/Widget/DocInfoDialog.h create mode 100644 ofdEditor/model/Widget/DocInfoDialog.ui diff --git a/ofdEditor/model/Convert/Doc_OFDConvertor.cpp b/ofdEditor/model/Convert/Doc_OFDConvertor.cpp index 7943414..82ca3b2 100644 --- a/ofdEditor/model/Convert/Doc_OFDConvertor.cpp +++ b/ofdEditor/model/Convert/Doc_OFDConvertor.cpp @@ -1,7 +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 index e3df7be..79b32bd 100644 --- a/ofdEditor/model/Convert/Doc_OFDConvertor.h +++ b/ofdEditor/model/Convert/Doc_OFDConvertor.h @@ -2,17 +2,43 @@ #define DOC_OFDCONVERTOR_H #include +#include "model_global.h" -class Doc_OFDConvertor : public QObject +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.h b/ofdEditor/model/Convert/OFD_DocConvertor.h index d10417d..288a4bd 100644 --- a/ofdEditor/model/Convert/OFD_DocConvertor.h +++ b/ofdEditor/model/Convert/OFD_DocConvertor.h @@ -28,33 +28,33 @@ 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(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); // 颜色转换 + QColor ctColorToQColor(CT_Color* ct_color); // 颜色转换 }; diff --git a/ofdEditor/model/Doc/DocBlock.cpp b/ofdEditor/model/Doc/DocBlock.cpp index 2f2c4aa..49d029f 100644 --- a/ofdEditor/model/Doc/DocBlock.cpp +++ b/ofdEditor/model/Doc/DocBlock.cpp @@ -155,6 +155,8 @@ void DocBlock::remove() { QGraphicsScene *scene = this->scene(); // 查找到本块所在的场景 scene->removeItem(this); // 从场景中移除该组件 + + emit this->signals_blockRemoved(this); // 发出信号 } @@ -348,12 +350,13 @@ void DocBlock::setWidget(QWidget *widget) void DocBlock::setWidget(DocTextBlock *textBlock) { // 建立connect - connect(textBlock,SIGNAL(signals_remove()), + connect(textBlock,SIGNAL(signals_remove(DocTextBlock*)), this,SLOT(remove())); // 和块做移除连接 connect(textBlock,SIGNAL(signals_setZValue(qreal)), this,SLOT(setZValue(qreal))); // 建立设置Z值的信号连接 - textBlock->setBlock(this); // 设置引用 + textBlock->setBlock(this); // 给DocTextBlock设置引用 + this->textBlock = textBlock; // 给DocBlock设置引用 QGraphicsProxyWidget::setWidget(textBlock); } @@ -407,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 1895c41..48a842a 100644 --- a/ofdEditor/model/Doc/DocBlock.h +++ b/ofdEditor/model/Doc/DocBlock.h @@ -36,6 +36,8 @@ public: qreal getZValue(){return this->realZValue;} // 获得当前块所在的Z值 RectAdjustStatus currentStatus(const QPointF& pos); // 鼠标所在位置可以进行什么调整 + bool isTextBlock(); // 判断是否DocBlock装的是否是DocTextBlock + DocTextBlock *getTextBlock(); // 获得DocTextBlock public slots: // 槽函数 void setLayer(DocLayer * layer){this->layer = layer;} @@ -73,11 +75,16 @@ private: QSizeF blockSize; // 用来纪录大小 QPointF blockOldPos; // 用来记录旧的位置 + DocTextBlock* textBlock; // 存下引用 + bool isFocused; // 是否被聚焦 bool blockIsResizing; // 是否正在改变大小 bool isInResizeArea(const QPointF& pos); // 检查鼠标是否在重置大小区域 qreal realZValue; // 真实的z值 +signals: + void signals_blockRemoved(DocBlock* block); // 当本块被移除时发出信号 + }; #endif // DOCBLOCK_H diff --git a/ofdEditor/model/Doc/DocPage.cpp b/ofdEditor/model/Doc/DocPage.cpp index 6b871ce..a01ce4a 100644 --- a/ofdEditor/model/Doc/DocPage.cpp +++ b/ofdEditor/model/Doc/DocPage.cpp @@ -109,10 +109,28 @@ 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*))); + + } + + // 分到层 switch (layer) { case Body: this->bodyLayer->addBlock(block); @@ -130,7 +148,6 @@ void DocPage::addBlock(DocBlock *block, DocPage::Layer layer) break; } - } /** @@ -179,6 +196,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 diff --git a/ofdEditor/model/Doc/DocPage.h b/ofdEditor/model/Doc/DocPage.h index 6519553..8291d08 100644 --- a/ofdEditor/model/Doc/DocPage.h +++ b/ofdEditor/model/Doc/DocPage.h @@ -56,6 +56,7 @@ public slots: void setBlockFlag(BlockFlag flag){this->newBlockFlag = flag;} void setInsertBlockType(InsertBlockInfo& blockInfo); // 设置下一个要插入的block的信息 + void remove(); // 移除本页 protected: void paintEvent(QPaintEvent *event); @@ -69,7 +70,6 @@ private: void init(); // 初始化UI DocPassage * passage; // 页所属文章 DocPageScene* docScene; // 场景数据 - //QVector layers; // 一个文档具有很多层 DocLayer* foregroundLayer; // 前景层 DocLayer* bodyLayer; // 正文层 @@ -88,12 +88,12 @@ private: QPointF newPos; // 新点 BlockFlag newBlockFlag; // 是否画块 - -// QList items; DocBlock * activeBlock; // 正在活跃的那个DocBlock signals: // 信号 - void signals_remove(); // 本页面被移除信号 + + void signals_insertTextBlock(DocTextBlock* textBlock ); // 插入文本框信号 + void signals_removeTextBlock(DocTextBlock* textBlock ); // 移除文本框信号 }; diff --git a/ofdEditor/model/Doc/DocPassage.cpp b/ofdEditor/model/Doc/DocPassage.cpp index fe833da..d0b3573 100644 --- a/ofdEditor/model/Doc/DocPassage.cpp +++ b/ofdEditor/model/Doc/DocPassage.cpp @@ -243,10 +243,10 @@ DocPage *DocPassage::getPage(int index) * @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 @@ -255,13 +255,10 @@ DocPage *DocPassage::getPage(int index) * @return CT_CommonData * @date 2017/05/23 */ -//CT_CommonData DocPassage::getCommonData() -//{ -// CT_CommonData common; -// common.copy(this->commonData); - -// return common; -//} +CT_CommonData* DocPassage::getCommonData() +{ + return this->commonData; +} /** * @Author Chaoqun diff --git a/ofdEditor/model/Doc/DocPassage.h b/ofdEditor/model/Doc/DocPassage.h index 005febf..67817f6 100644 --- a/ofdEditor/model/Doc/DocPassage.h +++ b/ofdEditor/model/Doc/DocPassage.h @@ -10,6 +10,8 @@ #include #include // 树状排布 #include +#include +#include // 类声明 class DocPage; @@ -51,8 +53,8 @@ public slots: void setDocInfo( CT_DocInfo & docInfo ); // 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;} @@ -62,22 +64,16 @@ public slots: 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; // 既作为数据,也作为渲染 @@ -92,16 +88,21 @@ private: int horizontalWhite; // 白色页面左右两边的灰色区域 int verticalWhite; // 白色页面上下的灰色区域 - -private: void init(); // 初始化 void adjustScrollBar(QScrollBar *scrollBar, 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 1edb508..af90c27 100644 --- a/ofdEditor/model/Doc/DocTextBlock.cpp +++ b/ofdEditor/model/Doc/DocTextBlock.cpp @@ -234,7 +234,7 @@ void DocTextBlock::setBlock(DocBlock *block) */ void DocTextBlock::remove() { - emit signals_remove(); // 发送信号,remove + emit signals_remove(this); // 发送信号,remove } /** @@ -599,6 +599,35 @@ void DocTextBlock::setCharFormatOnWordOrSelection( 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); // 设置字符格式 +} + /** * @Author Chaoqun * @brief 显示右键菜单 @@ -641,7 +670,8 @@ void DocTextBlock::contextMenuEvent(QContextMenuEvent *event) void DocTextBlock::focusInEvent(QFocusEvent *e) { this->showBoundaryFrame(true); - emit this->signals_focusIn(); + + emitFormatSignals(); // 当鼠标移进时,必须发出信号 QTextEdit::focusInEvent(e); } @@ -656,7 +686,6 @@ void DocTextBlock::focusInEvent(QFocusEvent *e) void DocTextBlock::focusOutEvent(QFocusEvent *e) { this->showBoundaryFrame(false); - emit this->signals_focusOut(); QTextEdit::focusOutEvent(e); } @@ -674,6 +703,72 @@ void DocTextBlock::contextMenuAboutToHideEvent() 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 初始化函数 @@ -694,17 +789,15 @@ void DocTextBlock::init() // 无边框 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相关 } @@ -780,7 +873,6 @@ void DocTextBlock::initAcitons() } - /** * @Author Chaoqun * @brief 初始化文字的样式 diff --git a/ofdEditor/model/Doc/DocTextBlock.h b/ofdEditor/model/Doc/DocTextBlock.h index 267baec..25d5609 100644 --- a/ofdEditor/model/Doc/DocTextBlock.h +++ b/ofdEditor/model/Doc/DocTextBlock.h @@ -59,10 +59,17 @@ public slots: 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( @@ -93,6 +100,8 @@ protected: private slots: void contextMenuAboutToHideEvent(); // 右键菜单隐藏绑定事件 + void checkCurrentFormat(); // 检查当前的格式是否发生改变 + void emitFormatSignals(); // 发射格式的信号 private: QString content; // 文字内容 @@ -116,20 +125,18 @@ private: qreal tempZValue; // 存储临时Z值 + QTextBlockFormat _currentBlockFormat; // 当前BlockFormat + QTextCharFormat _currentCharFormat; // 当前 + signals: - void signals_remove(); // 移除文本框的信号。 + void signals_remove(DocTextBlock* textBlock); // 移除文本框的信号。 void signals_setZValue(qreal z); // 设置Z值的信号 - // 该块被focus的信号 - void signals_focusIn(); - void signals_focusOut(); - 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 0000000..513a161 --- /dev/null +++ b/ofdEditor/model/Widget/DocInfoDialog.cpp @@ -0,0 +1,14 @@ +#include "DocInfoDialog.h" +#include "ui_DocInfoDialog.h" + +DocInfoDialog::DocInfoDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::DocInfoDialog) +{ + ui->setupUi(this); +} + +DocInfoDialog::~DocInfoDialog() +{ + delete ui; +} diff --git a/ofdEditor/model/Widget/DocInfoDialog.h b/ofdEditor/model/Widget/DocInfoDialog.h new file mode 100644 index 0000000..b911605 --- /dev/null +++ b/ofdEditor/model/Widget/DocInfoDialog.h @@ -0,0 +1,22 @@ +#ifndef DOCINFODIALOG_H +#define DOCINFODIALOG_H + +#include + +namespace Ui { +class DocInfoDialog; +} + +class DocInfoDialog : public QDialog +{ + Q_OBJECT + +public: + explicit DocInfoDialog(QWidget *parent = 0); + ~DocInfoDialog(); + +private: + Ui::DocInfoDialog *ui; +}; + +#endif // DOCINFODIALOG_H diff --git a/ofdEditor/model/Widget/DocInfoDialog.ui b/ofdEditor/model/Widget/DocInfoDialog.ui new file mode 100644 index 0000000..2b9d3bf --- /dev/null +++ b/ofdEditor/model/Widget/DocInfoDialog.ui @@ -0,0 +1,71 @@ + + + + + DocInfoDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 30 + 240 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + 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 84732d1..5b2f4a5 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/model.pro b/ofdEditor/model/model.pro index e7b846c..b43e9e8 100644 --- a/ofdEditor/model/model.pro +++ b/ofdEditor/model/model.pro @@ -50,7 +50,8 @@ SOURCES += model.cpp \ Convert/OFD_DocConvertor.cpp \ Convert/MergeCT_Texts.cpp \ Convert/Doc_OFDConvertor.cpp \ - Convert/Objects/MinTextUnit.cpp + Convert/Objects/MinTextUnit.cpp \ + Widget/DocInfoDialog.cpp HEADERS += model.h\ model_global.h \ @@ -80,7 +81,8 @@ HEADERS += model.h\ Convert/OFD_DocConvertor.h \ Convert/MergeCT_Texts.h \ Convert/Doc_OFDConvertor.h \ - Convert/Objects/MinTextUnit.h + Convert/Objects/MinTextUnit.h \ + Widget/DocInfoDialog.h DESTDIR = ../bin # 生成文件在这 MOC_DIR = ./moc # Q_OBJECT 类转换后的文件 @@ -107,4 +109,5 @@ win32{ FORMS += \ Widget/ParagraphFormatWidget.ui \ Widget/ParagraphFormatDialog.ui \ - Widget/FontSettingDialog.ui + Widget/FontSettingDialog.ui \ + Widget/DocInfoDialog.ui diff --git a/ofdEditor/start/ActionConnector/ActionConnector.cpp b/ofdEditor/start/ActionConnector/ActionConnector.cpp index 8608a9a..eaa8186 100644 --- a/ofdEditor/start/ActionConnector/ActionConnector.cpp +++ b/ofdEditor/start/ActionConnector/ActionConnector.cpp @@ -34,7 +34,7 @@ void ActionConnector::setMainWindow(PassageMainWindow *mainWindow) */ void ActionConnector::addNewPage() { - this->updateActivePassage(); // 更新选择的文章。 + this->passage->appendNewPage(); // 在队尾增加一页 } @@ -49,7 +49,7 @@ void ActionConnector::addNewPage() void ActionConnector::addNewBlock(InsertBlockInfo& blockInfo) { - this->updateActivePassage(); // 更新文章 +// this->updateActivePassage(); // 更新文章 DocPage * page = qobject_cast(this->passage->focusWidget()); if(page == NULL) { @@ -87,29 +87,29 @@ void ActionConnector::addTableBlock() this->addNewBlock(blockInfo); } - - - /** * @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"; + return; + } + DocPassage* passage = qobject_cast(window->widget()); // 获得文档 + if(passage == NULL) { - qDebug()<< " You haven't select any passage. " - <<"void ActionConnector::updateActivePassage()"; - this->passage = NULL; + qDebug()<< "The active MdiWindow may not DocPassage"; } else { - this->passage = temp; - // 待CT_DocType配置好了,这里可以输出文档名称 + this->passage = passage; } } diff --git a/ofdEditor/start/ActionConnector/ActionConnector.h b/ofdEditor/start/ActionConnector/ActionConnector.h index ffe0728..62f82d6 100644 --- a/ofdEditor/start/ActionConnector/ActionConnector.h +++ b/ofdEditor/start/ActionConnector/ActionConnector.h @@ -3,6 +3,7 @@ #include #include "Doc/DocPage.h" +#include class DocPassage; class PassageMainWindow; @@ -21,6 +22,8 @@ public: ActionConnector(); ActionConnector(PassageMainWindow * mainWindow); + DocPage::Layer getDefaultLayer(){return this->defaultLayer;} + public slots: void setMainWindow(PassageMainWindow * mainWindow); // 设置主窗口 void addNewPage(); // 添加一个新页面 @@ -30,15 +33,14 @@ public slots: void addTableBlock(); // 插入表格 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/ui/PassageMainWindow.cpp b/ofdEditor/start/ui/PassageMainWindow.cpp index e915072..f7e0505 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,11 @@ DocPassage *PassageMainWindow::createMdiChild() DocPassage * child = new DocPassage(this); child->addPage(new DocPage()); // 添加一个空白页 - this->area->addSubWindow(child); - child->setVisible(true); // 设置可见 - child->showMaximized(); +// this->area->addSubWindow(child); +// child->setVisible(true); // 设置可见 +// child->showMaximized(); + this->addDocPassage(child); // 加入到本视区 + return child; } @@ -269,6 +275,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 +331,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; // 留下引用 + + // 更新界面显示 } /** @@ -359,5 +436,17 @@ DocPassage *PassageMainWindow::addDocPassage(DocPassage *passage) this->area->addSubWindow(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 6d8ed6c..d07719f 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; // 函数功能的中间件 // 编辑窗口的主界面 @@ -72,6 +77,7 @@ private: QAction * helpAciton; // 帮助文档,如何使用本软件 QMdiArea * area; // 多窗口区域 + QVectorpassages; // 存储所有的passage ActionConnector* connector; // 功能连接中间件 @@ -81,12 +87,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); // 接受当前处理的字符格式 }; -- Gitee From a2fad887d9b6304bdb7b28a127d661a4bffb70db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=B6=85=E7=BE=A4?= Date: Fri, 23 Jun 2017 20:09:09 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9Model=E5=90=8E=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdEditor/model/Convert/OFD_DocConvertor.cpp | 26 +++++++++++--------- ofdEditor/model/Convert/OFD_DocConvertor.h | 3 ++- ofdEditor/model/Doc/DocPage.cpp | 1 + 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/ofdEditor/model/Convert/OFD_DocConvertor.cpp b/ofdEditor/model/Convert/OFD_DocConvertor.cpp index 5764488..ba8a2aa 100644 --- a/ofdEditor/model/Convert/OFD_DocConvertor.cpp +++ b/ofdEditor/model/Convert/OFD_DocConvertor.cpp @@ -37,7 +37,7 @@ DocPassage *OFD_DocConvertor::ofd_to_doc(OFD *ofd) try{ passage = new DocPassage(); - + passage->setVisible(false); // version passage->setVersion(ofd->getOfdVersion()); passage->setDocType(ofd->getDocType()); @@ -57,9 +57,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(...) @@ -67,10 +66,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 @@ -91,6 +91,7 @@ DocPage *OFD_DocConvertor::buildDocPage(Page *ct_page) page = new DocPage(); } + passage->addPage(page); // 加入到文章中来 page->setVisible(false); // 先隐藏显示 // 将每一层加入到页中 @@ -98,7 +99,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); // 将该层的内容加入到页面中 } @@ -193,7 +194,7 @@ void OFD_DocConvertor::insertPageBlock(DocPage *page, */ void OFD_DocConvertor::insertCT_Text(DocPage *page, DocPage::Layer layer, CT_Text *text) { - qDebug() << "execute insert CT_Text" << text->getID(); +// qDebug() << "execute insert CT_Text" << text->getID(); CT_Color * fillColor = text->getFillColor(); // 获得填充颜色 QColor color = this->ctColorToQColor(fillColor); // 获得填充颜色 @@ -208,9 +209,9 @@ void OFD_DocConvertor::insertCT_Text(DocPage *page, DocPage::Layer layer, CT_Tex CT_Font* ctFont = (CT_Font*) base_font; QString font_name = ctFont->getFontName(); // 字体名 QString family_name = ctFont->getFamilyName(); // 字体族名 - qDebug() << font_name << " "<< family_name; +// qDebug() << font_name << " "<< family_name; textFont.setFamily(family_name); - qDebug() << "After setting font family :"<getText(); // 文本内容 qDebug() << "insert Content:" << content; - DocTextBlock *textBlock = new DocTextBlock(); - DocBlock *block = new DocBlock(); - block->setWidget(textBlock); + DocTextBlock *textBlock = new DocTextBlock(); // 新建文本块 + DocBlock *block = new DocBlock(); // 新建块 + block->setWidget(textBlock); // 将块放入文本块中 block->resize(UnitTool::mmToPixel(width), UnitTool::mmToPixel(height)); // 调整块大小 @@ -294,6 +295,7 @@ void OFD_DocConvertor::insertCT_Text(DocPage *page, DocPage::Layer layer, CT_Tex cursor.insertText(content); // 插入文本 +// qDebug()<<"page->addBlock"; page->addBlock(block,layer); // 插入到场景中 } diff --git a/ofdEditor/model/Convert/OFD_DocConvertor.h b/ofdEditor/model/Convert/OFD_DocConvertor.h index 288a4bd..035c000 100644 --- a/ofdEditor/model/Convert/OFD_DocConvertor.h +++ b/ofdEditor/model/Convert/OFD_DocConvertor.h @@ -33,7 +33,8 @@ public: private: OFD * ofdFile; // 当前处理时使用的ofd文件-用来方便获取到公用的特征 - DocPage * buildDocPage(Page * ct_page); // 生成页 + DocPage * buildDocPage(DocPassage * passage , + Page * ct_page); // 生成页 void insertLayer(DocPage * page, CT_Layer * layer ); // 将每一层加入到页中 diff --git a/ofdEditor/model/Doc/DocPage.cpp b/ofdEditor/model/Doc/DocPage.cpp index a01ce4a..e5c94f2 100644 --- a/ofdEditor/model/Doc/DocPage.cpp +++ b/ofdEditor/model/Doc/DocPage.cpp @@ -129,6 +129,7 @@ void DocPage::addBlock(DocBlock *block, DocPage::Layer layer) passage,SIGNAL(signals_currentTextBlock(DocTextBlock*))); } +// qDebug()<< "connect"; // 分到层 switch (layer) { -- Gitee From d78c8fc4f26d8e07c75d7509d77bad01f1d3d450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=B6=85=E7=BE=A4?= Date: Sat, 24 Jun 2017 00:53:40 +0800 Subject: [PATCH 11/12] =?UTF-8?q?=E5=AE=8C=E5=96=84=20DocInfo=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E7=9A=84=E5=8A=9F=E8=83=BD=E5=B0=8F=E9=83=A8=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdEditor/model/Convert/OFD_DocConvertor.cpp | 3 +- ofdEditor/model/Doc/DocBlock.h | 4 - ofdEditor/model/Doc/DocPassage.cpp | 28 +- ofdEditor/model/Doc/DocPassage.h | 13 +- ofdEditor/model/Widget/DocInfoDialog.cpp | 126 +++ ofdEditor/model/Widget/DocInfoDialog.h | 21 +- ofdEditor/model/Widget/DocInfoDialog.ui | 228 ++++- .../model/Widget/ParagraphFormatDialog.ui | 600 ++++++------ .../model/Widget/ParagraphFormatWidget.ui | 872 +++++++----------- .../start/ActionConnector/ActionConnector.cpp | 33 + .../start/ActionConnector/ActionConnector.h | 1 + ofdEditor/start/ui/PassageMainWindow.cpp | 7 + ofdEditor/start/ui/PassageMainWindow.h | 1 + 13 files changed, 1039 insertions(+), 898 deletions(-) diff --git a/ofdEditor/model/Convert/OFD_DocConvertor.cpp b/ofdEditor/model/Convert/OFD_DocConvertor.cpp index ba8a2aa..ea000f2 100644 --- a/ofdEditor/model/Convert/OFD_DocConvertor.cpp +++ b/ofdEditor/model/Convert/OFD_DocConvertor.cpp @@ -44,7 +44,8 @@ DocPassage *OFD_DocConvertor::ofd_to_doc(OFD *ofd) QVector * bodys = ofd->getDocBodies(); DocBody * docBody = (*bodys)[0]; // DocBody - passage->setDocInfo(*(docBody->getDocInfo())); + + passage->setDocInfo(*(docBody->getDocInfo())); // 设置文档元信息 Document * document = (*(ofd->getDocuments()))[0]; // Document diff --git a/ofdEditor/model/Doc/DocBlock.h b/ofdEditor/model/Doc/DocBlock.h index 48a842a..76fbfde 100644 --- a/ofdEditor/model/Doc/DocBlock.h +++ b/ofdEditor/model/Doc/DocBlock.h @@ -50,8 +50,6 @@ public slots: // 槽函数 void setWidget(QWidget* widget); // 旧的函数 void setWidget(DocTextBlock *textBlock); // SetWidget - - protected: void paint(QPainter *painter, @@ -67,8 +65,6 @@ protected: void mouseReleaseEvent (QGraphicsSceneMouseEvent * event); void contextMenuEvent (QGraphicsSceneContextMenuEvent *event); // 邮件菜单吧 - - private: DocBox boundary; // 该块的外包矩形 DocLayer * layer; // 该块在哪一个层之中 diff --git a/ofdEditor/model/Doc/DocPassage.cpp b/ofdEditor/model/Doc/DocPassage.cpp index 92cbcc8..3364acf 100644 --- a/ofdEditor/model/Doc/DocPassage.cpp +++ b/ofdEditor/model/Doc/DocPassage.cpp @@ -10,7 +10,7 @@ #include #include #include - +#include /** * @Author Chaoqun @@ -193,7 +193,7 @@ void DocPassage::setDocInfo(CT_DocInfo &docInfo) * @brief 测试 * @param 参数 * @return 返回值 - * @date 2017/06/xx + * @date 2017/06/22 */ void DocPassage::testMessage() { @@ -207,11 +207,9 @@ void DocPassage::testMessage() * @return CT_DocInfo * @date 2017/05/23 */ -CT_DocInfo DocPassage::getDocInfo() +CT_DocInfo *DocPassage::getDocInfo() { - CT_DocInfo docInfo; - docInfo.copy( *this->docInfo); - return docInfo; + return this->docInfo; } /** @@ -262,6 +260,22 @@ CT_CommonData* DocPassage::getCommonData() return this->commonData; } +/** + * @Author Chaoqun + * @brief 设置 docID + * @param void + * @return void + * @date 2017/06/23 + */ +void DocPassage::resetDocId() +{ + QUuid uuid = QUuid::createUuid(); // 创建uuid + QString docId = uuid.toString(); // 转换为字符串 + qDebug() << "uuid : " << docId; + + this->docInfo->setDocID(docId); +} + /** * @Author Chaoqun * @brief 设置重置响应事件,窗口大小发生调整,将会调用这个函数u @@ -289,6 +303,8 @@ void DocPassage::closeEvent(QCloseEvent *event) void DocPassage::init() { + this->docInfo = new CT_DocInfo(); // 新建文档 元信息 + this->resetDocId(); // 设置UUID this->layout = new QVBoxLayout; // 新建布局 // 新增widget diff --git a/ofdEditor/model/Doc/DocPassage.h b/ofdEditor/model/Doc/DocPassage.h index 0502ecb..9a5e7d2 100644 --- a/ofdEditor/model/Doc/DocPassage.h +++ b/ofdEditor/model/Doc/DocPassage.h @@ -13,6 +13,8 @@ #include #include #include +#include + // 类声明 class DocPage; @@ -36,7 +38,7 @@ public: QString docType,double scaleFactor); ~DocPassage(); - CT_DocInfo getDocInfo(); // 获取CT_DocInfo数据 + CT_DocInfo* getDocInfo(); // 获取CT_DocInfo数据 QString getVersion( ){return this->version;} QString getDocType( ){return this->docType;} QVector& getPages(); // 获得文档中包含的所有页面 @@ -64,6 +66,9 @@ public slots: // DocType void setDocType(QString docType){this->docType = docType;} + // docId + void resetDocId(); // 重新设置DocId + void testMessage(); // 测试信号是否走通 protected: @@ -79,6 +84,12 @@ private: QVector pages; // 既作为数据,也作为渲染 + // 文件信息 + QString filePath; + QString fileName; + QString tempPath; // 保存成文件前的临时路径 + // 个人觉得可以用上UUID tmp/"uuid-fileName" + // 渲染区 QVBoxLayout * layout; // 纵向排列 QWidget * widget; // 用widget做缓冲 diff --git a/ofdEditor/model/Widget/DocInfoDialog.cpp b/ofdEditor/model/Widget/DocInfoDialog.cpp index 513a161..5054d2b 100644 --- a/ofdEditor/model/Widget/DocInfoDialog.cpp +++ b/ofdEditor/model/Widget/DocInfoDialog.cpp @@ -1,6 +1,10 @@ #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) @@ -8,7 +12,129 @@ DocInfoDialog::DocInfoDialog(QWidget *parent) : 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(); + 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 index b911605..1593f96 100644 --- a/ofdEditor/model/Widget/DocInfoDialog.h +++ b/ofdEditor/model/Widget/DocInfoDialog.h @@ -2,21 +2,40 @@ #define DOCINFODIALOG_H #include +#include "model_global.h" +class CT_DocInfo; // 文档元信息 namespace Ui { class DocInfoDialog; } -class DocInfoDialog : public QDialog +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 index 2b9d3bf..28d14a4 100644 --- a/ofdEditor/model/Widget/DocInfoDialog.ui +++ b/ofdEditor/model/Widget/DocInfoDialog.ui @@ -1,25 +1,23 @@ + - - - DocInfoDialog - + 0 0 - 400 - 300 + 483 + 641 Dialog - + - 30 - 240 + 70 + 590 341 32 @@ -31,8 +29,218 @@ QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + 10 + 20 + 461 + 361 + + + + 说明 + + + + + 21 + 21 + 411 + 301 + + + + + + + 文件: + + + + + + + 文档ID: + + + + + + + 更改 + + + + + + + 标题: + + + + + + + + + + 作者: + + + + + + + + + + 主题: + + + + + + + + + + 摘要: + + + + + + + + + + 关键字: + + + + + + + + + + 文档类型: + + + + + + + + + + 文档封面: + + + + + + + + + + 创建日期: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 10 + 420 + 461 + 151 + + + + 高级 + + + + + 20 + 30 + 431 + 111 + + + + + + + 最近修改时间: + + + + + + + + + + + + + + 创建应用程序: + + + + + + + + + + + + + + 应用程序版本: + + + + + + + + + + + + + - diff --git a/ofdEditor/model/Widget/ParagraphFormatDialog.ui b/ofdEditor/model/Widget/ParagraphFormatDialog.ui index 661cb5e..c5adafc 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 993df7d..a4b4401 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/start/ActionConnector/ActionConnector.cpp b/ofdEditor/start/ActionConnector/ActionConnector.cpp index f26a75e..badff0f 100644 --- a/ofdEditor/start/ActionConnector/ActionConnector.cpp +++ b/ofdEditor/start/ActionConnector/ActionConnector.cpp @@ -2,6 +2,8 @@ #include "Doc/DocPassage.h" #include "ui/PassageMainWindow.h" #include "Doc/DocPage.h" +#include "DataTypes/document/ct_docinfo.h" +#include "Widget/DocInfoDialog.h" #include #include @@ -18,6 +20,22 @@ ActionConnector::ActionConnector(PassageMainWindow *mainWindow) init(); } +void ActionConnector::showAttribute() +{ + if(this->passage == NULL) + { + qDebug() << "show attribute"; + 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; @@ -35,6 +53,8 @@ void ActionConnector::setMainWindow(PassageMainWindow *mainWindow) void ActionConnector::addNewPage() { + if(this->passage == NULL) + return; this->passage->appendNewPage(); // 在队尾增加一页 } @@ -48,6 +68,10 @@ void ActionConnector::addNewPage() */ void ActionConnector::addNewBlock(InsertBlockInfo& blockInfo) { + if(this->passage == NULL) + { + return; + } // this->updateActivePassage(); // 更新文章 DocPage * page = qobject_cast(this->passage->focusWidget()); @@ -71,18 +95,24 @@ 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); } @@ -115,12 +145,14 @@ void ActionConnector::updateActivePassage(QMdiSubWindow *window) { qDebug() << "updateActivePassage NULL" << "there's no actived window"; + this->passage = NULL; return; } DocPassage* passage = qobject_cast(window->widget()); // 获得文档 if(passage == NULL) { qDebug()<< "The active MdiWindow may not DocPassage"; + this->passage = NULL; } else { @@ -131,4 +163,5 @@ void ActionConnector::updateActivePassage(QMdiSubWindow *window) 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 9020998..b2d2eb6 100644 --- a/ofdEditor/start/ActionConnector/ActionConnector.h +++ b/ofdEditor/start/ActionConnector/ActionConnector.h @@ -25,6 +25,7 @@ public: DocPage::Layer getDefaultLayer(){return this->defaultLayer;} public slots: + void showAttribute(); // 显示文档元信息 void setMainWindow(PassageMainWindow * mainWindow); // 设置主窗口 void addNewPage(); // 添加一个新页面 void addNewBlock(InsertBlockInfo &blockInfo); // 插入一个块 diff --git a/ofdEditor/start/ui/PassageMainWindow.cpp b/ofdEditor/start/ui/PassageMainWindow.cpp index aa004e8..4fe5af5 100644 --- a/ofdEditor/start/ui/PassageMainWindow.cpp +++ b/ofdEditor/start/ui/PassageMainWindow.cpp @@ -121,6 +121,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); @@ -199,6 +202,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); @@ -261,6 +265,9 @@ 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())); // 在文章尾部加入新的一页 diff --git a/ofdEditor/start/ui/PassageMainWindow.h b/ofdEditor/start/ui/PassageMainWindow.h index d07719f..8ac6311 100644 --- a/ofdEditor/start/ui/PassageMainWindow.h +++ b/ofdEditor/start/ui/PassageMainWindow.h @@ -51,6 +51,7 @@ private: QAction * saveAction; // 保存 QAction * saveAsAction; // 另存为 QAction * printAction; // 打印 + QAction * attributeAction; // 文档属性 // 编辑 QAction * undoAction; // 撤销 -- Gitee From 0d85d3f4bdb7acc2386628b63a90fc850f57d10d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=B6=85=E7=BE=A4?= Date: Sat, 24 Jun 2017 15:29:13 +0800 Subject: [PATCH 12/12] =?UTF-8?q?APPInfo=EF=BC=8C=20=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E4=BA=86=E4=B8=80=E4=BA=9B=E9=97=AE=E9=A2=98=EF=BC=8C=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E8=BD=AC=E7=94=A8XML=E6=96=87=E4=BB=B6=E5=AD=98?= =?UTF-8?q?=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdEditor/model/Doc/DocPassage.cpp | 9 ++++ ofdEditor/model/Widget/DocInfoDialog.cpp | 8 ++++ ofdEditor/model/Widget/DocInfoDialog.h | 1 - .../start/ActionConnector/ActionConnector.cpp | 10 ++++- .../start/ActionConnector/ActionConnector.h | 2 + ofdEditor/start/app/APPInfo.cpp | 45 +++++++++++++++++++ ofdEditor/start/app/APPInfo.h | 30 +++++++++++++ ofdEditor/start/appinfo.qrc | 5 +++ ofdEditor/start/source/appInfo.json | 4 ++ ofdEditor/start/start.pro | 9 ++-- ofdEditor/start/ui/PassageMainWindow.cpp | 7 ++- 11 files changed, 121 insertions(+), 9 deletions(-) create mode 100644 ofdEditor/start/app/APPInfo.cpp create mode 100644 ofdEditor/start/app/APPInfo.h create mode 100644 ofdEditor/start/appinfo.qrc create mode 100644 ofdEditor/start/source/appInfo.json diff --git a/ofdEditor/model/Doc/DocPassage.cpp b/ofdEditor/model/Doc/DocPassage.cpp index 3364acf..66e39e5 100644 --- a/ofdEditor/model/Doc/DocPassage.cpp +++ b/ofdEditor/model/Doc/DocPassage.cpp @@ -271,6 +271,15 @@ 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); diff --git a/ofdEditor/model/Widget/DocInfoDialog.cpp b/ofdEditor/model/Widget/DocInfoDialog.cpp index 5054d2b..d9d8601 100644 --- a/ofdEditor/model/Widget/DocInfoDialog.cpp +++ b/ofdEditor/model/Widget/DocInfoDialog.cpp @@ -133,6 +133,14 @@ 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); diff --git a/ofdEditor/model/Widget/DocInfoDialog.h b/ofdEditor/model/Widget/DocInfoDialog.h index 1593f96..463453a 100644 --- a/ofdEditor/model/Widget/DocInfoDialog.h +++ b/ofdEditor/model/Widget/DocInfoDialog.h @@ -24,7 +24,6 @@ private: Ui::DocInfoDialog *ui; CT_DocInfo* docInfo; // 文档元信息 void init(); // 初始化 - void initUi(); // 初始化ui public slots: diff --git a/ofdEditor/start/ActionConnector/ActionConnector.cpp b/ofdEditor/start/ActionConnector/ActionConnector.cpp index badff0f..d555724 100644 --- a/ofdEditor/start/ActionConnector/ActionConnector.cpp +++ b/ofdEditor/start/ActionConnector/ActionConnector.cpp @@ -5,6 +5,8 @@ #include "DataTypes/document/ct_docinfo.h" #include "Widget/DocInfoDialog.h" +#include "app/APPInfo.h" + #include #include @@ -24,7 +26,7 @@ void ActionConnector::showAttribute() { if(this->passage == NULL) { - qDebug() << "show attribute"; + qDebug() << "show attribute this->passage == NULL"; return; } @@ -129,6 +131,11 @@ void ActionConnector::redo() this->passage->undoStack->redo(); } +void ActionConnector::setDocPassage(DocPassage *passage) +{ + this->passage = passage; +} + @@ -164,4 +171,5 @@ 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 b2d2eb6..878056b 100644 --- a/ofdEditor/start/ActionConnector/ActionConnector.h +++ b/ofdEditor/start/ActionConnector/ActionConnector.h @@ -5,6 +5,7 @@ #include "Doc/DocPage.h" #include + class DocPassage; class PassageMainWindow; @@ -34,6 +35,7 @@ public slots: void addTableBlock(); // 插入表格 void undo(); // undo void redo(); // redo + void setDocPassage(DocPassage* passage); // 设置passage void setDefaultLayer(DocPage::Layer layer){this->defaultLayer = layer;} diff --git a/ofdEditor/start/app/APPInfo.cpp b/ofdEditor/start/app/APPInfo.cpp new file mode 100644 index 0000000..f0d377a --- /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 0000000..5fe1839 --- /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 0000000..e6b0c6e --- /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 0000000..96f1088 --- /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 d56a76b..153a8dc 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 4fe5af5..76f366d 100644 --- a/ofdEditor/start/ui/PassageMainWindow.cpp +++ b/ofdEditor/start/ui/PassageMainWindow.cpp @@ -53,9 +53,6 @@ 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; @@ -446,7 +443,9 @@ DocPassage *PassageMainWindow::addDocPassage(DocPassage *passage) return NULL; } - this->area->addSubWindow(passage); + this->area->addSubWindow(passage); // 插入子窗口 + this->connector->setDocPassage(passage); // 设置引用 + passage->setVisible(true); // 设置可见 passage->showMaximized(); -- Gitee