cat /dev/maxilys

A glance in the mind of a KDE/Linux developer to see how ideas turn into code.

2007-03-01

KDE: Everything and more...

Kassie is reaching its version 0.1.99 i.e. it's that close from release. I made a significant improvement in the auto-reverse menu routine. In fact, it's so easy to do that I wonder how I couldn't "see" it earlier. But what should interest you more is what you can see.

Last time when I did my snapshots, I didn't realize that I forgot just one little thing. I shortened the entries in the popup menu for the drop destination but they then had a puzzling meaning without the popup title that forgot to add. That's one thing. The second thing will be the first one you'll see when you'll install Kassie: No ugly toolbutton any more. Well, it wasn't really ugly but strange. Kicker "prefers" simple icons. And I didn't loose any feature in the process. In particular, not the auto-close feature.


[Image][Image]

On the left, the popup menu to open a new session in selecting its name (as saved on disc by Kate). It pops up when you click on the nice icon with the arrow as popup indicator. What you can't see is that the icon glows like all icons on a Kicker's panel.

On the right (above and below), the popup "dialog" that appears when you drop files on Kassie's icon and when one or several instances of Kate are already running. Notice the popup title that I forgot last time. Note also that it isn't disabled because I patched my Kicker so that it uses standard KPopupTitle's and my KDE is patched too in order that it doesn't disable them unnecessarily. (In other words, it won't be so nice on your screen... Especially if you don't use Serenity style.) ;-)

[Image]
[Image]


I also added one of these automatic "About" dialogs KDE provides... but who cares? I did it because I could and despite the fact that I think it's too much for an applet.

Now, for those interested in coding auto-reverse popup menus, here's the trick:

int index = (position == bottom) ? 0 : -1;


Of course, you must change position and bottom into something applying to the situation. For example, for a kicker's applet, it will be:

int index = (position() == pBottom) ? 0 : -1;


Then you always give the index when you use KPopupMenu::insertTitle(), KPopupMenu::insertItem() or KPopupMenu::insertSeparator(). For example:

theMenu->insertItem(SmallIconSet("icon"), i18n("Entry label"),
this, SLOT(someSlot()), 0, -1, index);


And you build your menu from top to bottom without worrying about the direction.

That's all. No conditional code, no complex calculation, no calculation at all. No nothing. (Here, the 0 means "no accelerator key" and the -1 asks Qt to generate by itself a unique id for this item.)

The magic happens because you always insert an item at the given index. If the index is -1, Qt interprets is as "add to the end" so the menu builds itself from top to bottom. Perfectly normal. With an index of zero, each item is inserted at the topmost position and pushes the content toward the bottom. Thus the menu builds itself from bottom to top. Auto-reverse activated! That can't be any easier.

That will be all for today. Implementing the nice looking button was rather complex. Having to import files from Kicker's build tree into your own isn't what I would call easy. I left me no time to tame the virtual desktops as I wanted. I'm just back where I was yesterday... but a little differently.

Labels: , ,

0 Comments:

Post a Comment

<< Home