VirtualBox

Changeset 39021 in vbox


Ignore:
Timestamp:
Oct 18, 2011 3:10:13 PM (13 years ago)
Author:
vboxsync
Message:

FE/Qt: semantic refactoring and documentation: desktop geometry -> maximum guest size

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.cpp

    r38311 r39021  
    184184        return E_POINTER;
    185185    *pbSupported = TRUE;
    186     QSize screen = m_pMachineView->desktopGeometry();
     186    QSize screen = m_pMachineView->maxGuestSize();
    187187    if ((screen.width() != 0) && (uWidth > (ULONG)screen.width()))
    188188        *pbSupported = FALSE;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp

    r38992 r39021  
    160160    AssertMsg(newSize.isValid(), ("Size should be valid!\n"));
    161161
    162     /* Store the new size */
    163     storeConsoleSize(newSize.width(), newSize.height());
     162    /* Store the new hint */
     163    storeHintForGuestSizePolicy(newSize.width(), newSize.height());
    164164    /* Send new size-hint to the guest: */
    165165    session().GetConsole().GetDisplay().SetVideoModeHint(newSize.width(), newSize.height(), 0, screenId());
     
    238238    , m_pFrameBuffer(0)
    239239    , m_previousState(KMachineState_Null)
    240     , m_desktopGeometryType(DesktopGeo_Invalid)
     240    , m_maxGuestSizePolicy(MaxGuestSizePolicy_Invalid)
    241241#ifdef VBOX_WITH_VIDEOHWACCEL
    242242    , m_fAccelerate2DVideo(bAccelerate2DVideo)
     
    480480    /* Global settings: */
    481481    {
    482         /* Remember the desktop geometry and register for geometry
    483          * change events for telling the guest about video modes we like: */
    484         QString desktopGeometry = vboxGlobal().settings().publicProperty("GUI/MaxGuestResolution");
    485         if ((desktopGeometry == QString::null) || (desktopGeometry == "auto"))
    486             setDesktopGeometry(DesktopGeo_Automatic, 0, 0);
    487         else if (desktopGeometry == "any")
    488             setDesktopGeometry(DesktopGeo_Any, 0, 0);
    489         else
    490         {
    491             int width = desktopGeometry.section(',', 0, 0).toInt();
    492             int height = desktopGeometry.section(',', 1, 1).toInt();
    493             setDesktopGeometry(DesktopGeo_Fixed, width, height);
     482        /* Remember the maximum guest size policy for telling the guest about
     483         * video modes we like: */
     484        QString maxGuestSize = vboxGlobal().settings().publicProperty("GUI/MaxGuestResolution");
     485        if ((maxGuestSize == QString::null) || (maxGuestSize == "auto"))
     486            setMaxGuestSizePolicy(MaxGuestSizePolicy_Automatic, 0, 0);
     487        else if (maxGuestSize == "any")
     488            setMaxGuestSizePolicy(MaxGuestSizePolicy_Any, 0, 0);
     489        else  /** @todo Mea culpa, but what about error checking? */
     490        {
     491            int width  = maxGuestSize.section(',', 0, 0).toInt();
     492            int height = maxGuestSize.section(',', 1, 1).toInt();
     493            setMaxGuestSizePolicy(MaxGuestSizePolicy_Fixed, width, height);
    494494        }
    495495    }
     
    596596}
    597597
    598 QSize UIMachineView::desktopGeometry() const
    599 {
    600     QSize geometry;
    601     switch (m_desktopGeometryType)
    602     {
    603         case DesktopGeo_Fixed:
    604         case DesktopGeo_Automatic:
    605             geometry = QSize(qMax(m_desktopGeometry.width(), m_storedConsoleSize.width()),
    606                              qMax(m_desktopGeometry.height(), m_storedConsoleSize.height()));
    607             break;
    608         case DesktopGeo_Any:
    609             geometry = QSize(0, 0);
     598QSize UIMachineView::maxGuestSize() const
     599{
     600    QSize maxSize;
     601    switch (m_maxGuestSizePolicy)
     602    {
     603        case MaxGuestSizePolicy_Fixed:
     604        case MaxGuestSizePolicy_Automatic:
     605            maxSize = QSize(qMax(m_fixedMaxGuestSize.width(), m_storedGuestHintSize.width()),
     606                             qMax(m_fixedMaxGuestSize.height(), m_storedGuestHintSize.height()));
     607            break;
     608        case MaxGuestSizePolicy_Any:
     609            maxSize = QSize(0, 0);
    610610            break;
    611611        default:
    612             AssertMsgFailed(("Bad geometry type %d!\n", m_desktopGeometryType));
    613     }
    614     return geometry;
     612            AssertMsgFailed(("Invalid maximum guest size policy %d!\n",
     613                             m_maxGuestSizePolicy));
     614    }
     615    return maxSize;
    615616}
    616617
     
    650651}
    651652
    652 void UIMachineView::setDesktopGeometry(DesktopGeo geometry, int aWidth, int aHeight)
    653 {
    654     switch (geometry)
    655     {
    656         case DesktopGeo_Fixed:
    657             m_desktopGeometryType = DesktopGeo_Fixed;
    658             if (aWidth != 0 && aHeight != 0)
    659                 m_desktopGeometry = QSize(aWidth, aHeight);
     653void UIMachineView::setMaxGuestSizePolicy(MaxGuestSizePolicy policy, int cwMax,
     654                                          int chMax)
     655{
     656    switch (policy)
     657    {
     658        case MaxGuestSizePolicy_Fixed:
     659            m_maxGuestSizePolicy = MaxGuestSizePolicy_Fixed;
     660            if (cwMax != 0 && chMax != 0)
     661                m_fixedMaxGuestSize = QSize(cwMax, chMax);
    660662            else
    661                 m_desktopGeometry = QSize(0, 0);
    662             storeConsoleSize(0, 0);
    663             break;
    664         case DesktopGeo_Automatic:
    665             m_desktopGeometryType = DesktopGeo_Automatic;
    666             m_desktopGeometry = QSize(0, 0);
    667             storeConsoleSize(0, 0);
    668             break;
    669         case DesktopGeo_Any:
    670             m_desktopGeometryType = DesktopGeo_Any;
    671             m_desktopGeometry = QSize(0, 0);
     663                m_fixedMaxGuestSize = QSize(0, 0);
     664            storeHintForGuestSizePolicy(0, 0);
     665            break;
     666        case MaxGuestSizePolicy_Automatic:
     667            m_maxGuestSizePolicy = MaxGuestSizePolicy_Automatic;
     668            m_fixedMaxGuestSize = QSize(0, 0);
     669            storeHintForGuestSizePolicy(0, 0);
     670            break;
     671        case MaxGuestSizePolicy_Any:
     672            m_maxGuestSizePolicy = MaxGuestSizePolicy_Any;
     673            m_fixedMaxGuestSize = QSize(0, 0);
    672674            break;
    673675        default:
    674             AssertMsgFailed(("Invalid desktop geometry type %d\n", geometry));
    675             m_desktopGeometryType = DesktopGeo_Invalid;
    676     }
    677 }
    678 
    679 void UIMachineView::storeConsoleSize(int iWidth, int iHeight)
    680 {
    681     if (m_desktopGeometryType == DesktopGeo_Automatic)
    682         m_storedConsoleSize = QSize(iWidth, iHeight);
     676            AssertMsgFailed(("Invalid maximum guest size policy %d\n",
     677                             policy));
     678            m_maxGuestSizePolicy = MaxGuestSizePolicy_Invalid;
     679    }
     680}
     681
     682void UIMachineView::storeHintForGuestSizePolicy(int cWidth, int cHeight)
     683{
     684    if (m_maxGuestSizePolicy == MaxGuestSizePolicy_Automatic)
     685        m_storedGuestHintSize = QSize(cWidth, cHeight);
    683686}
    684687
     
    889892    session().GetConsole().GetDisplay().ResizeCompleted(screenId());
    890893
    891     /* We also recalculate the desktop geometry if this is determined
    892      * automatically. In fact, we only need this on the first resize,
    893      * but it is done every time to keep the code simpler. */
    894     calculateDesktopGeometry();
     894    /* We also recalculate the maximum guest size if necessary.  In fact we
     895     * only need this on the first resize, but it is done every time to keep
     896     * the code simpler. */
     897    calculateMaxGuestSize();
    895898
    896899    /* Emit a signal about guest was resized: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h

    r38987 r39021  
    4444public:
    4545
    46     /* Desktop geometry types: */
    47     enum DesktopGeo { DesktopGeo_Invalid = 0, DesktopGeo_Fixed, DesktopGeo_Automatic, DesktopGeo_Any };
     46    /** Policy for determining which guest resolutions we wish to
     47     * handle.  We also accept anything smaller than the current
     48     * resolution. */
     49    enum MaxGuestSizePolicy
     50    {
     51        /** Policy not set correctly. */
     52        MaxGuestSizePolicy_Invalid = 0,
     53        /** Anything up to a fixed size. */
     54        MaxGuestSizePolicy_Fixed,
     55        /** Anything up to available space on the host desktop. */
     56        MaxGuestSizePolicy_Automatic,
     57        /** We accept anything. */
     58        MaxGuestSizePolicy_Any
     59    };
    4860
    4961    /* Factory function to create machine-view: */
     
    123135    UIFrameBuffer* frameBuffer() const { return m_pFrameBuffer; }
    124136    const QPixmap& pauseShot() const { return m_pauseShot; }
    125     QSize storedConsoleSize() const { return m_storedConsoleSize; }
    126     DesktopGeo desktopGeometryType() const { return m_desktopGeometryType; }
    127     QSize desktopGeometry() const;
     137    /** Helper to retrieve the last non-fullscreen guest size hint
     138     * sent.  @note Currently unused. */
     139    QSize storedGuestHintSize() const { return m_storedGuestHintSize; }
     140    /** What policy are we currently applying for limiting guest
     141     * resolutions? */
     142    MaxGuestSizePolicy maxGuestSizePolicy() const
     143    { return m_maxGuestSizePolicy; }
     144    /** The maximum guest resolution which we currently wish to handle.
     145     * @note This must be safely called from another thread.
     146     * @todo So make it atomic.
     147     */
     148    QSize maxGuestSize() const;
     149    /** Retrieve the last non-fullscreen guest size hint (from extra data).
     150     */
    128151    QSize guestSizeHint();
    129152
    130153    /* Protected setters: */
    131     void setDesktopGeometry(DesktopGeo geometry, int iWidth, int iHeight);
    132     void storeConsoleSize(int iWidth, int iHeight);
     154    void setMaxGuestSizePolicy(MaxGuestSizePolicy policy, int cwMax,
     155                               int chMax);
     156    void storeHintForGuestSizePolicy(int cWidth, int cHeight);
    133157    void storeGuestSizeHint(const QSize &sizeHint);
    134158
     
    137161    virtual void takePauseShotSnapshot();
    138162    virtual void resetPauseShot() { m_pauseShot = QPixmap(); }
    139     virtual QRect workingArea() = 0;
    140     virtual void calculateDesktopGeometry() = 0;
     163    /** The available area on the current screen for application windows. */
     164    virtual QRect workingArea() const = 0;
     165    /** Calculate how big the guest desktop can be while still fitting on one
     166     * host screen. */
     167    virtual void calculateMaxGuestSize() = 0;
    141168    virtual void maybeRestrictMinimumSize() = 0;
    142169    virtual void updateSliders();
     
    176203    KMachineState m_previousState;
    177204
    178     DesktopGeo m_desktopGeometryType;
    179     QSize m_desktopGeometry;
    180     QSize m_storedConsoleSize;
     205    /** The policy for calculating the maximum guest resolution we wish to
     206     * support. */
     207    MaxGuestSizePolicy m_maxGuestSizePolicy;
     208    /** The maximum guest size for fixed size policy. */
     209    QSize m_fixedMaxGuestSize;
     210    /** The last guest size hint sent out, used for calculating the maximum
     211     * supported guest resolution. */
     212    QSize m_storedGuestHintSize;
    181213
    182214#ifdef VBOX_WITH_VIDEOHWACCEL
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineViewFullscreen.cpp

    r38992 r39021  
    9595void UIMachineViewFullscreen::sltDesktopResized()
    9696{
    97     /* If the desktop geometry is set automatically, this will update it: */
    98     calculateDesktopGeometry();
     97    /* Recalculate the maximum guest size if necessary. */
     98    calculateMaxGuestSize();
    9999}
    100100
     
    197197}
    198198
    199 QRect UIMachineViewFullscreen::workingArea()
     199QRect UIMachineViewFullscreen::workingArea() const
    200200{
    201201    /* Get corresponding screen: */
     
    205205}
    206206
    207 void UIMachineViewFullscreen::calculateDesktopGeometry()
     207void UIMachineViewFullscreen::calculateMaxGuestSize()
    208208{
    209209    /* This method should not get called until we have initially set up the desktop geometry type: */
    210     Assert((desktopGeometryType() != DesktopGeo_Invalid));
    211     /* If we are not doing automatic geometry calculation then there is nothing to do: */
    212     if (desktopGeometryType() == DesktopGeo_Automatic)
    213         m_desktopGeometry = workingArea().size();
     210    Assert((maxGuestSizePolicy() != MaxGuestSizePolicy_Invalid));
     211    /* If we are not doing automatic adjustment then there is nothing to do. */
     212    if (maxGuestSizePolicy() == MaxGuestSizePolicy_Automatic)
     213        m_fixedMaxGuestSize = workingArea().size();
    214214}
    215215
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineViewFullscreen.h

    r38978 r39021  
    7070    /* Private helpers: */
    7171    void normalizeGeometry(bool /* fAdjustPosition */) {}
    72     QRect workingArea();
    73     void calculateDesktopGeometry();
     72    QRect workingArea() const;
     73    void calculateMaxGuestSize();
    7474    void maybeRestrictMinimumSize();
    7575
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.cpp

    r38993 r39021  
    9898void UIMachineViewNormal::sltDesktopResized()
    9999{
    100     /* If the desktop geometry is set automatically, this will update it: */
    101     calculateDesktopGeometry();
     100    /* Recalculate the maximum guest size if necessary. */
     101    calculateMaxGuestSize();
    102102}
    103103
     
    297297}
    298298
    299 QRect UIMachineViewNormal::workingArea()
     299QRect UIMachineViewNormal::workingArea() const
    300300{
    301301    return QApplication::desktop()->availableGeometry(this);
    302302}
    303303
    304 void UIMachineViewNormal::calculateDesktopGeometry()
    305 {
    306     /* This method should not get called until we have initially set up the desktop geometry type: */
    307     Assert((desktopGeometryType() != DesktopGeo_Invalid));
    308     /* If we are not doing automatic geometry calculation then there is nothing to do: */
    309     if (desktopGeometryType() == DesktopGeo_Automatic)
     304void UIMachineViewNormal::calculateMaxGuestSize()
     305{
     306    /* This method should not get called until we have initially set up the
     307     * maximum guest size policy. */
     308    Assert((maxGuestSizePolicy() != MaxGuestSizePolicy_Invalid));
     309    /* If we are not doing automatic adjustment then there is nothing to do. */
     310    if (maxGuestSizePolicy() == MaxGuestSizePolicy_Automatic)
    310311    {
    311312        /* The area taken up by the machine window on the desktop,
     
    318319         * This works because the difference between machine window and machine central widget
    319320         * (or at least its width and height) is a constant. */
    320         m_desktopGeometry = QSize(workingArea().width() - (windowGeo.width() - centralWidgetGeo.width()),
    321                                   workingArea().height() - (windowGeo.height() - centralWidgetGeo.height()));
     321        m_fixedMaxGuestSize = QSize(  workingArea().width()
     322                                    - (windowGeo.width()
     323                                    - centralWidgetGeo.width()),
     324                                      workingArea().height()
     325                                    - (windowGeo.height()
     326                                    - centralWidgetGeo.height()));
    322327    }
    323328}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.h

    r38978 r39021  
    7979    /* Private helpers: */
    8080    void normalizeGeometry(bool fAdjustPosition);
    81     QRect workingArea();
    82     void calculateDesktopGeometry();
     81    QRect workingArea() const;
     82    void calculateMaxGuestSize();
    8383    void maybeRestrictMinimumSize();
    8484
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineViewScale.cpp

    r38992 r39021  
    154154void UIMachineViewScale::sltDesktopResized()
    155155{
    156     /* If the desktop geometry is set automatically, this will update it: */
    157     calculateDesktopGeometry();
     156    /* Recalculate the maximum guest size if necessary. */
     157    calculateMaxGuestSize();
    158158}
    159159
     
    186186            session().GetConsole().GetDisplay().ResizeCompleted(screenId());
    187187
    188             /* We also recalculate the desktop geometry if this is determined
    189              * automatically.  In fact, we only need this on the first resize,
    190              * but it is done every time to keep the code simpler. */
    191             calculateDesktopGeometry();
     188            /* We also recalculate the maximum guest size if necessary.  In
     189             * fact we only need this on the first resize, but it is done
     190             * every time to keep the code simpler. */
     191            calculateMaxGuestSize();
    192192
    193193            /* Emit a signal about guest was resized: */
     
    363363}
    364364
    365 QRect UIMachineViewScale::workingArea()
     365QRect UIMachineViewScale::workingArea() const
    366366{
    367367    return QApplication::desktop()->availableGeometry(this);
    368368}
    369369
    370 void UIMachineViewScale::calculateDesktopGeometry()
    371 {
    372     /* This method should not get called until we have initially set up the desktop geometry type: */
    373     Assert((desktopGeometryType() != DesktopGeo_Invalid));
    374     /* If we are not doing automatic geometry calculation then there is nothing to do: */
    375     if (desktopGeometryType() == DesktopGeo_Automatic)
     370void UIMachineViewScale::calculateMaxGuestSize()
     371{
     372    /* This method should not get called until we have initially set up the
     373     * maximum guest size policy. */
     374    Assert((maxGuestSizePolicy() != MaxGuestSizePolicy_Invalid));
     375    /* If we are not doing automatic adjustment then there is nothing to do. */
     376    if (maxGuestSizePolicy() == MaxGuestSizePolicy_Automatic)
    376377    {
    377378        /* The area taken up by the machine window on the desktop,
     
    384385         * This works because the difference between machine window and machine central widget
    385386         * (or at least its width and height) is a constant. */
    386         m_desktopGeometry = QSize(workingArea().width() - (windowGeo.width() - centralWidgetGeo.width()),
    387                                   workingArea().height() - (windowGeo.height() - centralWidgetGeo.height()));
     387        m_fixedMaxGuestSize = QSize(  workingArea().width()
     388                                    - (windowGeo.width()
     389                                    - centralWidgetGeo.width()),
     390                                      workingArea().height()
     391                                    - (windowGeo.height()
     392                                    - centralWidgetGeo.height()));
    388393    }
    389394}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineViewScale.h

    r38962 r39021  
    7171    QSize sizeHint() const;
    7272    void normalizeGeometry(bool /* fAdjustPosition */) {}
    73     QRect workingArea();
    74     void calculateDesktopGeometry();
     73    QRect workingArea() const;
     74    void calculateMaxGuestSize();
    7575    void maybeRestrictMinimumSize() {}
    7676    void updateSliders();
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.cpp

    r38992 r39021  
    9696void UIMachineViewSeamless::sltDesktopResized()
    9797{
    98     // TODO: Try to resize framebuffer according new desktop size, exit seamless if resize is failed!
    99 
    100     /* If the desktop geometry is set automatically, this will update it: */
    101     calculateDesktopGeometry();
     98    /** @todo Try to resize framebuffer according new desktop size,
     99     *        exit seamless if resize is failed! */
     100    /** @todo Check whether this isn't already fixed elsewhere.
     101     *        I don't think that it is the GUI's job to check that
     102     *        the resize succeeded though. */
     103
     104    /* Recalculate the maximum guest size if necessary. */
     105    calculateMaxGuestSize();
    102106}
    103107
     
    215219}
    216220
    217 QRect UIMachineViewSeamless::workingArea()
     221QRect UIMachineViewSeamless::workingArea() const
    218222{
    219223    /* Get corresponding screen: */
     
    223227}
    224228
    225 void UIMachineViewSeamless::calculateDesktopGeometry()
     229void UIMachineViewSeamless::calculateMaxGuestSize()
    226230{
    227231    /* This method should not get called until we have initially set up the desktop geometry type: */
    228     Assert((desktopGeometryType() != DesktopGeo_Invalid));
    229     /* If we are not doing automatic geometry calculation then there is nothing to do: */
    230     if (desktopGeometryType() == DesktopGeo_Automatic)
    231         m_desktopGeometry = workingArea().size();
    232 }
    233 
     232    Assert((maxGuestSizePolicy() != MaxGuestSizePolicy_Invalid));
     233    /* If we are not doing automatic adjustment then there is nothing to do. */
     234    if (maxGuestSizePolicy() == MaxGuestSizePolicy_Automatic)
     235        m_fixedMaxGuestSize = workingArea().size();
     236}
     237
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.h

    r38978 r39021  
    7474    /* Private helpers: */
    7575    void normalizeGeometry(bool /* fAdjustPosition */) {}
    76     QRect workingArea();
    77     void calculateDesktopGeometry();
     76    QRect workingArea() const;
     77    void calculateMaxGuestSize();
    7878    void maybeRestrictMinimumSize() {}
    7979
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