diff --git a/ofdEditor/model/Convert/Objects/MinTextUnit.cpp b/ofdEditor/model/Convert/Objects/MinTextUnit.cpp deleted file mode 100644 index 6cd92672e95d7742dceee9cb086373e5ae16dae3..0000000000000000000000000000000000000000 --- a/ofdEditor/model/Convert/Objects/MinTextUnit.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#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 deleted file mode 100644 index b10c012bfe0fe073c54068c8a8692e529daf037f..0000000000000000000000000000000000000000 --- a/ofdEditor/model/Convert/Objects/MinTextUnit.h +++ /dev/null @@ -1,25 +0,0 @@ -#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/DocBlock.cpp b/ofdEditor/model/Doc/DocBlock.cpp index 14764ec5d039d0f9c5ad95113efe04bec7621ade..854af47798ed315ebbaf202e4e993397a0477c66 100644 --- a/ofdEditor/model/Doc/DocBlock.cpp +++ b/ofdEditor/model/Doc/DocBlock.cpp @@ -126,7 +126,6 @@ void DocBlock::resize(const QSizeF &size) */ void DocBlock::setZValue(qreal z) { -// qDebug()<<"setZValue:" << z; QGraphicsProxyWidget::setZValue(z); this->realZValue = z; // 设置本地记录 } @@ -352,13 +351,11 @@ 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 1895c41f8ffb1c5ee40778416acd9b81f984ca7f..26d61f0f0f058a1b14e78685c0bdaa82e85721e7 100644 --- a/ofdEditor/model/Doc/DocBlock.h +++ b/ofdEditor/model/Doc/DocBlock.h @@ -49,7 +49,6 @@ 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 07da6603ff9f92799dc1ae9d93e39363f66c608e..8ea48ac3a6f04e276205892012800baa074156cd 100644 --- a/ofdEditor/model/Doc/DocLayer.cpp +++ b/ofdEditor/model/Doc/DocLayer.cpp @@ -80,7 +80,6 @@ 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/DocLayer.h b/ofdEditor/model/Doc/DocLayer.h index d18bc3ed28848c8037368113aeea9e414259fb58..7fbb8c9e3271e327a53aba0e5f31474ee30799c3 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/DocPage.cpp b/ofdEditor/model/Doc/DocPage.cpp index 6b871ce30d6c45e55c9601100fbc4b3304e3eee7..d33dee2ce3b71a5992080add5b0ba622eb71dde8 100644 --- a/ofdEditor/model/Doc/DocPage.cpp +++ b/ofdEditor/model/Doc/DocPage.cpp @@ -404,15 +404,12 @@ 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 1edb50852ba639ac108ceec46d16bd0f938e0461..76db7acec419fab2b6829cd0b2d057daad2016c0 100644 --- a/ofdEditor/model/Doc/DocTextBlock.cpp +++ b/ofdEditor/model/Doc/DocTextBlock.cpp @@ -126,91 +126,41 @@ void DocTextBlock::mergeFormatOnWordOrSelection( /** * @Author Chaoqun - * @brief 合并指定光标下的char和文字格式 - * @param QTextCursor &cursor - * @param QTextCharFormat &format - * @return void - * @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 + * @brief 当前CharFormat样式发上改变的响应函数, + * 当增加了一个字体控制的widget时,可以使用 + * @param const QTextCharFormat &format * @return void - * @date 2017/06/22 + * @date 2017/05/21 */ -void DocTextBlock::mergeBlockFormatOnBlock( - QTextBlockFormat &blockFormat) +void DocTextBlock::currentCharFormatChangedEvent( + const QTextCharFormat &format) { - QTextCursor cursor = this->textCursor(); // 光标 - if(!cursor.hasSelection()) - { - cursor.select(QTextCursor::BlockUnderCursor); // 选择光标下的块 - } - cursor.mergeBlockFormat(blockFormat); } /** * @Author Chaoqun - * @brief 合并给定光标下的块格式 - * @param QTextCursor &cursor - * @param QTextBlockFormat &blockFormat + * @brief 光标位置发生改变时的响应函数 + * @param void * @return void - * @date 2017/06/22 + * @date 2017/05/21 */ -void DocTextBlock::mergeBlockFormatOnBlock( - QTextCursor cursor, QTextBlockFormat &blockFormat) +void DocTextBlock::cursorPositionChangedEvent() { - if(!cursor.hasSelection()) - { - cursor.select(QTextCursor::BlockUnderCursor); // 选择光标下的块 - } - - cursor.mergeBlockFormat(blockFormat); + // qDebug() << "Cursor Position Changed!"; } - void DocTextBlock::setFont(const QFont &font) { - +// QTextCharFormat currentFormat = +// this->currentCharFormat(); // 当前选择文字的样式 QTextCursor cursor = this->textCursor(); QTextCharFormat currentFormat = cursor.charFormat(); currentFormat.setFont(font); // 设置字体 - 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); // 合并给定光标下的字体样式 +// mergeCurrentCharFormat(currentFormat); + mergeFormatOnWordOrSelection(currentFormat); } /** @@ -237,25 +187,6 @@ 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); // 隐藏边框 - } -} - /** @@ -278,33 +209,14 @@ void DocTextBlock::textBold() /** * @Author Chaoqun - * @brief 使用QTextCursor作为参数,并且通过mode参数可以控制是否设置加粗, - * 方便Command操作进行使用 - * mode = -1 普通, - * mode = 0 一般模式同无参的这个函数 - * mode = 1 加粗 - * @param QTextCursor & - * @return void + * @brief QTextCursor & + * @param 参数 + * @return 返回值 * @date 2017/06/20 */ -void DocTextBlock::textBold(QTextCursor &cursor, int mode) +void DocTextBlock::textBold(QTextCursor &cursor) { - 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); // 合并给定光标下的字体 } /** @@ -325,38 +237,6 @@ 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 设置斜体 @@ -374,42 +254,6 @@ 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,设置好了后, @@ -451,21 +295,6 @@ 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 通过字体小窗口设置字体 @@ -524,34 +353,9 @@ 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); - } /** @@ -573,30 +377,6 @@ 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 } /** @@ -620,11 +400,7 @@ void DocTextBlock::contextMenuEvent(QContextMenuEvent *event) this->ContextMenu->addAction(this->actionFontSetTest); // 字体 this->ContextMenu->addAction(this->actionRemove); // 移除操作 - connect(this->ContextMenu, SIGNAL(aboutToHide()), - this,SLOT(contextMenuAboutToHideEvent())); // 测试 - - this->tempZValue = this->getBlock()->getZValue(); - emit this->signals_setZValue(2000); + emit this->signals_setZValue(2000); // 将位置提升至最高层 // 展示菜单 this->ContextMenu->exec(event->globalPos()); @@ -640,9 +416,7 @@ void DocTextBlock::contextMenuEvent(QContextMenuEvent *event) */ void DocTextBlock::focusInEvent(QFocusEvent *e) { - this->showBoundaryFrame(true); - emit this->signals_focusIn(); - + this->setFrameStyle(QFrame::Box); // 显示边框 QTextEdit::focusInEvent(e); } @@ -655,25 +429,10 @@ void DocTextBlock::focusInEvent(QFocusEvent *e) */ void DocTextBlock::focusOutEvent(QFocusEvent *e) { - this->showBoundaryFrame(false); - emit this->signals_focusOut(); - + this->setFrameStyle(QFrame::NoFrame); // 隐藏边框 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 a58afff409cd7b15d82eb3b4c3c11db02f873041..c599d84f1193af82881d93bebd1a45dd2d67ca6a 100644 --- a/ofdEditor/model/Doc/DocTextBlock.h +++ b/ofdEditor/model/Doc/DocTextBlock.h @@ -6,7 +6,6 @@ #include #include #include -#include //class DocParagraph; class QAction; @@ -37,53 +36,29 @@ public: public slots: + // 文档编辑部分 void textBold(); // 将光标选择的文字粗体 - void textBold(QTextCursor& cursor, int mode = 0); // 将给定光标选择的文字设置为粗体 + void textBold(QTextCursor& cursor); // 将给定光标选择的文字设置为粗体 void textUnderline(); // 下划线 - void textUnderline(QTextCursor& cursor, int mode = 0);// 设置下划线 void textItalic(); // 斜体 - void textItalic(QTextCursor& cursor, int mode = 0); // 设置斜体 - void setTextColor(); // 设置字体颜色 - void setTextColor(QTextCursor& cursor,QColor color); // 设置颜色 - void textParagraph(); // 设置段落 - + void setTextColor(); // 设置字体颜色 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 mergeFormatOnWordOrSelection( - QTextCursor& cursor, - QTextCharFormat &format); // 合并指定光标处的文字格式 - - void mergeBlockFormatOnBlock( - QTextBlockFormat& blockFormat); // 合并blockFormat格式 - void mergeBlockFormatOnBlock( - QTextCursor cursor, - QTextBlockFormat &blockFormat); // 合并给定光标下块的格式 - + void currentCharFormatChangedEvent( + const QTextCharFormat &format); // 选中的文字格式发生了变化 + void cursorPositionChangedEvent( ); // 光标位置发生改变 void setFont(const QFont &font); // 设置格式 - void setFont( - QTextCursor& cursor, - const QFont &font); // 设置给定光标下的字体格式 // 关于框的一些其他部分 void setBlock(DocBlock* block); // 设置Block void remove(); // 移除本文本框 - void showBoundaryFrame(bool show); // 是否显示边界 protected: @@ -91,8 +66,6 @@ protected: void focusInEvent(QFocusEvent *e); void focusOutEvent(QFocusEvent *e); -private slots: - void contextMenuAboutToHideEvent(); // 右键菜单隐藏绑定事件 private: QString content; // 文字内容 @@ -114,21 +87,10 @@ 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( - QTextBlockFormat& fmt); // 当前选择的block格式发生了变化、 - }; diff --git a/ofdEditor/model/model.pro b/ofdEditor/model/model.pro index e7b846ce55c8b87965aece27bd3927e059598ef8..5e5c657ae59b30bc1ec6cf486c5f6ffb0bda6199 100644 --- a/ofdEditor/model/model.pro +++ b/ofdEditor/model/model.pro @@ -49,8 +49,7 @@ SOURCES += model.cpp \ Widget/FontSettingDialog.cpp \ Convert/OFD_DocConvertor.cpp \ Convert/MergeCT_Texts.cpp \ - Convert/Doc_OFDConvertor.cpp \ - Convert/Objects/MinTextUnit.cpp + Convert/Doc_OFDConvertor.cpp HEADERS += model.h\ model_global.h \ @@ -79,8 +78,7 @@ HEADERS += model.h\ Widget/FontSettingDialog.h \ Convert/OFD_DocConvertor.h \ Convert/MergeCT_Texts.h \ - Convert/Doc_OFDConvertor.h \ - Convert/Objects/MinTextUnit.h + Convert/Doc_OFDConvertor.h DESTDIR = ../bin # 生成文件在这 MOC_DIR = ./moc # Q_OBJECT 类转换后的文件