VirtualBox

Changeset 38947 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Oct 5, 2011 8:22:07 PM (13 years ago)
Author:
vboxsync
Message:

FE/Qt: refactor a slot into UIMachineView to avoid changing it in three places

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

Legend:

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

    r38505 r38947  
    2020/* Global includes */
    2121#include <QDesktopWidget>
     22#include <QMainWindow>
    2223#include <QTimer>
    2324#include <QPainter>
     
    145146}
    146147
     148void UIMachineView::sltPerformGuestResize(const QSize &toSize)
     149{
     150    /* Get machine window: */
     151    QMainWindow *pMachineWindow = machineWindowWrapper() && machineWindowWrapper()->machineWindow() ?
     152                                  qobject_cast<QMainWindow*>(machineWindowWrapper()->machineWindow()) : 0;
     153
     154    /* If this slot is invoked directly then use the passed size otherwise get
     155     * the available size for the guest display. We assume here that centralWidget()
     156     * contains this view only and gives it all available space: */
     157    QSize newSize(toSize.isValid() ? toSize : pMachineWindow ? pMachineWindow->centralWidget()->size() : QSize());
     158    AssertMsg(newSize.isValid(), ("Size should be valid!\n"));
     159
     160    /* Do not send the same hints as we already have: */
     161    if ((newSize.width() == storedConsoleSize().width()) && (newSize.height() == storedConsoleSize().height()))
     162        return;
     163
     164    /* We only actually send the hint if either an explicit new size was given
     165     * (e.g. if the request was triggered directly by a console resize event) or
     166     * if no explicit size was specified but a resize is flagged as being needed
     167     * (e.g. the autoresize was just enabled and the console was resized while it was disabled). */
     168    if (toSize.isValid() || m_fShouldWeDoResize)
     169    {
     170        /* Remember the new size: */
     171        storeConsoleSize(newSize.width(), newSize.height());
     172
     173        /* Send new size-hint to the guest: */
     174        session().GetConsole().GetDisplay().SetVideoModeHint(newSize.width(), newSize.height(), 0, screenId());
     175    }
     176
     177    /* We had requested resize now, rejecting other accident requests: */
     178    m_fShouldWeDoResize = false;
     179}
     180
    147181void UIMachineView::sltMachineStateChanged()
    148182{
     
    215249    , m_desktopGeometryType(DesktopGeo_Invalid)
    216250    , m_bIsMachineWindowResizeIgnored(false)
     251    , m_fShouldWeDoResize(false)
    217252#ifdef VBOX_WITH_VIDEOHWACCEL
    218253    , m_fAccelerate2DVideo(bAccelerate2DVideo)
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h

    r35247 r38947  
    7373
    7474protected slots:
     75
     76    /* Slot to perform guest resize: */
     77    void sltPerformGuestResize(const QSize &aSize = QSize());
    7578
    7679    /* Console callback handlers: */
     
    166169#endif
    167170
    168     /* Private members: */
     171    /* Protected members: */
    169172    UIMachineWindow *m_pMachineWindow;
    170173    ulong m_uScreenId;
     
    177180
    178181    bool m_bIsMachineWindowResizeIgnored : 1;
     182    bool m_fShouldWeDoResize : 1;
    179183#ifdef VBOX_WITH_VIDEOHWACCEL
    180184    bool m_fAccelerate2DVideo : 1;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineViewFullscreen.cpp

    r38348 r38947  
    5252                    )
    5353    , m_bIsGuestAutoresizeEnabled(gActionPool->action(UIActionIndexRuntime_Toggle_GuestAutoresize)->isChecked())
    54     , m_fShouldWeDoResize(false)
    5554    , m_pSyncBlocker(0)
    5655{
     
    8988}
    9089
    91 void UIMachineViewFullscreen::sltPerformGuestResize(const QSize &toSize)
    92 {
    93     if (m_bIsGuestAutoresizeEnabled && uisession()->isGuestSupportsGraphics())
    94     {
    95         /* Get machine window: */
    96         QMainWindow *pMachineWindow = machineWindowWrapper() && machineWindowWrapper()->machineWindow() ?
    97                                       qobject_cast<QMainWindow*>(machineWindowWrapper()->machineWindow()) : 0;
    98 
    99         /* If this slot is invoked directly then use the passed size otherwise get
    100          * the available size for the guest display. We assume here that centralWidget()
    101          * contains this view only and gives it all available space: */
    102         QSize newSize(toSize.isValid() ? toSize : pMachineWindow ? pMachineWindow->centralWidget()->size() : QSize());
    103         AssertMsg(newSize.isValid(), ("Size should be valid!\n"));
    104 
    105         /* Do not send the same hints as we already have: */
    106         if ((newSize.width() == storedConsoleSize().width()) && (newSize.height() == storedConsoleSize().height()))
    107             return;
    108 
    109         /* We only actually send the hint if either an explicit new size was given
    110          * (e.g. if the request was triggered directly by a console resize event) or
    111          * if no explicit size was specified but a resize is flagged as being needed
    112          * (e.g. the autoresize was just enabled and the console was resized while it was disabled). */
    113         if (toSize.isValid() || m_fShouldWeDoResize)
    114         {
    115             /* Remember the new size: */
    116             storeConsoleSize(newSize.width(), newSize.height());
    117 
    118             /* Send new size-hint to the guest: */
    119             session().GetConsole().GetDisplay().SetVideoModeHint(newSize.width(), newSize.height(), 0, screenId());
    120         }
    121 
    122         /* We had requested resize now, rejecting other accident requests: */
    123         m_fShouldWeDoResize = false;
    124     }
    125 }
    126 
    12790void UIMachineViewFullscreen::sltAdditionsStateChanged()
    12891{
     
    13093    maybeRestrictMinimumSize();
    13194
    132     /* Check if we should resize guest to fullscreen, all the
    133      * required features will be tested in sltPerformGuestResize(...): */
     95    /* Check if we should resize guest to fullscreen */
    13496    if ((int)frameBuffer()->width() != workingArea().size().width() ||
    13597        (int)frameBuffer()->height() != workingArea().size().height())
    136         sltPerformGuestResize(workingArea().size());
     98        if (m_bIsGuestAutoresizeEnabled && uisession()->isGuestSupportsGraphics())
     99            sltPerformGuestResize(workingArea().size());
    137100}
    138101
     
    321284        maybeRestrictMinimumSize();
    322285
    323         sltPerformGuestResize();
     286        if (uisession()->isGuestSupportsGraphics())
     287            sltPerformGuestResize();
    324288    }
    325289}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineViewFullscreen.h

    r30544 r38947  
    4141private slots:
    4242
    43     /* Slot to perform guest resize: */
    44     void sltPerformGuestResize(const QSize &aSize = QSize());
    45 
    4643    /* Console callback handlers: */
    4744    void sltAdditionsStateChanged();
     
    8178    /* Private variables: */
    8279    bool m_bIsGuestAutoresizeEnabled : 1;
    83     bool m_fShouldWeDoResize : 1;
    8480    UIMachineViewBlocker *m_pSyncBlocker;
    8581
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.cpp

    r38348 r38947  
    4848                    )
    4949    , m_bIsGuestAutoresizeEnabled(gActionPool->action(UIActionIndexRuntime_Toggle_GuestAutoresize)->isChecked())
    50     , m_fShouldWeDoResize(false)
    5150{
    5251    /* Load machine view settings: */
     
    8382    /* Cleanup frame buffer: */
    8483    cleanupFrameBuffer();
    85 }
    86 
    87 void UIMachineViewNormal::sltPerformGuestResize(const QSize &toSize)
    88 {
    89     if (m_bIsGuestAutoresizeEnabled && uisession()->isGuestSupportsGraphics())
    90     {
    91         /* Get machine window: */
    92         QMainWindow *pMachineWindow = machineWindowWrapper() && machineWindowWrapper()->machineWindow() ?
    93                                       qobject_cast<QMainWindow*>(machineWindowWrapper()->machineWindow()) : 0;
    94 
    95         /* If this slot is invoked directly then use the passed size otherwise get
    96          * the available size for the guest display. We assume here that centralWidget()
    97          * contains this view only and gives it all available space: */
    98         QSize newSize(toSize.isValid() ? toSize : pMachineWindow ? pMachineWindow->centralWidget()->size() : QSize());
    99         AssertMsg(newSize.isValid(), ("Size should be valid!\n"));
    100 
    101         /* Do not send the same hints as we already have: */
    102         if ((newSize.width() == storedConsoleSize().width()) && (newSize.height() == storedConsoleSize().height()))
    103             return;
    104 
    105         /* We only actually send the hint if either an explicit new size was given
    106          * (e.g. if the request was triggered directly by a console resize event) or
    107          * if no explicit size was specified but a resize is flagged as being needed
    108          * (e.g. the autoresize was just enabled and the console was resized while it was disabled). */
    109         if (toSize.isValid() || m_fShouldWeDoResize)
    110         {
    111             /* Remember the new size: */
    112             storeConsoleSize(newSize.width(), newSize.height());
    113 
    114             /* Send new size-hint to the guest: */
    115             session().GetConsole().GetDisplay().SetVideoModeHint(newSize.width(), newSize.height(), 0, screenId());
    116         }
    117 
    118         /* We had requested resize now, rejecting other accident requests: */
    119         m_fShouldWeDoResize = false;
    120     }
    12184}
    12285
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.h

    r30547 r38947  
    4040
    4141private slots:
    42 
    43     /* Slot to perform guest resize: */
    44     void sltPerformGuestResize(const QSize &size = QSize());
    4542
    4643    /* Console callback handlers: */
     
    8784    /* Private members: */
    8885    bool m_bIsGuestAutoresizeEnabled : 1;
    89     bool m_fShouldWeDoResize : 1;
    9086
    9187    /* Friend classes: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.cpp

    r32174 r38947  
    5050#endif
    5151                    )
    52     , m_fShouldWeDoResize(false)
    5352    , m_pSyncBlocker(0)
    5453{
     
    8988    /* Cleanup frame buffer: */
    9089    cleanupFrameBuffer();
    91 }
    92 
    93 void UIMachineViewSeamless::sltPerformGuestResize(const QSize &toSize)
    94 {
    95     if (uisession()->isGuestSupportsGraphics())
    96     {
    97         /* Get machine window: */
    98         QMainWindow *pMachineWindow = machineWindowWrapper() && machineWindowWrapper()->machineWindow() ?
    99                                       qobject_cast<QMainWindow*>(machineWindowWrapper()->machineWindow()) : 0;
    100 
    101         /* If this slot is invoked directly then use the passed size otherwise get
    102          * the available size for the guest display. We assume here that centralWidget()
    103          * contains this view only and gives it all available space: */
    104         QSize newSize(toSize.isValid() ? toSize : pMachineWindow ? pMachineWindow->centralWidget()->size() : QSize());
    105         AssertMsg(newSize.isValid(), ("Size should be valid!\n"));
    106 
    107         /* Do not send the same hints as we already have: */
    108         if ((newSize.width() == storedConsoleSize().width()) && (newSize.height() == storedConsoleSize().height()))
    109             return;
    110 
    111         /* We only actually send the hint if either an explicit new size was given
    112          * (e.g. if the request was triggered directly by a console resize event) or
    113          * if no explicit size was specified but a resize is flagged as being needed
    114          * (e.g. the autoresize was just enabled and the console was resized while it was disabled). */
    115         if (toSize.isValid() || m_fShouldWeDoResize)
    116         {
    117             /* Remember the new size: */
    118             storeConsoleSize(newSize.width(), newSize.height());
    119 
    120             /* Send new size-hint to the guest: */
    121             session().GetConsole().GetDisplay().SetVideoModeHint(newSize.width(), newSize.height(), 0, screenId());
    122         }
    123 
    124         /* We had requested resize now, rejecting other accident requests: */
    125         m_fShouldWeDoResize = false;
    126     }
    12790}
    12891
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.h

    r30545 r38947  
    4646private slots:
    4747
    48     /* Slot to perform guest resize: */
    49     void sltPerformGuestResize(const QSize &aSize = QSize());
    50 
    5148    /* Console callback handlers: */
    5249    void sltAdditionsStateChanged();
     
    8279
    8380    /* Private variables: */
    84     bool m_fShouldWeDoResize : 1;
    8581    QRegion m_lastVisibleRegion;
    8682    UIMachineViewBlocker *m_pSyncBlocker;
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