VirtualBox

Changeset 74837 in vbox for trunk


Ignore:
Timestamp:
Oct 15, 2018 8:57:13 AM (6 years ago)
Author:
vboxsync
Message:

bugref:9255. Make per-monitor scale factor configuration optional

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsDisplay.cpp

    r74757 r74837  
    408408    /* Load old 'Screen' data from the cache: */
    409409    m_pEditorVideoScreenCount->setValue(oldDisplayData.m_cGuestScreenCount);
     410    m_pScaleFactorEditor->setScaleFactors(oldDisplayData.m_scaleFactors);
    410411    m_pScaleFactorEditor->setMonitorCount(oldDisplayData.m_cGuestScreenCount);
    411     m_pScaleFactorEditor->setScaleFactors(oldDisplayData.m_scaleFactors);
    412412    m_pCheckbox3D->setChecked(oldDisplayData.m_f3dAccelerationEnabled);
    413413#ifdef VBOX_WITH_VIDEOHWACCEL
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIScaleFactorEditor.cpp

    r74757 r74837  
    4343    , m_pMaxScaleLabel(0)
    4444    , m_pMinScaleLabel(0)
     45    , m_dDefaultScaleFactor(1.0)
    4546{
    4647    /* Prepare: */
    4748    prepare();
     49    /* Append a default scale factor to the list as an global scale factor: */
     50    m_scaleFactors.append(1.0);
    4851}
    4952
     
    5255    if (!m_pMonitorComboBox)
    5356        return;
    54     if (iMonitorCount == m_pMonitorComboBox->count())
    55         return;
    56 
     57    /* We always have 0th for global scale factor (in combo box and scale factor list): */
     58    int iEndMonitorCount = iMonitorCount + 1;
     59    int iCurrentMonitorCount = m_pMonitorComboBox->count();
     60    if (iEndMonitorCount == iCurrentMonitorCount)
     61        return;
     62    m_pMonitorComboBox->setEnabled(iMonitorCount > 1);
    5763    m_pMonitorComboBox->blockSignals(true);
    58     int iCurrentMonitorCount = m_pMonitorComboBox->count();
    5964    int iCurrentMonitorIndex = m_pMonitorComboBox->currentIndex();
    60     //m_pMonitorComboBox->clear();
    61     if (iCurrentMonitorCount < iMonitorCount)
    62     {
    63         for (int i = iCurrentMonitorCount; i < iMonitorCount; ++i)
    64         {
    65             m_pMonitorComboBox->addItem(QString("Monitor %1").arg(i));
    66             /* In case that we have increased the # of monitors add new scale factors to the scale factor cache: */
    67             if (i >= m_scaleFactors.size())
    68                 m_scaleFactors.append(1.0);
    69         }
     65    if (iCurrentMonitorCount < iEndMonitorCount)
     66    {
     67        for (int i = iCurrentMonitorCount; i < iEndMonitorCount; ++i)
     68            m_pMonitorComboBox->insertItem(i, QString("Monitor %1").arg(i));
    7069    }
    7170    else
    7271    {
    73         for (int i = iCurrentMonitorCount - 1; i >= iMonitorCount; --i)
     72        for (int i = iCurrentMonitorCount - 1; i >= iEndMonitorCount; --i)
    7473            m_pMonitorComboBox->removeItem(i);
    7574    }
     75    m_pMonitorComboBox->setEnabled(iMonitorCount > 1);
     76    if (iMonitorCount <= 1)
     77        m_pMonitorComboBox->setCurrentIndex(0);
    7678    m_pMonitorComboBox->blockSignals(false);
    77 
     79    /* Update the slider and spinbox values if the combobox index has changed: */
    7880    if (iCurrentMonitorIndex != m_pMonitorComboBox->currentIndex())
    79         showMonitorScaleFactor();
     81        updateValuesAfterMonitorChange();
    8082}
    8183
    8284void UIScaleFactorEditor::setScaleFactors(const QList<double> &scaleFactors)
    8385{
    84     if (m_scaleFactors == scaleFactors)
    85         return;
    86     /* if m_scaleFactors has more items than @p scaleFactors than we keep the additional items
    87        this can happen for example when extra data has 4 scale factor while machine has 5 monitors: */
    88     if (m_scaleFactors.size() > scaleFactors.size())
    89     {
    90         for (int i = 0; i < scaleFactors.size(); ++i)
    91             m_scaleFactors[i] = scaleFactors[i];
     86    m_scaleFactors.clear();
     87    /* If we have a single value from the extra data and we treat if as a default scale factor: */
     88    if (scaleFactors.size() == 1)
     89    {
     90        m_dDefaultScaleFactor = scaleFactors.at(0);
     91        m_scaleFactors.append(m_dDefaultScaleFactor);
     92        isGlobalScaleFactor(true);
     93        return;
     94    }
     95
     96    // Insert 0th element as the global scalar value
     97    m_scaleFactors.append(m_dDefaultScaleFactor);
     98    m_scaleFactors.append(scaleFactors);
     99    isGlobalScaleFactor(false);
     100}
     101
     102QList<double> UIScaleFactorEditor::scaleFactors() const
     103{
     104    QList<double> scaleFactorList;
     105    if (m_scaleFactors.size() == 0)
     106        return scaleFactorList;
     107
     108    /* Decide if the users wants a global (not per monitor) scaling. */
     109    bool globalScaleFactor = false;
     110
     111    /* if "All Monitors" item is selected in the combobox: */
     112    if (m_pMonitorComboBox && m_pMonitorComboBox->currentIndex() == 0)
     113        globalScaleFactor = true;
     114    /* Also check if all of the monitor scale factors equal to the global scale factor: */
     115    if (!globalScaleFactor)
     116    {
     117        globalScaleFactor = true;
     118        for (int i = 1; i < m_scaleFactors.size() && globalScaleFactor; ++i)
     119            if (m_scaleFactors[0] != m_scaleFactors[i])
     120                globalScaleFactor = false;
     121    }
     122
     123    if (globalScaleFactor)
     124    {
     125        scaleFactorList << m_scaleFactors.at(0);
    92126    }
    93127    else
    94128    {
    95         m_scaleFactors = scaleFactors;
    96     }
    97     showMonitorScaleFactor();
    98 }
    99 
    100 
    101 const QList<double>& UIScaleFactorEditor::scaleFactors() const
    102 {
    103     return m_scaleFactors;
     129        /* Skip the 0th scale factor: */
     130        for (int i = 1; i < m_scaleFactors.size(); ++i)
     131            scaleFactorList.append(m_scaleFactors.at(i));
     132    }
     133
     134    return scaleFactorList;
     135}
     136
     137void UIScaleFactorEditor::isGlobalScaleFactor(bool bFlag)
     138{
     139    if (!m_pMonitorComboBox)
     140        return;
     141    if (bFlag && m_pMonitorComboBox->count() >= 1)
     142        m_pMonitorComboBox->setCurrentIndex(0);
     143    else
     144        if(m_pMonitorComboBox->count() >= 2)
     145            m_pMonitorComboBox->setCurrentIndex(1);
     146    updateValuesAfterMonitorChange();
     147}
     148
     149void UIScaleFactorEditor::setDefaultScaleFactor(double dDefaultScaleFactor)
     150{
     151    m_dDefaultScaleFactor = dDefaultScaleFactor;
    104152}
    105153
     
    107155{
    108156    if (m_pMaxScaleLabel)
    109     {
    110157        m_pMaxScaleLabel->setText(tr("Max"));
    111     }
    112158
    113159    if (m_pMinScaleLabel)
    114     {
    115160        m_pMinScaleLabel->setText(tr("Min"));
    116     }
     161
     162    if (m_pMonitorComboBox && m_pMonitorComboBox->count() > 0)
     163    {
     164        m_pMonitorComboBox->setItemText(0, tr("All Monitors"));
     165        for (int i = 0; i < m_pMonitorComboBox->count(); ++i)
     166            m_pMonitorComboBox->setItemText(i, tr("Monitor(%1)").arg(i));
     167    }
     168    setToolTip(tr("Controls the guest screen scale factor"));
    117169}
    118170
     
    131183}
    132184
    133 void UIScaleFactorEditor::sltMonitorComboIndexChanged(int index)
    134 {
    135     if (index >= m_scaleFactors.size())
    136         return;
    137 
    138     /* Update the slider and spinbox values without emitting signals: */
    139     int scaleFactor = 100 * m_scaleFactors[index];
    140     setSliderValue(scaleFactor);
    141     setSpinBoxValue(scaleFactor);
     185void UIScaleFactorEditor::sltMonitorComboIndexChanged(int)
     186{
     187    updateValuesAfterMonitorChange();
    142188}
    143189
     
    153199    {
    154200        m_pMainLayout->addWidget(m_pMonitorComboBox, 0, 0);
     201        m_pMonitorComboBox->insertItem(0, "All Monitors");
    155202        connect(m_pMonitorComboBox ,static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
    156203                this, &UIScaleFactorEditor::sltMonitorComboIndexChanged);
     
    203250void UIScaleFactorEditor::setScaleFactor(int iMonitorIndex, int iScaleFactor)
    204251{
    205     /* Make sure we have the corresponding scale value for the @p iMonitorIndex: */
    206     if (iMonitorIndex >= m_scaleFactors.size())
    207     {
    208         for (int i = m_scaleFactors.size(); i <= iMonitorIndex; ++i)
    209             m_scaleFactors.append(1.0);
     252    /* Make sure we have the corresponding scale values for all monitors: */
     253    if (m_pMonitorComboBox->count() > m_scaleFactors.size())
     254    {
     255        for (int i = m_scaleFactors.size(); i < m_pMonitorComboBox->count(); ++i)
     256            m_scaleFactors.append(m_dDefaultScaleFactor);
    210257    }
    211258    m_scaleFactors[iMonitorIndex] = iScaleFactor / 100.0;
     
    232279}
    233280
    234 void UIScaleFactorEditor::showMonitorScaleFactor()
     281void UIScaleFactorEditor::updateValuesAfterMonitorChange()
    235282{
    236283    /* Set the spinbox value for the currently selected monitor: */
     
    238285    {
    239286        int currentMonitorIndex = m_pMonitorComboBox->currentIndex();
    240         if (m_scaleFactors.size() > currentMonitorIndex && m_pScaleSpinBox)
    241         {
    242             setSpinBoxValue(100 * m_scaleFactors.at(currentMonitorIndex));
    243             setSliderValue(100 * m_scaleFactors.at(currentMonitorIndex));
    244         }
    245     }
    246 }
     287        while (m_scaleFactors.size() <= currentMonitorIndex)
     288            m_scaleFactors.append(m_dDefaultScaleFactor);
     289
     290        setSpinBoxValue(100 * m_scaleFactors.at(currentMonitorIndex));
     291        setSliderValue(100 * m_scaleFactors.at(currentMonitorIndex));
     292
     293    }
     294}
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIScaleFactorEditor.h

    r74757 r74837  
    3535class QIAdvancedSlider;
    3636
    37 /** QWidget reimplementation
    38  * providing GUI with monitor scale factor editing functionality. */
     37/** QWidget reimplementation providing GUI with monitor scale factor editing functionality.
     38 *  It includes a combo box to select a monitor, a slider, and a spinbox to display/modify values.
     39 *  The first item in the combo box is used to change the scale factor of all monitors.*/
    3940class SHARED_LIBRARY_STUFF UIScaleFactorEditor : public QIWithRetranslateUI<QWidget>
    4041{
     
    4344public:
    4445
    45     /** Constructor, passes @a pParent to the QWidget constructor.*/
    4646    UIScaleFactorEditor(QWidget *pParent);
    47     void setMonitorCount(int iMonitorCount);
    48     void setScaleFactors(const QList<double> &scaleFactors);
    49     const QList<double>& scaleFactors() const;
     47    void           setMonitorCount(int iMonitorCount);
     48    void           setScaleFactors(const QList<double> &scaleFactors);
     49    /* Returns either a single global scale factor or a list of scale factor for each monitor. */
     50    QList<double>  scaleFactors() const;
     51
     52    void           isGlobalScaleFactor(bool bFlag);
     53    void           setDefaultScaleFactor(double dDefaultScaleFactor);
    5054
    5155protected:
     
    6872    void               setSpinBoxValue(int iValue);
    6973    /* Set the spinbox and slider to scale factor of currently selected monitor */
    70     void               showMonitorScaleFactor();
     74    void               updateValuesAfterMonitorChange();
    7175    QSpinBox          *m_pScaleSpinBox;
    7276    QGridLayout       *m_pMainLayout;
     
    7579    QLabel            *m_pMaxScaleLabel;
    7680    QLabel            *m_pMinScaleLabel;
    77     /* Stores the per-monitor scale factors in range [.., 1, ..] */
     81    /* Stores the per-monitor scale factors. The 0th item is for all monitors (global) */
    7882    QList<double>      m_scaleFactors;
     83    double             m_dDefaultScaleFactor;
    7984};
    8085
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