From kwrite-devel Fri Dec 11 21:26:40 2020 From: Dominik Haumann Date: Fri, 11 Dec 2020 21:26:40 +0000 To: kwrite-devel Subject: Re: using ktexteditor as a base for a disassembly viewer Message-Id: X-MARC-Message: https://marc.info/?l=kwrite-devel&m=160772202429070 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--00000000000057e31c05b636f3e6" --00000000000057e31c05b636f3e6 Content-Type: text/plain; charset="UTF-8" I also believe that using KSyntaxHighlighting directly is the best approach with custom delegate. This way you'll also get the Background colors you want etc. Best regards Dominik Christoph Cullmann schrieb am Fr., 11. Dez. 2020, 20:25: > On 2020-12-11 20:19, Milian Wolff wrote: > > On Freitag, 11. Dezember 2020 16:52:25 CET Sven Brauch wrote: > >> Hi, > >> > >> > PS: How would one even use KSyntaxHighlighting for rendering into a > >> > QAbstractItemView? That also sounds somewhat nasty hmmm > >> > >> That doesn't sound too complicated, or maybe I'm mistaken? For one of > >> my > >> applications, I needed HTML rendering once, which I implemented by > >> creating > >> a delegate holding a QTextDocument. The delegate just sets the text on > >> the > >> document and then draws its contents. The same should work when you > >> set a > >> highlighter. Like this (sorry, not the cleanest code, it's already a > >> few > >> years old): http://pastie.org/p/6yTw8HZl47KcgvrjSBaDG8 > > > > Yes, that's obviously an easy approach to take, and for the amount of > > data I'm > > expecting should probably work out fine. But note that this approach > > requires > > a re-layouting for every paint. A better approach would store the > > layout (i.e. > > the text document) per item somehow. Maybe I can just put that into the > > model > > itself, next to the highlighting... > > > > Anyhow, probably premature optimization, and a KISS approach should > > work out > > fine for now. > > > >> Otherwise, I'm not sure either. I personally think it will be easier > >> if you > >> just use a QTableView, unless you need column-wise text selection. I > >> think > >> you could hook everything you need into KTextEditor as well (by e.g. > >> setting custom context menus depending on the column that was clicked > >> etc) > >> but it will require more lines of hacks than you would otherwise need > >> to > >> re-create the needed functionality yourself ;) Some applications use > >> the > >> text editor for a lot of stuff, maybe that can serve you as > >> inspiration -- > >> e.g. sublime text comes to mind, which presents its search results > >> (and > >> probably other things) as an interactive text document. > > > > Right, that could work. But it would let the disassembly view stand out > > a lot > > from the other hotspot views. > > > > Thank you, unless someone else chimes in with an awesome idea, I really > > think > > that we'll have to try the KSyntaxHighlighter + custom delegate > > approach. > > I guess that is the most pragmatic way to go. > > Greetings > Christoph > > -- > Ignorance is bliss... > https://cullmann.io | https://kate-editor.org > --00000000000057e31c05b636f3e6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I also believe that using KSyntaxHighlighting direct= ly is the best approach with custom delegate. This way you'll also get = the Background colors you want etc.

Best regards
Dominik

Christo= ph Cullmann <christoph@cullmann= .io> schrieb am Fr., 11. Dez. 2020, 20:25:
On 2020-12-11 20:19, Milian Wolff wrote:
> On Freitag, 11. Dezember 2020 16:52:25 CET Sven Brauch wrote:
>> Hi,
>>
>> > PS: How would one even use KSyntaxHighlighting for rendering = into a
>> > QAbstractItemView? That also sounds somewhat nasty hmmm
>>
>> That doesn't sound too complicated, or maybe I'm mistaken?= For one of
>> my
>> applications, I needed HTML rendering once, which I implemented by=
>> creating
>> a delegate holding a QTextDocument. The delegate just sets the tex= t on
>> the
>> document and then draws its contents. The same should work when yo= u
>> set a
>> highlighter. Like this (sorry, not the cleanest code, it's alr= eady a
>> few
>> years old): http://pastie.org/p/6yTw8H= Zl47KcgvrjSBaDG8
>
> Yes, that's obviously an easy approach to take, and for the amount= of
> data I'm
> expecting should probably work out fine. But note that this approach <= br> > requires
> a re-layouting for every paint. A better approach would store the
> layout (i.e.
> the text document) per item somehow. Maybe I can just put that into th= e
> model
> itself, next to the highlighting...
>
> Anyhow, probably premature optimization, and a KISS approach should > work out
> fine for now.
>
>> Otherwise, I'm not sure either. I personally think it will be = easier
>> if you
>> just use a QTableView, unless you need column-wise text selection.= I
>> think
>> you could hook everything you need into KTextEditor as well (by e.= g.
>> setting custom context menus depending on the column that was clic= ked
>> etc)
>> but it will require more lines of hacks than you would otherwise n= eed
>> to
>> re-create the needed functionality yourself ;) Some applications u= se
>> the
>> text editor for a lot of stuff, maybe that can serve you as
>> inspiration --
>> e.g. sublime text comes to mind, which presents its search results=
>> (and
>> probably other things) as an interactive text document.
>
> Right, that could work. But it would let the disassembly view stand ou= t
> a lot
> from the other hotspot views.
>
> Thank you, unless someone else chimes in with an awesome idea, I reall= y
> think
> that we'll have to try the KSyntaxHighlighter + custom delegate > approach.

I guess that is the most pragmatic way to go.

Greetings
Christoph

--
Ignorance is bliss...
https://cullmann.io | https://kate-editor.org
--00000000000057e31c05b636f3e6--