Tabs goodness in Qt

· by Thomas Zander · 2 min read · original post ↗

·

The Qt Scribe framework is a quite advanced typographical framework that even a typesetting capable app like KWord has chosen as its main text layout engine. As you may know, I have been replacing the KWord text engine with the Qt scribe one for the upcoming KOffice2 release. Even before I joined Trolltech, I have been pretty impressed with all the features that ‘just work’ in Qt scribe. In KWord I extended the scribe framework to all all the features that are required for good OpenDocument format layouting. One of these was tabs.

In any no-trivial text you will most probably find tabs, which are there to layout text to align and to structure. There are left tabs, right tabs, centered tabs and even tabs that allow you to line out text on a certain character (lining out on a decimal separator being the most used usecase).
As I wrote some months ago, I added that in KWord on top of QtScribe. But I was never satisfied with the solution. For one it was too slow because it required several re-layouts of the same text to get things right.

The technically correct solution was to extend the Qt scribe API and implement the set of missing features there. And thats exactly what I did. I calculate the required length of the tab based on things like if its a right-tab or a left-tab. And store that length in the text engine. This means that we now also correctly support tabs in paragraphs that are non-left-aligned with the same infrastructure. Some people will likely now be jumping up and down with excitement when reading this because upto Qt4.3 tabs in text were not used in paragraphs that are not left-aligned. You can check out the Qt4.4 snapshots to see this work just perfectly.

I still need to remove a bunch of code from the KOffice text flake, but removing obsolete code is always easier then writing code, isn’t it? :)

For those that are curious; here is a small example of the new API;


    QList tabs;  

    QTextOption::Tab tab;  

    tab.position = 100.0;  

    tab.type = QTextOption::CenterTab;  

    tabs.append(tab);

QTextOption option = block.layout()->textOption();  

    option.setTabs(tabs);  

    block.layout()->setTextOption(option);

QtKDE

More on KDE

More from Thomas Zander