KOffice Alpha 8

Thomas Zander pointed out to me sometime back that my name got mentioned in the link on Slashdot. I thought “Wow, that’s so cool. My first time on the dot. I mean now that I am famous and all, I can sell signed merchandise at akademy :-) ”.

I read the techworld article and it said “Among the technology developments are improvements to the OpenDocument format, particularly the text shape that is the base of KWord thanks to the full-time work of the NLNet-sponsored Girish Ramakrishnan“.

It’s easy to misread that. I am sure glad that my contributions have been noticed but I wanted to put in a word for the others. It is indeed true that I made improvements but I have to point out that they are minor compared to huge (read: massive) chunk of code that was already there. I mean, hey, I just started 2 months ago and people have been working on this for years :-) .

So, thanks and congrats to the entire team for KOffice Alpha 8!

twitter

Getting started with KWord Development

About 2 months ago, I started working on KWord ODF support. Getting productive working on KWord is no mean task – apart from the mandatory C++/Qt knowledge, one need to know Scribe, KDE, KOffice libs and KWord. I knew only C++/Qt and basic Scribe.

Thankfully, to add small ODF features to KWord, one can conveniently ignore most of the code base and concentrate on 4-5 files. Which is what I have been doing – committing like crazy to 4-5 files :-) Of course, I have never been at ease with this, I usually don’t develop this way but I wanted to have something up and running asap. Now that we (Roop and I) have most of the (supported) ODF test automated (63 in all), I took a 1 week break to read and understand the KWord/KOffice code.

If writing a word processor is not complex enough, KOffice/KWord code is extremely complex thanks to all the code sharing between the koffice applications, libraries, plugins/flake, kparts. So, I thought I should do something on my part to make KWord more approachable to a newbie. The result is:

http://wiki.koffice.org/index.php?title=KWord/Tutorials/LoadingOdf

It’s a code walk through/very detailed introduction to how loading of ODF works in KWord. I have deliberately opted for simplicity over correctness in many places. Some information there might be outright wrong, in which case, please edit the document and fix it (hey, I am new to this stuff too). Also, this probably belongs in techbase.

Writing this document has made me realize that writing code is so much simpler than understanding existing code :-)

Anyhoo, Comments/Suggestions?

P.S: I am in the process of writing the SavingOdf document.

twitter

Accessing QtScript arrays from C++

Roop was wondering how to access an (QScript) array from C++. I spent sometime trying to figure how to do that, so I thought I will let the world know.

A search on the QScriptValue documentation page yields QScriptValue::isArray(). We can use that to determine if the value is an array or not. Unfortunately, it doesn’t really state there how to access contents of the array. My initial reaction was to just convert the value to a QVariant (using toVariant()) and then convert the variant to a QVariantList (toList()). That didn’t quite work.

The answer lies in understanding arrays and objects in EcmaScript – Everything is an object. Every object is really a map from properties to values. What that means is that an EcmaScript array is just an object. And the values you put into it are just properties of the array. The [] syntax is EcmaScript is just to make us feel at home and make us believe you are working with arrays and not some fancy objects. So,

array[1] = “foo”; // creates property named “1″ with value “foo”

With that revelation, you should be able to find QScriptValue::property(). Just pass the values 0, 1, 2 and so on as arrayIndex and you should receive the values. But, what about the length of the array? Remember, everything is a property in an object. The length is stored in the length property of the array which you can query using the other QScriptValue::property() overload.

P.S 1:
Note that, array indices are not limited to integers (it is a map). So, the below is perfectly fine.

array[“one”] = “foo;

I can imagine it to be common to inspect all the properties of an object. You can use QScriptValueIterator for that.


P.S 2:
array[1] is the same thing as array[“1”]. The keys in EcmaScript maps are strings.

Update
Roop found a much much easier way to process arrays: qScriptValueToSequence

twitter

38

So, we are at 38 testcases now. After the initial burst, progress has been slow. This was expected because most of the remaining testcases are yet to be implemented in KWord.

Among other news, I made an announcement on the koffice-devel list about the progress. Pinaraf and dipesh who are actively working on adding other ODF features to KWord, had some trouble getting the tests up and running. As a result, I added a README and STATUS file to ease things up. If you are working on anything related to ODF support, give the test suite a shot. It is invaluable when it comes to regression testing.

