VirtualBox

Ignore:
Timestamp:
May 7, 2013 5:16:31 PM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: Popup-center: Support for visual-representation mode change; Popup-stack: Layout tuning.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIPopupCenter.cpp

    r45696 r45939  
    2121#include "UIPopupCenter.h"
    2222#include "UIPopupStack.h"
     23#include "UIMachineWindow.h"
    2324#include "QIMessageBox.h"
    2425#include "VBoxGlobal.h"
     
    4950        return;
    5051
     52    /* Cleanup instance: */
     53    m_spInstance->cleanup();
    5154    /* Destroy instance: */
    5255    delete m_spInstance;
     
    6366    /* Unassign instance: */
    6467    m_spInstance = 0;
     68}
     69
     70void UIPopupCenter::cleanup()
     71{
     72    /* Make sure all the popup-stacks destroyed: */
     73    foreach (const QString &strPopupStackID, m_stacks.keys())
     74    {
     75        delete m_stacks[strPopupStackID];
     76        m_stacks.remove(strPopupStackID);
     77    }
    6578}
    6679
     
    162175
    163176    /* Looking for the corresponding popup-stack: */
    164     QString strPopupStackID = pParent->metaObject()->className();
     177    const QString strPopupStackID(popupStackID(pParent));
    165178    UIPopupStack *pPopupStack = 0;
    166179    /* Is there already popup-stack with the same ID? */
     
    174187    {
    175188        /* Create new one: */
    176         pPopupStack = m_stacks[strPopupStackID] = new UIPopupStack(pParent);
     189        pPopupStack = m_stacks[strPopupStackID] = new UIPopupStack;
    177190        /* Attach popup-stack connections: */
    178191        connect(pPopupStack, SIGNAL(sigPopupPaneDone(QString, int)), this, SLOT(sltPopupPaneDone(QString, int)));
    179192        connect(pPopupStack, SIGNAL(sigRemove()), this, SLOT(sltRemovePopupStack()));
    180193        /* Show popup-stack: */
    181         pPopupStack->show();
     194        showPopupStack(pParent);
    182195    }
    183196
     
    202215}
    203216
     217void UIPopupCenter::showPopupStack(QWidget *pParent)
     218{
     219    /* Make sure passed parent is valid: */
     220    if (!pParent)
     221    {
     222        AssertMsgFailed(("Passed parent is NULL"));
     223        return;
     224    }
     225
     226    /* Do we have a stack for passed parent? */
     227    const QString strPopupStackID(popupStackID(pParent));
     228    if (!m_stacks.contains(strPopupStackID))
     229        return;
     230
     231    /* Install stack to passed parent: */
     232    UIPopupStack *pPopupStack = m_stacks[strPopupStackID];
     233    pParent->installEventFilter(pPopupStack);
     234    pPopupStack->setParent(pParent);
     235    pPopupStack->show();
     236}
     237
     238void UIPopupCenter::hidePopupStack(QWidget *pParent)
     239{
     240    /* Make sure passed parent is valid: */
     241    if (!pParent)
     242    {
     243        AssertMsgFailed(("Passed parent is NULL"));
     244        return;
     245    }
     246
     247    /* Do we have a stack for passed parent? */
     248    const QString strPopupStackID(popupStackID(pParent));
     249    if (!m_stacks.contains(strPopupStackID))
     250        return;
     251
     252    /* Uninstall stack from passed parent: */
     253    UIPopupStack *pPopupStack = m_stacks[strPopupStackID];
     254    pPopupStack->hide();
     255    pPopupStack->setParent(0);
     256    pParent->removeEventFilter(pPopupStack);
     257}
     258
    204259void UIPopupCenter::sltPopupPaneDone(QString strPopupPaneID, int iResultCode)
    205260{
     
    217272}
    218273
     274void UIPopupCenter::sltShowPopupStack()
     275{
     276    showPopupStack(vboxGlobal().activeMachineWindow());
     277}
     278
     279void UIPopupCenter::sltHidePopupStack()
     280{
     281    hidePopupStack(vboxGlobal().activeMachineWindow());
     282}
     283
    219284void UIPopupCenter::sltRemovePopupStack()
    220285{
     
    238303    m_stacks.remove(strPopupStackID);
    239304    delete pPopupStack;
     305}
     306
     307/* static */
     308QString UIPopupCenter::popupStackID(QWidget *pParent)
     309{
     310    /* Make sure passed parent is always valid: */
     311    if (!pParent)
     312    {
     313        AssertMsgFailed(("Passed parent is NULL"));
     314        return QString();
     315    }
     316
     317    /* Special handling for Runtime UI: */
     318    if (qobject_cast<UIMachineWindow*>(pParent))
     319        return QString("UIMachineWindow");
     320
     321    /* Common handling for other cases: */
     322    return pParent->metaObject()->className();
    240323}
    241324
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIPopupCenter.h

    r45696 r45939  
    9393    void sltPopupPaneDone(QString strPopupPaneID, int iResultCode);
    9494
    95     /* Handler: Popup-stack stuff: */
     95    /* Handlers: Popup-stack stuff: */
     96    void sltShowPopupStack();
     97    void sltHidePopupStack();
    9698    void sltRemovePopupStack();
    9799
     
    102104    ~UIPopupCenter();
    103105
     106    /* Helper: Cleanup stuff: */
     107    void cleanup();
     108
    104109    /* Helper: Popup-pane stuff: */
    105110    void showPopupPane(QWidget *pParent, const QString &strPopupPaneID,
     
    108113                       const QString &strButtonText1, const QString &strButtonText2,
    109114                       bool fProposeAutoConfirmation);
     115
     116    /* Helpers: Popup-stack stuff: */
     117    void showPopupStack(QWidget *pParent);
     118    void hidePopupStack(QWidget *pParent);
     119
     120    /* Static helper: Popup-stack stuff: */
     121    static QString popupStackID(QWidget *pParent);
    110122
    111123    /* Variable: Popup-stack stuff: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r45736 r45939  
    4747#include "VBoxGlobal.h"
    4848#include "UIMessageCenter.h"
     49#include "UIPopupCenter.h"
    4950#include "VBoxTakeSnapshotDlg.h"
    5051#include "VBoxVMInformationDlg.h"
     
    533534#endif /* Q_WS_MAC */
    534535{
     536    /* Register popup-center connections: */
     537    connect(this, SIGNAL(sigMachineWidnowsCreated()),
     538            &popupCenter(), SLOT(sltShowPopupStack()));
     539    connect(this, SIGNAL(sigMachineWidnowsDestroyed()),
     540            &popupCenter(), SLOT(sltHidePopupStack()));
     541}
     542
     543UIMachineLogic::~UIMachineLogic()
     544{
     545    /* Unregister popup-center connections: */
     546    disconnect(this, SIGNAL(sigMachineWidnowsCreated()),
     547               &popupCenter(), SLOT(sltShowPopupStack()));
     548    disconnect(this, SIGNAL(sigMachineWidnowsDestroyed()),
     549               &popupCenter(), SLOT(sltHidePopupStack()));
     550}
     551
     552void UIMachineLogic::setMachineWindowsCreated(bool fIsWindowsCreated)
     553{
     554    /* Make sure something changed: */
     555    if (m_fIsWindowsCreated == fIsWindowsCreated)
     556        return;
     557
     558    /* Special handling for 'destroyed' case: */
     559    if (!fIsWindowsCreated)
     560    {
     561        /* We emit this signal *before* the remembering new value
     562         * because we want UIMachineLogic::activeMachineWindow() to be yet alive. */
     563        emit sigMachineWidnowsDestroyed();
     564    }
     565
     566    /* Remember new value: */
     567    m_fIsWindowsCreated = fIsWindowsCreated;
     568
     569    /* Special handling for 'created' case: */
     570    if (fIsWindowsCreated)
     571    {
     572        /* We emit this signal *after* the remembering new value
     573         * because we want UIMachineLogic::activeMachineWindow() to be already alive. */
     574        emit sigMachineWidnowsCreated();
     575    }
    535576}
    536577
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h

    r45736 r45939  
    5353    Q_OBJECT;
    5454
     55signals:
     56
     57    /* Notifiers: Machine-window(s) stuff: */
     58    void sigMachineWidnowsCreated();
     59    void sigMachineWidnowsDestroyed();
     60
    5561public:
    5662
     
    112118protected:
    113119
    114     /* Constructor: */
     120    /* Constructor/destructor: */
    115121    UIMachineLogic(QObject *pParent, UISession *pSession, UIVisualStateType visualStateType);
     122    ~UIMachineLogic();
    116123
    117124    /* Protected getters/setters: */
    118125    bool isMachineWindowsCreated() const { return m_fIsWindowsCreated; }
    119     void setMachineWindowsCreated(bool fIsWindowsCreated) { m_fIsWindowsCreated = fIsWindowsCreated; }
     126    void setMachineWindowsCreated(bool fIsWindowsCreated);
    120127
    121128    /* Protected members: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp

    r45333 r45939  
    141141void UIMachineLogicFullscreen::prepareMachineWindows()
    142142{
    143     /* Do not create window(s) if they created already: */
     143    /* Do not create machine-window(s) if they created already: */
    144144    if (isMachineWindowsCreated())
    145145        return;
     
    151151#endif /* Q_WS_MAC */
    152152
    153     /* Update the multi screen layout: */
     153    /* Update the multi-screen layout: */
    154154    m_pScreenLayout->update();
    155155
    156     /* Create machine window(s): */
     156    /* Create machine-window(s): */
    157157    for (uint cScreenId = 0; cScreenId < session().GetMachine().GetMonitorCount(); ++cScreenId)
    158158        addMachineWindow(UIMachineWindow::create(this, cScreenId));
    159159
    160     /* Connect screen-layout change handler: */
     160    /* Connect multi-screen layout change handler: */
    161161    for (int i = 0; i < machineWindows().size(); ++i)
    162162        connect(m_pScreenLayout, SIGNAL(sigScreenLayoutChanged()),
     
    172172#endif /* Q_WS_MAC */
    173173
    174     /* Remember what machine window(s) created: */
     174    /* Mark machine-window(s) created: */
    175175    setMachineWindowsCreated(true);
    176176}
     
    187187void UIMachineLogicFullscreen::cleanupMachineWindows()
    188188{
    189     /* Do not cleanup machine window(s) if not present: */
     189    /* Do not destroy machine-window(s) if they destroyed already: */
    190190    if (!isMachineWindowsCreated())
    191191        return;
    192192
    193     /* Cleanup machine window(s): */
     193    /* Mark machine-window(s) destroyed: */
     194    setMachineWindowsCreated(false);
     195
     196    /* Cleanup machine-window(s): */
    194197    foreach (UIMachineWindow *pMachineWindow, machineWindows())
    195198        UIMachineWindow::destroy(pMachineWindow);
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp

    r41587 r45939  
    8686void UIMachineLogicNormal::prepareMachineWindows()
    8787{
    88     /* Do not create window(s) if they created already: */
     88    /* Do not create machine-window(s) if they created already: */
    8989    if (isMachineWindowsCreated())
    9090        return;
     
    105105        machineWindows()[uScreenId - 1]->raise();
    106106
    107     /* Remember what machine window(s) created: */
     107    /* Mark machine-window(s) created: */
    108108    setMachineWindowsCreated(true);
    109109}
     
    111111void UIMachineLogicNormal::cleanupMachineWindows()
    112112{
    113     /* Do not cleanup machine window(s) if not present: */
     113    /* Do not destroy machine-window(s) if they destroyed already: */
    114114    if (!isMachineWindowsCreated())
    115115        return;
    116116
    117     /* Cleanup machine window(s): */
     117    /* Mark machine-window(s) destroyed: */
     118    setMachineWindowsCreated(false);
     119
     120    /* Cleanup machine-window(s): */
    118121    foreach (UIMachineWindow *pMachineWindow, machineWindows())
    119122        UIMachineWindow::destroy(pMachineWindow);
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.cpp

    r41587 r45939  
    6666void UIMachineLogicScale::prepareMachineWindows()
    6767{
    68     /* Do not create window(s) if they created already: */
     68    /* Do not create machine-window(s) if they created already: */
    6969    if (isMachineWindowsCreated())
    7070        return;
     
    8585        machineWindows()[uScreenId - 1]->raise();
    8686
    87     /* Remember what machine window(s) created: */
     87    /* Mark machine-window(s) created: */
    8888    setMachineWindowsCreated(true);
    8989}
     
    9191void UIMachineLogicScale::cleanupMachineWindows()
    9292{
    93     /* Do not cleanup machine window(s) if not present: */
     93    /* Do not destroy machine-window(s) if they destroyed already: */
    9494    if (!isMachineWindowsCreated())
    9595        return;
    9696
    97     /* Cleanup machine window(s): */
     97    /* Mark machine-window(s) destroyed: */
     98    setMachineWindowsCreated(false);
     99
     100    /* Cleanup machine-window(s): */
    98101    foreach (UIMachineWindow *pMachineWindow, machineWindows())
    99102        UIMachineWindow::destroy(pMachineWindow);
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineLogicSeamless.cpp

    r45233 r45939  
    125125void UIMachineLogicSeamless::prepareMachineWindows()
    126126{
    127     /* Do not create window(s) if they created already: */
     127    /* Do not create machine-window(s) if they created already: */
    128128    if (isMachineWindowsCreated())
    129129        return;
     
    135135#endif /* Q_WS_MAC */
    136136
    137     /* Update the multi screen layout: */
     137    /* Update the multi-screen layout: */
    138138    m_pScreenLayout->update();
    139139
     
    142142        addMachineWindow(UIMachineWindow::create(this, cScreenId));
    143143
    144     /* Connect screen-layout change handler: */
     144    /* Connect multi-screen layout change handler: */
    145145    for (int i = 0; i < machineWindows().size(); ++i)
    146146        connect(m_pScreenLayout, SIGNAL(sigScreenLayoutChanged()),
    147147                static_cast<UIMachineWindowSeamless*>(machineWindows()[i]), SLOT(sltShowInNecessaryMode()));
    148148
    149     /* Remember what machine window(s) created: */
     149    /* Mark machine-window(s) created: */
    150150    setMachineWindowsCreated(true);
    151151}
     
    162162void UIMachineLogicSeamless::cleanupMachineWindows()
    163163{
    164     /* Do not cleanup machine window(s) if not present: */
     164    /* Do not destroy machine-window(s) if they destroyed already: */
    165165    if (!isMachineWindowsCreated())
    166166        return;
    167167
    168     /* Cleanup machine window(s): */
     168    /* Mark machine-window(s) destroyed: */
     169    setMachineWindowsCreated(false);
     170
     171    /* Cleanup machine-window(s): */
    169172    foreach (UIMachineWindow *pMachineWindow, machineWindows())
    170173        UIMachineWindow::destroy(pMachineWindow);
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupStack.cpp

    r45696 r45939  
    2626#include "UIPopupStack.h"
    2727#include "UIPopupPane.h"
     28#include "UIMachineWindowNormal.h"
    2829
    2930/* Other VBox includes: */
    3031#include <VBox/sup.h>
    3132
    32 UIPopupStack::UIPopupStack(QWidget *pParent)
    33     : QWidget(pParent)
    34     , m_fPolished(false)
    35     , m_iLayoutMargin(2), m_iLayoutSpacing(0)
    36     , m_iParentStatusBarHeight(parentStatusBarHeight(pParent))
    37 {
    38     /* Prepare: */
    39     prepare();
     33UIPopupStack::UIPopupStack()
     34    : m_iLayoutMargin(1), m_iLayoutSpacing(1)
     35{
    4036}
    4137
     
    6965    pPopupPane->show();
    7066
    71     /* Propagate desired width: */
    72     setDesiredWidth(parentWidget()->width());
    73     /* Adjust geometry: */
    74     sltAdjustGeometry();
     67    /* Adjust geometry only if parent is currently set: */
     68    if (parent())
     69    {
     70        /* Propagate desired width: */
     71        setDesiredWidth(parentWidget()->width());
     72        /* Adjust geometry: */
     73        sltAdjustGeometry();
     74    }
    7575}
    7676
     
    9191    pPopupPane->setDetails(strDetails);
    9292
    93     /* Propagate desired width: */
    94     setDesiredWidth(parentWidget()->width());
    95     /* Adjust geometry: */
    96     sltAdjustGeometry();
     93    /* Adjust geometry only if parent is currently set: */
     94    if (parent())
     95    {
     96        /* Propagate desired width: */
     97        setDesiredWidth(parentWidget()->width());
     98        /* Adjust geometry: */
     99        sltAdjustGeometry();
     100    }
     101}
     102
     103void UIPopupStack::setParent(QWidget *pParent)
     104{
     105    /* Call to base-class: */
     106    QWidget::setParent(pParent);
     107    /* Recalculate parent status-bar height: */
     108    m_iParentStatusBarHeight = parentStatusBarHeight(pParent);
    97109}
    98110
    99111void UIPopupStack::sltAdjustGeometry()
    100112{
     113    /* Adjust geometry only if parent is currently set: */
     114    if (!parent())
     115        return;
     116
    101117    /* Get this attributes: */
    102118    const int iWidth = parentWidget()->width();
     
    137153    delete pPopupPane;
    138154
     155    /* Layout content: */
     156    layoutContent();
     157
    139158    /* Make sure this stack still contains popup-panes: */
    140159    if (!m_panes.isEmpty())
     
    143162    /* Notify listeners about popup-stack: */
    144163    emit sigRemove();
    145 }
    146 
    147 void UIPopupStack::prepare()
    148 {
    149     /* Install event-filter to parent: */
    150     parent()->installEventFilter(this);
    151164}
    152165
     
    226239{
    227240    /* Make sure its parent event came: */
    228     if (pWatched != parent())
     241    if (!parent() || pWatched != parent())
    229242        return false;
    230243
     
    242255}
    243256
    244 void UIPopupStack::showEvent(QShowEvent *pEvent)
    245 {
    246     /* Make sure we should polish dialog: */
    247     if (m_fPolished)
    248         return;
    249 
    250     /* Call to polish-event: */
    251     polishEvent(pEvent);
    252 
    253     /* Mark dialog as polished: */
    254     m_fPolished = true;
    255 }
    256 
    257 void UIPopupStack::polishEvent(QShowEvent*)
    258 {
    259     /* Propagate desired width: */
    260     setDesiredWidth(parentWidget()->width());
    261     /* Adjust geometry: */
    262     sltAdjustGeometry();
     257void UIPopupStack::showEvent(QShowEvent*)
     258{
     259    /* Adjust geometry only if parent is currently set: */
     260    if (parent())
     261    {
     262        /* Propagate desired width: */
     263        setDesiredWidth(parentWidget()->width());
     264        /* Adjust geometry: */
     265        sltAdjustGeometry();
     266    }
    263267}
    264268
     
    266270int UIPopupStack::parentStatusBarHeight(QWidget *pParent)
    267271{
    268     /* Check if passed parent is QMainWindow and contains status-bar: */
    269     if (QMainWindow *pParentWindow = qobject_cast<QMainWindow*>(pParent))
    270         if (pParentWindow->statusBar())
    271             return pParentWindow->statusBar()->height();
     272    /* Status-bar can exist only on QMainWindow sub-class: */
     273    if (QMainWindow *pMainWindow = qobject_cast<QMainWindow*>(pParent))
     274    {
     275        /* Status-bar can exist only:
     276         * 1. on non-machine-window
     277         * 2. on machine-window in normal mode: */
     278        if (!qobject_cast<UIMachineWindow*>(pMainWindow) ||
     279            qobject_cast<UIMachineWindowNormal*>(pMainWindow))
     280            return pMainWindow->statusBar()->height();
     281    }
    272282    /* Zero by default: */
    273283    return 0;
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPopupStack.h

    r45696 r45939  
    4343
    4444    /* Constructor: */
    45     UIPopupStack(QWidget *pParent);
     45    UIPopupStack();
    4646
    4747    /* API: Popup-pane stuff: */
     
    5353    void updatePopupPane(const QString &strPopupPaneID,
    5454                         const QString &strMessage, const QString &strDetails);
     55
     56    /* API: Parent stuff: */
     57    void setParent(QWidget *pParent);
    5558
    5659private slots:
     
    6467private:
    6568
    66     /* Helper: Prepare stuff: */
    67     void prepare();
    68 
    6969    /* Helpers: Layout stuff: */
    7070    int minimumWidthHint();
     
    7777    bool eventFilter(QObject *pWatched, QEvent *pEvent);
    7878
    79     /* Handlers: Event stuff: */
    80     virtual void showEvent(QShowEvent *pEvent);
    81     virtual void polishEvent(QShowEvent *pEvent);
     79    /* Handler: Event stuff: */
     80    void showEvent(QShowEvent *pEvent);
    8281
    8382    /* Static helpers: Prepare stuff: */
     
    8584
    8685    /* Variables: */
    87     bool m_fPolished;
    8886    const int m_iLayoutMargin;
    8987    const int m_iLayoutSpacing;
    90     const int m_iParentStatusBarHeight;
     88    int m_iParentStatusBarHeight;
    9189    QMap<QString, UIPopupPane*> m_panes;
    9290};
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