cat /dev/maxilys

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

2006-05-27

KDE: Good old days

Good old days are back! I hated these days when I didn't succeed in doing what I wanted. I said I was frustrated. These days are back...

But I don't feel frustrated any more. Now, I can wander blindfolded across the sources of Serenity and I feel more stimulated than anything when I'm trying to do something not so easy. I won't say difficult because difficulty is only relative to what I was used to do.

Any way, here are the few things I worked on: First, the scrollbars. I always wanted to improve the mouseover effect so that you can see above which part you actually are instead of triggering the mouseover effect on the slider anywhere the mouse enters the scrollbar. That wasn't easy because I mismatched "slider" with "scrollbar". There was a time, during the golden age of the Atari computers when we were used to call a scrollbar a "slider" in French. I've worked long enough on my style to know what a slider is for Qt but it didn't prevent me from asking to my style to try to do with the sliders what I expected it to do with the scrollbars. It took me some time to realize my mistake but when I did and corrected everything, it worked immediately after! Call me stupid if you want, I already did it. :-D

The result was as expected. The scrollbars within Serenity are flat except the slider itself. Now when the mouse hovers an arrow, a tiny button appears for you to press it and when the mouse hovers the slider, it is tinted with the defined mouseover highlight color. That seems easy... but it is not. A scrollbar is only one widget with a complex drawing but without children widgets. Probably somebody thought it would have been too easy? Any way, it's manageable to have a real mouseover effect as if there were real widgets in it.

The only thing I didn't like was that both arrows pointing up reacted when you clicked any of them. A few thinking and even that became part of the past. What made me a little proud is that I didn't rip the code from anywhere. Well, I ripped the drawComplexControl(CC_ScrollBar, ...) part from the sources of KDE 3.5.2 but I had to tailor it to fit within Serenity and to handle mouseover effects. When I first saw this in KDE sources, I thought it was useless to have this part "natively" in Serenity. Things turned out differently. That's all I ripped. I wanted to get some "inspiration" from QtCurve style but I gave up the idea. I just couldn't figure out what to take, what to leave. QtCurve sources aren't a model of clarity or --at least-- they are too complicate for my taste. I had to invent my own wheel.

The principle is simple. I track the mouse in the event filter. When the cursor enters the area of a primitive item that needs a mouseover effect, I set a flag which indicates which one and I trigger a redraw. The drawComplexControl() part sets the Style_MouseOver flag of the primitive items according to my flag and initiate their actual redraw. Each primitive item reacts to the Style_MouseOver flag and that's it. My wheel is a simple disc without tire nor hub. ;-)

Well, the problem is that my wheel must be somewhat a little square. It doesn't work with the checkboxes and the radio buttons. I'm having a really hard time. I'm applying the same principle in considering that these widgets contain two areas: the one where the mouseover effect must apply and the other one where it must not. There is a little problem in Qt. It sets the Style_MouseOver flag when the mouse enter the area of the widget but it won't react to a mouse click unless it happens on the label or on the switch. So, when you want to show a nice and accurate mouseover effect, it's much better if you activate it only when the mouse is on the clickable area. With my square wheel, all that I got is that the effect works perfectly with the label --When I see some other styles failing with bitmap or multiline labels, I'm feeling very proud of myself. ;-)-- but once activated it won't let itself being deactivated from the switch until the mouse leaves the whole area of the widget. I banged my head against walls because my hairs are too short to pull them out but I still don't understand why. It makes absolutely no sense! The label and the switch react to the same flag... sometimes together... sometimes not together. There must be a reason but --for the moment-- I will just say it's another illustration of my favorite Murphy's Law:

Constants aren't. Variables won't.


My workaround for such a square wheel was to deactivate the mouseover effect for the switches and to forbid the one over the labels from being deactivated. Come on! There are other widgets I want to take care of, like the spin widget I want to re-design to have as big buttons as possible, the editable combobox that will match the spin widget if I like the new look... and eventually the non-editable combobox that may or may not look better in two colors. I'll dig around the checkboxes and radio buttons later... much later! I'm tired of them.

Now, excuse me but I think I'm going to take a nap. The sun is already up. What a night!

0 Comments:

Post a Comment

<< Home