twitter

KWord ODF Support

It’s been over a month now since Roop and I started working on getting the ODF support in KWord upto shape (Our work is sponsored by the NLNet foundation). To give us direction in pursuit of that holy grail, we started out automating the test suite at OpenDocument Fellowship.

We decided that we would take the tests one by one, make them work in KWord and then commit the test to the KWord repository.

Writing each test is quite a tedious task:

  • Read the specification for the feature. As all specs go, it leaves some details to the imagination of the reader.
  • The test case itself is then analyzed for correctness.
  • We then run the test in KWord and check if it works as expected.
  • If it does not work as expected, we fix KWord. This is the fun part :-)
  • Once the functionality is added/fixed in KWord, we finally get around to automating the testcase. We have a framework that compares the document (QTextDocument) created by a script (QtScript) and the document created by KWord. So, all we have to do to automate the test case is to write a QtScript that generates the expected document.

As it stands, out of a total of 160 test cases, 33 have been automated. So, thats 33 completely working ODF text features in KWord! Not bad for a month, eh? We have been a bit low this month though thanks to my super flaky internet connection (Tata Wimax, a big rant on this later) and Roop being occupied with getting the website up and running.

You can browse the test suite online here: http://websvn.kde.org/trunk/koffice/libs/kotext/opendocument/tests/

twitter

Theming Qt for fun and profit

This feels great. This post is an eight year old dream come true – I have always wanted to write an article titled “… for fun and profit” ever since I read the amazing phrack article :) .

Qt Style Sheets makes it possible to style Qt widgets, we all know that. But, what if some user loved this Qt application and would love it even more, if only it had red push buttons (some users have strange fetishes)?

Qt 4.3′s well kept secret
In Qt 4.3, users can customize the style of any application without touching or recompiling the code. All Qt applications can take an external stylesheet using the -stylesheet command line switch. So, create a file called mystyle.qss containing “QPushButton { background: red; }”. Now start, any Qt applications as “qtapp -stylesheet mystyle.qss”. Sweeeet.

Theming Qt
So one can style widgets, but what if one wants to move things around. What if one wants the application to have a completely different layout. We have received many requests for supporting layouting in Qt Style Sheets, but did you know theming Qt applications is already possible?

So let’s see – we need a mechanism for the user to specify the layout. We can probably define our own XML format but it turns out Qt already has one and you use it all the time – .ui files. .ui file is nothing but the user interface described in XML. All we need is a mechanism to load these ui files on the fly.

Enter our hero QUiLoader. QUiLoader reads a ui file and gives you back a QWidget pointer. Ui files can be edited using Qt Designer, so you don’t need to create your own layout tool. In addition, QUiLoader::setWorkingDirectory allows creating ui files with external resources. That said, the main disadvantage is that theming this way requires you to modify your application.

I cooked up a media player that implements the above idea. You can add new themes in the themes/ folder. In addition to a layout(ui) file, the theme can also specify a style sheet. MediaPlayer can load these new themes with no recompilation.

Here’s the Classic theme that has the media controls on the bottom.
Classic Media Player

Here’s the Modern theme that has the media controls on the side.
Modern Media Player

To create a new theme,
* Unpack the source (with git history)
* qmake && make
* cp -R themes/classic themes/mytheme. At this point, mytheme and classic are identical.
* Edit file in mytheme/mediaplayer.ui using Designer
* Edit style sheet in mytheme/mediaplayer.qss using text editor
* Edit icons (play/stop/pause) under mytheme/.
* Notice how media player can support new layouts and styles with no recompilation at all.

Enjoy!

P.S: This is really a guest blog since I don’t work for Trolltech anymore :-) Please contact me at ramakrishnan dot girish at gmail, if you have any questions.

twitter

QStyledItemDelegate – Styling Item views

It all started as a small feature request – Adding style sheet support for Item views. I quickly found out that our default delegate, QItemDelegate, doesn’t use QStyle the way it is supposed to. Jens had faced the same problem when trying to provide native look and feel for Vista and ended up writing his own delegate. This is quite a limitation because currently authors of custom QStyles can customize the look of everything in Qt except item views.

