VirtualBox

Ignore:
Timestamp:
Oct 13, 2014 1:38:17 PM (10 years ago)
Author:
vboxsync
Message:

FE/Qt: Runtime UI rework/cleanup for 7115 (part #15): Better encapsulation for UIMachine (part #5): Get rid of UIVisualState.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r52820 r53041  
    490490        src/runtime/UIActionPoolRuntime.cpp \
    491491        src/runtime/UIIndicatorsPool.cpp \
    492         src/runtime/UIMachine.cpp \
    493492        src/runtime/UIMenuBarEditorWindow.cpp \
    494493        src/runtime/UIStatusBarEditorWindow.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp

    r53040 r53041  
    3939#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    4040
    41 
    42 /* Visual state interface: */
    43 class UIVisualState : public QObject
    44 {
    45     Q_OBJECT;
    46 
    47 public:
    48 
    49     /* Constructor: */
    50     UIVisualState(QObject *pParent, UISession *pSession, UIVisualStateType type)
    51         : QObject(pParent)
    52         , m_type(type)
    53         , m_pSession(pSession)
    54         , m_pMachineLogic(0)
    55     {
    56     }
    57 
    58     /* Destructor: */
    59     ~UIVisualState()
    60     {
    61         /* Cleanup/delete machine logic if exists: */
    62         if (m_pMachineLogic)
    63         {
    64             /* Cleanup the logic object: */
    65             m_pMachineLogic->cleanup();
    66             /* Destroy the logic object: */
    67             UIMachineLogic::destroy(m_pMachineLogic);
    68         }
    69     }
    70 
    71     /* Visual state type getter: */
    72     UIVisualStateType visualStateType() const { return m_type; }
    73 
    74     /* Machine logic getter: */
    75     UIMachineLogic* machineLogic() const { return m_pMachineLogic; }
    76 
    77     /* Method to prepare change one visual state to another: */
    78     bool prepareChange()
    79     {
    80         m_pMachineLogic = UIMachineLogic::create(this, m_pSession, visualStateType());
    81         return m_pMachineLogic->checkAvailability();
    82     }
    83 
    84     /* Method to change one visual state to another: */
    85     void change()
    86     {
    87         /* Prepare the logic object: */
    88         m_pMachineLogic->prepare();
    89     }
    90 
    91 protected:
    92 
    93     /* Variables: */
    94     UIVisualStateType m_type;
    95     UISession *m_pSession;
    96     UIMachineLogic *m_pMachineLogic;
    97 };
    98 
    9941/* static */
    10042UIMachine* UIMachine::m_spInstance = 0;
     
    188130}
    189131
    190 UIMachineLogic* UIMachine::machineLogic() const
    191 {
    192     if (m_pVisualState && m_pVisualState->machineLogic())
    193         return m_pVisualState->machineLogic();
    194     return 0;
    195 }
    196 
    197132QWidget* UIMachine::activeWindow() const
    198133{
     
    202137}
    203138
    204 void UIMachine::asyncChangeVisualState(UIVisualStateType visualStateType)
    205 {
    206     emit sigRequestAsyncVisualStateChange(visualStateType);
    207 }
    208 
    209 void UIMachine::sltChangeVisualState(UIVisualStateType newVisualStateType)
    210 {
    211     /* Create new state: */
    212     UIVisualState *pNewVisualState = new UIVisualState(this, m_pSession, newVisualStateType);
    213 
    214     /* First we have to check if the selected mode is available at all.
    215      * Only then we delete the old mode and switch to the new mode. */
    216     if (pNewVisualState->prepareChange())
    217     {
    218         /* Delete previous state: */
    219         delete m_pVisualState;
    220 
    221         /* Set the new mode as current mode: */
    222         m_pVisualState = pNewVisualState;
    223         m_pVisualState->change();
     139void UIMachine::asyncChangeVisualState(UIVisualStateType visualState)
     140{
     141    emit sigRequestAsyncVisualStateChange(visualState);
     142}
     143
     144void UIMachine::sltChangeVisualState(UIVisualStateType visualState)
     145{
     146    /* Create new machine-logic: */
     147    UIMachineLogic *pMachineLogic = UIMachineLogic::create(this, m_pSession, visualState);
     148
     149    /* First we have to check if the selected machine-logic is available at all.
     150     * Only then we delete the old machine-logic and switch to the new one. */
     151    if (pMachineLogic->checkAvailability())
     152    {
     153        /* Delete previous machine-logic if exists: */
     154        if (m_pMachineLogic)
     155        {
     156            m_pMachineLogic->cleanup();
     157            UIMachineLogic::destroy(m_pMachineLogic);
     158        }
     159
     160        /* Set the new machine-logic as current one: */
     161        m_pMachineLogic = pMachineLogic;
     162        m_pMachineLogic->prepare();
     163
     164        /* Remember new visual state: */
     165        m_visualState = visualState;
    224166    }
    225167    else
    226168    {
    227         /* Discard the temporary created new state: */
    228         delete pNewVisualState;
    229 
    230         /* If there is no state currently created => we have to exit: */
    231         if (!m_pVisualState)
    232             deleteLater();
     169        /* Delete temporary created machine-logic: */
     170        pMachineLogic->cleanup();
     171        UIMachineLogic::destroy(pMachineLogic);
     172    }
     173
     174    /* Make sure machine-logic exists: */
     175    if (!m_pMachineLogic)
     176    {
     177        /* Reset initial visual state  to normal: */
     178        m_initialVisualState = UIVisualStateType_Normal;
     179        /* Enter initial visual state again: */
     180        enterInitialVisualState();
    233181    }
    234182}
     
    238186    , m_pSession(0)
    239187    , m_allowedVisualStates(UIVisualStateType_Invalid)
    240     , m_initialStateType(UIVisualStateType_Normal)
    241     , m_pVisualState(0)
     188    , m_initialVisualState(UIVisualStateType_Normal)
     189    , m_visualState(UIVisualStateType_Invalid)
     190    , m_pMachineLogic(0)
    242191{
    243192    m_spInstance = this;
     
    261210    vboxGlobal().startMediumEnumeration(false /* force start */);
    262211
    263     /* Prepare visual state: */
    264     prepareVisualState();
     212    /* Prepare machine-logic: */
     213    prepareMachineLogic();
    265214
    266215    /* Now power up the machine.
     
    287236}
    288237
    289 void UIMachine::prepareVisualState()
     238void UIMachine::prepareMachineLogic()
    290239{
    291240    /* Prepare async visual state type change handler: */
     
    308257        {
    309258            /* Direct transition to scale/fullscreen mode allowed: */
    310             case UIVisualStateType_Scale:      m_initialStateType = UIVisualStateType_Scale; break;
    311             case UIVisualStateType_Fullscreen: m_initialStateType = UIVisualStateType_Fullscreen; break;
     259            case UIVisualStateType_Scale:      m_initialVisualState = UIVisualStateType_Scale; break;
     260            case UIVisualStateType_Fullscreen: m_initialVisualState = UIVisualStateType_Fullscreen; break;
    312261            /* While to seamless is not, so we have to make request to do transition later: */
    313262            case UIVisualStateType_Seamless:   uisession()->setRequestedVisualState(UIVisualStateType_Seamless); break;
     
    320269}
    321270
    322 void UIMachine::cleanupVisualState()
     271void UIMachine::cleanupMachineLogic()
    323272{
    324273    /* Session UI can have requested visual state: */
     
    327276        /* Get requested visual state: */
    328277        UIVisualStateType requestedVisualState = uisession()->requestedVisualState();
    329         /* If requested state is invalid: */
     278        /* Or current visual state if requested is invalid: */
    330279        if (requestedVisualState == UIVisualStateType_Invalid)
    331         {
    332             /* Get current if still exists or normal otherwise: */
    333             requestedVisualState = m_pVisualState ? m_pVisualState->visualStateType() : UIVisualStateType_Normal;
    334         }
     280            requestedVisualState = m_visualState;
    335281
    336282        /* Save requested visual state: */
     
    338284    }
    339285
    340     /* Delete visual state: */
    341     delete m_pVisualState;
    342     m_pVisualState = 0;
     286    /* Destroy machine-logic if exists: */
     287    if (machineLogic())
     288    {
     289        m_pMachineLogic->cleanup();
     290        UIMachineLogic::destroy(m_pMachineLogic);
     291    }
    343292}
    344293
    345294void UIMachine::cleanupSession()
    346295{
    347     /* Destroy session UI if necessary: */
     296    /* Destroy session UI if exists: */
    348297    if (uisession())
    349298        UISession::destroy(m_pSession);
     
    352301void UIMachine::cleanup()
    353302{
    354     /* Cleanup visual state: */
    355     cleanupVisualState();
     303    /* Cleanup machine-logic: */
     304    cleanupMachineLogic();
    356305
    357306    /* Cleanup session UI: */
     
    364313void UIMachine::enterInitialVisualState()
    365314{
    366     sltChangeVisualState(m_initialStateType);
     315    sltChangeVisualState(m_initialVisualState);
    367316}
    368317
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h

    r53040 r53041  
    3131class QWidget;
    3232class UISession;
    33 class UIVisualState;
    3433class UIMachineLogic;
    3534
     
    5756    static UIMachine* instance() { return m_spInstance; }
    5857
    59     /** Returns UI session instance. */
     58    /** Returns session UI instance. */
    6059    UISession *uisession() const { return m_pSession; }
    61     /** Returns machine-logic reference (if possible). */
    62     UIMachineLogic* machineLogic() const;
     60    /** Returns machine-logic instance. */
     61    UIMachineLogic* machineLogic() const { return m_pMachineLogic; }
    6362    /** Returns active machine-window reference (if possible). */
    6463    QWidget* activeWindow() const;
     
    8685    /** Prepare routine: Session stuff. */
    8786    bool prepareSession();
    88     /** Prepare routine: Visual state stuff. */
    89     void prepareVisualState();
     87    /** Prepare routine: Machine-logic stuff. */
     88    void prepareMachineLogic();
    9089
    91     /** Cleanup routine: Visual state stuff. */
    92     void cleanupVisualState();
     90    /** Cleanup routine: Machine-logic stuff. */
     91    void cleanupMachineLogic();
    9392    /** Cleanup routine: Session stuff. */
    9493    void cleanupSession();
     
    9695    void cleanup();
    9796
    98     /** Moves VM to default (normal) state. */
     97    /** Moves VM to initial state. */
    9998    void enterInitialVisualState();
    10099
     
    105104    UISession *m_pSession;
    106105
    107     /** Holds allowed visual state types. */
     106    /** Holds allowed visual states. */
    108107    UIVisualStateType m_allowedVisualStates;
    109     /** Holds initial visual state type. */
    110     UIVisualStateType m_initialStateType;
     108    /** Holds initial visual state. */
     109    UIVisualStateType m_initialVisualState;
    111110    /** Holds current visual state. */
    112     UIVisualState *m_pVisualState;
     111    UIVisualStateType m_visualState;
     112    /** Holds current machine-logic. */
     113    UIMachineLogic *m_pMachineLogic;
    113114};
    114115
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