I would like to build a custom TextArea (or a Text objects...).
Here are the limitations I found in the currently available nodes:
TextArea: provide functionality to apply font styles, select, and "getSelected" text. but it does not allow for applying different style to sub-Strings. A style is applied to the whole TextArea.
HTMLEditor: provides means to apply different styles, but not ways to get what string the user selected.
TextFlow: Allows to program different styles to strings. But it is like a label. Not interactive.
I need something a Text Area where users can type, selected, and my code would know what they selected to give them option to apply font styles to the selected string. So I guess what I need a custom object.
Do you agree? How do I go about that?
It seems like you are waiting, like many of us, a kind of JEditorPane (or StyledText, for those who uses SWT) in Java FX.
For now, there is no component of this kind in Java FX.You can use CodeAreaFX, but the performances are not at the best.
If you ant to use WebView as a text editor, you can get selected text by using javascript.
Related
I am in the brainstorming phase of a website and trying to select how to write my CSS. The website will support two languages. One language is latin based, think French, and the other is not, think Arabic. Arabic is rtl language. Also, that means menus text are going to change along with other elements. For example if I have a menu button with "Who are we", it must be translated to the other language.
Do I need to define two separate CSS files and pick one based on region/or user selection? Or is there a better way to approach this?
Also, when it comes to changing menu text, do I change only these fields or the entire HTML? Or it depends on the amount of text needs to be changed per HTML page?
The way I do it, in vanilla JS, is I make a copy of each text element for each language and add language class to it(so I can query select it later). Make a html selector for languages. From JS I add class "hide" to all elements belonging to unselected languages. All CSS that class hide contains is display:none. Frameworks, like Angular, contain more elaborate solutions, but for JS this one makes due.
For react you can use npm install i18next react-i18next --save. This solution will leave you with much cleaner view template since there you are just going to name every text field and then in code add to each field its possible translations. As margins, alignments and rest of css goes, usually you donĀ“t even have to touch it, translated text is usually quite similar so if there are breaking differences go with individual solutions. For example, since Arabic is written from right to left, add class with text-align: right; when detecting Arabic.
Is it possible to apply automatic HTML formatting to text as it's typed into a JavaFX HTMLEditor?
Previously I achieved what I wanted via the RichTextFx class, but I wanted to see if it's possible via HTMLEditor as this is now standard to JavaFX.
The only way I can see so far is to get the HTML text, strip it of its tags, then apply my own tag formatting, then set the HTML text contents again. Although inefficient this would probably work for what I want, but having tried it the editor loses focus and requestFocus() doesn't focus, and even if it did I think I'd have to set the cursor position.
I suspect it is possible to do it as you describe, though it will be inefficient in the ways you have already identified.
Perhaps a better solution, assuming RichTextFX isn't an option, would be to roll your own solution using TextFlow and multiple Text nodes.
https://openjfx.io/javadoc/11/javafx.graphics/javafx/scene/text/TextFlow.html
That is essentially what RichTextFX is doing.
I am new to Umbraco, and just discovered that the Image editor (the one that is included in selectable editors for content rows) does not provide a way to enter a CSS class. This is surprising, considering that it is pretty standard these days to use Bootstrap classes to style images (img-responsive, for example). NOTE: I had planned to add screen shots of this; however, I've been given a message that I cannot do this until I earn 10 something-or-other-points. THIS NOT HELPFUL TO NEW MEMBERS!
While I understand that I can set a class within the Umbraco UI on the containing column div, this is not ideal. I also understand that I could use the Rich Text Editor, but this seems to be overkill for a column that is intended to contain images only.
What I would like to do is modify the existing editor to allow users to enter CSS classes, but I cannot find it.
Has anyone made this modification to your own implementation of Umbraco, and if so, could you guide me to how I could do this?
The image picker just stores the id of the image, it's up to you how you render it, if the classes are the same for all of the images in the column, you can just assign the class in the view/partial that renders the images.
If you want to have different classes for each image, rather than modifying the built in image picker, best practice is to create a new property editor. There is a tutorial on this here: https://our.umbraco.org/documentation/tutorials/Creating-a-Property-Editor/. Modifying the built in one will cause you problems if you ever upgrade Umbraco (your changes will be overwritten). But a custom property editor will be unaffected, and you can also use it on other Umbraco sites that you build!
Is there any specific reason not to use QAbstractItemView::setIndexWidget for an editor in a QTreeView?
I am having a hell of a time using QStyledItemDelegate's and setItemDelegateForColumn, with data not showing up in editors, checkboxes not replacing the checkbox from QAbstractItemModel.data(index, role).
The docs say not to use it but not why.
Actually docs do not tell to avoid using it at all, but make decision, based on your application behavior. Here is the quote:
This function should only be used to display static content within the
visible area corresponding to an item of data. If you want to display
custom dynamic content or implement a custom editor widget, subclass
QItemDelegate instead.
I've highlighted the key words that define in which cases you have to use which approach.
I'm new to QT, and am trying to figure out the best means of creating a WYSIWYG editor widget for a custom markup language that displays simple text, images, and links. I need to be able to propagate changes from the WYSIWYG editor to the custom markup representation.
As a concrete example of the problem domain, imagine that the custom markup might have a "player" tag which contains a player name and a team name. The markup could look like this:
Last week, <player id="1234"><name>Aaron Rodgers</name><team>Packers</team></player> threw a pass.
This text would display in the editor as:
Last week, Aaron Rodgers of the Packers threw a pass.
The player name and the team name would be editable directly within the editor in standard WYSIWYG fashion, so that my users do not have to learn any markup. Also, when the player name is moused-over, a details pop-up will appear about that player, and similarly for the team.
With that long introduction, I'm trying to figure out where to start with QT. It seems that the most logical option would be the Rich Text API using a QTextDocument. This approach seems less than ideal given the limitations of a QTextDocument:
I can't figure out how to capture navigation events from clicking on links.
Following links on click seems to only be enabled when the QTextEdit is readonly.
Custom objects that implement QTextObjectInterface are ignored in copy-and-paste operations
Any HTML-based markup that is passed to it as Rich Text is retranslated into a series of span tags and lots of other junk, making it extremely difficult to propagate changes from the editor back to the original custom markup.
A second option appears to be QWebKit, which allows for live editing of HTML5 markup, so I could specify a two-way translation between the custom markup and HTML5. I'm not clear on how one would propagate changes from the editor back to the original markup in real-time without re-translating the entire document on every text change. The QWebKit solutions looks like awfully bulky to me (Learning WebKit along with QT) to what should be a relatively simple problem.
I have also considered implementing the WYSIWYG with a custom class using native QT containers, labels, images, and other widgets manually. This seems like the most flexible approach, and the one most likely not to run into unresolvable problems. However, I'm pretty sure that implementing all the details of a normal text editor (selecting text, font changes, cut-and-paste support, undo/redo, dragging of objects, cursor placement, etc.) will be incredibly time consuming.
So, finally, my question: are there any QT gurus out there with some advice on where to start with this sort of project?
BTW, I am using QT because the application is a desktop application that needs platform independence.
Given that I got no advice here, I decided to go with the QTextEdit approach, although I'm actually using a QTextBrowser that is set to be editable so that I can capture link navigation events. I will be using QTextCharFormat's with the link names set to unique identifiers in order to convert from the QTextEdit back to the custom markup. The QTextEdit supports images already, so I won't have to deal with those.
I think I will hit the biggest roadblocks with the fact that I need to be able to insert/grow/shrink tables whose cells can have Excel-style functionality. I have not yet figured that whole process out.