[mythtv] Variable width buttons in MythUI - can anybody help?

Justin Hornsby justin_hornsby at hotmail.com
Wed Jul 22 07:36:58 UTC 2009

This is a yell for help, if anybody has some time to lend a hand..

I've been trying to hack up some mythui code changes to allow the widths of buttons in a mythuibuttonlist to be determined by the length of text in a statetype.  Currently, button sizes are defined in the theme xml which is all very well for many things but IMHO some theme ideas incorporating horizontal buttonlists could benefit from this feature.

A user going by the nick 'anykey' in IRC did the easy part on his own - namely parsing the xml for an <autosize> tag and calculating the width of a text element if the tag affirms it. I then lent a hand & had the code set the area to the new width rather than its drawarea (which didn't work but looked messy onscreen due to a Qt issue).  However, this on its own isn't enough.

Button positions & the amount of visible items are determined by the size of the parent, so the parent area size needs to be changed to that of the child to accomodate it.  I'm stuck on this part.  As far as I've been able to tell, the area of the child text is being changed but what needs to be done is expand (or contract) the area of its parent(s).

The hack as it stands is here:http://homepage.ntlworld.com/justin.hornsby2/hack.diff

There are some changes to button positioning code (to allow the 'selected' button item to be a different width) which kinda messes other things up, but they should be fairly easy to work out once this size changing aspect is squashed.

I shoved some VERBOSE in there to try & get an idea what is going on - it seems that the 

VERBOSE(VB_IMPORTANT, QString("button width=%1").arg(m_dWidth));  

is happening before the autosize xml tag is even parsed, which could be the root of the problem, I don't know. Or maybe the iteration in CollapseArea() needs to be recursive.  Or, maybe this is the wrong way to go about it entirely.

I'm new to coding, I don't have a firm grasp of anything yet but I'd love to get this working.  Any help here would truly be appreciated.  If we can pull this off, I genuinely believe we'll have a really useful feature that'll improve the usefulness of horizontal buttonlists no end

Obviously the diff is very rough at the moment & takes a few short-cuts which can be put right later - we could have it autosize to a maximum set by the 'normal' button size or use the xml set value as a minimum.. (or both) as I've already implied those are immaterial until the resizing of parent elements actually works.

So, if anyone has some time to spare to dig into libs/libmythui/mythuibuttonlist.cpp et al with me, please chime in with your suggestions.  Yes, taking the long route, signing up to college & learning c++ properly has crossed my mind already.. I'm getting that desperate ;-) (not that it'd necessarily help me understand the code here).

There are other improvements I'd like to make too, such as auto-centring buttons & auto-spacing them.. but I got sidetracked into this blind alley...


Windows Live Messenger: Happy 10-Year Anniversary—get free winks and emoticons.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mythtv.org/pipermail/mythtv-dev/attachments/20090722/13810a59/attachment.htm>

More information about the mythtv-dev mailing list