Recursing through all widgets to disable and enable

Jekteir

28-07-2007 00:59:15

I'm recursing through all the widgets within my guiSheet (default sheet) and disabling all those widgets which are not my "confirmExitWindow", or within that window. The idea is the same as a standard Windows 'on top of all others, holds focus'-style window. This seems to be working fine now (as you can see below, trying to disable a ListItem-style widget crashes the program with a bad pointer, so I avoid those types of widget; no idea where the crash happens; I assume it's because the disable code higher up does something inappropriate for that type of widget): when I pop my exit window up and run disableWidgets(), all widgets except for the 'Yes/No' dialog are disabled. They look disabled, too.

However, when I run enableWidgets() (assuming the user cancelled their decision to exit), while the functionality of all widgets is restored, the text at the top of menu lists (e.g. 'File' for the file menu: the text on that actual top bar), and also text within labels (and maybe other things, but that's all the widgets I have right now), are not made white again, but remain darkened.

Any idea how I could fix this? Feel free to use this code, or any of it you like, if you wanna create a similar 'always-on-top, holds-focus'-style toggle setting for widgets :) I'd be in favour. The try/catch statement, by the way, is just to establish the enum int value of any type that crashes on disable. I haven't tested that exceptions code, so I have no idea if it works ;)

Jek


void WorldEditor::disableWidgets(QuickGUI::Widget* widgetPointer)
{
if (widgetPointer->getInstanceName() != "confirmExitWindow" && widgetPointer->getWidgetType() != QuickGUI::Widget::QGUI_TYPE_LISTITEM)
{
try
{
widgetPointer->disable();
}
catch (int e)
{
std::stringstream ss;
std::string str;
ss << int(widgetPointer->getWidgetType());
ss >> str;
Ogre::LogManager::getSingletonPtr()->logMessage("Problem with " + str);
}
}
if (widgetPointer->getInstanceName() != "confirmExitWindow")
{
std::vector<QuickGUI::Widget*> *childWidgets = widgetPointer->getChildWidgetList();
if (!childWidgets->empty())
{
for (std::vector<QuickGUI::Widget*>::iterator i = childWidgets->begin(); i < childWidgets->end(); i++)
{
disableWidgets(*i);
}
}
}
}


void WorldEditor::enableWidgets(QuickGUI::Widget* widgetPointer)
{
if (widgetPointer->getInstanceName() != "confirmExitWindow" && widgetPointer->getWidgetType() != QuickGUI::Widget::QGUI_TYPE_LISTITEM)
{
widgetPointer->enable();
}
if (widgetPointer->getInstanceName() != "confirmExitWindow")
{
std::vector<QuickGUI::Widget*> *childWidgets = widgetPointer->getChildWidgetList();
if (!childWidgets->empty())
{
for (std::vector<QuickGUI::Widget*>::iterator i = childWidgets->begin(); i < childWidgets->end(); i++)
{
enableWidgets(*i);
}
}
}
}

kungfoomasta

28-07-2007 01:17:56

Yah, when enabling, I forgot to set the text back to the default color. :oops:

I think the disable function by default should recursively disable all children. It may not be doing that now, but it should be changed to behave like this. :wink:

Jekteir

28-07-2007 01:24:00

Hey, could you possibly tell me where the code for getting the text back to the right colour should go, please, so I can sort this out in my copy?

On the disabling all children front: well, that makes sense. I would still have to iterate through all the top-children of my default sheet, of course, so that I could disable all of them except for the window I want to keep working.

Jek


P.S. Can you see what pointer's giving grief when one tries to disable a ListItem?

Jekteir

30-07-2007 03:14:56

Got the text color thing working (I added some specific ColourValues to the enable/disable functions).

However, I'm now having a problem that seems to be related to doing this with more than one window -- not at a time, but at different times during the same run.

E.g.
1] I run the 'exit' window, then cancel that dialog, and all gets re-enabled. Fine.
2] I run the 'Load file' window, which works the same way, disables all the others, then I cancel that, all else gets restored and brightened. Fine.
3] I run the 'exit' window again. This time I cannot see the text in the titlebar of the exit window. It has evidently been darkened by the other disablement for the Load dialog, but never restored.

I believe this may be to do with titlebars/maybe other elements having more than one parent, or having some kind of parent confusion? Maybe not. I guess this means that on the disable from the Load window, the text in Exit got disabled (fine) but was not re-enabled on the cancel of the Load window.

Anyway, here is the code; you are meant to pass the guiSheet as the first argument (like the 'parent node' to recurse down from), and the window you want to be exempt from the enablement/disabled as the second (i.e. the window to have unique focus on it):


void WorldEditor::disableWidgets(QuickGUI::Widget* widgetPointer,QuickGUI::Widget* notThisWidget = 0)
{
if (widgetPointer != notThisWidget)
{
widgetPointer->disable();
std::vector<QuickGUI::Widget*> *childWidgets = widgetPointer->getChildWidgetList();
if (!childWidgets->empty())
{
for (std::vector<QuickGUI::Widget*>::iterator i = childWidgets->begin(); i < childWidgets->end(); i++)
{
disableWidgets(*i,notThisWidget);
}
}
}
}


void WorldEditor::enableWidgets(QuickGUI::Widget* widgetPointer,QuickGUI::Widget* notThisWidget = 0)
{
if (widgetPointer != notThisWidget)
{
widgetPointer->enable();
std::vector<QuickGUI::Widget*> *childWidgets = widgetPointer->getChildWidgetList();
if (!childWidgets->empty())
{
for (std::vector<QuickGUI::Widget*>::iterator i = childWidgets->begin(); i < childWidgets->end(); i++)
{
enableWidgets(*i,notThisWidget);
}
}
}
}


Can you see what it might be doing, to miss a titlebar's text?