VirtualBox

Changeset 71943 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Apr 20, 2018 1:55:21 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9049: Full and heavy cleanup for VBoxGuestRAMSlider, renaming it to UIGuestRAMSlider and move it to VBoxGlobal library.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
6 edited
2 moved

Legend:

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

    r71942 r71943  
    679679        src/widgets/UIFilePathSelector.h \
    680680        src/widgets/UIFilmContainer.h \
     681        src/widgets/UIGuestRAMSlider.h \
    681682        src/widgets/UIHostComboEditor.h \
    682683        src/widgets/UIHotKeyEditor.h \
     
    776777        src/widgets/UIFilePathSelector.h \
    777778        src/widgets/UIFilmContainer.h \
     779        src/widgets/UIGuestRAMSlider.h \
    778780        src/widgets/UIHostComboEditor.h \
    779781        src/widgets/UIHotKeyEditor.h \
     
    10561058        src/widgets/UISlidingWidget.cpp \
    10571059        src/widgets/UITabBar.cpp \
    1058         src/widgets/VBoxGuestRAMSlider.cpp \
    10591060        src/widgets/VBoxMediaComboBox.cpp \
    10601061        src/widgets/UIMenuToolBar.cpp \
     
    12151216        src/widgets/UIFilePathSelector.cpp \
    12161217        src/widgets/UIFilmContainer.cpp \
     1218        src/widgets/UIGuestRAMSlider.cpp \
    12171219        src/widgets/UIHostComboEditor.cpp \
    12181220        src/widgets/UIHotKeyEditor.cpp \
     
    13381340        src/widgets/UIFilePathSelector.cpp \
    13391341        src/widgets/UIFilmContainer.cpp \
     1342        src/widgets/UIGuestRAMSlider.cpp \
    13401343        src/widgets/UIHostComboEditor.cpp \
    13411344        src/widgets/UIHotKeyEditor.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/precomp.h

    r70824 r71943  
    639639#include "UIFilePathSelector.h"
    640640#include "VBoxGlobal.h"
    641 #include "VBoxGuestRAMSlider.h"
     641#include "UIGuestRAMSlider.h"
    642642//#include "VBoxIChatTheaterWrapper.h"
    643643#include "VBoxLicenseViewer.h"
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSystem.ui

    r71027 r71943  
    4949          </property>
    5050          <item>
    51            <widget class="VBoxGuestRAMSlider" name="m_pSliderMemorySize">
     51           <widget class="UIGuestRAMSlider" name="m_pSliderMemorySize">
    5252            <property name="whatsThis">
    5353             <string>Controls the amount of memory provided to the virtual machine. If you assign too much, the machine might not start.</string>
     
    658658  </customwidget>
    659659  <customwidget>
    660    <class>VBoxGuestRAMSlider</class>
     660   <class>UIGuestRAMSlider</class>
    661661   <extends>QIAdvancedSlider</extends>
    662    <header>VBoxGuestRAMSlider.h</header>
     662   <header>UIGuestRAMSlider.h</header>
    663663  </customwidget>
    664664  <customwidget>
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIGuestRAMSlider.cpp

    r71942 r71943  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - VirtualBox Qt extensions: VBoxGuestRAMSlider class implementation.
     3 * VBox Qt GUI - UIGuestRAMSlider class implementation.
    44 */
    55
    66/*
    7  * Copyright (C) 2009-2017 Oracle Corporation
     7 * Copyright (C) 2009-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121
    2222/* GUI includes: */
    23 # include "VBoxGuestRAMSlider.h"
    2423# include "VBoxGlobal.h"
     24# include "UIGuestRAMSlider.h"
    2525
    2626/* COM includes: */
     
    3030
    3131
    32 VBoxGuestRAMSlider::VBoxGuestRAMSlider (QWidget *aParent /* = 0 */)
    33   : QIAdvancedSlider (aParent)
    34   , mMinRAM (0)
    35   , mMaxRAMOpt (0)
    36   , mMaxRAMAlw (0)
    37   , mMaxRAM (0)
     32UIGuestRAMSlider::UIGuestRAMSlider(QWidget *pParent /* = 0 */)
     33  : QIAdvancedSlider(pParent)
     34  , m_uMinRAM(0)
     35  , m_uMaxRAMOpt(0)
     36  , m_uMaxRAMAlw(0)
     37  , m_uMaxRAM(0)
    3838{
    39     init();
     39    /* Prepare: */
     40    prepare();
    4041}
    4142
    42 VBoxGuestRAMSlider::VBoxGuestRAMSlider (Qt::Orientation aOrientation, QWidget *aParent /* = 0 */)
    43   : QIAdvancedSlider (aOrientation, aParent)
    44   , mMinRAM (0)
    45   , mMaxRAMOpt (0)
    46   , mMaxRAMAlw (0)
    47   , mMaxRAM (0)
     43UIGuestRAMSlider::UIGuestRAMSlider(Qt::Orientation enmOrientation, QWidget *pParent /* = 0 */)
     44  : QIAdvancedSlider(enmOrientation, pParent)
     45  , m_uMinRAM(0)
     46  , m_uMaxRAMOpt(0)
     47  , m_uMaxRAMAlw(0)
     48  , m_uMaxRAM(0)
    4849{
    49     init();
     50    /* Prepare: */
     51    prepare();
    5052}
    5153
    52 uint VBoxGuestRAMSlider::minRAM() const
     54uint UIGuestRAMSlider::minRAM() const
    5355{
    54     return mMinRAM;
     56    return m_uMinRAM;
    5557}
    5658
    57 uint VBoxGuestRAMSlider::maxRAMOpt() const
     59uint UIGuestRAMSlider::maxRAMOpt() const
    5860{
    59     return mMaxRAMOpt;
     61    return m_uMaxRAMOpt;
    6062}
    6163
    62 uint VBoxGuestRAMSlider::maxRAMAlw() const
     64uint UIGuestRAMSlider::maxRAMAlw() const
    6365{
    64     return mMaxRAMAlw;
     66    return m_uMaxRAMAlw;
    6567}
    6668
    67 uint VBoxGuestRAMSlider::maxRAM() const
     69uint UIGuestRAMSlider::maxRAM() const
    6870{
    69     return mMaxRAM;
     71    return m_uMaxRAM;
    7072}
    7173
    72 void VBoxGuestRAMSlider::init()
     74void UIGuestRAMSlider::prepare()
    7375{
    74     ulong fullSize = vboxGlobal().host().GetMemorySize();
     76    ulong uFullSize = vboxGlobal().host().GetMemorySize();
    7577    CSystemProperties sys = vboxGlobal().virtualBox().GetSystemProperties();
    76     mMinRAM = sys.GetMinGuestRAM();
    77     mMaxRAM = RT_MIN (RT_ALIGN (fullSize, _1G / _1M), sys.GetMaxGuestRAM());
     78    m_uMinRAM = sys.GetMinGuestRAM();
     79    m_uMaxRAM = RT_MIN(RT_ALIGN(uFullSize, _1G / _1M), sys.GetMaxGuestRAM());
    7880
    7981    /* Come up with some nice round percent boundaries relative to
     
    105107     * Note. We might wanna put these calculations somewhere global later. */
    106108
    107     /* System RAM amount test */
    108     mMaxRAMAlw  = (uint)(0.75 * fullSize);
    109     mMaxRAMOpt  = (uint)(0.50 * fullSize);
    110     if (fullSize < 3072)
     109    /* System RAM amount test: */
     110    m_uMaxRAMAlw = (uint)(0.75 * uFullSize);
     111    m_uMaxRAMOpt = (uint)(0.50 * uFullSize);
     112    if (uFullSize < 3072)
    111113        /* done */;
    112     else if (fullSize < 4096)   /* 3GB */
    113         mMaxRAMAlw = (uint)(0.80 * fullSize);
    114     else if (fullSize < 6144)   /* 4-5GB */
     114    else if (uFullSize < 4096)   /* 3GB */
     115        m_uMaxRAMAlw = (uint)(0.80 * uFullSize);
     116    else if (uFullSize < 6144)   /* 4-5GB */
    115117    {
    116         mMaxRAMAlw = (uint)(0.84 * fullSize);
    117         mMaxRAMOpt = (uint)(0.60 * fullSize);
     118        m_uMaxRAMAlw = (uint)(0.84 * uFullSize);
     119        m_uMaxRAMOpt = (uint)(0.60 * uFullSize);
    118120    }
    119     else if (fullSize < 8192)   /* 6-7GB */
     121    else if (uFullSize < 8192)   /* 6-7GB */
    120122    {
    121         mMaxRAMAlw = (uint)(0.88 * fullSize);
    122         mMaxRAMOpt = (uint)(0.65 * fullSize);
     123        m_uMaxRAMAlw = (uint)(0.88 * uFullSize);
     124        m_uMaxRAMOpt = (uint)(0.65 * uFullSize);
    123125    }
    124     else if (fullSize < 16384)  /* 8-15GB */
     126    else if (uFullSize < 16384)  /* 8-15GB */
    125127    {
    126         mMaxRAMAlw = (uint)(0.90 * fullSize);
    127         mMaxRAMOpt = (uint)(0.70 * fullSize);
     128        m_uMaxRAMAlw = (uint)(0.90 * uFullSize);
     129        m_uMaxRAMOpt = (uint)(0.70 * uFullSize);
    128130    }
    129     else if (fullSize < 32768)  /* 16-31GB */
     131    else if (uFullSize < 32768)  /* 16-31GB */
    130132    {
    131         mMaxRAMAlw = (uint)(0.93 * fullSize);
    132         mMaxRAMOpt = (uint)(0.75 * fullSize);
     133        m_uMaxRAMAlw = (uint)(0.93 * uFullSize);
     134        m_uMaxRAMOpt = (uint)(0.75 * uFullSize);
    133135    }
    134     else if (fullSize < 65536)  /* 32-63GB */
     136    else if (uFullSize < 65536)  /* 32-63GB */
    135137    {
    136         mMaxRAMAlw = (uint)(0.94 * fullSize);
    137         mMaxRAMOpt = (uint)(0.80 * fullSize);
     138        m_uMaxRAMAlw = (uint)(0.94 * uFullSize);
     139        m_uMaxRAMOpt = (uint)(0.80 * uFullSize);
    138140    }
    139     else if (fullSize < 131072) /* 64-127GB */
     141    else if (uFullSize < 131072) /* 64-127GB */
    140142    {
    141         mMaxRAMAlw = (uint)(0.95 * fullSize);
    142         mMaxRAMOpt = (uint)(0.85 * fullSize);
     143        m_uMaxRAMAlw = (uint)(0.95 * uFullSize);
     144        m_uMaxRAMOpt = (uint)(0.85 * uFullSize);
    143145    }
    144146    else                        /* 128GB- */
    145147    {
    146         mMaxRAMAlw = (uint)(0.96 * fullSize);
    147         mMaxRAMOpt = (uint)(0.90 * fullSize);
     148        m_uMaxRAMAlw = (uint)(0.96 * uFullSize);
     149        m_uMaxRAMOpt = (uint)(0.90 * uFullSize);
    148150    }
    149151    /* Now check the calculated maximums are out of the range for the guest
    150152     * RAM. If so change it accordingly. */
    151     mMaxRAMAlw  = RT_MIN (mMaxRAMAlw, mMaxRAM);
    152     mMaxRAMOpt  = RT_MIN (mMaxRAMOpt, mMaxRAM);
     153    m_uMaxRAMAlw = RT_MIN(m_uMaxRAMAlw, m_uMaxRAM);
     154    m_uMaxRAMOpt = RT_MIN(m_uMaxRAMOpt, m_uMaxRAM);
    153155
    154     setPageStep (calcPageStep (mMaxRAM));
    155     setSingleStep (pageStep() / 4);
    156     setTickInterval (pageStep());
     156    setPageStep(calcPageStep(m_uMaxRAM));
     157    setSingleStep(pageStep() / 4);
     158    setTickInterval(pageStep());
    157159    /* Setup the scale so that ticks are at page step boundaries */
    158     setMinimum ((mMinRAM / pageStep()) * pageStep());
    159     setMaximum (mMaxRAM);
    160     setSnappingEnabled (true);
    161     setOptimalHint (mMinRAM, mMaxRAMOpt);
    162     setWarningHint (mMaxRAMOpt, mMaxRAMAlw);
    163     setErrorHint (mMaxRAMAlw, mMaxRAM);
     160    setMinimum((m_uMinRAM / pageStep()) * pageStep());
     161    setMaximum(m_uMaxRAM);
     162    setSnappingEnabled(true);
     163    setOptimalHint(m_uMinRAM, m_uMaxRAMOpt);
     164    setWarningHint(m_uMaxRAMOpt, m_uMaxRAMAlw);
     165    setErrorHint(m_uMaxRAMAlw, m_uMaxRAM);
    164166}
    165167
    166 /**
    167  *  Calculates a suitable page step size for the given max value. The returned
    168  *  size is so that there will be no more than 32 pages. The minimum returned
    169  *  page size is 4.
    170  */
    171 int VBoxGuestRAMSlider::calcPageStep (int aMax) const
     168int UIGuestRAMSlider::calcPageStep(int iMaximum) const
    172169{
    173     /* reasonable max. number of page steps is 32 */
    174     uint page = ((uint) aMax + 31) / 32;
    175     /* make it a power of 2 */
    176     uint p = page, p2 = 0x1;
     170    /* Calculate a suitable page step size for the given max value.
     171     * The returned size is so that there will be no more than 32
     172     * pages. The minimum returned page size is 4. */
     173
     174    /* Reasonable max. number of page steps is 32: */
     175    uint uPage = ((uint)iMaximum + 31) / 32;
     176    /* Make it a power of 2: */
     177    uint p = uPage, p2 = 0x1;
    177178    while ((p >>= 1))
    178179        p2 <<= 1;
    179     if (page != p2)
     180    if (uPage != p2)
    180181        p2 <<= 1;
    181182    if (p2 < 4)
     
    183184    return (int) p2;
    184185}
    185 
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIGuestRAMSlider.h

    r71942 r71943  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - VBoxGuestRAMSlider class declaration.
     3 * VBox Qt GUI - UIGuestRAMSlider class declaration.
    44 */
    55
    66/*
    7  * Copyright (C) 2009-2017 Oracle Corporation
     7 * Copyright (C) 2009-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1717
    1818
    19 #ifndef __VBoxGuestRAMSlider_h__
    20 #define __VBoxGuestRAMSlider_h__
     19#ifndef ___UIGuestRAMSlider_h___
     20#define ___UIGuestRAMSlider_h___
    2121
    22 /* VBox includes */
     22/* GUI includes: */
    2323#include "QIAdvancedSlider.h"
     24#include "UILibraryDefs.h"
    2425
    25 class VBoxGuestRAMSlider: public QIAdvancedSlider
     26/** QIAdvancedSlider subclass used as a guest RAM slider. */
     27class SHARED_LIBRARY_STUFF UIGuestRAMSlider : public QIAdvancedSlider
    2628{
     29    Q_OBJECT;
     30
    2731public:
    28     VBoxGuestRAMSlider (QWidget *aParent = 0);
    29     VBoxGuestRAMSlider (Qt::Orientation aOrientation, QWidget *aParent = 0);
    3032
     33    /** Constructs guest RAM slider passing @a pParent to the base-class. */
     34    UIGuestRAMSlider(QWidget *pParent = 0);
     35    /** Constructs guest RAM slider passing @a pParent and @a enmOrientation to the base-class. */
     36    UIGuestRAMSlider(Qt::Orientation enmOrientation, QWidget *pParent = 0);
     37
     38    /** Returns the minimum RAM. */
    3139    uint minRAM() const;
     40    /** Returns the maximum optimal RAM. */
    3241    uint maxRAMOpt() const;
     42    /** Returns the maximum allowed RAM. */
    3343    uint maxRAMAlw() const;
     44    /** Returns the maximum possible RAM. */
    3445    uint maxRAM() const;
    3546
    3647private:
    37     /* Private methods */
    38     void init();
    39     int calcPageStep (int aMax) const;
    4048
    41     /* Private member vars */
    42     uint mMinRAM;
    43     uint mMaxRAMOpt;
    44     uint mMaxRAMAlw;
    45     uint mMaxRAM;
     49    /** Prepares all. */
     50    void prepare();
     51
     52    /** Calculates page step for passed @a iMaximum value. */
     53    int calcPageStep(int iMaximum) const;
     54
     55    /** Holds the minimum RAM. */
     56    uint m_uMinRAM;
     57    /** Holds the maximum optimal RAM. */
     58    uint m_uMaxRAMOpt;
     59    /** Holds the maximum allowed RAM. */
     60    uint m_uMaxRAMAlw;
     61    /** Holds the maximum possible RAM. */
     62    uint m_uMaxRAM;
    4663};
    4764
    48 #endif /* __VBoxGuestRAMSlider_h__ */
    49 
     65#endif /* !___UIGuestRAMSlider_h___ */
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasic2.cpp

    r71027 r71943  
    3232# include "UIWizardNewVM.h"
    3333# include "VBoxGlobal.h"
    34 # include "VBoxGuestRAMSlider.h"
     34# include "UIGuestRAMSlider.h"
    3535# include "QIRichTextLabel.h"
    3636
     
    6666        QGridLayout *pMemoryLayout = new QGridLayout;
    6767        {
    68             m_pRamSlider = new VBoxGuestRAMSlider(this);
     68            m_pRamSlider = new UIGuestRAMSlider(this);
    6969            {
    7070                m_pRamSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
     
    102102
    103103    /* Setup connections: */
    104     connect(m_pRamSlider, &VBoxGuestRAMSlider::valueChanged,
     104    connect(m_pRamSlider, &UIGuestRAMSlider::valueChanged,
    105105            this, &UIWizardNewVMPageBasic2::sltRamSliderValueChanged);
    106106    connect(m_pRamEditor, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged),
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasic2.h

    r71027 r71943  
    2323
    2424/* Forward declarations: */
    25 class VBoxGuestRAMSlider;
     25class UIGuestRAMSlider;
    2626class QSpinBox;
    2727class QLabel;
     
    4141
    4242    /* Widgets: */
    43     VBoxGuestRAMSlider *m_pRamSlider;
     43    UIGuestRAMSlider *m_pRamSlider;
    4444    QSpinBox *m_pRamEditor;
    4545    QLabel *m_pRamMin;
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageExpert.cpp

    r71027 r71943  
    3636# include "UIIconPool.h"
    3737# include "UINameAndSystemEditor.h"
    38 # include "VBoxGuestRAMSlider.h"
     38# include "UIGuestRAMSlider.h"
    3939# include "VBoxMediaComboBox.h"
    4040# include "QIToolButton.h"
     
    6464            QGridLayout *pMemoryCntLayout = new QGridLayout(m_pMemoryCnt);
    6565            {
    66                 m_pRamSlider = new VBoxGuestRAMSlider(m_pMemoryCnt);
     66                m_pRamSlider = new UIGuestRAMSlider(m_pMemoryCnt);
    6767                {
    6868                    m_pRamSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
     
    140140    connect(m_pNameAndSystemEditor, &UINameAndSystemEditor::sigOsTypeChanged,
    141141            this, &UIWizardNewVMPageExpert::sltOsTypeChanged);
    142     connect(m_pRamSlider, &VBoxGuestRAMSlider::valueChanged,
     142    connect(m_pRamSlider, &UIGuestRAMSlider::valueChanged,
    143143            this, &UIWizardNewVMPageExpert::sltRamSliderValueChanged);
    144144    connect(m_pRamEditor, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged),
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