VirtualBox

Changeset 42832 in vbox for trunk/src


Ignore:
Timestamp:
Aug 15, 2012 9:08:59 PM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: 6234: Support for VM groups: Chooser-item lookup mechanism.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserHandlerKeyboard.cpp

    r42830 r42832  
    316316        case Qt::Key_Space:
    317317        {
     318            /* If model is performing lookup: */
     319            if (model()->isPerformingLookup())
     320            {
     321                /* Continue lookup: */
     322                QString strText = pEvent->text();
     323                if (!strText.isEmpty())
     324                    model()->lookFor(strText);
     325            }
    318326            /* If there is a focus item: */
    319             if (UIGChooserItem *pFocusItem = model()->focusItem())
     327            else if (UIGChooserItem *pFocusItem = model()->focusItem())
    320328            {
    321329                /* Of the group type: */
     
    336344        }
    337345        default:
     346        {
     347            /* Start lookup: */
     348            QString strText = pEvent->text();
     349            if (!strText.isEmpty())
     350                model()->lookFor(strText);
    338351            break;
     352        }
    339353    }
    340354    /* Pass all other events: */
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItem.cpp

    r42734 r42832  
    165165            /* And make sure its opened: */
    166166            if (pParentItem->closed())
    167                 pParentItem->open();
     167                pParentItem->open(false);
    168168        }
    169169    }
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.cpp

    r42830 r42832  
    6262    , m_pContextMenuGroup(0)
    6363    , m_pContextMenuMachine(0)
     64    , m_pLookupTimer(0)
    6465{
    6566    /* Prepare scene: */
     
    6970    prepareRoot();
    7071
     72    /* Prepare lookup: */
     73    prepareLookup();
     74
    7175    /* Prepare context-menu: */
    7276    prepareContextMenu();
     
    8387    /* Prepare context-menu: */
    8488    cleanupContextMenu();
     89
     90    /* Cleanup lookup: */
     91    cleanupLookup();
    8592
    8693    /* Cleanup root: */
     
    515522{
    516523    return UIGroupsSavingThread::instance();
     524}
     525
     526void UIGChooserModel::lookFor(const QString &strLookupSymbol)
     527{
     528    /* Restart timer to reset lookup-string: */
     529    m_pLookupTimer->start();
     530    /* Look for item which is starting from the lookup-string: */
     531    UIGChooserItem *pItem = lookForItem(mainRoot(), m_strLookupString + strLookupSymbol);
     532    /* If item found: */
     533    if (pItem)
     534    {
     535        /* Choose it: */
     536        pItem->makeSureItsVisible();
     537        setCurrentItem(pItem);
     538        /* Append lookup symbol: */
     539        m_strLookupString += strLookupSymbol;
     540    }
     541}
     542
     543bool UIGChooserModel::isPerformingLookup() const
     544{
     545    return m_pLookupTimer->isActive();
    517546}
    518547
     
    890919}
    891920
     921void UIGChooserModel::sltEraseLookupTimer()
     922{
     923    m_pLookupTimer->stop();
     924    m_strLookupString = QString();
     925}
     926
    892927QVariant UIGChooserModel::data(int iKey) const
    893928{
     
    909944{
    910945    m_rootStack << new UIGChooserItemGroup(scene());
     946}
     947
     948void UIGChooserModel::prepareLookup()
     949{
     950    m_pLookupTimer = new QTimer(this);
     951    m_pLookupTimer->setInterval(1000);
     952    m_pLookupTimer->setSingleShot(true);
     953    connect(m_pLookupTimer, SIGNAL(timeout()), this, SLOT(sltEraseLookupTimer()));
    911954}
    912955
     
    10181061    delete m_pContextMenuMachine;
    10191062    m_pContextMenuMachine = 0;
     1063}
     1064
     1065void UIGChooserModel::cleanupLookup()
     1066{
     1067    delete m_pLookupTimer;
     1068    m_pLookupTimer = 0;
    10201069}
    10211070
     
    17761825}
    17771826
     1827UIGChooserItem* UIGChooserModel::lookForItem(UIGChooserItem *pParent, const QString &strStartingFrom)
     1828{
     1829    /* Search among the machines: */
     1830    foreach (UIGChooserItem *pItem, pParent->items(UIGChooserItemType_Machine))
     1831        if (pItem->name().startsWith(strStartingFrom, Qt::CaseInsensitive))
     1832            return pItem;
     1833    /* Search among the groups: */
     1834    foreach (UIGChooserItem *pItem, pParent->items(UIGChooserItemType_Group))
     1835    {
     1836        if (pItem->name().startsWith(strStartingFrom, Qt::CaseInsensitive))
     1837            return pItem;
     1838        if (UIGChooserItem *pResult = lookForItem(pItem, strStartingFrom))
     1839            return pResult;
     1840    }
     1841    /* Nothing found: */
     1842    return 0;
     1843}
     1844
    17781845/* static */
    17791846UIGroupsSavingThread* UIGroupsSavingThread::m_spInstance = 0;
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.h

    r42830 r42832  
    4444class UIGChooserHandlerMouse;
    4545class UIGChooserHandlerKeyboard;
     46class QTimer;
    4647
    4748/* Context-menu type: */
     
    156157    bool isGroupSavingInProgress() const;
    157158
     159    /* API: Lookup stuff: */
     160    void lookFor(const QString &strLookupSymbol);
     161    bool isPerformingLookup() const;
     162
    158163private slots:
    159164
     
    204209    void sltGroupSavingComplete();
    205210
     211    /* Handler: Lookup stuff: */
     212    void sltEraseLookupTimer();
     213
    206214private:
    207215
     
    219227    void prepareScene();
    220228    void prepareRoot();
     229    void prepareLookup();
    221230    void prepareContextMenu();
    222231    void prepareHandlers();
     
    227236    void cleanupHandlers();
    228237    void cleanupContextMenu();
     238    void cleanupLookup();
    229239    void cleanupRoot();
    230240    void cleanupScene();
     
    293303    /* Helper: Group saving stuff: */
    294304    void makeSureGroupSavingIsFinished();
     305
     306    /* Helper: Lookup stuff: */
     307    UIGChooserItem* lookForItem(UIGChooserItem *pParent, const QString &strStartingFrom);
    295308
    296309    /* Variables: */
     
    314327    QMenu *m_pContextMenuGroup;
    315328    QMenu *m_pContextMenuMachine;
     329
     330    /* Variables: Lookup stuff: */
     331    QTimer *m_pLookupTimer;
     332    QString m_strLookupString;
    316333};
    317334
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