So was born QStyledItemDelegate – The default delegate for Item views starting 4.4. To let that sink in – all our views now delegate painting to QStyledItemDelegate instead of QItemDelegate. QStyledItemDelegate prompty plays its part by delegating everything to QStyle :-) The cool thing is that this delegate uses the QStyle to determine the sizeHint, the layout of the text, indicators and icon. And of course, it paints everything through QStyle. Complete control to QStyle.

Jens has already incorporated this new feature into QWindowsVistaStyle. So, by default, your views will look all fancy in 4.4 like below:

vistatree2.png

We are unsure about how selection in table view must be handled. We are open to suggestions:

Chart example in vista style

On other platforms, they should exactly like before. If you had written your own delegate using QItemDelegate, it is completely unaffected by this change. If having to write a custom QStyle or a custom delegate sounds daunting, just use style sheets. Try something like this,

QTreeView::item {
    border: 1px solid #d9d9d9;
    border-top-color: transparent;
    border-bottom-color: transparent;
}

QTreeView::item:hover {
    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1);
    border: 1px solid #bfcde4;
}

QTreeView::item:selected {
    border: 1px solid #567dbc;
}

QTreeView::item:selected:active{
    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6ea1f1, stop: 1 #567dbc);
}

QTreeView::item:selected:!active {
    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6b9be8, stop: 1 #577fbf);
}

Here’s how it looks:

stylesheet-treeview.png

See Customizing QTreeView, Customizing QListView for more information.

We merged the new delegate into our main branch last week, so if use the latest snapshots, you already have it. If you have any specific requirements to styling of tree widgets, list views and tables in mind and are wondering if it is possible now using the new delegate, please leave behind a note!

twitter

Qt/Windows Open Source Edition to support VS Express

So here is more dramatic news following the Qtopia Phone is completely GPL announcement.

A couple of years back, we made a big move by Open Sourcing Qt for Windows. The Open Source edition of Qt/Windows supported only MinGW (and MinGW/MSYS starting Qt 4.3). The MSVC Makefile, project generator and the Integration was available only to commercial customers.

Today (a week back actually), we made another big move. We have decided to support Visual Studio Express with Qt/Windows Open Source – we are dual licensing the MSVC Makefile and project generator (Sorry, no VS Integration for Open Source users). Many thanks to our PM Eivind Thronsen for making this happen. So when will you get this? Well, if you had checked out the 4.3 snapshots, the generators have been available for about a week now. The mkspecs are on their way. We did schedule it for Qt 4.4 but some quick work by Marius and André will see this feature in Qt 4.3.2. Why make you wait for 5 more months to get hold of such goodness ;-) ?

The Visual Studio Express environment is just so much superior and easier to use for existing Windows developers compared to what MinGW provides. We foresee many of the Open Source projects switching to VS EE for development after this change. Video killed the radio star?

twitter

Qt 4.3.1 Style Sheet documentation

After the mega feature enhancements that we added to Style Sheet in 4.3, we have been getting an awful lot of support requests and mails asking for examples to do all sorts of stuff. As a direct consequence, I have added tons of new documentation. What’s cool is that there is a separate example for styling each and every widget in the Customizing Specific Widgets section. Previously, the documentation was one flat html file. But it grew so big that our doc team has now split it up into separate pages. Trivia question: Which is the biggest documentation manual in Qt ? :) .

My favorite bit is the Customizing TreeView example. One can style the tree view branches with 5 images. If you don’t like the tree view lines, you need only two. Here’s how it looks:
Tree View Branches

Comments/Suggestions? Leave a note behind.

twitter

Qt 4.3.1 released

We just released 4.3.1, get it here.

We try to do a patch release every 1.5 months or so. This time around, given that most developers disappeared for summer vacation, getting 4.3.1 out was quite a challenge. But there, we/2 did it :-) But really, this post is just an excuse to show the picture of our brave support engineers (customers can get pretty aggressive at times). We have four support offices (click on the images and hover over the face to see their names):

The Beijing office support team
Beijing support team

The San Jose office support team
SJ Support team

The Oslo office support team
Oslo support team

The Brisbane office support team
—- watch out this space for Brisbane team picture —-

P.S. Yes, yes, we know about the difference in sex ratio between Oslo development team and Oslo support team. We (devs) are working on it – by joining support, of course ;-)

twitter