VirtualBox

Changeset 43819 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Nov 7, 2012 7:20:34 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
81884
Message:

FE/Qt: VM group UI: Group-item cleanup.

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

Legend:

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

    r43810 r43819  
    4848
    4949    /* Add item to the scene: */
    50     if (pScene)
    51         pScene->addItem(this);
     50    AssertMsg(pScene, ("Incorrect scene passed!"));
     51    pScene->addItem(this);
    5252
    5353    /* Translate finally: */
     
    7070
    7171    /* Add item to the scene: */
    72     if (pScene)
    73         pScene->addItem(this);
     72    AssertMsg(pScene, ("Incorrect scene passed!"));
     73    pScene->addItem(this);
    7474
    7575    /* Copy content to 'this': */
     
    177177        return "/";
    178178    /* Get full parent name, append with '/' if not yet appended: */
    179     QString strParentFullName = parentItem()->fullName();
    180     if (!strParentFullName.endsWith('/'))
    181         strParentFullName.append('/');
     179    QString strFullParentName = parentItem()->fullName();
     180    if (!strFullParentName.endsWith('/'))
     181        strFullParentName.append('/');
    182182    /* Return full item name based on parent prefix: */
    183     return strParentFullName + name();
     183    return strFullParentName + name();
    184184}
    185185
     
    191191void UIGChooserItemGroup::setName(const QString &strName)
    192192{
     193    /* Something changed? */
     194    if (m_strName == strName)
     195        return;
     196
     197    /* Remember new name: */
    193198    m_strName = strName;
     199
     200    /* Update visible name: */
     201    recacheVisibleName();
     202    /* Update minimum header size: */
     203    recacheHeaderSize();
    194204}
    195205
     
    207217{
    208218    AssertMsg(parentItem(), ("Can't close root-item!"));
    209     m_pToggleButton->setToggled(false ,fAnimated);
     219    m_pToggleButton->setToggled(false, fAnimated);
    210220}
    211221
     
    216226}
    217227
    218 bool UIGChooserItemGroup::contains(const QString &strId) const
    219 {
    220     /* Check machine items: */
     228bool UIGChooserItemGroup::isContainsMachine(const QString &strId) const
     229{
     230    /* Check each machine-item: */
    221231    foreach (UIGChooserItem *pItem, m_machineItems)
    222232        if (pItem->toMachineItem()->id() == strId)
     
    227237bool UIGChooserItemGroup::isContainsLockedMachine()
    228238{
    229     /* For each machine-item: */
     239    /* Check each machine-item: */
    230240    foreach (UIGChooserItem *pItem, items(UIGChooserItemType_Machine))
    231241        if (pItem->toMachineItem()->isLockedMachine())
    232242            return true;
    233     /* For each group-item: */
     243    /* Check each group-item: */
    234244    foreach (UIGChooserItem *pItem, items(UIGChooserItemType_Group))
    235245        if (pItem->toGroupItem()->isContainsLockedMachine())
     
    240250void UIGChooserItemGroup::sltHandleGeometryChange()
    241251{
    242     /* Which is new geometry? */
     252    /* What is the new geometry? */
    243253    QRectF newGeometry = geometry();
    244254
     
    247257        recacheVisibleName();
    248258
    249     /* Remember new geometry: */
     259    /* Remember the new geometry: */
    250260    m_previousGeometry = newGeometry;
    251261}
     
    264274    foreach (UIGChooserItem *pItem, parentItem()->items(UIGChooserItemType_Group))
    265275        groupNames << pItem->name();
    266 
    267276    /* If proposed name is empty or not unique, reject it: */
    268277    QString strNewName = m_pNameEditorWidget->text().trimmed();
     
    274283    strNewName.replace(QRegExp("[\\\\/:*?\"<>]"), "_");
    275284
    276     /* Set new name / update model: */
    277     m_strName = strNewName;
    278     recacheVisibleName();
    279     recacheHeaderSize();
     285    /* Set new name, save settings: */
     286    setName(strNewName);
    280287    model()->saveGroupSettings();
    281288}
     
    298305    {
    299306        /* Toggle-state and navigation will be
    300          * updated on toggle finish signal! */
     307         * updated on toggle-finish signal! */
    301308    }
    302309    /* Group opened, we are closing it: */
     
    334341void UIGChooserItemGroup::sltIndentRoot()
    335342{
     343    /* Unhover before indenting: */
    336344    setHovered(false);
     345
     346    /* Indent to this root: */
    337347    model()->indentRoot(this);
    338348}
     
    340350void UIGChooserItemGroup::sltUnindentRoot()
    341351{
     352    /* Unhover before unindenting: */
    342353    setHovered(false);
     354
     355    /* Unindent to previous root: */
    343356    model()->unindentRoot();
    344357}
     
    396409    m_machinesPixmap = QPixmap(":/machine_16px.png");
    397410
    398     /* Geometry change handler: */
     411    /* Geometry-change handler: */
    399412    connect(this, SIGNAL(geometryChanged()), this, SLOT(sltHandleGeometryChange()));
    400413
    401     /* Non root item only: */
     414    /* Items except roots: */
    402415    if (!isRoot())
    403416    {
     
    414427
    415428        /* Setup name-editor: */
    416         m_pNameEditorWidget = new UIGroupRenameEditor(m_strName, this);
     429        m_pNameEditorWidget = new UIGroupRenameEditor(name(), this);
    417430        m_pNameEditorWidget->setFont(m_nameFont);
    418431        connect(m_pNameEditorWidget, SIGNAL(sigEditingFinished()), this, SLOT(sltNameEditingFinished()));
     
    421434        m_pNameEditor->hide();
    422435    }
    423     /* Root item but non main: */
     436    /* Items except main root: */
    424437    if (!isMainRoot())
    425438    {
     
    437450void UIGChooserItemGroup::copyContent(UIGChooserItemGroup *pFrom, UIGChooserItemGroup *pTo)
    438451{
    439     /* Copy group items: */
     452    /* Copy group-items: */
    440453    foreach (UIGChooserItem *pGroupItem, pFrom->items(UIGChooserItemType_Group))
    441454        new UIGChooserItemGroup(pTo, pGroupItem->toGroupItem());
    442     /* Copy machine items: */
     455    /* Copy machine-items: */
    443456    foreach (UIGChooserItem *pMachineItem, pFrom->items(UIGChooserItemType_Machine))
    444457        new UIGChooserItemMachine(pTo, pMachineItem->toMachineItem());
     
    449462    /* Update visible name: */
    450463    recacheVisibleName();
    451 
    452464    /* Update minimum header size: */
    453465    recacheHeaderSize();
     
    456468void UIGChooserItemGroup::recacheVisibleName()
    457469{
     470    /* Not for main root: */
     471    if (isMainRoot())
     472        return;
     473
    458474    /* Prepare variables: */
    459475    int iHorizontalMargin = data(GroupItemData_HorizonalMargin).toInt();
     
    468484    int iMaximumWidth = geometry().width();
    469485
    470     /* Calculate name width: */
    471     iMaximumWidth -= 2 * iHorizontalMargin;
     486    /* Left margin: */
     487    iMaximumWidth -= iHorizontalMargin;
     488    /* Button width: */
    472489    if (isRoot())
    473     {
    474         iMaximumWidth -= (iExitButtonWidth + iMajorSpacing);
    475     }
     490        iMaximumWidth -= iExitButtonWidth;
    476491    else
    477     {
    478         iMaximumWidth -= (iToggleButtonWidth + iMajorSpacing);
    479         if (isHovered())
    480             iMaximumWidth -= iEnterButtonWidth;
    481     }
     492        iMaximumWidth -= iToggleButtonWidth;
     493    /* Spacing between button and name: */
     494    iMaximumWidth -= iMajorSpacing;
    482495    if (isHovered())
    483496    {
     497        /* Spacing between name and info: */
    484498        iMaximumWidth -= iMajorSpacing;
    485         if (iGroupCountTextWidth != 0)
     499        /* Group info width: */
     500        if (!m_groupItems.isEmpty())
    486501            iMaximumWidth -= (iGroupPixmapWidth + iGroupCountTextWidth);
    487         if (iMachineCountTextWidth != 0)
     502        /* Machine info width: */
     503        if (!m_machineItems.isEmpty())
    488504            iMaximumWidth -= (iMachinePixmapWidth + iMachineCountTextWidth);
    489505    }
    490 
    491     /* Recache name: */
    492     m_strVisibleName = compressText(m_nameFont, model()->paintDevice(), m_strName, iMaximumWidth);
     506    /* Button width: */
     507    if (!isRoot() && isHovered())
     508        iMaximumWidth -= iEnterButtonWidth;
     509    /* Right margin: */
     510    iMaximumWidth -= iHorizontalMargin;
     511
     512    /* Recache visible name: */
     513    m_strVisibleName = compressText(m_nameFont, model()->paintDevice(), name(), iMaximumWidth);
     514
     515    /* Repaint item: */
    493516    update();
    494517}
     
    514537    QFontMetrics fm(m_nameFont, pPaintDevice);
    515538    int iMaximumNameWidth = textWidth(m_nameFont, pPaintDevice, 20);
    516     QString strCompressedName = compressText(m_nameFont, pPaintDevice, m_strName, iMaximumNameWidth);
     539    QString strCompressedName = compressText(m_nameFont, pPaintDevice, name(), iMaximumNameWidth);
    517540    int iMinimumNameWidth = fm.width(strCompressedName);
    518541    int iMinimumNameHeight = fm.height();
     
    533556    /* Group info width: */
    534557    if (!m_groupItems.isEmpty())
    535         iHeaderWidth += groupPixmapSize.width() +
    536                         groupCountTextSize.width();
     558        iHeaderWidth += (groupPixmapSize.width() + groupCountTextSize.width());
    537559    /* Machine info width: */
    538560    if (!m_machineItems.isEmpty())
    539         iHeaderWidth += machinePixmapSize.width() +
    540                         machineCountTextSize.width();
     561        iHeaderWidth += (machinePixmapSize.width() + machineCountTextSize.width());
    541562    /* Button width: */
    542563    if (!isRoot())
     
    552573    heights /* Minimum name height: */
    553574            << iMinimumNameHeight
    554             /* Group info height: */
     575            /* Group info heights: */
    555576            << groupPixmapSize.height() << groupCountTextSize.height()
    556             /* Machine info height: */
     577            /* Machine info heights: */
    557578            << machinePixmapSize.height() << machineCountTextSize.height();
    558579    /* Button height: */
     
    611632    /* Unlock name-editor: */
    612633    m_pNameEditor->show();
    613     m_pNameEditorWidget->setText(m_strName);
     634    m_pNameEditorWidget->setText(name());
    614635    m_pNameEditorWidget->setFocus();
    615636}
     
    11691190            {
    11701191                /* Make sure passed item is ours or there is no other item with such id: */
    1171                 return m_machineItems.contains(pItem) || !contains(pItem->toMachineItem()->id());
     1192                return m_machineItems.contains(pItem) || !isContainsMachine(pItem->toMachineItem()->id());
    11721193            }
    11731194            case Qt::CopyAction:
    11741195            {
    11751196                /* Make sure there is no other item with such id: */
    1176                 return !contains(pItem->toMachineItem()->id());
     1197                return !isContainsMachine(pItem->toMachineItem()->id());
    11771198            }
    11781199        }
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemGroup.h

    r43810 r43819  
    7979
    8080    /* API: Children stuff: */
    81     bool contains(const QString &strId) const;
     81    bool isContainsMachine(const QString &strId) const;
    8282    bool isContainsLockedMachine();
    8383
Note: See TracChangeset for help on using the changeset viewer.

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