Paragraph style based rich text edit with qt
French Paragon last edited by
Hello, I'm working on an application for comic, fiction book and pen&paper rpg universe development, inspired by the old desktop version of celtx. I'd like to be able to attach simple rich text to a hierarchy of items like characters, places, ... and then refer to them in some other texts.
My requirements are:
- all the styles are given by paragraph metadata, and only by the paragraph metadata.
- some kind of hierarchy has to be maintained between the paragraph, ideally the documents chapters and sub-chapters can be explored via a QTreeView.
- paragraph styles and their hierarchy is enforced by the type of text edited, none can be defined by the user.
- The text styles can contain some prefix and/or suffix like chapter numbering.
- Editor must be responsive to it parent width and idealy show all the text.
- small errors in margin and inter-paragraph linebreak are not a problem.
- Links to other items in the project can be added in the text and some ref-counting mechanism can be synchronized with those links.
I looked for documentation and examples all over the internet and found nothing very clear, but I have two ideas:
First, subclass QTextEdit to capture a few events, especially to capture line breaks. Then use a nested series of QTextFrames to store the paragraphs with the associated styles. It has the advantages to be simple (most of rich text edit functions are already implemented in Qt) but lacks some flexibility (for examples to manage chapter numbers, or references, which as almost to be done "by hand").
Or, create something based on the model/view framework, which has the advantages to have a very clear way of storing data and document structure, but lack some simplicity, as QTreeView has to be adapted as a rich text editor using a mix of appropriate item delegates and event handling.
What do think ? Do you see any critical problem with those approaches ? Do you see another, better approach ? Do you have any examples of applications which did something similar ?