VirtualBox

Changeset 67068 in vbox


Ignore:
Timestamp:
May 24, 2017 5:47:44 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: Selector UI: Tools pane: Initial implementation (not integrated for now).

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

Legend:

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

    r67067 r67068  
    378378        src/selector/UISelectorWindow.h \
    379379        src/selector/UISnapshotPane.h \
     380        src/selector/UIToolsPane.h \
    380381        src/selector/graphics/chooser/UIGChooser.h \
    381382        src/selector/graphics/chooser/UIGChooserModel.h \
     
    686687        src/selector/UISelectorWindow.cpp \
    687688        src/selector/UISnapshotPane.cpp \
     689        src/selector/UIToolsPane.cpp \
    688690        src/selector/graphics/chooser/UIGChooser.cpp \
    689691        src/selector/graphics/chooser/UIGChooserModel.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/VirtualBox1.qrc

    r67047 r67068  
    6363        <file alias="disconnect_16px.png">images/disconnect_16px.png</file>
    6464        <file alias="diskimage_16px.png">images/diskimage_16px.png</file>
     65        <file alias="diskimage_22px.png">images/diskimage_22px.png</file>
    6566        <file alias="diskimage_32px.png">images/diskimage_32px.png</file>
    6667        <file alias="display_hardware_16px.png">images/display_hardware_16px.png</file>
     
    174175        <file alias="help_button_pressed_mac_22px.png">images/help_button_pressed_mac_22px.png</file>
    175176        <file alias="host_iface_manager_16px.png">images/host_iface_manager_16px.png</file>
     177        <file alias="host_iface_manager_22px.png">images/host_iface_manager_22px.png</file>
    176178        <file alias="host_iface_manager_32px.png">images/host_iface_manager_32px.png</file>
    177179        <file alias="hostkey_16px.png">images/hostkey_16px.png</file>
  • trunk/src/VBox/Frontends/VirtualBox/VirtualBox1_hidpi.qrc

    r67047 r67068  
    6363        <file alias="disconnect_16px_hidpi.png">images/hidpi/disconnect_16px_hidpi.png</file>
    6464        <file alias="diskimage_16px_hidpi.png">images/hidpi/diskimage_16px_hidpi.png</file>
     65        <file alias="diskimage_22px_hidpi.png">images/hidpi/diskimage_22px_hidpi.png</file>
    6566        <file alias="diskimage_32px_hidpi.png">images/hidpi/diskimage_32px_hidpi.png</file>
    6667        <file alias="display_hardware_16px_hidpi.png">images/hidpi/display_hardware_16px_hidpi.png</file>
     
    174175        <file alias="help_button_pressed_mac_22px_hidpi.png">images/hidpi/help_button_pressed_mac_22px_hidpi.png</file>
    175176        <file alias="host_iface_manager_16px_hidpi.png">images/hidpi/host_iface_manager_16px_hidpi.png</file>
     177        <file alias="host_iface_manager_22px_hidpi.png">images/hidpi/host_iface_manager_22px_hidpi.png</file>
    176178        <file alias="host_iface_manager_32px_hidpi.png">images/hidpi/host_iface_manager_32px_hidpi.png</file>
    177179        <file alias="hostkey_16px_hidpi.png">images/hidpi/hostkey_16px_hidpi.png</file>
  • trunk/src/VBox/Frontends/VirtualBox/VirtualBox2.qrc

    r66681 r67068  
    140140        <file alias="snapshot_delete_disabled_16px.png">images/snapshot_delete_disabled_16px.png</file>
    141141        <file alias="snapshot_delete_disabled_22px.png">images/snapshot_delete_disabled_22px.png</file>
     142        <file alias="snapshot_manager_16px.png">images/snapshot_manager_16px.png</file>
     143        <file alias="snapshot_manager_22px.png">images/snapshot_manager_22px.png</file>
    142144        <file alias="snapshot_offline_16px.png">images/snapshot_offline_16px.png</file>
    143145        <file alias="snapshot_online_16px.png">images/snapshot_online_16px.png</file>
  • trunk/src/VBox/Frontends/VirtualBox/VirtualBox2_hidpi.qrc

    r66681 r67068  
    145145        <file alias="site_oracle_16px_hidpi.png">images/hidpi/site_oracle_16px_hidpi.png</file>
    146146        <file alias="site_warning_16px_hidpi.png">images/hidpi/site_warning_16px_hidpi.png</file>
     147        <file alias="snapshot_manager_16px_hidpi.png">images/hidpi/snapshot_manager_16px_hidpi.png</file>
     148        <file alias="snapshot_manager_22px_hidpi.png">images/hidpi/snapshot_manager_22px_hidpi.png</file>
    147149        <file alias="snapshot_delete_16px_hidpi.png">images/hidpi/snapshot_delete_16px_hidpi.png</file>
    148150        <file alias="snapshot_delete_22px_hidpi.png">images/hidpi/snapshot_delete_22px_hidpi.png</file>
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UIToolsPane.cpp

    r67016 r67068  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIDesktopPane class implementation.
     3 * VBox Qt GUI - UIToolsPane class implementation.
    44 */
    55
    66/*
    7  * Copyright (C) 2010-2016 Oracle Corporation
     7 * Copyright (C) 2017 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121
    2222/* Qt includes: */
    23 # include <QAction>
    24 # include <QLabel>
    2523# include <QStackedWidget>
    26 # include <QToolButton>
    27 # include <QVBoxLayout>
     24# include <QTabBar>
    2825
    2926/* GUI includes */
    30 # include "QIWithRetranslateUI.h"
    31 # include "UIDesktopPane.h"
    32 # include "VBoxUtils.h"
     27# include "QIToolButton.h"
     28# include "UIHostNetworkManager.h"
     29# include "UIIconPool.h"
     30# include "UIMediumManager.h"
     31# include "UIMenuToolBar.h"
     32# include "UISnapshotPane.h"
     33# include "UIToolsPane.h"
    3334
    3435/* Other VBox includes: */
     
    3839
    3940
    40 /** QStackedWidget subclass representing container which have two panes:
    41   * 1. Text pane reflecting base information about VirtualBox,
    42   * 2. Error pane reflecting information about currently chosen
    43   *    inaccessible VM and allowing to operate over it. */
    44 class UIDesktopPanePrivate : public QIWithRetranslateUI<QStackedWidget>
    45 {
    46     Q_OBJECT;
    47 
    48 public:
    49 
    50     /** Constructs private desktop pane passing @a pParent to the base-class.
    51       * @param  pRefreshAction  Brings the refresh action reference. */
    52     UIDesktopPanePrivate(QWidget *pParent, QAction *pRefreshAction);
    53 
    54     /** Assigns @a strText and switches to text pane. */
    55     void setText(const QString &strText);
    56     /** Assigns @a strError and switches to error pane. */
    57     void setError(const QString &strError);
    58 
    59 protected:
    60 
    61     /** Handles translation event. */
    62     void retranslateUi();
    63 
    64     /** Prepares text pane. */
    65     void prepareTextPane();
    66     /** Prepares error pane. */
    67     void prepareErrorPane();
    68 
    69 private:
    70 
    71     /** Holds the text pane instance. */
    72     QRichTextBrowser *m_pText;
    73 
    74     /** Holds the error pane container. */
    75     QWidget *m_pErrBox;
    76     /** Holds the error label instance. */
    77     QLabel *m_pErrLabel;
    78     /** Holds the error text-browser instance. */
    79     QTextBrowser *m_pErrText;
    80     /** Holds the VM refresh button instance. */
    81     QToolButton *m_pRefreshButton;
    82     /** Holds the VM refresh action reference. */
    83     QAction *m_pRefreshAction;
    84 };
    85 
    86 
    87 /*********************************************************************************************************************************
    88 *   Class UIDesktopPanePrivate implementation.                                                                                   *
    89 *********************************************************************************************************************************/
    90 
    91 UIDesktopPanePrivate::UIDesktopPanePrivate(QWidget *pParent, QAction *pRefreshAction)
    92     : QIWithRetranslateUI<QStackedWidget>(pParent)
    93     , m_pText(0)
    94     , m_pErrBox(0), m_pErrLabel(0), m_pErrText(0)
    95     , m_pRefreshButton(0), m_pRefreshAction(pRefreshAction)
    96 {
    97     /* Make sure refresh action was passed: */
    98     AssertMsg(m_pRefreshAction, ("Refresh action was NOT passed!"));
    99 
    100     /* Translate finally: */
     41UIToolsPane::UIToolsPane(QWidget *pParent /* = 0 */)
     42    : QIWithRetranslateUI<QWidget>(pParent)
     43    , m_pLayoutMain(0)
     44    , m_pStackedWidget(0)
     45    , m_pPaneSnapshots(0)
     46    , m_pLayoutControls(0)
     47    , m_pTabBar(0)
     48    , m_pMenuToolbar(0)
     49    , m_pMenu(0)
     50{
     51    /* Prepare: */
     52    prepare();
     53}
     54
     55void UIToolsPane::setMachine(const CMachine &comMachine)
     56{
     57    /* Update the panes: */
     58    AssertPtrReturnVoid(m_pPaneSnapshots);
     59    m_pPaneSnapshots->setMachine(comMachine);
     60}
     61
     62void UIToolsPane::retranslateUi()
     63{
     64    /* Translate menu: */
     65    m_pMenu->menuAction()->setText(tr("More Tools"));
     66    m_pMenu->setToolTip(tr("Holds a list of tools"));
     67    m_pMenu->setTitle(tr("Tools"));
     68
     69    /* Translate actions: */
     70    m_actions[ToolsType_SnapshotManager]->setText(tr("Snapshot Manager"));
     71    m_actions[ToolsType_VirtualMediaManager]->setText(tr("Virtual Media Manager"));
     72    m_actions[ToolsType_HostNetworkManager]->setText(tr("Host Network Manager"));
     73
     74    /* Translate tab-bar: */
     75    for (int iTabIndex = 0; iTabIndex < m_pTabBar->count(); ++iTabIndex)
     76    {
     77        const ToolsType enmType = m_pTabBar->tabData(iTabIndex).value<ToolsType>();
     78        m_pTabBar->setTabText(iTabIndex, m_actions.value(enmType)->text());
     79    }
     80}
     81
     82void UIToolsPane::sltHandleMenuToolbarTrigger()
     83{
     84    /* Get the sender: */
     85    QAction *pAction = sender() ? qobject_cast<QAction*>(sender()) : 0;
     86    AssertPtrReturnVoid(pAction);
     87
     88    /* Acquire sender's type: */
     89    const ToolsType enmType = pAction->property("ToolsType").value<ToolsType>();
     90    AssertReturnVoid(enmType != ToolsType_Invalid);
     91
     92    /* Add corresponding tab: */
     93    addTabBarTab(enmType, true);
     94}
     95
     96void UIToolsPane::sltHandleTabBarTabMoved(int iFrom, int iTo)
     97{
     98    /* Swap stack-widget pages as well: */
     99    QWidget *pWidget = m_pStackedWidget->widget(iFrom);
     100    m_pStackedWidget->removeWidget(pWidget);
     101    m_pStackedWidget->insertWidget(iTo, pWidget);
     102}
     103
     104void UIToolsPane::sltHandleTabBarCurrentChange(int iIndex)
     105{
     106    /* Activate corresponding indexes: */
     107    m_pStackedWidget->setCurrentIndex(iIndex);
     108}
     109
     110void UIToolsPane::sltHandleTabBarButtonClick()
     111{
     112    /* Get the sender: */
     113    QIToolButton *pButton = sender() ? qobject_cast<QIToolButton*>(sender()) : 0;
     114    AssertPtrReturnVoid(pButton);
     115
     116    /* Acquire sender's type: */
     117    const ToolsType enmType = pButton->property("ToolsType").value<ToolsType>();
     118    AssertReturnVoid(enmType != ToolsType_Invalid);
     119
     120    /* Search for the tab with such type: */
     121    int iActualTabIndex = -1;
     122    for (int iTabIndex = 0; iTabIndex < m_pTabBar->count(); ++iTabIndex)
     123        if (m_pTabBar->tabData(iTabIndex).value<ToolsType>() == enmType)
     124            iActualTabIndex = iTabIndex;
     125    AssertReturnVoid(iActualTabIndex != -1);
     126
     127    /* Delete the tab and corresponding widget: */
     128    m_pTabBar->removeTab(iActualTabIndex);
     129    QWidget *pWidget = m_pStackedWidget->widget(iActualTabIndex);
     130    m_pStackedWidget->removeWidget(pWidget);
     131    delete pWidget;
     132}
     133
     134void UIToolsPane::prepare()
     135{
     136    /* Create main layout: */
     137    m_pLayoutMain = new QVBoxLayout(this);
     138    AssertPtrReturnVoid(m_pLayoutMain);
     139    {
     140        /* Configure layout: */
     141        m_pLayoutMain->setSpacing(0);
     142        m_pLayoutMain->setContentsMargins(3, 4, 5, 0);
     143
     144        /* Prepare stacked-widget: */
     145        prepareStackedWidget();
     146
     147        /* Create controls layout: */
     148        m_pLayoutControls = new QHBoxLayout;
     149        AssertPtrReturnVoid(m_pLayoutControls);
     150        {
     151            /* Configure layout: */
     152            m_pLayoutControls->setSpacing(0);
     153            m_pLayoutControls->setContentsMargins(0, 0, 0, 0);
     154
     155            /* Prepare tab-bar: */
     156            prepareTabBar();
     157            /* Prepare menu-toolbar: */
     158            prepareMenuToolbar();
     159            /* Add Snapshot Manager pane: */
     160            addTabBarTab(ToolsType_SnapshotManager, false);
     161
     162            /* Add into layout: */
     163            m_pLayoutMain->addLayout(m_pLayoutControls);
     164        }
     165    }
     166
     167    /* Apply language settings: */
    101168    retranslateUi();
    102169}
    103170
    104 void UIDesktopPanePrivate::setText(const QString &strText)
    105 {
    106     /* Prepare text pane if necessary: */
    107     prepareTextPane();
    108 
    109     /* Assign corresponding text: */
    110     m_pText->setText(strText);
    111 
    112     /* Raise corresponding widget: */
    113     setCurrentIndex(indexOf(m_pText));
    114 }
    115 
    116 void UIDesktopPanePrivate::setError(const QString &strError)
    117 {
    118     /* Prepare error pane if necessary: */
    119     prepareErrorPane();
    120 
    121     /* Assign corresponding text: */
    122     m_pErrText->setText(strError);
    123 
    124     /* Raise corresponding widget: */
    125     setCurrentIndex(indexOf(m_pErrBox));
    126 }
    127 
    128 void UIDesktopPanePrivate::retranslateUi()
    129 {
    130     /* Translate error-label text: */
    131     if (m_pErrLabel)
    132         m_pErrLabel->setText(QApplication::translate("UIDetailsPagePrivate",
    133                                  "The selected virtual machine is <i>inaccessible</i>. "
    134                                  "Please inspect the error message shown below and press the "
    135                                  "<b>Refresh</b> button if you want to repeat the accessibility check:"));
    136 
    137     /* Translate refresh button & action text: */
    138     if (m_pRefreshAction && m_pRefreshButton)
    139     {
    140         m_pRefreshButton->setText(m_pRefreshAction->text());
    141         m_pRefreshButton->setIcon(m_pRefreshAction->icon());
    142         m_pRefreshButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
    143     }
    144 }
    145 
    146 void UIDesktopPanePrivate::prepareTextPane()
    147 {
    148     if (m_pText)
    149         return;
    150 
    151     /* Create text pane: */
    152     m_pText = new QRichTextBrowser(this);
    153     m_pText->setFocusPolicy(Qt::StrongFocus);
    154     m_pText->document()->setDefaultStyleSheet("a { text-decoration: none; }");
    155     /* Make text pane transparent: */
    156     m_pText->setFrameShape(QFrame::NoFrame);
    157     m_pText->viewport()->setAutoFillBackground(false);
    158     m_pText->setOpenLinks(false);
    159 
    160     /* Add into the stack: */
    161     addWidget(m_pText);
    162 
    163     /* Retranslate finally: */
    164     retranslateUi();
    165 }
    166 
    167 void UIDesktopPanePrivate::prepareErrorPane()
    168 {
    169     if (m_pErrBox)
    170         return;
    171 
    172     /* Create error pane: */
    173     m_pErrBox = new QWidget;
    174 
    175     /* Create main layout: */
    176     QVBoxLayout *pMainLayout = new QVBoxLayout(m_pErrBox);
    177 #if   defined(VBOX_WS_MAC)
    178     pMainLayout->setContentsMargins(4, 5, 5, 5);
    179 #elif defined(VBOX_WS_WIN)
    180     pMainLayout->setContentsMargins(3, 5, 5, 0);
    181 #elif defined(VBOX_WS_X11)
    182     pMainLayout->setContentsMargins(0, 5, 5, 5);
    183 #endif
    184     pMainLayout->setSpacing(10);
    185 
    186     /* Create error label: */
    187     m_pErrLabel = new QLabel(m_pErrBox);
    188     m_pErrLabel->setWordWrap(true);
    189     m_pErrLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    190     pMainLayout->addWidget(m_pErrLabel);
    191 
    192     /* Create error text-browser: */
    193     m_pErrText = new QTextBrowser(m_pErrBox);
    194     m_pErrText->setFocusPolicy(Qt::StrongFocus);
    195     m_pErrText->document()->setDefaultStyleSheet("a { text-decoration: none; }");
    196     pMainLayout->addWidget(m_pErrText);
    197 
    198     /* If refresh action was set: */
    199     if (m_pRefreshAction)
    200     {
    201         /* Create refresh button: */
    202         m_pRefreshButton = new QToolButton(m_pErrBox);
    203         m_pRefreshButton->setFocusPolicy(Qt::StrongFocus);
    204 
    205         /* Create refresh button layout: */
    206         QHBoxLayout *pButtonLayout = new QHBoxLayout;
    207         pMainLayout->addLayout(pButtonLayout);
    208         pButtonLayout->addStretch();
    209         pButtonLayout->addWidget(m_pRefreshButton);
    210 
    211         /* Connect refresh button: */
    212         connect(m_pRefreshButton, SIGNAL(clicked()), m_pRefreshAction, SIGNAL(triggered()));
    213     }
    214 
    215     pMainLayout->addStretch();
    216 
    217     /* Add into the stack: */
    218     addWidget(m_pErrBox);
    219 
    220     /* Retranslate finally: */
    221     retranslateUi();
    222 }
    223 
    224 
    225 /*********************************************************************************************************************************
    226 *   Class UIDesktopPane implementation.                                                                                          *
    227 *********************************************************************************************************************************/
    228 
    229 UIDesktopPane::UIDesktopPane(QAction *pRefreshAction, QWidget *pParent)
    230     : QWidget(pParent)
    231 {
    232     /* Prepare main layout: */
    233     QVBoxLayout *pMainLayout = new QVBoxLayout(this);
    234     pMainLayout->setContentsMargins(0, 0, 0, 0);
    235 
    236     /* Create desktop pane: */
    237     m_pDesktopPrivate = new UIDesktopPanePrivate(this, pRefreshAction);
    238 
    239     /* Add it to the layout: */
    240     pMainLayout->addWidget(m_pDesktopPrivate);
    241 }
    242 
    243 void UIDesktopPane::updateDetailsText(const QString &strText)
    244 {
    245     m_pDesktopPrivate->setText(strText);
    246 }
    247 
    248 void UIDesktopPane::updateDetailsError(const QString &strError)
    249 {
    250     m_pDesktopPrivate->setError(strError);
    251 }
    252 
    253 #include "UIDesktopPane.moc"
    254 
     171void UIToolsPane::prepareStackedWidget()
     172{
     173    /* Create stacked-widget: */
     174    m_pStackedWidget = new QStackedWidget;
     175    AssertPtrReturnVoid(m_pStackedWidget);
     176    {
     177        /* Add into layout: */
     178        m_pLayoutMain->addWidget(m_pStackedWidget);
     179    }
     180}
     181
     182void UIToolsPane::prepareTabBar()
     183{
     184    /* Create tab-bar: */
     185    m_pTabBar = new QTabBar;
     186    AssertPtrReturnVoid(m_pTabBar);
     187    {
     188        /* Configure tab-bar: */
     189        const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) * 1.375;
     190        m_pTabBar->setIconSize(QSize(iIconMetric, iIconMetric));
     191        m_pTabBar->setMovable(true);
     192        m_pTabBar->setDrawBase(false);
     193        m_pTabBar->setExpanding(false);
     194        m_pTabBar->setShape(QTabBar::RoundedSouth);
     195        m_pTabBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
     196        connect(m_pTabBar, &QTabBar::tabMoved, this, &UIToolsPane::sltHandleTabBarTabMoved);
     197        connect(m_pTabBar, &QTabBar::currentChanged, this, &UIToolsPane::sltHandleTabBarCurrentChange);
     198
     199        /* Add into layout: */
     200        m_pLayoutControls->addWidget(m_pTabBar);
     201    }
     202}
     203
     204void UIToolsPane::prepareMenuToolbar()
     205{
     206    /* Create menu-toolbar: */
     207    m_pMenuToolbar = new UIMenuToolBar;
     208    AssertPtrReturnVoid(m_pMenuToolbar);
     209    {
     210        /* Configure menu-toolbar: */
     211        const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
     212        m_pMenuToolbar->setIconSize(QSize(iIconMetric, iIconMetric));
     213        m_pMenuToolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
     214        m_pMenuToolbar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
     215        m_pMenuToolbar->setAlignmentType(UIMenuToolBar::AlignmentType_BottomRight);
     216
     217        /* Prepare menu: */
     218        prepareMenu();
     219
     220        /* Add into layout: */
     221        m_pLayoutControls->addWidget(m_pMenuToolbar);
     222    }
     223}
     224
     225void UIToolsPane::prepareMenu()
     226{
     227    /* Create menu: */
     228    m_pMenu = new QMenu(m_pMenuToolbar);
     229    AssertPtrReturnVoid(m_pMenu);
     230    {
     231        /* Configure menus: */
     232        m_pMenu->setIcon(UIIconPool::iconSet(":/vm_settings_16px.png"));
     233
     234        /* Create SnapShot manager action: */
     235        m_actions[ToolsType_SnapshotManager] = m_pMenu->addAction(UIIconPool::iconSetFull(":/snapshot_manager_22px.png",
     236                                                                                          ":/snapshot_manager_16px.png"),
     237                                                                  QString(), this, &UIToolsPane::sltHandleMenuToolbarTrigger);
     238        {
     239            m_actions[ToolsType_SnapshotManager]->
     240                setProperty("ToolsType", QVariant::fromValue(ToolsType_SnapshotManager));
     241        }
     242
     243        /* Create Virtual Media manager action: */
     244        m_actions[ToolsType_VirtualMediaManager] = m_pMenu->addAction(UIIconPool::iconSetFull(":/diskimage_22px.png",
     245                                                                                              ":/diskimage_16px.png"),
     246                                                                      QString(), this, &UIToolsPane::sltHandleMenuToolbarTrigger);
     247        {
     248            m_actions[ToolsType_VirtualMediaManager]->
     249                setProperty("ToolsType", QVariant::fromValue(ToolsType_VirtualMediaManager));
     250        }
     251
     252        /* Create Host Network manager action: */
     253        m_actions[ToolsType_HostNetworkManager] = m_pMenu->addAction(UIIconPool::iconSetFull(":/host_iface_manager_22px.png",
     254                                                                                             ":/host_iface_manager_16px.png"),
     255                                                                     QString(), this, &UIToolsPane::sltHandleMenuToolbarTrigger);
     256        {
     257            m_actions[ToolsType_HostNetworkManager]->
     258                setProperty("ToolsType", QVariant::fromValue(ToolsType_HostNetworkManager));
     259        }
     260
     261        /* Add as tool-button into tool-bar: */
     262        m_pMenuToolbar->setMenuAction(m_pMenu->menuAction());
     263        QToolButton *pButton = qobject_cast<QToolButton*>(m_pMenuToolbar->widgetForAction(m_pMenu->menuAction()));
     264        AssertPtrReturnVoid(pButton);
     265        {
     266            /* Configure tool-button: */
     267            pButton->setPopupMode(QToolButton::InstantPopup);
     268            pButton->setAutoRaise(true);
     269        }
     270    }
     271}
     272
     273void UIToolsPane::addTabBarTab(ToolsType enmType, bool fCloseable)
     274{
     275    /* Search for a tab with such type: */
     276    int iActualTabIndex = -1;
     277    for (int iTabIndex = 0; iTabIndex < m_pTabBar->count(); ++iTabIndex)
     278        if (m_pTabBar->tabData(iTabIndex).value<ToolsType>() == enmType)
     279            iActualTabIndex = iTabIndex;
     280
     281    /* If tab with such type doesn't exist: */
     282    m_pTabBar->blockSignals(true);
     283    if (iActualTabIndex == -1)
     284    {
     285        /* Append stack-widget with corresponding page: */
     286        switch (enmType)
     287        {
     288            case ToolsType_SnapshotManager:
     289                m_pPaneSnapshots = new UISnapshotPane;
     290                m_pStackedWidget->addWidget(m_pPaneSnapshots);
     291                break;
     292            case ToolsType_VirtualMediaManager:
     293                m_pStackedWidget->addWidget(new UIMediumManagerWidget);
     294                break;
     295            case ToolsType_HostNetworkManager:
     296                m_pStackedWidget->addWidget(new UIHostNetworkManagerWidget);
     297                break;
     298            default:
     299                AssertFailedReturnVoid();
     300        }
     301
     302        /* Append tab-bar with corresponding tab: */
     303        iActualTabIndex = m_pTabBar->addTab(m_actions.value(enmType)->icon(), m_actions.value(enmType)->text());
     304        {
     305            /* Create close button if requested: */
     306            if (fCloseable)
     307            {
     308                QIToolButton *pButtonClose = new QIToolButton;
     309                AssertPtrReturnVoid(pButtonClose);
     310                {
     311                    /* Configure button: */
     312                    pButtonClose->setIcon(UIIconPool::iconSet(":/close_16px.png"));
     313                    pButtonClose->setProperty("ToolsType", QVariant::fromValue(enmType));
     314                    connect(pButtonClose, &QIToolButton::clicked, this, &UIToolsPane::sltHandleTabBarButtonClick);
     315                    /* Add into tab-bar: */
     316                    m_pTabBar->setTabButton(iActualTabIndex, QTabBar::RightSide, pButtonClose);
     317                }
     318            }
     319            /* Store the data: */
     320            m_pTabBar->setTabData(iActualTabIndex, QVariant::fromValue(enmType));
     321        }
     322    }
     323
     324    /* Activate corresponding indexes: */
     325    m_pStackedWidget->setCurrentIndex(iActualTabIndex);
     326    m_pTabBar->setCurrentIndex(iActualTabIndex);
     327    m_pTabBar->blockSignals(false);
     328}
     329
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UIToolsPane.h

    r67016 r67068  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIDesktopPane class declaration.
     3 * VBox Qt GUI - UIToolsPane class declaration.
    44 */
    55
    66/*
    7  * Copyright (C) 2010-2016 Oracle Corporation
     7 * Copyright (C) 2017 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef ___UIDesktopPane_h___
    19 #define ___UIDesktopPane_h___
     18#ifndef ___UIToolsPane_h___
     19#define ___UIToolsPane_h___
    2020
    2121/* Qt includes: */
    2222#include <QWidget>
    2323
     24/* GUI includes: */
     25#include "QIWithRetranslateUI.h"
     26
    2427/* Forward declarations: */
    25 class UIDesktopPanePrivate;
     28class QAction;
     29class QHBoxLayout;
     30class QMenu;
     31class QStackedWidget;
     32class QTabBar;
     33class QVBoxLayout;
     34class UIMenuToolBar;
     35class UISnapshotPane;
     36class CMachine;
    2637
    2738
    28 /** QWidget subclass representing container which have two panes:
    29   * 1. Text details pane reflecting base information about VirtualBox,
    30   * 2. Error details pane reflecting information about currently chosen
    31   *    inaccessible VM and allowing to operate over it. */
    32 class UIDesktopPane : public QWidget
     39/** QWidget subclass representing container for tool panes. */
     40class UIToolsPane : public QIWithRetranslateUI<QWidget>
    3341{
    3442    Q_OBJECT;
     
    3644public:
    3745
    38     /** Constructs desktop pane passing @a pParent to the base-class.
    39       * @param  pRefreshAction  Brings the refresh action reference. */
    40     UIDesktopPane(QAction *pRefreshAction, QWidget *pParent);
     46    /** Tools types. */
     47    enum ToolsType
     48    {
     49        ToolsType_Invalid,
     50        ToolsType_SnapshotManager,
     51        ToolsType_VirtualMediaManager,
     52        ToolsType_HostNetworkManager,
     53    };
    4154
    42     /** Updates @a strText details and switches to text details pane. */
    43     void updateDetailsText(const QString &strText);
    44     /** Updates @a strError details and switches to error details pane. */
    45     void updateDetailsError(const QString &strError);
     55    /** Constructs tools pane passing @a pParent to the base-class. */
     56    UIToolsPane(QWidget *pParent = 0);
     57
     58    /** Defines the @a comMachine object. */
     59    void setMachine(const CMachine &comMachine);
     60
     61protected:
     62
     63    /** Handles translation event. */
     64    virtual void retranslateUi() /* override */;
     65
     66private slots:
     67
     68    /** Handles menu-toolbar trigger. */
     69    void sltHandleMenuToolbarTrigger();
     70
     71    /** Handles Tools tab-bar tab movement. */
     72    void sltHandleTabBarTabMoved(int iFrom, int iTo);
     73    /** Handles Tools tab-bar current tab change. */
     74    void sltHandleTabBarCurrentChange(int iIndex);
     75    /** Handles Tools tab-bar button click. */
     76    void sltHandleTabBarButtonClick();
    4677
    4778private:
    4879
    49     /** Holds the private desktop pane instance. */
    50     UIDesktopPanePrivate *m_pDesktopPrivate;
     80    /** Prepares all. */
     81    void prepare();
     82    /** Prepares stacked-widget. */
     83    void prepareStackedWidget();
     84    /** Prepares tab-bar. */
     85    void prepareTabBar();
     86    /** Prepares menu-toolbar. */
     87    void prepareMenuToolbar();
     88    /** Prepares menu. */
     89    void prepareMenu();
     90
     91    /** Adds corresponding tab-bar tab. */
     92    void addTabBarTab(ToolsType enmType, bool fCloseable);
     93
     94    /** Holds the main layout isntance. */
     95    QVBoxLayout               *m_pLayoutMain;
     96    /** Holds the stacked-widget instance. */
     97    QStackedWidget            *m_pStackedWidget;
     98    /** Holds the snapshot pane. */
     99    UISnapshotPane            *m_pPaneSnapshots;
     100    /** Holds the controls layout instance. */
     101    QHBoxLayout               *m_pLayoutControls;
     102    /** Holds the tab-bar instance. */
     103    QTabBar                   *m_pTabBar;
     104    /** Holds the menu-toolbar instance. */
     105    UIMenuToolBar             *m_pMenuToolbar;
     106    /** Holds the menu instance. */
     107    QMenu                     *m_pMenu;
     108    /** Holds the menu action instances. */
     109    QMap<ToolsType, QAction*>  m_actions;
    51110};
    52111
    53 #endif /* !___UIDesktopPane_h___ */
     112/* Make sure QVariant can eat UIToolsPane::ToolsType: */
     113Q_DECLARE_METATYPE(UIToolsPane::ToolsType);
    54114
     115#endif /* !___UIToolsPane_h___ */
     116
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