VirtualBox

Changeset 97302 in vbox


Ignore:
Timestamp:
Oct 26, 2022 10:26:14 AM (2 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10313 Adding font scaling widget class.

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

Legend:

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

    r97085 r97302  
    921921        src/settings/editors/UIDragAndDropEditor.h \
    922922        src/settings/editors/UIExecutionCapEditor.h \
     923        src/settings/editors/UIFontScaleEditor.h \
    923924        src/settings/editors/UIGraphicsControllerEditor.h \
    924925        src/settings/editors/UIHostComboEditor.h \
     
    15041505        src/settings/editors/UIDragAndDropEditor.cpp \
    15051506        src/settings/editors/UIExecutionCapEditor.cpp \
     1507        src/settings/editors/UIFontScaleEditor.cpp \
    15061508        src/settings/editors/UIGraphicsControllerEditor.cpp \
    15071509        src/settings/editors/UIHostComboEditor.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UIFontScaleEditor.cpp

    r97301 r97302  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIScaleFactorEditor class implementation.
     3 * VBox Qt GUI - UIFontScaleEditor class implementation.
    44 */
    55
     
    2727
    2828/* Qt includes: */
    29 #include <QComboBox>
    3029#include <QGridLayout>
    3130#include <QLabel>
     
    3736#include "QIAdvancedSlider.h"
    3837#include "UIDesktopWidgetWatchdog.h"
    39 #include "UIScaleFactorEditor.h"
     38#include "UIFontScaleEditor.h"
    4039
    4140/* External includes: */
     
    4342
    4443
    45 UIScaleFactorEditor::UIScaleFactorEditor(QWidget *pParent)
     44UIFontScaleEditor::UIFontScaleEditor(QWidget *pParent)
    4645    : QIWithRetranslateUI<QWidget>(pParent)
    4746    , m_pLayout(0)
    4847    , m_pLabel(0)
    49     , m_pMonitorComboBox(0)
    5048    , m_pScaleSlider(0)
    5149    , m_pScaleSpinBox(0)
    5250    , m_pMinScaleLabel(0)
    5351    , m_pMaxScaleLabel(0)
    54     , m_dDefaultScaleFactor(1.0)
    5552{
    5653    /* Prepare: */
    5754    prepare();
    58     /* Append a default scale factor to the list as an global scale factor: */
    59     m_scaleFactors.append(1.0);
    60 }
    61 
    62 void UIScaleFactorEditor::setMonitorCount(int iMonitorCount)
    63 {
    64     if (!m_pMonitorComboBox)
    65         return;
    66     /* We always have 0th for global scale factor (in combo box and scale factor list): */
    67     int iEndMonitorCount = iMonitorCount + 1;
    68     int iCurrentMonitorCount = m_pMonitorComboBox->count();
    69     if (iEndMonitorCount == iCurrentMonitorCount)
    70         return;
    71     m_pMonitorComboBox->setEnabled(iMonitorCount > 1);
    72     m_pMonitorComboBox->blockSignals(true);
    73     int iCurrentMonitorIndex = m_pMonitorComboBox->currentIndex();
    74     if (iCurrentMonitorCount < iEndMonitorCount)
    75     {
    76         for (int i = iCurrentMonitorCount; i < iEndMonitorCount; ++i)
    77             m_pMonitorComboBox->insertItem(i, tr("Monitor %1").arg(i));
    78     }
    79     else
    80     {
    81         for (int i = iCurrentMonitorCount - 1; i >= iEndMonitorCount; --i)
    82             m_pMonitorComboBox->removeItem(i);
    83     }
    84     m_pMonitorComboBox->setEnabled(iMonitorCount > 1);
    85     /* If we have a single monitor select the "All Monitors" item in the combo
    86        but make sure we retain the scale factor of the 0th monitor: */
    87     if (iMonitorCount <= 1)
    88     {
    89         if (m_scaleFactors.size() >= 2)
    90             m_scaleFactors[0] = m_scaleFactors[1];
    91         m_pMonitorComboBox->setCurrentIndex(0);
    92     }
    93     m_pMonitorComboBox->blockSignals(false);
    94     /* Update the slider and spinbox values if the combobox index has changed: */
    95     if (iCurrentMonitorIndex != m_pMonitorComboBox->currentIndex())
    96         updateValuesAfterMonitorChange();
    97 }
    98 
    99 void UIScaleFactorEditor::setScaleFactors(const QList<double> &scaleFactors)
    100 {
    101     m_scaleFactors.clear();
    102     /* If we have a single value from the extra data and we treat if as a default scale factor: */
    103     if (scaleFactors.size() == 1)
    104     {
    105         m_dDefaultScaleFactor = scaleFactors.at(0);
    106         m_scaleFactors.append(m_dDefaultScaleFactor);
    107         setIsGlobalScaleFactor(true);
    108         return;
    109     }
    110 
    111     /* Insert 0th element as the global scalar value: */
    112     m_scaleFactors.append(m_dDefaultScaleFactor);
    113     m_scaleFactors.append(scaleFactors);
    114     setIsGlobalScaleFactor(false);
    115 }
    116 
    117 QList<double> UIScaleFactorEditor::scaleFactors() const
    118 {
    119     QList<double> scaleFactorList;
    120     if (m_scaleFactors.size() == 0)
    121         return scaleFactorList;
    122 
    123     /* Decide if the users wants a global (not per monitor) scaling. */
    124     bool globalScaleFactor = false;
    125 
    126     /* if "All Monitors" item is selected in the combobox: */
    127     if (m_pMonitorComboBox && m_pMonitorComboBox->currentIndex() == 0)
    128         globalScaleFactor = true;
    129     /* Also check if all of the monitor scale factors equal to the global scale factor: */
    130     if (!globalScaleFactor)
    131     {
    132         globalScaleFactor = true;
    133         for (int i = 1; i < m_scaleFactors.size() && globalScaleFactor; ++i)
    134             if (m_scaleFactors[0] != m_scaleFactors[i])
    135                 globalScaleFactor = false;
    136     }
    137 
    138     if (globalScaleFactor)
    139     {
    140         scaleFactorList << m_scaleFactors.at(0);
    141     }
    142     else
    143     {
    144         /* Skip the 0th scale factor: */
    145         for (int i = 1; i < m_scaleFactors.size(); ++i)
    146             scaleFactorList.append(m_scaleFactors.at(i));
    147     }
    148 
    149     return scaleFactorList;
    150 }
    151 
    152 void UIScaleFactorEditor::setIsGlobalScaleFactor(bool bFlag)
    153 {
    154     if (!m_pMonitorComboBox)
    155         return;
    156     if (bFlag && m_pMonitorComboBox->count() >= 1)
    157         m_pMonitorComboBox->setCurrentIndex(0);
    158     else
    159         if(m_pMonitorComboBox->count() >= 2)
    160             m_pMonitorComboBox->setCurrentIndex(1);
    161     updateValuesAfterMonitorChange();
    162 }
    163 
    164 void UIScaleFactorEditor::setDefaultScaleFactor(double dDefaultScaleFactor)
    165 {
    166     m_dDefaultScaleFactor = dDefaultScaleFactor;
    167 }
    168 
    169 void UIScaleFactorEditor::setSpinBoxWidthHint(int iHint)
     55}
     56
     57void UIFontScaleEditor::setSpinBoxWidthHint(int iHint)
    17058{
    17159    m_pScaleSpinBox->setMinimumWidth(iHint);
    17260}
    17361
    174 int UIScaleFactorEditor::minimumLabelHorizontalHint() const
     62int UIFontScaleEditor::minimumLabelHorizontalHint() const
    17563{
    17664    return m_pLabel ? m_pLabel->minimumSizeHint().width() : 0;
    17765}
    17866
    179 void UIScaleFactorEditor::setMinimumLayoutIndent(int iIndent)
     67void UIFontScaleEditor::setMinimumLayoutIndent(int iIndent)
    18068{
    18169    if (m_pLayout)
     
    18371}
    18472
    185 void UIScaleFactorEditor::retranslateUi()
     73void UIFontScaleEditor::retranslateUi()
    18674{
    18775    if (m_pLabel)
    188         m_pLabel->setText(tr("Scale &Factor:"));
    189 
    190     if (m_pMonitorComboBox)
    191     {
    192         if (m_pMonitorComboBox->count() > 0)
    193         {
    194             m_pMonitorComboBox->setItemText(0, tr("All Monitors"));
    195             for (int i = 1; i < m_pMonitorComboBox->count(); ++i)
    196                 m_pMonitorComboBox->setItemText(i, tr("Monitor %1").arg(i));
    197         }
    198         m_pMonitorComboBox->setToolTip(tr("Selects the index of monitor guest screen scale factor being defined for."));
    199     }
     76        m_pLabel->setText(tr("F&ont Scaling:"));
    20077
    20178    if (m_pScaleSlider)
    202         m_pScaleSlider->setToolTip(tr("Holds the guest screen scale factor."));
     79        m_pScaleSlider->setToolTip(tr("Holds the scaling factor for the font size."));
    20380    if (m_pScaleSpinBox)
    204         m_pScaleSpinBox->setToolTip(tr("Holds the guest screen scale factor."));
     81        m_pScaleSpinBox->setToolTip(tr("Holds the scaling factor for the font size."));
    20582
    20683    if (m_pMinScaleLabel)
     
    21693}
    21794
    218 void UIScaleFactorEditor::sltScaleSpinBoxValueChanged(int value)
     95void UIFontScaleEditor::sltScaleSpinBoxValueChanged(int value)
    21996{
    22097    setSliderValue(value);
    221     if (m_pMonitorComboBox)
    222         setScaleFactor(m_pMonitorComboBox->currentIndex(), value);
    223 }
    224 
    225 void UIScaleFactorEditor::sltScaleSliderValueChanged(int value)
     98}
     99
     100void UIFontScaleEditor::sltScaleSliderValueChanged(int value)
    226101{
    227102    setSpinBoxValue(value);
    228     if (m_pMonitorComboBox)
    229         setScaleFactor(m_pMonitorComboBox->currentIndex(), value);
    230 }
    231 
    232 void UIScaleFactorEditor::sltMonitorComboIndexChanged(int)
    233 {
    234     updateValuesAfterMonitorChange();
    235 }
    236 
    237 void UIScaleFactorEditor::prepare()
     103}
     104
     105void UIFontScaleEditor::sltMonitorComboIndexChanged(int)
     106{
     107}
     108
     109void UIFontScaleEditor::prepare()
    238110{
    239111    m_pLayout = new QGridLayout(this);
     
    242114        m_pLayout->setContentsMargins(0, 0, 0, 0);
    243115        m_pLayout->setColumnStretch(1, 1);
    244         m_pLayout->setColumnStretch(2, 1);
    245116
    246117        /* Prepare label: */
     
    250121            m_pLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    251122            m_pLayout->addWidget(m_pLabel, 0, 0);
    252         }
    253 
    254         m_pMonitorComboBox = new QComboBox(this);
    255         if (m_pMonitorComboBox)
    256         {
    257             m_pMonitorComboBox->insertItem(0, "All Monitors");
    258             connect(m_pMonitorComboBox ,static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
    259                     this, &UIScaleFactorEditor::sltMonitorComboIndexChanged);
    260 
    261             m_pLayout->addWidget(m_pMonitorComboBox, 0, 1);
    262123        }
    263124
     
    271132            m_pScaleSlider->setSnappingEnabled(true);
    272133            connect(m_pScaleSlider, static_cast<void(QIAdvancedSlider::*)(int)>(&QIAdvancedSlider::valueChanged),
    273                     this, &UIScaleFactorEditor::sltScaleSliderValueChanged);
    274 
    275             m_pLayout->addWidget(m_pScaleSlider, 0, 2, 1, 2);
     134                    this, &UIFontScaleEditor::sltScaleSliderValueChanged);
     135
     136            m_pLayout->addWidget(m_pScaleSlider, 0, 1, 1, 4);
    276137        }
    277138
     
    282143            m_pScaleSpinBox->setSuffix("%");
    283144            connect(m_pScaleSpinBox ,static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged),
    284                     this, &UIScaleFactorEditor::sltScaleSpinBoxValueChanged);
    285             m_pLayout->addWidget(m_pScaleSpinBox, 0, 4);
     145                    this, &UIFontScaleEditor::sltScaleSpinBoxValueChanged);
     146            m_pLayout->addWidget(m_pScaleSpinBox, 0, 5);
    286147        }
    287148
    288149        m_pMinScaleLabel = new QLabel(this);
    289150        if (m_pMinScaleLabel)
    290             m_pLayout->addWidget(m_pMinScaleLabel, 1, 2);
     151            m_pLayout->addWidget(m_pMinScaleLabel, 1, 1);
    291152
    292153        m_pMaxScaleLabel = new QLabel(this);
    293154        if (m_pMaxScaleLabel)
    294             m_pLayout->addWidget(m_pMaxScaleLabel, 1, 3);
     155            m_pLayout->addWidget(m_pMaxScaleLabel, 1, 4);
    295156    }
    296157
     
    299160}
    300161
    301 void UIScaleFactorEditor::prepareScaleFactorMinMaxValues()
     162void UIFontScaleEditor::prepareScaleFactorMinMaxValues()
    302163{
    303164    const int iHostScreenCount = gpDesktop->screenCount();
     
    323184}
    324185
    325 void UIScaleFactorEditor::setScaleFactor(int iMonitorIndex, int iScaleFactor)
    326 {
    327     /* Make sure we have the corresponding scale values for all monitors: */
    328     if (m_pMonitorComboBox->count() > m_scaleFactors.size())
    329     {
    330         for (int i = m_scaleFactors.size(); i < m_pMonitorComboBox->count(); ++i)
    331             m_scaleFactors.append(m_dDefaultScaleFactor);
    332     }
    333     m_scaleFactors[iMonitorIndex] = iScaleFactor / 100.0;
    334 }
    335 
    336 void UIScaleFactorEditor::setSliderValue(int iValue)
     186void UIFontScaleEditor::setSliderValue(int iValue)
    337187{
    338188    if (m_pScaleSlider && iValue != m_pScaleSlider->value())
     
    344194}
    345195
    346 void UIScaleFactorEditor::setSpinBoxValue(int iValue)
     196void UIFontScaleEditor::setSpinBoxValue(int iValue)
    347197{
    348198    if (m_pScaleSpinBox && iValue != m_pScaleSpinBox->value())
     
    354204}
    355205
    356 void UIScaleFactorEditor::updateValuesAfterMonitorChange()
    357 {
    358     /* Set the spinbox value for the currently selected monitor: */
    359     if (m_pMonitorComboBox)
    360     {
    361         int currentMonitorIndex = m_pMonitorComboBox->currentIndex();
    362         while (m_scaleFactors.size() <= currentMonitorIndex)
    363             m_scaleFactors.append(m_dDefaultScaleFactor);
    364 
    365         setSpinBoxValue(100 * m_scaleFactors.at(currentMonitorIndex));
    366         setSliderValue(100 * m_scaleFactors.at(currentMonitorIndex));
    367 
    368     }
    369 }
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UIFontScaleEditor.h

    r97301 r97302  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIScaleFactorEditor class declaration.
     3 * VBox Qt GUI - UIFontScaleEditor class declaration.
    44 */
    55
     
    2626 */
    2727
    28 #ifndef FEQT_INCLUDED_SRC_settings_editors_UIScaleFactorEditor_h
    29 #define FEQT_INCLUDED_SRC_settings_editors_UIScaleFactorEditor_h
     28#ifndef FEQT_INCLUDED_SRC_settings_editors_UIFontScaleEditor_h
     29#define FEQT_INCLUDED_SRC_settings_editors_UIFontScaleEditor_h
    3030#ifndef RT_WITHOUT_PRAGMA_ONCE
    3131# pragma once
     
    3737
    3838/* Forward declarations: */
    39 class QComboBox;
    4039class QGridLayout;
    4140class QLabel;
     
    4746  * It includes a combo box to select a monitor, a slider, and a spinbox to display/modify values.
    4847  * The first item in the combo box is used to change the scale factor of all monitors. */
    49 class SHARED_LIBRARY_STUFF UIScaleFactorEditor : public QIWithRetranslateUI<QWidget>
     48class SHARED_LIBRARY_STUFF UIFontScaleEditor : public QIWithRetranslateUI<QWidget>
    5049{
    5150    Q_OBJECT;
     
    5453
    5554    /** Constructs editor passing @a pParent to the base-class. */
    56     UIScaleFactorEditor(QWidget *pParent);
    57 
    58     /** Defines @a iMonitorCount. */
    59     void setMonitorCount(int iMonitorCount);
    60     /** Defines a list of guest-screen @a scaleFactors. */
    61     void setScaleFactors(const QList<double> &scaleFactors);
    62 
    63     /** Returns either a single global scale factor or a list of scale factor for each monitor. */
    64     QList<double> scaleFactors() const;
    65 
    66     /** Defines @a dDefaultScaleFactor. */
    67     void setDefaultScaleFactor(double dDefaultScaleFactor);
     55    UIFontScaleEditor(QWidget *pParent);
    6856
    6957    /** Defines minimum width @a iHint for internal spin-box. */
     
    9684    void prepareScaleFactorMinMaxValues();
    9785
    98     /** Defines whether scale factor is @a fGlobal one. */
    99     void setIsGlobalScaleFactor(bool fGlobal);
    100     /** Defines @a iScaleFactor for certain @a iMonitorIndex. */
    101     void setScaleFactor(int iMonitorIndex, int iScaleFactor);
     86
    10287    /** Defines slider's @a iValue. */
    10388    void setSliderValue(int iValue);
     
    10590    void setSpinBoxValue(int iValue);
    10691
    107     /** Sets the spinbox and slider to scale factor of currently selected monitor. */
    108     void updateValuesAfterMonitorChange();
    10992
    11093    /** @name Member widgets.
     
    11295        QGridLayout      *m_pLayout;
    11396        QLabel           *m_pLabel;
    114         QComboBox        *m_pMonitorComboBox;
    11597        QIAdvancedSlider *m_pScaleSlider;
    11698        QSpinBox         *m_pScaleSpinBox;
     
    118100        QLabel           *m_pMaxScaleLabel;
    119101    /** @} */
    120 
    121     /** Holds the per-monitor scale factors. The 0th item is for all monitors (global). */
    122     QList<double>  m_scaleFactors;
    123     /** Holds the default scale factor. */
    124     double         m_dDefaultScaleFactor;
    125102};
    126103
    127 #endif /* !FEQT_INCLUDED_SRC_settings_editors_UIScaleFactorEditor_h */
     104#endif /* !FEQT_INCLUDED_SRC_settings_editors_UIFontScaleEditor_h */
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsDisplay.cpp

    r97245 r97302  
    3232#include "UIDesktopWidgetWatchdog.h"
    3333#include "UIExtraDataManager.h"
     34#include "UIFontScaleEditor.h"
    3435#include "UIDisplayFeaturesEditor.h"
    3536#include "UIGlobalSettingsDisplay.h"
     
    8384    , m_pEditorScaleFactor(0)
    8485    , m_pEditorGlobalDisplayFeatures(0)
     86    , m_pFontScaleEditor(0)
    8587{
    8688    prepare();
     
    187189    iMinimumLayoutHint = qMax(iMinimumLayoutHint, m_pEditorScaleFactor->minimumLabelHorizontalHint());
    188190    iMinimumLayoutHint = qMax(iMinimumLayoutHint, m_pEditorGlobalDisplayFeatures->minimumLabelHorizontalHint());
     191    iMinimumLayoutHint = qMax(iMinimumLayoutHint, m_pFontScaleEditor->minimumLabelHorizontalHint());
    189192    m_pEditorMaximumGuestScreenSize->setMinimumLayoutIndent(iMinimumLayoutHint);
    190193    m_pEditorScaleFactor->setMinimumLayoutIndent(iMinimumLayoutHint);
    191194    m_pEditorGlobalDisplayFeatures->setMinimumLayoutIndent(iMinimumLayoutHint);
     195    m_pFontScaleEditor->setMinimumLayoutIndent(iMinimumLayoutHint);
    192196}
    193197
     
    225229        if (m_pEditorGlobalDisplayFeatures)
    226230            pLayout->addWidget(m_pEditorGlobalDisplayFeatures);
     231
     232        /* Prepare 'font scale' editor: */
     233        m_pFontScaleEditor = new UIFontScaleEditor(this);
     234        if (m_pFontScaleEditor)
     235            pLayout->addWidget(m_pFontScaleEditor);
    227236
    228237        /* Add stretch to the end: */
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsDisplay.h

    r97245 r97302  
    3737/* Forward declarations: */
    3838class UIDisplayFeaturesEditor;
     39class UIFontScaleEditor;
    3940class UIMaximumGuestScreenSizeEditor;
    4041class UIScaleFactorEditor;
     
    99100        /** Holds the global display features editor instance. */
    100101        UIDisplayFeaturesEditor        *m_pEditorGlobalDisplayFeatures;
     102        /** Holds the font scale editor instance. */
     103        UIFontScaleEditor              *m_pFontScaleEditor;
    101104    /** @} */
    102105};
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