Page 1 of 3 123 LastLast
Results 1 to 20 of 48

Thread: a Text Editor with line numbers...

  1. #1
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default a Text Editor with line numbers...

    hi,
    I'm working on a C++ IDE with build-in support for Qt4.
    Basic GUI is working but QTextEdit does not match my requirements:
    I'm looking for an editor which would show lines number, allow search and replace and so on...
    QScintilla may have be fine but it hasn't been ported to Qt4 yet.
    QSA implements a similar text editor but I have troubles customizing it!!!
    Any ideas???
    Current Qt projects : QCodeEdit, RotiDeCode

  2. #2
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a Text Editor with line numbers...

    can you post any code..?

    I am loking for such beast myself

  3. #3
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a Text Editor with line numbers...

    still working on it when I've got time and nothing to post.

    about IDE also:
    how to customize a QTreeWidget (or QTreeView as well) so as to allow each item to have a working context menu???
    Current Qt projects : QCodeEdit, RotiDeCode

  4. #4
    Join Date
    Jan 2006
    Location
    England
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a Text Editor with line numbers...

    Connect the customContextMenuRequested signal to a slot where you look at the x,y co-ordinates to find out which cell the menu was requested from using QTableWidget::itemAt(QPoint).
    Last edited by Corran; 13th January 2006 at 17:58.

  5. #5
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a Text Editor with line numbers...

    If you cannot release code, then some questions instead:

    How are you handeling the tabs->convertion (show tabs as 8 spaces, etc)
    Are displaying the current line in another color?

    What other goodies do you have implemented?

  6. #6
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a Text Editor with line numbers...

    Quote Originally Posted by Corran
    Connect the customContextMenuRequested signal to a slot where you look at the x,y co-ordinates to find out which cell the menu was requested from using QTableWidget::itemAt(QPoint).
    Thanks but I have already done it by myself. I asked the question before thinking about the answer!!!

    Dear elcuco, your beast appeared to me!!!
    Looks nice but still needs a little work.
    Quote Originally Posted by elcuco
    If you cannot release code, then some questions instead:

    How are you handeling the tabs->convertion (show tabs as 8 spaces, etc)
    Are displaying the current line in another color?

    What other goodies do you have implemented?
    Let's describe the "Graal" I made starting from QSA's editor

    DevEdit : inherits QTextEdit
    - custom contextMenu
    - some additional signals and slots for convinience

    DevStatus : inherits QStatusBar
    - additional slot to write right aligned message (in my case its colum and row)

    DevLineNumber : inherits QWidget
    - draws line number (note : taken verbatim from QSA)
    - additional signals and slots are planned for integrated debugging purpose

    DevEditor : inherits QWidget
    - All the widgets described above are put into a QGridLayout and signals are properly connected to have those widgets working together
    following signals are wrapped for convinience:
    - QTextEdit's signals
    - QStatusBar signal
    - QTextEdit's scrollbar's signals

    The description I give may not be very clear but you'll understand with the code.
    I'm gonna post it during the week. Wait...

    edit :
    posted a screenshot.

    After thinking a bit I decided to reimplement my DevEdit as clone of QTextEdit but without any HTML stuff making it slow and with a custom highlighting mechanism.

    You'll have to wait more before the final version but if anyone is interested in the current one he can e-mail me to get it.

    edit 2:
    WTF !!! I looked into Qt's source and QTextedit would be quite hard to reimplement using inheritance... I'll try to craft a widget with a QAbstractScrollArea inside and custom paint, keypress, context menu (...)events.
    I do not like the idea of starting from scratch but...
    Last edited by fullmetalcoder; 10th February 2006 at 15:41.
    Current Qt projects : QCodeEdit, RotiDeCode

  7. #7
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a Text Editor with line numbers...

    Ok, nice. So it can be done...

    I see you have exactly the same problem I have.
    I am using a QTabWidget, I seem to have an orrible space on the right side, which means the right scrollbar is not on the "infinite-right". I have looked into Qt-Assistant code for some ideas about how they did it, and I "borrowed" that code, but still the internal editor is way from from the sides of the window.

    Again, a few questions if you do not mind:
    1) "display tab as X spaces", did you implement it? If so how? if not, how are you planning?
    2) The syntax highlighter. It's based on the examples from the trolls? See notes bellow.
    3) Current line and match brackets. Planned...? Implemented...?

    I am toying with this issue myself, and I already implemented a hack of a system for displaying and loading SL. I am currently loading parts of GtkSourceView SH definitions, and I can display in a rather good quality C/C++/C# syntaxes. I will fix the implementation I have to display DIFF and other goodies (I am still messing the implementation...). I used as a base the SH example supplied by the trolls with some spin ups.

    If found that using RegEx for for the painting is extreamly painfull, as in big files (~1000 lines) text will take about 5 seconds to load. I will try to see if the code for settign the QSyntaxHighliter can be put in a QTimer::singleShot() to make this call asynchroneous and improove usability, as hack for a good SH system.

    Did you write the SH yourself (as the example on Qt4.0 showed), or are you deriving QSyntaxHihlighter. In any case, how is the drawing made? (hard coded contexts or something like Kate?)

  8. #8
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: a Text Editor with line numbers...

    Quote Originally Posted by fullmetalcoder
    hi,
    I'm working on a C++ IDE with build-in support for Qt4.
    Basic GUI is working but QTextEdit does not match my requirements:
    I'm looking for an editor which would show lines number, allow search and replace and so on...
    QScintilla may have be fine but it hasn't been ported to Qt4 yet.
    QSA implements a similar text editor but I have troubles customizing it!!!
    Any ideas???
    I use "kwrite" or "kate"

  9. #9
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a Text Editor with line numbers...

    Quote Originally Posted by impeteperry
    I use "kwrite" or "kate"
    lol
    You don't seem to pay attention to profile on the right of each post! I'm a Windows user, even if I would like to change there's no way, other users would'nt agree!

    Quote Originally Posted by elcuco
    Again, a few questions if you do not mind:
    1) "display tab as X spaces", did you implement it? If so how? if not, how are you planning?
    2) The syntax highlighter. It's based on the examples from the trolls? See notes bellow.
    3) Current line and match brackets. Planned...? Implemented...?

    [...]

    If found that using RegEx for for the painting is extreamly painfull, as in big files (~1000 lines) text will take about 5 seconds to load. I will try to see if the code for settign the QSyntaxHighliter can be put in a QTimer::singleShot() to make this call asynchroneous and improove usability, as hack for a good SH system.

    Did you write the SH yourself (as the example on Qt4.0 showed), or are you deriving QSyntaxHihlighter. In any case, how is the drawing made? (hard coded contexts or something like Kate?)
    I don' mind!

    1) three ways:
    - either reimplementing the whole paint event which may be very hard.
    - either using each time font gets modified :
    Qt Code:
    1. setTabStopWidth( x * QFontMetrics( font() ).width(' ') );
    To copy to clipboard, switch view to plain text mode 
    - either hacking the keypress event so that any tab char is translated as x spaces [pretty uggly and stupid]

    2)Sure it is! Actually I took the reimplementation from QSA and subclassed it as C++ syntax highlighter. Yes it's based on QRegExp which is an inherently slow method with large files but, well...

    3)What do you call current line? Isn't that implemented in two ways?
    What do you call match bracket? Indentation? Indentation is planned but not that easy!
    There was a "parenthesis matcher" in QSA code but I didn't understand it's goal so I removed it!
    Current Qt projects : QCodeEdit, RotiDeCode

  10. #10
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a Text Editor with line numbers...

    1) Please, don't reimplement the drawing engine. I am not a native english speaker. My native language is Spanish, but since I live in Israel, my real language is Hebrew - which as you may know already it's a complex script (google for RTL or BIDI).

    If you reimplement the drawing code of the QTextEdit, you will loose any BiDI support in that widget. You will probably mess up Chinese, Hindic, and some other languages which Lars has worked so hard to get in perfect shape.

    The setTabStopWidth() seems to beright way. As you will be able to convert the tab to "spaces" and back. This means you do not mess with the text the use loaded.

    2) Reguarding the SH, I will see if there is a way to set it in a callback or something, otherwise th UI gets frezzed for several seconds when the initial painting is done. I also found no eay to rehighlight the code (what if the user wants to use another highlight...?)

    3) current line = current pararaph in QTextDocument terminology. I want to draw the current line with a different background.

    When the cursor is on "}", that char should be drawed with another background color, and the same for the first "{".

    I assume you support only C/C++/H files right now...?

  11. #11
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a Text Editor with line numbers...

    Quote Originally Posted by elcuco
    3) current line = current pararaph in QTextDocument terminology. I want to draw the current line with a different background.
    It's planned but not working right now.

    Quote Originally Posted by elcuco
    When the cursor is on "}", that char should be drawed with another background color, and the same for the first "{".
    Would be quite hard!!!

    Quote Originally Posted by elcuco
    I assume you support only C/C++/H files right now...?
    Entierely true.

    Due to the limitations of my wrapper around QTextEdit I started porting QScintilla to Qt4.
    Pretty long and hard as I never learned Qt3!
    Current Qt projects : QCodeEdit, RotiDeCode

  12. #12
    Join Date
    Jan 2006
    Location
    Winnipeg, MB. Canada
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a Text Editor with line numbers...

    Quote Originally Posted by fullmetalcoder
    Due to the limitations of my wrapper around QTextEdit I started porting QScintilla to Qt4.
    Yea, i played with porting QScintilla to Qt4. Of course if qt3to4 did all the work, it would be too easy, but there is still tons of hand-massaging you have to do. Porting from scratch using Riverbank's code as a guideline might in the end be the best way to go.

  13. #13
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a Text Editor with line numbers...

    Quote Originally Posted by rh
    Yea, i played with porting QScintilla to Qt4. Of course if qt3to4 did all the work, it would be too easy, but there is still tons of hand-massaging you have to do. Porting from scratch using Riverbank's code as a guideline might in the end be the best way to go.
    Where to find Riverbak's code? Would be happy to find an easy way!!!
    Current Qt projects : QCodeEdit, RotiDeCode

  14. #14
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a Text Editor with line numbers...

    QScintilla does not support anything but Latin1 and thus it's unusable for me and many others.

  15. #15
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Angry Re: a Text Editor with line numbers...

    I ported QScintilla by hand from Qt3 to Qt4, it compiled without even one warning.
    I then tried to use it in a very simple program and it linked with no problem, the window appeared...
    but not the cursor
    then tryed to copy from another editor... NO WAY!!! but the context menu displayed...
    then tryed to typoe by hand a few words... NO WAY!!! What the fuck is that???
    I spent 4hours porting something that doesn't work!!!
    Current Qt projects : QCodeEdit, RotiDeCode

  16. #16
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a Text Editor with line numbers...

    Quote Originally Posted by fullmetalcoder
    I ported QScintilla by hand from Qt3 to Qt4, it compiled without even one warning.
    I then tried to use it in a very simple program and it linked with no problem, the window appeared...
    but not the cursor
    then tryed to copy from another editor... NO WAY!!! but the context menu displayed...
    then tryed to typoe by hand a few words... NO WAY!!! What the fuck is that???
    I spent 4hours porting something that doesn't work!!!
    release the code or shut up...

    at last for the first editor!

  17. #17
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a Text Editor with line numbers...

    which code??? buggy QScintilla or working QTextEdit???

    QTextEdit based now highlight current line in cyan but there's still a twist:
    no simple way to make it highlight the whole line, as in Dev-C++ for example.
    any ideas on how to do that?

    cheers
    Current Qt projects : QCodeEdit, RotiDeCode

  18. #18
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a Text Editor with line numbers...

    I would like to see a code based on QTextEdit, because of the reasons I explained before. But that's me

  19. #19
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a Text Editor with line numbers...

    I should be able to post it tomorrow.

    No solutions comes to me about current line colouring but I implemented the basis of a breakpoint management system.

    Seems to progress!!!
    Current Qt projects : QCodeEdit, RotiDeCode

  20. #20
    Join Date
    Jan 2006
    Location
    Winnipeg, MB. Canada
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a Text Editor with line numbers...

    If you want to see more information on scintilla implementations, you may want to check out:

    http://www.codeproject.com

    and search for "scintilla". Of course these will be implemented with MFC or in C#, but you might get some ideas.

    P.S. CodeProject's search isn't very good; you'll get more hits googling the CodeProject site.
    Plan? There ain't no plan!

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. QTcpSocket exception.
    By Fastman in forum Qt Programming
    Replies: 9
    Last Post: 29th January 2008, 13:51
  3. Qwizard crashed when created in a slot
    By joshlareau in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2008, 09:16
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.