VirtualBox

Changeset 79996 in vbox


Ignore:
Timestamp:
Jul 26, 2019 11:12:25 AM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:7720: UIBaseMemoryEditor: A possibility to create editor without main label; This requires to integrate editor into settings dialog; Besides that, assertions replaced with ifs in more versatile approach.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/widgets
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIBaseMemoryEditor.cpp

    r79959 r79996  
    2727#include "UIBaseMemorySlider.h"
    2828
    29 /* Other VBox includes: */
    30 #include "iprt/assert.h"
    3129
    32 
    33 UIBaseMemoryEditor::UIBaseMemoryEditor(QWidget *pParent)
     30UIBaseMemoryEditor::UIBaseMemoryEditor(QWidget *pParent /* = 0 */, bool fWithLabel /* = false */)
    3431    : QIWithRetranslateUI<QWidget>(pParent)
     32    , m_fWithLabel(fWithLabel)
    3533    , m_pLabelMemory(0)
    3634    , m_pSlider(0)
     
    4442void UIBaseMemoryEditor::setValue(int iValue)
    4543{
    46     AssertPtrReturnVoid(m_pSlider);
    47     m_pSlider->setValue(iValue);
     44    if (m_pSlider)
     45        m_pSlider->setValue(iValue);
    4846}
    4947
    5048int UIBaseMemoryEditor::value() const
    5149{
    52     AssertPtrReturn(m_pSlider, 0);
    53     return m_pSlider->value();
     50    return m_pSlider ? m_pSlider->value() : 0;
     51}
     52
     53uint UIBaseMemoryEditor::maxRAMOpt() const
     54{
     55    return m_pSlider ? m_pSlider->maxRAMOpt() : 0;
     56}
     57
     58uint UIBaseMemoryEditor::maxRAMAlw() const
     59{
     60    return m_pSlider ? m_pSlider->maxRAMAlw() : 0;
    5461}
    5562
    5663void UIBaseMemoryEditor::retranslateUi()
    5764{
    58     AssertPtrReturnVoid(m_pSlider);
    59     AssertPtrReturnVoid(m_pSpinBox);
    60 
    61     m_pLabelMemory->setText(tr("Base &Memory:"));
    62     m_pLabelMemoryMin->setText(tr("%1 MB").arg(m_pSlider->minRAM()));
    63     m_pLabelMemoryMax->setText(tr("%1 MB").arg(m_pSlider->maxRAM()));
    64     m_pSpinBox->setSuffix(QString(" %1").arg(tr("MB")));
     65    if (m_pLabelMemory)
     66        m_pLabelMemory->setText(tr("Base &Memory:"));
     67    if (m_pLabelMemoryMin)
     68        m_pLabelMemoryMin->setText(tr("%1 MB").arg(m_pSlider->minRAM()));
     69    if (m_pLabelMemoryMax)
     70        m_pLabelMemoryMax->setText(tr("%1 MB").arg(m_pSlider->maxRAM()));
     71    if (m_pSpinBox)
     72        m_pSpinBox->setSuffix(QString(" %1").arg(tr("MB")));
    6573}
    6674
    6775void UIBaseMemoryEditor::sltHandleSliderChange()
    6876{
    69     AssertPtrReturnVoid(m_pSlider);
    70     AssertPtrReturnVoid(m_pSpinBox);
    71 
    7277    /* Apply spin-box value keeping it's signals disabled: */
    73     m_pSpinBox->blockSignals(true);
    74     m_pSpinBox->setValue(m_pSlider->value());
    75     m_pSpinBox->blockSignals(false);
     78    if (m_pSpinBox && m_pSlider)
     79    {
     80        m_pSpinBox->blockSignals(true);
     81        m_pSpinBox->setValue(m_pSlider->value());
     82        m_pSpinBox->blockSignals(false);
     83    }
    7684
    7785    /* Revalidate to send signal to listener: */
     
    8189void UIBaseMemoryEditor::sltHandleSpinBoxChange()
    8290{
    83     AssertPtrReturnVoid(m_pSlider);
    84     AssertPtrReturnVoid(m_pSpinBox);
    85 
    8691    /* Apply slider value keeping it's signals disabled: */
    87     m_pSlider->blockSignals(true);
    88     m_pSlider->setValue(m_pSpinBox->value());
    89     m_pSlider->blockSignals(false);
     92    if (m_pSpinBox && m_pSlider)
     93    {
     94        m_pSlider->blockSignals(true);
     95        m_pSlider->setValue(m_pSpinBox->value());
     96        m_pSlider->blockSignals(false);
     97    }
    9098
    9199    /* Revalidate to send signal to listener: */
     
    100108    {
    101109        pMainLayout->setContentsMargins(0, 0, 0, 0);
     110        int iRow = 0;
    102111
    103112        /* Create memory label: */
    104         m_pLabelMemory = new QLabel(this);
     113        if (m_fWithLabel)
     114            m_pLabelMemory = new QLabel(this);
    105115        if (m_pLabelMemory)
    106             pMainLayout->addWidget(m_pLabelMemory, 0, 0, 1, 1);
     116            pMainLayout->addWidget(m_pLabelMemory, 0, iRow++, 1, 1);
    107117
    108118        /* Create slider layout: */
     
    146156
    147157            /* Add slider layout to main layout: */
    148             pMainLayout->addLayout(pSliderLayout, 0, 1, 2, 1);
     158            pMainLayout->addLayout(pSliderLayout, 0, iRow++, 2, 1);
    149159        }
    150160
     
    153163        if (m_pSpinBox)
    154164        {
    155             m_pLabelMemory->setBuddy(m_pSpinBox);
     165            setFocusProxy(m_pSpinBox);
     166            if (m_pLabelMemory)
     167                m_pLabelMemory->setBuddy(m_pSpinBox);
    156168            m_pSpinBox->setMinimum(m_pSlider->minRAM());
    157169            m_pSpinBox->setMaximum(m_pSlider->maxRAM());
    158170            connect(m_pSpinBox, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged),
    159171                    this, &UIBaseMemoryEditor::sltHandleSpinBoxChange);
    160             pMainLayout->addWidget(m_pSpinBox, 0, 2, 1, 1);
     172            pMainLayout->addWidget(m_pSpinBox, 0, iRow++, 1, 1);
    161173        }
    162174    }
     
    168180void UIBaseMemoryEditor::revalidate()
    169181{
    170     emit sigValidChanged(m_pSlider->value() < (int)m_pSlider->maxRAMAlw());
     182    if (m_pSlider)
     183        emit sigValidChanged(m_pSlider->value() < (int)m_pSlider->maxRAMAlw());
    171184}
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIBaseMemoryEditor.h

    r79959 r79996  
    4646public:
    4747
    48     /** Constructs base-memory editor passing @a pParent to the base-class. */
    49     UIBaseMemoryEditor(QWidget *pParent = 0);
     48    /** Constructs base-memory editor passing @a pParent to the base-class.
     49      * @param  fWithLabel  Brings whether we should add label ourselves. */
     50    UIBaseMemoryEditor(QWidget *pParent = 0, bool fWithLabel = false);
    5051
    5152    /** Defines editor @a iValue. */
     
    5354    /** Returns editor value. */
    5455    int value() const;
     56
     57    /** Returns the maximum optimal RAM. */
     58    uint maxRAMOpt() const;
     59    /** Returns the maximum allowed RAM. */
     60    uint maxRAMAlw() const;
    5561
    5662protected:
     
    7480    void revalidate();
    7581
     82    /** Holds whether descriptive label should be created. */
     83    bool  m_fWithLabel;
     84
    7685    /** Holds the memory label instance. */
    7786    QLabel             *m_pLabelMemory;
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