VirtualBox

Changeset 3806 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jul 24, 2007 11:06:48 AM (18 years ago)
Author:
vboxsync
Message:

FE/Qt: Added VBoxAsyncEvent and VBoxGlobal::findWidget() helpers (see class docs for details).

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxDefs.h

    r3802 r3806  
    117117
    118118    /** VM display rendering mode. */
    119     enum RenderMode {
     119    enum RenderMode
     120    {
    120121        InvalidRenderMode, TimerMode, QImageMode, SDLMode, DDRAWMode
    121122    };
    122123
    123124    /** Additional Qt event types. */
    124     enum {
    125         ResizeEventType = QEvent::User,
     125    enum
     126    {
     127        AsyncEventType = QEvent::User + 100,
     128        ResizeEventType,
    126129        RepaintEventType,
    127130        SetRegionEventType,
     
    137140        RuntimeErrorEventType,
    138141        ModifierKeyChangeEventType,
    139         EnumerateMediaEventType = QEvent::User + 100,
     142        EnumerateMediaEventType,
    140143#if defined (Q_WS_WIN)
    141144        ShellExecuteEventType,
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxGlobal.h

    r3448 r3806  
    435435    static QString removeAccelMark (const QString &aText);
    436436
     437    static QWidget *findWidget (QWidget *aParent, const char *aName,
     438                                const char *aClassName = NULL,
     439                                bool aRecursive = false);
     440
    437441signals:
    438442
     
    548552inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
    549553
     554// Helper classes
     555////////////////////////////////////////////////////////////////////////////////
     556
     557/**
     558 *  Generic asyncronous event.
     559 *
     560 *  This abstract class is intended to provide a conveinent way to execute
     561 *  code on the main GUI thread asynchronously to the calling party. This is
     562 *  done by putting necessary actions to the #handle() function in a subclass
     563 *  and then posting an instance of the subclass using #post(). The instance
     564 *  must be allocated on the heap using the <tt>new</tt> operation and will be
     565 *  automatically deleted after processing. Note that if you don't call #post()
     566 *  on the created instance, you have to delete it yourself.
     567 */
     568class VBoxAsyncEvent : public QEvent
     569{
     570public:
     571
     572    VBoxAsyncEvent() : QEvent ((QEvent::Type) VBoxDefs::AsyncEventType) {}
     573
     574    /**
     575     *  Worker function. Gets executed on the GUI thread when the posted event
     576     *  is processed by the main event loop.
     577     */
     578    virtual void handle() = 0;
     579
     580    /**
     581     *  Posts this event to the main event loop.
     582     *  The caller loses ownership of this object after this method returns
     583     *  and must not delete the object.
     584     */
     585    void post()
     586    {
     587        QApplication::postEvent (&vboxGlobal(), this);
     588    }
     589};
    550590
    551591/**
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp

    r3762 r3806  
    29902990}
    29912991
     2992/**
     2993 *  Searches for a widget that with @a aName (if it is not NULL) which inherits
     2994 *  @a aClassName (if it is not NULL) and among children of @a aParent. If @a
     2995 *  aParent is NULL, all top-level widgets are searched. If @a aRecursive is
     2996 *  true, child widgets are recursively searched as well. 
     2997 */
     2998/* static */
     2999QWidget *VBoxGlobal::findWidget (QWidget *aParent, const char *aName,
     3000                                 const char *aClassName /* = NULL */,
     3001                                 bool aRecursive /* = false */)
     3002{
     3003    if (aParent == NULL)
     3004    {
     3005        QWidgetList *list = QApplication::topLevelWidgets();
     3006        QWidgetListIt it (*list);
     3007        QWidget *w = NULL;
     3008        for (; (w = it.current()) != NULL; ++ it)
     3009        {
     3010            if ((!aName || strcmp (w->name(), aName) == 0) &&
     3011                (!aClassName || strcmp (w->className(), aClassName) == 0))
     3012                break;
     3013            if (aRecursive)
     3014            {
     3015                w = findWidget (w, aName, aClassName, aRecursive);
     3016                if (w)
     3017                    break;
     3018            }
     3019        }
     3020        delete list;
     3021        return w;
     3022    }
     3023
     3024    QObjectList *list = aParent->queryList (aName, aClassName, false, true);
     3025    QObjectListIt it (*list);
     3026    QObject *obj = NULL;
     3027    for (; (obj = it.current()) != NULL; ++ it)
     3028    {
     3029        if (obj->isWidgetType())
     3030            break;
     3031    }
     3032    delete list;
     3033    return (QWidget *) obj;
     3034}
     3035
    29923036// Protected members
    29933037////////////////////////////////////////////////////////////////////////////////
     
    30093053        }
    30103054#endif
     3055
     3056        case VBoxDefs::AsyncEventType:
     3057        {
     3058            VBoxAsyncEvent *ev = (VBoxAsyncEvent *) e;
     3059            ev->handle();
     3060            return true;
     3061        }
    30113062
    30123063        case VBoxDefs::EnumerateMediaEventType:
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette