VirtualBox

Changeset 80043 in vbox


Ignore:
Timestamp:
Jul 29, 2019 12:16:59 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
132479
Message:

FE/Qt: bugref:7720: VM settings / Display page: Replace heavily distributed across display page widgets related to video-memory editing functionality with single UIVideoMemoryEditor.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
4 edited
2 copied

Legend:

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

    r79979 r80043  
    915915        src/widgets/UISearchLineEdit.h \
    916916        src/widgets/UIToolBar.h \
     917        src/widgets/UIVideoMemoryEditor.h \
    917918        src/widgets/UIWarningPane.h \
    918919        src/wizards/UIWizard.h \
     
    14071408        src/widgets/UIStatusBarEditorWindow.cpp \
    14081409        src/widgets/UIToolBar.cpp \
     1410        src/widgets/UIVideoMemoryEditor.cpp \
    14091411        src/widgets/UIWarningPane.cpp \
    14101412        src/wizards/UIWizard.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsDisplay.cpp

    r80042 r80043  
    287287UIMachineSettingsDisplay::UIMachineSettingsDisplay()
    288288    : m_comGuestOSType(CGuestOSType())
    289     , m_iMinVRAM(0)
    290     , m_iMaxVRAM(0)
    291     , m_iMaxVRAMVisible(0)
    292     , m_iInitialVRAM(0)
    293289#ifdef VBOX_WITH_CRHGSMI
    294290    , m_fWddmModeSupported(false)
     
    317313    /* Remember new guest OS type: */
    318314    m_comGuestOSType = comGuestOSType;
     315    m_pVideoMemoryEditor->setGuestOSType(m_comGuestOSType);
    319316
    320317#ifdef VBOX_WITH_CRHGSMI
     
    322319    const QString strGuestOSTypeId = m_comGuestOSType.isNotNull() ? m_comGuestOSType.GetId() : QString();
    323320    m_fWddmModeSupported = UICommon::isWddmCompatibleOsType(strGuestOSTypeId);
     321    m_pVideoMemoryEditor->set3DAccelerationSupported(m_fWddmModeSupported);
    324322#endif
    325323#ifdef VBOX_WITH_VIDEOHWACCEL
     
    327325    const QString strGuestOSTypeFamily = m_comGuestOSType.isNotNull() ? m_comGuestOSType.GetFamilyId() : QString();
    328326    m_f2DVideoAccelerationSupported = strGuestOSTypeFamily == "Windows";
    329 #endif
    330 
    331     /* Recheck video RAM requirement: */
    332     checkVRAMRequirements();
     327    m_pVideoMemoryEditor->set2DVideoAccelerationSupported(m_f2DVideoAccelerationSupported);
     328#endif
    333329
    334330    /* Revalidate: */
     
    410406    }
    411407
    412     /* Gather other old display data: */
    413     m_iInitialVRAM = RT_MIN(oldDisplayData.m_iCurrentVRAM, m_iMaxVRAM);
    414 
    415408    /* Cache old display data: */
    416409    m_pCache->cacheInitialData(oldDisplayData);
     
    436429    m_pCheckbox2DVideo->setChecked(oldDisplayData.m_f2dVideoAccelerationEnabled);
    437430#endif
     431    /* Push required value to m_pVideoMemoryEditor: */
     432    sltHandleGuestScreenCountEditorChange();
     433    sltHandleGraphicsControllerComboChange();
     434#ifdef VBOX_WITH_CRHGSMI
     435    sltHandle3DAccelerationCheckboxChange();
     436#endif
     437#ifdef VBOX_WITH_VIDEOHWACCEL
     438    sltHandle2DVideoAccelerationCheckboxChange();
     439#endif
    438440    // Should be the last one for this tab, since it depends on some of others:
    439     m_pEditorVideoMemorySize->setValue(oldDisplayData.m_iCurrentVRAM);
     441    m_pVideoMemoryEditor->setValue(oldDisplayData.m_iCurrentVRAM);
    440442
    441443    /* If remote display server is supported: */
     
    487489
    488490    /* Gather new 'Screen' data: */
    489     newDisplayData.m_iCurrentVRAM = m_pEditorVideoMemorySize->value();
     491    newDisplayData.m_iCurrentVRAM = m_pVideoMemoryEditor->value();
    490492    newDisplayData.m_cGuestScreenCount = m_pEditorVideoScreenCount->value();
    491493    newDisplayData.m_scaleFactors = m_pScaleFactorEditor->scaleFactors();
     
    566568bool UIMachineSettingsDisplay::validate(QList<UIValidationMessage> &messages)
    567569{
    568     /* Check if video RAM requirement changed first: */
    569     checkVRAMRequirements();
    570 
    571570    /* Pass by default: */
    572571    bool fPass = true;
     
    584583
    585584            /* Basic video RAM amount test: */
    586             if ((quint64)m_pEditorVideoMemorySize->value() * _1M < uNeedBytes)
     585            if ((quint64)m_pVideoMemoryEditor->value() * _1M < uNeedBytes)
    587586            {
    588587                message.second << tr("The virtual machine is currently assigned less than <b>%1</b> of video memory "
     
    595594            {
    596595                uNeedBytes = qMax(uNeedBytes, (quint64) 128 * _1M);
    597                 if ((quint64)m_pEditorVideoMemorySize->value() * _1M < uNeedBytes)
     596                if ((quint64)m_pVideoMemoryEditor->value() * _1M < uNeedBytes)
    598597                {
    599598                    message.second << tr("The virtual machine is set up to use hardware graphics acceleration "
     
    609608            {
    610609                uNeedBytes += VBox2DHelpers::required2DOffscreenVideoMemory();
    611                 if ((quint64)m_pEditorVideoMemorySize->value() * _1M < uNeedBytes)
     610                if ((quint64)m_pVideoMemoryEditor->value() * _1M < uNeedBytes)
    612611                {
    613612                    message.second << tr("The virtual machine is currently assigned less than <b>%1</b> of video memory "
     
    689688    /* Screen tab-order: */
    690689    setTabOrder(pWidget, m_pTabWidget->focusProxy());
    691     setTabOrder(m_pTabWidget->focusProxy(), m_pSliderVideoMemorySize);
    692     setTabOrder(m_pSliderVideoMemorySize, m_pEditorVideoMemorySize);
    693     setTabOrder(m_pEditorVideoMemorySize, m_pSliderVideoScreenCount);
     690    setTabOrder(m_pTabWidget->focusProxy(), m_pVideoMemoryEditor);
     691    setTabOrder(m_pVideoMemoryEditor, m_pSliderVideoScreenCount);
    694692    setTabOrder(m_pSliderVideoScreenCount, m_pEditorVideoScreenCount);
    695693    setTabOrder(m_pEditorVideoScreenCount, m_pScaleFactorEditor);
     
    721719    /* Screen stuff: */
    722720    CSystemProperties sys = uiCommon().virtualBox().GetSystemProperties();
    723     m_pEditorVideoMemorySize->setSuffix(QString(" %1").arg(tr("MB")));
    724     m_pLabelVideoMemorySizeMin->setText(tr("%1 MB").arg(m_iMinVRAM));
    725     m_pLabelVideoMemorySizeMax->setText(tr("%1 MB").arg(m_iMaxVRAMVisible));
    726721    m_pLabelVideoScreenCountMin->setText(QString::number(1));
    727722    m_pLabelVideoScreenCountMax->setText(QString::number(qMin(sys.GetMaxGuestMonitors(), (ULONG)8)));
     
    762757
    763758    /* Polish 'Screen' availability: */
    764     m_pLabelVideoMemorySize->setEnabled(isMachineOffline());
    765     m_pSliderVideoMemorySize->setEnabled(isMachineOffline());
    766     m_pLabelVideoMemorySizeMin->setEnabled(isMachineOffline());
    767     m_pLabelVideoMemorySizeMax->setEnabled(isMachineOffline());
    768     m_pEditorVideoMemorySize->setEnabled(isMachineOffline());
     759    m_pVideoMemoryLabel->setEnabled(isMachineOffline());
     760    m_pVideoMemoryEditor->setEnabled(isMachineOffline());
    769761    m_pLabelVideoScreenCount->setEnabled(isMachineOffline());
    770762    m_pSliderVideoScreenCount->setEnabled(isMachineOffline());
     
    798790}
    799791
    800 void UIMachineSettingsDisplay::sltHandleVideoMemorySizeSliderChange()
    801 {
    802     /* Apply proposed memory-size: */
    803     m_pEditorVideoMemorySize->blockSignals(true);
    804     m_pEditorVideoMemorySize->setValue(m_pSliderVideoMemorySize->value());
    805     m_pEditorVideoMemorySize->blockSignals(false);
    806 
    807     /* Revalidate: */
    808     revalidate();
    809 }
    810 
    811 void UIMachineSettingsDisplay::sltHandleVideoMemorySizeEditorChange()
    812 {
    813     /* Apply proposed memory-size: */
    814     m_pSliderVideoMemorySize->blockSignals(true);
    815     m_pSliderVideoMemorySize->setValue(m_pEditorVideoMemorySize->value());
    816     m_pSliderVideoMemorySize->blockSignals(false);
    817 
    818     /* Revalidate: */
    819     revalidate();
    820 }
    821 
    822792void UIMachineSettingsDisplay::sltHandleGuestScreenCountSliderChange()
    823793{
     
    828798
    829799    /* Update Video RAM requirements: */
    830     checkVRAMRequirements();
     800    m_pVideoMemoryEditor->setGuestScreenCount(m_pSliderVideoScreenCount->value());
    831801
    832802    /* Update recording tab screen count: */
     
    845815
    846816    /* Update Video RAM requirements: */
    847     checkVRAMRequirements();
     817    m_pVideoMemoryEditor->setGuestScreenCount(m_pEditorVideoScreenCount->value());
    848818
    849819    /* Update recording tab screen count: */
     
    853823    revalidate();
    854824}
     825
     826void UIMachineSettingsDisplay::sltHandleGraphicsControllerComboChange()
     827{
     828    /* Update Video RAM requirements: */
     829    m_pVideoMemoryEditor->setGraphicsControllerType(gpConverter->fromString<KGraphicsControllerType>(m_pComboGraphicsControllerType->currentText()));
     830
     831    /* Revalidate: */
     832    revalidate();
     833}
     834
     835#ifdef VBOX_WITH_CRHGSMI
     836void UIMachineSettingsDisplay::sltHandle3DAccelerationCheckboxChange()
     837{
     838    /* Update Video RAM requirements: */
     839    m_pVideoMemoryEditor->set3DAccelerationEnabled(m_pCheckbox3D->isChecked());
     840
     841    /* Revalidate: */
     842    revalidate();
     843}
     844#endif /* VBOX_WITH_CRHGSMI */
     845
     846#ifdef VBOX_WITH_VIDEOHWACCEL
     847void UIMachineSettingsDisplay::sltHandle2DVideoAccelerationCheckboxChange()
     848{
     849    /* Update Video RAM requirements: */
     850    m_pVideoMemoryEditor->set2DVideoAccelerationEnabled(m_pCheckbox2DVideo->isChecked());
     851
     852    /* Revalidate: */
     853    revalidate();
     854}
     855#endif /* VBOX_WITH_VIDEOHWACCEL */
    855856
    856857void UIMachineSettingsDisplay::sltHandleRecordingCheckboxToggle()
     
    980981    /* Prepare common variables: */
    981982    const CSystemProperties sys = uiCommon().virtualBox().GetSystemProperties();
    982     m_iMinVRAM = sys.GetMinGuestVRAM();
    983     m_iMaxVRAM = sys.GetMaxGuestVRAM();
    984     m_iMaxVRAMVisible = m_iMaxVRAM;
    985983
    986984    /* Tab and it's layout created in the .ui file. */
    987985    {
    988         /* Memory-size slider created in the .ui file. */
    989         AssertPtrReturnVoid(m_pSliderVideoMemorySize);
    990         {
    991             /* Configure slider: */
    992             m_pSliderVideoMemorySize->setMinimum(m_iMinVRAM);
    993             m_pSliderVideoMemorySize->setMaximum(m_iMaxVRAMVisible);
    994             m_pSliderVideoMemorySize->setPageStep(calculatePageStep(m_iMaxVRAMVisible));
    995             m_pSliderVideoMemorySize->setSingleStep(m_pSliderVideoMemorySize->pageStep() / 4);
    996             m_pSliderVideoMemorySize->setTickInterval(m_pSliderVideoMemorySize->pageStep());
    997             m_pSliderVideoMemorySize->setSnappingEnabled(true);
    998             m_pSliderVideoMemorySize->setErrorHint(0, 1);
    999         }
    1000 
    1001         /* Memory-size editor created in the .ui file. */
    1002         AssertPtrReturnVoid(m_pEditorVideoMemorySize);
    1003         {
    1004             /* Configure editor: */
    1005             uiCommon().setMinimumWidthAccordingSymbolCount(m_pEditorVideoMemorySize, 7);
    1006             m_pEditorVideoMemorySize->setMinimum(m_iMinVRAM);
    1007             m_pEditorVideoMemorySize->setMaximum(m_iMaxVRAMVisible);
     986        /* Video-memory label and editor created in the .ui file. */
     987        AssertPtrReturnVoid(m_pVideoMemoryLabel);
     988        AssertPtrReturnVoid(m_pVideoMemoryEditor);
     989        {
     990            /* Configure label & editor: */
     991            m_pVideoMemoryLabel->setBuddy(m_pVideoMemoryEditor->focusProxy());
    1008992        }
    1009993
     
    10321016            m_pEditorVideoScreenCount->setMinimum(1);
    10331017            m_pEditorVideoScreenCount->setMaximum(cMaxGuestScreens);
    1034         }
    1035 
    1036         /* Scale-factor editor created in the .ui file. */
    1037         AssertPtrReturnVoid(m_pScaleFactorEditor);
    1038         {
    1039             /* Configure editor: */
    1040             m_pScaleFactorEditor->setSpinBoxWidthHint(m_pEditorVideoMemorySize->minimumWidth());
    10411018        }
    10421019
     
    12181195{
    12191196    /* Configure 'Screen' connections: */
    1220     connect(m_pSliderVideoMemorySize, SIGNAL(valueChanged(int)), this, SLOT(sltHandleVideoMemorySizeSliderChange()));
    1221     connect(m_pEditorVideoMemorySize, SIGNAL(valueChanged(int)), this, SLOT(sltHandleVideoMemorySizeEditorChange()));
     1197    connect(m_pVideoMemoryEditor, &UIVideoMemoryEditor::sigValidChanged, this, &UIMachineSettingsDisplay::revalidate);
    12221198    connect(m_pSliderVideoScreenCount, SIGNAL(valueChanged(int)), this, SLOT(sltHandleGuestScreenCountSliderChange()));
    12231199    connect(m_pEditorVideoScreenCount, SIGNAL(valueChanged(int)), this, SLOT(sltHandleGuestScreenCountEditorChange()));
     1200    connect(m_pComboGraphicsControllerType, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
     1201            this, &UIMachineSettingsDisplay::sltHandleGraphicsControllerComboChange);
    12241202#ifdef VBOX_WITH_CRHGSMI
    12251203    connect(m_pCheckbox3D, &QCheckBox::stateChanged,
    1226             this, &UIMachineSettingsDisplay::revalidate);
     1204            this, &UIMachineSettingsDisplay::sltHandle3DAccelerationCheckboxChange);
    12271205#endif
    12281206#ifdef VBOX_WITH_VIDEOHWACCEL
    12291207    connect(m_pCheckbox2DVideo, &QCheckBox::stateChanged,
    1230             this, &UIMachineSettingsDisplay::revalidate);
     1208            this, &UIMachineSettingsDisplay::sltHandle2DVideoAccelerationCheckboxChange);
    12311209#endif
    12321210
     
    12571235}
    12581236
    1259 void UIMachineSettingsDisplay::checkVRAMRequirements()
    1260 {
    1261     /* Make sure guest OS type is set: */
    1262     if (m_comGuestOSType.isNull())
    1263         return;
    1264 
    1265     /* Get monitors count and base video memory requirements: */
    1266     const int cGuestScreenCount = m_pEditorVideoScreenCount->value();
    1267     quint64 uNeedMBytes = UICommon::requiredVideoMemory(m_comGuestOSType.GetId(), cGuestScreenCount) / _1M;
    1268 
    1269     /* Initial value: */
    1270     m_iMaxVRAMVisible = cGuestScreenCount * 32;
    1271 
    1272     /* No more than m_iMaxVRAM: */
    1273     if (m_iMaxVRAMVisible > m_iMaxVRAM)
    1274         m_iMaxVRAMVisible = m_iMaxVRAM;
    1275 
    1276     /* No less than 128MB (if possible): */
    1277     if (m_iMaxVRAMVisible < 128 && m_iMaxVRAM >= 128)
    1278         m_iMaxVRAMVisible = 128;
    1279 
    1280     /* No less than initial VRAM size (wtf?): */
    1281     if (m_iMaxVRAMVisible < m_iInitialVRAM)
    1282         m_iMaxVRAMVisible = m_iInitialVRAM;
    1283 
    1284 #ifdef VBOX_WITH_VIDEOHWACCEL
    1285     if (m_pCheckbox2DVideo->isChecked() && m_f2DVideoAccelerationSupported)
    1286     {
    1287         uNeedMBytes += VBox2DHelpers::required2DOffscreenVideoMemory() / _1M;
    1288     }
    1289 #endif
    1290 
    1291 #ifdef VBOX_WITH_CRHGSMI
    1292     if (m_pCheckbox3D->isChecked() && m_fWddmModeSupported)
    1293     {
    1294         uNeedMBytes = qMax(uNeedMBytes, (quint64) 128);
    1295         /* No less than 256MB (if possible): */
    1296         if (m_iMaxVRAMVisible < 256 && m_iMaxVRAM >= 256)
    1297             m_iMaxVRAMVisible = 256;
    1298     }
    1299 #endif
    1300 
    1301     m_pEditorVideoMemorySize->setMaximum(m_iMaxVRAMVisible);
    1302     m_pSliderVideoMemorySize->setMaximum(m_iMaxVRAMVisible);
    1303     m_pSliderVideoMemorySize->setPageStep(calculatePageStep(m_iMaxVRAMVisible));
    1304     m_pSliderVideoMemorySize->setWarningHint(1, qMin((int)uNeedMBytes, m_iMaxVRAMVisible));
    1305     m_pSliderVideoMemorySize->setOptimalHint(qMin((int)uNeedMBytes, m_iMaxVRAMVisible), m_iMaxVRAMVisible);
    1306     m_pLabelVideoMemorySizeMax->setText(tr("%1 MB").arg(m_iMaxVRAMVisible));
    1307 }
    1308 
    13091237bool UIMachineSettingsDisplay::shouldWeWarnAboutLowVRAM()
    13101238{
     
    13171245
    13181246    return fResult;
    1319 }
    1320 
    1321 /* static */
    1322 int UIMachineSettingsDisplay::calculatePageStep(int iMax)
    1323 {
    1324     /* Reasonable max. number of page steps is 32. */
    1325     uint uPage = ((uint)iMax + 31) / 32;
    1326     /* Make it a power of 2: */
    1327     uint uP = uPage, p2 = 0x1;
    1328     while ((uP >>= 1))
    1329         p2 <<= 1;
    1330     if (uPage != p2)
    1331         p2 <<= 1;
    1332     if (p2 < 4)
    1333         p2 = 4;
    1334     return (int)p2;
    13351247}
    13361248
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsDisplay.h

    r80042 r80043  
    8888private slots:
    8989
    90     /** Handles Video Memory size slider change. */
    91     void sltHandleVideoMemorySizeSliderChange();
    92     /** Handles Video Memory size editor change. */
    93     void sltHandleVideoMemorySizeEditorChange();
    9490    /** Handles Guest Screen count slider change. */
    9591    void sltHandleGuestScreenCountSliderChange();
    9692    /** Handles Guest Screen count editor change. */
    9793    void sltHandleGuestScreenCountEditorChange();
     94    /** Handles Graphics Controller combo change. */
     95    void sltHandleGraphicsControllerComboChange();
     96#ifdef VBOX_WITH_CRHGSMI
     97    /** Handles 3D Acceleration check-box change. */
     98    void sltHandle3DAccelerationCheckboxChange();
     99#endif
     100#ifdef VBOX_WITH_VIDEOHWACCEL
     101    /** Handles 2D Video Acceleration check-box change. */
     102    void sltHandle2DVideoAccelerationCheckboxChange();
     103#endif
    98104
    99105    /** Handles recording toggle. */
     
    130136    void cleanup();
    131137
    132     /** Checks the VRAM requirements. */
    133     void checkVRAMRequirements();
    134138    /** Returns whether the VRAM requirements are important. */
    135139    bool shouldWeWarnAboutLowVRAM();
    136     /** Calculates the reasonably sane slider page step. */
    137     static int calculatePageStep(int iMax);
    138140
    139141    /** Searches for corresponding frame size preset. */
     
    162164    /** Holds the guest OS type ID. */
    163165    CGuestOSType  m_comGuestOSType;
    164     /** Holds the minimum lower limit of VRAM (MiB). */
    165     int           m_iMinVRAM;
    166     /** Holds the maximum upper limit of VRAM (MiB). */
    167     int           m_iMaxVRAM;
    168     /** Holds the upper limit of VRAM (MiB) for this dialog.
    169       * This value is lower than m_iMaxVRAM to save careless
    170       * users from setting useless big values. */
    171     int           m_iMaxVRAMVisible;
    172     /** Holds the initial VRAM value when the dialog is opened. */
    173     int           m_iInitialVRAM;
    174166#ifdef VBOX_WITH_CRHGSMI
    175167    /** Holds whether the guest OS supports WDDM. */
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsDisplay.ui

    r76184 r80043  
    3535         <layout class="QGridLayout" name="m_pLayoutContainerVideo">
    3636          <item row="0" column="0">
    37            <widget class="QLabel" name="m_pLabelVideoMemorySize">
     37           <widget class="QLabel" name="m_pVideoMemoryLabel">
    3838            <property name="text">
    3939             <string>Video &amp;Memory:</string>
     
    4242             <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
    4343            </property>
    44             <property name="buddy">
    45              <cstring>m_pEditorVideoMemorySize</cstring>
    46             </property>
    47            </widget>
    48           </item>
    49           <item row="0" column="1" rowspan="2">
    50            <layout class="QGridLayout" name="m_pLayoutVideoMemorySizeSlider">
    51             <property name="spacing">
    52              <number>0</number>
    53             </property>
    54             <item row="0" column="0" colspan="3">
    55              <widget class="QIAdvancedSlider" name="m_pSliderVideoMemorySize">
    56               <property name="whatsThis">
    57                <string>Controls the amount of video memory provided to the virtual machine.</string>
    58               </property>
    59               <property name="orientation">
    60                <enum>Qt::Horizontal</enum>
    61               </property>
    62              </widget>
    63             </item>
    64             <item row="1" column="0">
    65              <widget class="QLabel" name="m_pLabelVideoMemorySizeMin"/>
    66             </item>
    67             <item row="1" column="1">
    68              <spacer name="m_pSpacerVideoMemorySize">
    69               <property name="orientation">
    70                <enum>Qt::Horizontal</enum>
    71               </property>
    72               <property name="sizeHint" stdset="0">
    73                <size>
    74                 <width>0</width>
    75                 <height>0</height>
    76                </size>
    77               </property>
    78              </spacer>
    79             </item>
    80             <item row="1" column="2">
    81              <widget class="QLabel" name="m_pLabelVideoMemorySizeMax"/>
    82             </item>
    83            </layout>
    84           </item>
    85           <item row="0" column="2">
    86            <widget class="QSpinBox" name="m_pEditorVideoMemorySize">
     44           </widget>
     45          </item>
     46          <item row="0" column="1" rowspan="2" colspan="2">
     47           <widget class="UIVideoMemoryEditor" name="m_pVideoMemoryEditor">
    8748            <property name="whatsThis">
    8849             <string>Controls the amount of video memory provided to the virtual machine.</string>
     
    817778   <header>UIScaleFactorEditor.h</header>
    818779  </customwidget>
     780  <customwidget>
     781   <class>UIVideoMemoryEditor</class>
     782   <extends>QWidget</extends>
     783   <header>UIVideoMemoryEditor.h</header>
     784  </customwidget>
    819785 </customwidgets>
    820786 <resources/>
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIVideoMemoryEditor.cpp

    r79996 r80043  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIBaseMemoryEditor class implementation.
     3 * VBox Qt GUI - UIVideoMemoryEditor class implementation.
    44 */
    55
     
    2424
    2525/* GUI includes: */
    26 #include "UIBaseMemoryEditor.h"
    27 #include "UIBaseMemorySlider.h"
    28 
    29 
    30 UIBaseMemoryEditor::UIBaseMemoryEditor(QWidget *pParent /* = 0 */, bool fWithLabel /* = false */)
     26#include "QIAdvancedSlider.h"
     27#include "UICommon.h"
     28#include "UIVideoMemoryEditor.h"
     29#include "VBox2DHelpers.h"
     30
     31/* COM includes: */
     32#include "CSystemProperties.h"
     33
     34
     35UIVideoMemoryEditor::UIVideoMemoryEditor(QWidget *pParent /* = 0 */, bool fWithLabel /* = false */)
    3136    : QIWithRetranslateUI<QWidget>(pParent)
    3237    , m_fWithLabel(fWithLabel)
     38    , m_comGuestOSType(CGuestOSType())
     39    , m_cGuestScreenCount(1)
     40    , m_enmGraphicsControllerType(KGraphicsControllerType_Null)
     41#ifdef VBOX_WITH_CRHGSMI
     42    , m_f3DAccelerationSupported(false)
     43    , m_f3DAccelerationEnabled(false)
     44#endif
     45#ifdef VBOX_WITH_VIDEOHWACCEL
     46    , m_f2DVideoAccelerationSupported(false)
     47    , m_f2DVideoAccelerationEnabled(false)
     48#endif
     49    , m_iMinVRAM(0)
     50    , m_iMaxVRAM(0)
     51    , m_iMaxVRAMVisible(0)
     52    , m_iInitialVRAM(0)
    3353    , m_pLabelMemory(0)
    3454    , m_pSlider(0)
     
    4060}
    4161
    42 void UIBaseMemoryEditor::setValue(int iValue)
     62void UIVideoMemoryEditor::setValue(int iValue)
    4363{
    4464    if (m_pSlider)
    45         m_pSlider->setValue(iValue);
    46 }
    47 
    48 int UIBaseMemoryEditor::value() const
     65    {
     66        m_iInitialVRAM = RT_MIN(iValue, m_iMaxVRAM);
     67        m_pSlider->setValue(m_iInitialVRAM);
     68    }
     69}
     70
     71int UIVideoMemoryEditor::value() const
    4972{
    5073    return m_pSlider ? m_pSlider->value() : 0;
    5174}
    5275
    53 uint UIBaseMemoryEditor::maxRAMOpt() const
    54 {
    55     return m_pSlider ? m_pSlider->maxRAMOpt() : 0;
    56 }
    57 
    58 uint UIBaseMemoryEditor::maxRAMAlw() const
    59 {
    60     return m_pSlider ? m_pSlider->maxRAMAlw() : 0;
    61 }
    62 
    63 void UIBaseMemoryEditor::retranslateUi()
     76void UIVideoMemoryEditor::setGuestOSType(const CGuestOSType &comGuestOSType)
     77{
     78    /* Check if guest OS type really changed: */
     79    if (m_comGuestOSType == comGuestOSType)
     80        return;
     81
     82    /* Remember new guest OS type: */
     83    m_comGuestOSType = comGuestOSType;
     84
     85    /* Update requirements: */
     86    updateRequirements();
     87}
     88
     89void UIVideoMemoryEditor::setGuestScreenCount(int cGuestScreenCount)
     90{
     91    /* Check if guest screen count really changed: */
     92    if (m_cGuestScreenCount == cGuestScreenCount)
     93        return;
     94
     95    /* Remember new guest screen count: */
     96    m_cGuestScreenCount = cGuestScreenCount;
     97
     98    /* Update requirements: */
     99    updateRequirements();
     100}
     101
     102void UIVideoMemoryEditor::setGraphicsControllerType(const KGraphicsControllerType &enmGraphicsControllerType)
     103{
     104    /* Check if graphics controller type really changed: */
     105    if (m_enmGraphicsControllerType == enmGraphicsControllerType)
     106        return;
     107
     108    /* Remember new graphics controller type: */
     109    m_enmGraphicsControllerType = enmGraphicsControllerType;
     110
     111    /* Update requirements: */
     112    updateRequirements();
     113}
     114
     115#ifdef VBOX_WITH_CRHGSMI
     116void UIVideoMemoryEditor::set3DAccelerationSupported(bool fSupported)
     117{
     118    /* Check if 3D acceleration really changed: */
     119    if (m_f3DAccelerationSupported == fSupported)
     120        return;
     121
     122    /* Remember new 3D acceleration: */
     123    m_f3DAccelerationSupported = fSupported;
     124
     125    /* Update requirements: */
     126    updateRequirements();
     127}
     128
     129void UIVideoMemoryEditor::set3DAccelerationEnabled(bool fEnabled)
     130{
     131    /* Check if 3D acceleration really changed: */
     132    if (m_f3DAccelerationEnabled == fEnabled)
     133        return;
     134
     135    /* Remember new 3D acceleration: */
     136    m_f3DAccelerationEnabled = fEnabled;
     137
     138    /* Update requirements: */
     139    updateRequirements();
     140}
     141#endif /* VBOX_WITH_CRHGSMI */
     142
     143#ifdef VBOX_WITH_VIDEOHWACCEL
     144void UIVideoMemoryEditor::set2DVideoAccelerationSupported(bool fSupported)
     145{
     146    /* Check if 2D video acceleration really changed: */
     147    if (m_f2DVideoAccelerationSupported == fSupported)
     148        return;
     149
     150    /* Remember new 2D video acceleration: */
     151    m_f2DVideoAccelerationSupported = fSupported;
     152
     153    /* Update requirements: */
     154    updateRequirements();
     155}
     156
     157void UIVideoMemoryEditor::set2DVideoAccelerationEnabled(bool fEnabled)
     158{
     159    /* Check if 2D video acceleration really changed: */
     160    if (m_f2DVideoAccelerationEnabled == fEnabled)
     161        return;
     162
     163    /* Remember new 2D video acceleration: */
     164    m_f2DVideoAccelerationEnabled = fEnabled;
     165
     166    /* Update requirements: */
     167    updateRequirements();
     168}
     169#endif /* VBOX_WITH_VIDEOHWACCEL */
     170
     171void UIVideoMemoryEditor::retranslateUi()
    64172{
    65173    if (m_pLabelMemory)
    66         m_pLabelMemory->setText(tr("Base &Memory:"));
     174        m_pLabelMemory->setText(tr("Video &Memory:"));
    67175    if (m_pLabelMemoryMin)
    68         m_pLabelMemoryMin->setText(tr("%1 MB").arg(m_pSlider->minRAM()));
     176        m_pLabelMemoryMin->setText(tr("%1 MB").arg(m_iMinVRAM));
    69177    if (m_pLabelMemoryMax)
    70         m_pLabelMemoryMax->setText(tr("%1 MB").arg(m_pSlider->maxRAM()));
     178        m_pLabelMemoryMax->setText(tr("%1 MB").arg(m_iMaxVRAMVisible));
    71179    if (m_pSpinBox)
    72180        m_pSpinBox->setSuffix(QString(" %1").arg(tr("MB")));
    73181}
    74182
    75 void UIBaseMemoryEditor::sltHandleSliderChange()
     183void UIVideoMemoryEditor::sltHandleSliderChange()
    76184{
    77185    /* Apply spin-box value keeping it's signals disabled: */
     
    87195}
    88196
    89 void UIBaseMemoryEditor::sltHandleSpinBoxChange()
     197void UIVideoMemoryEditor::sltHandleSpinBoxChange()
    90198{
    91199    /* Apply slider value keeping it's signals disabled: */
     
    101209}
    102210
    103 void UIBaseMemoryEditor::prepare()
    104 {
     211void UIVideoMemoryEditor::prepare()
     212{
     213    /* Prepare common variables: */
     214    const CSystemProperties comProperties = uiCommon().virtualBox().GetSystemProperties();
     215    m_iMinVRAM = comProperties.GetMinGuestVRAM();
     216    m_iMaxVRAM = comProperties.GetMaxGuestVRAM();
     217    m_iMaxVRAMVisible = m_iMaxVRAM;
     218
    105219    /* Create main layout: */
    106220    QGridLayout *pMainLayout = new QGridLayout(this);
     
    123237
    124238            /* Create memory slider: */
    125             m_pSlider = new UIBaseMemorySlider(this);
     239            m_pSlider = new QIAdvancedSlider(this);
    126240            if (m_pSlider)
    127241            {
     242                m_pSlider->setMinimum(m_iMinVRAM);
     243                m_pSlider->setMaximum(m_iMaxVRAMVisible);
     244                m_pSlider->setPageStep(calculatePageStep(m_iMaxVRAMVisible));
     245                m_pSlider->setSingleStep(m_pSlider->pageStep() / 4);
     246                m_pSlider->setTickInterval(m_pSlider->pageStep());
     247                m_pSlider->setSnappingEnabled(true);
     248                m_pSlider->setErrorHint(0, 1);
    128249                m_pSlider->setMinimumWidth(150);
    129                 connect(m_pSlider, &UIBaseMemorySlider::valueChanged,
    130                         this, &UIBaseMemoryEditor::sltHandleSliderChange);
     250                connect(m_pSlider, &QIAdvancedSlider::valueChanged,
     251                        this, &UIVideoMemoryEditor::sltHandleSliderChange);
    131252                pSliderLayout->addWidget(m_pSlider);
    132253            }
     
    166287            if (m_pLabelMemory)
    167288                m_pLabelMemory->setBuddy(m_pSpinBox);
    168             m_pSpinBox->setMinimum(m_pSlider->minRAM());
    169             m_pSpinBox->setMaximum(m_pSlider->maxRAM());
     289            m_pSpinBox->setMinimum(m_iMinVRAM);
     290            m_pSpinBox->setMaximum(m_iMaxVRAMVisible);
    170291            connect(m_pSpinBox, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged),
    171                     this, &UIBaseMemoryEditor::sltHandleSpinBoxChange);
     292                    this, &UIVideoMemoryEditor::sltHandleSpinBoxChange);
    172293            pMainLayout->addWidget(m_pSpinBox, 0, iRow++, 1, 1);
    173294        }
     
    178299}
    179300
    180 void UIBaseMemoryEditor::revalidate()
    181 {
     301void UIVideoMemoryEditor::updateRequirements()
     302{
     303    /* Make sure guest OS type is set: */
     304    if (m_comGuestOSType.isNull())
     305        return;
     306
     307    /* Get monitors count and base video memory requirements: */
     308    quint64 uNeedMBytes = UICommon::requiredVideoMemory(m_comGuestOSType.GetId(), m_cGuestScreenCount) / _1M;
     309
     310    /* Initial value: */
     311    m_iMaxVRAMVisible = m_cGuestScreenCount * 32;
     312
     313    /* No more than m_iMaxVRAM: */
     314    if (m_iMaxVRAMVisible > m_iMaxVRAM)
     315        m_iMaxVRAMVisible = m_iMaxVRAM;
     316
     317    /* No less than 128MB (if possible): */
     318    if (m_iMaxVRAMVisible < 128 && m_iMaxVRAM >= 128)
     319        m_iMaxVRAMVisible = 128;
     320
     321    /* No less than initial VRAM size (wtf?): */
     322    if (m_iMaxVRAMVisible < m_iInitialVRAM)
     323        m_iMaxVRAMVisible = m_iInitialVRAM;
     324
     325#ifdef VBOX_WITH_CRHGSMI
     326    if (m_f3DAccelerationEnabled && m_f3DAccelerationSupported)
     327    {
     328        uNeedMBytes = qMax(uNeedMBytes, (quint64)128);
     329        /* No less than 256MB (if possible): */
     330        if (m_iMaxVRAMVisible < 256 && m_iMaxVRAM >= 256)
     331            m_iMaxVRAMVisible = 256;
     332    }
     333#endif
     334
     335#ifdef VBOX_WITH_VIDEOHWACCEL
     336    if (m_f2DVideoAccelerationEnabled && m_f2DVideoAccelerationSupported)
     337    {
     338        uNeedMBytes += VBox2DHelpers::required2DOffscreenVideoMemory() / _1M;
     339    }
     340#endif
     341
     342    if (m_pSpinBox)
     343        m_pSpinBox->setMaximum(m_iMaxVRAMVisible);
    182344    if (m_pSlider)
    183         emit sigValidChanged(m_pSlider->value() < (int)m_pSlider->maxRAMAlw());
    184 }
     345    {
     346        m_pSlider->setMaximum(m_iMaxVRAMVisible);
     347        m_pSlider->setPageStep(calculatePageStep(m_iMaxVRAMVisible));
     348        m_pSlider->setWarningHint(1, qMin((int)uNeedMBytes, m_iMaxVRAMVisible));
     349        m_pSlider->setOptimalHint(qMin((int)uNeedMBytes, m_iMaxVRAMVisible), m_iMaxVRAMVisible);
     350    }
     351    if (m_pLabelMemoryMax)
     352        m_pLabelMemoryMax->setText(tr("%1 MB").arg(m_iMaxVRAMVisible));
     353}
     354
     355void UIVideoMemoryEditor::revalidate()
     356{
     357    if (m_pSlider)
     358        emit sigValidChanged(   m_enmGraphicsControllerType == KGraphicsControllerType_Null
     359                             || m_pSlider->value() > 0);
     360}
     361
     362/* static */
     363int UIVideoMemoryEditor::calculatePageStep(int iMax)
     364{
     365    /* Reasonable max. number of page steps is 32. */
     366    const uint uPage = ((uint)iMax + 31) / 32;
     367    /* Make it a power of 2: */
     368    uint uP = uPage, p2 = 0x1;
     369    while ((uP >>= 1))
     370        p2 <<= 1;
     371    if (uPage != p2)
     372        p2 <<= 1;
     373    if (p2 < 4)
     374        p2 = 4;
     375    return (int)p2;
     376}
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIVideoMemoryEditor.h

    r79996 r80043  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIBaseMemoryEditor class declaration.
     3 * VBox Qt GUI - UIVideoMemoryEditor class declaration.
    44 */
    55
     
    1616 */
    1717
    18 #ifndef FEQT_INCLUDED_SRC_widgets_UIBaseMemoryEditor_h
    19 #define FEQT_INCLUDED_SRC_widgets_UIBaseMemoryEditor_h
     18#ifndef FEQT_INCLUDED_SRC_widgets_UIVideoMemoryEditor_h
     19#define FEQT_INCLUDED_SRC_widgets_UIVideoMemoryEditor_h
    2020#ifndef RT_WITHOUT_PRAGMA_ONCE
    2121# pragma once
     
    2929#include "UILibraryDefs.h"
    3030
     31/* COM includes: */
     32#include "COMEnums.h"
     33#include "CGuestOSType.h"
     34
    3135/* Forward declarations: */
    3236class QLabel;
    3337class QSpinBox;
    34 class UIBaseMemorySlider;
     38class QIAdvancedSlider;
    3539
    36 /** QWidget subclass used as a base memory editor. */
    37 class SHARED_LIBRARY_STUFF UIBaseMemoryEditor : public QIWithRetranslateUI<QWidget>
     40/** QWidget subclass used as a video memory editor. */
     41class SHARED_LIBRARY_STUFF UIVideoMemoryEditor : public QIWithRetranslateUI<QWidget>
    3842{
    3943    Q_OBJECT;
     
    4650public:
    4751
    48     /** Constructs base-memory editor passing @a pParent to the base-class.
     52    /** Constructs video-memory editor passing @a pParent to the base-class.
    4953      * @param  fWithLabel  Brings whether we should add label ourselves. */
    50     UIBaseMemoryEditor(QWidget *pParent = 0, bool fWithLabel = false);
     54    UIVideoMemoryEditor(QWidget *pParent = 0, bool fWithLabel = false);
    5155
    5256    /** Defines editor @a iValue. */
     
    5559    int value() const;
    5660
    57     /** Returns the maximum optimal RAM. */
    58     uint maxRAMOpt() const;
    59     /** Returns the maximum allowed RAM. */
    60     uint maxRAMAlw() const;
     61    /** Defines @a comGuestOSType. */
     62    void setGuestOSType(const CGuestOSType &comGuestOSType);
     63
     64    /** Defines @a cGuestScreenCount. */
     65    void setGuestScreenCount(int cGuestScreenCount);
     66
     67    /** Defines @a enmGraphicsControllerType. */
     68    void setGraphicsControllerType(const KGraphicsControllerType &enmGraphicsControllerType);
     69
     70#ifdef VBOX_WITH_CRHGSMI
     71    /** Defines whether 3D acceleration is @a fSupported. */
     72    void set3DAccelerationSupported(bool fSupported);
     73    /** Defines whether 3D acceleration is @a fEnabled. */
     74    void set3DAccelerationEnabled(bool fEnabled);
     75#endif
     76
     77#ifdef VBOX_WITH_VIDEOHWACCEL
     78    /** Defines whether 2D video acceleration is @a fSupported. */
     79    void set2DVideoAccelerationSupported(bool fSupported);
     80    /** Defines whether 2D video acceleration is @a fEnabled. */
     81    void set2DVideoAccelerationEnabled(bool fEnabled);
     82#endif
    6183
    6284protected:
     
    7799    void prepare();
    78100
     101    /** Update requirements. */
     102    void updateRequirements();
     103
    79104    /** Revalidates and emits validity change signal. */
    80105    void revalidate();
     106
     107    /** Calculates the reasonably sane slider page step. */
     108    static int calculatePageStep(int iMax);
    81109
    82110    /** Holds whether descriptive label should be created. */
    83111    bool  m_fWithLabel;
    84112
     113    /** Holds the guest OS type ID. */
     114    CGuestOSType             m_comGuestOSType;
     115    /** Holds the guest screen count. */
     116    int                      m_cGuestScreenCount;
     117    /** Holds the graphics controller type. */
     118    KGraphicsControllerType  m_enmGraphicsControllerType;
     119#ifdef VBOX_WITH_CRHGSMI
     120    /** Holds whether 3D acceleration is supported. */
     121    bool                     m_f3DAccelerationSupported;
     122    /** Holds whether 3D acceleration is enabled. */
     123    bool                     m_f3DAccelerationEnabled;
     124#endif
     125#ifdef VBOX_WITH_VIDEOHWACCEL
     126    /** Holds whether 2D video acceleration is supported. */
     127    bool                     m_f2DVideoAccelerationSupported;
     128    /** Holds whether 2D video acceleration is enabled. */
     129    bool                     m_f2DVideoAccelerationEnabled;
     130#endif
     131
     132    /** Holds the minimum lower limit of VRAM (MiB). */
     133    int  m_iMinVRAM;
     134    /** Holds the maximum upper limit of VRAM (MiB). */
     135    int  m_iMaxVRAM;
     136    /** Holds the upper limit of VRAM (MiB) for this dialog.
     137      * @note This value is lower than m_iMaxVRAM to save
     138      *       careless users from setting useless big values. */
     139    int  m_iMaxVRAMVisible;
     140    /** Holds the initial VRAM value when the dialog is opened. */
     141    int  m_iInitialVRAM;
     142
    85143    /** Holds the memory label instance. */
    86     QLabel             *m_pLabelMemory;
     144    QLabel           *m_pLabelMemory;
    87145    /** Holds the memory slider instance. */
    88     UIBaseMemorySlider *m_pSlider;
     146    QIAdvancedSlider *m_pSlider;
    89147    /** Holds minimum memory label instance. */
    90     QLabel             *m_pLabelMemoryMin;
     148    QLabel           *m_pLabelMemoryMin;
    91149    /** Holds maximum memory label instance. */
    92     QLabel             *m_pLabelMemoryMax;
     150    QLabel           *m_pLabelMemoryMax;
    93151    /** Holds the memory spin-box instance. */
    94     QSpinBox           *m_pSpinBox;
     152    QSpinBox         *m_pSpinBox;
    95153};
    96154
    97 #endif /* !FEQT_INCLUDED_SRC_widgets_UIBaseMemoryEditor_h */
     155#endif /* !FEQT_INCLUDED_SRC_widgets_UIVideoMemoryEditor_h */
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette