VirtualBox

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


Ignore:
Timestamp:
Jun 5, 2014 11:23:55 AM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
94198
Message:

FE/Qt: 6660: Advanced extra-data management framework: Integrate GUI_LastNormalWindowPosition, GUI_LastScaleWindowPosition, GUI_LastWindowState_Max.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp

    r51548 r51549  
    510510}
    511511
     512QRect UIExtraDataManager::machineWindowGeometry(UIVisualStateType visualStateType, ulong uScreenIndex, const QString &strId) const
     513{
     514    /* Choose corresponding key: */
     515    QString strKey;
     516    switch (visualStateType)
     517    {
     518        case UIVisualStateType_Normal: strKey = GUI_LastNormalWindowPosition; break;
     519        case UIVisualStateType_Scale:  strKey = GUI_LastScaleWindowPosition; break;
     520        default: AssertFailedReturn(QRect());
     521    }
     522    /* Append with screen-index: */
     523    if (uScreenIndex)
     524        strKey += QString::number(uScreenIndex);
     525
     526    /* Load corresponding extra-data: */
     527    const QStringList data = extraDataStringList(strKey, strId);
     528
     529    /* Parse loaded data: */
     530    int iX = 0, iY = 0, iW = 0, iH = 0;
     531    bool fOk = data.size() >= 4;
     532    do
     533    {
     534        if (!fOk) break;
     535        iX = data[0].toInt(&fOk);
     536        if (!fOk) break;
     537        iY = data[1].toInt(&fOk);
     538        if (!fOk) break;
     539        iW = data[2].toInt(&fOk);
     540        if (!fOk) break;
     541        iH = data[3].toInt(&fOk);
     542    }
     543    while (0);
     544
     545    /* Return geometry (loaded or null): */
     546    return fOk ? QRect(iX, iY, iW, iH) : QRect();
     547}
     548
     549bool UIExtraDataManager::isMachineWindowShouldBeMaximized(UIVisualStateType visualStateType, ulong uScreenIndex, const QString &strId) const
     550{
     551    /* Choose corresponding key: */
     552    QString strKey;
     553    switch (visualStateType)
     554    {
     555        case UIVisualStateType_Normal: strKey = GUI_LastNormalWindowPosition; break;
     556        case UIVisualStateType_Scale:  strKey = GUI_LastScaleWindowPosition; break;
     557        default: AssertFailedReturn(false);
     558    }
     559    /* Append with screen-index: */
     560    if (uScreenIndex)
     561        strKey += QString::number(uScreenIndex);
     562
     563    /* Load corresponding extra-data: */
     564    const QStringList data = extraDataStringList(strKey, strId);
     565
     566    /* Make sure 5th item has required value: */
     567    return data.size() == 5 && data[4] == GUI_LastWindowState_Max;
     568}
     569
     570void UIExtraDataManager::setMachineWindowGeometry(UIVisualStateType visualStateType, ulong uScreenIndex, const QRect &geometry, bool fMaximized, const QString &strId)
     571{
     572    /* Choose corresponding key: */
     573    QString strKey;
     574    switch (visualStateType)
     575    {
     576        case UIVisualStateType_Normal: strKey = GUI_LastNormalWindowPosition; break;
     577        case UIVisualStateType_Scale:  strKey = GUI_LastScaleWindowPosition; break;
     578        default: AssertFailedReturnVoid();
     579    }
     580    /* Append with screen-index: */
     581    if (uScreenIndex)
     582        strKey += QString::number(uScreenIndex);
     583
     584    /* Serialize passed values: */
     585    QStringList data;
     586    data << QString::number(geometry.x());
     587    data << QString::number(geometry.y());
     588    data << QString::number(geometry.width());
     589    data << QString::number(geometry.height());
     590    if (fMaximized)
     591        data << GUI_LastWindowState_Max;
     592
     593    /* Re-cache corresponding extra-data: */
     594    setExtraDataStringList(strKey, data, strId);
     595}
     596
    512597bool UIExtraDataManager::isFirstRun(const QString &strId) const
    513598{
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.h

    r51548 r51549  
    173173    /** Defines selector-window preview update @a interval. */
    174174    void setSelectorWindowPreviewUpdateInterval(PreviewUpdateIntervalType interval);
     175
     176    /** Returns geometry for machine-window with @a uScreenIndex in @a visualStateType. */
     177    QRect machineWindowGeometry(UIVisualStateType visualStateType, ulong uScreenIndex, const QString &strId) const;
     178    /** Returns whether machine-window with @a uScreenIndex in @a visualStateType should be maximized or not. */
     179    bool isMachineWindowShouldBeMaximized(UIVisualStateType visualStateType, ulong uScreenIndex, const QString &strId) const;
     180    /** Defines geometry for machine-window with @a uScreenIndex in @a visualStateType as @a geometry and @a fMaximized. */
     181    void setMachineWindowGeometry(UIVisualStateType visualStateType, ulong uScreenIndex, const QRect &geometry, bool fMaximized, const QString &strId);
    175182
    176183    /** Returns whether this machine started for the first time. */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp

    r51398 r51549  
    432432    CMachine m = machine();
    433433
    434     /* Load extra-data settings: */
    435     {
    436         /* Load window position settings: */
    437         QString strPositionAddress = m_uScreenId == 0 ? QString("%1").arg(GUI_LastNormalWindowPosition) :
    438                                      QString("%1%2").arg(GUI_LastNormalWindowPosition).arg(m_uScreenId);
    439         QStringList strPositionSettings = m.GetExtraDataStringList(strPositionAddress);
    440         bool ok = !strPositionSettings.isEmpty(), max = false;
    441         int x = 0, y = 0, w = 0, h = 0;
    442         if (ok && strPositionSettings.size() > 0)
    443             x = strPositionSettings[0].toInt(&ok);
    444         else ok = false;
    445         if (ok && strPositionSettings.size() > 1)
    446             y = strPositionSettings[1].toInt(&ok);
    447         else ok = false;
    448         if (ok && strPositionSettings.size() > 2)
    449             w = strPositionSettings[2].toInt(&ok);
    450         else ok = false;
    451         if (ok && strPositionSettings.size() > 3)
    452             h = strPositionSettings[3].toInt(&ok);
    453         else ok = false;
    454         if (ok && strPositionSettings.size() > 4)
    455             max = strPositionSettings[4] == GUI_LastWindowState_Max;
    456         QRect ar = ok ? QApplication::desktop()->availableGeometry(QPoint(x, y)) :
    457                         QApplication::desktop()->availableGeometry(this);
    458 
    459         /* If previous parameters were read correctly: */
    460         if (ok)
     434    /* Load window geometry: */
     435    {
     436        /* Load extra-data: */
     437        QRect geo = gEDataManager->machineWindowGeometry(machineLogic()->visualStateType(),
     438                                                         m_uScreenId, vboxGlobal().managedVMUuid());
     439
     440        /* If we do have proper geometry: */
     441        if (!geo.isNull())
    461442        {
    462             /* If previous machine state is SAVED: */
     443            /* If previous machine-state was SAVED: */
    463444            if (m.GetState() == KMachineState_Saved)
    464445            {
    465                 /* Restore window size and position: */
    466                 m_normalGeometry = QRect(x, y, w, h);
     446                /* Restore window geometry: */
     447                m_normalGeometry = geo;
    467448                setGeometry(m_normalGeometry);
    468449            }
    469             /* If previous machine state was not SAVED: */
     450            /* If previous machine-state was NOT SAVED: */
    470451            else
    471452            {
    472453                /* Restore only window position: */
    473                 m_normalGeometry = QRect(x, y, width(), height());
     454                m_normalGeometry = QRect(geo.x(), geo.y(), width(), height());
    474455                setGeometry(m_normalGeometry);
    475                 /* Normalize to the optimal size: */
     456                /* And normalize to the optimal-size: */
    476457                normalizeGeometry(false);
    477458            }
    478             /* Maximize if needed: */
    479             if (max)
     459
     460            /* Maximize (if necessary): */
     461            if (gEDataManager->isMachineWindowShouldBeMaximized(machineLogic()->visualStateType(),
     462                                                                m_uScreenId, vboxGlobal().managedVMUuid()))
    480463                setWindowState(windowState() | Qt::WindowMaximized);
    481464        }
     465        /* If we do NOT have proper geometry: */
    482466        else
    483467        {
     468            /* Get available geometry, for screen with (x,y) coords if possible: */
     469            QRect availableGeo = !geo.isNull() ? QApplication::desktop()->availableGeometry(QPoint(geo.x(), geo.y())) :
     470                                                 QApplication::desktop()->availableGeometry(this);
     471
    484472            /* Normalize to the optimal size: */
    485473            normalizeGeometry(true);
    486             /* Move newly created window to the screen center: */
     474            /* Move newly created window to the screen-center: */
    487475            m_normalGeometry = geometry();
    488             m_normalGeometry.moveCenter(ar.center());
     476            m_normalGeometry.moveCenter(availableGeo.center());
    489477            setGeometry(m_normalGeometry);
    490478        }
     
    534522void UIMachineWindowNormal::saveSettings()
    535523{
    536     /* Get machine: */
    537     CMachine m = machine();
    538 
    539     /* Save extra-data settings: */
    540     {
    541         QString strWindowPosition = QString("%1,%2,%3,%4")
    542                                     .arg(m_normalGeometry.x()).arg(m_normalGeometry.y())
    543                                     .arg(m_normalGeometry.width()).arg(m_normalGeometry.height());
    544         if (isMaximizedChecked())
    545             strWindowPosition += QString(",%1").arg(GUI_LastWindowState_Max);
    546         QString strPositionAddress = m_uScreenId == 0 ? QString("%1").arg(GUI_LastNormalWindowPosition) :
    547                                      QString("%1%2").arg(GUI_LastNormalWindowPosition).arg(m_uScreenId);
    548         m.SetExtraData(strPositionAddress, strWindowPosition);
     524    /* Save window geometry: */
     525    {
     526        gEDataManager->setMachineWindowGeometry(machineLogic()->visualStateType(),
     527                                                m_uScreenId, m_normalGeometry,
     528                                                isMaximizedChecked(), vboxGlobal().managedVMUuid());
    549529    }
    550530
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineWindowScale.cpp

    r51054 r51549  
    105105    /* Load extra-data settings: */
    106106    {
    107         QString strPositionAddress = m_uScreenId == 0 ? QString("%1").arg(GUI_LastScaleWindowPosition) :
    108                                      QString("%1%2").arg(GUI_LastScaleWindowPosition).arg(m_uScreenId);
    109         QStringList strPositionSettings = m.GetExtraDataStringList(strPositionAddress);
    110 
    111         bool ok = !strPositionSettings.isEmpty(), max = false;
    112         int x = 0, y = 0, w = 0, h = 0;
    113 
    114         if (ok && strPositionSettings.size() > 0)
    115             x = strPositionSettings[0].toInt(&ok);
    116         else ok = false;
    117         if (ok && strPositionSettings.size() > 1)
    118             y = strPositionSettings[1].toInt(&ok);
    119         else ok = false;
    120         if (ok && strPositionSettings.size() > 2)
    121             w = strPositionSettings[2].toInt(&ok);
    122         else ok = false;
    123         if (ok && strPositionSettings.size() > 3)
    124             h = strPositionSettings[3].toInt(&ok);
    125         else ok = false;
    126         if (ok && strPositionSettings.size() > 4)
    127             max = strPositionSettings[4] == GUI_LastWindowState_Max;
    128 
    129         QRect ar = ok ? QApplication::desktop()->availableGeometry(QPoint(x, y)) :
    130                         QApplication::desktop()->availableGeometry(this);
    131 
    132         /* If previous parameters were read correctly: */
    133         if (ok)
    134         {
    135             /* Restore window size and position: */
    136             m_normalGeometry = QRect(x, y, w, h);
     107        /* Load extra-data: */
     108        QRect geo = gEDataManager->machineWindowGeometry(machineLogic()->visualStateType(),
     109                                                         m_uScreenId, vboxGlobal().managedVMUuid());
     110
     111        /* If we do have proper geometry: */
     112        if (!geo.isNull())
     113        {
     114            /* Restore window geometry: */
     115            m_normalGeometry = geo;
    137116            setGeometry(m_normalGeometry);
    138             /* Maximize if needed: */
    139             if (max)
     117
     118            /* Maximize (if necessary): */
     119            if (gEDataManager->isMachineWindowShouldBeMaximized(machineLogic()->visualStateType(),
     120                                                                m_uScreenId, vboxGlobal().managedVMUuid()))
    140121                setWindowState(windowState() | Qt::WindowMaximized);
    141122        }
     123        /* If we do NOT have proper geometry: */
    142124        else
    143125        {
     126            /* Get available geometry, for screen with (x,y) coords if possible: */
     127            QRect availableGeo = !geo.isNull() ? QApplication::desktop()->availableGeometry(QPoint(geo.x(), geo.y())) :
     128                                                 QApplication::desktop()->availableGeometry(this);
     129
    144130            /* Resize to default size: */
    145131            resize(640, 480);
    146             qApp->processEvents();
    147             /* Move newly created window to the screen center: */
     132            /* Move newly created window to the screen-center: */
    148133            m_normalGeometry = geometry();
    149             m_normalGeometry.moveCenter(ar.center());
     134            m_normalGeometry.moveCenter(availableGeo.center());
    150135            setGeometry(m_normalGeometry);
    151136        }
     
    158143    CMachine m = machine();
    159144
    160     /* Save extra-data settings: */
    161     {
    162         QString strWindowPosition = QString("%1,%2,%3,%4")
    163                                     .arg(m_normalGeometry.x()).arg(m_normalGeometry.y())
    164                                     .arg(m_normalGeometry.width()).arg(m_normalGeometry.height());
    165         if (isMaximizedChecked())
    166             strWindowPosition += QString(",%1").arg(GUI_LastWindowState_Max);
    167         QString strPositionAddress = m_uScreenId == 0 ? QString("%1").arg(GUI_LastScaleWindowPosition) :
    168                                      QString("%1%2").arg(GUI_LastScaleWindowPosition).arg(m_uScreenId);
    169         m.SetExtraData(strPositionAddress, strWindowPosition);
     145    /* Save window geometry: */
     146    {
     147        gEDataManager->setMachineWindowGeometry(machineLogic()->visualStateType(),
     148                                                m_uScreenId, m_normalGeometry,
     149                                                isMaximizedChecked(), vboxGlobal().managedVMUuid());
    170150    }
    171151
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