Qt WYSIWYG 编辑器 - 不可编辑/生成的区域

发布于 2024-09-18 05:56:48 字数 699 浏览 9 评论 0原文

我正在开发一个所见即所得的文档编辑器。该编辑器是围绕 Qt 框架构建的,因为 Linux/KDE 是其运行的主要平台。

到目前为止,我一直在使用 QTextEdit 小部件,并且已经进行了基本的文本编辑和格式化。但是,我在如何实现以下要求方面陷入了停滞:

文档被分为多个级别的标题,并且必须有一个自动的标题。生成的目录位于顶部。

您应该能够为文本段落(标题 1、标题 2、...、段落)选择样式,如果选择标题样式,则该行会以节号为前缀。

例如,包含文本“设计规范”且样式为“标题 3”的段落可能会显示为:

3.4.2 设计规范

其中前缀部分编号“< em>3.4.2' 是自动生成的。当在其上方插入和删除标题时,节号应更新。用户不应自行修改或删除此前缀。如果他们确实删除了前缀,则该段落应恢复为“段落”样式,而不是保留标题。

当标题被插入/修改/删除时,目录应该自动更新。用户也不应该能够修改或删除目录。

我陷入了如何在编辑器中实现该功能的困境。我正在考虑存储一棵不可编辑范围的树(包括目录和每个前缀的范围),并且每次光标位置/当前选择更改时,如果选择重叠或将 QTextEdit 控件设置为只读光标位于范围内。但随之而来的问题是,每次修改某些内容时,都要使所有这些范围保持最新(重建树),这在所见即所得编辑器中很常见。

我不知道如何继续,我将不胜感激任何有关此事的建议。

I am developing a WYSIWYG document editor. The editor is build around the Qt framework because Linux/KDE is the main platform it will run on.

I have been using the QTextEdit widget so far and have gotten basic text editing and formatting in. However I've come to a standstill on how to implement the following requirement:

A document is split into multiple levels of headings and there must be a automatically generated table of contents at the top.

You should be able to select a style for a paragraph of text (heading 1, heading 2, ..., paragraph) and if you select a heading style then the line is prefixed with a section number.

For example, a paragraph containing the text "Design Specification" with the style 'heading 3' might be displayed as:

3.4.2 Design Specification

Where the prefixed section number '3.4.2' was automatically generated. The section number should update as headers are inserted and removed above it. The user should not be able to modify or remove this prefix themselves. If they do remove the prefix then the paragraph should revert back to the 'paragraph' style rather than remain a header.

As the headers are inserted/modified/removed the table of contents should automatically be updated. The user also should not be able to modify or delete the table of contents.

I am stuck at how to implement that functionality into my editor. I was thinking of perhaps of storing a tree of uneditable ranges (ranges that include the table of contents and each of the prefixes) and each time the cursor position/current selection changes I will set the QTextEdit control to readonly if it the selection overlaps or the cursor is inside of a range. But then there is the issue of keeping all of these ranges up to date (rebuilding the tree) every time something is modified, which would be quite often in a WYSIWYG editor.

I am stuck at how to proceed and I will appreciate any advice on this matter.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

喜爱纠缠 2024-09-25 05:56:48

IMO 您不需要使用编辑器添加这些数字:只需 使用CSS 并让 HTML 渲染器添加/显示它们。

IMO you shouldn't need to add those numbers with an editor: just declare them using CSS and let the HTML renderer add/display them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文